1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.IO;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Reflection;
|
---|
26 | using System.Threading;
|
---|
27 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
28 | using HeuristicLab.Clients.Hive;
|
---|
29 | using HeuristicLab.Clients.Hive.Jobs;
|
---|
30 | using HeuristicLab.Common;
|
---|
31 | using HeuristicLab.Core;
|
---|
32 | using HeuristicLab.Optimization;
|
---|
33 | using HeuristicLab.PluginInfrastructure;
|
---|
34 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
35 | using HeuristicLab.Problems.TestFunctions;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.HiveEngine.Test {
|
---|
38 | public class Program {
|
---|
39 | static void Main(string[] args) {
|
---|
40 | PluginManager pm = new PluginManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
|
---|
41 | pm.DiscoverAndCheckPlugins();
|
---|
42 | pm.Run(pm.Applications.Where(x => x.Name == "HeuristicLab.HiveEngine.Test").SingleOrDefault());
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | [Plugin("HeuristicLab.HiveEngine.Test", "1.0.0.0")]
|
---|
47 | [PluginFile("HeuristicLab.HiveEngine.Test.exe", PluginFileType.Assembly)]
|
---|
48 | public class TestPlugin : PluginBase { }
|
---|
49 |
|
---|
50 | [Application("HeuristicLab.HiveEngine.Test")]
|
---|
51 | public class TestApp : ApplicationBase {
|
---|
52 |
|
---|
53 | public override void Run() {
|
---|
54 | ContentManager.Initialize(new PersistenceContentManager());
|
---|
55 |
|
---|
56 | OptimizerTask job = new OptimizerTask(new Experiment());
|
---|
57 | job.IndexInParentOptimizerList = 15;
|
---|
58 |
|
---|
59 | //byte[] data = PersistenceUtil.Serialize(task);
|
---|
60 |
|
---|
61 | //var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
|
---|
62 |
|
---|
63 | #region Credentials
|
---|
64 | ServiceLocator.Instance.Username = "cneumuel";
|
---|
65 | ServiceLocator.Instance.Password = "";
|
---|
66 | #endregion
|
---|
67 |
|
---|
68 | GeneticAlgorithm alg = new GeneticAlgorithm();
|
---|
69 | alg.Problem = new SingleObjectiveTestFunctionProblem();
|
---|
70 | alg.Engine = new HiveEngine() { ResourceNames = "HEAL" };
|
---|
71 | alg.Elites.Value = 0;
|
---|
72 | alg.PopulationSize.Value = 10;
|
---|
73 | alg.MaximumGenerations.Value = 3;
|
---|
74 |
|
---|
75 | //var alg = ContentManager.Load("Meta-GA - Meta Optimization Problem (Genetic Programming - Symbolic Regression 3.4 scaled)_small.hl") as GeneticAlgorithm;
|
---|
76 | //alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" };
|
---|
77 | //alg.PopulationSize.Value = 2;
|
---|
78 | //((MetaOptimizationProblem)alg.Problem).Repetitions.Value = 5;
|
---|
79 |
|
---|
80 | alg.Start();
|
---|
81 |
|
---|
82 | while (alg.ExecutionState != Core.ExecutionState.Stopped && alg.ExecutionState != Core.ExecutionState.Paused) {
|
---|
83 | Thread.Sleep(2000);
|
---|
84 | Console.Clear();
|
---|
85 | Console.WriteLine(string.Join(Environment.NewLine, alg.Results.Select(x => x.ToString()).ToArray()));
|
---|
86 | Console.WriteLine("---");
|
---|
87 | Console.WriteLine("Log:");
|
---|
88 | Console.WriteLine(string.Join(Environment.NewLine, alg.Engine.Log.Messages.ToArray()));
|
---|
89 | var exps = ((HiveEngine)alg.Engine).Jobs;
|
---|
90 | foreach (var exp in exps) {
|
---|
91 | Console.WriteLine("# " + exp.ToString());
|
---|
92 | Console.WriteLine(string.Join(Environment.NewLine, exp.Log.Messages.ToArray()));
|
---|
93 | }
|
---|
94 | }
|
---|
95 | Console.WriteLine("finished: " + alg.ExecutionState);
|
---|
96 |
|
---|
97 | Console.WriteLine("Storing...");
|
---|
98 | ContentManager.Save((IStorableContent)alg, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
|
---|
99 | Console.WriteLine("Finished");
|
---|
100 |
|
---|
101 | Console.ReadLine();
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|