Changeset 6042


Ignore:
Timestamp:
04/23/11 00:29:24 (9 years ago)
Author:
abeham
Message:

#1425

  • Changed LocalImprovementOperators
    • Changed interface (made Problem a property, added a property that denotes the type of the problem that it can be applied on, added some general parameters)
    • Added some parameters and wiring
    • Changed move discovery and parameterization and added a helper class to ease finding compatible move operators
    • Discovering only IMultiMoveOperators and IExhaustiveMoveOperators and putting the multi move ones first
    • Fixed bug in Apply method that could create an endless string of nested execution contexts
    • Removed all problem specific analyzers in the two local improvement operators and only left the BestAverageWorstQualityAnalyzer since it doesn't make any sense to perform diversity or allele analysis during local improvement in the most common case and those analyzers take a lot of time (one can always add them manually should he/she be interested). The analyzers in the VNS's Analyzer parameter are left untouched.
  • Removed shaking operator and interface from VNS plugin and added that to Optimization and Optimization.Operators
  • Changed some ValueParameters to ConstrainedValueParameters and added type discovery to fill them (using the ProblemType property to get compatible local improvement operators)
  • Added missing GPL license headers
  • Changed some ValueParameters to the new FixedValueParameters
  • Added an additional encoding specific ShakingOperator to each encoding and added that to each problem
    • reason is that only the problem/encoding can really decide if a shaking operator is meaningful or not
  • Fixed an unrelated bug in the BestAverageWorstQualityAnalyzer that I encountered (and made the fix backwards compatible)
    • Also added a snippet for creating the backwards compatible comment marker and region
  • Fixed the operator graph of the VNS main loop
    • The condition to continue only when the local search was not successful is not necessary and is not part of the VNS definition as far as I know it (only condition to break the inner loop is when k reaches k_max)
  • Changed the ShakingOperator to input current index and output the maximum number of neighborhoods instead of a boolean that indicates that the last index has been reached since the maximum number is a little more generally useful and equally powerful in modeling
    • Remodeled the VNS main loop to check for k < k_max in order to continue the inner loop
  • other changes that I forgot...

Still necessary

  • test, test, test
  • check for backwards compatible breakers
  • add a maximum evaluated solutions stop criterion
  • optionally: implement fast problem specific local search improvement operators that do not build on the whole generic overhead (e.g. a 2-opt TSP specific local search operator). The idea of VNS is really to converge to a local optimum which is difficult to achieve using the current rather limited termination options
Location:
trunk
Files:
19 added
2 deleted
27 edited

