Exemplo n.º 1
0
 /// <summary>
 /// Creates a new ClimberAlgorithm using the given comparison strategy to compare
 /// evaluations and the given successorPicker to select the next EvaluableState to
 /// evaluate against in a greedy or non-greedy configuration
 /// </summary>
 /// <param name="greedy">Determines the greedyness of the algorithm</param>
 /// <param name="comparisonStrategy">The Comparer that which Optimize will use to compare optimizations</param>
 /// <param name="successorPicker">The successor picker to choose the next EvaluableState in to evaluate at an optimization step</param>
 protected ClimberAlgorithm(bool greedy,
                            IComparer <TEvaluation> comparisonStrategy,
                            ISuccessorPicker <TState, TEvaluation> successorPicker)
 {
     this.successorPicker    = successorPicker;
     this.comparisonStrategy = comparisonStrategy;
     this.greedy             = greedy;
 }
        public void TestRandomRestartHillClimberSameRestartPointEachTime()
        {
            comparer   = new MaximizingComparer <int>();
            generator  = new TestLinearIntegerSuccessorGenerator();
            picker     = new ClimberSuccessorPicker <TestIntegerEvaluableState, int>(generator, comparer);
            algorithm  = new LocalClimberAlgorithm <TestIntegerEvaluableState, int>(comparer, picker);
            randomizer = new TestIntegerEvaluableStateNonRandomizer();
            climber    = new RandomRestartHillClimber <TestIntegerEvaluableState, int>(randomizer, algorithm, 5);

            RunTest(climber, 2, 100);
        }
        public void TestRandomRestartHillClimberIncrementingRestartPoint()
        {
            comparer   = new MaximizingComparer <int>();
            generator  = new TestExponentialIntegerSuccessorGenerator();
            picker     = new ClimberSuccessorPicker <TestIntegerEvaluableState, int>(generator, comparer);
            algorithm  = new LocalClimberAlgorithm <TestIntegerEvaluableState, int>(comparer, picker);
            randomizer = new TestIntegerRandomizerSimulator();
            climber    = new RandomRestartHillClimber <TestIntegerEvaluableState, int>(randomizer, algorithm, 5);


            RunTest(climber, 1, 64);
        }
 /// <summary>
 /// Creates a new LocalClimberAlgorithm using the given comparison strategy to compare
 /// evaluations and the given successorPicker to select the next EvaluableState to
 /// evaluate against in a greedy or non-greedy configuration
 /// </summary>
 /// <param name="greedy">Determines the greedyness of the algorithm</param>
 /// <param name="comparisonStrategy">The Comparer that which Optimize will use to compare optimizations</param>
 /// <param name="successorPicker">The successor picker to choose the next EvaluableState in to evaluate at an optimization step</param>
 public LocalClimberAlgorithm(bool greedy, IComparer <TEvaluation> comparisonStrategy, ISuccessorPicker <TState, TEvaluation> successorPicker) : base(greedy, comparisonStrategy, successorPicker)
 {
 }
 /// <summary>
 /// Creates a new LocalClimberAlgorithm using the given comparison strategy to compare
 /// evaluations and the given successorPicker to select the next EvaluableState to
 /// evaluate against non-greedily
 /// </summary>
 /// <param name="comparisonStrategy">The Comparer that which Optimize will use to determine optimality</param>
 /// <param name="successorPicker">The successor picker to choose the next EvaluableState in to evaluate at an optimization step</param>
 public LocalClimberAlgorithm(IComparer <TEvaluation> comparisonStrategy, ISuccessorPicker <TState, TEvaluation> successorPicker) : this(false, comparisonStrategy, successorPicker)
 {
 }
