Table of Contents

Struct RealVector<T>

Namespace
Evolutionary
Assembly
Evolutionary.dll

Represents an immutable real-valued vector individual for continuous evolutionary algorithms.

public readonly struct RealVector<T> : IFormattable, IEquatable<RealVector<T>>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable where T : IFloatingPoint<T>

Type Parameters

T

The floating point type of the vector elements, e.g. double or float.

Implements
Inherited Members

Remarks

A real-valued vector is the natural representation for continuous optimization problems like the minimization of benchmark functions. The default instance of the struct is an empty vector. The values are formatted with the invariant culture unless a format provider is specified - mathematical output is usually easier to read with a fixed culture.

Constructors

RealVector(int)

Initializes a new vector with all values set to zero.

public RealVector(int n)

Parameters

n int

The number of dimensions.

RealVector(T[])

Initializes a new vector from the given array. The array is not copied and not validated.

public RealVector(T[] values)

Parameters

values T[]

The values of the vector.

Properties

Count

Gets the number of dimensions.

public int Count { get; }

Property Value

int

this[int]

Gets the value at the given dimension.

public T this[int index] { get; }

Parameters

index int

The zero-based index of the dimension.

Property Value

T

The value.

Length

Gets the number of dimensions.

public int Length { get; }

Property Value

int

Methods

Equals(RealVector<T>)

Indicates whether the current vector and the given one are equal.

public bool Equals(RealVector<T> other)

Parameters

other RealVector<T>

The other vector.

Returns

bool

true if both vectors are equal.

Equals(object?)

Indicates whether the current vector and the given object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with.

Returns

bool

true if both are equal.

GetEnumerator()

Returns an enumerator that iterates through the values.

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

The enumerator.

GetHashCode()

Returns a hash code for the vector. Two equal vectors have the same hash code.

public override int GetHashCode()

Returns

int

The hash code.

ToArray()

Returns a copy of the values as array.

public T[] ToArray()

Returns

T[]

The values.

ToString()

Returns the values as string, e.g. [0.5, -1.25]. The values are formatted with the invariant culture.

public override string ToString()

Returns

string

The string representation.

ToString(string?)

Returns the values as string, e.g. [1.50, -1.25]. The values are formatted with the given format string and the invariant culture.

public string ToString(string? format)

Parameters

format string

The format to use for every value, or null to use the default format.

Returns

string

The string representation.

ToString(string?, IFormatProvider?)

Returns the values as string, e.g. [1.50, -1.25]. The values are formatted with the given format string.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format to use for every value, or null to use the default format.

formatProvider IFormatProvider

The format provider to use, or null to use the invariant culture.

Returns

string

The string representation.

Operators

operator ==(RealVector<T>, RealVector<T>)

Indicates whether two vectors are equal.

public static bool operator ==(RealVector<T> lhs, RealVector<T> rhs)

Parameters

lhs RealVector<T>

The first vector.

rhs RealVector<T>

The second vector.

Returns

bool

true if both vectors are equal.

operator !=(RealVector<T>, RealVector<T>)

Indicates whether two vectors are not equal.

public static bool operator !=(RealVector<T> lhs, RealVector<T> rhs)

Parameters

lhs RealVector<T>

The first vector.

rhs RealVector<T>

The second vector.

Returns

bool

true if both vectors are not equal.