Skip to content

Commit 33304a5

Browse files
committed
Merge branch 'release/v2.4.0'
2 parents f9c504d + 002b5cd commit 33304a5

39 files changed

+1260
-140
lines changed

README.md

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,21 @@ Can be used in any kind of .NET Core and .NET Framework apps, like ASP .NET MVC,
4747
Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain/Fitnesses/IFitness.cs) interface.
4848

4949
### [Populations](src/GeneticSharp.Domain/Populations)
50+
- [Population](src/GeneticSharp.Domain/Populations/Population.cs)
51+
- [TplPopulation](src/GeneticSharp.Domain/Populations/TplPopulation.cs)
52+
- Others populations can be added implementing [IPopulation](src/GeneticSharp.Domain/IPopulation) interface or extending [Population](src/GeneticSharp.Domain/Populations/Population.cs).
53+
54+
### [Generations](src/GeneticSharp.Domain/Populations/Generation.cs)
5055
- [Generation](src/GeneticSharp.Domain/Populations/Generation.cs)
5156
- [Generation strategy](src/GeneticSharp.Domain/Populations/IGenerationStrategy.cs)
5257
- [Performance strategy](src/GeneticSharp.Domain/Populations/PerformanceGenerationStrategy.cs)
5358
- [Tracking strategy](src/GeneticSharp.Domain/Populations/TrackingGenerationStrategy.cs)
59+
- Others generation strategies can be added implementing [IGenerationStrategy.cs](src/GeneticSharp.Domain/IGenerationStrategy.cs) interface.
60+
61+
### [Operators strategy](src/GeneticSharp.Domain/src/GeneticSharp.Domain/IOperatorsStrategy.cs)
62+
- [DefaultOperatorsStrategy](src/GeneticSharp.Domain/DefaultOperatorsStrategy.cs)
63+
- [TplOperatorsStrategy](src/GeneticSharp.Domain/TplOperatorsStrategy.cs)
64+
- Others operators strategies can be added implementing [IOperatorsStrategy](src/GeneticSharp.Domain/IOperatorsStrategy.cs) interface.
5465

5566
### [Selections](src/GeneticSharp.Domain/Selections)
5667
- [Elite](src/GeneticSharp.Domain/Selections/EliteSelection.cs) (also know as Truncate or Truncation)
@@ -60,6 +71,7 @@ Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain
6071
- Others selections can be added implementing [ISelection](src/GeneticSharp.Domain/Selections/ISelection.cs) interface or extending [SelectionBase](src/GeneticSharp.Domain/Selections/SelectionBase.cs).
6172

6273
### [Crossovers](src/GeneticSharp.Domain/Crossovers)
74+
- [Alternating-position (AP)](src/GeneticSharp.Domain/Crossovers/AlternatingPositionCrossover.cs)
6375
- [Cut and Splice](src/GeneticSharp.Domain/Crossovers/CutAndSpliceCrossover.cs)
6476
- [Cycle (CX)](src/GeneticSharp.Domain/Crossovers/CycleCrossover.cs)
6577
- [One-Point (C1)](src/GeneticSharp.Domain/Crossovers/OnePointCrossover.cs)
@@ -70,6 +82,7 @@ Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain
7082
- [Three parent](src/GeneticSharp.Domain/Crossovers/ThreeParentCrossover.cs)
7183
- [Two-Point (C2)](src/GeneticSharp.Domain/Crossovers/TwoPointCrossover.cs)
7284
- [Uniform](src/GeneticSharp.Domain/Crossovers/UniformCrossover.cs)
85+
- [Voting Recombination (VR)](src/GeneticSharp.Domain/Crossovers/VotingRecombinationCrossover.cs)
7386
- Others crossovers can be added implementing [ICrossover](src/GeneticSharp.Domain/Crossovers/ICrossover.cs) interface or extending [CrossoverBase](src/GeneticSharp.Domain/Crossovers/CrossoverBase.cs).
7487

7588
### [Mutations](src/GeneticSharp.Domain/Mutations)
@@ -102,28 +115,38 @@ Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain
102115
- [Fast random](src/GeneticSharp.Domain/Randomizations/FastRandomRandomization.cs)
103116
- If you need a special kind of randomization for your GA, just implement the [IRandomization](src/GeneticSharp.Domain/Randomizations/IRandomization.cs) interface.
104117

