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
RevLine 
[6000]1using System;
2using System.IO;
3using System.Linq;
4using System.Reflection;
5using System.Threading;
6using HeuristicLab.Algorithms.GeneticAlgorithm;
7using HeuristicLab.Clients.Hive;
[6110]8using HeuristicLab.Clients.Hive.Jobs;
[6000]9using HeuristicLab.Common;
10using HeuristicLab.Core;
[6110]11using HeuristicLab.Optimization;
[6000]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
[6725]35      OptimizerTask job = new OptimizerTask(new Experiment());
[6033]36      job.IndexInParentOptimizerList = 15;
37
[6725]38      //byte[] data = PersistenceUtil.Serialize(task);
[6033]39
[6357]40      //var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
[6110]41     
[6000]42      #region Credentials
43      ServiceLocator.Instance.Username = "cneumuel";
[6373]44      ServiceLocator.Instance.Password = "";
[6000]45      #endregion
46
[6357]47      GeneticAlgorithm alg = new GeneticAlgorithm();
48      alg.Problem = new SingleObjectiveTestFunctionProblem();
[6381]49      alg.Engine = new HiveEngine() { ResourceNames = "HEAL" };
[6357]50      alg.Elites.Value = 0;
51      alg.PopulationSize.Value = 10;
52      alg.MaximumGenerations.Value = 3;
[6000]53
[6357]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;
[6039]58
[6357]59      alg.Start();
[6039]60
[6357]61      while (alg.ExecutionState != Core.ExecutionState.Stopped && alg.ExecutionState != Core.ExecutionState.Paused) {
[6000]62        Thread.Sleep(2000);
63        Console.Clear();
[6357]64        Console.WriteLine(string.Join(Environment.NewLine, alg.Results.Select(x => x.ToString()).ToArray()));
[6000]65        Console.WriteLine("---");
66        Console.WriteLine("Log:");
[6357]67        Console.WriteLine(string.Join(Environment.NewLine, alg.Engine.Log.Messages.ToArray()));
[6725]68        var exps = ((HiveEngine)alg.Engine).Jobs;
[6357]69        foreach (var exp in exps) {
70          Console.WriteLine("# " + exp.ToString());
71          Console.WriteLine(string.Join(Environment.NewLine, exp.Log.Messages.ToArray()));
72        }
[6000]73      }
[6357]74      Console.WriteLine("finished: " + alg.ExecutionState);
[6000]75
76      Console.WriteLine("Storing...");
[6357]77      ContentManager.Save((IStorableContent)alg, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
[6000]78      Console.WriteLine("Finished");
79
80      Console.ReadLine();
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.