• Stars
    star
    1,257
  • Rank 37,401 (Top 0.8 %)
  • Language
    C#
  • License
    MIT License
  • Created over 11 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Build status Quality status Coverage Status License Nuget Stack Overflow

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 6, .NET Standard and .NET Framework apps, like ASP .NET MVC, ASP .NET Core, Blazor, Web Forms, UWP, Windows Forms, GTK#, Xamarin, MAUI and Unity3D games.


Projects, papers, journals, books, tutorials, courses and apps using GeneticSharp

Features

Add your own fitness evaluation, implementing IFitness interface.

Samples

  • AutoConfig
  • Bitmap equality
  • Equality equation
  • Equation solver
  • Function builder
  • Ghostwriter
  • TSP (Travelling Salesman Problem)

  • Bitmap equality
  • Function optimization
  • Sudoku
  • TSP (Travelling Salesman Problem)

  • Car2D
  • TSP (Travelling Salesman Problem)
  • Wall Builder

Multi-platform

  • .NET 6, .NET Standard 2.0, Mono and .NET Framework 4.6.2 support
  • Fully tested on Windows and MacOS

Code quality


Setup

.NET 6

Only GeneticSharp:

install-package GeneticSharp

GeneticSharp and extensions (TSP, AutoConfig, Bitmap equality, Equality equation, Equation solver, Function builder, etc):

install-package GeneticSharp.Extensions

Unity3D

You should use the UnityNuGet to install GeneticSharp directly from NuGet.

Or you can use the latest GeneticSharp.unitypackage available on our release page.

.NET Standard 2.0 and .NET Framework 4.6.2

To install previous version that support .NET Standard 2.0 and .NET Framework 4.6.2:

install-package GeneticSharp -Version 2.6.0

Mono and .NET Framework 3.5

To install previous version that support .NET Framework 3.5:

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 page wiki.

An easy way to run the Unity Samples, if you have a Android device, is download it from Google Play.

Usage

Creating your own fitness evaluation

public class MyProblemFitness : IFitness
{  
	public double Evaluate (IChromosome chromosome)
	{
		// Evaluate the fitness of chromosome.
	}
}

Creating your own chromosome

public class MyProblemChromosome : ChromosomeBase
{
	// Change the argument value passed to base constructor to change the length 
	// of your chromosome.
	public MyProblemChromosome() : base(10) 
	{
		CreateGenes();
	}

	public override Gene GenerateGene (int geneIndex)
	{
		// Generate a gene base on my problem chromosome representation.
	}

	public override IChromosome CreateNew ()
	{
		return new MyProblemChromosome();
	}
}

Running your GA

var selection = new EliteSelection();
var crossover = new OrderedCrossover();
var mutation = new ReverseSequenceMutation();
var fitness = new MyProblemFitness();
var chromosome = new MyProblemChromosome();
var population = new Population (50, 70, chromosome);

var ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation);
ga.Termination = new GenerationNumberTermination(100);

Console.WriteLine("GA running...");
ga.Start();

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

Templates for dotnet new

If you're using .NET 6 or .NET Core, you can install GeneticSharp.Templates:

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

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.

dotnet new GeneticSharpConsoleApp -n MyNamespace -o MyOutoputFolder

TSP Console application

A console application template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).

dotnet new GeneticSharpTspConsoleApp -n MyNamespace -o MyOutoputFolder

TSP Unity3D

A Unity3D template with GeneticSharp ready to run a Travelling Salesman Problem (TSP).

dotnet new GeneticSharpTspUnity3d -n MyNamespace -o MyOutoputFolder

FAQ

Having troubles?


How to improve it?

Create a fork of GeneticSharp.

Did you change it? Submit a pull request.

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, etc.

Thanks to

  • AppVeyor: open source license for continuous integration.
  • JetBrains: open source license for all products pack.
  • SMASHINGLOGO: GeneticSharp's logo.
  • SonarCloud: open source license for online inspection.

More Repositories

