Пример #1
0
        public override void Run(IGene[] genes)
        {
            int index1, index2, customerCount = genes.Count();

            RandomGeneratorThreadSafe.NextTwoDifferentInts(customerCount, out index1, out index2);
            Swap(genes, index1, index2);
        }
Пример #2
0
        public override void Run(IGene[] genes)
        {
            int indexOfElement, indexOfDestination;

            RandomGeneratorThreadSafe.NextTwoDifferentInts(genes.Length, out indexOfElement, out indexOfDestination);
            Insert(genes, indexOfElement, indexOfDestination);
        }
Пример #3
0
        public override void Run(ref Chromosome solution)
        {
            int indexOfElement, indexOfDestination;

            RandomGeneratorThreadSafe.NextTwoDifferentInts(solution.Genes.Length, out indexOfElement, out indexOfDestination);
            Insert(solution.Genes, indexOfElement, indexOfDestination);
            solution.Refresh();
        }
Пример #4
0
        /// <summary>
        /// Runs the swap operator.
        /// </summary>
        /// <param name="solution">The referenced solution for a change.</param>
        public override void Run(ref Chromosome solution)
        {
            var genes = solution.Genes;
            int index1, index2, customerCount = genes.Count();

            RandomGeneratorThreadSafe.NextTwoDifferentInts(customerCount, out index1, out index2);
            Swap(genes, index1, index2);
            solution.Refresh();
        }
        public override void Run(IGene[] genes)
        {
            int startIndex, destIndex, length;

            RandomGeneratorThreadSafe.NextTwoDifferentInts(genes.Length - 1, out startIndex, out destIndex);
            int upperLimit = startIndex > destIndex ? startIndex : destIndex;

            length = RandomGeneratorThreadSafe.NextInt(1, genes.Length - upperLimit + 1);
            Displace(genes, startIndex, destIndex, length);
        }
        public override void Run(ref Chromosome solution)
        {
            int startIndex, destIndex, length;

            RandomGeneratorThreadSafe.NextTwoDifferentInts(solution.Genes.Length - 1, out startIndex, out destIndex);
            int upperLimit = startIndex > destIndex ? startIndex : destIndex;

            length = RandomGeneratorThreadSafe.NextInt(1, solution.Genes.Length - upperLimit + 1);
            Displace(solution.Genes, startIndex, destIndex, length);
            solution.Refresh();
        }
        public override Chromosome RandomNeighbourSolution(Chromosome chromosome)
        {
            IGene[]    newGenes;
            Chromosome newSolution, newChromosome;

            newChromosome = (Chromosome)chromosome.Clone();
            newGenes      = newChromosome.Genes;
            int position1, position2;

            RandomGeneratorThreadSafe.NextTwoDifferentInts(chromosome.Size(), out position1, out position2);
            IGene swappedGene1 = newGenes[position1];
            IGene swappedGene2 = newGenes[position2];

            newGenes[position1] = swappedGene2;
            newGenes[position2] = swappedGene1;
            newSolution         = new Solution((VrptwProblem)chromosome.Problem, newGenes);
            return(newSolution);
        }