/// ------------------------------------------------------
/// SwarmOps - Numeric and heuristic optimization for C#
/// Copyright (C) 2003-2011 Magnus Erik Hvass Pedersen.
/// Please see the file license.txt for license details.
/// SwarmOps on the internet: http://www.Hvass-Labs.org/
/// ------------------------------------------------------
using System.Diagnostics;
namespace SwarmOps
{
public static partial class Tools
{
///
/// Initialize array with value.
///
/// Array to be initialized.
/// Value.
public static void Initialize(ref double[] x, double value)
{
for (int i = 0; i < x.Length; i++)
{
x[i] = value;
}
}
///
/// Initialize array with uniform random values between given boundaries.
///
/// Array to be initialized.
/// Lower boundary.
/// Upper boundary.
public static void InitializeUniform(ref double[] x, double lower, double upper)
{
for (int i = 0; i < x.Length; i++)
{
x[i] = Globals.Random.Uniform(lower, upper);
}
}
///
/// Initialize array with uniform random values between given boundaries.
///
/// Array to be initialized.
/// Array of lower boundary.
/// Array of upper boundary.
public static void InitializeUniform(ref double[] x, double[] lower, double[] upper)
{
for (int i = 0; i < x.Length; i++)
{
x[i] = Globals.Random.Uniform(lower[i], upper[i]);
}
}
///
/// Initialize array with the range between the boundaries.
/// That is, x[i] = upper[i]-lower[i].
///
/// Array to be initialized.
/// Lower boundary.
/// Upper boundary.
public static void InitializeRange(ref double[] x, double[] lower, double[] upper)
{
for (int i = 0; i < x.Length; i++)
{
x[i] = upper[i] - lower[i];
Debug.Assert(x[i] >= 0);
}
}
}
}