GeneticSharp Documentation
repository·master·Indexed 23 days ago
https://github.com/giacomelli/geneticsharpA high-performance, multithreaded C# library for implementing Genetic Algorithms. Compatible with .NET 6, .NET Standard, and .NET Framework, it supports a wide range of environments including ASP.NET Core, Blazor, Xamarin, MAUI, and Unity3D. The library provides a modular architecture with extensible components for chromosomes, fitness evaluation, populations, selection, crossover, mutation, and termination conditions.
What's inside GeneticSharp
- GeneticSharp is a fast, extensible, multi-platform, and multithreading C# library designed to simplify the development of applications using Genetic Algorithms (GAs). It is built to be highly flexible and can be integrated into various .NET environments.
Overview of GeneticSharp components
masterGeneticSharp is composed of several modular components that can be customized by implementing specific interfaces or extending base classes:
- Chromosomes: Representations of solutions (e.g.,
FloatingPointChromosome,IntegerChromosome). ImplementIChromosomeor extendChromosomeBase. - Fitness: Evaluation logic. Implement
IFitness. - Populations: Collections of chromosomes (e.g.,
Population,TplPopulation). ImplementIPopulationor extendPopulation. - Generations: Logic for evolving populations. Implement
IGenerationStrategy. - Operators Strategy: Controls how operators are applied (e.g.,
DefaultOperatorsStrategy,TplOperatorsStrategy). ImplementIOperatorsStrategy. - Selections: Methods to pick parents (e.g.,
Elite,Tournament,Roulette Wheel). ImplementISelectionor extendSelectionBase. - Crossovers: Methods to combine parents (e.g.,
OnePointCrossover,UniformCrossover). ImplementICrossoveror extendCrossoverBase. - Mutations: Methods to introduce variation (e.g.,
FlipBitMutation,UniformMutation). ImplementIMutationor extendMutationBase. - Reinsertions: Logic for placing offspring back into the population (e.g.,
Elitist,Uniform). ImplementIReinsertionor extendReinsertionBase. - Terminations: Conditions to stop the GA (e.g.,
GenerationNumberTermination,FitnessThresholdTermination). ImplementITerminationor extendTerminationBase. - Randomizations: Random number generation strategies. Implement
IRandomization. - Task Executors: Execution models for parallel/linear tasks. Implement
ITaskExecutor.
- Chromosomes: Representations of solutions (e.g.,
Supported .NET Runtimes and Frameworks
masterGeneticSharp is compatible with a wide range of .NET platforms, making it suitable for desktop, web, mobile, and game development. Supported environments include:
- .NET 6
- .NET Standard
- .NET Framework
Common application types include:
- ASP.NET MVC and ASP.NET Core
- Blazor
- Web Forms
- UWP (Universal Windows Platform)
- Windows Forms
- GTK#
- Xamarin
- MAUI
- Unity3D games
Use GeneticSharp .NET Templates
masterAfter installing the templates, you can scaffold new projects using the following commands. Replace
MyNamespaceandMyOutoputFolderwith your desired values.TSP Blazor application
A Blazor client application template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).
dotnet new GeneticSharpTspBlazorApp -n MyNamespace -o MyOutoputFolderConsole application
A basic console application template. You must implement the chromosome and fitness function yourself.
dotnet new GeneticSharpConsoleApp -n MyNamespace -o MyOutoputFolderTSP Console application
A console application template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).
dotnet new GeneticSharpTspConsoleApp -n MyNamespace -o MyOutoputFolderTSP Unity3D
A Unity3D template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).
dotnet new GeneticSharpTspUnity3d -n MyNamespace -o MyOutoputFolderInstall GeneticSharp in Unity3D
masterTo use GeneticSharp in Unity, you can either use UnityNuGet to install it directly from NuGet, or download the latestGeneticSharp.unitypackagefrom the official releases page.Use Open Iconic's SVG Sprite
masterThe SVG sprite allows you to load all icons in a single request. To use it, reference the icon ID within the
xlink:hrefattribute of a<use>tag inside an<svg>element.Styling
- Sizing: Set equal
widthandheighton the<svg>tag. - Coloring: Set the
fillCSS property on the<use>tag.
Tip: Add a general class to the
<svg>tag for shared styles and a unique class to the<use>tag for icon-specific styling.<svg class="icon"> <use xlink:href="open-iconic.svg#account-login" class="icon-account-login"></use> </svg>.icon { width: 16px; height: 16px; } .icon-account-login { fill: #f00; }- Sizing: Set equal
Use Open Iconic Icon Font with Foundation
masterTo use Open Iconic with Foundation, include the Foundation-specific stylesheet and use the
fi-icon-nameclass pattern on a<span>element.<link href="/open-iconic/font/css/open-iconic-foundation.css" rel="stylesheet"> <span class="fi-icon-name" title="icon name" aria-hidden="true"></span>Use Open Iconic Icon Font standalone
masterTo use the default Open Iconic icon font without Bootstrap or Foundation, include the default stylesheet and use the
oiclass with thedata-glyphattribute.<link href="/open-iconic/font/css/open-iconic.css" rel="stylesheet"> <span class="oi" data-glyph="icon-name" title="icon name" aria-hidden="true"></span>Install GeneticSharp via NuGet
masterTo use GeneticSharp in a .NET 6 project, install the core package. If you require additional features like TSP, AutoConfig, or Equation solvers, install the extensions package as well.
For older environments, specific versions are required for compatibility with .NET Standard 2.0, .NET Framework 4.6.2, or .NET Framework 3.5.
# .NET 6 core install-package GeneticSharp # .NET 6 with extensions (TSP, AutoConfig, etc.) install-package GeneticSharp.Extensions # .NET Standard 2.0 and .NET Framework 4.6.2 install-package GeneticSharp -Version 2.6.0 # Mono and .NET Framework 3.5 install-package GeneticSharp -Version 1.2.0Install GeneticSharp .NET Templates
masterIf you are using .NET 6 or .NET Core, you can install the
GeneticSharp.Templatespackage to access pre-configured project templates for various application types.dotnet new -i GeneticSharp.TemplatesUse Open Iconic SVGs
masterYou can display Open Iconic icons as standard SVG images. It is recommended to use the
altattribute for accessibility.<img src="/open-iconic/svg/icon-name.svg" alt="icon name">Use Open Iconic Icon Font with Bootstrap
masterTo use Open Iconic with Bootstrap, include the Bootstrap-specific stylesheet and use the
oi oi-icon-nameclass pattern on a<span>element.<link href="/open-iconic/font/css/open-iconic-bootstrap.css" rel="stylesheet"> <span class="oi oi-icon-name" title="icon name" aria-hidden="true"></span>