static void Main(string[] args) { var tspData = LoadCsv("Berlin52.csv"); var initData = new TSPInitData(tspData); var optimizer = Optimizer.Create(); optimizer.Settings.WithSeed(Environment.TickCount); optimizer.Settings.AddSubProblem("TSP", new TravelingSalesman(tspData.Count)); optimizer.Settings.WithEntityType <TSPEntity>().WithEvaluation <TSPEvaluation>(); optimizer.SetParameter("TestParameter", 42.0); var fitnessLimit = new MultiObjectiveFitness(new double[] { -7545 }); optimizer.Settings.StopWhen().FitnessLimitExceeded(fitnessLimit) .Or().TimeoutElapsed(300000); optimizer.SetParameter(Pea.Core.Island.ParameterNames.IslandsCount, 10); Stopwatch sw = Stopwatch.StartNew(); var result = optimizer.Run(initData); //var result = AsyncUtil.RunSync(() => system.Start(initData)); foreach (var reason in result.StopReasons) { Console.WriteLine(reason); } sw.Stop(); var elapsed = sw.ElapsedMilliseconds; var entities = TSPEvaluation.EntityCount; var speed = entities / elapsed; Console.WriteLine($"Elapsed: {elapsed} Entities: {entities} ({speed} ent./ms)"); Console.ReadLine(); }
static void Main(string[] args) { var tripList = TripLoader.LoadTrips(@"Data/Trips_Szeged.csv"); var distances = DistanceLoader.LoadDistances(@"Data/Distances_Szeged.csv"); var initData = new VSInitData(tripList, distances); var optimizer = Optimizer.Create(); optimizer.Settings.AddSubProblem("VehicleScheduling", new VehicleScheduling(tripList.Count)) .AddConflictDetector <VSConflictDetector>(); optimizer.Settings.WithEntityType <VehicleSchedulingEntity>() .WithEvaluation <VSEvaluation>(); //TODO: WithCreator optimizer.Settings.StopWhen().TimeoutElapsed(120 * 1000); optimizer.SetParameter(ParameterNames.IslandsCount, 10); //system.Settings.Random = typeof(FastRandom); //-> PeaSettings //Evaluation = new VSEvaluation(); //Evaluation.Init(initData); //var creator = new VSEntityCreator(); //creator.Init(initData); //var conflictDetector = new VSConflictDetector(); //conflictDetector.Init(initData); //Chromosome.Implementation.SortedSubset.SortedSubsetChromosomeValidator.ConflictDetector = conflictDetector; //var islandEngine = Island.IslandEngineFactory.Create(system.Settings.Build()); ////islandEngine.EntityCreators.Add(creator, 1); //var algorithmFactory = new Algorithm.SteadyState(); //var algorithm = algorithmFactory.GetAlgorithm(islandEngine); //islandEngine.Algorithm = algorithm; Stopwatch sw = Stopwatch.StartNew(); var result = optimizer.Run(initData); //var result = AsyncUtil.RunSync(() => system.Start(initData)); foreach (var reason in result.StopReasons) { Console.WriteLine(reason); } //try //{ // initData.Build(); // islandEngine.InitConflictDetectors(initData); // algorithm.InitPopulation(); // var c = 0; // while (true) // { // algorithm.RunOnce(); // var stopDecision = islandEngine.StopCriteria.MakeDecision(islandEngine, algorithm.Population); // if (stopDecision.MustStop) // { // Console.WriteLine(stopDecision.Reasons[0]); // break; // } // c++; // } //} //catch (ApplicationException ex) //{ // Console.WriteLine(ex.Message); //} sw.Stop(); var elapsed = sw.ElapsedMilliseconds; var entities = VSEvaluation.EntityCount; var speed = entities / (double)elapsed; Console.WriteLine($"Elapsed: {elapsed} Entities: {entities} ({speed} ent./ms)"); //ResultWriter.WriteResults("VehicleSchedulingResults", algorithm.Population.Bests); Console.ReadLine(); }