当前位置: 首页>>代码示例>>C#>>正文


C# DoubleValue类代码示例

本文整理汇总了C#中DoubleValue的典型用法代码示例。如果您正苦于以下问题:C# DoubleValue类的具体用法?C# DoubleValue怎么用?C# DoubleValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DoubleValue类属于命名空间,在下文中一共展示了DoubleValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Apply

 /// <summary>
 /// Performs the some positions bitflip mutation on a binary vector.
 /// </summary>
 /// <param name="random">The random number generator to use.</param>
 /// <param name="vector">The vector that should be manipulated.</param>
 /// <param name="pm">The probability a bit is flipped.</param>
 public static void Apply(IRandom random, BinaryVector vector, DoubleValue pm) {
   for (int i = 0; i < vector.Length; i++) {
     if (random.NextDouble() < pm.Value) {
       vector[i] = !vector[i];
     }
   }
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:13,代码来源:SomePositionsBitflipManipulator.cs

示例2: PolynomialAllPositionManipulatorApplyTest

 public void PolynomialAllPositionManipulatorApplyTest() {
   TestRandom random = new TestRandom();
   RealVector parent, expected;
   DoubleValue contiguity, maxManipulation;
   bool exceptionFired;
   // The following test is not based on published examples
   random.Reset();
   random.DoubleNumbers = new double[] { 0.2, 0.7, 0.8, 0.01, 0.1 };
   parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   expected = new RealVector(new double[] { 0.120213215256006, 0.249415354697564, 0.379786784743994, 0.322759240811056, -0.0182075293954083 });
   contiguity = new DoubleValue(0.8);
   maxManipulation = new DoubleValue(0.2);
   PolynomialAllPositionManipulator.Apply(random, parent, contiguity, maxManipulation);
   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.7, 0.8, 0.01, 0.1 };
   parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   contiguity = new DoubleValue(-1); //Contiguity value < 0
   maxManipulation = new DoubleValue(0.2);
   try {
     PolynomialAllPositionManipulator.Apply(random, parent, contiguity, maxManipulation);
   } catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:28,代码来源:PolynomialAllPositionManipulatorTest.cs

示例3: Apply

    /// <summary>
    /// Performs a breeder genetic algorithm manipulation on the given <paramref name="vector"/>.
    /// </summary>
    /// <param name="random">A random number generator.</param>
    /// <param name="vector">The real vector to manipulate.</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="searchIntervalFactor">The factor determining the size of the search interval.</param>
    public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, DoubleValue searchIntervalFactor) {
      int length = vector.Length;
      double prob, value;
      do {
        value = Sigma(random);
      } while (value == 0);

      prob = 1.0 / (double)length;
      bool wasMutated = false;

      for (int i = 0; i < length; i++) {
        if (random.NextDouble() < prob) {
          double range = bounds[i % bounds.Rows, 1] - bounds[i % bounds.Rows, 0];
          if (random.NextDouble() < 0.5) {
            vector[i] = vector[i] + value * searchIntervalFactor.Value * range;
          } else {
            vector[i] = vector[i] - value * searchIntervalFactor.Value * range;
          }
          wasMutated = true;
        }
      }

      // make sure at least one gene was mutated
      if (!wasMutated) {
        int pos = random.Next(length);
        double range = bounds[pos % bounds.Rows, 1] - bounds[pos % bounds.Rows, 0];
        if (random.NextDouble() < 0.5) {
          vector[pos] = vector[pos] + value * searchIntervalFactor.Value * range;
        } else {
          vector[pos] = vector[pos] - value * searchIntervalFactor.Value * range;
        }
      }
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:40,代码来源:BreederGeneticAlgorithmManipulator.cs

示例4: Apply

    public override IOperation Apply() {
      bool maximization = MaximizationParameter.ActualValue.Value;
      double quality = QualityParameter.ActualValue.Value, max = MaximumQualityParameter.ActualValue.Value, min = MinimumQualityParameter.ActualValue.Value;
      double difference;

      difference = ((quality - min) / (max - min));
      if (maximization) difference = 1.0 - difference;

      DoubleValue differenceValue = ScaledDifferenceParameter.ActualValue;
      if (differenceValue == null) {
        differenceValue = new DoubleValue(difference);
        ScaledDifferenceParameter.ActualValue = differenceValue;
      } else differenceValue.Value = difference;

      ResultCollection results = ResultsParameter.ActualValue;
      if (results != null) {
        IResult r;
        if (!results.TryGetValue(ScaledDifferenceParameter.TranslatedName, out r)) {
          r = new Result(ScaledDifferenceParameter.TranslatedName, differenceValue);
          results.Add(r);
        }
      }

      return base.Apply();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:25,代码来源:ScaledQualityDifferenceAnalyzer.cs

示例5: PolynomialOnePositionManipulatorApplyTest

 public void PolynomialOnePositionManipulatorApplyTest() {
   TestRandom random = new TestRandom();
   RealVector parent, expected;
   DoubleValue contiguity, maxManipulation;
   bool exceptionFired;
   // The following test is not based on published examples
   random.Reset();
   random.IntNumbers = new int[] { 3 };
   random.DoubleNumbers = new double[] { 0.2 };
   parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   expected = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.1261980542102, 0.1 });
   contiguity = new DoubleValue(0.2);
   maxManipulation = new DoubleValue(0.7);
   PolynomialOnePositionManipulator.Apply(random, parent, contiguity, maxManipulation);
   Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(expected, parent));
   // The following test is not based on published examples
   exceptionFired = false;
   random.Reset();
   random.IntNumbers = new int[] { 3 };
   random.DoubleNumbers = new double[] { 0.2 };
   parent = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   contiguity = new DoubleValue(-1); //Contiguity value < 0
   maxManipulation = new DoubleValue(0.2);
   try {
     PolynomialOnePositionManipulator.Apply(random, parent, contiguity, maxManipulation);
   } catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:30,代码来源:PolynomialOnePositionManipulatorTest.cs

