Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/10 20:56:34 (15 years ago)
Author:
abeham
Message:

Updated simulated annealing:

  • Added inner loop to noticeably speed up algorithm
  • Removed exception in StochasticTwoOptMultiMoveGenerator when more moves would be generated than from the exhaustive move generator. The StochasticTwoOptMultiMoveGenerator simply draws from all moves with replacement.

#923

Location:
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3098 r3101  
    5353      get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    5454    }
    55     private ConstrainedValueParameter<ISingleMoveGenerator> MoveGeneratorParameter {
    56       get { return (ConstrainedValueParameter<ISingleMoveGenerator>)Parameters["MoveGenerator"]; }
     55    private ConstrainedValueParameter<IMultiMoveGenerator> MoveGeneratorParameter {
     56      get { return (ConstrainedValueParameter<IMultiMoveGenerator>)Parameters["MoveGenerator"]; }
    5757    }
    5858    private ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
     
    6767    private ValueParameter<IntValue> MaximumIterationsParameter {
    6868      get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
     69    }
     70    private ValueParameter<IntValue> InnerIterationsParameter {
     71      get { return (ValueParameter<IntValue>)Parameters["InnerIterations"]; }
    6972    }
    7073    private ValueParameter<DoubleValue> StartTemperatureParameter {
     
    8588      set { SetSeedRandomlyParameter.Value = value; }
    8689    }
    87     public ISingleMoveGenerator MoveGenerator {
     90    public IMultiMoveGenerator MoveGenerator {
    8891      get { return MoveGeneratorParameter.Value; }
    8992      set { MoveGeneratorParameter.Value = value; }
     
    100103      get { return MaximumIterationsParameter.Value; }
    101104      set { MaximumIterationsParameter.Value = value; }
     105    }
     106    public IntValue InnerIterations {
     107      get { return InnerIterationsParameter.Value; }
     108      set { InnerIterationsParameter.Value = value; }
     109    }
     110    public DoubleValue StartTemperature {
     111      get { return StartTemperatureParameter.Value; }
     112      set { StartTemperatureParameter.Value = value; }
     113    }
     114    public DoubleValue EndTemperature {
     115      get { return EndTemperatureParameter.Value; }
     116      set { EndTemperatureParameter.Value = value; }
    102117    }
    103118    private RandomCreator RandomCreator {
     
    121136      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    122137      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    123       Parameters.Add(new ConstrainedValueParameter<ISingleMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
     138      Parameters.Add(new ConstrainedValueParameter<IMultiMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
    124139      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
    125140      Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
    126141      Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("AnnealingOperator", "The operator used to modify the temperature."));
    127       Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     142      Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(100)));
     143      Parameters.Add(new ValueParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again).", new IntValue(10)));
    128144      Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100)));
    129145      Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6)));
     
    176192      ParameterizeSolutionsCreator();
    177193      ParameterizeMainLoop();
    178       ParameterizeMoveEvaluator();
    179       ParameterizeMoveMaker();
     194      ParameterizeMoveEvaluators();
     195      ParameterizeMoveMakers();
     196      ParameterizeMoveGenerators();
    180197      UpdateMoveGenerator();
    181198      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    191208      ParameterizeSolutionsCreator();
    192209      ParameterizeMainLoop();
    193       ParameterizeMoveEvaluator();
    194       ParameterizeMoveMaker();
     210      ParameterizeMoveEvaluators();
     211      ParameterizeMoveMakers();
    195212      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    196213      base.Problem_EvaluatorChanged(sender, e);
     
    204221        op.MoveQualityParameter.ActualNameChanged += new EventHandler(MoveEvaluator_MoveQualityParameter_ActualNameChanged);
    205222      }
    206       ISingleMoveGenerator oldMoveGenerator = MoveGenerator;
     223      IMultiMoveGenerator oldMoveGenerator = MoveGenerator;
    207224      UpdateMoveGenerator();
    208225      if (oldMoveGenerator == MoveGenerator) // in this case MoveGeneratorParameter_ValueChanged did not fire
    209226        UpdateMoveParameters();
    210227      ParameterizeMainLoop();
    211       ParameterizeMoveEvaluator();
    212       ParameterizeMoveMaker();
     228      ParameterizeMoveEvaluators();
     229      ParameterizeMoveMakers();
     230      ParameterizeMoveGenerators();
    213231      base.Problem_OperatorsChanged(sender, e);
    214232    }
    215233    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    216234      ParameterizeMainLoop();
    217       ParameterizeMoveEvaluator();
    218       ParameterizeMoveMaker();
     235      ParameterizeMoveEvaluators();
     236      ParameterizeMoveMakers();
    219237    }
    220238    private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
     
    223241    private void MoveEvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    224242      ParameterizeMainLoop();
    225       ParameterizeMoveEvaluator();
    226       ParameterizeMoveMaker();
     243      ParameterizeMoveEvaluators();
     244      ParameterizeMoveMakers();
    227245    }
    228246    private void MoveEvaluator_MoveQualityParameter_ActualNameChanged(object sender, EventArgs e) {
    229247      ParameterizeMainLoop();
    230       ParameterizeMoveEvaluator();
    231       ParameterizeMoveMaker();
     248      ParameterizeMoveEvaluators();
     249      ParameterizeMoveMakers();
    232250    }
    233251    #endregion
     
    257275    }
    258276    private void UpdateMoveGenerator() {
    259       ISingleMoveGenerator oldMoveGenerator = MoveGenerator;
     277      IMultiMoveGenerator oldMoveGenerator = MoveGenerator;
    260278      MoveGeneratorParameter.ValidValues.Clear();
    261279      if (Problem != null) {
    262         foreach (ISingleMoveGenerator generator in Problem.Operators.OfType<ISingleMoveGenerator>().Where(x => !(x is IMultiMoveGenerator)).OrderBy(x => x.Name))
     280        foreach (IMultiMoveGenerator generator in Problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name))
    263281          MoveGeneratorParameter.ValidValues.Add(generator);
    264282      }
    265283      if (oldMoveGenerator != null) {
    266         ISingleMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
     284        IMultiMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
    267285        if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
    268286      }
     
    314332        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    315333    }
    316     private void ParameterizeMoveEvaluator() {
     334    private void ParameterizeMoveEvaluators() {
    317335      foreach (ISingleObjectiveMoveEvaluator op in Problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
    318336        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    319337      }
    320338    }
    321     private void ParameterizeMoveMaker() {
     339    private void ParameterizeMoveMakers() {
    322340      foreach (IMoveMaker op in Problem.Operators.OfType<IMoveMaker>()) {
    323341        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     
    337355      }
    338356    }
     357    private void ParameterizeMoveGenerators() {
     358      foreach (IMultiMoveGenerator op in Problem.Operators.OfType<IMultiMoveGenerator>()) {
     359        op.SampleSizeParameter.ActualName = InnerIterationsParameter.Name;
     360      }
     361    }
    339362    #endregion
    340363  }
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs

    r3094 r3101  
    5555      get { return (ValueLookupParameter<DoubleValue>)Parameters["EndTemperature"]; }
    5656    }
     57    public ValueLookupParameter<IntValue> InnerIterationsParameter {
     58      get { return (ValueLookupParameter<IntValue>)Parameters["InnerIterations"]; }
     59    }
    5760    public ValueLookupParameter<IntValue> MaximumIterationsParameter {
    5861      get { return (ValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     
    97100      Parameters.Add(new ValueLookupParameter<DoubleValue>("StartTemperature", "The initial temperature."));
    98101      Parameters.Add(new ValueLookupParameter<DoubleValue>("EndTemperature", "The end temperature."));
     102      Parameters.Add(new ValueLookupParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again)."));
    99103      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed."));
    100104      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     
    116120      Placeholder annealingOperator = new Placeholder();
    117121      UniformSequentialSubScopesProcessor mainProcessor = new UniformSequentialSubScopesProcessor();
     122      DataTableValuesCollector valuesCollector = new DataTableValuesCollector();
    118123      Placeholder moveGenerator = new Placeholder();
    119       SequentialSubScopesProcessor moveEvaluationProcessor = new SequentialSubScopesProcessor();
     124      UniformSequentialSubScopesProcessor moveEvaluationProcessor = new UniformSequentialSubScopesProcessor();
    120125      Placeholder moveEvaluator = new Placeholder();
    121126      ProbabilisticQualityComparator qualityComparator = new ProbabilisticQualityComparator();
     
    123128      Placeholder moveMaker = new Placeholder();
    124129      SubScopesRemover subScopesRemover = new SubScopesRemover();
    125       DataTableValuesCollector valuesCollector = new DataTableValuesCollector();
    126130      IntCounter iterationsCounter = new IntCounter();
    127131      Comparator iterationsComparator = new Comparator();
     
    142146      annealingOperator.OperatorParameter.ActualName = "AnnealingOperator";
    143147
     148      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality"));
     149      valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));
     150      valuesCollector.DataTableParameter.ActualName = "Qualities";
     151
    144152      moveGenerator.Name = "Move generator (placeholder)";
    145153      moveGenerator.OperatorParameter.ActualName = "MoveGenerator";
     
    159167
    160168      subScopesRemover.RemoveAllSubScopes = true;
    161 
    162       valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Quality"));
    163       valuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("BestQuality"));
    164       valuesCollector.DataTableParameter.ActualName = "Qualities";
    165169
    166170      iterationsCounter.Name = "Increment Iterations";
     
    188192      bestQualityMemorizer.Successor = annealingOperator;
    189193      annealingOperator.Successor = mainProcessor;
    190       mainProcessor.Operator = moveGenerator;
    191       mainProcessor.Successor = valuesCollector;
     194      mainProcessor.Operator = valuesCollector;
     195      mainProcessor.Successor = iterationsCounter;
     196      valuesCollector.Successor = moveGenerator;
    192197      moveGenerator.Successor = moveEvaluationProcessor;
    193       moveEvaluationProcessor.Operators.Add(moveEvaluator);
     198      moveEvaluationProcessor.Operator = moveEvaluator;
    194199      moveEvaluationProcessor.Successor = subScopesRemover;
    195200      moveEvaluator.Successor = qualityComparator;
    196201      qualityComparator.Successor = improvesQualityBranch;
    197202      improvesQualityBranch.TrueBranch = moveMaker;
    198       valuesCollector.Successor = iterationsCounter;
    199203      iterationsCounter.Successor = iterationsComparator;
    200204      iterationsComparator.Successor = iterationsTermination;
Note: See TracChangeset for help on using the changeset viewer.