Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1233

  • refactoring of slave core
  • created JobManager, which is responsible for managing jobs without knowing anything about the service. this class is easier testable than slave core
  • lots of cleanup
  • created console test project for slave
File size: 3.2 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      OptimizerJob job = new OptimizerJob(new Experiment());
36      job.IndexInParentOptimizerList = 15;
37
38      //byte[] data = PersistenceUtil.Serialize(job);
39
40      //var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
41     
42      #region Credentials
43      ServiceLocator.Instance.Username = "cneumuel";
44      ServiceLocator.Instance.Password = "Stormlord105.";
45      #endregion
46
47      GeneticAlgorithm alg = new GeneticAlgorithm();
48      alg.Problem = new SingleObjectiveTestFunctionProblem();
49      alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" };
50      alg.Elites.Value = 0;
51      alg.PopulationSize.Value = 10;
52      alg.MaximumGenerations.Value = 3;
53
54      //var alg = ContentManager.Load("Meta-GA - Meta Optimization Problem (Genetic Programming - Symbolic Regression 3.4 scaled)_small.hl") as GeneticAlgorithm;
55      //alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" };
56      //alg.PopulationSize.Value = 2;
57      //((MetaOptimizationProblem)alg.Problem).Repetitions.Value = 5;
58
59      alg.Start();
60
61      while (alg.ExecutionState != Core.ExecutionState.Stopped && alg.ExecutionState != Core.ExecutionState.Paused) {
62        Thread.Sleep(2000);
63        Console.Clear();
64        Console.WriteLine(string.Join(Environment.NewLine, alg.Results.Select(x => x.ToString()).ToArray()));
65        Console.WriteLine("---");
66        Console.WriteLine("Log:");
67        Console.WriteLine(string.Join(Environment.NewLine, alg.Engine.Log.Messages.ToArray()));
68        var exps = ((HiveEngine)alg.Engine).HiveExperiments;
69        foreach (var exp in exps) {
70          Console.WriteLine("# " + exp.ToString());
71          Console.WriteLine(string.Join(Environment.NewLine, exp.Log.Messages.ToArray()));
72        }
73      }
74      Console.WriteLine("finished: " + alg.ExecutionState);
75
76      Console.WriteLine("Storing...");
77      ContentManager.Save((IStorableContent)alg, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
78      Console.WriteLine("Finished");
79
80      Console.ReadLine();
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.