forked from giacomelli/GeneticSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuncFitness.cs
35 lines (32 loc) · 946 Bytes
/
FuncFitness.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using GeneticSharp.Domain.Chromosomes;
using GeneticSharp.Infrastructure.Framework.Commons;
namespace GeneticSharp.Domain.Fitnesses
{
/// <summary>
/// An IFitness implementation that defer the fitness evaluation to a Func.
/// </summary>
public class FuncFitness : IFitness
{
private readonly Func<IChromosome, double> m_func;
/// <summary>
/// Initializes a new instance of the <see cref="T:GeneticSharp.Domain.Fitnesses.FuncFitness"/> class.
/// </summary>
/// <param name="func">The fitness evaluation Func.</param>
public FuncFitness (Func<IChromosome, double> func)
{
ExceptionHelper.ThrowIfNull("func", func);
m_func = func;
}
#region IFitness implementation
/// <summary>
/// Evaluate the specified chromosome.
/// </summary>
/// <param name="chromosome">Chromosome.</param>
public double Evaluate (IChromosome chromosome)
{
return m_func (chromosome);
}
#endregion
}
}