Skip to content

Commit

Permalink
Merge branch 'release/v2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomelli committed Jan 19, 2019
2 parents f9c504d + 002b5cd commit 33304a5
Show file tree
Hide file tree
Showing 39 changed files with 1,260 additions and 140 deletions.
84 changes: 39 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,21 @@ Can be used in any kind of .NET Core and .NET Framework apps, like ASP .NET MVC,
Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain/Fitnesses/IFitness.cs) interface.

### [Populations](src/GeneticSharp.Domain/Populations)
- [Population](src/GeneticSharp.Domain/Populations/Population.cs)
- [TplPopulation](src/GeneticSharp.Domain/Populations/TplPopulation.cs)
- Others populations can be added implementing [IPopulation](src/GeneticSharp.Domain/IPopulation) interface or extending [Population](src/GeneticSharp.Domain/Populations/Population.cs).

### [Generations](src/GeneticSharp.Domain/Populations/Generation.cs)
- [Generation](src/GeneticSharp.Domain/Populations/Generation.cs)
- [Generation strategy](src/GeneticSharp.Domain/Populations/IGenerationStrategy.cs)
- [Performance strategy](src/GeneticSharp.Domain/Populations/PerformanceGenerationStrategy.cs)
- [Tracking strategy](src/GeneticSharp.Domain/Populations/TrackingGenerationStrategy.cs)
- Others generation strategies can be added implementing [IGenerationStrategy.cs](src/GeneticSharp.Domain/IGenerationStrategy.cs) interface.

### [Operators strategy](src/GeneticSharp.Domain/src/GeneticSharp.Domain/IOperatorsStrategy.cs)
- [DefaultOperatorsStrategy](src/GeneticSharp.Domain/DefaultOperatorsStrategy.cs)
- [TplOperatorsStrategy](src/GeneticSharp.Domain/TplOperatorsStrategy.cs)
- Others operators strategies can be added implementing [IOperatorsStrategy](src/GeneticSharp.Domain/IOperatorsStrategy.cs) interface.

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

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

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

### [Task executors](src/GeneticSharp.Infrastructure.Framework/Threading/ITaskExecutor.cs)
- [LinearTaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/LinearTaskExecutor.cs)
- [ParallelTaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/ParallelTaskExecutor.cs)
- [TplTaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/TplTaskExecutor.cs)
- Others task executors can be added implementing [ITaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/ITaskExecutor.cs) interface.

## Samples
### [Console sample](src/GeneticSharp.Runner.ConsoleApp)
### [Console samples](src/GeneticSharp.Runner.ConsoleApp)
- AutoConfig
- Bitmap equality
- Equality equation
- Equation solver
- Function builder
- Ghostwriter
- TSP (Travelling Salesman Problem)

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

- Ghostwriter
- TSP (Travelling Salesman Problem)

### [GTK# sample](src/GeneticSharp.Runner.GtkApp)
### [GTK# samples](src/GeneticSharp.Runner.GtkApp)
- Bitmap equality
- Function optimization
- Sudoku
- TSP (Travelling Salesman Problem)

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

#### Bitmap equality
![](docs/gifs/GeneticSharp-BitmapEquality_sample01.gif)

### [Unity3D Samples](src/GeneticSharp.Runner.UnityApp)
- Car2D
- TSP (Travelling Salesman Problem)
- Wall Builder

