using System; using System.IO; using System.Linq; using System.Reflection; using System.Threading; using HeuristicLab.Algorithms.GeneticAlgorithm; using HeuristicLab.Clients.Hive; using HeuristicLab.Clients.Hive.Jobs; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Optimization; using HeuristicLab.PluginInfrastructure; using HeuristicLab.PluginInfrastructure.Manager; using HeuristicLab.Problems.TestFunctions; namespace HeuristicLab.HiveEngine.Test { public class Program { static void Main(string[] args) { PluginManager pm = new PluginManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); pm.DiscoverAndCheckPlugins(); pm.Run(pm.Applications.Where(x => x.Name == "HeuristicLab.HiveEngine.Test").SingleOrDefault()); } } [Plugin("HeuristicLab.HiveEngine.Test", "1.0.0.0")] [PluginFile("HeuristicLab.HiveEngine.Test.exe", PluginFileType.Assembly)] public class TestPlugin : PluginBase { } [Application("HeuristicLab.HiveEngine.Test")] public class TestApp : ApplicationBase { public override void Run() { ContentManager.Initialize(new PersistenceContentManager()); OptimizerJob job = new OptimizerJob(new Experiment()); job.IndexInParentOptimizerList = 15; //byte[] data = PersistenceUtil.Serialize(job); //var job2 = PersistenceUtil.Deserialize(data); #region Credentials ServiceLocator.Instance.Username = "cneumuel"; ServiceLocator.Instance.Password = ""; #endregion GeneticAlgorithm alg = new GeneticAlgorithm(); alg.Problem = new SingleObjectiveTestFunctionProblem(); alg.Engine = new HiveEngine() { ResourceNames = "HEAL" }; alg.Elites.Value = 0; alg.PopulationSize.Value = 10; alg.MaximumGenerations.Value = 3; //var alg = ContentManager.Load("Meta-GA - Meta Optimization Problem (Genetic Programming - Symbolic Regression 3.4 scaled)_small.hl") as GeneticAlgorithm; //alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" }; //alg.PopulationSize.Value = 2; //((MetaOptimizationProblem)alg.Problem).Repetitions.Value = 5; alg.Start(); while (alg.ExecutionState != Core.ExecutionState.Stopped && alg.ExecutionState != Core.ExecutionState.Paused) { Thread.Sleep(2000); Console.Clear(); Console.WriteLine(string.Join(Environment.NewLine, alg.Results.Select(x => x.ToString()).ToArray())); Console.WriteLine("---"); Console.WriteLine("Log:"); Console.WriteLine(string.Join(Environment.NewLine, alg.Engine.Log.Messages.ToArray())); var exps = ((HiveEngine)alg.Engine).HiveExperiments; foreach (var exp in exps) { Console.WriteLine("# " + exp.ToString()); Console.WriteLine(string.Join(Environment.NewLine, exp.Log.Messages.ToArray())); } } Console.WriteLine("finished: " + alg.ExecutionState); Console.WriteLine("Storing..."); ContentManager.Save((IStorableContent)alg, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true); Console.WriteLine("Finished"); Console.ReadLine(); } } }