C# Class SwarmOps.Tools

Show file Open project: DanWBR/dwsim3

Public Methods

Method Description
ArrayToString ( double x ) : string

Convert an array of System.double values to a string.

ArrayToString ( double x, int digits ) : string

Convert an array of System.double values to a string.

ArrayToStringRaw ( double x ) : string

Convert an array of System.double values to a string. Not formatted like a C# array.

ArrayToStringRaw ( double x, int digits ) : string

Convert an array of System.double values to a string. Not formattet like a C# array.

BetterFeasible ( bool oldFeasible, bool newFeasible ) : bool

Return whether feasibility (constraint satisfaction) of new candidate solution is same as or better than feasibility of old candidate solution.

BetterFeasibleFitness ( bool oldFeasible, bool newFeasible, double oldFitness, double newFitness ) : bool

Return whether the new candidate solution is better than the old, depending on their feasibility (constraint satisfaction) and fitness.

BetweenBounds ( double x, double lower, double upper ) : bool

Return whether array of values is between lower and upper boundaries.

Bound ( double x, double lower, double upper ) : double

Bound a value between lower and upper boundaries.

Bound ( double &x, double lower, double upper ) : void

Bound array of values between lower and upper boundaries.

Denormalize ( double x ) : double

Return denormalized version of x. This is useful for avoiding expensive CPU usage when x underflows.

Denormalize ( double &x ) : void

Denormalize an array.

DenormalizeTruncate ( double x ) : double

If Abs(x) is below a limit then it is set to zero.

FormatNumber ( double d ) : string

Convert numeric value d to a string with convenient formatting.

FormatPercent ( double d ) : string

Convert numeric value d to a percentage string, e.g. d==0.253212 returns string "25.32%"

Initialize ( double &x, double value ) : void

Initialize array with value.

InitializeRange ( double &x, double lower, double upper ) : void

Initialize array with the range between the boundaries. That is, x[i] = upper[i]-lower[i].

InitializeUniform ( double &x, double lower, double upper ) : void

Initialize array with uniform random values between given boundaries.

NewMatrix ( int dim1, int dim2 ) : double[][]

Allocate and return a new matrix double[dim1][dim2].

Norm ( double x ) : double

Euclidian norm (or length) of a numeric vector.

NumberToString ( double x, int digits ) : string

Convert a double-value to a string, formatted for array output.

PrintNewline ( ) : void

Print a newline to Console.

PrintParameters ( Problem problem, double parameters ) : void

Print parameters using names associated with an optimization problem.

PrintSolution ( double parameters, double fitness, double fitnessLimit, bool oldFeasible, bool newFeasible, bool formatAsArray ) : void

Print parameters, fitness and feasibility to Console, and print a marking if fitness was an improvement to fitnessLimit.

Sample ( double x, double range ) : double

Pick a uniform random sample from [x-range, x+range].

SampleBounded ( double x, double range, double lowerBound, double upperBound ) : double

First bound the sampling range [x-range, x+range] using lowerBound and upperBound respectively, and then pick a uniform random sample from the bounded range. This avoids samples being boundary points.

Method Details

ArrayToString() public static method

Convert an array of System.double values to a string.
public static ArrayToString ( double x ) : string
x double Array of values to be converted to string.
return string

ArrayToString() public static method

Convert an array of System.double values to a string.
public static ArrayToString ( double x, int digits ) : string
x double Array of values to be converted to string.
digits int Number of digits for each value.
return string

ArrayToStringRaw() public static method

Convert an array of System.double values to a string. Not formatted like a C# array.
public static ArrayToStringRaw ( double x ) : string
x double Array of values to be converted to string.
return string

ArrayToStringRaw() public static method

Convert an array of System.double values to a string. Not formattet like a C# array.
public static ArrayToStringRaw ( double x, int digits ) : string
x double Array of values to be converted to string.
digits int Number of digits for each value.
return string

BetterFeasible() public static method

Return whether feasibility (constraint satisfaction) of new candidate solution is same as or better than feasibility of old candidate solution.
public static BetterFeasible ( bool oldFeasible, bool newFeasible ) : bool
oldFeasible bool Feasibility of old candidate solution.
newFeasible bool Feasibility of new candidate solution.
return bool

