DarwinGA 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DarwinGA --version 1.0.0
                    
NuGet\Install-Package DarwinGA -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DarwinGA" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DarwinGA" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DarwinGA" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DarwinGA --version 1.0.0
                    
#r "nuget: DarwinGA, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DarwinGA@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DarwinGA&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DarwinGA&version=1.0.0
                    
Install as a Cake Tool

🧩 Creating a Custom Evolutionary Problem

DarwinGA is designed to be problem-agnostic.

That means you don’t solve a problem directly — you define how a solution behaves, and the algorithm evolves it.

To use DarwinGA, you only need to define 3 things:


1️⃣ Define your Solution (Chromosome)

This represents a candidate solution.

public class MySolution
{
    public double Price { get; set; }
}

👉 This is what evolves.

You can model anything:

  • numbers
  • arrays
  • objects
  • strategies

2️⃣ Define the Fitness Function

This is the most important part.

It tells the algorithm:

“How good is this solution?”

public class MyFitnessEvaluator : IFitnessEvaluator<MySolution>
{
    public double Evaluate(MySolution solution)
    {
        // Example: maximize profit
        double demand = 100 - solution.Price;
        double profit = solution.Price * demand;

        return profit;
    }
}

👉 The algorithm will try to maximize this value.


3️⃣ (Optional) Customize Mutation & Crossover

You can control how solutions evolve.

Mutation
public class MyMutation : IMutationStrategy<MySolution>
{
    public void Mutate(MySolution solution)
    {
        solution.Price += Random.Shared.NextDouble() * 2 - 1;
    }
}
Crossover
public class MyCrossover : ICrossoverStrategy<MySolution>
{
    public MySolution Crossover(MySolution a, MySolution b)
    {
        return new MySolution
        {
            Price = (a.Price + b.Price) / 2
        };
    }
}

👉 These define how evolution behaves.


🚀 Running the Algorithm

Once defined, you plug everything into the engine:

var ga = new GeneticAlgorithm<MySolution>(
    populationSize: 100,
    mutationRate: 0.05,
    crossoverRate: 0.7,
    fitnessEvaluator: new MyFitnessEvaluator(),
    mutationStrategy: new MyMutation(),
    crossoverStrategy: new MyCrossover()
);

ga.Initialize(() => new MySolution
{
    Price = Random.Shared.NextDouble() * 100
});

ga.Run(generations: 200);

var best = ga.GetBestSolution();

Console.WriteLine($"Best price found: {best.Price}");

🧠 How to Think in Evolutionary Terms

Instead of asking:

❌ “How do I solve this problem?”

You ask:

✅ “What does a solution look like?” ✅ “How do I measure if it's good?” ✅ “How can I slightly modify it?”

That’s it.

The algorithm does the rest.


💡 Key Insight

A good evolutionary setup depends on:

  • ✔️ A meaningful fitness function
  • ✔️ A representation that can evolve smoothly
  • ✔️ Balanced mutation (not too random, not too rigid)

⚠️ Common Mistakes

  • ❌ Fitness function too simple → no evolution
  • ❌ Mutation too aggressive → chaos
  • ❌ No diversity → early stagnation
  • ❌ Overfitting to a specific case

🔥 Real Example Ideas

You can build custom evolutions for:

  • 💰 Pricing optimization
  • 📦 Warehouse distribution
  • 🚚 Delivery routes
  • 🧠 AI parameter tuning
  • 🎯 Strategy optimization

🧬 Final Mental Model

Think of DarwinGA as:

A system where you define the rules of survival, and solutions fight to become the best.


Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 74 4/7/2026
1.0.2 87 3/25/2026
1.0.1 78 3/25/2026
1.0.0 84 3/23/2026