Example #1
0
        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();
        }
Example #2
0
 public void Init(IEvaluationInitData initData)
 {
     InitData = (VSInitData)initData;
     InitData.Build();
 }