public void SortedSubsetOperatorBase_CleanOutSections_DeleteSectionsWith0Length(int sectionIndex1, int sectionIndex2) { var originalChromosome = SortedSubsetTestData.CreateChromosome(); var sections = new int[originalChromosome.Sections.Length + 2][]; var sourceIndex = 0; for (int targetIndex = 0; targetIndex < sections.Length; targetIndex++) { if (targetIndex != sectionIndex1 && targetIndex != sectionIndex2) { sections[targetIndex] = originalChromosome.Sections[sourceIndex]; sourceIndex++; } else { sections[targetIndex] = new int[0]; } } var testChromosome = new SortedSubsetChromosome(sections); var random = Substitute.For <IRandom>(); var parameterSet = new ParameterSet(); var conflictDetectors = new List <INeighborhoodConflictDetector>() { AllRightConflictDetector.Instance }; var operatorBase = new SortedSubsetOperatorBase(random, parameterSet, conflictDetectors); operatorBase.CleanOutSections(testChromosome); testChromosome.Sections.Should().BeEquivalentTo(originalChromosome.Sections); }
public IEntity CreateEntity() { IRandom random = new FastRandom(DateTime.Now.Millisecond); List <List <int> > indices = new List <List <int> >(); for (int i = 0; i < InitData.Trips.Length; i++) { int targetIndex; targetIndex = ChooseTarget(random, indices, i); if (targetIndex == indices.Count) { indices.Add(new List <int>()); } indices[targetIndex].Add(i); } int[][] geneSections = CreateSectionsFromList(indices); var chromosome = new SortedSubsetChromosome(geneSections); var entity = new VehicleSchedulingEntity(); entity.Chromosomes.Add(Key, chromosome); return(entity); }
public void GivenSortedSubsetChromosome_WhenDeepClone_ThenShouldBeEquivalent() { var chromosome = new SortedSubsetChromosome(new int[][] { new int[] { 1, 2 }, new int[] { 3, 4, 5 } }); var clone = chromosome.DeepClone(); clone.Sections.Should().BeEquivalentTo(chromosome.Sections); }
public static SortedSubsetChromosome CreateChromosome() { var section1 = new int[] { 1, 4, 5, 7 }; var section2 = new int[] { 3, 6, 8 }; var section3 = new int[] { 2, 9 }; var sections = new int[][] { section1, section2, section3 }; var chromosome = new SortedSubsetChromosome(sections); return(chromosome); }
public void GivenChromosome_WithOneSection_WhenReplaceOneGene_ThenShouldReturnNull() { var random = new SystemRandom(Environment.TickCount); var parameterSet = new ParameterSet(); var chromosome = new SortedSubsetChromosome(new List <ICollection <int> >() { new int[] { 1, 2, 3, 4, 5, 6 } }); var conflictDetectors = new List <INeighborhoodConflictDetector>() { AllRightConflictDetector.Instance }; var mutation = new ReplaceOneGeneMutation(random, parameterSet, conflictDetectors); var result = mutation.Mutate(chromosome); result.Should().BeNull(); }