cs-swarm-intelligence 1.0.1

dotnet add package cs-swarm-intelligence --version 1.0.1                
NuGet\Install-Package cs-swarm-intelligence -Version 1.0.1                
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="cs-swarm-intelligence" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add cs-swarm-intelligence --version 1.0.1                
#r "nuget: cs-swarm-intelligence, 1.0.1"                
#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.
// Install cs-swarm-intelligence as a Cake Addin
#addin nuget:?package=cs-swarm-intelligence&version=1.0.1

// Install cs-swarm-intelligence as a Cake Tool
#tool nuget:?package=cs-swarm-intelligence&version=1.0.1                

cs-swarm-intelligence

Swam intelligence for numerical optimization implemented in .NET

Features

The current library support optimization problems in which solutions are either discrete or continuous vectors. The algorithms implemented for swarm-intelligence are listed below:

  • Particle Swarm Optimization (PSO)
  • Bees Algorithm
  • Ant Colony System

Usage

Running PSO

The sample codes below shows how to solve the "Rosenbrock Saddle" continuous optmization problem using PSO:

int maxIterations = 2000;
int dimension = 2;
int popSize = 200;
double[] lowerBounds = new double[] { -2.048, -2.048 };
double[] upperBounds = new double[] { 2.048, 2.048 };
SimpleParticle finalSolution;

ParticleSwarm<SimpleParticle>.Solve(popSize, dimension, (solution, constraints) =>
{
	// this is the Rosenbrock Saddle cost function
	double[] positions = solution.Positions;
	double x0 = positions[0];
	double x1 = positions[1];

	double cost = 100 * Math.Pow(x0 * x0 - x1, 2) + Math.Pow(1 - x0, 2);
	return cost;
}, lowerBounds, upperBounds, out finalSolution, maxIterations);

Running Bees Algorithm

The sample codes below shows how to solve the "Rosenbrock Saddle" continuous optmization problem using Bees Algorithm:

int maxIterations = 2000;
int dimension = 2;
int displayEvery = 10;
double[] lowerBounds = new double[] { -2.048, -2.048 };
double[] upperBounds = new double[] { 2.048, 2.048 };
SimpleBee finalSolution;

BeeSwarm<SimpleBee>.Solve(dimension, (solution) =>
{
	// this is the Rosenbrock Saddle cost function
	
	double x0 = solution[0];
	double x1 = solution[1];

	double cost = 100 * Math.Pow(x0 * x0 - x1, 2) + Math.Pow(1 - x0, 2);
	return cost;
}, out finalSolution, lowerBounds, upperBounds, maxIterations, displayEvery);

Ant Colony System

The sample codes belows show to solve the Travelling Salesman Problem (TSP) using Ant Colony System:

int populationSize = 100;

SimpleAnt bestSolution;
TspBenchmark tsp = Tsp.get(Tsp.Instance.bayg29);
int problemSize = tsp.ProblemSize();
int displayEvery = 10;
int maxIterations = 1000;
AntColonySystem<SimpleAnt>.SolveByAntColonySystem(populationSize, problemSize
, solution => // this returns the cost of the solution which in the case of the TSP is the total distance of visiting every cities exactly once using the route represented by the solution 
{
	double cost = 0;
	for(int i=0; i < solution.Length; ++i)
	{
		int j = (i + 1) % solution.Length;
		int v = solution[i];
		int w = solution[j];
		cost += tsp.Distance(v, w);
	}
	return cost;
}, (state1, state2) => // this returns the heuristic value for a move from state1 to state2
{ 
	return 1.0 / (1.0 + tsp.Distance(state1, state2));
}, displayEvery, out bestSolution, null, maxIterations);

Ant System

The sample codes belows show to solve the Travelling Salesman Problem (TSP) using Ant System:


int populationSize = 100;
            
SimpleAnt bestSolution;
TspBenchmark tsp = Tsp.get(Tsp.Instance.bayg29);
int problemSize = tsp.ProblemSize();
int displayEvery = 10;
int maxIterations = 1000;
AntSystem<SimpleAnt>.SolveByAntSystem(populationSize, problemSize, solution =>
{
	double cost = 0;
	for(int i=0; i < solution.Length; ++i)
	{
		int j = (i + 1) % solution.Length;
		int v = solution[i];
		int w = solution[j];
		cost += tsp.Distance(v, w);
	}
	return cost;
}, (state1, state2) =>
{
	return 1.0 / (1.0 + tsp.Distance(state1, state2));
}, displayEvery, out bestSolution, null, maxIterations);
Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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.1 1,199 12/2/2017

Swarm Intelligence and Optimization in .NET 4.5.2