Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine.Test/Program.cs @ 6039

Last change on this file since 6039 was 6039, checked in by cneumuel, 13 years ago

#1233

  • small fixes
File size: 2.8 KB
Line 
1using System;
2using System.IO;
3using System.Linq;
4using System.Reflection;
5using System.Threading;
6using HeuristicLab.Algorithms.GeneticAlgorithm;
7using HeuristicLab.Clients.Hive;
8using HeuristicLab.Common;
9using HeuristicLab.Core;
10using HeuristicLab.PluginInfrastructure;
11using HeuristicLab.PluginInfrastructure.Manager;
12using HeuristicLab.Problems.TestFunctions;
13using HeuristicLab.Clients.Hive.Jobs;
14using HeuristicLab.Optimization;
15
16namespace HeuristicLab.HiveEngine.Test {
17  public class Program {
18    static void Main(string[] args) {
19      PluginManager pm = new PluginManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
20      pm.DiscoverAndCheckPlugins();
21      pm.Run(pm.Applications.Where(x => x.Name == "HeuristicLab.HiveEngine.Test").SingleOrDefault());
22    }
23  }
24
25  [Plugin("HeuristicLab.HiveEngine.Test", "1.0.0.0")]
26  [PluginFile("HeuristicLab.HiveEngine.Test.exe", PluginFileType.Assembly)]
27  public class TestPlugin : PluginBase { }
28
29  [Application("HeuristicLab.HiveEngine.Test")]
30  public class TestApp : ApplicationBase {
31
32    public override void Run() {
33      ContentManager.Initialize(new PersistenceContentManager());
34
35
36      OptimizerJob job = new OptimizerJob(new Experiment());
37      job.IndexInParentOptimizerList = 15;
38
39      byte[] data = PersistenceUtil.Serialize(job);
40
41      var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
42
43
44
45      #region Credentials
46      ServiceLocator.Instance.Username = "cneumuel";
47      ServiceLocator.Instance.Password = "YouWillNeverKnow";
48      #endregion
49
50      GeneticAlgorithm ga = new GeneticAlgorithm();
51      ga.Problem = new SingleObjectiveTestFunctionProblem();
52      ga.Engine = new HiveEngine();     
53      ga.PopulationSize.Value = 3;
54      ga.MaximumGenerations.Value = 3;
55
56      //var plugins = new List<IPluginDescription>();
57      //IEnumerable<Type> types;
58      //PersistenceUtil.Serialize(ga, out types);
59      //PluginUtil.CollectDeclaringPlugins(plugins, types);
60
61
62      ga.Start();
63
64      while (ga.ExecutionState != Core.ExecutionState.Stopped && ga.ExecutionState != Core.ExecutionState.Paused) {
65        Thread.Sleep(2000);
66        Console.Clear();
67        Console.WriteLine(string.Join(Environment.NewLine, ga.Results.Select(x => x.ToString()).ToArray()));
68        Console.WriteLine("---");
69        Console.WriteLine("Log:");
70        Console.WriteLine(string.Join(Environment.NewLine, ga.Engine.Log.Messages.ToArray()));
71      }
72      Console.WriteLine("finished: " + ga.ExecutionState);
73
74      Console.WriteLine("Storing...");
75      ContentManager.Save((IStorableContent)ga, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
76      Console.WriteLine("Finished");
77
78      Console.ReadLine();
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.