Esempio n. 1
0
 private Solution(Solution original, Cloner cloner)
   : base(original, cloner) {
   this.length = original.length;
   this.width = original.width;
   this.tree = cloner.Clone(tree);
 }
    public override IOperation Apply() {
      var trees = SymbolicExpressionTreeParameter.ActualValue;
      var qualities = QualityParameter.ActualValue;

      // find max tree
      double maxQuality = double.NegativeInfinity;
      ISymbolicExpressionTree bestTree = null;
      for (int i = 0; i < qualities.Length; i++) {
        if (qualities[i].Value > maxQuality) {
          maxQuality = qualities[i].Value;
          bestTree = trees[i];
        }
      }
      int length = LawnLengthParameter.ActualValue.Value;
      int width = LawnWidthParameter.ActualValue.Value;
      var bestSolution = new Solution(bestTree, length, width);
      BestSolutionParameter.ActualValue = bestSolution;

      var resultCollection = ResultParameter.ActualValue;
      if (!resultCollection.ContainsKey(BestSolutionParameterName)) {
        resultCollection.Add(new Result(BestSolutionParameterName, "The best lawn mower solution", bestSolution));
      } else {
        resultCollection[BestSolutionParameterName].Value = bestSolution;
      }

      return base.Apply();
    }