Skip to content

Commit 2654a2b

Browse files
author
giacomelli
committed
Merge branch 'release/2.2.0'
2 parents 8a1264a + 0409618 commit 2654a2b

File tree

19 files changed

+17498
-48
lines changed

19 files changed

+17498
-48
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ Can be used in any kind of .NET Core and .NET Framework apps, like ASP .NET MVC,
1717

1818
--------
1919

20-
## Projects, papers, journals, books, tutorials and apps using GeneticSharp
20+
## Projects, papers, journals, books, tutorials, courses and apps using GeneticSharp
2121
* [AeroVision: aircraft trajectories optimization and visualization (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/AeroVision-Aircraft-trajectories-optimization-and-visualization.pdf)
22-
* [Analysis and comparison between Black-Scholes and Merton and Corrado-Su for options pricing (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Analysis-and-comparison-between-Black-Scholes-and-Merton-and-Corrado-Su-for-options-pricing.pdf)
22+
* [Artificial Intelligence course in French engineering schools (course)](https://github.com/giacomelli/GeneticSharp/pull/43#issuecomment-433662175)
23+
* [Analysis and comparison between Black-Scholes and Merton and Corrado-Su for options pricing (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Analysis-and-comparison-between-Black-Scholes-and-Merton-and-Corrado-Su-for-options-pricing.pdf) 🇧🇷
2324
* [Context-Sensitive Code Completion: improving predictions with genetic algorithms (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Context-Sensitive-Code-Completion-improving-predictions-with-genetic-algorithms.pdf) [(Github)](https://github.com/godtopus/GeneCSCC)
2425
* [Deriving Functions for Pareto Optimal Fronts Using Genetic Programming (paper/book)](https://books.google.com.br/books?id=w_lcDwAAQBAJ&lpg=PA473&ots=Rv7O6FhCSM&dq=%22GeneticSharp%22&hl=pt-BR&pg=PA464#v=onepage&q=%22GeneticSharp%22&f=false)
2526
* [Designing and creating a self managing distributed file system (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Designing-and-creating-a-self-managing-distributed-file-system.pdf)
2627
* [Developing trading strategies with genetic algorithms (forum)](https://www.quantconnect.com/forum/discussion/2396/developing-trading-strategies-with-genetic-algorithms) [(paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Developing-Trading-Strategies-with-Genetic-Algorithms.pdf)
2728
* [Function optimization with GeneticSharp (tutorial)](http://diegogiacomelli.com.br/function-optimization-with-geneticsharp/)
2829
* [GeneticSharp Car2D (sample)](http://diegogiacomelli.com.br/GeneticSharp-Car2D/)
2930
* [GeneticSharp Unity3d Samples (Android app)](https://play.google.com/store/apps/details?id=br.com.diegogiacomelli.geneticsharprunnersunityapp)
30-
* [Genetic Scheduler: a genetic algorithm for scheduling tasks with temporal restriction in distributed systems (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Genetic-Scheduler.pdf)
31+
* [Genetic Scheduler: a genetic algorithm for scheduling tasks with temporal restriction in distributed systems (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Genetic-Scheduler.pdf) 🇧🇷
3132
* [Lean Optimization: genetic optimization using LEAN (GitHub)](https://github.com/Jay-Jay-D/LeanOptimization)
3233
* [Overload journal 142: Evolutionary computing frameworks for optimisation (journal)](https://accu.org/var/uploads/journals/Overload142.pdf)
3334
* [Path Finding with Genetic Algorithms (project)](https://yoloprogramming.com/post/2017/01/11/path-finding-with-genetic-algorithms)
@@ -116,7 +117,7 @@ Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain
116117

117118
### [GTK# sample](src/GeneticSharp.Runner.GtkApp)
118119

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

122123
#### Bitmap equality

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2.0.{build}
1+
version: 2.2.{build}
22
os: Visual Studio 2017
33
configuration: Release
44
environment:
@@ -47,9 +47,9 @@ after_build:
4747
- cmd: >-
4848
mkdir .\src\nuget
4949
50-
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.1.0
50+
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.2.0
5151
52-
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.1.0
52+
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.2.0
5353
5454
test_script:
5555
- cmd: dotnet clean src/GeneticSharp.Domain.UnitTests

src/GeneticSharp.Domain/GeneticAlgorithm.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using GeneticSharp.Domain.Chromosomes;
56
using GeneticSharp.Domain.Crossovers;
@@ -79,6 +80,7 @@ public sealed class GeneticAlgorithm : IGeneticAlgorithm
7980
private bool m_stopRequested;
8081
private readonly object m_lock = new object();
8182
private GeneticAlgorithmState m_state;
83+
private Stopwatch m_stopwatch;
8284
#endregion
8385

8486
#region Constructors
@@ -231,11 +233,7 @@ private set
231233

232234
if (shouldStop)
233235
{
234-
var handler = Stopped;
235-
if (handler != null)
236-
{
237-
handler(this, EventArgs.Empty);
238-
}
236+
Stopped?.Invoke(this, EventArgs.Empty);
239237
}
240238
}
241239
}
@@ -268,9 +266,10 @@ public void Start()
268266
lock (m_lock)
269267
{
270268
State = GeneticAlgorithmState.Started;
271-
var startDateTime = DateTime.Now;
269+
m_stopwatch = Stopwatch.StartNew();
272270
Population.CreateInitialGeneration();
273-
TimeEvolving = DateTime.Now - startDateTime;
271+
m_stopwatch.Stop();
272+
TimeEvolving = m_stopwatch.Elapsed;
274273
}
275274

276275
Resume();
@@ -312,7 +311,6 @@ public void Resume()
312311
}
313312

314313
bool terminationConditionReached = false;
315-
DateTime startDateTime;
316314

317315
do
318316
{
@@ -321,9 +319,10 @@ public void Resume()
321319
break;
322320
}
323321

324-
startDateTime = DateTime.Now;
322+
m_stopwatch.Restart();
325323
terminationConditionReached = EvolveOneGeneration();
326-
TimeEvolving += DateTime.Now - startDateTime;
324+
m_stopwatch.Stop();
325+
TimeEvolving += m_stopwatch.Elapsed;
327326
}
328327
while (!terminationConditionReached);
329328
}
@@ -374,20 +373,14 @@ private bool EndCurrentGeneration()
374373
Population.EndCurrentGeneration();
375374

376375
var handler = GenerationRan;
377-
if (handler != null)
378-
{
379-
handler(this, EventArgs.Empty);
380-
}
376+
handler?.Invoke(this, EventArgs.Empty);
381377

382378
if (Termination.HasReached(this))
383379
{
384380
State = GeneticAlgorithmState.TerminationReached;
385381

386382
handler = TerminationReached;
387-
if (handler != null)
388-
{
389-
handler(this, EventArgs.Empty);
390-
}
383+
handler?.Invoke(this, EventArgs.Empty);
391384

392385
return true;
393386
}

src/GeneticSharp.Domain/Properties/SolutionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
[assembly: AssemblyConfiguration("Release")]
99
#endif
1010

11-
[assembly: AssemblyVersion("2.1.0")]
12-
[assembly: AssemblyFileVersion("2.1.0.0")]
11+
[assembly: AssemblyVersion("2.2.0")]
12+
[assembly: AssemblyFileVersion("2.2.0.0")]

src/GeneticSharp.Extensions.UnitTests/GeneticSharp.Extensions.UnitTests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@
2121
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
2222
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
2323
</ItemGroup>
24+
25+
<ItemGroup>
26+
<None Update="Sudoku\SudokuList.sdk">
27+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28+
</None>
29+
</ItemGroup>
2430
</Project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using GeneticSharp.Domain;
6+
using GeneticSharp.Domain.Chromosomes;
7+
using GeneticSharp.Domain.Crossovers;
8+
using GeneticSharp.Domain.Fitnesses;
9+
using GeneticSharp.Domain.Mutations;
10+
using GeneticSharp.Domain.Populations;
11+
using GeneticSharp.Domain.Selections;
12+
using GeneticSharp.Domain.Terminations;
13+
using GeneticSharp.Extensions.Multiple;
14+
using GeneticSharp.Extensions.Tsp;
15+
using NUnit.Framework;
16+
17+
namespace GeneticSharp.Extensions.UnitTests.Multiple
18+
{
19+
20+
21+
[TestFixture]
22+
[Category("Extensions")]
23+
class MultipleTest
24+
{
25+
26+
[Test()]
27+
public void Evolve_CompareToSingleChromosome_Evolved()
28+
{
29+
int numberOfCities = 30;
30+
var selection = new EliteSelection();
31+
var crossover = new UniformCrossover();
32+
var mutation = new TworsMutation();
33+
34+
35+
// Given enough generations, the Multiple Chromosome should start exhibiting convergence
36+
// we compare TSP /25 gen with 3*TSP / 500 gen
37+
38+
IChromosome chromosome = new TspChromosome(numberOfCities);
39+
IFitness fitness = new TspFitness(numberOfCities, 0, 1000, 0, 1000);
40+
var population = new Population(30, 30, chromosome);
41+
var ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation)
42+
{
43+
Termination = new GenerationNumberTermination(26)
44+
};
45+
ga.Start();
46+
var simpleChromosomeDistance = ((TspChromosome)ga.Population.BestChromosome).Distance;
47+
48+
chromosome = new MultipleChromosome((i) => new TspChromosome(numberOfCities), 3);
49+
//MultiChromosome should create 3 TSP chromosomes and store them in the corresponding property
50+
Assert.AreEqual(((MultipleChromosome)chromosome).Chromosomes.Count, 3);
51+
var tempMultiFitness = ((MultipleChromosome)chromosome).Chromosomes.Sum(c => fitness.Evaluate(c));
52+
fitness = new MultipleFitness(fitness);
53+
//Multi fitness should sum over the fitnesses of individual chromosomes
54+
Assert.AreEqual(tempMultiFitness, fitness.Evaluate(chromosome));
55+
population = new Population(30, 30, chromosome);
56+
ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation)
57+
{
58+
Termination = new GenerationNumberTermination(501)
59+
};
60+
ga.Start();
61+
var bestTSPChromosome = (TspChromosome)((MultipleChromosome)ga.Population.BestChromosome).Chromosomes
62+
.OrderByDescending(c => c.Fitness).First();
63+
var multiChromosomesDistance = bestTSPChromosome.Distance;
64+
65+
Assert.Less(multiChromosomesDistance, simpleChromosomeDistance);
66+
}
67+
68+
69+
70+
}
71+
}

0 commit comments

Comments
 (0)