### Installing GeneticSharp Core Package (.NET 6) - Shell
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command installs the core GeneticSharp NuGet package for .NET 6 projects. It provides the fundamental components of the genetic algorithm library without extensions, serving as the basic setup for integrating GeneticSharp into a .NET 6 application.
```shell
install-package GeneticSharp
```
--------------------------------
### Running a Genetic Algorithm Instance (C#)
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This C# code snippet demonstrates the setup and execution of a genetic algorithm using GeneticSharp. It initializes key components like selection, crossover, mutation, fitness, and chromosome, then creates a population and a GeneticAlgorithm instance. The Termination condition is set, and the Start method initiates the evolutionary process, finally printing the fitness of the best solution found.
```csharp
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);
```
--------------------------------
### Installing GeneticSharp Extensions Package (.NET 6) - Shell
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command installs the GeneticSharp.Extensions NuGet package for .NET 6 projects. This package includes various pre-built components and examples such as TSP, AutoConfig, Bitmap equality, and Equation Solver, providing a richer set of functionalities for common genetic algorithm problems.
```shell
install-package GeneticSharp.Extensions
```
--------------------------------
### Installing GeneticSharp Templates with dotnet new (Shell)
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command installs the `GeneticSharp.Templates` NuGet package, making its project templates available for use with the `dotnet new` command-line interface. It is a necessary first step to create new projects based on GeneticSharp's pre-defined structures, enabling rapid setup for genetic algorithm applications.
```shell
dotnet new -i GeneticSharp.Templates
```
--------------------------------
### Installing GeneticSharp for .NET Framework 3.5 - Shell
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command installs a very old version (1.2.0) of the GeneticSharp NuGet package. This specific version is required for compatibility with projects targeting the .NET Framework 3.5, catering to very old application environments.
```shell
install-package GeneticSharp -Version 1.2.0
```
--------------------------------
### Installing GeneticSharp for .NET Standard 2.0 / .NET Framework 4.6.2 - Shell
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command installs a specific older version (2.6.0) of the GeneticSharp NuGet package. This version is compatible with projects targeting .NET Standard 2.0 and .NET Framework 4.6.2, providing support for legacy or specific environment requirements.
```shell
install-package GeneticSharp -Version 2.6.0
```
--------------------------------
### Creating TSP Unity3D Application with dotnet new (Shell)
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command creates a new Unity3D project template, integrated with GeneticSharp and specifically set up to solve the Travelling Salesman Problem (TSP). The `-n` parameter defines the root namespace for the generated project, and the `-o` parameter specifies the output directory where the Unity project will be initialized.
```shell
dotnet new GeneticSharpTspUnity3d -n MyNamespace -o MyOutoputFolder
```
--------------------------------
### Creating Generic Console Application with dotnet new (Shell)
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command creates a new console application project integrated with GeneticSharp, providing a basic structure for genetic algorithm implementations. Users are required to implement their specific chromosome and fitness functions to define the algorithm's behavior. The `-n` parameter sets the namespace, and `-o` specifies the output folder for the new project.
```shell
dotnet new GeneticSharpConsoleApp -n MyNamespace -o MyOutoputFolder
```
--------------------------------
### Creating TSP Blazor Application with dotnet new (Shell)
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command generates a new Blazor client application project, pre-configured with GeneticSharp to solve the Travelling Salesman Problem (TSP). The `-n` parameter sets the root namespace for the generated project files, and the `-o` parameter specifies the output directory where the new project will be created.
```shell
dotnet new GeneticSharpTspBlazorApp -n MyNamespace -o MyOutoputFolder
```
--------------------------------
### Creating TSP Console Application with dotnet new (Shell)
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This command generates a new console application project, pre-configured with GeneticSharp to solve the Travelling Salesman Problem (TSP). Similar to other templates, the `-n` parameter defines the project's root namespace, and the `-o` parameter specifies the output directory for the newly created project files.
```shell
dotnet new GeneticSharpTspConsoleApp -n MyNamespace -o MyOutoputFolder
```
--------------------------------
### Implementing Custom Chromosome (C#)
Source: https://github.com/giacomelli/geneticsharp/blob/master/README.md
This C# code snippet illustrates how to define a custom chromosome by inheriting from ChromosomeBase. The constructor sets the chromosome length, GenerateGene defines how individual genes are created, and CreateNew provides a factory method for creating new instances. This class represents the solution encoding for the genetic algorithm.
```csharp
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();
}
}
```
--------------------------------
### Displaying Open Iconic Font Standalone
Source: https://github.com/giacomelli/geneticsharp/blob/master/src/GeneticSharp.Runner.BlazorApp/wwwroot/css/open-iconic/README.md
This HTML snippet demonstrates how to display an Open Iconic font icon when used standalone. The oi class initializes the icon font, and data-glyph specifies the particular icon to display, with title and aria-hidden for accessibility.
```HTML
```
--------------------------------
### Initializing Google Analytics with gtag.js - JavaScript
Source: https://github.com/giacomelli/geneticsharp/blob/master/src/GeneticSharp.Runner.BlazorApp/tools/jekyll-files/index.html
This snippet initializes Google Analytics using the gtag.js library. It sets up the 'dataLayer' array, defines the 'gtag' function to push events, and configures the tracking ID 'UA-50922592-1'. It is typically used for website analytics and tracking.
```JavaScript
window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-50922592-1');
```
--------------------------------
### Rewriting URLs for GitHub Pages SPAs in JavaScript
Source: https://github.com/giacomelli/geneticsharp/blob/master/src/GeneticSharp.Runner.BlazorApp/tools/jekyll-files/404.html
This JavaScript snippet redirects the browser by converting the current URL's path and query string into a single query parameter (e.g., 'p' for path, 'q' for query) to support single-page applications on GitHub Pages. It handles custom domains and project pages by adjusting 'segmentCount' to preserve the base path, ensuring the client-side router receives the full intended route.
```JavaScript
var segmentCount = 0; var l = window.location; l.replace( l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') + l.pathname.split('/').slice(0, 1 + segmentCount).join('/') + '/?p=/' + l.pathname.slice(1).split('/').slice(segmentCount).join('/').replace(/&/g, '~and~') + (l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') + l.hash );
```
--------------------------------
### Linking Open Iconic Standalone Stylesheet
Source: https://github.com/giacomelli/geneticsharp/blob/master/src/GeneticSharp.Runner.BlazorApp/wwwroot/css/open-iconic/README.md
This HTML snippet shows how to link the default Open Iconic stylesheet for standalone usage, without Bootstrap or Foundation. This stylesheet provides the necessary CSS classes to use Open Iconic as an icon font in any web project.
```HTML
```
--------------------------------
### Using Open Iconic SVG Sprite in HTML
Source: https://github.com/giacomelli/geneticsharp/blob/master/src/GeneticSharp.Runner.BlazorApp/wwwroot/css/open-iconic/README.md
This HTML snippet shows how to reference an icon from an Open Iconic SVG sprite using the