Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.HiveEngine/3.3/Tests/Program.cs @ 6727

Last change on this file since 6727 was 6725, checked in by ascheibe, 13 years ago

#1233 more renaming for more consistency

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      OptimizerTask job = new OptimizerTask(new Experiment());
36      job.IndexInParentOptimizerList = 15;
37
38      //byte[] data = PersistenceUtil.Serialize(task);
39
40      //var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
41     
42      #region Credentials
43      ServiceLocator.Instance.Username = "cneumuel";
44      ServiceLocator.Instance.Password = "";
45      #endregion
46
47      GeneticAlgorithm alg = new GeneticAlgorithm();
48      alg.Problem = new SingleObjectiveTestFunctionProblem();
49      alg.Engine = new HiveEngine() { ResourceNames = "HEAL" };
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).Jobs;
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.