BetterFeasibleFitness() public static method

Return whether the new candidate solution is better than the old, depending on their feasibility (constraint satisfaction) and fitness.
public static BetterFeasibleFitness ( bool oldFeasible, bool newFeasible, double oldFitness, double newFitness ) : bool
oldFeasible bool Feasibility of old candidate solution.
newFeasible bool Feasibility of new candidate solution.
oldFitness double Fitness of old candidate solution.
newFitness double Fitness of new candidate solution.
return bool

BetweenBounds() public static method

Return whether array of values is between lower and upper boundaries.
public static BetweenBounds ( double x, double lower, double upper ) : bool
x double Array of values to be bounded.
lower double Lower boundaries.
upper double Upper boundaries.
return bool

Bound() public static method

Bound a value between lower and upper boundaries.
public static Bound ( double x, double lower, double upper ) : double
x double Parameter to be bounded.
lower double Lower boundary.
upper double Upper boundary.
return double

Bound() public static method

Bound array of values between lower and upper boundaries.
public static Bound ( double &x, double lower, double upper ) : void
x double Array of values to be bounded.
lower double Lower boundaries.
upper double Upper boundaries.
return void

Denormalize() public static method

Return denormalized version of x. This is useful for avoiding expensive CPU usage when x underflows.
public static Denormalize ( double x ) : double
x double
return double

Denormalize() public static method

Denormalize an array.
public static Denormalize ( double &x ) : void
x double
return void

DenormalizeTruncate() public static method

If Abs(x) is below a limit then it is set to zero.
public static DenormalizeTruncate ( double x ) : double
x double
return double

FormatNumber() public static method

Convert numeric value d to a string with convenient formatting.
public static FormatNumber ( double d ) : string
d double
return string

FormatPercent() public static method

Convert numeric value d to a percentage string, e.g. d==0.253212 returns string "25.32%"
public static FormatPercent ( double d ) : string
d double
return string

Initialize() public static method

Initialize array with value.
public static Initialize ( double &x, double value ) : void
x double Array to be initialized.
value double Value.
return void

InitializeRange() public static method

Initialize array with the range between the boundaries. That is, x[i] = upper[i]-lower[i].
public static InitializeRange ( double &x, double lower, double upper ) : void
x double Array to be initialized.
lower double Lower boundary.
upper double Upper boundary.
return void

InitializeUniform() public static method

Initialize array with uniform random values between given boundaries.
public static InitializeUniform ( double &x, double lower, double upper ) : void
x double Array to be initialized.
lower double Lower boundary.
upper double Upper boundary.
return void

NewMatrix() public static method

Allocate and return a new matrix double[dim1][dim2].
public static NewMatrix ( int dim1, int dim2 ) : double[][]
dim1 int
dim2 int
return double[][]

Norm() public static method

Euclidian norm (or length) of a numeric vector.
public static Norm ( double x ) : double
x double
return double

NumberToString() public static method

Convert a double-value to a string, formatted for array output.
public static NumberToString ( double x, int digits ) : string
x double Value to convert.
digits int Number of digits.
return string

PrintNewline() public static method

Print a newline to Console.
public static PrintNewline ( ) : void
return void

PrintParameters() public static method

Print parameters using names associated with an optimization problem.
public static PrintParameters ( Problem problem, double parameters ) : void
problem Problem Optimization problem with associated parameter-names.
parameters double Parameters to be printed.
return void

PrintSolution() public static method

Print parameters, fitness and feasibility to Console, and print a marking if fitness was an improvement to fitnessLimit.
public static PrintSolution ( double parameters, double fitness, double fitnessLimit, bool oldFeasible, bool newFeasible, bool formatAsArray ) : void
parameters double
fitness double
fitnessLimit double
oldFeasible bool
newFeasible bool
formatAsArray bool
return void

Sample() public static method

Pick a uniform random sample from [x-range, x+range].
public static Sample ( double x, double range ) : double
x double
range double
return double

SampleBounded() public static method

First bound the sampling range [x-range, x+range] using lowerBound and upperBound respectively, and then pick a uniform random sample from the bounded range. This avoids samples being boundary points.
public static SampleBounded ( double x, double range, double lowerBound, double upperBound ) : double
x double
range double
lowerBound double
upperBound double
return double