本文整理汇总了C#中IntValue类的典型用法代码示例。如果您正苦于以下问题:C# IntValue类的具体用法?C# IntValue怎么用?C# IntValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IntValue类属于命名空间,在下文中一共展示了IntValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AntTrail
public AntTrail(BoolMatrix world, SymbolicExpressionTree expression, IntValue maxTimeSteps)
: this() {
this.world = world;
this.expression = expression;
this.maxTimeSteps = maxTimeSteps;
Initialize();
}
示例2: TestUpdateBranchingNameSpaces
public void TestUpdateBranchingNameSpaces()
{
Dictionary dictionary = CreateDictionary("Test");
NameSpace nameSpace = CreateNameSpace(dictionary, "N");
NameSpace nameSpace1 = CreateNameSpace(nameSpace, "N1");
NameSpace nameSpace2 = CreateNameSpace(nameSpace, "N2");
Function function1 = CreateFunction(nameSpace1, "f", "Bool");
Case cas1 = CreateCase(function1, "Case 1", "N2.q()");
Function function2 = CreateFunction(nameSpace2, "q", "Bool");
Case cas2 = CreateCase(function2, "Case 1", "True");
Dictionary dictionary2 = CreateDictionary("TestUpdate");
dictionary2.setUpdates(dictionary.Guid);
Function updateFunction1 = function1.CreateFunctionUpdate(dictionary2);
updateFunction1.TypeName = "Integer";
Case updcas1 = (Case) updateFunction1.Cases[0];
updcas1.ExpressionText = "2";
PreCondition precond = CreatePreCondition(updcas1, "N2.q()");
Case newCase = CreateCase(updateFunction1, "Case 2", "1");
Function updateFunction2 = function2.CreateFunctionUpdate(dictionary2);
((Case) updateFunction2.Cases[0]).ExpressionText = "False";
Compiler.Compile_Synchronous(true);
Expression expression = Parser.Expression(dictionary, "N.N1.f()");
IValue value = expression.GetValue(new InterpretationContext(), null);
IValue refVal = new IntValue(System.IntegerType, 1);
Assert.AreEqual(refVal.LiteralName, value.LiteralName);
}
示例3: read
public Value read(BinaryReader reader)
{
IntValue ret = new IntValue();
int val = reader.ReadInt32();
ret.value = val;
return ret;
}
示例4: Add
public void Add()
{
var three = new IntValue(3);
var five = new IntValue(5);
var threePlusFive = three + five;
AssertEquals(threePlusFive.Value, 8);
}
示例5: MichalewiczNonUniformAllPositionsManipulatorApplyTest
public void MichalewiczNonUniformAllPositionsManipulatorApplyTest() {
TestRandom random = new TestRandom();
RealVector parent, expected;
DoubleValue generationsDependency;
DoubleMatrix bounds;
IntValue currentGeneration, maximumGenerations;
bool exceptionFired;
// The following test is not based on published examples
random.Reset();
random.DoubleNumbers = new double[] { 0.2, 0.5, 0.7, 0.8, 0.9, 0.5, 0.2, 0.5, 0.7, 0.8 };
parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
expected = new RealVector(new double[] { 0.45, 0.22, 0.3, 0.6, 0.14 });
bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
generationsDependency = new DoubleValue(0.1);
currentGeneration = new IntValue(1);
maximumGenerations = new IntValue(4);
MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
// The following test is not based on published examples
exceptionFired = false;
random.Reset();
random.DoubleNumbers = new double[] { 0.2, 0.5, 0.7, 0.8, 0.9, 0.5, 0.2, 0.5, 0.7, 0.8 };
parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
bounds = new DoubleMatrix(new double[,] { { 0.3, 0.7 } });
generationsDependency = new DoubleValue(0.1);
currentGeneration = new IntValue(5); //current generation > max generation
maximumGenerations = new IntValue(4);
try {
MichalewiczNonUniformAllPositionsManipulator.Apply(random, parent, bounds, currentGeneration, maximumGenerations, generationsDependency);
} catch (System.ArgumentException) {
exceptionFired = true;
}
Assert.IsTrue(exceptionFired);
}
示例6: Apply
public static ItemArray<IItem> Apply(IItem initiator, IItem guide, IntValue k, PercentValue n) {
if (!(initiator is RealVector) || !(guide is RealVector))
throw new ArgumentException("Cannot relink path because one of the provided solutions or both have the wrong type.");
if (n.Value <= 0.0)
throw new ArgumentException("RelinkingAccuracy must be greater than 0.");
RealVector v1 = initiator.Clone() as RealVector;
RealVector v2 = guide as RealVector;
if (v1.Length != v2.Length)
throw new ArgumentException("The solutions are of different length.");
IList<RealVector> solutions = new List<RealVector>();
for (int i = 0; i < k.Value; i++) {
RealVector solution = v1.Clone() as RealVector;
for (int j = 0; j < solution.Length; j++)
solution[j] = v1[j] + 1 / (k.Value - i) * (v2[j] - v1[j]);
solutions.Add(solution);
}
IList<IItem> selection = new List<IItem>();
if (solutions.Count > 0) {
int noSol = (int)(solutions.Count * n.Value);
if (noSol <= 0) noSol++;
double stepSize = (double)solutions.Count / (double)noSol;
for (int i = 0; i < noSol; i++)
selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5)));
}
return new ItemArray<IItem>(selection);
}
示例7: PRVRandomCreator
public PRVRandomCreator()
: base() {
NrOfRules = new IntValue(10);
Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator."));
Parameters.Add(new ValueLookupParameter<IntValue>("Jobs", "The number of jobs handled in this problem instance."));
Parameters.Add(new ValueLookupParameter<IntValue>("Resources", "The number of resources used in this problem instance."));
ScheduleEncodingParameter.ActualName = "PriorityRulesVector";
}
示例8: Create
protected override IntegerVector Create(IRandom random, IntValue length, IntMatrix bounds) {
int startPoint = StartingPointParameter.ActualValue.Value;
int endPoint = TerminalPointParameter.ActualValue.Value;
int numPoints = ScoresParameter.ActualValue.Length;
var distances = DistanceMatrixParameter.ActualValue;
double pointVisitingCosts = PointVisitingCostsParameter.ActualValue.Value;
double maxDistance = MaximumDistanceParameter.ActualValue.Value;
var scores = ScoresParameter.ActualValue;
// Find all points within the maximum distance allowed (ellipse)
var feasiblePoints = (
from point in Enumerable.Range(0, numPoints)
let distance = distances[startPoint, point] + distances[point, endPoint] + pointVisitingCosts
let score = scores[point]
where distance <= maxDistance
where point != startPoint && point != endPoint
orderby score descending
select point
).ToList();
// Add the starting and terminus point
var tour = new List<int> {
startPoint,
endPoint
};
double tourLength = distances[startPoint, endPoint];
// Add points in a greedy way
bool insertionPerformed = true;
while (insertionPerformed) {
insertionPerformed = false;
for (int i = 0; i < feasiblePoints.Count; i++) {
for (int insertPosition = 1; insertPosition < tour.Count; insertPosition++) {
// Create the candidate tour
double detour = distances.CalculateInsertionCosts(tour, insertPosition, feasiblePoints[i], pointVisitingCosts);
// If the insertion would be feasible, perform it
if (tourLength + detour <= maxDistance) {
tour.Insert(insertPosition, feasiblePoints[i]);
tourLength += detour;
feasiblePoints.RemoveAt(i);
insertionPerformed = true;
break;
}
}
if (insertionPerformed) break;
}
}
return new IntegerVector(tour.ToArray());
}
示例9: Ints
public void Ints()
{
IntValue value1 = new IntValue();
IntValue value2 = new IntValue();
IntValue value3 = new IntValue();
value1.Value = 1;
value2.Value = 1;
value3.Value = 2;
Assert.That(value1 == value2);
Assert.That(value1 != value3);
}
示例10: Apply
/// <summary>
/// Performs a N point crossover at randomly chosen positions of the two
/// given parent binary vectors.
/// </summary>
/// <exception cref="ArgumentException">Thrown when the value for N is invalid or when the parent vectors are of different length.</exception>
/// <param name="random">A random number generator.</param>
/// <param name="parent1">The first parent for crossover.</param>
/// <param name="parent2">The second parent for crossover.</param>
/// <param name="n">Number of crossover points.</param>
/// <returns>The newly created binary vector, resulting from the N point crossover.</returns>
public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, IntValue n) {
if (parent1.Length != parent2.Length)
throw new ArgumentException("NPointCrossover: The parents are of different length.");
if (n.Value > parent1.Length)
throw new ArgumentException("NPointCrossover: There cannot be more breakpoints than the size of the parents.");
if (n.Value < 1)
throw new ArgumentException("NPointCrossover: N cannot be < 1.");
int length = parent1.Length;
bool[] result = new bool[length];
int[] breakpoints = new int[n.Value];
//choose break points
List<int> breakpointPool = new List<int>();
for (int i = 0; i < length; i++)
breakpointPool.Add(i);
for (int i = 0; i < n.Value; i++) {
int index = random.Next(breakpointPool.Count);
breakpoints[i] = breakpointPool[index];
breakpointPool.RemoveAt(index);
}
Array.Sort(breakpoints);
//perform crossover
int arrayIndex = 0;
int breakPointIndex = 0;
bool firstParent = true;
while (arrayIndex < length) {
if (breakPointIndex < breakpoints.Length &&
arrayIndex == breakpoints[breakPointIndex]) {
breakPointIndex++;
firstParent = !firstParent;
}
if (firstParent)
result[arrayIndex] = parent1[arrayIndex];
else
result[arrayIndex] = parent2[arrayIndex];
arrayIndex++;
}
return new BinaryVector(result);
}
示例11: NPointCrossoverApplyTest
public void NPointCrossoverApplyTest() {
TestRandom random = new TestRandom();
BinaryVector parent1, parent2, expected, actual;
IntValue n;
bool exceptionFired;
// The following test is based on Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, p. 48
random.Reset();
n = new IntValue(1);
random.IntNumbers = new int[] { 4 };
parent1 = new BinaryVector(new bool[] { false, false, false, false, true, false, false, false, false });
parent2 = new BinaryVector(new bool[] { true, true, false, true, false, false, false, false, true });
expected = new BinaryVector(new bool[] { false, false, false, false, false, false, false, false, true });
actual = NPointCrossover.Apply(random, parent1, parent2, n);
Assert.IsTrue(Auxiliary.BinaryVectorIsEqualByPosition(actual, expected));
// The following test is based on Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, p. 48
random.Reset();
n = new IntValue(2);
random.IntNumbers = new int[] { 4, 5 };
parent1 = new BinaryVector(new bool[] { false, false, false, false, true, false, false, false, false });
parent2 = new BinaryVector(new bool[] { true, true, false, true, false, false, false, false, true });
expected = new BinaryVector(new bool[] { false, false, false, false, false, false, false, false, false });
actual = NPointCrossover.Apply(random, parent1, parent2, n);
Assert.IsTrue(Auxiliary.BinaryVectorIsEqualByPosition(actual, expected));
// The following test is based on Eiben, A.E. and Smith, J.E. 2003. Introduction to Evolutionary Computation. Natural Computing Series, Springer-Verlag Berlin Heidelberg, p. 48
random.Reset();
n = new IntValue(2);
random.IntNumbers = new int[] { 4, 5 };
parent2 = new BinaryVector(new bool[] { false, false, false, false, true, false, false, false, false });
parent1 = new BinaryVector(new bool[] { true, true, false, true, false, false, false, false, true });
expected = new BinaryVector(new bool[] { true, true, false, true, true, false, false, false, true });
actual = NPointCrossover.Apply(random, parent1, parent2, n);
Assert.IsTrue(Auxiliary.BinaryVectorIsEqualByPosition(actual, expected));
// The following test is not based on any published examples
random.Reset();
random.IntNumbers = new int[] { 2 };
parent1 = new BinaryVector(new bool[] { false, true, true, false, false }); // this parent is longer
parent2 = new BinaryVector(new bool[] { false, true, true, false });
exceptionFired = false;
try {
actual = NPointCrossover.Apply(random, parent1, parent2, n);
}
catch (System.ArgumentException) {
exceptionFired = true;
}
Assert.IsTrue(exceptionFired);
}
示例12: Create
/// <summary>
/// Forwards the call to <see cref="Apply(IRandom, RealVector, DoubleArray, DoubleMatrix)"/>.
/// </summary>
/// <param name="random">The pseudo random number generator to use.</param>
/// <param name="length">The length of the real vector.</param>
/// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param>
/// <returns>The newly created real vector.</returns>
protected override RealVector Create(IRandom random, IntValue length, DoubleMatrix bounds) {
return Apply(length, random, MeanParameter.ActualValue, SigmaParameter.ActualValue, bounds, MaximumTriesParameter.Value.Value);
}
示例13: Apply
/// <summary>
/// Generates a new random real vector normally distributed around the given mean with the given <paramref name="length"/> and in the interval [min,max).
/// </summary>
/// <exception cref="ArgumentException">
/// Thrown when <paramref name="random"/> is null.<br />
/// Thrown when <paramref name="mean"/> is null or of length 0.<br />
/// Thrown when <paramref name="sigma"/> is null or of length 0.<br />
/// </exception>
/// <remarks>
/// If no bounds are given the bounds will be set to (double.MinValue;double.MaxValue).
///
/// If dimensions of the mean do not lie within the given bounds they're set to either to the min or max of the bounds depending on whether the given dimension
/// for the mean is smaller or larger than the bounds. If min and max for a certain dimension are almost the same the resulting value will be set to min.
///
/// However, please consider that such static bounds are not really meaningful to optimize.
///
/// The sigma vector can contain 0 values in which case the dimension will be exactly the same as the given mean.
/// </remarks>
/// <param name="random">The random number generator.</param>
/// <param name="means">The mean vector around which the resulting vector is sampled.</param>
/// <param name="sigmas">The vector of standard deviations, must have at least one row.</param>
/// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param>
/// <param name="maximumTries">The maximum number of tries to sample a value inside the bounds for each dimension. If a valid value cannot be obtained, the mean will be used.</param>
/// <returns>The newly created real vector.</returns>
public static RealVector Apply(IntValue lengthValue, IRandom random, RealVector means, DoubleArray sigmas, DoubleMatrix bounds, int maximumTries = 1000) {
if (lengthValue == null || lengthValue.Value == 0) throw new ArgumentException("Length is not defined or zero");
if (random == null) throw new ArgumentNullException("Random is not defined", "random");
if (means == null || means.Length == 0) throw new ArgumentNullException("Mean is not defined", "mean");
if (sigmas == null || sigmas.Length == 0) throw new ArgumentNullException("Sigma is not defined.", "sigma");
if (bounds == null || bounds.Rows == 0) bounds = new DoubleMatrix(new[,] { { double.MinValue, double.MaxValue } });
var length = lengthValue.Value;
var nd = new NormalDistributedRandom(random, 0, 1);
var result = new RealVector(length);
for (int i = 0; i < result.Length; i++) {
var min = bounds[i % bounds.Rows, 0];
var max = bounds[i % bounds.Rows, 1];
var mean = means[i % means.Length];
var sigma = sigmas[i % sigmas.Length];
if (min.IsAlmost(max) || mean < min) result[i] = min;
else if (mean > max) result[i] = max;
else {
int count = 0;
bool inRange;
do {
result[i] = mean + sigma * nd.NextDouble();
inRange = result[i] >= min && result[i] < max;
count++;
} while (count < maximumTries && !inRange);
if (count == maximumTries && !inRange)
result[i] = mean;
}
}
return result;
}
示例14: getValue
/// <summary>
/// Gets a value based on its image
/// </summary>
/// <param name="image"></param>
/// <returns></returns>
public override IValue getValue(string image)
{
IValue retVal = null;
try
{
retVal = new IntValue(this, Decimal.Parse(image));
}
catch (Exception e)
{
AddException(e);
}
return retVal;
}
示例15: Improve
public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, DoubleArray probabilities, CancellationToken cancellation) {
var distanceM = (DistanceMatrix)distances;
Func<int, int, double> distance = (a, b) => distanceM[a, b];
for (var i = localIterations.Value; i < maxIterations; i++) {
TranslocationMove bestMove = null;
var bestQuality = quality.Value; // we have to make an improvement, so current quality is the baseline
var evaluations = 0.0;
foreach (var move in ExhaustiveInsertionMoveGenerator.Generate(assignment)) {
var moveQuality = PTSPAnalyticalInsertionMoveEvaluator.EvaluateMove(assignment, move, distance, probabilities);
evaluations++;
if (maximization && moveQuality > bestQuality
|| !maximization && moveQuality < bestQuality) {
bestQuality = moveQuality;
bestMove = move;
}
}
evaluatedSolutions.Value += (int)Math.Ceiling(evaluations);
if (bestMove == null) break;
TranslocationManipulator.Apply(assignment, bestMove.Index1, bestMove.Index2, bestMove.Index3);
quality.Value = bestQuality;
localIterations.Value++;
cancellation.ThrowIfCancellationRequested();
}
}