- Timestamp:
- 04/23/11 10:00:31 (14 years ago)
- Location:
- branches/histogram
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/histogram
- Property svn:ignore
-
old new 10 10 protoc.exe 11 11 HeuristicLab 3.3.5.1.ReSharper.user 12 *.psess 13 *.vsp
-
- Property svn:mergeinfo changed
/trunk/sources merged: 6026,6029-6031,6035-6037,6042-6045
- Property svn:ignore
-
branches/histogram/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/HeuristicLab.Algorithms.VariableNeighborhoodSearch-3.3.csproj
r5753 r6046 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> -
branches/histogram/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/HeuristicLabAlgorithmsVariableNeighborhoodSearchPlugin.cs.frame
r5830 r6046 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")] -
branches/histogram/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearch.cs
r5809 r6046 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() { -
branches/histogram/HeuristicLab.Algorithms.VariableNeighborhoodSearch/3.3/VariableNeighborhoodSearchMainLoop.cs
r5753 r6046 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();
Note: See TracChangeset
for help on using the changeset viewer.