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


C# IVRPProblemInstance.Evaluate方法代码示例

本文整理汇总了C#中IVRPProblemInstance.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# IVRPProblemInstance.Evaluate方法的具体用法?C# IVRPProblemInstance.Evaluate怎么用?C# IVRPProblemInstance.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IVRPProblemInstance的用法示例。


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

示例1: Apply

    public static ItemArray<IItem> Apply(PotvinEncoding initiator, PotvinEncoding guide, PercentValue n, int sampleSize, int iterations, IRandom rand, IVRPProblemInstance problemInstance) {
      if (initiator == null || guide == null)
        throw new ArgumentException("Cannot relink path because one of the provided solutions or both are null.");

      double sigma = 1.5;
      double minPenalty = 0.001;
      double maxPenalty = 1000000000;

      var originalOverloadPenalty = new DoubleValue();
      if (problemInstance is IHomogenousCapacitatedProblemInstance)
        originalOverloadPenalty.Value = (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value;
      var originalTardinessPenalty = new DoubleValue();
      if (problemInstance is ITimeWindowedProblemInstance)
        originalTardinessPenalty.Value = (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value;

      PotvinEncoding current = MatchTours(initiator, guide, problemInstance);
      double currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide);

      IList<PotvinEncoding> solutions = new List<PotvinEncoding>();
      int i = 0;
      while (i < iterations && !currentSimilarity.IsAlmost(1.0)) {
        var currentEval = problemInstance.Evaluate(current);
        currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide);

        if (currentSimilarity < 1.0) {
          for (int sample = 0; sample < sampleSize; sample++) {
            var next = current.Clone() as PotvinEncoding;

            int neighborhood = rand.Next(3);
            switch (neighborhood) {
              case 0: next = RouteBasedXOver(next, guide, rand,
                problemInstance);
                break;
              case 1: next = SequenceBasedXOver(next, guide, rand,
                problemInstance);
                break;
              case 2: GuidedRelocateMove(next, guide, rand);
                break;
            }

            next = MatchTours(next, guide, problemInstance);

            var nextEval = problemInstance.Evaluate(next);
            if ((nextEval.Quality < currentEval.Quality)) {
              current = next;
              solutions.Add(current);
              break;
            }
          }

          if (problemInstance is IHomogenousCapacitatedProblemInstance) {
            if (((CVRPEvaluation)currentEval).Overload > 0) {
              (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value =
                Math.Min(maxPenalty,
                (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value * sigma);
            } else {
              (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value =
                Math.Max(minPenalty,
                (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value * sigma);
            }
          }


          if (problemInstance is ITimeWindowedProblemInstance) {
            if (((CVRPTWEvaluation)currentEval).Tardiness > 0) {
              (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value =
                Math.Min(maxPenalty,
              (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value * sigma);
            } else {
              (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value =
                Math.Max(minPenalty,
                (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value / sigma);
            }
          }

          i++;
        }
      }

      if (problemInstance is IHomogenousCapacitatedProblemInstance)
        (problemInstance as IHomogenousCapacitatedProblemInstance).OverloadPenalty.Value = originalOverloadPenalty.Value;
      if (problemInstance is ITimeWindowedProblemInstance)
        (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value = originalTardinessPenalty.Value;

      return new ItemArray<IItem>(ChooseSelection(solutions, n));
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:86,代码来源:VRPPathRelinker.cs

示例2: Apply

    public static void Apply(AlbaEncoding solution, int maxIterations,
      int lambda, int samples, IRandom random, IVRPProblemInstance problemInstance, ref double quality, out int evaluatedSolutions) {
      evaluatedSolutions = 0;

      for (int i = 0; i < maxIterations; i++) {
        AlbaLambdaInterchangeMove bestMove = null;
        foreach (AlbaLambdaInterchangeMove move in AlbaStochasticLambdaInterchangeMultiMoveGenerator.GenerateAllMoves(solution, problemInstance, lambda, samples, random)) {
          AlbaEncoding newSolution = solution.Clone() as AlbaEncoding;
          AlbaLambdaInterchangeMoveMaker.Apply(newSolution, move);
          double moveQuality =
            problemInstance.Evaluate(newSolution).Quality;

          evaluatedSolutions++;
          if (moveQuality < quality || quality == -1) {
            quality = moveQuality;
            bestMove = move;
          }
        }
        if (bestMove != null)
          AlbaLambdaInterchangeMoveMaker.Apply(solution, bestMove);
      }
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:22,代码来源:AlbaLambdaInterchangeLocalImprovementOperator.cs


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