Ejemplo n.º 1
0
        private static void checkHugeProblem()
        {
            var hugeProblem = new TspEvaluation(@"C:\Users\jbelter\source\repos\machine-learning-cvrp\data\M-n200-k16.vrp");
            List <TspEvaluation> problem = new List <TspEvaluation>();

            problem.Add(hugeProblem);
            //TestRandom(problem);
            //TestGreedy(problem);
            TestGA(hugeProblem, .8, .4, 200, 500, 20);
        }
Ejemplo n.º 2
0
 public TspGreedy(TspEvaluation evaluation, AStopCondition stopCondition, int start)
     : base(evaluation, stopCondition)
 {
     if (start < evaluation.iSize)
     {
         startPosition = start;
     }
     else
     {
         throw new Exception("incorrect starting position");
     }
 }
Ejemplo n.º 3
0
        private static void TestCrossoverVsMutation()
        {
            List <double> b          = new List <double>();
            List <double> w          = new List <double>();
            List <double> a          = new List <double>();
            var           evaluation = new TspEvaluation(@"C:\Users\jbelter\source\repos\machine-learning-cvrp\data\A-n46-k7.vrp");

            double[] px = { 0, .1, .8, 1, 0, 0, 0 };
            double[] pw = { 0, 0, 0, 0, .2, .5, 1 };
            for (int j = 0; j < 7; j++)
            {
                for (int i = 0; i < 20; i++)
                {
                    var stopCondition = new IterationsStopCondition(200);
                    //var optimizer = new TspRandomSearch(evaluation, stopCondition);
                    var        generator = new TspGenerator(new Random());
                    ASelection selection = new TournamentSelection(Convert.ToInt32(5));

                    var crossover = new OrderedCrossover(px[j]);
                    var mutation  = new SwapMutation(pw[j]);
                    var optimizer = new GeneticAlgorithm <int>(evaluation, stopCondition, generator, selection, crossover, mutation, 100);

                    optimizer.Run();

                    b.Add(optimizer.bestSolutions.Last());
                    w.Add(optimizer.worstValues.Last());
                    a.Add(optimizer.averageValues.Last());
                }
                double avgB = 0.0, avgA = 0.0, avgW = 0.0;
                for (int i = 0; i < b.Count; i++)
                {
                    avgB += b[i];
                    avgA += a[i];
                    avgW += w[i];
                }

                avgB /= b.Count;
                avgA /= b.Count;
                avgW /= b.Count;

                Console.WriteLine("avg(best value): " + avgB.ToString() +
                                  " avg(average value): " + avgA.ToString() +
                                  " avg(worst value): " + avgW.ToString());
            }
        }
 public TspRandomSearch(TspEvaluation evaluation, AStopCondition stopCondition)
     : base(evaluation, stopCondition, new TspGenerator(new Random()))
 {
 }