[![](docs/screenshots/GeneticSharp-UnityApp.png)](https://youtu.be/xXqNcgeOU_g)
[![](docs/images/google-play-badge.png)](https://play.google.com/store/apps/details?id=br.com.diegogiacomelli.geneticsharprunnersunityapp)

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

![](docs/screenshots/VisualStudioMacAndWin.png)

## Code quality
- 100% unit test code coverage.
- FxCop validated.
- Code duplicated verification.
- Good (and well used) design patterns.
- 100% code documentation
- [SonarCloud](https://sonarcloud.io/dashboard?id=GeneticSharp) validated.

--------

Expand Down Expand Up @@ -170,6 +189,8 @@ install-package GeneticSharp -Version 1.2.0
## Running samples
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.

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).

## Usage

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

Console.WriteLine("Best solution found has {0} fitness.", ga.BestChromosome.Fitness);
```

--------

## Roadmap
- Add new problems/classic sample
- Checkers
- Time series
- Knapsack problem
- Add new selections
- Reward-based
- Add new crossovers
- Voting recombination
- Alternating-position (AP)
- Sequential Constructive (SCX)
- Shuffle crossover
- Precedence Preservative Crossover (PPX)
- Add new mutations
- Non-Uniform
- Boundary
- Gaussian
- Add new terminations
- Fitness convergence
- Population convergence
- Chromosome convergence
- New samples
- Xamarin runner app (sample)
- Parallel populations (islands)

--------

Expand All @@ -266,10 +260,10 @@ Having troubles?
- Tutorials
- [Function optimization with GeneticSharp](http://diegogiacomelli.com.br/function-optimization-with-geneticsharp/)
- [TSP with GeneticSharp and Unity3D](http://diegogiacomelli.com.br/tsp-with-GeneticSharp-and-Unity3d/)
- Ask on Twitter [@ogiacomelli](http://twitter.com/ogiacomelli).
- Ask on [Stack Overflow](http://stackoverflow.com/questions/tagged/geneticsharp) using the tag [GeneticSharp](http://stackoverflow.com/questions/tagged/geneticsharp).

--------
- Open an [issue](https://github.com/giacomelli/GeneticSharp/issues).

--------

## How to improve it?

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

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

# Thanks to
I would like to thanks to the guys from [SMASHINGLOGO (https://smashinglogo.com)](https://smashinglogo.com/) for the amazing GeneticSharp logo.
12 changes: 4 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.2.{build}
version: 2.4.{build}
os: Visual Studio 2017
configuration: Release
environment:
Expand All @@ -15,11 +15,7 @@ assembly_info:
assembly_informational_version: '{version}'

install:
- cmd: choco install gtksharp

nuget:
account_feed: true
project_feed: true
- cmd: choco install gtksharp

before_build:
- cmd: dotnet --version
Expand Down Expand Up @@ -47,9 +43,9 @@ after_build:
- cmd: >-
mkdir .\src\nuget
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.2.0
dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.4.0
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.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.4.0
test_script:
- cmd: dotnet clean src/GeneticSharp.Domain.UnitTests
Expand Down
Binary file modified docs/Crossover operators in genetic algorithms - A review.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System.Collections.Generic;
using GeneticSharp.Domain.Chromosomes;
using GeneticSharp.Domain.Crossovers;
using GeneticSharp.Domain.Randomizations;
using NUnit.Framework;
using NSubstitute;
using System;
using GeneticSharp.Domain.Populations;
using GeneticSharp.Domain.Fitnesses;
using System.Linq;
using GeneticSharp.Domain.Selections;
using GeneticSharp.Domain.Mutations;
using GeneticSharp.Domain.Terminations;
using System.Diagnostics;
using GeneticSharp.Extensions.Tsp;

namespace GeneticSharp.Domain.UnitTests.Crossovers
{
[TestFixture]
[Category("Crossovers")]
public class AlternatingPositionCrossoverTest
{
[TearDown]
public void Cleanup()
{
RandomizationProvider.Current = new BasicRandomization();
}

[Test]
public void Cross_ParentWithNoOrderedGenes_Exception()
{
var target = new AlternatingPositionCrossover();

var chromosome1 = Substitute.For<ChromosomeBase>(8);
chromosome1.ReplaceGenes(0, new Gene[] {
new Gene(8),
new Gene(2),
new Gene(3),
new Gene(4),
new Gene(6),
new Gene(5),
new Gene(7),
new Gene(1)
});

// 3 7 5 1 6 8 2 4
var chromosome2 = Substitute.For<ChromosomeBase>(8);
chromosome2.ReplaceGenes(0, new Gene[] {
new Gene(1),
new Gene(2),
new Gene(3),
new Gene(4),
new Gene(5),
new Gene(5),
new Gene(6),
new Gene(7)
});

Assert.Catch<CrossoverException>(() =>
{
target.Cross(new List<IChromosome>() { chromosome1, chromosome2 });
}, "The Alternating-position (AP) can be only used with ordered chromosomes. The specified chromosome has repeated genes.");
}

[Test]
public void Cross_DocumentationSample_Child()
{
var target = new AlternatingPositionCrossover();

// 1 2 3 4 5 6 7 8
var chromosome1 = Substitute.For<ChromosomeBase>(8);
chromosome1.ReplaceGenes(0, new Gene[] {
new Gene(1),
new Gene(2),
new Gene(3),
new Gene(4),
new Gene(5),
new Gene(6),
new Gene(7),
new Gene(8)
});

var child1 = Substitute.For<ChromosomeBase>(8);
chromosome1.CreateNew().Returns(child1);

// 3 7 5 1 6 8 2 4
var chromosome2 = Substitute.For<ChromosomeBase>(8);
chromosome2.ReplaceGenes(0, new Gene[] {
new Gene(3),
new Gene(7),
new Gene(5),
new Gene(1),
new Gene(6),
new Gene(8),
new Gene(2),
new Gene(4)
});
var child2 = Substitute.For<ChromosomeBase>(8);
chromosome2.CreateNew().Returns(child2);

var actual = target.Cross(new List<IChromosome>() { chromosome1, chromosome2 });

Assert.AreEqual(2, actual.Count);

// 1 3 2 7 5 4 6 8
var actualChild = actual[0];
Assert.AreEqual(8, actualChild.Length);

Assert.AreEqual(1, actualChild.GetGene(0).Value);
Assert.AreEqual(3, actualChild.GetGene(1).Value);
Assert.AreEqual(2, actualChild.GetGene(2).Value);
Assert.AreEqual(7, actualChild.GetGene(3).Value);
Assert.AreEqual(5, actualChild.GetGene(4).Value);
Assert.AreEqual(4, actualChild.GetGene(5).Value);
Assert.AreEqual(6, actualChild.GetGene(6).Value);
Assert.AreEqual(8, actualChild.GetGene(7).Value);

// 3 1 7 2 5 4 6 8
actualChild = actual[1];
Assert.AreEqual(8, actualChild.Length);
Assert.AreEqual(3, actualChild.GetGene(0).Value);
Assert.AreEqual(1, actualChild.GetGene(1).Value);
Assert.AreEqual(7, actualChild.GetGene(2).Value);
Assert.AreEqual(2, actualChild.GetGene(3).Value);
Assert.AreEqual(5, actualChild.GetGene(4).Value);
Assert.AreEqual(4, actualChild.GetGene(5).Value);
Assert.AreEqual(6, actualChild.GetGene(6).Value);
Assert.AreEqual(8, actualChild.GetGene(7).Value);
}

[Test]
public void GA_WithAlternatingPositionCrossover_Evolve()
{
var chromosome = new TspChromosome(50);
var population = new Population(50, 50, chromosome)
{
GenerationStrategy = new TrackingGenerationStrategy()
};
var fitness = new TspFitness(chromosome.Length, 0, 1000, 0, 1000);
var crossover = new AlternatingPositionCrossover();
var ga = new GeneticAlgorithm(population, fitness, new EliteSelection(), crossover, new ReverseSequenceMutation())
{
Termination = new GenerationNumberTermination(100)
};

ga.Start();

Assert.Less(
population.Generations.First().BestChromosome.Fitness.Value,
population.Generations.Last().BestChromosome.Fitness.Value);
}
}
}
Loading

0 comments on commit 33304a5

Please sign in to comment.