Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/11 10:00:31 (14 years ago)
Author:
abeham
Message:

#1465

  • updated branch with trunk changes
Location:
branches/histogram
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram

  • branches/histogram/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingImprovementOperator.cs

    r5809 r6046  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
     24using HeuristicLab.Analysis;
     25using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Data;
     28using HeuristicLab.Operators;
     29using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
    2731using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Operators;
    29 using HeuristicLab.Common;
    30 using HeuristicLab.Parameters;
    31 using HeuristicLab.Algorithms.SimulatedAnnealing;
    32 using HeuristicLab.Data;
    33 using HeuristicLab.Optimization;
    34 using HeuristicLab.Optimization.Operators;
    35 using HeuristicLab.Analysis;
    3632using HeuristicLab.PluginInfrastructure;
    3733
     
    4238  [Item("SimulatedAnnealingImprovementOperator", "A simulated annealing improvement operator.")]
    4339  [StorableClass]
    44   public class SimulatedAnnealingImprovementOperator: SingleSuccessorOperator, ILocalImprovementOperator {
     40  public sealed class SimulatedAnnealingImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator, IStochasticOperator {
     41    #region IGenericLocalImprovementOperator Properties
     42    public Type ProblemType { get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); } }
     43    public IProblem Problem {
     44      get { return problem; }
     45      set {
     46        if (problem != value) {
     47          if (value != null && !(value is ISingleObjectiveHeuristicOptimizationProblem))
     48            throw new ArgumentException("Only problems of type " + ProblemType.ToString() + " can be assigned.");
     49          if (problem != null) DeregisterProblemEventHandlers();
     50          problem = (ISingleObjectiveHeuristicOptimizationProblem)value;
     51          if (problem != null) RegisterProblemEventHandlers();
     52          UpdateProblem();
     53        }
     54      }
     55    }
     56    #endregion
     57
     58    [Storable]
     59    private ISingleObjectiveHeuristicOptimizationProblem problem;
    4560    [Storable]
    4661    private SimulatedAnnealingMainLoop loop;
    47 
    4862    [Storable]
    4963    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
    50    
     64
     65    #region Parameter Properties
     66    public ILookupParameter<IRandom> RandomParameter {
     67      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     68    }
    5169    private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
    5270      get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
     
    5876      get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
    5977    }
    60     private ValueParameter<IntValue> MaximumIterationsParameter {
    61       get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    62     }
    63     private ValueParameter<IntValue> InnerIterationsParameter {
    64       get { return (ValueParameter<IntValue>)Parameters["InnerIterations"]; }
    65     }
    66     public LookupParameter<IntValue> EvaluatedSolutionsParameter {
    67       get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     78    private IValueLookupParameter<IntValue> InnerIterationsParameter {
     79      get { return (IValueLookupParameter<IntValue>)Parameters["InnerIterations"]; }
    6880    }
    6981    public ValueParameter<MultiAnalyzer> AnalyzerParameter {
     
    7991      get { return (ConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["AnnealingOperator"]; }
    8092    }
    81 
     93    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
     94      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     95    }
     96    #region ILocalImprovementOperator Parameters
     97    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     98      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     99    }
     100    public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
     101      get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     102    }
     103    public ILookupParameter<ResultCollection> ResultsParameter {
     104      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
     105    }
     106    #endregion
     107    #endregion
     108
     109    #region Properties
    82110    public IMoveGenerator MoveGenerator {
    83111      get { return MoveGeneratorParameter.Value; }
     
    96124      set { AnalyzerParameter.Value = value; }
    97125    }
     126    #endregion
    98127
    99128    [StorableConstructor]
    100     protected SimulatedAnnealingImprovementOperator(bool deserializing) : base(deserializing) {}
     129    private SimulatedAnnealingImprovementOperator(bool deserializing) : base(deserializing) { }
     130    private SimulatedAnnealingImprovementOperator(SimulatedAnnealingImprovementOperator original, Cloner cloner)
     131      : base(original, cloner) {
     132      this.problem = cloner.Clone(original.problem);
     133      this.loop = cloner.Clone(original.loop);
     134      this.qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     135      RegisterEventHandlers();
     136    }
     137    public SimulatedAnnealingImprovementOperator()
     138      : base() {
     139      loop = new SimulatedAnnealingMainLoop();
     140
     141      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     142
     143      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
     144      Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
     145      Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
     146      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
     147      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(150)));
     148      Parameters.Add(new ValueLookupParameter<IntValue>("InnerIterations", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(1500)));
     149      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated moves."));
     150      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer()));
     151      Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100)));
     152      Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6)));
     153      Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("AnnealingOperator", "The operator used to modify the temperature."));
     154      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The variable where the results are stored."));
     155      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality/fitness value of a solution."));
     156
     157      foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
     158        AnnealingOperatorParameter.ValidValues.Add(op);
     159
     160      ParameterizeAnnealingOperators();
     161      ParameterizeSAMainLoop();
     162
     163      RegisterEventHandlers();
     164    }
     165
     166    public override IDeepCloneable Clone(Cloner cloner) {
     167      return new SimulatedAnnealingImprovementOperator(this, cloner);
     168    }
     169
    101170    [StorableHook(HookType.AfterDeserialization)]
    102171    private void AfterDeserialization() {
    103       Initialize();
    104     }
    105     protected SimulatedAnnealingImprovementOperator(SimulatedAnnealingImprovementOperator original, Cloner cloner)
    106       : base(original, cloner) {
    107         this.loop = cloner.Clone(original.loop);
    108         this.qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
    109         Initialize();
    110     }
    111     public override IDeepCloneable Clone(Cloner cloner) {
    112       return new SimulatedAnnealingImprovementOperator(this, cloner);
    113     }
    114     public SimulatedAnnealingImprovementOperator()
    115       : base() {
    116         loop = new SimulatedAnnealingMainLoop();
    117 
    118         qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    119 
    120         Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
    121         Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
    122         Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
    123         Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(150)));
    124         Parameters.Add(new ValueParameter<IntValue>("InnerIterations", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(1500)));
    125         Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated moves."));
    126         Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer()));
    127         Parameters.Add(new ValueParameter<DoubleValue>("StartTemperature", "The initial temperature.", new DoubleValue(100)));
    128         Parameters.Add(new ValueParameter<DoubleValue>("EndTemperature", "The final temperature which should be reached when iterations reaches maximum iterations.", new DoubleValue(1e-6)));
    129         Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("AnnealingOperator", "The operator used to modify the temperature."));
    130 
    131         foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
    132           AnnealingOperatorParameter.ValidValues.Add(op);
    133 
    134         ParameterizeAnnealingOperators();
    135 
    136         Initialize();
    137     }
    138 
    139     private void Initialize() {
     172      RegisterEventHandlers();
     173    }
     174
     175    #region Event Handler Registration
     176    private void RegisterEventHandlers() {
    140177      MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
    141     }
     178      if (problem != null)
     179        RegisterProblemEventHandlers();
     180    }
     181
     182    private void RegisterProblemEventHandlers() {
     183      problem.Reset += new EventHandler(problem_Reset);
     184      problem.OperatorsChanged += new EventHandler(problem_OperatorsChanged);
     185    }
     186
     187    private void DeregisterProblemEventHandlers() {
     188      problem.Reset -= new EventHandler(problem_Reset);
     189      problem.OperatorsChanged -= new EventHandler(problem_OperatorsChanged);
     190    }
     191    #endregion
     192
     193    #region Event Handlers
     194    private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
     195      ChooseMoveOperators();
     196      ParameterizeSAMainLoop();
     197    }
     198
     199    private void problem_Reset(object sender, EventArgs e) {
     200      UpdateProblem();
     201    }
     202
     203    private void problem_OperatorsChanged(object sender, EventArgs e) {
     204      UpdateProblem();
     205    }
     206    #endregion
    142207
    143208    private void ParameterizeAnnealingOperators() {
     
    152217    }
    153218
    154     public void OnProblemChanged(IProblem problem) {
    155       UpdateMoveOperators(problem);
     219    public void UpdateProblem() {
     220      UpdateMoveOperators();
    156221      ChooseMoveOperators();
    157222
    158       ParameterizeMoveGenerators(problem as ISingleObjectiveHeuristicOptimizationProblem);
    159       ParameterizeMoveEvaluators(problem as ISingleObjectiveHeuristicOptimizationProblem);
    160       ParameterizeMoveMakers(problem as ISingleObjectiveHeuristicOptimizationProblem);
    161 
    162       ParameterizeAnalyzers(problem as ISingleObjectiveHeuristicOptimizationProblem);
    163       UpdateAnalyzers(problem as ISingleObjectiveHeuristicOptimizationProblem);
    164     }
    165 
    166     void ParameterizeAnalyzers(ISingleObjectiveHeuristicOptimizationProblem problem) {
     223      ParameterizeMoveGenerators();
     224
     225      ParameterizeSAMainLoop();
     226      ParameterizeAnalyzers();
     227      UpdateAnalyzers();
     228    }
     229
     230    private void ParameterizeAnalyzers() {
    167231      qualityAnalyzer.ResultsParameter.ActualName = "Results";
    168232      if (problem != null) {
     
    174238    }
    175239
    176     void UpdateAnalyzers(ISingleObjectiveHeuristicOptimizationProblem problem) {
     240    private void ParameterizeSAMainLoop() {
     241      loop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     242      loop.EvaluatedMovesParameter.ActualName = EvaluatedSolutionsParameter.Name;
     243      loop.IterationsParameter.ActualName = "LocalIterations";
     244      loop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
     245      loop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
     246      loop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
     247      loop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
     248      loop.QualityParameter.ActualName = QualityParameter.Name;
     249      loop.RandomParameter.ActualName = RandomParameter.Name;
     250      loop.ResultsParameter.ActualName = ResultsParameter.Name;
     251
     252      if (problem != null) {
     253        loop.BestKnownQualityParameter.ActualName = problem.BestKnownQualityParameter.Name;
     254        loop.MaximizationParameter.ActualName = problem.MaximizationParameter.Name;
     255      }
     256      if (MoveEvaluator != null) {
     257        loop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
     258      }
     259    }
     260
     261    private void UpdateAnalyzers() {
    177262      Analyzer.Operators.Clear();
    178263      if (problem != null) {
     
    187272    }
    188273
    189     void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
    190       ChooseMoveOperators();
    191     }
    192 
    193     private void UpdateMoveOperators(IProblem problem) {
     274    private void UpdateMoveOperators() {
    194275      IMoveGenerator oldMoveGenerator = MoveGenerator;
    195276      IMoveMaker oldMoveMaker = MoveMaker;
     
    199280
    200281      if (problem != null) {
    201         foreach (IMoveGenerator generator in problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name))
     282        foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name))
    202283          MoveGeneratorParameter.ValidValues.Add(generator);
    203 
    204         foreach (IMoveMaker maker in problem.Operators.OfType<IMoveMaker>().OrderBy(x => x.Name))
    205           MoveMakerParameter.ValidValues.Add(maker);
    206 
    207         foreach (ISingleObjectiveMoveEvaluator evaluator in problem.Operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(x => x.Name))
    208           MoveEvaluatorParameter.ValidValues.Add(evaluator);
    209       }
    210 
    211       if (oldMoveGenerator != null) {
    212         IMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
    213         if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
    214       }
    215       if (MoveGenerator == null) {
    216         ClearMoveParameters();
    217       }
    218 
    219       if (oldMoveMaker != null) {
    220         IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    221         if (mm != null) MoveMaker = mm;
    222       }
    223 
    224       if (oldMoveEvaluator != null) {
    225         ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    226         if (me != null) MoveEvaluator = me;
    227       }
    228     }
    229 
    230     private void ChooseMoveOperators() {
    231       IMoveMaker oldMoveMaker = MoveMaker;
    232       ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
     284        foreach (IExhaustiveMoveGenerator generator in problem.Operators.OfType<IExhaustiveMoveGenerator>().OrderBy(x => x.Name))
     285          MoveGeneratorParameter.ValidValues.Add(generator);
     286
     287        if (oldMoveGenerator != null) {
     288          IMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
     289          if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
     290        }
     291
     292        ChooseMoveOperators(oldMoveMaker, oldMoveEvaluator);
     293      }
     294    }
     295
     296    private void ChooseMoveOperators(IMoveMaker oldMoveMaker = null, ISingleObjectiveMoveEvaluator oldMoveEvaluator = null) {
     297      if (oldMoveMaker == null) oldMoveMaker = MoveMaker;
     298      if (oldMoveEvaluator == null) oldMoveEvaluator = MoveEvaluator;
     299      MoveMakerParameter.ValidValues.Clear();
     300      MoveEvaluatorParameter.ValidValues.Clear();
    233301
    234302      if (MoveGenerator != null) {
    235         List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
    236         foreach (Type type in moveTypes.ToList()) {
    237           if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
    238             moveTypes.Remove(type);
    239         }
    240         List<IMoveMaker> validMoveMakers = new List<IMoveMaker>();
    241         List<ISingleObjectiveMoveEvaluator> validMoveEvaluators = new List<ISingleObjectiveMoveEvaluator>();
    242 
    243         foreach (Type type in moveTypes) {
    244           var moveMakers = MoveMakerParameter.ValidValues.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    245           foreach (IMoveMaker moveMaker in moveMakers)
    246             validMoveMakers.Add(moveMaker);
    247 
    248           var moveEvaluators = MoveEvaluatorParameter.ValidValues.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    249           foreach (ISingleObjectiveMoveEvaluator moveEvaluator in moveEvaluators)
    250             validMoveEvaluators.Add(moveEvaluator);
    251         }
     303        IMoveGenerator generator = MoveGeneratorParameter.Value;
     304        foreach (IMoveMaker moveMaker in MoveHelper.GetCompatibleMoveMakers(generator, Problem.Operators).OrderBy(x => x.Name))
     305          MoveMakerParameter.ValidValues.Add(moveMaker);
     306        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in MoveHelper.GetCompatibleSingleObjectiveMoveEvaluators(generator, Problem.Operators).OrderBy(x => x.Name))
     307          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     308
    252309        if (oldMoveMaker != null) {
    253           IMoveMaker mm = validMoveMakers.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
     310          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    254311          if (mm != null) MoveMaker = mm;
    255           else MoveMaker = validMoveMakers.FirstOrDefault();
    256         }
    257 
     312        }
    258313        if (oldMoveEvaluator != null) {
    259           ISingleObjectiveMoveEvaluator me = validMoveEvaluators.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
     314          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    260315          if (me != null) MoveEvaluator = me;
    261           else MoveEvaluator = validMoveEvaluators.FirstOrDefault();
    262         }
     316        }
    263317      }
    264318    }
     
    270324    }
    271325
    272     private void ParameterizeMoveGenerators(ISingleObjectiveHeuristicOptimizationProblem problem) {
     326    private void ParameterizeMoveGenerators() {
    273327      if (problem != null) {
    274328        foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>())
     
    276330      }
    277331    }
    278     private void ParameterizeMoveEvaluators(ISingleObjectiveHeuristicOptimizationProblem problem) {
    279       foreach (ISingleObjectiveMoveEvaluator op in problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
    280         op.QualityParameter.ActualName = problem.Evaluator.QualityParameter.ActualName;
    281       }
    282     }
    283     private void ParameterizeMoveMakers(ISingleObjectiveHeuristicOptimizationProblem problem) {
    284       foreach (IMoveMaker op in problem.Operators.OfType<IMoveMaker>()) {
    285         op.QualityParameter.ActualName = problem.Evaluator.QualityParameter.ActualName;
    286         if (MoveEvaluator != null)
    287           op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
    288       }
    289     }
    290332
    291333    public override IOperation Apply() {
    292       Scope subScope = new Scope();
     334      IScope currentScope = ExecutionContext.Scope;
     335
     336      Scope localScope = new Scope();
    293337      Scope individual = new Scope();
    294338
    295       foreach (Variable var in ExecutionContext.Scope.Variables) {
    296         individual.Variables.Add(var);
    297       }
    298       subScope.SubScopes.Add(individual);
    299 
    300       ExecutionContext.Scope.SubScopes.Add(subScope);
    301       int index = subScope.Parent.SubScopes.IndexOf(subScope);
     339      foreach (IVariable var in currentScope.Variables)
     340        individual.Variables.Add(var); // add reference to variable otherwise the analyzer fails (it's looking down the tree)
     341
     342      localScope.SubScopes.Add(individual);
     343      currentScope.SubScopes.Add(localScope);
     344      int index = currentScope.SubScopes.Count - 1;
    302345
    303346      SubScopesProcessor processor = new SubScopesProcessor();
     
    307350      remover.SubScopeIndexParameter.Value = new IntValue(index);
    308351
    309       for (int i = 0; i < index; i++) {
    310         processor.Operators.Add(new EmptyOperator());
     352      if (index > 0) {
     353        EmptyOperator eo = new EmptyOperator();
     354        for (int i = 0; i < index - 1; i++) {
     355          processor.Operators.Add(eo);
     356        }
    311357      }
    312358
    313359      VariableCreator variableCreator = new VariableCreator();
    314       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("LocalIterations", new IntValue(0)));
     360      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>(loop.IterationsParameter.ActualName, new IntValue(0)));
    315361
    316362      variableCreator.Successor = loop;
    317 
    318       loop.EvaluatedMovesParameter.ActualName = EvaluatedSolutionsParameter.ActualName;
    319363
    320364      processor.Operators.Add(variableCreator);
    321365      processor.Successor = remover;
    322366
    323       IOperation next = base.Apply();
    324       if (next as ExecutionContext != null) {
    325         remover.Successor = (next as ExecutionContext).Operator;
    326       }
    327 
    328       return ExecutionContext.CreateChildOperation(processor);
     367      OperationCollection next = new OperationCollection(base.Apply());
     368      next.Insert(0, ExecutionContext.CreateChildOperation(processor));
     369
     370      return next;
    329371    }
    330372  }
  • branches/histogram/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs

    r5753 r6046  
    6161    }
    6262    public LookupParameter<IntValue> IterationsParameter {
    63       get { return (LookupParameter<IntValue>)Parameters["LocalIterations"]; }
     63      get { return (LookupParameter<IntValue>)Parameters["Iterations"]; }
    6464    }
    6565    public ValueLookupParameter<IntValue> MaximumIterationsParameter {
     
    112112      Parameters.Add(new ValueLookupParameter<DoubleValue>("EndTemperature", "The end temperature."));
    113113      Parameters.Add(new ValueLookupParameter<IntValue>("InnerIterations", "The amount of inner iterations (number of moves before temperature is adjusted again)."));
    114       Parameters.Add(new LookupParameter<IntValue>("LocalIterations", "The number of generations."));
     114      Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations."));
    115115      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed."));
    116116
     
    231231    }
    232232
     233    [StorableHook(HookType.AfterDeserialization)]
     234    private void AfterDeserialization() {
     235      // BackwardsCompatibility3.3
     236      #region Backwards compatible code (remove with 3.4)
     237      if (!Parameters.ContainsKey("Iterations"))
     238        Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations."));
     239      #endregion
     240    }
     241
    233242    public override IOperation Apply() {
    234243      if (MoveGeneratorParameter.ActualValue == null || MoveEvaluatorParameter.ActualValue == null || MoveMakerParameter.ActualValue == null)
Note: See TracChangeset for help on using the changeset viewer.