Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomelli committed Nov 3, 2018
2 parents 8a1264a + 0409618 commit 2654a2b
Show file tree
Hide file tree
Showing 19 changed files with 17,498 additions and 48 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ Can be used in any kind of .NET Core and .NET Framework apps, like ASP .NET MVC,

--------

## Projects, papers, journals, books, tutorials and apps using GeneticSharp
## Projects, papers, journals, books, tutorials, courses and apps using GeneticSharp
* [AeroVision: aircraft trajectories optimization and visualization (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/AeroVision-Aircraft-trajectories-optimization-and-visualization.pdf)
* [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)
* [Artificial Intelligence course in French engineering schools (course)](https://github.com/giacomelli/GeneticSharp/pull/43#issuecomment-433662175)
* [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) 🇧🇷
* [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)
* [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)
* [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)
* [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)
* [Function optimization with GeneticSharp (tutorial)](http://diegogiacomelli.com.br/function-optimization-with-geneticsharp/)
* [GeneticSharp Car2D (sample)](http://diegogiacomelli.com.br/GeneticSharp-Car2D/)
* [GeneticSharp Unity3d Samples (Android app)](https://play.google.com/store/apps/details?id=br.com.diegogiacomelli.geneticsharprunnersunityapp)
* [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)
* [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) 🇧🇷
* [Lean Optimization: genetic optimization using LEAN (GitHub)](https://github.com/Jay-Jay-D/LeanOptimization)
* [Overload journal 142: Evolutionary computing frameworks for optimisation (journal)](https://accu.org/var/uploads/journals/Overload142.pdf)
* [Path Finding with Genetic Algorithms (project)](https://yoloprogramming.com/post/2017/01/11/path-finding-with-genetic-algorithms)
Expand Down Expand Up @@ -116,7 +117,7 @@ Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain

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

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

#### Bitmap equality
Expand Down
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.0.{build}
version: 2.2.{build}
os: Visual Studio 2017
configuration: Release
environment:
Expand Down Expand Up @@ -47,9 +47,9 @@ after_build:
- cmd: >-
mkdir .\src\nuget
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.1.0
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.2.0
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.1.0
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.2.0
test_script:
- cmd: dotnet clean src/GeneticSharp.Domain.UnitTests
Expand Down
29 changes: 11 additions & 18 deletions src/GeneticSharp.Domain/GeneticAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using GeneticSharp.Domain.Chromosomes;
using GeneticSharp.Domain.Crossovers;
Expand Down Expand Up @@ -79,6 +80,7 @@ public sealed class GeneticAlgorithm : IGeneticAlgorithm
private bool m_stopRequested;
private readonly object m_lock = new object();
private GeneticAlgorithmState m_state;
private Stopwatch m_stopwatch;
#endregion

#region Constructors
Expand Down Expand Up @@ -231,11 +233,7 @@ private set

if (shouldStop)
{
var handler = Stopped;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
Stopped?.Invoke(this, EventArgs.Empty);
}
}
}
Expand Down Expand Up @@ -268,9 +266,10 @@ public void Start()
lock (m_lock)
{
State = GeneticAlgorithmState.Started;
var startDateTime = DateTime.Now;
m_stopwatch = Stopwatch.StartNew();
Population.CreateInitialGeneration();
TimeEvolving = DateTime.Now - startDateTime;
m_stopwatch.Stop();
TimeEvolving = m_stopwatch.Elapsed;
}

Resume();
Expand Down Expand Up @@ -312,7 +311,6 @@ public void Resume()
}

bool terminationConditionReached = false;
DateTime startDateTime;

do
{
Expand All @@ -321,9 +319,10 @@ public void Resume()
break;
}

startDateTime = DateTime.Now;
m_stopwatch.Restart();
terminationConditionReached = EvolveOneGeneration();
TimeEvolving += DateTime.Now - startDateTime;
m_stopwatch.Stop();
TimeEvolving += m_stopwatch.Elapsed;
}
while (!terminationConditionReached);
}
Expand Down Expand Up @@ -374,20 +373,14 @@ private bool EndCurrentGeneration()
Population.EndCurrentGeneration();

var handler = GenerationRan;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
handler?.Invoke(this, EventArgs.Empty);

if (Termination.HasReached(this))
{
State = GeneticAlgorithmState.TerminationReached;

handler = TerminationReached;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
handler?.Invoke(this, EventArgs.Empty);

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GeneticSharp.Domain/Properties/SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
[assembly: AssemblyConfiguration("Release")]
#endif

[assembly: AssemblyVersion("2.1.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.2.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
</ItemGroup>

<ItemGroup>
<None Update="Sudoku\SudokuList.sdk">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
71 changes: 71 additions & 0 deletions src/GeneticSharp.Extensions.UnitTests/Multiple/MultipleTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeneticSharp.Domain;
using GeneticSharp.Domain.Chromosomes;
using GeneticSharp.Domain.Crossovers;
using GeneticSharp.Domain.Fitnesses;
using GeneticSharp.Domain.Mutations;
using GeneticSharp.Domain.Populations;
using GeneticSharp.Domain.Selections;
using GeneticSharp.Domain.Terminations;
using GeneticSharp.Extensions.Multiple;
using GeneticSharp.Extensions.Tsp;
using NUnit.Framework;

namespace GeneticSharp.Extensions.UnitTests.Multiple
{


[TestFixture]
[Category("Extensions")]
class MultipleTest
{

[Test()]
public void Evolve_CompareToSingleChromosome_Evolved()
{
int numberOfCities = 30;
var selection = new EliteSelection();
var crossover = new UniformCrossover();
var mutation = new TworsMutation();


// Given enough generations, the Multiple Chromosome should start exhibiting convergence
// we compare TSP /25 gen with 3*TSP / 500 gen

IChromosome chromosome = new TspChromosome(numberOfCities);
IFitness fitness = new TspFitness(numberOfCities, 0, 1000, 0, 1000);
var population = new Population(30, 30, chromosome);
var ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation)
{
Termination = new GenerationNumberTermination(26)
};
ga.Start();
var simpleChromosomeDistance = ((TspChromosome)ga.Population.BestChromosome).Distance;

chromosome = new MultipleChromosome((i) => new TspChromosome(numberOfCities), 3);
//MultiChromosome should create 3 TSP chromosomes and store them in the corresponding property
Assert.AreEqual(((MultipleChromosome)chromosome).Chromosomes.Count, 3);
var tempMultiFitness = ((MultipleChromosome)chromosome).Chromosomes.Sum(c => fitness.Evaluate(c));
fitness = new MultipleFitness(fitness);
//Multi fitness should sum over the fitnesses of individual chromosomes
Assert.AreEqual(tempMultiFitness, fitness.Evaluate(chromosome));
population = new Population(30, 30, chromosome);
ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation)
{
Termination = new GenerationNumberTermination(501)
};
ga.Start();
var bestTSPChromosome = (TspChromosome)((MultipleChromosome)ga.Population.BestChromosome).Chromosomes
.OrderByDescending(c => c.Fitness).First();
var multiChromosomesDistance = bestTSPChromosome.Distance;

Assert.Less(multiChromosomesDistance, simpleChromosomeDistance);
}



}
}
Loading

0 comments on commit 2654a2b

Please sign in to comment.