- Timestamp:
- 04/23/11 00:29:24 (14 years ago)
- Location:
- trunk
- Files:
-
- 19 added
- 2 deleted
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
r5809 r6042 185 185 mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves"; 186 186 mainLoop.IterationsParameter.ActualName = "Iterations"; 187 mainLoop.Best QualityParameter.ActualName = "BestQuality";187 mainLoop.BestLocalQualityParameter.ActualName = "BestQuality"; 188 188 189 189 moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchImprovementOperator.cs
r5809 r6042 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 24 using HeuristicLab.Analysis; … … 29 28 using HeuristicLab.Operators; 30 29 using HeuristicLab.Optimization; 31 using HeuristicLab.Optimization.Operators;32 30 using HeuristicLab.Parameters; 33 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 39 37 [Item("LocalSearchImprovementOperator", "A local search improvement operator.")] 40 38 [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; 42 59 [Storable] 43 60 private LocalSearchMainLoop loop; 44 45 61 [Storable] 46 62 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 47 63 48 private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter { 64 #region Parameter Properties 65 public ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter { 49 66 get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; } 50 67 } 51 p rivateConstrainedValueParameter<IMoveMaker> MoveMakerParameter {68 public ConstrainedValueParameter<IMoveMaker> MoveMakerParameter { 52 69 get { return (ConstrainedValueParameter<IMoveMaker>)Parameters["MoveMaker"]; } 53 70 } 54 p rivateConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter {71 public ConstrainedValueParameter<ISingleObjectiveMoveEvaluator> MoveEvaluatorParameter { 55 72 get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; } 56 73 } 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"]; } 65 76 } 66 77 public ValueParameter<MultiAnalyzer> AnalyzerParameter { 67 78 get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 68 79 } 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 70 100 public IMoveGenerator MoveGenerator { 71 101 get { return MoveGeneratorParameter.Value; } … … 84 114 set { AnalyzerParameter.Value = value; } 85 115 } 116 #endregion 86 117 87 118 [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) 94 121 : base(original, cloner) { 95 122 this.loop = cloner.Clone(original.loop); 96 123 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(); 101 126 } 102 127 public LocalSearchImprovementOperator() 103 128 : 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 111 129 Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution.")); 112 130 Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move.")); 113 131 Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move.")); 114 Parameters.Add(new Value Parameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(150)));115 Parameters.Add(new Value Parameter<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))); 116 134 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated moves.")); 117 135 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() { 123 160 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) { 128 178 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; 140 226 if (problem != null) { 141 227 qualityAnalyzer.MaximizationParameter.ActualName = problem.MaximizationParameter.Name; … … 146 232 } 147 233 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() { 166 235 IMoveGenerator oldMoveGenerator = MoveGenerator; 167 236 IMoveMaker oldMoveMaker = MoveMaker; … … 171 240 172 241 if (problem != null) { 173 foreach (IM oveGenerator generator in problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name))242 foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name)) 174 243 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 224 269 if (oldMoveMaker != null) { 225 IMoveMaker mm = validMoveMakers.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());270 IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType()); 226 271 if (mm != null) MoveMaker = mm; 227 else MoveMaker = validMoveMakers.FirstOrDefault(); 228 } 229 272 } 230 273 if (oldMoveEvaluator != null) { 231 ISingleObjectiveMoveEvaluator me = validMoveEvaluators.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());274 ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType()); 232 275 if (me != null) MoveEvaluator = me; 233 else MoveEvaluator = validMoveEvaluators.FirstOrDefault();234 276 } 235 277 } … … 242 284 } 243 285 244 private void ParameterizeMoveGenerators( ISingleObjectiveHeuristicOptimizationProblem problem) {286 private void ParameterizeMoveGenerators() { 245 287 if (problem != null) { 246 288 foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>()) … … 248 290 } 249 291 } 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 262 293 263 294 public override IOperation Apply() { 264 Scope subScope = new Scope(); 295 IScope currentScope = ExecutionContext.Scope; 296 297 Scope localScope = new Scope(); 265 298 Scope individual = new Scope(); 266 299 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; 274 306 275 307 SubScopesProcessor processor = new SubScopesProcessor(); … … 279 311 remover.SubScopeIndexParameter.Value = new IntValue(index); 280 312 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 } 283 318 } 284 319 285 320 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))); 288 323 289 324 variableCreator.Successor = loop; 290 291 loop.EvaluatedMovesParameter.ActualName = EvaluatedSolutionsParameter.ActualName;292 325 293 326 processor.Operators.Add(variableCreator); 294 327 processor.Successor = remover; 295 328 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; 302 333 } 303 334 } -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs
r5753 r6042 46 46 get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; } 47 47 } 48 public LookupParameter<DoubleValue> Best QualityParameter {48 public LookupParameter<DoubleValue> BestLocalQualityParameter { 49 49 get { return (LookupParameter<DoubleValue>)Parameters["BestLocalQuality"]; } 50 50 } … … 56 56 } 57 57 public LookupParameter<IntValue> IterationsParameter { 58 get { return (LookupParameter<IntValue>)Parameters[" LocalIterations"]; }58 get { return (LookupParameter<IntValue>)Parameters["Iterations"]; } 59 59 } 60 60 public ValueLookupParameter<IntValue> MaximumIterationsParameter { … … 85 85 public LocalSearchMainLoop() 86 86 : base() { 87 87 Initialize(); 88 88 } 89 89 private LocalSearchMainLoop(LocalSearchMainLoop original, Cloner cloner) … … 100 100 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 101 101 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.")); 103 103 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.")); 105 105 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); 106 106 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); … … 140 140 141 141 bestQualityInitializer.Name = "Initialize BestQuality"; 142 bestQualityInitializer.LeftSideParameter.ActualName = Best QualityParameter.Name;142 bestQualityInitializer.LeftSideParameter.ActualName = BestLocalQualityParameter.Name; 143 143 bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name; 144 144 … … 148 148 resultsCollector1.CopyValue = new BoolValue(false); 149 149 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name)); 150 resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(Best QualityParameter.Name, null, BestQualityParameter.Name));150 resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name)); 151 151 resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; 152 152 … … 177 177 178 178 bestQualityUpdater.Name = "Update BestQuality"; 179 bestQualityUpdater.LeftSideParameter.ActualName = Best QualityParameter.Name;179 bestQualityUpdater.LeftSideParameter.ActualName = BestLocalQualityParameter.Name; 180 180 bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name; 181 181 182 182 resultsCollector2.CopyValue = new BoolValue(false); 183 resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(Best QualityParameter.Name, null, BestQualityParameter.Name));183 resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(BestLocalQualityParameter.Name, null, BestLocalQualityParameter.Name)); 184 184 resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name; 185 185 -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingImprovementOperator.cs
r5809 r6042 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using System.Linq; 25 using System.Text; 24 using HeuristicLab.Analysis; 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 28 using HeuristicLab.Operators; 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 27 31 using 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;36 32 using HeuristicLab.PluginInfrastructure; 37 33 … … 42 38 [Item("SimulatedAnnealingImprovementOperator", "A simulated annealing improvement operator.")] 43 39 [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; 45 60 [Storable] 46 61 private SimulatedAnnealingMainLoop loop; 47 48 62 [Storable] 49 63 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 50 64 65 #region Parameter Properties 66 public ILookupParameter<IRandom> RandomParameter { 67 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 68 } 51 69 private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter { 52 70 get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; } … … 58 76 get { return (ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>)Parameters["MoveEvaluator"]; } 59 77 } 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"]; } 68 80 } 69 81 public ValueParameter<MultiAnalyzer> AnalyzerParameter { … … 79 91 get { return (ConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["AnnealingOperator"]; } 80 92 } 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 82 110 public IMoveGenerator MoveGenerator { 83 111 get { return MoveGeneratorParameter.Value; } … … 96 124 set { AnalyzerParameter.Value = value; } 97 125 } 126 #endregion 98 127 99 128 [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 101 170 [StorableHook(HookType.AfterDeserialization)] 102 171 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() { 140 177 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 142 207 143 208 private void ParameterizeAnnealingOperators() { … … 152 217 } 153 218 154 public void OnProblemChanged(IProblem problem) {155 UpdateMoveOperators( problem);219 public void UpdateProblem() { 220 UpdateMoveOperators(); 156 221 ChooseMoveOperators(); 157 222 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() { 167 231 qualityAnalyzer.ResultsParameter.ActualName = "Results"; 168 232 if (problem != null) { … … 174 238 } 175 239 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() { 177 262 Analyzer.Operators.Clear(); 178 263 if (problem != null) { … … 187 272 } 188 273 189 void MoveGeneratorParameter_ValueChanged(object sender, EventArgs e) { 190 ChooseMoveOperators(); 191 } 192 193 private void UpdateMoveOperators(IProblem problem) { 274 private void UpdateMoveOperators() { 194 275 IMoveGenerator oldMoveGenerator = MoveGenerator; 195 276 IMoveMaker oldMoveMaker = MoveMaker; … … 199 280 200 281 if (problem != null) { 201 foreach (IM oveGenerator generator in problem.Operators.OfType<IMoveGenerator>().OrderBy(x => x.Name))282 foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>().OrderBy(x => x.Name)) 202 283 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(); 233 301 234 302 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 252 309 if (oldMoveMaker != null) { 253 IMoveMaker mm = validMoveMakers.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());310 IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType()); 254 311 if (mm != null) MoveMaker = mm; 255 else MoveMaker = validMoveMakers.FirstOrDefault(); 256 } 257 312 } 258 313 if (oldMoveEvaluator != null) { 259 ISingleObjectiveMoveEvaluator me = validMoveEvaluators.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());314 ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType()); 260 315 if (me != null) MoveEvaluator = me; 261 else MoveEvaluator = validMoveEvaluators.FirstOrDefault(); 262 } 316 } 263 317 } 264 318 } … … 270 324 } 271 325 272 private void ParameterizeMoveGenerators( ISingleObjectiveHeuristicOptimizationProblem problem) {326 private void ParameterizeMoveGenerators() { 273 327 if (problem != null) { 274 328 foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>()) … … 276 330 } 277 331 } 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 }290 332 291 333 public override IOperation Apply() { 292 Scope subScope = new Scope(); 334 IScope currentScope = ExecutionContext.Scope; 335 336 Scope localScope = new Scope(); 293 337 Scope individual = new Scope(); 294 338 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; 302 345 303 346 SubScopesProcessor processor = new SubScopesProcessor(); … … 307 350 remover.SubScopeIndexParameter.Value = new IntValue(index); 308 351 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 } 311 357 } 312 358 313 359 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))); 315 361 316 362 variableCreator.Successor = loop; 317 318 loop.EvaluatedMovesParameter.ActualName = EvaluatedSolutionsParameter.ActualName;319 363 320 364 processor.Operators.Add(variableCreator); 321 365 processor.Successor = remover; 322 366 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; 329 371 } 330 372 } -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs
r5753 r6042 61 61 } 62 62 public LookupParameter<IntValue> IterationsParameter { 63 get { return (LookupParameter<IntValue>)Parameters[" LocalIterations"]; }63 get { return (LookupParameter<IntValue>)Parameters["Iterations"]; } 64 64 } 65 65 public ValueLookupParameter<IntValue> MaximumIterationsParameter { … … 112 112 Parameters.Add(new ValueLookupParameter<DoubleValue>("EndTemperature", "The end temperature.")); 113 113 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.")); 115 115 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations which should be processed.")); 116 116 … … 231 231 } 232 232 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 233 242 public override IOperation Apply() { 234 243 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 108 108 <ItemGroup> 109 109 <Compile Include="HeuristicLabAlgorithmsVariableNeighborhoodSearchPlugin.cs" /> 110 <Compile Include="IShakingOperator.cs" />111 110 <Compile Include="Properties\AssemblyInfo.cs" /> 112 <Compile Include="ShakingOperator.cs" />113 111 <Compile Include="VariableNeighborhoodSearch.cs" /> 114 112 <Compile Include="VariableNeighborhoodSearchMainLoop.cs" /> … … 120 118 </ItemGroup> 121 119 <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>126 120 <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj"> 127 121 <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project> -
trunk/sources/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/HeuristicLabAlgorithmsVariableNeighborhoodSearchPlugin.cs.frame
r5830 r6042 28 28 [Plugin("HeuristicLab.Algorithms.VariableNeighborhoodSearch", "3.3.3.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Algorithms.VariableNeighborhoodSearch-3.3.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.Algorithms.LocalSearch", "3.3")]31 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] 32 31 [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 22 using System; 3 23 using System.Linq; 4 using HeuristicLab.Algorithms.LocalSearch;5 24 using HeuristicLab.Analysis; 6 25 using HeuristicLab.Common; … … 12 31 using HeuristicLab.Parameters; 13 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 using HeuristicLab.PluginInfrastructure; 14 34 using HeuristicLab.Random; 15 35 … … 32 52 33 53 #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"]; } 48 68 } 49 69 private ValueParameter<MultiAnalyzer> AnalyzerParameter { 50 70 get { return (ValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 51 71 } 52 p rivate VariableNeighborhoodSearchMainLoop VNSMainLoop{53 get { return FindMainLoop(SolutionsCreator.Successor); }72 public FixedValueParameter<IntValue> LocalImprovementMaximumIterationsParameter { 73 get { return (FixedValueParameter<IntValue>)Parameters["LocalImprovementMaximumIterations"]; } 54 74 } 55 75 #endregion … … 66 86 get { return (SolutionsCreator)RandomCreator.Successor; } 67 87 } 88 private VariableNeighborhoodSearchMainLoop MainLoop { 89 get { return FindMainLoop(SolutionsCreator.Successor); } 90 } 68 91 #endregion 69 92 … … 73 96 [StorableConstructor] 74 97 private VariableNeighborhoodSearch(bool deserializing) : base(deserializing) { } 75 [StorableHook(HookType.AfterDeserialization)]76 private void AfterDeserialization() {77 78 }79 98 private VariableNeighborhoodSearch(VariableNeighborhoodSearch original, Cloner cloner) 80 99 : base(original, cloner) { 81 100 qualityAnalyzer = cloner.Clone(original.qualityAnalyzer); 82 Initialize(); 83 } 84 public override IDeepCloneable Clone(Cloner cloner) { 85 return new VariableNeighborhoodSearch(this, cloner); 101 RegisterEventHandlers(); 86 102 } 87 103 public VariableNeighborhoodSearch() 88 104 : 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))); 94 111 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution and moves.", new MultiAnalyzer())); 95 112 … … 112 129 113 130 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))); 115 136 variableCreator.Successor = resultsCollector; 116 137 117 138 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); 139 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 118 140 resultsCollector.ResultsParameter.ActualName = "Results"; 119 141 resultsCollector.Successor = mainLoop; 120 142 143 mainLoop.IterationsParameter.ActualName = "Iterations"; 144 mainLoop.CurrentNeighborhoodIndexParameter.ActualName = "CurrentNeighborhoodIndex"; 145 mainLoop.NeighborhoodCountParameter.ActualName = "NeighborhoodCount"; 121 146 mainLoop.LocalImprovementParameter.ActualName = LocalImprovementParameter.Name; 122 mainLoop.Shaking Parameter.ActualName = ShakingParameter.Name;147 mainLoop.ShakingOperatorParameter.ActualName = ShakingOperatorParameter.Name; 123 148 mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 124 149 mainLoop.RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; … … 127 152 mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; 128 153 154 InitializeLocalImprovementOperators(); 129 155 qualityAnalyzer = new BestAverageWorstQualityAnalyzer(); 130 156 ParameterizeAnalyzers(); 131 157 UpdateAnalyzers(); 132 158 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(); 134 169 } 135 170 … … 138 173 } 139 174 140 private void Initialize() { 175 private void RegisterEventHandlers() { 176 LocalImprovementParameter.ValueChanged += new EventHandler(LocalImprovementParameter_ValueChanged); 141 177 if (Problem != null) { 142 178 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 143 179 } 144 LocalImprovementParameter.ValueChanged += new EventHandler(LocalImprovementParameter_ValueChanged);145 180 } 146 181 147 182 #region Events 148 183 protected override void OnProblemChanged() { 184 InitializeLocalImprovementOperators(); 185 UpdateShakingOperators(); 186 UpdateAnalyzers(); 187 149 188 ParameterizeStochasticOperator(Problem.SolutionCreator); 150 189 ParameterizeStochasticOperator(Problem.Evaluator); 151 190 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 152 191 ParameterizeSolutionsCreator(); 153 Parameterize VNSMainLoop();192 ParameterizeMainLoop(); 154 193 ParameterizeAnalyzers(); 155 194 ParameterizeIterationBasedOperators(); 156 UpdateShakingOperator(); 157 UpdateLocalImprovementOperator(); 158 UpdateAnalyzers(); 195 ParameterizeLocalImprovementOperators(); 159 196 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 160 197 base.OnProblemChanged(); 161 198 } 162 163 199 protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { 164 200 ParameterizeStochasticOperator(Problem.SolutionCreator); … … 169 205 ParameterizeStochasticOperator(Problem.Evaluator); 170 206 ParameterizeSolutionsCreator(); 171 Parameterize VNSMainLoop();207 ParameterizeMainLoop(); 172 208 ParameterizeAnalyzers(); 173 209 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 175 211 } 176 212 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 213 UpdateShakingOperators(); 214 UpdateAnalyzers(); 177 215 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 178 216 ParameterizeIterationBasedOperators(); 179 UpdateShakingOperator();180 UpdateLocalImprovementOperator();181 UpdateAnalyzers();182 217 base.Problem_OperatorsChanged(sender, e); 183 218 } 184 185 219 private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) { 186 Parameterize VNSMainLoop();220 ParameterizeMainLoop(); 187 221 ParameterizeAnalyzers(); 188 222 } 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(); 193 225 } 194 226 #endregion … … 203 235 ((IStochasticOperator)op).RandomParameter.ActualName = RandomCreator.RandomParameter.ActualName; 204 236 } 205 private void Parameterize VNSMainLoop() {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; 209 241 } 210 242 private void ParameterizeAnalyzers() { … … 221 253 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 222 254 op.IterationsParameter.ActualName = "Iterations"; 223 op.MaximumIterationsParameter.ActualName = "MaximumIterations";255 op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 224 256 } 225 257 } 226 258 } 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); 248 276 } 249 277 } 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 } 275 286 } 276 287 private void UpdateAnalyzers() { -
trunk/sources/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearchMainLoop.cs
r5753 r6042 20 20 #endregion 21 21 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;28 22 using HeuristicLab.Common; 29 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 25 using HeuristicLab.Operators; 26 using HeuristicLab.Optimization; 27 using HeuristicLab.Optimization.Operators; 30 28 using HeuristicLab.Parameters; 31 using HeuristicLab.Data; 32 using HeuristicLab.Optimization.Operators; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 33 30 using HeuristicLab.Selection; 34 using HeuristicLab.Optimization;35 31 36 32 namespace HeuristicLab.Algorithms.VariableNeighborhoodSearch { … … 42 38 public sealed class VariableNeighborhoodSearchMainLoop : AlgorithmOperator { 43 39 #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"]; } 76 81 } 77 82 #endregion … … 81 86 public VariableNeighborhoodSearchMainLoop() 82 87 : base() { 83 88 Initialize(); 84 89 } 85 90 private VariableNeighborhoodSearchMainLoop(VariableNeighborhoodSearchMainLoop original, Cloner cloner) … … 97 102 Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); 98 103 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.")); 99 105 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); 100 106 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 101 102 107 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution.")); 103 108 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions.")); 104 109 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.")); 106 113 #endregion 107 114 … … 126 133 127 134 QualityComparator qualityComparator = new QualityComparator(); 128 ConditionalBranch improvesQualityBranch1 = new ConditionalBranch(); 129 ConditionalBranch improvesQualityBranch2 = new ConditionalBranch(); 135 ConditionalBranch improvesQualityBranch = new ConditionalBranch(); 130 136 131 137 Assigner bestQualityUpdater = new Assigner(); … … 139 145 Placeholder analyzer2 = new Placeholder(); 140 146 147 Comparator indexComparator = new Comparator(); 141 148 ConditionalBranch indexTermination = new ConditionalBranch(); 142 149 … … 145 152 ConditionalBranch iterationsTermination = new ConditionalBranch(); 146 153 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)));150 154 variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("IsBetter", new BoolValue(false))); 151 155 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0))); … … 159 163 160 164 resultsCollector1.CopyValue = new BoolValue(false); 161 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));162 165 resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality")); 163 166 resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; 164 167 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; 169 172 iterationInit.RightSideParameter.Value = new IntValue(0); 170 173 … … 176 179 177 180 shaking.Name = "Shaking operator (placeholder)"; 178 shaking.OperatorParameter.ActualName = Shaking Parameter.Name;181 shaking.OperatorParameter.ActualName = ShakingOperatorParameter.Name; 179 182 180 183 localImprovement.Name = "Local improvement operator (placeholder)"; … … 192 195 qualityComparator.ResultParameter.ActualName = "IsBetter"; 193 196 194 improvesQualityBranch1.ConditionParameter.ActualName = "IsBetter"; 195 improvesQualityBranch2.ConditionParameter.ActualName = "IsBetter"; 197 improvesQualityBranch.ConditionParameter.ActualName = "IsBetter"; 196 198 197 199 bestQualityUpdater.Name = "Update BestQuality"; … … 204 206 bestSelector.QualityParameter.ActualName = QualityParameter.Name; 205 207 206 indexCounter.Name = "Count index";208 indexCounter.Name = "Count neighborhood index"; 207 209 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; 212 214 indexResetter.RightSideParameter.Value = new IntValue(0); 213 215 … … 217 219 iterationsCounter.Name = "Iterations Counter"; 218 220 iterationsCounter.Increment = new IntValue(1); 219 iterationsCounter.ValueParameter.ActualName = "Iterations";221 iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name; 220 222 221 223 iterationsComparator.Name = "Iterations >= MaximumIterations"; 222 224 iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); 223 iterationsComparator.LeftSideParameter.ActualName = "Iterations";225 iterationsComparator.LeftSideParameter.ActualName = IterationsParameter.Name; 224 226 iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name; 225 227 iterationsComparator.ResultParameter.ActualName = "Terminate"; … … 228 230 iterationsTermination.ConditionParameter.ActualName = "Terminate"; 229 231 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 230 238 indexTermination.Name = "Index Termination Condition"; 231 indexTermination.ConditionParameter.ActualName = "Continue ";239 indexTermination.ConditionParameter.ActualName = "ContinueIteration"; 232 240 #endregion 233 241 … … 255 263 evalCounter.Successor = localImprovement; 256 264 localImprovement.Successor = qualityComparator; 257 qualityComparator.Successor = improvesQualityBranch 1;258 improvesQualityBranch 1.TrueBranch = bestQualityUpdater;259 improvesQualityBranch 1.FalseBranch = indexCounter;265 qualityComparator.Successor = improvesQualityBranch; 266 improvesQualityBranch.TrueBranch = bestQualityUpdater; 267 improvesQualityBranch.FalseBranch = indexCounter; 260 268 261 269 bestQualityUpdater.Successor = indexResetter; … … 266 274 bestSelector.Successor = rightReducer; 267 275 rightReducer.Successor = analyzer2; 268 analyzer2.Successor = indexTermination; 269 indexTermination.TrueBranch = improvesQualityBranch2; 276 analyzer2.Successor = indexComparator; 277 indexComparator.Successor = indexTermination; 278 indexTermination.TrueBranch = createChild; 270 279 indexTermination.FalseBranch = null; 271 272 improvesQualityBranch2.TrueBranch = null;273 improvesQualityBranch2.FalseBranch = createChild;274 280 275 281 iterationsCounter.Successor = iterationsComparator; … … 281 287 282 288 public override IOperation Apply() { 283 if (LocalImprovementParameter.ActualValue == null || EvaluatorParameter.ActualValue == null)289 if (LocalImprovementParameter.ActualValue == null || ShakingOperatorParameter.ActualValue == null) 284 290 return null; 285 291 return base.Apply(); -
trunk/sources/HeuristicLab.Analysis/3.3/QualityAnalysis/BestAverageWorstQualityAnalyzer.cs
r5445 r6042 68 68 get { return (ValueLookupParameter<PercentValue>)Parameters["RelativeDifferenceBestKnownToBest"]; } 69 69 } 70 public ValueLookupParameter< VariableCollection> ResultsParameter {71 get { return (ValueLookupParameter< VariableCollection>)Parameters["Results"]; }70 public ValueLookupParameter<ResultCollection> ResultsParameter { 71 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } 72 72 } 73 73 #endregion … … 106 106 Parameters.Add(new ValueLookupParameter<DoubleValue>("AbsoluteDifferenceBestKnownToBest", "The absolute difference of the best known quality value to the best quality value.")); 107 107 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.")); 109 109 #endregion 110 110 … … 166 166 private void AfterDeserialization() { 167 167 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 168 175 } 169 176 170 177 private void Initialize() { 171 178 QualityParameter.DepthChanged += new EventHandler(QualityParameter_DepthChanged); -
trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj
r5163 r6042 12 12 <AssemblyName>HeuristicLab.Encodings.BinaryVectorEncoding-3.3</AssemblyName> 13 13 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 14 <TargetFrameworkProfile></TargetFrameworkProfile> 14 <TargetFrameworkProfile> 15 </TargetFrameworkProfile> 15 16 <FileAlignment>512</FileAlignment> 16 17 <SignAssembly>true</SignAssembly> … … 118 119 <Compile Include="HeuristicLabEncodingsBinaryVectorEncodingPlugin.cs" /> 119 120 <Compile Include="BinaryVector.cs" /> 121 <Compile Include="Interfaces\IBinaryVectorMultiNeighborhoodShakingOperator.cs" /> 120 122 <Compile Include="Interfaces\IOneBitflipMoveOperator.cs" /> 121 123 <Compile Include="Interfaces\IBinaryVectorCreator.cs" /> … … 140 142 <Compile Include="Moves\OneIndexMove.cs" /> 141 143 <Compile Include="Properties\AssemblyInfo.cs" /> 144 <Compile Include="ShakingOperators\BinaryVectorShakingOperator.cs" /> 142 145 </ItemGroup> 143 146 <ItemGroup> … … 200 203 </BootstrapperPackage> 201 204 </ItemGroup> 205 <ItemGroup /> 202 206 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 203 207 <!-- 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 12 12 <AssemblyName>HeuristicLab.Encodings.IntegerVectorEncoding-3.3</AssemblyName> 13 13 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 14 <TargetFrameworkProfile></TargetFrameworkProfile> 14 <TargetFrameworkProfile> 15 </TargetFrameworkProfile> 15 16 <FileAlignment>512</FileAlignment> 16 17 <SignAssembly>true</SignAssembly> … … 117 118 <Compile Include="Interfaces\IIntegerVectorCrossover.cs" /> 118 119 <Compile Include="Interfaces\IIntegerVectorManipulator.cs" /> 120 <Compile Include="Interfaces\IIntegerVectorMultiNeighborhoodShakingOperator.cs" /> 119 121 <Compile Include="Interfaces\IIntegerVectorOperator.cs" /> 120 122 <Compile Include="IntegerVectorCrossover.cs" /> … … 126 128 <Compile Include="Properties\AssemblyInfo.cs" /> 127 129 <Compile Include="IntegerVectorCreator.cs" /> 130 <Compile Include="ShakingOperators\IntegerVectorShakingOperator.cs" /> 128 131 </ItemGroup> 129 132 <ItemGroup> … … 147 150 <Project>{23DA7FF4-D5B8-41B6-AA96-F0561D24F3EE}</Project> 148 151 <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> 149 156 </ProjectReference> 150 157 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> -
trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/HeuristicLabEncodingsIntegerVectorEncodingPlugin.cs.frame
r5446 r6042 34 34 [PluginDependency("HeuristicLab.Operators", "3.3")] 35 35 [PluginDependency("HeuristicLab.Optimization", "3.3")] 36 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 36 37 [PluginDependency("HeuristicLab.Parameters", "3.3")] 37 38 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/HeuristicLab.Encodings.PermutationEncoding-3.3.csproj
r5933 r6042 19 19 </UpgradeBackupLocation> 20 20 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 21 <TargetFrameworkProfile></TargetFrameworkProfile> 21 <TargetFrameworkProfile> 22 </TargetFrameworkProfile> 22 23 <PublishUrl>publish\</PublishUrl> 23 24 <Install>true</Install> … … 118 119 <Compile Include="Crossovers\PositionBasedCrossover.cs" /> 119 120 <Compile Include="HeuristicLabEncodingsPermutationEncodingPlugin.cs" /> 121 <Compile Include="Interfaces\IPermutationMultiNeighborhoodShakingOperator.cs" /> 120 122 <Compile Include="Interfaces\IPermutationSwap2MoveOperator.cs" /> 121 123 <Compile Include="Interfaces\IPermutationCreator.cs" /> … … 183 185 <Compile Include="PermutationTypes.cs" /> 184 186 <Compile Include="Properties\AssemblyInfo.cs" /> 187 <Compile Include="ShakingOperators\PermutationShakingOperator.cs" /> 185 188 </ItemGroup> 186 189 <ItemGroup> -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj
r5560 r6042 104 104 </ItemGroup> 105 105 <ItemGroup> 106 <Compile Include="Interfaces\IRealVectorMultiNeighborhoodShakingOperator.cs" /> 106 107 <Compile Include="ParticleOperators\RealVectorParticleCreator.cs" /> 107 108 <Compile Include="Crossovers\BlendAlphaBetaCrossover.cs" /> … … 168 169 <Compile Include="Manipulators\UniformOnePositionManipulator.cs" /> 169 170 <Compile Include="ReflectiveBoundsChecker.cs" /> 171 <Compile Include="ShakingOperators\RealVectorShakingOperator.cs" /> 170 172 <Compile Include="StrategyParameters\StdDevStrategyVectorCreator.cs" /> 171 173 <Compile Include="StrategyParameters\StdDevStrategyVectorCrossover.cs" /> -
trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj
r5163 r6042 19 19 </UpgradeBackupLocation> 20 20 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 21 <TargetFrameworkProfile></TargetFrameworkProfile> 21 <TargetFrameworkProfile> 22 </TargetFrameworkProfile> 22 23 <PublishUrl>publish\</PublishUrl> 23 24 <Install>true</Install> … … 109 110 <Compile Include="MultiObjective\FastNonDominatedSort.cs" /> 110 111 <Compile Include="MultiObjective\RankAndCrowdingSorter.cs" /> 112 <Compile Include="ShakingOperator.cs" /> 111 113 <Compile Include="UserDefinedCrossover.cs" /> 112 114 <Compile Include="UserDefinedEvaluator.cs" /> -
trunk/sources/HeuristicLab.Optimization.Operators/3.3/QualityComparator.cs
r5445 r6042 51 51 Parameters.Add(new LookupParameter<DoubleValue>("LeftSide", "The left side of the comparison.")); 52 52 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.")); 54 54 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 55 55 } -
trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r5954 r6042 120 120 <Compile Include="Interfaces\ILocalParticleUpdater.cs" /> 121 121 <Compile Include="Algorithms\HeuristicOptimizationAlgorithm.cs" /> 122 <Compile Include="Interfaces\IMultiNeighborhoodShakingOperator.cs" /> 123 <Compile Include="MoveHelper.cs" /> 122 124 <Compile Include="Problems\MultiObjectiveHeuristicOptimizationProblem.cs" /> 123 125 <Compile Include="Problems\HeuristicOptimizationProblem.cs" /> -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ILocalImprovementOperator.cs
r5753 r6042 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 23 using HeuristicLab.Core; 27 using HeuristicLab. Optimization;24 using HeuristicLab.Data; 28 25 29 26 namespace 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; } 32 33 } 33 34 } -
trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
r5755 r6042 115 115 <EmbeddedResource Include="Documents\SGP_SymbClass_Mammographic.hl" /> 116 116 <EmbeddedResource Include="Documents\SGP_SymbReg.hl" /> 117 <EmbeddedResource Include="Documents\VNS_TSP.hl" />118 117 <None Include="HeuristicLabOptimizerPlugin.cs.frame" /> 119 118 <Compile Include="CreateExperimentDialog.cs"> -
trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs
r5809 r6042 339 339 op.ValuesParameter.ActualName = ValuesParameter.Name; 340 340 } 341 foreach (var op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) 342 op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 341 343 } 342 344 #endregion -
trunk/sources/HeuristicLab.Problems.OneMax/3.3/OnemaxProblem.cs
r5809 r6042 262 262 op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 263 263 } 264 foreach (var op in Operators.OfType<IBinaryVectorMultiNeighborhoodShakingOperator>()) 265 op.BinaryVectorParameter.ActualName = SolutionCreator.BinaryVectorParameter.ActualName; 264 266 } 265 267 #endregion -
trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs
r5953 r6042 287 287 } 288 288 } 289 foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()) 290 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 289 291 } 290 292 -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r5951 r6042 417 417 op.MaximizationParameter.ActualName = MaximizationParameter.Name; 418 418 } 419 foreach (var op in Operators.OfType<IRealVectorMultiNeighborhoodShakingOperator>()) 420 op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 419 421 } 420 422 private void UpdateStrategyVectorBounds() { -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r5809 r6042 389 389 foreach (IPermutationTranslocationMoveOperator op in Operators.OfType<IPermutationTranslocationMoveOperator>()) 390 390 op.TranslocationMoveParameter.ActualName = translocationMove; 391 foreach (IPermutationMultiNeighborhoodShakingOperator op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>()) 392 op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 391 393 } 392 394 -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/HeuristicLab.Problems.VehicleRouting-3.3.csproj
r5163 r6042 19 19 </UpgradeBackupLocation> 20 20 <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 21 <TargetFrameworkProfile></TargetFrameworkProfile> 21 <TargetFrameworkProfile> 22 </TargetFrameworkProfile> 22 23 <PublishUrl>publish\</PublishUrl> 23 24 <Install>true</Install> … … 111 112 <Compile Include="Analyzers\BestVRPToursMemorizer.cs" /> 112 113 <Compile Include="Analyzers\BestVRPSolutionAnalyzer.cs" /> 114 <Compile Include="Interfaces\IVRPMultiNeighborhoodShakingOperator.cs" /> 115 <Compile Include="ShakingOperators\VehicleRoutingShakingOperator.cs" /> 113 116 <Compile Include="SolutionParser.cs" /> 114 117 <Compile Include="Encodings\Alba\Crossovers\AlbaPermutationCrossover.cs" /> -
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/VehicleRoutingProblem.cs
r5809 r6042 607 607 op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName; 608 608 } 609 610 foreach (var op in Operators.OfType<IVRPMultiNeighborhoodShakingOperator>()) { 611 op.VRPToursParameter.ActualName = SolutionCreator.VRPToursParameter.ActualName; 612 } 609 613 } 610 614 private void ClearDistanceMatrix() {
Note: See TracChangeset
for help on using the changeset viewer.