protected ParameterlessPopulationPyramid(ParameterlessPopulationPyramid original, Cloner cloner)
     : base(original, cloner)
 {
     random  = cloner.Clone(original.random);
     pyramid = original.pyramid.Select(cloner.Clone).ToList();
     tracker = cloner.Clone(original.tracker);
     seen    = new HashSet <BinaryVector>(original.seen.Select(cloner.Clone), new EnumerableBoolEqualityComparer());
 }
 private EvaluationTracker(EvaluationTracker original, Cloner cloner)
   : base(original, cloner) {
   problem = cloner.Clone(original.problem);
   maxEvaluations = original.maxEvaluations;
   BestQuality = original.BestQuality;
   Evaluations = original.Evaluations;
   BestFoundOnEvaluation = original.BestFoundOnEvaluation;
   BestSolution = cloner.Clone(BestSolution);
 }
Example #3
0
 private EvaluationTracker(EvaluationTracker original, Cloner cloner)
     : base(original, cloner)
 {
     problem               = cloner.Clone(original.problem);
     maxEvaluations        = original.maxEvaluations;
     BestQuality           = original.BestQuality;
     Evaluations           = original.Evaluations;
     BestFoundOnEvaluation = original.BestFoundOnEvaluation;
     BestSolution          = cloner.Clone(original.BestSolution);
 }
Example #4
0
        protected override void Run(CancellationToken cancellationToken)
        {
            // Set up the algorithm
            if (SetSeedRandomly)
            {
                Seed = new System.Random().Next();
            }
            pyramid = new List <Population>();
            seen.Clear();
            random.Reset(Seed);
            tracker = new EvaluationTracker(Problem, MaximumEvaluations);

            // Set up the results display
            Results.Add(new Result("Iterations", new IntValue(0)));
            Results.Add(new Result("Evaluations", new IntValue(0)));
            Results.Add(new Result("Best Solution", new BinaryVector(tracker.BestSolution)));
            Results.Add(new Result("Best Quality", new DoubleValue(tracker.BestQuality)));
            Results.Add(new Result("Evaluation Best Solution Was Found", new IntValue(tracker.BestFoundOnEvaluation)));
            var table = new DataTable("Qualities");

            table.Rows.Add(new DataRow("Best Quality"));
            var iterationRows = new DataRow("Iteration Quality");

            iterationRows.VisualProperties.LineStyle = DataRowVisualProperties.DataRowLineStyle.Dot;
            table.Rows.Add(iterationRows);
            Results.Add(new Result("Qualities", table));

            table = new DataTable("Pyramid Levels");
            table.Rows.Add(new DataRow("Levels"));
            Results.Add(new Result("Pyramid Levels", table));

            table = new DataTable("Stored Solutions");
            table.Rows.Add(new DataRow("Solutions"));
            Results.Add(new Result("Stored Solutions", table));

            // Loop until iteration limit reached or canceled.
            for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++)
            {
                double fitness = double.NaN;

                try {
                    fitness = iterate();
                    cancellationToken.ThrowIfCancellationRequested();
                } finally {
                    ResultsEvaluations           = tracker.Evaluations;
                    ResultsBestSolution          = new BinaryVector(tracker.BestSolution);
                    ResultsBestQuality           = tracker.BestQuality;
                    ResultsBestFoundOnEvaluation = tracker.BestFoundOnEvaluation;
                    ResultsQualitiesBest.Values.Add(tracker.BestQuality);
                    ResultsQualitiesIteration.Values.Add(fitness);
                    ResultsLevels.Values.Add(pyramid.Count);
                    ResultsSolutions.Values.Add(seen.Count);
                }
            }
        }
        protected override void Initialize(CancellationToken cancellationToken)
        {
            // Set up the algorithm
            if (SetSeedRandomly)
            {
                Seed = RandomSeedGenerator.GetSeed();
            }
            pyramid = new List <Population>();
            seen.Clear();
            random.Reset(Seed);
            tracker = new EvaluationTracker(Problem, MaximumEvaluations);

            // Set up the results display
            Results.Add(new Result("Iterations", new IntValue(0)));
            Results.Add(new Result("Evaluations", new IntValue(0)));
            Results.Add(new Result("Best Solution", new BinaryVector(tracker.BestSolution)));
            Results.Add(new Result("Best Quality", new DoubleValue(tracker.BestQuality)));
            Results.Add(new Result("Evaluation Best Solution Was Found", new IntValue(tracker.BestFoundOnEvaluation)));
            var table = new DataTable("Qualities");

            table.Rows.Add(new DataRow("Best Quality"));
            var iterationRows = new DataRow("Iteration Quality");

            iterationRows.VisualProperties.LineStyle = DataRowVisualProperties.DataRowLineStyle.Dot;
            table.Rows.Add(iterationRows);
            Results.Add(new Result("Qualities", table));

            table = new DataTable("Pyramid Levels");
            table.Rows.Add(new DataRow("Levels"));
            Results.Add(new Result("Pyramid Levels", table));

            table = new DataTable("Stored Solutions");
            table.Rows.Add(new DataRow("Solutions"));
            Results.Add(new Result("Stored Solutions", table));

            base.Initialize(cancellationToken);
        }
    protected override void Run(CancellationToken cancellationToken) {
      // Set up the algorithm
      if (SetSeedRandomly) Seed = new System.Random().Next();
      pyramid = new List<Population>();
      seen.Clear();
      random.Reset(Seed);
      tracker = new EvaluationTracker(Problem, MaximumEvaluations);

      // Set up the results display
      Results.Add(new Result("Iterations", new IntValue(0)));
      Results.Add(new Result("Evaluations", new IntValue(0)));
      Results.Add(new Result("Best Solution", new BinaryVector(tracker.BestSolution)));
      Results.Add(new Result("Best Quality", new DoubleValue(tracker.BestQuality)));
      Results.Add(new Result("Evaluation Best Solution Was Found", new IntValue(tracker.BestFoundOnEvaluation)));
      var table = new DataTable("Qualities");
      table.Rows.Add(new DataRow("Best Quality"));
      var iterationRows = new DataRow("Iteration Quality");
      iterationRows.VisualProperties.LineStyle = DataRowVisualProperties.DataRowLineStyle.Dot;
      table.Rows.Add(iterationRows);
      Results.Add(new Result("Qualities", table));

      table = new DataTable("Pyramid Levels");
      table.Rows.Add(new DataRow("Levels"));
      Results.Add(new Result("Pyramid Levels", table));

      table = new DataTable("Stored Solutions");
      table.Rows.Add(new DataRow("Solutions"));
      Results.Add(new Result("Stored Solutions", table));

      // Loop until iteration limit reached or canceled.
      for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {
        double fitness = double.NaN;

        try {
          fitness = iterate();
          cancellationToken.ThrowIfCancellationRequested();
        } finally {
          ResultsEvaluations = tracker.Evaluations;
          ResultsBestSolution = new BinaryVector(tracker.BestSolution);
          ResultsBestQuality = tracker.BestQuality;
          ResultsBestFoundOnEvaluation = tracker.BestFoundOnEvaluation;
          ResultsQualitiesBest.Values.Add(tracker.BestQuality);
          ResultsQualitiesIteration.Values.Add(fitness);
          ResultsLevels.Values.Add(pyramid.Count);
          ResultsSolutions.Values.Add(seen.Count);
        }
      }
    }