118+
### [Task executors](src/GeneticSharp.Infrastructure.Framework/Threading/ITaskExecutor.cs)
119+
- [LinearTaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/LinearTaskExecutor.cs)
120+
- [ParallelTaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/ParallelTaskExecutor.cs)
121+
- [TplTaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/TplTaskExecutor.cs)
122+
- Others task executors can be added implementing [ITaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/ITaskExecutor.cs) interface.
123+
105124
## Samples
106-
### [Console sample](src/GeneticSharp.Runner.ConsoleApp)
125+
### [Console samples](src/GeneticSharp.Runner.ConsoleApp)
107126
- AutoConfig
108127
- Bitmap equality
109128
- Equality equation
110129
- Equation solver
111130
- Function builder
131+
- Ghostwriter
132+
- TSP (Travelling Salesman Problem)
112133

113134
![](docs/gifs/GeneticSharp-ConsoleApp-EquationSolver-FunctionBuilder.gif)
114135

115-
- Ghostwriter
116-
- TSP (Travelling Salesman Problem)
117136

118-
### [GTK# sample](src/GeneticSharp.Runner.GtkApp)
137+
### [GTK# samples](src/GeneticSharp.Runner.GtkApp)
138+
- Bitmap equality
139+
- Function optimization
140+
- Sudoku
141+
- TSP (Travelling Salesman Problem)
119142

120-
#### TSP (Travelling Salesman Problem), Function optimization and Sudoku
121143
![](docs/gifs/GeneticSharp-GtkApp.gif)
122144

