Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1233

  • renamed engines to executors
  • changed locking in StartJobInAppDomain
  • avoid destruction of proxy object after 5 minutes for Slave.Core
  • added JobStarted event and fixed ExecutionStateChanged and ExecutionTimeChanged
  • slaves which are moved to another slavegroup will pause their jobs now, if they must not calculate them
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.Clients.Hive.Jobs;
9using HeuristicLab.Common;
10using HeuristicLab.Core;
11using HeuristicLab.Optimization;
12using HeuristicLab.PluginInfrastructure;
13using HeuristicLab.PluginInfrastructure.Manager;
14using HeuristicLab.Problems.TestFunctions;
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      #region Credentials
44      ServiceLocator.Instance.Username = "cneumuel";
45      ServiceLocator.Instance.Password = "YouWillNeverKnow";
46      #endregion
47
48      GeneticAlgorithm ga = new GeneticAlgorithm();
49      ga.Problem = new SingleObjectiveTestFunctionProblem();
50      ga.Engine = new HiveEngine();     
51      ga.PopulationSize.Value = 3;
52      ga.MaximumGenerations.Value = 3;
53
54      //var plugins = new List<IPluginDescription>();
55      //IEnumerable<Type> types;
56      //PersistenceUtil.Serialize(ga, out types);
57      //PluginUtil.CollectDeclaringPlugins(plugins, types);
58
59
60      ga.Start();
61
62      while (ga.ExecutionState != Core.ExecutionState.Stopped && ga.ExecutionState != Core.ExecutionState.Paused) {
63        Thread.Sleep(2000);
64        Console.Clear();
65        Console.WriteLine(string.Join(Environment.NewLine, ga.Results.Select(x => x.ToString()).ToArray()));
66        Console.WriteLine("---");
67        Console.WriteLine("Log:");
68        Console.WriteLine(string.Join(Environment.NewLine, ga.Engine.Log.Messages.ToArray()));
69      }
70      Console.WriteLine("finished: " + ga.ExecutionState);
71
72      Console.WriteLine("Storing...");
73      ContentManager.Save((IStorableContent)ga, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
74      Console.WriteLine("Finished");
75
76      Console.ReadLine();
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.