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
- Implements
-
IEquatable<RealVector<T>>IEnumerable<T>
- 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
nintThe 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
valuesT[]The values of the vector.
Properties
Count
Gets the number of dimensions.
public int Count { get; }
Property Value
this[int]
Gets the value at the given dimension.
public T this[int index] { get; }
Parameters
indexintThe zero-based index of the dimension.
Property Value
- T
The value.
Length
Gets the number of dimensions.
public int Length { get; }
Property Value
Methods
Equals(RealVector<T>)
Indicates whether the current vector and the given one are equal.
public bool Equals(RealVector<T> other)
Parameters
otherRealVector<T>The other vector.
Returns
Equals(object?)
Indicates whether the current vector and the given object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with.
Returns
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
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
formatstringThe format to use for every value, or null to use the default format.
formatProviderIFormatProviderThe 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
lhsRealVector<T>The first vector.
rhsRealVector<T>The second vector.
Returns
operator !=(RealVector<T>, RealVector<T>)
Indicates whether two vectors are not equal.
public static bool operator !=(RealVector<T> lhs, RealVector<T> rhs)
Parameters
lhsRealVector<T>The first vector.
rhsRealVector<T>The second vector.