Exemplo n.º 1
0
        public Solution Decode(EncodedSolution encodedSolution)
        {
            var orderedRandomKeys = encodedSolution.GetOrderedRandomKeys();

            var problem = Provider.GetFreshProblem();

            var keyIndex = 0;
            var vehicle = problem.VehicleFleet.Vehicles[0];
            while (keyIndex < orderedRandomKeys.Count)
            {
                var currentDestination = problem.Map.Destinations[orderedRandomKeys[keyIndex].Position];
                vehicle = GetNextAvailableVehicleFor(problem, currentDestination, vehicle.Number);
                if(vehicle == null)
                    break;

                vehicle.Route.AddDestination(currentDestination);
                keyIndex++;
            }

            return problem;
        }
Exemplo n.º 2
0
        private EncodedSolution Mate(EncodedSolution eliteParent, EncodedSolution nonEliteParent)
        {
            var child = new EncodedSolution(eliteParent.ProblemDecoder, new List<RandomKey>());

            for (var index = 0; index < eliteParent.RandomKeys.Count; index ++)
                child.RandomKeys.Insert(index, TakeOne(eliteParent.RandomKeys[index].Key, nonEliteParent.RandomKeys[index].Key, index));

            return child;
        }
Exemplo n.º 3
0
        public Population Generate()
        {
            var population = new Population();

            var randomGenerator = new Random();
            for (var index = 0; index < PopulationSize; index++)
            {
                EncodedSolution encodedSolution;
                do
                {
                    var randomVector = GenerateRandomVector(AmountOfDestinations, randomGenerator.Next());
                    encodedSolution = new EncodedSolution(ProblemDecoder, randomVector);
                } while (population.EncodedProblems.Any(ep => ep.IsEquivalenteTo(encodedSolution)));

                population.EncodedProblems.Add(encodedSolution);
            }

            return population;
        }
Exemplo n.º 4
0
 public bool IsEquivalenteTo(EncodedSolution encodedSolution)
 {
     return GetPseudoHash() == encodedSolution.GetPseudoHash();
 }