private GeneticAlgorithm CreateGaVrpSample()
        {
            GeneticAlgorithm ga = new GeneticAlgorithm();

            #region Problem Configuration
            VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();

            SolomonFormatInstanceProvider instanceProvider = new SolomonInstanceProvider();
            CVRPTWData data = instanceProvider.Import(@"Test Resources\C101.txt", @"Test Resources\C101.opt.txt") as CVRPTWData;
            vrpProblem.Load(data);
            vrpProblem.Name        = "C101 VRP (imported from Solomon)";
            vrpProblem.Description = "Represents a Vehicle Routing Problem.";
            CVRPTWProblemInstance instance = vrpProblem.ProblemInstance as CVRPTWProblemInstance;
            instance.DistanceFactor.Value   = 1;
            instance.FleetUsageFactor.Value = 100;
            instance.OverloadPenalty.Value  = 100;
            instance.TardinessPenalty.Value = 100;
            instance.TimeFactor.Value       = 0;
            vrpProblem.MaximizationParameter.Value.Value = false;
            instance.UseDistanceMatrix.Value             = true;
            instance.Vehicles.Value = 25;
            #endregion
            #region Algorithm Configuration
            ga.Name        = "Genetic Algorithm - VRP";
            ga.Description = "A genetic algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)";
            ga.Problem     = vrpProblem;
            SamplesUtils.ConfigureGeneticAlgorithmParameters <TournamentSelector, MultiVRPSolutionCrossover, MultiVRPSolutionManipulator>(
                ga, 100, 1, 1000, 0.05, 3);

            var xOver = (MultiVRPSolutionCrossover)ga.Crossover;
            foreach (var op in xOver.Operators)
            {
                xOver.Operators.SetItemCheckedState(op, false);
            }
            xOver.Operators.SetItemCheckedState(xOver.Operators
                                                .OfType <PotvinRouteBasedCrossover>()
                                                .Single(), true);
            xOver.Operators.SetItemCheckedState(xOver.Operators
                                                .OfType <PotvinSequenceBasedCrossover>()
                                                .Single(), true);

            var manipulator = (MultiVRPSolutionManipulator)ga.Mutator;
            foreach (var op in manipulator.Operators)
            {
                manipulator.Operators.SetItemCheckedState(op, false);
            }
            manipulator.Operators.SetItemCheckedState(manipulator.Operators
                                                      .OfType <PotvinOneLevelExchangeMainpulator>()
                                                      .Single(), true);
            manipulator.Operators.SetItemCheckedState(manipulator.Operators
                                                      .OfType <PotvinTwoLevelExchangeManipulator>()
                                                      .Single(), true);
            #endregion

            return(ga);
        }
Exemple #2
0
        private ScatterSearch CreateScatterSearchVRPSample()
        {
            #region Problem Configuration
            var provider = new SolomonInstanceProvider();
            var instance = provider.GetDataDescriptors().Single(x => x.Name == "C101");
            VehicleRoutingProblem vrpProblem = new VehicleRoutingProblem();
            vrpProblem.Load(provider.LoadData(instance));
            #endregion

            #region Algorithm Configuration
            ScatterSearch ss = new ScatterSearch();
            ss.Engine      = new SequentialEngine.SequentialEngine();
            ss.Name        = "Scatter Search - VRP";
            ss.Description = "A scatter search algorithm which solves the \"C101\" vehicle routing problem (imported from Solomon)";
            ss.Problem     = vrpProblem;

            var improver = ss.Problem.Operators.OfType <VRPIntraRouteImprovementOperator>().First();
            improver.ImprovementAttemptsParameter.Value.Value = 15;
            improver.SampleSizeParameter.Value.Value          = 10;
            ss.Improver = improver;

            var pathRelinker = ss.Problem.Operators.OfType <VRPPathRelinker>().First();
            pathRelinker.IterationsParameter.Value.Value = 25;
            ss.PathRelinker = pathRelinker;

            var similarityCalculator = ss.SimilarityCalculatorParameter.ValidValues.OfType <VRPSimilarityCalculator>().First();
            ss.SimilarityCalculator = similarityCalculator;

            ss.MaximumIterations.Value = 2;
            ss.PopulationSize.Value    = 20;
            ss.ReferenceSetSize.Value  = 10;
            ss.Seed.Value = 0;
            return(ss);

            #endregion
        }