示例6: ConvertToZeroOneScaleZeroTest

 public void ConvertToZeroOneScaleZeroTest()
 {
     DoubleValue value1 = new DoubleValue(50);
     DoubleValue value2 = new DoubleValue(0);
     var convertToZeroOneScale = value1.ConvertToZeroOneScale(value2);
     Assert.AreEqual(0.0, convertToZeroOneScale);
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:7,代码来源:DoubleValueTest.cs

示例7: 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);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:34,代码来源:MichalewiczNonUniformAllPositionsManipulatorTest.cs

示例8: Apply

    /// <summary>
    /// Performs the rounded blend alpha crossover (BLX-a) of two integer vectors.<br/>
    /// It creates new offspring by sampling a new value in the range [min_i - d * alpha, max_i + d * alpha) at each position i
    /// and rounding the result to the next integer.
    /// Here min_i and max_i are the smaller and larger value of the two parents at position i and d is max_i - min_i.
    /// </summary>
    /// <exception cref="ArgumentException">
    /// Thrown when <paramref name="parent1"/> and <paramref name="parent2"/> are of different length or<br/>
    /// when <paramref name="alpha"/> is less than 0.
    /// </exception>
    /// <param name="random">The random number generator.</param>
    /// <param name="parent1">The first parent for the crossover operation.</param>
    /// <param name="parent2">The second parent for the crossover operation.</param>
    /// <param name="bounds">The bounds and step size for each dimension (will be cycled in case there are less rows than elements in the parent vectors).</param>
    /// <param name="alpha">The alpha value for the crossover.</param>
    /// <returns>The newly created integer vector resulting from the crossover operation.</returns>
    public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2, IntMatrix bounds, DoubleValue alpha) {
      if (parent1.Length != parent2.Length) throw new ArgumentException("RoundedBlendAlphaCrossover: The parents' vectors are of different length.", "parent1");
      if (alpha.Value < 0) throw new ArgumentException("RoundedBlendAlphaCrossover: Paramter alpha must be greater or equal than 0.", "alpha");
      if (bounds == null || bounds.Rows < 1 || bounds.Columns < 2) throw new ArgumentException("RoundedBlendAlphaCrossover: Invalid bounds specified.", "bounds");

      int length = parent1.Length;
      var result = new IntegerVector(length);
      double max = 0, min = 0, d = 0, resMin = 0, resMax = 0;
      int minBound, maxBound, step = 1;

      for (int i = 0; i < length; i++) {
        minBound = bounds[i % bounds.Rows, 0];
        maxBound = bounds[i % bounds.Rows, 1];
        if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2];
        maxBound = FloorFeasible(minBound, maxBound, step, maxBound - 1);

        max = Math.Max(parent1[i], parent2[i]);
        min = Math.Min(parent1[i], parent2[i]);
        d = Math.Abs(max - min);
        resMin = FloorFeasible(minBound, maxBound, step, min - d * alpha.Value);
        resMax = CeilingFeasible(minBound, maxBound, step, max + d * alpha.Value);

        result[i] = RoundFeasible(minBound, maxBound, step, resMin + random.NextDouble() * Math.Abs(resMax - resMin));
      }
      return result;
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:42,代码来源:RoundedBlendAlphaCrossover.cs

