public virtual double Evaluate(IChromosome chromosome)
        {
            try
            {
                string output = "";
                var    list   = ((Chromosome)chromosome).ToDictionary();

                foreach (var item in list)
                {
                    output += item.Key + ": " + item.Value.ToString() + ", ";
                }

                var result = AppDomainManager.RunAlgorithm(list);

                var fitness = CalculateFitness(result);

                output += string.Format("{0}: {1}", this.Name, fitness.Value);
                Program.Output(output);

                return(fitness.Fitness);
            }
            catch (Exception ex)
            {
                //todo: log
                return(0);
            }
        }
        public static void Main(string[] args)
        {
            _config = LoadConfig(args);
            File.Copy(_config.ConfigPath, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"), true);

            var path = _config.AlgorithmLocation;

            if (!string.IsNullOrEmpty(path))
            {
                File.Copy(path, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(path)), true);
                var pdb = path.Replace(Path.GetExtension(path), ".pdb");
                if (File.Exists(pdb))
                {
                    File.Copy(pdb, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(pdb)), true);
                }
            }

            AppDomainManager.Initialize(_config);

            var instance = (OptimizerFitness)Assembly.GetExecutingAssembly().CreateInstance(_config.FitnessTypeName,
                                                                                            false, BindingFlags.Default, null,
                                                                                            new[] { _config }, null, null);

            var manager = new GeneManager(_config, instance);

            manager.Start();

            Console.ReadKey();
        }
示例#3
0
        public Dictionary <string, string> Run(Dictionary <string, object> items)
        {
            string plain = string.Join(",", items.Select(s => s.Value));

            Dictionary <string, Dictionary <string, string> > results = AppDomainManager.GetResults(AppDomain.CurrentDomain);

            _config = AppDomainManager.GetConfig(AppDomain.CurrentDomain);

            if (results.ContainsKey(plain))
            {
                return(results[plain]);
            }

            foreach (var pair in items)
            {
                Config.Set(pair.Key, pair.Value.ToString());
            }

            LaunchLean();

            results.Add(plain, _resultsHandler.FinalStatistics);
            AppDomainManager.SetResults(AppDomain.CurrentDomain, results);

            return(_resultsHandler.FinalStatistics);
        }
示例#4
0
        public static void Main(string[] args)
        {
            _config = LoadConfig(args);
            string path = _config.ConfigPath;

            System.IO.File.Copy(path, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json"), true);

            path = _config.AlgorithmLocation;
            if (!string.IsNullOrEmpty(path))
            {
                System.IO.File.Copy(path, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(path)), true);
                string pdb = path.Replace(Path.GetExtension(path), ".pdb");
                if (File.Exists(pdb))
                {
                    System.IO.File.Copy(pdb, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(pdb)), true);
                }
            }

            _writerLock = new object();

            using (_writer = System.IO.File.AppendText("optimizer.txt"))
            {
                AppDomainManager.Initialize(_config);

                OptimizerFitness instance = (OptimizerFitness)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(_config.FitnessTypeName, false, BindingFlags.Default, null,
                                                                                                                               new[] { _config }, null, null);

                var manager = new GeneticManager(_config, instance, new LogManager());
                manager.Start();
            }

            Console.ReadKey();
        }