Skip to content

Commit f9c504d

Browse files
committed
Merge branch 'release/2.2.3'
2 parents ac17144 + 9825fd0 commit f9c504d

20 files changed

+296
-40
lines changed

.gitignore

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2-
[Bb]in/
2+
33
[Oo]bj/
44

55
# mstest test results
@@ -88,7 +88,6 @@ csx
8888
AppPackages/
8989

9090
# Others
91-
[Bb]in
9291
[Oo]bj
9392
sql
9493
TestResults
@@ -118,14 +117,6 @@ opencoverCoverage.xml
118117
*.nupkg
119118
stylecop-report.violations.xml
120119
stylecop-report.xml
121-
src/GeneticSharp.Extensions/ExpressionTree/ExpressionTreeChromosome.cs
122-
src/GeneticSharp.Extensions/Hangman/HangmanChromosome.cs
123-
src/GeneticSharp.Extensions/Hangman/HangmanEnglishFitness.cs
124-
src/GeneticSharp.Extensions/Numberlink/NumberlinkChromosome.cs
125-
src/GeneticSharp.Extensions/Numberlink/NumberlinkFitness.cs
126-
src/GeneticSharp.Extensions/Numberlink/NumberlinkSquare.cs
127-
src/GeneticSharp.Runner.ConsoleApp/Samples/HangmanSampleController.cs
128-
src/GeneticSharp.Runner.GtkApp/Samples/NumberlinkSampleController.cs
129120
dupFinder-report.xml
130121
Issue9Sample.sln.GhostDoc.xml
131122
/build

src/GeneticSharp.Domain.UnitTests/Chromosomes/BinaryChromosomeBaseTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace GeneticSharp.Domain.UnitTests.Chromosomes
99
public class BinaryChromosomeBaseTest
1010
{
1111
[Test]
12-
public void FlipBit_Index_ValueFlip()
12+
public void FlipGene_Index_ValueFlip()
1313
{
1414
var target = new BinaryChromosomeStub (2);
1515
target.ReplaceGenes (0, new Gene[] {

src/GeneticSharp.Domain.UnitTests/Chromosomes/FloatingPointChromosomeTest.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ public void Constructor_FromZeroToZero_Double()
8383

8484
Assert.AreEqual(0, actual);
8585
}
86-
}
86+
87+
[Test]
88+
public void FlipGene_Index_ValueFlip()
89+
{
90+
RandomizationProvider.Current = Substitute.For<IRandomization>();
91+
RandomizationProvider.Current.GetDouble(0, 0).Returns(0);
92+
var target = new FloatingPointChromosome(0, 0, 2);
93+
94+
target.FlipGene(0);
95+
Assert.AreEqual("10000000000000000000000000000000", target.ToString());
96+
97+
target.FlipGene(1);
98+
Assert.AreEqual("11000000000000000000000000000000", target.ToString());
99+
100+
target.FlipGene(31);
101+
Assert.AreEqual("11000000000000000000000000000001", target.ToString());
102+
103+
target.FlipGene(30);
104+
Assert.AreEqual("11000000000000000000000000000011", target.ToString());
105+
}
106+
}
87107
}
88108

src/GeneticSharp.Domain.UnitTests/Chromosomes/IntegerChromosomeTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ public void CreateNew_NoArgs_NewInstance()
4949
var actual = target.ToInteger();
5050
Assert.AreEqual(-2, actual);
5151
}
52+
53+
[Test]
54+
public void FlipGene_Index_ValueFlip()
55+
{
56+
RandomizationProvider.Current = Substitute.For<IRandomization>();
57+
RandomizationProvider.Current.GetInt(0, 3).Returns(-2);
58+
59+
var target = new IntegerChromosome(0, 3);
60+
Assert.AreEqual("11111111111111111111111111111110", target.ToString());
61+
62+
target.FlipGene(0);
63+
Assert.AreEqual("01111111111111111111111111111110", target.ToString());
64+
65+
target.FlipGene(1);
66+
Assert.AreEqual("00111111111111111111111111111110", target.ToString());
67+
68+
target.FlipGene(10);
69+
Assert.AreEqual("00111111110111111111111111111110", target.ToString());
70+
71+
target.FlipGene(31);
72+
Assert.AreEqual("00111111110111111111111111111111", target.ToString());
73+
74+
target.FlipGene(30);
75+
Assert.AreEqual("00111111110111111111111111111101", target.ToString());
76+
}
5277
}
5378
}
5479

src/GeneticSharp.Domain/Chromosomes/BinaryChromosomeBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected BinaryChromosomeBase(int length)
2727
/// <remarks>>
2828
/// If gene's value is 0, the it will be flip to 1 and vice-versa.</remarks>
2929
/// <param name="index">The gene index.</param>
30-
public void FlipGene (int index)
30+
public virtual void FlipGene (int index)
3131
{
3232
var value = (int) GetGene (index).Value;
3333

src/GeneticSharp.Domain/Chromosomes/IntegerChromosome.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public IntegerChromosome(int minValue, int maxValue) : base(32)
2929
CreateGenes();
3030
}
3131

32-
#region implemented abstract members of ChromosomeBase
3332
/// <summary>
3433
/// Generates the gene.
3534
/// </summary>
@@ -51,8 +50,6 @@ public override IChromosome CreateNew()
5150
return new IntegerChromosome(m_minValue, m_maxValue);
5251
}
5352