123-
#### Bitmap equality
124-
![](docs/gifs/GeneticSharp-BitmapEquality_sample01.gif)
125-
126145
### [Unity3D Samples](src/GeneticSharp.Runner.UnityApp)
146+
- Car2D
147+
- TSP (Travelling Salesman Problem)
148+
- Wall Builder
149+
127150
[![](docs/screenshots/GeneticSharp-UnityApp.png)](https://youtu.be/xXqNcgeOU_g)
128151
[![](docs/images/google-play-badge.png)](https://play.google.com/store/apps/details?id=br.com.diegogiacomelli.geneticsharprunnersunityapp)
129152

@@ -132,14 +155,10 @@ Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain
132155
- Mono, .NET Standard 2.0 and .NET Framework 4.6.2 support.
133156
- Fully tested on Windows and MacOS.
134157

135-
![](docs/screenshots/VisualStudioMacAndWin.png)
136-
137158
## Code quality
138159
- 100% unit test code coverage.
139-
- FxCop validated.
140-
- Code duplicated verification.
141-
- Good (and well used) design patterns.
142160
- 100% code documentation
161+
- [SonarCloud](https://sonarcloud.io/dashboard?id=GeneticSharp) validated.
143162

144163
--------
145164

@@ -170,6 +189,8 @@ install-package GeneticSharp -Version 1.2.0
170189
## Running samples
171190
If you want to run the console, GTK# and Unity samples, just fork this repository and follow the instruction from our [setup](https://github.com/giacomelli/GeneticSharp/wiki/setup) page wiki.
172191

192+
An easy way to run the Unity Samples, if you have a Android device, is download it from [Google Play](https://play.google.com/store/apps/details?id=br.com.diegogiacomelli.geneticsharprunnersunityapp).
193+
173194
## Usage
174195

175196
### Creating your own fitness evaluation
@@ -228,33 +249,6 @@ ga.Start();
228249

229250
Console.WriteLine("Best solution found has {0} fitness.", ga.BestChromosome.Fitness);
230251
```
231-
232-
--------
233-
234-
## Roadmap
235-
- Add new problems/classic sample
236-
- Checkers
237-
- Time series
238-
- Knapsack problem
239-
- Add new selections
240-
- Reward-based
241-
- Add new crossovers
242-
- Voting recombination
243-
- Alternating-position (AP)
244-
- Sequential Constructive (SCX)
245-
- Shuffle crossover
246-
- Precedence Preservative Crossover (PPX)
247-
- Add new mutations
248-
- Non-Uniform
249-
- Boundary
250-
- Gaussian
251-
- Add new terminations
252-
- Fitness convergence
253-
- Population convergence
254-
- Chromosome convergence
255-
- New samples
256-
- Xamarin runner app (sample)
257-
- Parallel populations (islands)
258252

259253
--------
260254

@@ -266,10 +260,10 @@ Having troubles?
266260
- Tutorials
267261
- [Function optimization with GeneticSharp](http://diegogiacomelli.com.br/function-optimization-with-geneticsharp/)
268262
- [TSP with GeneticSharp and Unity3D](http://diegogiacomelli.com.br/tsp-with-GeneticSharp-and-Unity3d/)
269-
- Ask on Twitter [@ogiacomelli](http://twitter.com/ogiacomelli).
270263
- Ask on [Stack Overflow](http://stackoverflow.com/questions/tagged/geneticsharp) using the tag [GeneticSharp](http://stackoverflow.com/questions/tagged/geneticsharp).
271-
272-
--------
264+
- Open an [issue](https://github.com/giacomelli/GeneticSharp/issues).
265+
266+
--------
273267

274268
## How to improve it?
275269

@@ -278,8 +272,8 @@ Create a fork of [GeneticSharp](https://github.com/giacomelli/GeneticSharp/fork)
278272
Did you change it? [Submit a pull request](https://github.com/giacomelli/GeneticSharp/pull/new/master).
279273

280274
## License
281-
Licensed under the The MIT License (MIT).
282-
In others words, you can use this library for developement any kind of software: open source, commercial, proprietary and alien.
275+
Licensed under the The [MIT License (MIT)](LICENSE).
276+
In others words, you can use this library for developement any kind of software: open source, commercial, proprietary, etc.
283277

284278
# Thanks to
285279
I would like to thanks to the guys from [SMASHINGLOGO (https://smashinglogo.com)](https://smashinglogo.com/) for the amazing GeneticSharp logo.

appveyor.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2.2.{build}
1+
version: 2.4.{build}
22
os: Visual Studio 2017
33
configuration: Release
44
environment:
@@ -15,11 +15,7 @@ assembly_info:
1515
assembly_informational_version: '{version}'
1616

1717
install:
18-
- cmd: choco install gtksharp
19-
20-
nuget:
21-
account_feed: true
22-
project_feed: true
18+
- cmd: choco install gtksharp
2319

2420
before_build:
2521
- cmd: dotnet --version
@@ -47,9 +43,9 @@ after_build:
4743
- cmd: >-
4844
mkdir .\src\nuget
4945
50-
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.2.0
46+
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.4.0
5147
52-
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.2.0
48+
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.4.0
5349
5450
test_script:
5551
- cmd: dotnet clean src/GeneticSharp.Domain.UnitTests
-137 KB
Binary file not shown.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
using System.Collections.Generic;
2+
using GeneticSharp.Domain.Chromosomes;
3+
using GeneticSharp.Domain.Crossovers;
4+
using GeneticSharp.Domain.Randomizations;
5+
using NUnit.Framework;
6+
using NSubstitute;
7+
using System;
8+
using GeneticSharp.Domain.Populations;
9+
using GeneticSharp.Domain.Fitnesses;
10+
using System.Linq;
11+
using GeneticSharp.Domain.Selections;
12+
using GeneticSharp.Domain.Mutations;
13+
using GeneticSharp.Domain.Terminations;
14+
using System.Diagnostics;
15+
using GeneticSharp.Extensions.Tsp;
16+
17+
namespace GeneticSharp.Domain.UnitTests.Crossovers
18+
{
19+
[TestFixture]
20+
[Category("Crossovers")]
21+
public class AlternatingPositionCrossoverTest
22+
{
23+
[TearDown]
24+
public void Cleanup()
25+
{
26+
RandomizationProvider.Current = new BasicRandomization();
27+
}
28+
29+
[Test]
30+
public void Cross_ParentWithNoOrderedGenes_Exception()
31+
{
32+
var target = new AlternatingPositionCrossover();
33+
34+
var chromosome1 = Substitute.For<ChromosomeBase>(8);
35+
chromosome1.ReplaceGenes(0, new Gene[] {
36+
new Gene(8),
37+
new Gene(2),
38+
new Gene(3),
39+
new Gene(4),
40+
new Gene(6),
41+
new Gene(5),
42+
new Gene(7),
43+
new Gene(1)
44+
});
45+
46+
// 3 7 5 1 6 8 2 4
47+
var chromosome2 = Substitute.For<ChromosomeBase>(8);
48+
chromosome2.ReplaceGenes(0, new Gene[] {
49+
new Gene(1),
50+
new Gene(2),
51+
new Gene(3),
52+
new Gene(4),
53+
new Gene(5),
54+
new Gene(5),
55+
new Gene(6),
56+
new Gene(7)
57+
});
58+
59+
Assert.Catch<CrossoverException>(() =>
60+
{
61+
target.Cross(new List<IChromosome>() { chromosome1, chromosome2 });
62+
}, "The Alternating-position (AP) can be only used with ordered chromosomes. The specified chromosome has repeated genes.");
63+
}
64+
65+
[Test]
66+
public void Cross_DocumentationSample_Child()
67+
{
68+
var target = new AlternatingPositionCrossover();
69+
70+
// 1 2 3 4 5 6 7 8
71+
var chromosome1 = Substitute.For<ChromosomeBase>(8);
72+
chromosome1.ReplaceGenes(0, new Gene[] {
73+
new Gene(1),
74+
new Gene(2),
75+
new Gene(3),
76+
new Gene(4),
77+
new Gene(5),
78+
new Gene(6),
79+
new Gene(7),
80+
new Gene(8)
81+
});
82+
83+
var child1 = Substitute.For<ChromosomeBase>(8);
84+
chromosome1.CreateNew().Returns(child1);
85+
86+
// 3 7 5 1 6 8 2 4
87+
var chromosome2 = Substitute.For<ChromosomeBase>(8);
88+
chromosome2.ReplaceGenes(0, new Gene[] {
89+
new Gene(3),
90+
new Gene(7),
91+
new Gene(5),
92+
new Gene(1),
93+
new Gene(6),
94+
new Gene(8),
95+
new Gene(2),
96+
new Gene(4)
97+
});
98+
var child2 = Substitute.For<ChromosomeBase>(8);
99+
chromosome2.CreateNew().Returns(child2);
100+
101+
var actual = target.Cross(new List<IChromosome>() { chromosome1, chromosome2 });
102+
103+
Assert.AreEqual(2, actual.Count);
104+
105+
// 1 3 2 7 5 4 6 8
106+
var actualChild = actual[0];
107+
Assert.AreEqual(8, actualChild.Length);
108+
109+
Assert.AreEqual(1, actualChild.GetGene(0).Value);
110+
Assert.AreEqual(3, actualChild.GetGene(1).Value);
111+
Assert.AreEqual(2, actualChild.GetGene(2).Value);
112+
Assert.AreEqual(7, actualChild.GetGene(3).Value);
113+
Assert.AreEqual(5, actualChild.GetGene(4).Value);
114+
Assert.AreEqual(4, actualChild.GetGene(5).Value);
115+
Assert.AreEqual(6, actualChild.GetGene(6).Value);
116+
Assert.AreEqual(8, actualChild.GetGene(7).Value);
117+
118+
// 3 1 7 2 5 4 6 8
119+
actualChild = actual[1];
120+
Assert.AreEqual(8, actualChild.Length);
121+
Assert.AreEqual(3, actualChild.GetGene(0).Value);
122+
Assert.AreEqual(1, actualChild.GetGene(1).Value);
123+
Assert.AreEqual(7, actualChild.GetGene(2).Value);
124+
Assert.AreEqual(2, actualChild.GetGene(3).Value);
125+
Assert.AreEqual(5, actualChild.GetGene(4).Value);
126+
Assert.AreEqual(4, actualChild.GetGene(5).Value);
127+
Assert.AreEqual(6, actualChild.GetGene(6).Value);
128+
Assert.AreEqual(8, actualChild.GetGene(7).Value);
129+
}
130+
131+
[Test]
132+
public void GA_WithAlternatingPositionCrossover_Evolve()
133+
{
134+
var chromosome = new TspChromosome(50);
135+
var population = new Population(50, 50, chromosome)
136+
{
137+
GenerationStrategy = new TrackingGenerationStrategy()
138+
};
139+
var fitness = new TspFitness(chromosome.Length, 0, 1000, 0, 1000);
140+
var crossover = new AlternatingPositionCrossover();
141+
var ga = new GeneticAlgorithm(population, fitness, new EliteSelection(), crossover, new ReverseSequenceMutation())
142+
{
143+
Termination = new GenerationNumberTermination(100)
144+
};
145+
146+
ga.Start();
147+
148+
Assert.Less(
149+
population.Generations.First().BestChromosome.Fitness.Value,
150+
population.Generations.Last().BestChromosome.Fitness.Value);
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)