HBA.Evolutionary
1.0.0
dotnet add package HBA.Evolutionary --version 1.0.0
NuGet\Install-Package HBA.Evolutionary -Version 1.0.0
<PackageReference Include="HBA.Evolutionary" Version="1.0.0" />
<PackageVersion Include="HBA.Evolutionary" Version="1.0.0" />
<PackageReference Include="HBA.Evolutionary" />
paket add HBA.Evolutionary --version 1.0.0
#r "nuget: HBA.Evolutionary, 1.0.0"
#:package HBA.Evolutionary@1.0.0
#addin nuget:?package=HBA.Evolutionary&version=1.0.0
#tool nuget:?package=HBA.Evolutionary&version=1.0.0
HBA.Evolutionary
Biblioteca de algoritmos evolutivos para .NET que implementa:
- GA clásico (
GeneticAlgorithm): optimizacion de un único objetivo. - NSGA-II (
NSGA2): optimizacion multiobjetivo con frente de Pareto.
La convencion de la biblioteca es:
Mayor valor = mejor resultado.
Si un objetivo se minimiza (costo, error, distancia), transformelo a maximizar, por ejemplo usando -costo o 1.0 / (1.0 + costo).
Caracteristicas
- API genetica basada en cromosomas (
ICustomChromosome). - Soporte para problemas de un objetivo (
ISingleObjectiveChromosome) y multiobjetivo (IMultiObjectiveChromosome). - Configuracion flexible:
CrossoverProbability,MutationProbability.- Estrategias de crossover y mutacion personalizables.
- Semilla (
Seed) para reproducibilidad.
- Callbacks de progreso por generacion.
- Implementacion de NSGA-II con:
- Non-dominated sorting.
- Crowding distance.
- Frente de Pareto final.
Instalacion
dotnet add package HBA.Evolutionary
O desde la consola de NuGet:
Install-Package HBA.Evolutionary
Uso rapido
GA: maximizar unos en un vector binario
using HBA.Evolutionary.Core;
using HBA.Evolutionary.GeneticAlgorithm;
public sealed class BitChromosome : ISingleObjectiveChromosome
{
public bool[] Genes { get; set; } = new bool[20];
public void Randomize(GeneticRandom random)
{
for (int i = 0; i < Genes.Length; i++)
Genes[i] = random.NextDouble() < 0.5;
}
public double EvaluateFitness()
{
return Genes.Count(g => g);
}
public ICustomChromosome Clone()
{
return new BitChromosome
{
Genes = (bool[])Genes.Clone()
};
}
}
public sealed class BitCrossover : ICrossover<BitChromosome>
{
public BitChromosome Apply(
BitChromosome parent1,
BitChromosome parent2,
GeneticRandom random)
{
var child = new BitChromosome();
int cut = random.Next(1, parent1.Genes.Length);
for (int i = 0; i < child.Genes.Length; i++)
{
child.Genes[i] = i < cut
? parent1.Genes[i]
: parent2.Genes[i];
}
return child;
}
}
public sealed class BitMutation : IMutation<BitChromosome>
{
public void Apply(BitChromosome chromosome, GeneticRandom random)
{
int position = random.Next(chromosome.Genes.Length);
chromosome.Genes[position] = !chromosome.Genes[position];
}
}
Ejecucion:
var configuration = new GeneticConfiguration<BitChromosome>
{
CrossoverProbability = 0.90,
MutationProbability = 0.10,
Seed = 42,
Crossover = new BitCrossover(),
Mutation = new BitMutation()
};
var best = GeneticAlgorithmSolver.Solve(
prototype: new BitChromosome(),
selection: new TournamentSelection<BitChromosome>(size: 3),
populationSize: 100,
generations: 100,
configuration: configuration,
onGenerationCompleted: (generation, fitness) =>
{
if (generation % 10 == 0)
Console.WriteLine($"Generacion {generation}: {fitness}");
});
Console.WriteLine($"Mejor fitness: {best.EvaluateFitness()}");
NSGA-II: dos objetivos en conflicto
Objetivo 1: maximizar x.
Objetivo 2: maximizar 10 - x.
using HBA.Evolutionary.Core;
using HBA.Evolutionary.MultiObjetive;
public sealed class TradeoffChromosome : IMultiObjectiveChromosome
{
public double X { get; set; }
public int Rank { get; set; }
public double CrowdingDistance { get; set; }
public void Randomize(GeneticRandom random)
{
X = 10.0 * random.NextDouble();
}
public double[] EvaluateObjectives()
{
return new[]
{
X, // Mayor X es mejor.
10.0 - X // Menor X es mejor, transformado.
};
}
public ICustomChromosome Clone()
{
return new TradeoffChromosome
{
X = X,
Rank = Rank,
CrowdingDistance = CrowdingDistance
};
}
}
public sealed class TradeoffCrossover
: ICrossover<TradeoffChromosome>
{
public TradeoffChromosome Apply(
TradeoffChromosome parent1,
TradeoffChromosome parent2,
GeneticRandom random)
{
double alpha = random.NextDouble();
return new TradeoffChromosome
{
X = alpha * parent1.X + (1.0 - alpha) * parent2.X
};
}
}
public sealed class TradeoffMutation
: IMutation<TradeoffChromosome>
{
public void Apply(
TradeoffChromosome chromosome,
GeneticRandom random)
{
double change = (random.NextDouble() * 2.0 - 1.0) * 0.5;
chromosome.X = Math.Clamp(
chromosome.X + change,
0.0,
10.0);
}
}
Ejecucion:
var configuration = new GeneticConfiguration<TradeoffChromosome>
{
CrossoverProbability = 0.90,
MutationProbability = 0.20,
Seed = 42,
Crossover = new TradeoffCrossover(),
Mutation = new TradeoffMutation()
};
var pareto = NSGA2Solver.Solve(
prototype: new TradeoffChromosome(),
populationSize: 100,
generations: 200,
configuration: configuration,
onGenerationCompleted: (generation, front) =>
{
if (generation % 20 == 0)
Console.WriteLine(
$"Generacion {generation}: " +
$"{front.Count} soluciones Pareto");
});
foreach (var solution in pareto.OrderBy(s => s.X))
{
var objectives = solution.EvaluateObjectives();
Console.WriteLine(
$"X={solution.X:F4}, " +
$"obj1={objectives[0]:F4}, " +
$"obj2={objectives[1]:F4}");
}
Cuadro comparativo
| Caracteristica | GA | NSGA-II |
|---|---|---|
| Objetivos | Uno | Dos o mas |
| Evaluacion | EvaluateFitness() |
EvaluateObjectives() |
| Resultado | Mejor cromosoma | Frente de Pareto (lista) |
| Comparacion | Mayor fitness | Dominancia, Rank y Crowding |
| Uso tipico | Una metrica principal | Compromisos entre objetivos |
Recomendaciones de parametros
Como punto de partida:
- Problema sencillo:
populationSize = 100,generations = 100–300. - Crossover:
0.90. - Mutacion:
0.05–0.15. - Use
Seedsi necesita reproducibilidad.
Licencia
HBA.Evolutionary es software propietario desarrollado por HbaTech.
La biblioteca se distribuye gratuitamente bajo la HBA.Evolutionary Free Use License (EULA).
Se permite:
- Usar HBA.Evolutionary en proyectos personales, académicos y comerciales.
- Incorporar HBA.Evolutionary como motor o dependencia de aplicaciones propias.
- Crear y comercializar aplicaciones que utilicen HBA.Evolutionary.
- Crear cromosomas, operadores de crossover, mutaciones y demás componentes propios.
- Distribuir aplicaciones que incluyan o utilicen HBA.Evolutionary.
No se permite:
- Modificar el código fuente de HBA.Evolutionary.
- Crear y distribuir versiones modificadas de HBA.Evolutionary.
- Presentar HBA.Evolutionary como software desarrollado por terceros.
- Vender HBA.Evolutionary como producto o biblioteca independiente.
- Eliminar los avisos de copyright y atribución de HbaTech.
- Utilizar el nombre o la marca HBA.Evolutionary para hacer creer que un producto de terceros es oficial de HbaTech.
El uso de HBA.Evolutionary no transfiere ningún derecho de propiedad intelectual sobre la biblioteca. Los derechos sobre HBA.Evolutionary permanecen en HbaTech.
Para consultar los términos completos, vea el archivo LICENSE.
| Product | Versions 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. |
-
net8.0
- No dependencies.
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.0 | 107 | 9/9/2026 |