1

SalesforceSharp

An easy-to-use .NET client library for Salesforce REST API
C#
80
star
2

HarSharp

A small and easy-to-use library to parse HTTP Archive (HAR) format to .NET objects.
C#
61
star
3

HelperSharp

A set of helpers and extensions for C# programming.
C#
53
star
4

Giacomelli.Unity.EditorToolbox

Unity3d editor tools to make life easier for game developers
C#
26
star
5

DocsByReflection

Discover the code documentation at runtime by reflection.
C#
21
star
6

KissSpecifications

A KISS approach for specification pattern
C#
19
star
7

JobSharp

An easy-to-use C# jobs runner.
C#
15
star
8

Doog

Doog is a framework to create console/terminal games, but using advanced game programming patterns
C#
8
star
9

Giacomelli.Unity.Metadata

Unity3d assets metadata
HTML
7
star
10

unity-avatar-mask-and-animation-layers

Starter project and complete solution for the tutorial: Unity Avatar Mask and Animation Layers (http://diegogiacomelli.com.br/unity-avatar-mask-and-animation-layers)
Mask
7
star
11

SqlAsFile

Use your SQL in .sql files instead of strings in C#
C#
6
star
12

jumpstart

jumpstart is a command-line tool to create new C# projects from prebuilt/templates
C#
6
star
13

MonoDevelop.ThoseMissingFeatures

Add-in to add those missing features we would like to see in MonoDevelop
C#
6
star
14

EasyBuild

An easy-to-use collection of MS Build tasks to help improve your build process.
C#
5
star
15

TestSharp

A set of helpers and asserts for unit and functional tests
C#
5
star
16

BadgesSharp

BadgesSharp is a free service to generate badges that need some kind of input and processing before you can display them on GitHub repositories: https://badgessharp.apphb.com
C#
4
star
17

SpecFlowHelper

C#
4
star
18

coding-an-editorwindow-to-create-default-animations-from-sprites

Starter project and complete solution for the tutorial: Unity Avatar Mask and Animation Layers (http://diegogiacomelli.com.br/coding-an-editorwindow-to-create-default-animations-from-sprites)
C#
4
star
19

AutoFilter

An easy way to auto build expression trees filters from an user input.
C#
3
star
20

DG.TwitterClient

C#/WPF multi-account twitter client
C#
3
star
21

unitytips-museum

A Blazor client app with the best #unitytips - http://diegogiacomelli.com.br/apps/unitytips-museum
HTML
2
star
22

Razor2Pdf

Razor2Pdf is a easy-to-use, cross-platform library to build PDF files from Razor template files
C#
2
star
23

Giacomelli.Unity.ToastyNotification

A fun editor log interceptor that play Mortal Kombat's Toasty easter-egg every time an error is logged
C#
2
star
24

BotWorld

A platform to create bots, environments and renderers for simulations.
C#
2
star
25

the-fundamentals-of-unity-2d-collider-tutorial

C#
2
star
26

BuxferSharp

An easy-to-use C# client library to Buxfer API
C#
2
star
27

AudioShooter

A shoot 'em up game where the level designer is the audio
C#
1
star
28

Buildron.SlackBotMod

A Slack bot to interact with Buildron
ASP
1
star
29

Skahal.Core

Skahal core library
C#
1
star
30

GlobalServer

Global Server for turn based multiplayer games
JavaScript
1
star
31

ProjectBreakout

An unfinished breakout game made using C# and MDX (Managed DirectX)
C#
1
star
32

aspnetwebapi-apigee

Implementing ASP .NET Web API using the Apigee Web API Design
C#
1
star
33

SmartDiagnostics

Extensions to facilitate diagnosis .NET code.
C#
1
star
34

SampleProject

C#
1
star
35

AppsInfo

Components to show informations about ASP .NET Web Apps (MVC and Web API)
C#
1
star
36

SurvivorAI

Some experiments of survival scenarios using GeneticSharp
GLSL
1
star