コード例 #1
0
 private OneMaxSolution(OneMaxSolution original, Cloner cloner)
     : base(original, cloner)
 {
     binaryVector = cloner.Clone(original.binaryVector);
     quality      = cloner.Clone(original.quality);
     Initialize();
 }
コード例 #2
0
        public override IOperation Apply()
        {
            ItemArray <BinaryVector> binaryVectors = BinaryVectorParameter.ActualValue;
            ItemArray <DoubleValue>  qualities     = QualityParameter.ActualValue;
            ResultCollection         results       = ResultsParameter.ActualValue;
            bool        max = MaximizationParameter.ActualValue.Value;
            DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;

            int i = -1;

            if (!max)
            {
                i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
            }
            else
            {
                i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
            }

            if (bestKnownQuality == null ||
                max && qualities[i].Value > bestKnownQuality.Value ||
                !max && qualities[i].Value < bestKnownQuality.Value)
            {
                BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
            }

            OneMaxSolution solution = BestSolutionParameter.ActualValue;

            if (solution == null)
            {
                solution = new OneMaxSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value));
                BestSolutionParameter.ActualValue = solution;
                results.Add(new Result("Best OneMax Solution", solution));
            }
            else
            {
                if (max && qualities[i].Value > solution.Quality.Value ||
                    !max && qualities[i].Value < solution.Quality.Value)
                {
                    solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone();
                    solution.Quality      = new DoubleValue(qualities[i].Value);
                }
            }

            return(base.Apply());
        }
コード例 #3
0
    public override IOperation Apply() {
      ItemArray<BinaryVector> binaryVectors = BinaryVectorParameter.ActualValue;
      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
      ResultCollection results = ResultsParameter.ActualValue;
      bool max = MaximizationParameter.ActualValue.Value;
      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;

      int i = -1;
      if (!max)
        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;

      if (bestKnownQuality == null ||
          max && qualities[i].Value > bestKnownQuality.Value ||
          !max && qualities[i].Value < bestKnownQuality.Value) {
        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
      }

      OneMaxSolution solution = BestSolutionParameter.ActualValue;
      if (solution == null) {
        solution = new OneMaxSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value));
        BestSolutionParameter.ActualValue = solution;
        results.Add(new Result("Best OneMax Solution", solution));
      } else {
        if (max && qualities[i].Value > solution.Quality.Value ||
          !max && qualities[i].Value < solution.Quality.Value) {
          solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone();
          solution.Quality = new DoubleValue(qualities[i].Value);
        }
      }

      return base.Apply();
    }
コード例 #4
0
 private OneMaxSolution(OneMaxSolution original, Cloner cloner)
   : base(original, cloner) {
   binaryVector = cloner.Clone(original.binaryVector);
   quality = cloner.Clone(original.quality);
   Initialize();
 }