Skip to content

Commit

Permalink
Merge branch 'release/2.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomelli committed Jul 11, 2019
2 parents 2a9847f + c31103a commit 362508f
Show file tree
Hide file tree
Showing 141 changed files with 6,527 additions and 51 deletions.
60 changes: 51 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

![](docs/logo/logo-small.png)


[![Build status](https://ci.appveyor.com/api/projects/status/h9ptxpyj30ah3mva/branch/master?svg=true)](https://ci.appveyor.com/project/giacomelli/geneticsharp)
[![Quality status](https://sonarcloud.io/api/project_badges/measure?project=GeneticSharp&metric=alert_status)](https://sonarcloud.io/dashboard?id=GeneticSharp)
[![Coverage Status](https://sonarcloud.io/api/project_badges/measure?project=GeneticSharp&metric=coverage)](https://sonarcloud.io/dashboard?id=GeneticSharp)
Expand All @@ -12,31 +10,36 @@

GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).

Can be used in any kind of .NET Core and .NET Framework apps, like ASP .NET MVC, ASP .NET Core, Web Forms, UWP, Windows Forms, GTK#, Xamarin and Unity3D games.
Can be used in any kind of .NET Core and .NET Framework apps, like ASP .NET MVC, ASP .NET Core, Blazor, Web Forms, UWP, Windows Forms, GTK#, Xamarin and Unity3D games.


--------

## 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)
* [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) 🇧🇷
* [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) ![](https://img.shields.io/badge/BR-green.svg)
* [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)
* [Design of a warehouse order picking policy using genetic algorithm (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Design-of-a-warehouse-order-picking-policy-using-genetic-algorithm.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)
* [Fabrication of Adiabatic Quantum-Flux-Parametron Integrated Circuits Using an Automatic Placement Tool Based on Genetic Algorithms (paper)](https://ieeexplore.ieee.org/document/8643945)
* [Frixel: 2D framing / pixel structural optimization (project)](https://github.com/EmilPoulsen/Frixel)
* [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) ![](https://img.shields.io/badge/BR-green.svg)
* [Lean Optimization: genetic optimization using LEAN (GitHub)](https://github.com/Jay-Jay-D/LeanOptimization)
* [OpenFMSL: simulate stationary chemical processes using mass and energy balances (project)](https://github.com/Nukleon84/OpenFMSL)
* [Modelling and Simulation Analysis of Goal-Oriented Business Process (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Modelling-and-Simulation-Analysis-of-Goal-Oriented-Business-Process.pdf) ![](https://img.shields.io/badge/LT-red.svg)
* [Optimization of patient flow in emergency departments using Genetic Algorithms (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Optimization-of-Patient-Flow-in-Emergency-Departments-using-Genetic-Algorithms.pdf)
* [Optimization by genetic algorithm of lattices structures for the media generation in additive manufacturing (paper)](https://github.com/giacomelli/GeneticSharp/blob/master/docs/mentioning-GeneticSharp/Optimisation-par-algorithme-genetique-de-structures-lattices.pdf) ![](https://img.shields.io/badge/FR-blue.svg)
* [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)
* [SurvivorAI: some experiments of survival scenarios (project)](https://github.com/giacomelli/SurvivorAI)
* [ThermalDesign (project)](https://github.com/simonjduff/ThermalDesign)
* [TrussOptimization (project)](https://trussoptimizationweb.herokuapp.com)
* [TSP with GeneticSharp and Unity3D (tutorial)](http://diegogiacomelli.com.br/tsp-with-GeneticSharp-and-Unity3d/)
* [VetMedData.NET: a .NET Core class library for obtaining structured data on UK-licensed Veterinary Medicines (project)](https://github.com/Jongmassey/VetMedData.NET)
* Are you using GeneticSharp in your project? Please, [let me know!](https://twitter.com/ogiacomelli)
Expand Down Expand Up @@ -127,6 +130,9 @@ Add your own fitness evaluation, implementing [IFitness](src/GeneticSharp.Domain
- Others task executors can be added implementing [ITaskExecutor](src/GeneticSharp.Infrastructure.Framework/Threading/ITaskExecutor.cs) interface.

## Samples
### [Blazor samples](src/GeneticSharp.Runner.BlacorApp)
- [TSP (Travelling Salesman Problem) [online]](http://diegogiacomelli.com.br/apps/geneticsharp-runner-blazorapp)

### [Console samples](src/GeneticSharp.Runner.ConsoleApp)
- AutoConfig
- Bitmap equality
Expand Down Expand Up @@ -183,7 +189,9 @@ GeneticSharp and extensions (TSP, AutoConfig, Bitmap equality, Equality equation
install-package GeneticSharp.Extensions
```
## Unity3D
If want to use GeneticSharp on Unity3D you can use the latest GeneticSharp.unitypackage available on our [release page](https://github.com/giacomelli/GeneticSharp/releases).
You should use the [UnityNuGet](https://github.com/xoofx/UnityNuGet) to install GeneticSharp directly from NuGet.

Or you can use the latest GeneticSharp.unitypackage available on our [release page](https://github.com/giacomelli/GeneticSharp/releases).

## Mono and .NET Framework 3.5
To install previous version that support .NET Framework 3.5:
Expand Down Expand Up @@ -217,7 +225,7 @@ public class MyProblemFitness : IFitness

public class MyProblemChromosome : ChromosomeBase
{
// Change the argument value passed to base construtor to change the length
// Change the argument value passed to base constructor to change the length
// of your chromosome.
public MyProblemChromosome() : base(10)
{
Expand Down Expand Up @@ -255,6 +263,39 @@ ga.Start();

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


## Templates for `dotnet new`
If you're using .NET Core, you can install GeneticSharp.Templates:

```shell
dotnet new -i GeneticSharp.Templates
```

There are 4 templates in GeneticSharp.Templates:
### TSP Blazor application
A Blazor client application template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).
```shell
dotnet new GeneticSharpTspBlazorApp -n MyNamespace -o MyOutoputFolder
```

### Console application
A console application template with GeneticSharp, you just need to implement the chromosome and fitness function.
```shell
dotnet new GeneticSharpConsoleApp -n MyNamespace -o MyOutoputFolder
```

### TSP Console application
A console application template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).
```shell
dotnet new GeneticSharpTspConsoleApp -n MyNamespace -o MyOutoputFolder
```

### TSP Unity3D
A Unity3D template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).
```shell
dotnet new GeneticSharpTspUnity3d -n MyNamespace -o MyOutoputFolder
```

--------

Expand All @@ -264,7 +305,8 @@ Having troubles?

- Read our [wiki](https://github.com/giacomelli/GeneticSharp/wiki).
- Tutorials
- [Function optimization with GeneticSharp](http://diegogiacomelli.com.br/function-optimization-with-geneticsharp/)
- [Function optimization with GeneticSharp](http://diegogiacomelli.com.br/function-optimization-with-geneticsharp/)
- [TSP with GeneticSharp and Blazor](http://diegogiacomelli.com.br/tsp-with-geneticsharp-and-blazor)
- [TSP with GeneticSharp and Unity3D](http://diegogiacomelli.com.br/tsp-with-GeneticSharp-and-Unity3d/)
- 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).
Expand All @@ -289,4 +331,4 @@ In others words, you can use this library for developement any kind of software:


[![](docs/images/appveyor-logo.png)](https://www.appveyor.com/)|[![](docs/images/jetbrains-logo.png)](https://www.jetbrains.com/)|[![](docs/images/smashinglogo-logo.png)](https://smashinglogo.com/)|[![](docs/images/sonarcloud-logo.png)](https://sonarcloud.io)|
|:-:|:-:|:-:|:-:|
|:-:|:-:|:-:|:-:|
14 changes: 8 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ build_script:
- cmd: dotnet build src/GeneticSharp.Runner.ConsoleApp -f netcoreapp2.0

after_build:
- cmd: >-
mkdir .\src\nuget
# Build the GeneticSharp and GeneticSharp.Extensions NuGet packages.
- cmd: tools/buildLibrariesNuget.cmd

dotnet pack src/GeneticSharp.Domain/GeneticSharp.Domain.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.5.2
dotnet pack src/GeneticSharp.Extensions/GeneticSharp.Extensions.csproj -c release --no-build --output ../nuget /p:PackageVersion=2.5.2
# Build the GeneticSharp.Templates NuGet package.
- cmd: tools/buildTemplatesNuget.cmd

test_script:
- cmd: dotnet clean src/GeneticSharp.Domain.UnitTests
Expand All @@ -59,4 +58,7 @@ test_script:

artifacts:
- path: .\src\nuget\*.nupkg
name: NuGet packages
name: Libraries NuGet packages

- path: .\src\Templates\*.nupkg
name: Templates NuGet package
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 4 additions & 3 deletions src/GeneticSharp.Domain/Chromosomes/ChromosomeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public static class ChromosomeExtensions
/// <param name="chromosomes">The chromosomes.</param>
public static bool AnyHasRepeatedGene(this IList<IChromosome> chromosomes)
{
foreach (var p in chromosomes)
for (int i = 0; i < chromosomes.Count; i++)
{
var notRepeatedGenesLength = p.GetGenes().Distinct().Count();
var c = chromosomes[i];
var notRepeatedGenesLength = c.GetGenes().Distinct().Count();

if (notRepeatedGenesLength < p.Length)
if (notRepeatedGenesLength < c.Length)
{
return true;
}
Expand Down
9 changes: 5 additions & 4 deletions src/GeneticSharp.Domain/DefaultOperatorsStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public class DefaultOperatorsStrategy : IOperatorsStrategy
/// <returns>The result chromosomes.</returns>
public IList<IChromosome> Cross(IPopulation population, ICrossover crossover, float crossoverProbability, IList<IChromosome> parents)
{
var offspring = new List<IChromosome>();
var minSize = population.MinSize;
var offspring = new List<IChromosome>(minSize);

for (int i = 0; i < population.MinSize; i += crossover.ParentsNumber)
for (int i = 0; i < minSize; i += crossover.ParentsNumber)
{
var selectedParents = parents.Skip(i).Take(crossover.ParentsNumber).ToList();

Expand All @@ -48,9 +49,9 @@ public IList<IChromosome> Cross(IPopulation population, ICrossover crossover, fl
/// <param name="chromosomes">The chromosomes.</param>
public void Mutate(IMutation mutation, float mutationProbability, IList<IChromosome> chromosomes)
{
foreach (var c in chromosomes)
for (int i = 0; i < chromosomes.Count; i++)
{
mutation.Mutate(c, mutationProbability);
mutation.Mutate(chromosomes[i], mutationProbability);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/GeneticSharp.Domain/Mutations/UniformMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ protected override void PerformMutate(IChromosome chromosome, float probability)
}
}

foreach (var i in m_mutableGenesIndexes)
for (int i = 0; i < m_mutableGenesIndexes.Length; i++)
{
if (i >= genesLength)
var geneIndex = m_mutableGenesIndexes[i];

if (geneIndex >= genesLength)
{
throw new MutationException(this, "The chromosome has no gene on index {0}. The chromosome genes length is {1}.".With(i, genesLength));
throw new MutationException(this, "The chromosome has no gene on index {0}. The chromosome genes length is {1}.".With(geneIndex, genesLength));
}

if (RandomizationProvider.Current.GetDouble() <= probability)
{
chromosome.ReplaceGene(i, chromosome.GenerateGene(i));
chromosome.ReplaceGene(geneIndex, chromosome.GenerateGene(geneIndex));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/GeneticSharp.Domain/Populations/Generation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Generation(int number, IList<IChromosome> chromosomes)
public void End(int chromosomesNumber)
{
Chromosomes = Chromosomes
.Where(c => ValidateChromosome(c))
.Where(ValidateChromosome)
.OrderByDescending(c => c.Fitness.Value)
.ToList();

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.5.2")]
[assembly: AssemblyFileVersion("2.5.2.0")]
[assembly: AssemblyVersion("2.6.0")]
[assembly: AssemblyFileVersion("2.6.0.0")]
6 changes: 3 additions & 3 deletions src/GeneticSharp.Domain/Reinsertions/ElitistReinsertion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ protected override IList<IChromosome> PerformSelectChromosomes(IPopulation popul

if (diff > 0)
{
var bestParents = parents.OrderByDescending(p => p.Fitness).Take(diff);
var bestParents = parents.OrderByDescending(p => p.Fitness).Take(diff).ToList();

foreach (var p in bestParents)
for (int i = 0; i < bestParents.Count; i++)
{
offspring.Add(p);
offspring.Add(bestParents[i]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/GeneticSharp.Domain/Selections/RouletteWheelSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ protected static void CalculateCumulativePercentFitness(IList<IChromosome> chrom

var cumulativePercent = 0.0;

foreach (var c in chromosomes)
for (int i = 0; i < chromosomes.Count; i++)
{
cumulativePercent += c.Fitness.Value / sumFitness;
cumulativePercent += chromosomes[i].Fitness.Value / sumFitness;
rouletteWheel.Add(cumulativePercent);
}
}
Expand All @@ -99,7 +99,7 @@ protected override IList<IChromosome> PerformSelectChromosomes(int number, Gener
CalculateCumulativePercentFitness(chromosomes, rouletteWheel);

return SelectFromWheel(number, chromosomes, rouletteWheel, () => rnd.GetDouble());
}
}
#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ protected LogicalOperatorTerminationBase(params ITermination[] terminations)
{
if (terminations != null)
{
foreach (var t in terminations)
for (int i = 0; i < terminations.Length; i++)
{
AddTermination(t);
AddTermination(terminations[i]);
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/GeneticSharp.Extensions/Tsp/TspFitness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,14 @@ public double Evaluate(IChromosome chromosome)
var genes = chromosome.GetGenes();
var distanceSum = 0.0;
var lastCityIndex = Convert.ToInt32(genes[0].Value, CultureInfo.InvariantCulture);
var citiesIndexes = new List<int>();
citiesIndexes.Add(lastCityIndex);
var citiesIndexes = new List<int>
{
lastCityIndex
};

foreach (var g in genes)
for (int i = 0, genesLength = genes.Length; i < genesLength; i++)
{
var currentCityIndex = Convert.ToInt32(g.Value, CultureInfo.InvariantCulture);
var currentCityIndex = Convert.ToInt32(genes[i].Value, CultureInfo.InvariantCulture);
distanceSum += CalcDistanceTwoCities(Cities[currentCityIndex], Cities[lastCityIndex]);
lastCityIndex = currentCityIndex;

Expand Down
5 changes: 5 additions & 0 deletions src/GeneticSharp.Runner.BlazorApp/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Router AppAssembly="typeof(Program).Assembly">
<NotFoundContent>
<p>Sorry, there's nothing at this address.</p>
</NotFoundContent>
</Router>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="geneticsharp" Version="2.5.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview6.19307.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview6.19307.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview6.19307.2" PrivateAssets="all" />
</ItemGroup>

</Project>
Loading

0 comments on commit 362508f

Please sign in to comment.