示例9: VRPSolution

    public VRPSolution(IVRPProblemInstance problemInstance, IVRPEncoding solution, DoubleValue quality)
      : base() {
      this.problemInstance = problemInstance;
      this.solution = solution;
      this.quality = quality;

      Initialize();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:8,代码来源:VRPSolution.cs

示例10: SamplingCriteriaContext

 public SamplingCriteriaContext(UintValue maxTopStackOccurrence, DoubleValue maxDuration)
 {
     Contract.Requires(maxTopStackOccurrence != null);
     Contract.Requires(maxDuration != null);
     _maxTopStackOccurrence = maxTopStackOccurrence;
     _maxDuration = maxDuration;
     _availableCriteria = new Criterion[]{TopStackOccurrenceCriterion, DurationCriterion};
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:8,代码来源:SamplingCriteriaContext.cs

示例11: SetUp

 public void SetUp()
 {
     _enterCount = new UintValue(1);
     _wallClockDurationHns = new Uint64Value(2);
     _activeTime = new DoubleValue(3);
     Mock<IEnumerable<Method>> mockCallingMethods = new Mock<IEnumerable<Method>>(MockBehavior.Strict);
     Mock<IEnumerable<Method>> mockCalledMethods = new Mock<IEnumerable<Method>>(MockBehavior.Strict);
     _method = new TracingMethod(1,"stub", 20, 50, "MethodFull", @"C:\code\source.cs",_enterCount,_wallClockDurationHns,_activeTime );//, mockCallingMethods.Object,
                          //mockCalledMethods.Object);
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:10,代码来源:MethodTest.cs

示例12: Apply

 /// <summary>
 /// Performs the arithmetic crossover on all positions by calculating x = alpha * p1 + (1 - alpha) * p2.
 /// </summary>
 /// <exception cref="ArgumentException">Thrown when the parent vectors are of different length or alpha is outside the range [0;1].</exception>
 /// <param name="random">The random number generator.</param>
 /// <param name="parent1">The first parent vector.</param>
 /// <param name="parent2">The second parent vector.</param>
 /// <param name="alpha">The alpha parameter (<see cref="AlphaParameter"/>).</param>
 /// <returns>The vector resulting from the crossover.</returns>
 public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha) {
   int length = parent1.Length;
   if (length != parent2.Length) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: The parent vectors are of different length.", "parent1");
   if (alpha.Value < 0 || alpha.Value > 1) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: Parameter alpha must be in the range [0;1]", "alpha");
   RealVector result = new RealVector(length);
   for (int i = 0; i < length; i++) {
     result[i] = alpha.Value * parent1[i] + (1 - alpha.Value) * parent2[i];
   }
   return result;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:19,代码来源:UniformAllPositionsArithmeticCrossover.cs

示例13: TracingCriteriaContext

 public TracingCriteriaContext(UintValue maxCallCount, Uint64Value maxTimeWallClock, DoubleValue maxTimeActive)
 {
     Contract.Requires(maxCallCount != null);
     Contract.Requires(maxTimeWallClock != null);
     Contract.Requires(maxTimeActive != null);
     _maxCallCount = maxCallCount;
     _maxTimeWallClock = maxTimeWallClock;
     _maxTimeWallClock = maxTimeWallClock;
     _maxTimeActive = maxTimeActive;
     _availableCriteria = new Criterion[] { CallCountCriterion, TimeWallClockCriterion, TimeActiveCriterion };
 }
开发者ID:rasiths,项目名称:visual-profiler,代码行数:11,代码来源:TracingCriteriaContext.cs

示例14: BlendAlphaCrossoverApplyTest

 public void BlendAlphaCrossoverApplyTest() {
   TestRandom random = new TestRandom();
   RealVector parent1, parent2, expected, actual;
   DoubleValue alpha;
   bool exceptionFired;
   // The following test is not based on published examples
   random.Reset();
   random.DoubleNumbers = new double[] { 0.5, 0.5, 0.5, 0.5, 0.5 };
   alpha = new DoubleValue(0.5);
   parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
   expected = new RealVector(new double[] { 0.3, 0.15, 0.3, 0.35, 0.45 });
   actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
   Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
   // The following test is not based on published examples
   random.Reset();
   random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 };
   alpha = new DoubleValue(0.25);
   parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
   expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });
   actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
   Assert.IsTrue(Auxiliary.RealVectorIsAlmostEqualByPosition(actual, expected));
   // The following test is not based on published examples
   random.Reset();
   random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25 };
   alpha = new DoubleValue(-0.25); // negative values for alpha are not allowed
   parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1 });
   parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
   expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });
   exceptionFired = false;
   try {
     actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
   }
   catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
   // The following test is not based on published examples
   random.Reset();
   random.DoubleNumbers = new double[] { 0.25, 0.75, 0.25, 0.75, 0.25, .75 };
   alpha = new DoubleValue(0.25);
   parent1 = new RealVector(new double[] { 0.2, 0.2, 0.3, 0.5, 0.1, 0.9 }); // this parent is longer
   parent2 = new RealVector(new double[] { 0.4, 0.1, 0.3, 0.2, 0.8 });
   expected = new RealVector(new double[] { 0.225, 0.1875, 0.3, 0.4625, 0.1875 });
   exceptionFired = false;
   try {
     actual = BlendAlphaCrossover.Apply(random, parent1, parent2, alpha);
   }
   catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:54,代码来源:BlendAlphaCrossoverTest.cs

示例15: Apply

    public override IOperation Apply() {
      if (Cache == null)
        return base.Apply();

      if (Quality == null) Quality = new DoubleValue(0);
      Quality.Value = Cache.GetValue(BuildSolutionMessage(), m => EvaluateOnNextAvailableClient(m).Quality);
      if (Successor != null)
        return ExecutionContext.CreateOperation(Successor);
      else
        return null;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:11,代码来源:CachedExternalEvaluator.cs


注:本文中的DoubleValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。