Optimization : Optimization Namespace

Fitness Class

Fitness expression class.

public class Fitness : ICloneable

Remarks

Class that represents a solution fitness. This class has two basic modes of operation. In the most simple cases, the fitness can be a single value in which case you can simply set the value of the fitness object (see Fitness.Value). However, the fitness can also be calculated using a mathematical expression using multi modal fitness values as received from evaluating a solution. You can do this by calling Optimization.Math.Expression.Parse on the Fitness.Expression fitness expression. Then you can add additional variables (which can be single values, or mathematical expressions themselves) to be used as a context for evaluating the fitness expression. This is mostly useful for separating different constants in your expressions, or defining subexpressions. Then, when you request the fitness value, the expression will be evaluated with the combined context of variables, and the solution fitness dictionary.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Members

See Also: Inherited members from object.

Public Constructors

Create new fitness.

Public Properties

static
CompareMode Fitness.Mode . Fitness compare mode.
[read-only]
Context Dictionary<string, object> . The fitness context.
[read-only]
Expression Biorob.Math.Expression . The mathematical expression to evaluate.
default property
Item (string) double . Access solution fitness values.
[read-only]
Unknowns string[]. Get unknowns.
Value double . Fitness value.
Values Dictionary<string, double> . Solution fitness values.
[read-only]
Variables Dictionary<string, Fitness.Variable> . Variables.

Public Methods

AddVariable (string, string, Fitness.Mode)
Add a fitness variable.
Clear ()
Clear fitness.
Clone () : object
Create a clone of the fitness object.
static
Compare (Fitness, Fitness) : int
Compare two fitnesses.
static
CompareByMode (Fitness.Mode, double, double) : int
Compare two values based on a fitness mode.
static
ModeAsString (Fitness.Mode) : string
Fitness mode as string.
static
ModeFromString (string) : Fitness.Mode
Fitness mode from string.
Parse (string) : bool
Parse fitness expression.
RemoveVariable (string)
Remove variable.
Reset ()
Reset fitness.
Update ()
Update.

Public Operators

static
GreaterThan (Fitness, Fitness) Compare two fitnesses.
static
LessThan (Fitness, Fitness) Compare two fitnesses.

Member Details

Fitness Constructor

Create new fitness.

public Fitness ()

Remarks

Create new fitness.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

AddVariable Method

Add a fitness variable.

public void AddVariable (string name, string expression, Fitness.Mode mode)

Parameters

name
Varialbe name.
expression
Variable fitness expression.
mode
Variable fitness mode.

Remarks

Add a fitness variable.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Clear Method

Clear fitness.

public void Clear ()

Remarks

Clear fitness.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Clone Method

Create a clone of the fitness object.

public object Clone ()

Returns

A new fitness object.

Remarks

This creates a clone of the fitness object. Note that only the solution fitness values are copied using a deep copy, the mathematical expression and the expression variables are copied by reference.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Compare Method

Compare two fitnesses.

public static int Compare (Fitness a, Fitness b)

Parameters

a
Fitness.
b
Fitness.

Returns

How fitness a compares to fitness b.

Remarks

Compare two fitness objects given their fitness modes. Returns 1 if a is better than b, -1 if b is better than a and 0 if both are equal.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

CompareByMode Method

Compare two values based on a fitness mode.

public static int CompareByMode (Fitness.Mode mode, double a, double b)

Parameters

mode
The fitness mode.
a
Value.
b
Value.

Returns

How a compares to b.

Remarks

Compares two values given the specified fitness mode. Returns 1 if a is better than b, -1 if b is better than a and 0 if both are equal.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

CompareMode Property

Fitness compare mode.

public static Fitness.Mode CompareMode { set; get; }

Value

The fitness compare mode.

Remarks

The fitness compare mode.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Context Property

The fitness context.

public Dictionary<string, object> Context { get; }

Value

The fitness context.

Remarks

Get the fitness context. This contains all the variables of the fitness and can be used to evaluate the fitness expression.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Expression Property

The mathematical expression to evaluate.

public Biorob.Math.Expression Expression { get; }

Value

Mathematical expression.

Remarks

The mathematical expression to evaluate (when set) to calculate the fitness value.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Item Property

Access solution fitness values.

This is the default property for this class.

public double this [string key] { set; get; }

Parameters

key
Fitness name.

Value

Fitness value.

Remarks

Access solution fitness value.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

ModeAsString Method

Fitness mode as string.

public static string ModeAsString (Fitness.Mode mode)

Parameters

mode
The fitness mode.

Returns

Fitness mode as string.

Remarks

Get the fitness mode as string.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

ModeFromString Method

Fitness mode from string.

public static Fitness.Mode ModeFromString (string mode)

Parameters

mode
Fitness mode.

Returns

Fitness mode.

Remarks

Get a fitness mode from a string.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

op_GreaterThan Method

Compare two fitnesses.

public static bool operator> (Fitness first, Fitness second)

Parameters

first
Fitness.
second
Fitness.

Returns

.

Remarks

Compare two fitnesses.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

op_LessThan Method

Compare two fitnesses.

public static bool operator< (Fitness first, Fitness second)

Parameters

first
Fitness.
second
Fitness.

Returns

true if first is greater than second.

Remarks

Compare two fitnesses.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Parse Method

Parse fitness expression.

public bool Parse (string expression)

Parameters

expression
Expression.

Returns

Whether parsing was successful.

Remarks

Parse a fitness expression.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

RemoveVariable Method

Remove variable.

public void RemoveVariable (string name)

Parameters

name
Variable name.

Remarks

Remove a varable.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Reset Method

Reset fitness.

public void Reset ()

Remarks

Resetting the fitness will remove any solution values previously set.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Unknowns Property

Get unknowns.

public string[] Unknowns { get; }

Value

List of unknowns.

Remarks

Get a list of unknown variables in the fitness expression.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Update Method

Update.

public void Update ()

Remarks

Update the fitness.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Value Property

Fitness value.

public double Value { set; get; }

Value

Fitness value.

Remarks

Get or set the final fitness value.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Values Property

Solution fitness values.

public Dictionary<string, double> Values { set; get; }

Value

Fitness values.

Remarks

Fitness values as evaluated for the solution. These values are used as part of the context to evaluate the mathematical expression that computes the fitness.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)

Variables Property

Variables.

public Dictionary<string, Fitness.Variable> Variables { get; }

Value

Variables.

Remarks

Variables used in the context to evaluate the mathematical expression.

Requirements

Namespace: Optimization
Assembly: Optimization (in Optimization.dll)