Legend:

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

    r5809 r6042  
    185185      mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";
    186186      mainLoop.IterationsParameter.ActualName = "Iterations";
    187       mainLoop.BestQualityParameter.ActualName = "BestQuality";
     187      mainLoop.BestLocalQualityParameter.ActualName = "BestQuality";
    188188
    189189      moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchImprovementOperator.cs

    r5809 r6042  
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using System.Linq;
    2524using HeuristicLab.Analysis;
     
    2928using HeuristicLab.Operators;
    3029using HeuristicLab.Optimization;
    31 using HeuristicLab.Optimization.Operators;
    3230using HeuristicLab.Parameters;
    3331using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3937  [Item("LocalSearchImprovementOperator", "A local search improvement operator.")]
    4038  [StorableClass]
    41   public class LocalSearchImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator {
     39  public sealed class LocalSearchImprovementOperator : SingleSuccessorOperator, IGenericLocalImprovementOperator, IStochasticOperator {
     40    #region IGenericLocalImprovementOperator Properties
     41    public Type ProblemType { get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); } }
     42    public IProblem Problem {
     43      get { return problem; }
     44      set {
     45        if (problem != value) {
     46          if (value != null && !(value is ISingleObjectiveHeuristicOptimizationProblem))
     47            throw new ArgumentException("Only problems of type " + ProblemType.ToString() + " can be assigned.");
     48          if (problem != null) DeregisterProblemEventHandlers();
     49          problem = (ISingleObjectiveHeuristicOptimizationProblem)value;
     50          if (problem != null) RegisterProblemEventHandlers();
     51          UpdateProblem();
     52        }
     53      }
     54    }
     55    #endregion
     56
     57    [Storable]
     58    private ISingleObjectiveHeuristicOptimizationProblem problem;
    4259    [Storable]
    4360    private LocalSearchMainLoop loop;
    44 
    4561    [Storable]
    4662    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
    4763
    48     private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
     64    #region Parameter Properties
     65    public ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter {
    4966      get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; }
    5067    }
    51     private ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
     68    public ConstrainedValueParameter<IMoveMaker> MoveMakerParameter {
    5269      get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; }
    5370    }
    54     private ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
     71    public ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {
    5572      get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; }
    5673    }
    57     private ValueParameter<IntValue> MaximumIterationsParameter {
    58       get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    59     }
    60     private ValueParameter<IntValue> SampleSizeParameter {
    61       get { return (ValueParameter<IntValue>)Parameters["SampleSize"]; }
    62     }
    63     public LookupParameter<IntValue> EvaluatedSolutionsParameter {
    64       get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     74    public IValueLookupParameter<IntValue> SampleSizeParameter {
     75      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
    6576    }
    6677    public ValueParameter<MultiAnalyzer> AnalyzerParameter {
    6778      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    6879    }
    69 
     80    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
     81      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     82    }
     83    public ILookupParameter<IRandom> RandomParameter {
     84      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     85    }
     86    #region ILocalImprovementOperator Parameters
     87    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     88      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     89    }
     90    public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
     91      get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     92    }
     93    public ILookupParameter<ResultCollection> ResultsParameter {
     94      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
     95    }
     96    #endregion
     97    #endregion
     98
     99    #region Properties
    70100    public IMoveGenerator MoveGenerator {
    71101      get { return MoveGeneratorParameter.Value; }
     
    84114      set { AnalyzerParameter.Value = value; }
    85115    }
     116    #endregion
    86117
    87118    [StorableConstructor]
    88     protected LocalSearchImprovementOperator(bool deserializing) : base(deserializing) { }
    89     [StorableHook(HookType.AfterDeserialization)]
    90     private void AfterDeserialization() {
    91       Initialize();
    92     }
    93     protected LocalSearchImprovementOperator(LocalSearchImprovementOperator original, Cloner cloner)
     119    private LocalSearchImprovementOperator(bool deserializing) : base(deserializing) { }
     120    private LocalSearchImprovementOperator(LocalSearchImprovementOperator original, Cloner cloner)
    94121      : base(original, cloner) {
    95122      this.loop = cloner.Clone(original.loop);
    96123      this.qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
    97       Initialize();
    98     }
    99     public override IDeepCloneable Clone(Cloner cloner) {
    100       return new LocalSearchImprovementOperator(this, cloner);
     124      this.problem = cloner.Clone(original.problem);
     125      RegisterEventHandlers();
    101126    }
    102127    public LocalSearchImprovementOperator()
    103128      : base() {
    104       loop = new LocalSearchMainLoop();
    105 
    106       ResultsCollector rc = (loop.OperatorGraph.InitialOperator as SingleSuccessorOperator).Successor as ResultsCollector;
    107       rc.CollectedValues.Remove("BestLocalQuality");
    108 
    109       qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    110 
    111129      Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution."));
    112130      Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move."));
    113131      Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move."));
    114       Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(150)));
    115       Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(1500)));
     132      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(150)));
     133      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(300)));
    116134      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated moves."));
    117135      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer()));
    118 
    119       Initialize();
    120     }
    121 
    122     private void Initialize() {
     136      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The name of the collection where the results are stored."));
     137      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality/fitness value of a solution."));
     138      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
     139
     140      loop = new LocalSearchMainLoop();
     141      ParameterizeLSMainLoop();
     142
     143      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     144      Analyzer.Operators.Add(qualityAnalyzer);
     145
     146      RegisterEventHandlers();
     147    }
     148
     149    public override IDeepCloneable Clone(Cloner cloner) {
     150      return new LocalSearchImprovementOperator(this, cloner);
     151    }
     152
     153    [StorableHook(HookType.AfterDeserialization)]
     154    private void AfterDeserialization() {
     155      RegisterEventHandlers();
     156    }
     157
     158    #region Event Handler Registration
     159    private void RegisterEventHandlers() {
    123160      MoveGeneratorParameter.ValueChanged += new EventHandler(MoveGeneratorParameter_ValueChanged);
    124     }
    125 
    126     public void OnProblemChanged(IProblem problem) {
    127       UpdateMoveOperators(problem);
     161      if (problem != null)
     162        RegisterProblemEventHandlers();
     163    }
     164
     165    private void RegisterProblemEventHandlers() {
     166      problem.Reset += new EventHandler(problem_Reset);
     167      problem.OperatorsChanged += new EventHandler(problem_OperatorsChanged);
     168    }
     169
     170    private void DeregisterProblemEventHandlers() {
     171      problem.Reset -= new EventHandler(problem_Reset);
     172      problem.OperatorsChanged -= new EventHandler(problem_OperatorsChanged);
     173    }
     174    #endregion
     175
     176    #region Event Handlers
     177    private void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
    128178      ChooseMoveOperators();
    129 
    130       ParameterizeMoveGenerators(problem as ISingleObjectiveHeuristicOptimizationProblem);
    131       ParameterizeMoveEvaluators(problem as ISingleObjectiveHeuristicOptimizationProblem);
    132       ParameterizeMoveMakers(problem as ISingleObjectiveHeuristicOptimizationProblem);
    133 
    134       ParameterizeAnalyzers(problem as ISingleObjectiveHeuristicOptimizationProblem);
    135       UpdateAnalyzers(problem as ISingleObjectiveHeuristicOptimizationProblem);
    136     }
    137 
    138     void ParameterizeAnalyzers(ISingleObjectiveHeuristicOptimizationProblem problem) {
    139       qualityAnalyzer.ResultsParameter.ActualName = "Results";
     179      ParameterizeLSMainLoop();
     180    }
     181
     182    private void problem_Reset(object sender, EventArgs e) {
     183      UpdateProblem();
     184    }
     185
     186    private void problem_OperatorsChanged(object sender, EventArgs e) {
     187      UpdateProblem();
     188    }
     189    #endregion
     190
     191    #region Parameterize and Update Methods
     192    private void UpdateProblem() {
     193      UpdateMoveOperators();
     194      ChooseMoveOperators();
     195
     196      ParameterizeMoveGenerators();
     197
     198      ParameterizeLSMainLoop();
     199      ParameterizeAnalyzers();
     200    }
     201
     202    private void ParameterizeLSMainLoop() {
     203      loop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     204      loop.BestLocalQualityParameter.ActualName = QualityParameter.Name;
     205      loop.EvaluatedMovesParameter.ActualName = EvaluatedSolutionsParameter.Name;
     206      loop.IterationsParameter.ActualName = "LocalIterations";
     207      loop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
     208      loop.MoveEvaluatorParameter.ActualName = MoveEvaluatorParameter.Name;
     209      loop.MoveGeneratorParameter.ActualName = MoveGeneratorParameter.Name;
     210      loop.MoveMakerParameter.ActualName = MoveMakerParameter.Name;
     211      loop.QualityParameter.ActualName = QualityParameter.Name;
     212      loop.RandomParameter.ActualName = RandomParameter.Name;
     213      loop.ResultsParameter.ActualName = ResultsParameter.Name;
     214
     215      if (problem != null) {
     216        loop.BestKnownQualityParameter.ActualName = problem.BestKnownQualityParameter.Name;
     217        loop.MaximizationParameter.ActualName = problem.MaximizationParameter.Name;
     218      }
     219      if (MoveEvaluator != null) {
     220        loop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
     221      }
     222    }
     223
     224    private void ParameterizeAnalyzers() {
     225      qualityAnalyzer.ResultsParameter.ActualName = ResultsParameter.Name;
    140226      if (problem != null) {
    141227        qualityAnalyzer.MaximizationParameter.ActualName = problem.MaximizationParameter.Name;
     
    146232    }
    147233
    148     void UpdateAnalyzers(ISingleObjectiveHeuristicOptimizationProblem problem) {
    149       Analyzer.Operators.Clear();
    150       if (problem != null) {
    151         foreach (IAnalyzer analyzer in problem.Operators.OfType<IAnalyzer>()) {
    152           IAnalyzer clone = analyzer.Clone() as IAnalyzer;
    153           foreach (IScopeTreeLookupParameter param in clone.Parameters.OfType<IScopeTreeLookupParameter>())
    154             param.Depth = 0;
    155           Analyzer.Operators.Add(clone);
    156         }
    157       }
    158       Analyzer.Operators.Add(qualityAnalyzer);
    159     }
    160 
    161     void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) {
    162       ChooseMoveOperators();
    163     }
    164 
    165     private void UpdateMoveOperators(IProblem problem) {
     234    private void UpdateMoveOperators() {
    166235      IMoveGenerator oldMoveGenerator = MoveGenerator;
    167236      IMoveMaker oldMoveMaker = MoveMaker;
     
    171240
    172241      if (problem != null) {
    173         foreach (IMoveGenerator generator in problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name))
     242        foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name))
    174243          MoveGeneratorParameter.ValidValues.Add(generator);
    175 
    176         foreach (IMoveMaker maker in problem.Operators.OfType<IMoveMaker>().OrderBy(x => x.Name))
    177           MoveMakerParameter.ValidValues.Add(maker);
    178 
    179         foreach (ISingleObjectiveMoveEvaluator evaluator in problem.Operators.OfType<ISingleObjectiveMoveEvaluator>().OrderBy(x => x.Name))
    180           MoveEvaluatorParameter.ValidValues.Add(evaluator);
    181       }
    182 
    183       if (oldMoveGenerator != null) {
    184         IMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
    185         if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
    186       }
    187       if (MoveGenerator == null) {
    188         ClearMoveParameters();
    189       }
    190 
    191       if (oldMoveMaker != null) {
    192         IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    193         if (mm != null) MoveMaker = mm;
    194       }
    195 
    196       if (oldMoveEvaluator != null) {
    197         ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    198         if (me != null) MoveEvaluator = me;
    199       }
    200     }
    201 
    202     private void ChooseMoveOperators() {
    203       IMoveMaker oldMoveMaker = MoveMaker;
    204       ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;
    205 
    206       if (MoveGenerator != null) {
    207         List<Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
    208         foreach (Type type in moveTypes.ToList()) {
    209           if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
    210             moveTypes.Remove(type);
    211         }
    212         List<IMoveMaker> validMoveMakers = new List<IMoveMaker>();
    213         List<ISingleObjectiveMoveEvaluator> validMoveEvaluators = new List<ISingleObjectiveMoveEvaluator>();
    214 
    215         foreach (Type type in moveTypes) {
    216           var moveMakers = MoveMakerParameter.ValidValues.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    217           foreach (IMoveMaker moveMaker in moveMakers)
    218             validMoveMakers.Add(moveMaker);
    219 
    220           var moveEvaluators = MoveEvaluatorParameter.ValidValues.Where(x => type.IsAssignableFrom(x.GetType())).OrderBy(x => x.Name);
    221           foreach (ISingleObjectiveMoveEvaluator moveEvaluator in moveEvaluators)
    222             validMoveEvaluators.Add(moveEvaluator);
    223         }
     244        foreach (IExhaustiveMoveGenerator generator in problem.Operators.OfType<IExhaustiveMoveGenerator>().OrderBy(x => x.Name))
     245          MoveGeneratorParameter.ValidValues.Add(generator);
     246
     247        if (oldMoveGenerator != null) {
     248          IMoveGenerator newMoveGenerator = MoveGeneratorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveGenerator.GetType());
     249          if (newMoveGenerator != null) MoveGenerator = newMoveGenerator;
     250        }
     251
     252        ChooseMoveOperators(oldMoveMaker, oldMoveEvaluator);
     253      }
     254    }
     255
     256    private void ChooseMoveOperators(IMoveMaker oldMoveMaker = null, ISingleObjectiveMoveEvaluator oldMoveEvaluator = null) {
     257      if (oldMoveMaker == null) oldMoveMaker = MoveMaker;
     258      if (oldMoveEvaluator == null) oldMoveEvaluator = MoveEvaluator;
     259      MoveMakerParameter.ValidValues.Clear();
     260      MoveEvaluatorParameter.ValidValues.Clear();
     261
     262      if (MoveGenerator != null && Problem != null) {
     263        IMoveGenerator generator = MoveGeneratorParameter.Value;
     264        foreach (IMoveMaker moveMaker in MoveHelper.GetCompatibleMoveMakers(generator, Problem.Operators).OrderBy(x => x.Name))
     265          MoveMakerParameter.ValidValues.Add(moveMaker);
     266        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in MoveHelper.GetCompatibleSingleObjectiveMoveEvaluators(generator, Problem.Operators).OrderBy(x => x.Name))
     267          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
     268
    224269        if (oldMoveMaker != null) {
    225           IMoveMaker mm = validMoveMakers.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
     270          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
    226271          if (mm != null) MoveMaker = mm;
    227           else MoveMaker = validMoveMakers.FirstOrDefault();
    228         }
    229 
     272        }
    230273        if (oldMoveEvaluator != null) {
    231           ISingleObjectiveMoveEvaluator me = validMoveEvaluators.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
     274          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
    232275          if (me != null) MoveEvaluator = me;
    233           else MoveEvaluator = validMoveEvaluators.FirstOrDefault();
    234276        }
    235277      }
     
    242284    }
    243285
    244     private void ParameterizeMoveGenerators(ISingleObjectiveHeuristicOptimizationProblem problem) {
     286    private void ParameterizeMoveGenerators() {
    245287      if (problem != null) {
    246288        foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>())
     
    248290      }
    249291    }
    250     private void ParameterizeMoveEvaluators(ISingleObjectiveHeuristicOptimizationProblem problem) {
    251       foreach (ISingleObjectiveMoveEvaluator op in problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) {
    252         op.QualityParameter.ActualName = problem.Evaluator.QualityParameter.ActualName;
    253       }
    254     }
    255     private void ParameterizeMoveMakers(ISingleObjectiveHeuristicOptimizationProblem problem) {
    256       foreach (IMoveMaker op in problem.Operators.OfType<IMoveMaker>()) {
    257         op.QualityParameter.ActualName = problem.Evaluator.QualityParameter.ActualName;
    258         if (MoveEvaluator != null)
    259           op.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;
    260       }
    261     }
     292    #endregion
    262293
    263294    public override IOperation Apply() {
    264       Scope subScope = new Scope();
     295      IScope currentScope = ExecutionContext.Scope;
     296
     297      Scope localScope = new Scope();
    265298      Scope individual = new Scope();
    266299
    267       foreach (Variable var in ExecutionContext.Scope.Variables) {
    268         individual.Variables.Add(var);
    269       }
    270       subScope.SubScopes.Add(individual);
    271 
    272       ExecutionContext.Scope.SubScopes.Add(subScope);
    273       int index = subScope.Parent.SubScopes.IndexOf(subScope);
     300      foreach (IVariable var in currentScope.Variables)
     301        individual.Variables.Add(var); // add reference to variable otherwise the analyzer fails (it's looking down the tree)
     302
     303      localScope.SubScopes.Add(individual);
     304      currentScope.SubScopes.Add(localScope);
     305      int index = currentScope.SubScopes.Count - 1;
    274306
    275307      SubScopesProcessor processor = new SubScopesProcessor();
     
    279311      remover.SubScopeIndexParameter.Value = new IntValue(index);
    280312
    281       for (int i = 0; i < index; i++) {
    282         processor.Operators.Add(new EmptyOperator());
     313      if (index > 0) {
     314        EmptyOperator eo = new EmptyOperator();
     315        for (int i = 0; i < index - 1; i++) {
     316          processor.Operators.Add(eo);
     317        }
    283318      }
    284319
    285320      VariableCreator variableCreator = new VariableCreator();
    286       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("LocalIterations", new IntValue(0)));
    287       variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestLocalQuality", new DoubleValue(0)));
     321      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>(loop.IterationsParameter.ActualName, new IntValue(0)));
     322      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>(loop.BestLocalQualityParameter.ActualName, new DoubleValue(0)));
    288323
    289324      variableCreator.Successor = loop;
    290 
    291       loop.EvaluatedMovesParameter.ActualName = EvaluatedSolutionsParameter.ActualName;
    292325
    293326      processor.Operators.Add(variableCreator);
    294327      processor.Successor = remover;
    295328
    296       IOperation next = base.Apply();
    297       if (next as ExecutionContext != null) {
    298         remover.Successor = (next as ExecutionContext).Operator;
    299       }
    300 
    301       return ExecutionContext.CreateChildOperation(processor);
     329      OperationCollection next = new OperationCollection(base.Apply());
     330      next.Insert(0, ExecutionContext.CreateChildOperation(processor));
     331
     332      return next;
    302333    }
    303334  }
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs

    r5753 r6042  
    4646      get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
    4747    }
    48     public LookupParameter<DoubleValue> BestQualityParameter {
     48    public LookupParameter<DoubleValue> BestLocalQualityParameter {
    4949      get { return (LookupParameter<DoubleValue>)Parameters["BestLocalQuality"]; }
    5050    }
     
    5656    }
    5757    public LookupParameter<IntValue> IterationsParameter {
    58       get { return (LookupParameter<IntValue>)Parameters["LocalIterations"]; }
     58      get { return (LookupParameter<IntValue>)Parameters["Iterations"]; }
    5959    }
    6060    public ValueLookupParameter<IntValue> MaximumIterationsParameter {
     
    8585    public LocalSearchMainLoop()
    8686      : base() {
    87         Initialize();
     87      Initialize();
    8888    }
    8989    private LocalSearchMainLoop(LocalSearchMainLoop original, Cloner cloner)
     
    100100      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    101101      Parameters.Add(new LookupParameter<DoubleValue>("BestLocalQuality", "The value which represents the best quality found so far."));
    102       Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
     102      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far."));
    103103      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
    104       Parameters.Add(new LookupParameter<IntValue>("LocalIterations", "The number of generations."));
     104      Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations performed."));
    105105      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
    106106      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
     
    140140
    141141      bestQualityInitializer.Name = "Initialize BestQuality";
    142       bestQualityInitializer.LeftSideParameter.ActualName = BestQualityParameter.Name;
     142      bestQualityInitializer.LeftSideParameter.ActualName = BestLocalQualityParameter.Name;
    143143      bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name;
    144144
     
    148148      resultsCollector1.CopyValue = new BoolValue(false);
    149149      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name));
    150       resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(BestQualityParameter.Name, null, BestQualityParameter.Name));
     150      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name));
    151151      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
    152152
     
    177177
    178178      bestQualityUpdater.Name = "Update BestQuality";
    179       bestQualityUpdater.LeftSideParameter.ActualName = BestQualityParameter.Name;
     179      bestQualityUpdater.LeftSideParameter.ActualName = BestLocalQualityParameter.Name;
    180180      bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name;
    181181
    182182      resultsCollector2.CopyValue = new BoolValue(false);
    183       resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(BestQualityParameter.Name, null, BestQualityParameter.Name));
     183      resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name));
    184184      resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name;
    185185
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingImprovementOperator.cs

    r5809 r6042  
    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, IGenericLocalImprovementOperator, 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  }
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs

    r5753 r6042  
    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)
  • trunk/sources/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/HeuristicLab.Algorithms.VariableNeighborhoodSearch-3.3.csproj

    r5753 r6042  
    108108  <ItemGroup>
    109109    <Compile Include="HeuristicLabAlgorithmsVariableNeighborhoodSearchPlugin.cs" />
    110     <Compile Include="IShakingOperator.cs" />
    111110    <Compile Include="Properties\AssemblyInfo.cs" />
    112     <Compile Include="ShakingOperator.cs" />
    113111    <Compile Include="VariableNeighborhoodSearch.cs" />
    114112    <Compile Include="VariableNeighborhoodSearchMainLoop.cs" />
     
    120118  </ItemGroup>
    121119  <ItemGroup>
    122     <ProjectReference Include="..\..\HeuristicLab.Algorithms.LocalSearch\3.3\HeuristicLab.Algorithms.LocalSearch-3.3.csproj">
    123       <Project>{4AE3FC69-C575-42D2-BC46-0FAD5850EFC5}</Project>
    124       <Name>HeuristicLab.Algorithms.LocalSearch-3.3</Name>
    125     </ProjectReference>
    126120    <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
    127121      <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project>
  • trunk/sources/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/HeuristicLabAlgorithmsVariableNeighborhoodSearchPlugin.cs.frame

    r5830 r6042  
    2828  [Plugin("HeuristicLab.Algorithms.VariableNeighborhoodSearch", "3.3.3.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Algorithms.VariableNeighborhoodSearch-3.3.dll", PluginFileType.Assembly)]
    30   [PluginDependency("HeuristicLab.Algorithms.LocalSearch", "3.3")]
    3130  [PluginDependency("HeuristicLab.Analysis", "3.3")] 
    3231  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • trunk/sources/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearch.cs

    r5809 r6042  
    1 using System;
    2 using System.Collections.Generic;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    323using System.Linq;
    4 using HeuristicLab.Algorithms.LocalSearch;
    524using HeuristicLab.Analysis;
    625using HeuristicLab.Common;
     
    1231using HeuristicLab.Parameters;
    1332using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     33using HeuristicLab.PluginInfrastructure;
    1434using HeuristicLab.Random;
    1535
     
    3252
    3353    #region Parameter Properties
    34     private ValueParameter<IntValue> SeedParameter {
    35       get { return (ValueParameter<IntValue>)Parameters["Seed"]; }
    36     }
    37     private ValueParameter<BoolValue> SetSeedRandomlyParameter {
    38       get { return (ValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    39     }
    40     private ValueParameter<ILocalImprovementOperator> LocalImprovementParameter {
    41       get { return (ValueParameter<ILocalImprovementOperator>)Parameters["LocalImprovement"]; }
    42     }
    43     private ValueParameter<IShakingOperator> ShakingParameter {
    44       get { return (ValueParameter<IShakingOperator>)Parameters["Shaking"]; }
    45     }
    46     private ValueParameter<IntValue> MaximumIterationsParameter {
    47       get { return (ValueParameter<IntValue>)Parameters["MaximumIterations"]; }
     54    private FixedValueParameter<IntValue> SeedParameter {
     55      get { return (FixedValueParameter<IntValue>)Parameters["Seed"]; }
     56    }
     57    private FixedValueParameter<BoolValue> SetSeedRandomlyParameter {
     58      get { return (FixedValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
     59    }
     60    private ConstrainedValueParameter<ILocalImprovementOperator> LocalImprovementParameter {
     61      get { return (ConstrainedValueParameter<ILocalImprovementOperator>)Parameters["LocalImprovement"]; }
     62    }
     63    private ConstrainedValueParameter<IMultiNeighborhoodShakingOperator> ShakingOperatorParameter {
     64      get { return (ConstrainedValueParameter<IMultiNeighborhoodShakingOperator>)Parameters["ShakingOperator"]; }
     65    }
     66    private FixedValueParameter<IntValue> MaximumIterationsParameter {
     67      get { return (FixedValueParameter<IntValue>)Parameters["MaximumIterations"]; }
    4868    }
    4969    private ValueParameter<MultiAnalyzer> AnalyzerParameter {
    5070      get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    5171    }
    52     private VariableNeighborhoodSearchMainLoop VNSMainLoop {
    53       get { return FindMainLoop(SolutionsCreator.Successor); }
     72    public FixedValueParameter<IntValue> LocalImprovementMaximumIterationsParameter {
     73      get { return (FixedValueParameter<IntValue>)Parameters["LocalImprovementMaximumIterations"]; }
    5474    }
    5575    #endregion
     
    6686      get { return (SolutionsCreator)RandomCreator.Successor; }
    6787    }
     88    private VariableNeighborhoodSearchMainLoop MainLoop {
     89      get { return FindMainLoop(SolutionsCreator.Successor); }
     90    }
    6891    #endregion
    6992
     
    7396    [StorableConstructor]
    7497    private VariableNeighborhoodSearch(bool deserializing) : base(deserializing) { }
    75     [StorableHook(HookType.AfterDeserialization)]
    76     private void AfterDeserialization() {
    77 
    78     }
    7998    private VariableNeighborhoodSearch(VariableNeighborhoodSearch original, Cloner cloner)
    8099      : base(original, cloner) {
    81100      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
    82       Initialize();
    83     }
    84     public override IDeepCloneable Clone(Cloner cloner) {
    85       return new VariableNeighborhoodSearch(this, cloner);
     101      RegisterEventHandlers();
    86102    }
    87103    public VariableNeighborhoodSearch()
    88104      : base() {
    89       Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    90       Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    91       Parameters.Add(new ValueParameter<ILocalImprovementOperator>("LocalImprovement", "The local improvement operation", new LocalSearchImprovementOperator()));
    92       Parameters.Add(new ValueParameter<IShakingOperator>("Shaking", "The shaking operation"));
    93       Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(1000)));
     105      Parameters.Add(new FixedValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     106      Parameters.Add(new FixedValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     107      Parameters.Add(new ConstrainedValueParameter<ILocalImprovementOperator>("LocalImprovement", "The local improvement operation"));
     108      Parameters.Add(new ConstrainedValueParameter<IMultiNeighborhoodShakingOperator>("ShakingOperator", "The operator that performs the shaking of solutions."));
     109      Parameters.Add(new FixedValueParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed.", new IntValue(50)));
     110      Parameters.Add(new FixedValueParameter<IntValue>("LocalImprovementMaximumIterations", "The maximum number of iterations which should be performed in the local improvement phase.", new IntValue(50)));
    94111      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer()));
    95112
     
    112129
    113130      variableCreator.Name = "Initialize Evaluated Solutions";
    114       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue()));
     131
     132      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
     133      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0)));
     134      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentNeighborhoodIndex", new IntValue(0)));
     135      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NeighborhoodCount", new IntValue(0)));
    115136      variableCreator.Successor = resultsCollector;
    116137
    117138      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
     139      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
    118140      resultsCollector.ResultsParameter.ActualName = "Results";
    119141      resultsCollector.Successor = mainLoop;
    120142
     143      mainLoop.IterationsParameter.ActualName = "Iterations";
     144      mainLoop.CurrentNeighborhoodIndexParameter.ActualName = "CurrentNeighborhoodIndex";
     145      mainLoop.NeighborhoodCountParameter.ActualName = "NeighborhoodCount";
    121146      mainLoop.LocalImprovementParameter.ActualName = LocalImprovementParameter.Name;
    122       mainLoop.ShakingParameter.ActualName = ShakingParameter.Name;
     147      mainLoop.ShakingOperatorParameter.ActualName = ShakingOperatorParameter.Name;
    123148      mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
    124149      mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
     
    127152      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
    128153
     154      InitializeLocalImprovementOperators();
    129155      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    130156      ParameterizeAnalyzers();
    131157      UpdateAnalyzers();
    132158
    133       Initialize();
     159      RegisterEventHandlers();
     160    }
     161
     162    public override IDeepCloneable Clone(Cloner cloner) {
     163      return new VariableNeighborhoodSearch(this, cloner);
     164    }
     165
     166    [StorableHook(HookType.AfterDeserialization)]
     167    private void AfterDeserialization() {
     168      RegisterEventHandlers();
    134169    }
    135170
     
    138173    }
    139174
    140     private void Initialize() {
     175    private void RegisterEventHandlers() {
     176      LocalImprovementParameter.ValueChanged += new EventHandler(LocalImprovementParameter_ValueChanged);
    141177      if (Problem != null) {
    142178        Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    143179      }
    144       LocalImprovementParameter.ValueChanged += new EventHandler(LocalImprovementParameter_ValueChanged);
    145180    }
    146181
    147182    #region Events
    148183    protected override void OnProblemChanged() {
     184      InitializeLocalImprovementOperators();
     185      UpdateShakingOperators();
     186      UpdateAnalyzers();
     187
    149188      ParameterizeStochasticOperator(Problem.SolutionCreator);
    150189      ParameterizeStochasticOperator(Problem.Evaluator);
    151190      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    152191      ParameterizeSolutionsCreator();
    153       ParameterizeVNSMainLoop();
     192      ParameterizeMainLoop();
    154193      ParameterizeAnalyzers();
    155194      ParameterizeIterationBasedOperators();
    156       UpdateShakingOperator();
    157       UpdateLocalImprovementOperator();
    158       UpdateAnalyzers();
     195      ParameterizeLocalImprovementOperators();
    159196      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    160197      base.OnProblemChanged();
    161198    }
    162 
    163199    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
    164200      ParameterizeStochasticOperator(Problem.SolutionCreator);
     
    169205      ParameterizeStochasticOperator(Problem.Evaluator);
    170206      ParameterizeSolutionsCreator();
    171       ParameterizeVNSMainLoop();
     207      ParameterizeMainLoop();
    172208      ParameterizeAnalyzers();
    173209      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    175211    }
    176212    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     213      UpdateShakingOperators();
     214      UpdateAnalyzers();
    177215      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
    178216      ParameterizeIterationBasedOperators();
    179       UpdateShakingOperator();
    180       UpdateLocalImprovementOperator();
    181       UpdateAnalyzers();
    182217      base.Problem_OperatorsChanged(sender, e);
    183218    }
    184 
    185219    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    186       ParameterizeVNSMainLoop();
     220      ParameterizeMainLoop();
    187221      ParameterizeAnalyzers();
    188222    }
    189 
    190     void LocalImprovementParameter_ValueChanged(object sender, EventArgs e) {
    191       if (LocalImprovementParameter.Value != null)
    192         LocalImprovementParameter.Value.OnProblemChanged(Problem);
     223    private void LocalImprovementParameter_ValueChanged(object sender, EventArgs e) {
     224      ParameterizeLocalImprovementOperators();
    193225    }
    194226    #endregion
     
    203235        ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName;
    204236    }
    205     private void ParameterizeVNSMainLoop() {
    206       VNSMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    207       VNSMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    208       VNSMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     237    private void ParameterizeMainLoop() {
     238      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     239      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     240      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    209241    }
    210242    private void ParameterizeAnalyzers() {
     
    221253        foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) {
    222254          op.IterationsParameter.ActualName = "Iterations";
    223           op.MaximumIterationsParameter.ActualName = "MaximumIterations";
     255          op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name;
    224256        }
    225257      }
    226258    }
    227     private void UpdateShakingOperator() {
    228       Type manipulatorType = typeof(IManipulator);
    229       List<Type> manipulatorInterfaces = new List<Type>();
    230 
    231       foreach (IManipulator mutator in Problem.Operators.OfType<IManipulator>().OrderBy(x => x.Name)) {
    232         Type t = mutator.GetType();
    233         Type[] interfaces = t.GetInterfaces();
    234 
    235         for (int i = 0; i < interfaces.Length; i++) {
    236           if (manipulatorType.IsAssignableFrom(interfaces[i])) {
    237             bool assignable = false;
    238             for (int j = 0; j < interfaces.Length; j++) {
    239               if (i != j && interfaces[i].IsAssignableFrom(interfaces[j])) {
    240                 assignable = true;
    241                 break;
    242               }
    243             }
    244 
    245             if (!assignable)
    246               manipulatorInterfaces.Add(interfaces[i]);
    247           }
     259    private void ParameterizeLocalImprovementOperators() {
     260      foreach (ILocalImprovementOperator op in LocalImprovementParameter.ValidValues) {
     261        if (op != LocalImprovementParameter.Value) op.Problem = null;
     262        op.MaximumIterationsParameter.Value = null;
     263        op.MaximumIterationsParameter.ActualName = LocalImprovementMaximumIterationsParameter.Name;
     264      }
     265      if (LocalImprovementParameter.Value != null)
     266        LocalImprovementParameter.Value.Problem = Problem;
     267    }
     268    private void InitializeLocalImprovementOperators() {
     269      if (Problem == null) {
     270        LocalImprovementParameter.ValidValues.Clear();
     271      } else {
     272        LocalImprovementParameter.ValidValues.RemoveWhere(x => !x.ProblemType.IsAssignableFrom(Problem.GetType()));
     273        foreach (ILocalImprovementOperator op in ApplicationManager.Manager.GetInstances<ILocalImprovementOperator>().Where(x => x.ProblemType.IsAssignableFrom(Problem.GetType()))) {
     274          if (!LocalImprovementParameter.ValidValues.Any(x => x.GetType() == op.GetType()))
     275            LocalImprovementParameter.ValidValues.Add(op);
    248276        }
    249277      }
    250 
    251       foreach (Type manipulatorInterface in manipulatorInterfaces) {
    252         //manipulatorInterface is more specific
    253         if (manipulatorType.IsAssignableFrom(manipulatorInterface)) {
    254           //and compatible to all other found manipulator types
    255           bool compatible = true;
    256           foreach (Type manipulatorInterface2 in manipulatorInterfaces) {
    257             if (!manipulatorInterface.IsAssignableFrom(manipulatorInterface2)) {
    258               compatible = false;
    259               break;
    260             }
    261           }
    262 
    263           if (compatible)
    264             manipulatorType = manipulatorInterface;
    265         }
    266       }
    267 
    268       Type genericType = typeof(ShakingOperator<>).MakeGenericType(manipulatorType);
    269       ShakingParameter.Value = (IShakingOperator)Activator.CreateInstance(genericType, new object[] { });
    270 
    271       ShakingParameter.Value.OnProblemChanged(Problem);
    272     }
    273     private void UpdateLocalImprovementOperator() {
    274       LocalImprovementParameter.Value.OnProblemChanged(Problem);
     278    }
     279    private void UpdateShakingOperators() {
     280      ShakingOperatorParameter.ValidValues.Clear();
     281      foreach (IMultiNeighborhoodShakingOperator op in Problem.Operators.OfType<IMultiNeighborhoodShakingOperator>()) {
     282        ShakingOperatorParameter.ValidValues.Add(op);
     283        op.CurrentNeighborhoodIndexParameter.ActualName = "CurrentNeighborhoodIndex";
     284        op.NeighborhoodCountParameter.ActualName = "NeighborhoodCount";
     285      }
    275286    }
    276287    private void UpdateAnalyzers() {
  • trunk/sources/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearchMainLoop.cs

    r5753 r6042  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using HeuristicLab.Operators;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2822using HeuristicLab.Common;
    2923using HeuristicLab.Core;
     24using HeuristicLab.Data;
     25using HeuristicLab.Operators;
     26using HeuristicLab.Optimization;
     27using HeuristicLab.Optimization.Operators;
    3028using HeuristicLab.Parameters;
    31 using HeuristicLab.Data;
    32 using HeuristicLab.Optimization.Operators;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3330using HeuristicLab.Selection;
    34 using HeuristicLab.Optimization;
    3531
    3632namespace HeuristicLab.Algorithms.VariableNeighborhoodSearch {
     
    4238  public sealed class VariableNeighborhoodSearchMainLoop : AlgorithmOperator {
    4339    #region Parameter properties
    44     public ValueLookupParameter<IRandom> RandomParameter {
    45       get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; }
    46     }
    47     public ValueLookupParameter<BoolValue> MaximizationParameter {
    48       get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    49     }
    50     public LookupParameter<DoubleValue> QualityParameter {
    51       get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; }
    52     }
    53     public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
    54       get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    55     }
    56     public ValueLookupParameter<IOperator> EvaluatorParameter {
    57       get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
    58     }
    59     public ValueLookupParameter<IntValue> MaximumIterationsParameter {
    60       get { return (ValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
    61     }
    62     public ValueLookupParameter<VariableCollection> ResultsParameter {
    63       get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
    64     }
    65     public ValueLookupParameter<IOperator> AnalyzerParameter {
    66       get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
    67     }
    68     public LookupParameter<IntValue> EvaluatedSolutionsParameter {
    69       get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
    70     }
    71     public ValueLookupParameter<ILocalImprovementOperator> LocalImprovementParameter {
    72       get { return (ValueLookupParameter<ILocalImprovementOperator>)Parameters["LocalImprovement"]; }
    73     }
    74     public ValueLookupParameter<IShakingOperator> ShakingParameter {
    75       get { return (ValueLookupParameter<IShakingOperator>)Parameters["Shaking"]; }
     40    public IValueLookupParameter<IRandom> RandomParameter {
     41      get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; }
     42    }
     43    public IValueLookupParameter<BoolValue> MaximizationParameter {
     44      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     45    }
     46    public ILookupParameter<DoubleValue> QualityParameter {
     47      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
     48    }
     49    public IValueLookupParameter<DoubleValue> BestKnownQualityParameter {
     50      get { return (IValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     51    }
     52    public IValueLookupParameter<IOperator> EvaluatorParameter {
     53      get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
     54    }
     55    public ILookupParameter<IntValue> IterationsParameter {
     56      get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; }
     57    }
     58    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
     59      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     60    }
     61    public IValueLookupParameter<VariableCollection> ResultsParameter {
     62      get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; }
     63    }
     64    public IValueLookupParameter<IOperator> AnalyzerParameter {
     65      get { return (IValueLookupParameter<IOperator>)Parameters["Analyzer"]; }
     66    }
     67    public ILookupParameter<IntValue> EvaluatedSolutionsParameter {
     68      get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     69    }
     70    public ILookupParameter<IntValue> CurrentNeighborhoodIndexParameter {
     71      get { return (ILookupParameter<IntValue>)Parameters["CurrentNeighborhoodIndex"]; }
     72    }
     73    public ILookupParameter<IntValue> NeighborhoodCountParameter {
     74      get { return (ILookupParameter<IntValue>)Parameters["NeighborhoodCount"]; }
     75    }
     76    public IValueLookupParameter<ILocalImprovementOperator> LocalImprovementParameter {
     77      get { return (IValueLookupParameter<ILocalImprovementOperator>)Parameters["LocalImprovement"]; }
     78    }
     79    public IValueLookupParameter<IMultiNeighborhoodShakingOperator> ShakingOperatorParameter {
     80      get { return (IValueLookupParameter<IMultiNeighborhoodShakingOperator>)Parameters["ShakingOperator"]; }
    7681    }
    7782    #endregion
     
    8186    public VariableNeighborhoodSearchMainLoop()
    8287      : base() {
    83         Initialize();
     88      Initialize();
    8489    }
    8590    private VariableNeighborhoodSearchMainLoop(VariableNeighborhoodSearchMainLoop original, Cloner cloner)
     
    97102      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
    98103      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
     104      Parameters.Add(new LookupParameter<IntValue>("Iterations", "The iterations to count."));
    99105      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
    100106      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    101 
    102107      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution."));
    103108      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions."));
    104109      Parameters.Add(new ValueLookupParameter<ILocalImprovementOperator>("LocalImprovement", "The local improvement operation."));
    105       Parameters.Add(new ValueLookupParameter<IShakingOperator>("Shaking", "The shaking operation."));
     110      Parameters.Add(new ValueLookupParameter<IMultiNeighborhoodShakingOperator>("ShakingOperator", "The shaking operation."));
     111      Parameters.Add(new LookupParameter<IntValue>("CurrentNeighborhoodIndex", "The index of the current shaking operation that should be applied."));
     112      Parameters.Add(new LookupParameter<IntValue>("NeighborhoodCount", "The number of neighborhood operators used for shaking."));
    106113      #endregion
    107114
     
    126133
    127134      QualityComparator qualityComparator = new QualityComparator();
    128       ConditionalBranch improvesQualityBranch1 = new ConditionalBranch();
    129       ConditionalBranch improvesQualityBranch2 = new ConditionalBranch();
     135      ConditionalBranch improvesQualityBranch = new ConditionalBranch();
    130136
    131137      Assigner bestQualityUpdater = new Assigner();
     
    139145      Placeholder analyzer2 = new Placeholder();
    140146
     147      Comparator indexComparator = new Comparator();
    141148      ConditionalBranch indexTermination = new ConditionalBranch();
    142149
     
    145152      ConditionalBranch iterationsTermination = new ConditionalBranch();
    146153
    147       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0)));
    148       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Index", new IntValue(0)));
    149       variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("Continue", new BoolValue(false)));
    150154      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("IsBetter", new BoolValue(false)));
    151155      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0)));
     
    159163
    160164      resultsCollector1.CopyValue = new BoolValue(false);
    161       resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
    162165      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
    163166      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;
    164167
    165       iteration.Name = "Iteration";
    166 
    167       iterationInit.Name = "Init iteration";
    168       iterationInit.LeftSideParameter.ActualName = "Index";
     168      iteration.Name = "MainLoop Body";
     169
     170      iterationInit.Name = "Init k = 0";
     171      iterationInit.LeftSideParameter.ActualName = CurrentNeighborhoodIndexParameter.Name;
    169172      iterationInit.RightSideParameter.Value = new IntValue(0);
    170173
     
    176179
    177180      shaking.Name = "Shaking operator (placeholder)";
    178       shaking.OperatorParameter.ActualName = ShakingParameter.Name;
     181      shaking.OperatorParameter.ActualName = ShakingOperatorParameter.Name;
    179182
    180183      localImprovement.Name = "Local improvement operator (placeholder)";
     
    192195      qualityComparator.ResultParameter.ActualName = "IsBetter";
    193196
    194       improvesQualityBranch1.ConditionParameter.ActualName = "IsBetter";
    195       improvesQualityBranch2.ConditionParameter.ActualName = "IsBetter";
     197      improvesQualityBranch.ConditionParameter.ActualName = "IsBetter";
    196198
    197199      bestQualityUpdater.Name = "Update BestQuality";
     
    204206      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
    205207
    206       indexCounter.Name = "Count index";
     208      indexCounter.Name = "Count neighborhood index";
    207209      indexCounter.Increment.Value = 1;
    208       indexCounter.ValueParameter.ActualName = "Index";
    209 
    210       indexResetter.Name = "Reset index";
    211       indexResetter.LeftSideParameter.ActualName = "Index";
     210      indexCounter.ValueParameter.ActualName = CurrentNeighborhoodIndexParameter.Name;
     211
     212      indexResetter.Name = "Reset neighborhood index";
     213      indexResetter.LeftSideParameter.ActualName = CurrentNeighborhoodIndexParameter.Name;
    212214      indexResetter.RightSideParameter.Value = new IntValue(0);
    213215
     
    217219      iterationsCounter.Name = "Iterations Counter";
    218220      iterationsCounter.Increment = new IntValue(1);
    219       iterationsCounter.ValueParameter.ActualName = "Iterations";
     221      iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name;
    220222
    221223      iterationsComparator.Name = "Iterations >= MaximumIterations";
    222224      iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
    223       iterationsComparator.LeftSideParameter.ActualName = "Iterations";
     225      iterationsComparator.LeftSideParameter.ActualName = IterationsParameter.Name;
    224226      iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
    225227      iterationsComparator.ResultParameter.ActualName = "Terminate";
     
    228230      iterationsTermination.ConditionParameter.ActualName = "Terminate";
    229231
     232      indexComparator.Name = "k < k_max (index condition)";
     233      indexComparator.LeftSideParameter.ActualName = CurrentNeighborhoodIndexParameter.Name;
     234      indexComparator.RightSideParameter.ActualName = NeighborhoodCountParameter.Name;
     235      indexComparator.Comparison = new Comparison(ComparisonType.Less);
     236      indexComparator.ResultParameter.ActualName = "ContinueIteration";
     237
    230238      indexTermination.Name = "Index Termination Condition";
    231       indexTermination.ConditionParameter.ActualName = "Continue";
     239      indexTermination.ConditionParameter.ActualName = "ContinueIteration";
    232240      #endregion
    233241
     
    255263      evalCounter.Successor = localImprovement;
    256264      localImprovement.Successor = qualityComparator;
    257       qualityComparator.Successor = improvesQualityBranch1;
    258       improvesQualityBranch1.TrueBranch = bestQualityUpdater;
    259       improvesQualityBranch1.FalseBranch = indexCounter;
     265      qualityComparator.Successor = improvesQualityBranch;
     266      improvesQualityBranch.TrueBranch = bestQualityUpdater;
     267      improvesQualityBranch.FalseBranch = indexCounter;
    260268
    261269      bestQualityUpdater.Successor = indexResetter;
     
    266274      bestSelector.Successor = rightReducer;
    267275      rightReducer.Successor = analyzer2;
    268       analyzer2.Successor = indexTermination;
    269       indexTermination.TrueBranch = improvesQualityBranch2;
     276      analyzer2.Successor = indexComparator;
     277      indexComparator.Successor = indexTermination;
     278      indexTermination.TrueBranch = createChild;
    270279      indexTermination.FalseBranch = null;
    271 
    272       improvesQualityBranch2.TrueBranch = null;
    273       improvesQualityBranch2.FalseBranch = createChild;
    274280
    275281      iterationsCounter.Successor = iterationsComparator;
     
    281287
    282288    public override IOperation Apply() {
    283       if (LocalImprovementParameter.ActualValue == null || EvaluatorParameter.ActualValue == null)
     289      if (LocalImprovementParameter.ActualValue == null || ShakingOperatorParameter.ActualValue == null)
    284290        return null;
    285291      return base.Apply();
  • trunk/sources/HeuristicLab.Analysis/3.3/QualityAnalysis/BestAverageWorstQualityAnalyzer.cs

    r5445 r6042  
    6868      get { return (ValueLookupParameter<PercentValue>)Parameters["RelativeDifferenceBestKnownToBest"]; }
    6969    }
    70     public ValueLookupParameter<VariableCollection> ResultsParameter {
    71       get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
     70    public ValueLookupParameter<ResultCollection> ResultsParameter {
     71      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    7272    }
    7373    #endregion
     
    106106      Parameters.Add(new ValueLookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", "The absolute difference of the best known quality value to the best quality value."));
    107107      Parameters.Add(new ValueLookupParameter<PercentValue>("RelativeDifferenceBestKnownToBest", "The relative difference of the best known quality value to the best quality value."));
    108       Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The results collection where the analysis values should be stored."));
     108      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
    109109      #endregion
    110110
     
    166166    private void AfterDeserialization() {
    167167      Initialize();
     168      // BackwardsCompatibility3.3
     169      #region Backwards compatible code, remove with 3.4
     170      if (Parameters["Results"] is ValueLookupParameter<VariableCollection>) {
     171        Parameters.Remove("Results");
     172        Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
     173      }
     174      #endregion
    168175    }
    169    
     176
    170177    private void Initialize() {
    171178      QualityParameter.DepthChanged += new EventHandler(QualityParameter_DepthChanged);
  • trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj

    r5163 r6042  
    1212    <AssemblyName>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    14     <TargetFrameworkProfile></TargetFrameworkProfile>
     14    <TargetFrameworkProfile>
     15    </TargetFrameworkProfile>
    1516    <FileAlignment>512</FileAlignment>
    1617    <SignAssembly>true</SignAssembly>
     
    118119    <Compile Include="HeuristicLabEncodingsBinaryVectorEncodingPlugin.cs" />
    119120    <Compile Include="BinaryVector.cs" />
     121    <Compile Include="Interfaces\IBinaryVectorMultiNeighborhoodShakingOperator.cs" />
    120122    <Compile Include="Interfaces\IOneBitflipMoveOperator.cs" />
    121123    <Compile Include="Interfaces\IBinaryVectorCreator.cs" />
     
    140142    <Compile Include="Moves\OneIndexMove.cs" />
    141143    <Compile Include="Properties\AssemblyInfo.cs" />
     144    <Compile Include="ShakingOperators\BinaryVectorShakingOperator.cs" />
    142145  </ItemGroup>
    143146  <ItemGroup>
     
    200203    </BootstrapperPackage>
    201204  </ItemGroup>
     205  <ItemGroup />
    202206  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    203207  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj

    r5163 r6042  
    1212    <AssemblyName>HeuristicLab.Encodings.IntegerVectorEncoding-3.3</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    14     <TargetFrameworkProfile></TargetFrameworkProfile>
     14    <TargetFrameworkProfile>
     15    </TargetFrameworkProfile>
    1516    <FileAlignment>512</FileAlignment>
    1617    <SignAssembly>true</SignAssembly>
     
    117118    <Compile Include="Interfaces\IIntegerVectorCrossover.cs" />
    118119    <Compile Include="Interfaces\IIntegerVectorManipulator.cs" />
     120    <Compile Include="Interfaces\IIntegerVectorMultiNeighborhoodShakingOperator.cs" />
    119121    <Compile Include="Interfaces\IIntegerVectorOperator.cs" />
    120122    <Compile Include="IntegerVectorCrossover.cs" />
     
    126128    <Compile Include="Properties\AssemblyInfo.cs" />
    127129    <Compile Include="IntegerVectorCreator.cs" />
     130    <Compile Include="ShakingOperators\IntegerVectorShakingOperator.cs" />
    128131  </ItemGroup>
    129132  <ItemGroup>
     
    147150      <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project>
    148151      <Name>HeuristicLab.Operators-3.3</Name>
     152    </ProjectReference>
     153    <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj">
     154      <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project>
     155      <Name>HeuristicLab.Optimization.Operators-3.3</Name>
    149156    </ProjectReference>
    150157    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLabEncodingsIntegerVectorEncodingPlugin.cs.frame

    r5446 r6042  
    3434  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3535  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     36  [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]
    3637  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    3738  [PluginDependency("HeuristicLab.Persistence", "3.3")]
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj

    r5933 r6042  
    1919    </UpgradeBackupLocation>
    2020    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    21     <TargetFrameworkProfile></TargetFrameworkProfile>
     21    <TargetFrameworkProfile>
     22    </TargetFrameworkProfile>
    2223    <PublishUrl>publish\</PublishUrl>
    2324    <Install>true</Install>
     
    118119    <Compile Include="Crossovers\PositionBasedCrossover.cs" />
    119120    <Compile Include="HeuristicLabEncodingsPermutationEncodingPlugin.cs" />
     121    <Compile Include="Interfaces\IPermutationMultiNeighborhoodShakingOperator.cs" />
    120122    <Compile Include="Interfaces\IPermutationSwap2MoveOperator.cs" />
    121123    <Compile Include="Interfaces\IPermutationCreator.cs" />
     
    183185    <Compile Include="PermutationTypes.cs" />
    184186    <Compile Include="Properties\AssemblyInfo.cs" />
     187    <Compile Include="ShakingOperators\PermutationShakingOperator.cs" />
    185188  </ItemGroup>
    186189  <ItemGroup>
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj

    r5560 r6042  
    104104  </ItemGroup>
    105105  <ItemGroup>
     106    <Compile Include="Interfaces\IRealVectorMultiNeighborhoodShakingOperator.cs" />
    106107    <Compile Include="ParticleOperators\RealVectorParticleCreator.cs" />
    107108    <Compile Include="Crossovers\BlendAlphaBetaCrossover.cs" />
     
    168169    <Compile Include="Manipulators\UniformOnePositionManipulator.cs" />
    169170    <Compile Include="ReflectiveBoundsChecker.cs" />
     171    <Compile Include="ShakingOperators\RealVectorShakingOperator.cs" />
    170172    <Compile Include="StrategyParameters\StdDevStrategyVectorCreator.cs" />
    171173    <Compile Include="StrategyParameters\StdDevStrategyVectorCrossover.cs" />
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj

    r5163 r6042  
    1919    </UpgradeBackupLocation>
    2020    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    21     <TargetFrameworkProfile></TargetFrameworkProfile>
     21    <TargetFrameworkProfile>
     22    </TargetFrameworkProfile>
    2223    <PublishUrl>publish\</PublishUrl>
    2324    <Install>true</Install>
     
    109110    <Compile Include="MultiObjective\FastNonDominatedSort.cs" />
    110111    <Compile Include="MultiObjective\RankAndCrowdingSorter.cs" />
     112    <Compile Include="ShakingOperator.cs" />
    111113    <Compile Include="UserDefinedCrossover.cs" />
    112114    <Compile Include="UserDefinedEvaluator.cs" />
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/QualityComparator.cs

    r5445 r6042  
    5151      Parameters.Add(new LookupParameter<DoubleValue>("LeftSide", "The left side of the comparison."));
    5252      Parameters.Add(new ValueLookupParameter<DoubleValue>("RightSide", "The right side of the comparison."));
    53       Parameters.Add(new LookupParameter<BoolValue>("Result", "The result of the comparison."));
     53      Parameters.Add(new LookupParameter<BoolValue>("Result", "The result of the comparison, true if the quality on the LeftSide is better than the quality on the RightSide."));
    5454      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    5555    }
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r5954 r6042  
    120120    <Compile Include="Interfaces\ILocalParticleUpdater.cs" />
    121121    <Compile Include="Algorithms\HeuristicOptimizationAlgorithm.cs" />
     122    <Compile Include="Interfaces\IMultiNeighborhoodShakingOperator.cs" />
     123    <Compile Include="MoveHelper.cs" />
    122124    <Compile Include="Problems\MultiObjectiveHeuristicOptimizationProblem.cs" />
    123125    <Compile Include="Problems\HeuristicOptimizationProblem.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ILocalImprovementOperator.cs

    r5753 r6042  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623using HeuristicLab.Core;
    27 using HeuristicLab.Optimization;
     24using HeuristicLab.Data;
    2825
    2926namespace HeuristicLab.Optimization {
    30   public interface ILocalImprovementOperator: IOperator {
    31     void OnProblemChanged(IProblem problem);
     27  public interface ILocalImprovementOperator : IOperator {
     28    Type ProblemType { get; }
     29    IProblem Problem { get; set; }
     30    IValueLookupParameter<IntValue> MaximumIterationsParameter { get; }
     31    ILookupParameter<IntValue> EvaluatedSolutionsParameter { get; }
     32    ILookupParameter<ResultCollection> ResultsParameter { get; }
    3233  }
    3334}
  • trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj

    r5755 r6042  
    115115    <EmbeddedResource Include="Documents\SGP_SymbClass_Mammographic.hl" />
    116116    <EmbeddedResource Include="Documents\SGP_SymbReg.hl" />
    117     <EmbeddedResource Include="Documents\VNS_TSP.hl" />
    118117    <None Include="HeuristicLabOptimizerPlugin.cs.frame" />
    119118    <Compile Include="CreateExperimentDialog.cs">
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r5809 r6042  
    339339        op.ValuesParameter.ActualName = ValuesParameter.Name;
    340340      }
     341      foreach (var op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>())
     342        op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    341343    }
    342344    #endregion
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs

    r5809 r6042  
    262262        op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    263263      }
     264      foreach (var op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>())
     265        op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName;
    264266    }
    265267    #endregion
  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r5953 r6042  
    287287        }
    288288      }
     289      foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())
     290        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    289291    }
    290292
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r5951 r6042  
    417417        op.MaximizationParameter.ActualName = MaximizationParameter.Name;
    418418      }
     419      foreach (var op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>())
     420        op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    419421    }
    420422    private void UpdateStrategyVectorBounds() {
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r5809 r6042  
    389389      foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>())
    390390        op.TranslocationMoveParameter.ActualName = translocationMove;
     391      foreach (IPermutationMultiNeighborhoodShakingOperator op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())
     392        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    391393    }
    392394
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/HeuristicLab.Problems.VehicleRouting-3.3.csproj

    r5163 r6042  
    1919    </UpgradeBackupLocation>
    2020    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    21     <TargetFrameworkProfile></TargetFrameworkProfile>
     21    <TargetFrameworkProfile>
     22    </TargetFrameworkProfile>
    2223    <PublishUrl>publish\</PublishUrl>
    2324    <Install>true</Install>
     
    111112    <Compile Include="Analyzers\BestVRPToursMemorizer.cs" />
    112113    <Compile Include="Analyzers\BestVRPSolutionAnalyzer.cs" />
     114    <Compile Include="Interfaces\IVRPMultiNeighborhoodShakingOperator.cs" />
     115    <Compile Include="ShakingOperators\VehicleRoutingShakingOperator.cs" />
    113116    <Compile Include="SolutionParser.cs" />
    114117    <Compile Include="Encodings\Alba\Crossovers\AlbaPermutationCrossover.cs" />
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs

    r5809 r6042  
    607607        op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
    608608      }
     609
     610      foreach (var op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) {
     611        op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName;
     612      }
    609613    }
    610614    private void ClearDistanceMatrix() {
Note: See TracChangeset for help on using the changeset viewer.