Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1233

  • added semaphores to ensure an appdomain is never unloaded when the start method has not finished
  • HiveEngine uploading and downloading of jobs works and is displayed in the view
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.Elites.Value = 0;
52      ga.PopulationSize.Value = 4;
53      ga.MaximumGenerations.Value = 3;
54
55      //var plugins = new List<IPluginDescription>();
56      //IEnumerable<Type> types;
57      //PersistenceUtil.Serialize(ga, out types);
58      //PluginUtil.CollectDeclaringPlugins(plugins, types);
59
60
61      ga.Start();
62
63      while (ga.ExecutionState != Core.ExecutionState.Stopped && ga.ExecutionState != Core.ExecutionState.Paused) {
64        Thread.Sleep(2000);
65        Console.Clear();
66        Console.WriteLine(string.Join(Environment.NewLine, ga.Results.Select(x => x.ToString()).ToArray()));
67        Console.WriteLine("---");
68        Console.WriteLine("Log:");
69        Console.WriteLine(string.Join(Environment.NewLine, ga.Engine.Log.Messages.ToArray()));
70      }
71      Console.WriteLine("finished: " + ga.ExecutionState);
72
73      Console.WriteLine("Storing...");
74      ContentManager.Save((IStorableContent)ga, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
75      Console.WriteLine("Finished");
76
77      Console.ReadLine();
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.