Changeset 7412 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms
- Timestamp:
- 01/25/12 18:32:44 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP
- Property svn:ignore
-
old new 1 1 *.suo 2 TestResults
-
- Property svn:ignore
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASPWithPathRelinking.cs
r7363 r7412 61 61 get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; } 62 62 } 63 public IValueParameter<IntValue> MaximumIterationsParameter { 64 get { return (IValueParameter<IntValue>)Parameters["MaximumIterations"]; } 65 } 63 66 private IFixedValueParameter<IntValue> EliteSetSizeParameter { 64 67 get { return (IFixedValueParameter<IntValue>)Parameters["EliteSetSize"]; } … … 76 79 get { return (ConstrainedValueParameter<ICrossover>)Parameters["PathRelinking"]; } 77 80 } 78 public ConstrainedValueParameter<IMerger> EliteSet ReplacerParameter {81 public ConstrainedValueParameter<IMerger> EliteSetMergerParameter { 79 82 get { return (ConstrainedValueParameter<IMerger>)Parameters["EliteSetMerger"]; } 80 83 } … … 106 109 get { return (RandomCreator)OperatorGraph.InitialOperator; } 107 110 } 108 #endregion 111 private GRASPWithPathRelinkingMainLoop MainLoop { 112 get { return RandomCreator.Successor as GRASPWithPathRelinkingMainLoop; } 113 } 114 #endregion 115 116 [Storable] 117 private BestAverageWorstQualityAnalyzer analyzer; 109 118 110 119 [StorableConstructor] … … 112 121 private GRASPWithPathRelinking(GRASPWithPathRelinking original, Cloner cloner) 113 122 : base(original, cloner) { 123 analyzer = cloner.Clone(original.analyzer); 114 124 RegisterEventHandlers(); 115 125 } … … 119 129 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.")); 120 130 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each iteration.", new MultiAnalyzer())); 131 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of iterations that the algorithm should run.", new IntValue(1000))); 121 132 Parameters.Add(new FixedValueParameter<IntValue>("EliteSetSize", "The elite set stores the best found solutions.", new IntValue(10))); 122 Parameters.Add(new FixedValueParameter<IntValue>("LocalImprovementMaximumIterations", "The maximum number of iterations performed by the local improvement operator.", new IntValue(100 )));133 Parameters.Add(new FixedValueParameter<IntValue>("LocalImprovementMaximumIterations", "The maximum number of iterations performed by the local improvement operator.", new IntValue(1000))); 123 134 Parameters.Add(new ConstrainedValueParameter<ILocalImprovementOperator>("LocalImprovement", "Performs a local search on the solution.")); 124 Parameters.Add(new FixedValueParameter<IntValue>("MinimumEliteSetSize", "(ρ) The minimum amount of elites for performing path relinking.", new IntValue( 1)));135 Parameters.Add(new FixedValueParameter<IntValue>("MinimumEliteSetSize", "(ρ) The minimum amount of elites for performing path relinking.", new IntValue(2))); 125 136 Parameters.Add(new ConstrainedValueParameter<ICrossover>("PathRelinking", "The operator that performs the path relinking.")); 126 137 Parameters.Add(new ConstrainedValueParameter<IMerger>("EliteSetMerger", "The operator that merges new solutions into the elite set.")); 138 139 analyzer = new BestAverageWorstQualityAnalyzer(); 140 Analyzer.Operators.Add(analyzer); 127 141 128 142 RandomCreator randomCreator = new RandomCreator(); … … 136 150 137 151 var mainLoop = new GRASPWithPathRelinkingMainLoop(); 152 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 153 mainLoop.EliteSetMergerParameter.ActualName = EliteSetMergerParameter.Name; 154 mainLoop.EliteSetSizeParameter.ActualName = EliteSetSizeParameter.Name; 155 mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions"; 156 mainLoop.LocalImprovementParameter.ActualName = LocalImprovementParameter.Name; 157 mainLoop.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 158 mainLoop.PathRelinkingParameter.ActualName = PathRelinkingParameter.Name; 159 mainLoop.ResultsParameter.ActualName = "Results"; 138 160 randomCreator.Successor = mainLoop; 139 161 … … 185 207 Analyzer.Operators.Clear(); 186 208 if (Problem != null) { 187 foreach (IAnalyzer a nalyzerin Problem.Operators.OfType<IAnalyzer>()) {188 foreach (var param in a nalyzer.Parameters.OfType<IScopeTreeLookupParameter>())209 foreach (IAnalyzer a in Problem.Operators.OfType<IAnalyzer>()) { 210 foreach (var param in a.Parameters.OfType<IScopeTreeLookupParameter>()) 189 211 param.Depth = 1; 190 Analyzer.Operators.Add(a nalyzer);212 Analyzer.Operators.Add(a); 191 213 } 192 214 InitializeFromInstallation(LocalImprovementParameter, x => x.ProblemType.IsAssignableFrom(Problem.GetType())); 193 215 InitializeFromProblem(PathRelinkingParameter); 194 InitializeFromProblem(EliteSet ReplacerParameter);216 InitializeFromProblem(EliteSetMergerParameter); 195 217 } else { 196 218 LocalImprovementParameter.ValidValues.Clear(); 197 219 PathRelinkingParameter.ValidValues.Clear(); 198 EliteSetReplacerParameter.ValidValues.Clear(); 199 } 220 EliteSetMergerParameter.ValidValues.Clear(); 221 } 222 Analyzer.Operators.Add(analyzer); 200 223 201 224 Parameterize(); … … 203 226 204 227 private void Parameterize() { 228 if (Problem != null) { 229 MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 230 MainLoop.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 231 232 analyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 233 } 205 234 foreach (var localImprovement in LocalImprovementParameter.ValidValues) { 206 235 localImprovement.MaximumIterationsParameter.ActualName = LocalImprovementMaximumIterationsParameter.Name; … … 210 239 localImprovement.Problem = Problem; 211 240 } 241 foreach (var merger in EliteSetMergerParameter.ValidValues) { 242 merger.PopulationSizeParameter.ActualName = EliteSetSizeParameter.Name; 243 } 212 244 } 213 245 214 246 private void InitializeFromProblem<T>(ConstrainedValueParameter<T> parameter) where T : class, INamedItem { 215 InitializeFromProblem (parameter, x => true);247 InitializeFromProblem<T>(parameter, x => true); 216 248 } 217 249 private void InitializeFromProblem<T>(ConstrainedValueParameter<T> parameter, Func<T, bool> condition) where T : class, INamedItem { … … 228 260 } 229 261 private void InitializeFromInstallation<T>(ConstrainedValueParameter<T> parameter) where T : class, INamedItem { 230 InitializeFromInstallation (parameter, x => true);262 InitializeFromInstallation<T>(parameter, x => true); 231 263 } 232 264 private void InitializeFromInstallation<T>(ConstrainedValueParameter<T> parameter, Func<T, bool> condition) where T : class, INamedItem { -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASPWithPathRelinkingMainLoop.cs
r7373 r7412 89 89 variableCreator1.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 90 90 91 var resultsCollector = new ResultsCollector(); 92 resultsCollector.CopyValue = new BoolValue(false); 93 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 94 91 95 var variableCreator2 = new VariableCreator(); 92 96 variableCreator2.Name = "ActualEliteSetSize = 0"; … … 157 161 placeholder2.OperatorParameter.ActualName = PathRelinkingParameter.Name; 158 162 163 var placeholder3 = new Placeholder(); 164 placeholder3.Name = "(Evaluator)"; 165 placeholder3.OperatorParameter.ActualName = EvaluatorParameter.Name; 166 159 167 var subScopesRemover = new SubScopesRemover(); 160 168 subScopesRemover.RemoveAllSubScopes = true; … … 162 170 var ssp4 = new SubScopesProcessor(); 163 171 164 var placeholder3 = new Placeholder();165 placeholder3.Name = "(LocalImprovement)";166 placeholder3.OperatorParameter.ActualName = LocalImprovementParameter.Name;167 168 172 var placeholder4 = new Placeholder(); 169 placeholder4.Name = "(EliteSetMerger)"; 170 placeholder4.OperatorParameter.ActualName = EliteSetMergerParameter.Name; 173 placeholder4.Name = "(LocalImprovement)"; 174 placeholder4.OperatorParameter.ActualName = LocalImprovementParameter.Name; 175 176 var placeholder5 = new Placeholder(); 177 placeholder5.Name = "(EliteSetMerger)"; 178 placeholder5.OperatorParameter.ActualName = EliteSetMergerParameter.Name; 171 179 172 180 var counter = new IntCounter(); … … 191 199 192 200 OperatorGraph.InitialOperator = variableCreator1; 193 variableCreator1.Successor = variableCreator2; 201 variableCreator1.Successor = resultsCollector; 202 resultsCollector.Successor = variableCreator2; 194 203 variableCreator2.Successor = subScopesCounter1; 195 204 subScopesCounter1.Successor = comparator1; … … 200 209 ssp1.Operators.Add(eo1); 201 210 ssp1.Operators.Add(solutionsCreator); 202 ssp1.Successor = placeholder 4;211 ssp1.Successor = placeholder5; 203 212 eo1.Successor = null; 204 213 solutionsCreator.Successor = subScopesCounter2; … … 216 225 ssp3.Operators.Add(placeholder2); 217 226 ssp3.Successor = null; 218 placeholder2.Successor = subScopesRemover; 227 placeholder2.Successor = placeholder3; 228 placeholder3.Successor = subScopesRemover; 219 229 subScopesRemover.Successor = null; 220 ssp4.Operators.Add(placeholder 3);230 ssp4.Operators.Add(placeholder4); 221 231 ssp4.Successor = null; 222 placeholder 4.Successor = counter;232 placeholder5.Successor = counter; 223 233 counter.Successor = analyzer1; 224 234 analyzer1.Successor = comparator3;
Note: See TracChangeset
for help on using the changeset viewer.