54-
#endregion
55-
5653
/// <summary>
5754
/// Converts the chromosome to its integer representation.
5855
/// </summary>
@@ -75,6 +72,20 @@ public override string ToString()
7572
{
7673
return String.Join("", GetGenes().Reverse().Select(g => (bool) g.Value ? "1" : "0").ToArray());
7774
}
75+
76+
/// <summary>
77+
/// Flips the gene.
78+
/// </summary>
79+
/// <remarks>>
80+
/// If gene's value is 0, the it will be flip to 1 and vice-versa.</remarks>
81+
/// <param name="index">The gene index.</param>
82+
public override void FlipGene(int index)
83+
{
84+
var realIndex = Math.Abs(31 - index);
85+
var value = (bool)GetGene(realIndex).Value;
86+
87+
ReplaceGene(realIndex, new Gene(!value));
88+
}
7889
}
7990
}
8091

src/GeneticSharp.Domain/Crossovers/PartiallyMappedCrossover.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace GeneticSharp.Domain.Crossovers
1313
/// The partially-mapped crossover operator was suggested by Gold- berg and Lingle (1985).
1414
/// It passes on ordering and value information from the parent tours to the offspring tours.
1515
/// A portion of one parent’s string is mapped onto a portion of the other parent’s string and the remaining information is exchanged.
16-
/// <see href="http://lev4projdissertation.googlecode.com/svn-history/r100/trunk/reading/read/aiRev99.pdf">Genetic Algorithms for the Travelling Salesman Problem - A Review of Representations and Operators</see>
16+
/// <see href="http://www.dca.fee.unicamp.br/~gomide/courses/EA072/artigos/Genetic_Algorithm_TSPR_eview_Larranaga_1999.pdf">Genetic Algorithms for the Travelling Salesman Problem - A Review of Representations and Operators</see>
1717
/// </remarks>
1818
/// </summary>
1919
[DisplayName("Partially Mapped (PMX)")]
@@ -44,26 +44,26 @@ protected override IList<IChromosome> PerformCross(IList<IChromosome> parents)
4444
throw new CrossoverException(this, "The Partially Mapped Crossover (PMX) can be only used with ordered chromosomes. The specified chromosome has repeated genes.");
4545
}
4646

47-
// Chosse the thow parents.
47+
// Choose the thow parents.
4848
var parent1 = parents[0];
4949
var parent2 = parents[1];
5050

5151
// Create, sort and define the cut point indexes.
5252
var cutPointsIndexes = RandomizationProvider.Current.GetUniqueInts(2, 0, parent1.Length);
5353
Array.Sort(cutPointsIndexes);
5454
var firstCutPointIndex = cutPointsIndexes[0];
55-
var secondCutPointIdnex = cutPointsIndexes[1];
55+
var secondCutPointIndex = cutPointsIndexes[1];
5656

5757
// Parent1 creates the mapping section.
5858
var parent1Genes = parent1.GetGenes();
59-
var parent1MappingSection = parent1Genes.Skip(firstCutPointIndex).Take((secondCutPointIdnex - firstCutPointIndex) + 1).ToArray();
59+
var parent1MappingSection = parent1Genes.Skip(firstCutPointIndex).Take((secondCutPointIndex - firstCutPointIndex) + 1).ToArray();
6060

6161
// Parent12 creates the mapping section.
6262
var parent2Genes = parent2.GetGenes();
63-
var parent2MappingSection = parent2Genes.Skip(firstCutPointIndex).Take((secondCutPointIdnex - firstCutPointIndex) + 1).ToArray();
63+
var parent2MappingSection = parent2Genes.Skip(firstCutPointIndex).Take((secondCutPointIndex - firstCutPointIndex) + 1).ToArray();
6464

6565
// The new offsprings are created and
66-
// their genes ar replaced starat in the first cut point index
66+
// their genes ar replaced start in the first cut point index
6767
// and using the genes in the mapping section from parent 1 e 2.
6868
var offspring1 = parent1.CreateNew();
6969
var offspring2 = parent2.CreateNew();
@@ -75,16 +75,16 @@ protected override IList<IChromosome> PerformCross(IList<IChromosome> parents)
7575

7676
for (int i = 0; i < length; i++)
7777
{
78-
if (i >= firstCutPointIndex && i <= secondCutPointIdnex)
78+
if (i >= firstCutPointIndex && i <= secondCutPointIndex)
7979
{
8080
continue;
8181
}
8282

83-
var geneForUffspring1 = GetGeneNotInMappingSection(parent1Genes[i], parent2MappingSection, parent1MappingSection);
84-
offspring1.ReplaceGene(i, geneForUffspring1);
83+
var geneForOffspring1 = GetGeneNotInMappingSection(parent1Genes[i], parent2MappingSection, parent1MappingSection);
84+
offspring1.ReplaceGene(i, geneForOffspring1);
8585

86-
var geneForoffspring2 = GetGeneNotInMappingSection(parent2Genes[i], parent1MappingSection, parent2MappingSection);
87-
offspring2.ReplaceGene(i, geneForoffspring2);
86+
var geneForOffspring2 = GetGeneNotInMappingSection(parent2Genes[i], parent1MappingSection, parent2MappingSection);
87+
offspring2.ReplaceGene(i, geneForOffspring2);
8888
}
8989

9090
return new List<IChromosome>() { offspring1, offspring2 };
3 KB
Binary file not shown.
Binary file not shown.
512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)