Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngineTest/Program.cs @ 5213

Last change on this file since 5213 was 5213, checked in by cneumuel, 14 years ago

#1260

  • changed HiveEngine to be compatible with recent changes of engine
File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Algorithms.GeneticAlgorithm;
6using HeuristicLab.Problems.TestFunctions;
7using System.Threading;
8using HeuristicLab.Optimization;
9using HeuristicLab.Operators;
10using HeuristicLab.Hive.ExperimentManager;
11using HeuristicLab.PluginInfrastructure.Manager;
12using HeuristicLab.PluginInfrastructure;
13using System.Reflection;
14using System.IO;
15using HeuristicLab.Common;
16using HeuristicLab.Core;
17
18namespace HeuristicLab.HiveEngineTest {
19  class Program {
20    static void Main(string[] args) {
21      //PluginLoader.pluginAssemblies.Any();
22      PluginManager pm = new PluginManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
23      pm.DiscoverAndCheckPlugins();
24
25      pm.Run(pm.Applications.Where(x => x.Name == "TestApp").SingleOrDefault());
26    }
27  }
28
29  [Application("TestApp")]
30  public class TestApp : ApplicationBase {
31
32    public override void Run() {
33      ContentManager.Initialize(new PersistenceContentManager());
34      ServiceLocator.Instance.ClientFacadePool.UserName = "cneumuel";
35      ServiceLocator.Instance.ClientFacadePool.Password = "cneumuel";
36      ServiceLocator.Instance.StreamedClientFacadePool.UserName = "cneumuel";
37      ServiceLocator.Instance.StreamedClientFacadePool.Password = "cneumuel";
38
39      GeneticAlgorithm ga = new GeneticAlgorithm();
40      ga.Problem = new SingleObjectiveTestFunctionProblem();
41      ga.Engine = new HiveEngine.HiveEngine();
42      ga.PopulationSize.Value = 10;
43      ga.MaximumGenerations.Value = 3;
44
45      ga.Start();
46
47      while (ga.ExecutionState != Core.ExecutionState.Stopped && ga.ExecutionState != Core.ExecutionState.Paused) {
48        Thread.Sleep(2000);
49        Console.Clear();
50        Console.WriteLine(string.Join(Environment.NewLine, ga.Results.Select(x => x.ToString()).ToArray()));
51        Console.WriteLine("---");
52        Console.WriteLine("Log:");
53        Console.WriteLine(string.Join(Environment.NewLine, ga.Engine.Log.Messages.ToArray()));
54      }
55      Console.WriteLine("finished: " + ga.ExecutionState);
56
57      Console.WriteLine("Storing...");
58      ContentManager.Save((IStorableContent)ga, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
59      Console.WriteLine("Finished");
60    }
61  }
62
63  [Plugin("TestPlugin", "1.0.0.0")]
64  [PluginFile("HeuristicLab.HiveEngineTest.exe", PluginFileType.Assembly)]
65  public class TestPlugin : PluginBase { }
66
67}
Note: See TracBrowser for help on using the repository browser.