Exemplo n.º 6
0
 protected Optimizer(ISuccessorPicker <TState, TEvaluation> successorPicker)
 {
     this.successorPicker = successorPicker;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Create a new StateRandomizer with the given compaer, using the given SuccessorPicker that will perform
 /// the given number of randomizations before returning a result. A numRanfomizations of -1 will have the optimier
 /// return the first encountered optimal state
 /// </summary>
 /// <param name="evaluationComparer"></param>
 /// <param name="successorPicker"></param>
 /// <param name="numRandomizations"></param>
 public StateRandomizer(IComparer <TEvaluation> evaluationComparer, ISuccessorPicker <TState, TEvaluation> successorPicker, int numRandomizations)
     : base(successorPicker)
 {
     EvaluationComparer = evaluationComparer;
     NumRandomizations  = numRandomizations;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Create a new StateRandomizer with the given compaer, using the given SuccessorPicker that will perform
 /// a single randomization and return the most optimal result
 /// </summary>
 /// <param name="evaluationComparer"></param>
 /// <param name="successorPicker"></param>
 public StateRandomizer(IComparer <TEvaluation> evaluationComparer, ISuccessorPicker <TState, TEvaluation> successorPicker)
     : this(evaluationComparer, successorPicker, 1)
 {
 }
 /// <summary>
 /// Creates a RandomRestartHillClimber that will restart the Optimization from the given ClimberAlgorithm
 /// up to numRestarts in parallel with the given ParallelOptions
 /// </summary>
 /// <param name="stateRandomizer">A successor picker that will generate a random successor state from the initial state</param>
 /// <param name="algorithm">The climber algorithm to use for optimzation</param>
 /// <param name="numRestarts">The number of random restart operations to complete</param>
 /// <param name="parallelOptions">The options for the Parallel restart operations</param>
 public RandomRestartHillClimber(ISuccessorPicker <TState, TEvaluation> stateRandomizer, ClimberAlgorithm <TState, TEvaluation> algorithm, uint numRestarts, ParallelOptions parallelOptions) : base(algorithm)
 {
     this.numRestarts     = numRestarts;
     this.parallelOptions = parallelOptions;
     this.stateRandomizer = stateRandomizer;
 }
 /// <summary>
 /// Creates a RandomRestartHillClimber that will restart the Optimization from the given ClimberAlgorithm
 /// up to numRestarts. The operation will run in parallel with as many available processors up to maxDegreeOfParallelism.
 /// </summary>
 /// <param name="stateRandomizer">A successor picker that will generate a random successor state from the initial state</param>
 /// <param name="algorithm">The climber algorithm to use for optimzation</param>
 /// <param name="numRestarts">The number of random restart operations to complete</param>
 /// <param name="maxDegreeOfParallelism">The maximum number of processors that will attempt to perform an optimization operation</param>
 public RandomRestartHillClimber(ISuccessorPicker <TState, TEvaluation> stateRandomizer, ClimberAlgorithm <TState, TEvaluation> algorithm, uint numRestarts, int maxDegreeOfParallelism)
     : this(stateRandomizer, algorithm, numRestarts, new ParallelOptions() { MaxDegreeOfParallelism = maxDegreeOfParallelism })
 {
 }
 /// <summary>
 /// Creates a RandomRestartHillClimber that will restart the Optimization from the given ClimberAlgorithm
 /// up to numRestarts. If parallel is true, the operation will be completed with all available processors
 /// </summary>
 /// <param name="stateRandomizer">A successor picker that will generate a random successor state from the initial state</param>
 /// <param name="algorithm">The climber algorithm to use for optimzation</param>
 /// <param name="numRestarts">The number of random restart operations to complete</param>
 /// <param name="parallel">Flag to determine if the process should run in parallel</param>
 public RandomRestartHillClimber(ISuccessorPicker <TState, TEvaluation> stateRandomizer, ClimberAlgorithm <TState, TEvaluation> algorithm, uint numRestarts, bool parallel)
     : this(stateRandomizer, algorithm, numRestarts, parallel ? -1 : 1)
 {
 }
 /// <summary>
 /// Creates a RandomRestartHillClimber that will restart the Optimization from the given ClimberAlgorithm
 /// up to numRestarts in serial (one thread)
 /// </summary>
 /// <param name="stateRandomizer">A successor picker that will generate a random successor state from the initial state</param>
 /// <param name="algorithm">The climber algorithm to use for optimzation</param>
 /// <param name="numRestarts">The number of random restart operations to complete</param>
 public RandomRestartHillClimber(ISuccessorPicker <TState, TEvaluation> stateRandomizer, ClimberAlgorithm <TState, TEvaluation> algorithm, uint numRestarts)
     : this(stateRandomizer, algorithm, numRestarts, false)
 {
 }