#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using HeuristicLab.Core;
using HeuristicLab.Data;
namespace HeuristicLab.IntVector {
///
/// Uniformly distributed change of all positions of an integer vector.
///
public class UniformAllPositionsManipulator : IntVectorManipulatorBase {
///
public override string Description {
get { return "Uniformly distributed change of all positions of an integer vector."; }
}
///
/// Initializes a new instance of with two variable infos
/// (Minimum and Maximum).
///
public UniformAllPositionsManipulator() {
AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(IntData), VariableKind.In));
AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(IntData), VariableKind.In));
}
///
/// Changes all positions in the given integer .
///
/// A random number generator.
/// The integer vector to manipulate.
/// The minimum value of the sampling range for each vector element (inclusive).
/// The maximum value of the sampling range for each vector element (exclusive).
/// The new integer vector which has been manipulated.
public static int[] Apply(IRandom random, int[] vector, int min, int max) {
int[] result = new int[vector.Length];
for (int i = 0; i < result.Length; i++)
result[i] = random.Next(min, max);
return result;
}
///
/// Changes all positions in the given integer .
///
/// Calls .
/// The current scope.
/// A random number generator.
/// The integer vector to manipulate.
/// The new integer vector which has been manipulated.
protected override int[] Manipulate(IScope scope, IRandom random, int[] vector) {
int min = GetVariableValue("Minimum", scope, true).Data;
int max = GetVariableValue("Maximum", scope, true).Data;
return Apply(random, vector, min, max);
}
}
}