- Timestamp:
- 04/12/12 16:42:17 (13 years ago)
- Location:
- branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs
r7722 r7724 39 39 get { return (ScopeParameter)Parameters["CurrentScope"]; } 40 40 } 41 p ublicValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {41 private ValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter { 42 42 get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; } 43 43 } 44 p ublicValueLookupParameter<IntValue> ReferenceSetSizeParameter {44 private ValueLookupParameter<IntValue> ReferenceSetSizeParameter { 45 45 get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; } 46 46 } … … 48 48 49 49 #region Properties 50 p ublicIScope CurrentScope {50 private IScope CurrentScope { 51 51 get { return CurrentScopeParameter.ActualValue; } 52 52 } 53 p ublicIntValue NumberOfHighQualitySolutions {53 private IntValue NumberOfHighQualitySolutions { 54 54 get { return NumberOfHighQualitySolutionsParameter.ActualValue; } 55 55 set { NumberOfHighQualitySolutionsParameter.ActualValue = value; } 56 56 } 57 p ublicIntValue ReferenceSetSize {57 private IntValue ReferenceSetSize { 58 58 get { return ReferenceSetSizeParameter.ActualValue; } 59 59 set { ReferenceSetSizeParameter.ActualValue = value; } -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs
r7722 r7724 93 93 foreach (var r in CurrentScope.SubScopes[1].SubScopes) { 94 94 BinaryVector rSol = r.Variables["KnapsackSolution"].Value as BinaryVector; 95 if (pSol != null && rSol != null) {96 diversity += CalculateDiversity(pSol, rSol);97 }98 if (mostDiverseSolution == null || diversity > maxDiversity)99 mostDiverseSolution = p;95 if (pSol != null && rSol != null) diversity += CalculateDiversity(pSol, rSol); 96 } 97 if (mostDiverseSolution == null || diversity > maxDiversity) { 98 mostDiverseSolution = p; 99 maxDiversity = diversity; 100 100 } 101 101 } -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs
r7722 r7724 37 37 38 38 namespace HeuristicLab.Algorithms.ScatterSearch { 39 /// <summary> 40 /// A scatter search algorithm. 41 /// </summary> 39 42 [Item("Scatter Search", "A scatter search algorithm.")] 40 43 [Creatable("Algorithms")] … … 263 266 base.OnProblemChanged(); 264 267 } 265 266 268 protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { 267 269 ParameterizeStochasticOperator(Problem.SolutionCreator); … … 269 271 base.Problem_SolutionCreatorChanged(sender, e); 270 272 } 271 272 273 protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { 273 274 ParameterizeStochasticOperator(Problem.Evaluator); … … 280 281 base.Problem_EvaluatorChanged(sender, e); 281 282 } 282 283 283 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 284 284 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); … … 393 393 foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) { 394 394 foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>()) 395 param.Depth = 0;395 param.Depth = 1; 396 396 Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault); 397 397 } … … 409 409 private void ParameterizeMainLoop() { 410 410 if (Problem != null) { 411 //MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;412 //MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;413 //MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;414 } 415 if (MoveEvaluator != null) ;416 //MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName;411 MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 412 MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 413 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 414 } 415 if (MoveEvaluator != null) 416 MainLoop.MoveQualityParameter.ActualName = MoveEvaluator.MoveQualityParameter.ActualName; 417 417 } 418 418 private void ParameterizeStochasticOperator(IOperator op) { … … 476 476 } 477 477 } 478 479 478 private ScatterSearchMainLoop FindMainLoop(IOperator start) { 480 479 IOperator mainLoop = start; -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearchMainLoop.cs
r7722 r7724 47 47 get { return (LookupParameter<IntValue>)Parameters["MaximumIterations"]; } 48 48 } 49 internal LookupParameter<BoolValue> MaximizationParameter { 50 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 51 } 49 52 internal LookupParameter<IntValue> SampleSizeParameter { 50 53 get { return (LookupParameter<IntValue>)Parameters["SampleSize"]; } … … 59 62 get { return (LookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; } 60 63 } 64 internal LookupParameter<DoubleValue> QualityParameter { 65 get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; } 66 } 67 internal LookupParameter<DoubleValue> BestKnownQualityParameter { 68 get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 69 } 70 internal LookupParameter<DoubleValue> MoveQualityParameter { 71 get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 72 } 61 73 internal LookupParameter<VariableCollection> ResultsParameter { 62 74 get { return (LookupParameter<VariableCollection>)Parameters["Results"]; } 75 } 76 internal LookupParameter<IOperator> MoveEvaluatorParameter { 77 get { return (LookupParameter<IOperator>)Parameters["MoveEvaluator"]; } 78 } 79 internal LookupParameter<IOperator> MoveGeneratorParameter { 80 get { return (LookupParameter<IOperator>)Parameters["MoveGenerator"]; } 81 } 82 internal LookupParameter<IOperator> MoveMakerParameter { 83 get { return (LookupParameter<IOperator>)Parameters["MoveMaker"]; } 63 84 } 64 85 internal LookupParameter<IMultiAnalyzer> AnalyzerParameter { … … 80 101 set { MaximumIterationsParameter.ActualValue = value; } 81 102 } 103 public BoolValue Maximization { 104 get { return MaximizationParameter.ActualValue; } 105 set { MaximizationParameter.ActualValue = value; } 106 } 82 107 public IntValue SampleSize { 83 108 get { return SampleSizeParameter.ActualValue; } … … 96 121 set { NumberOfHighQualitySolutionsParameter.ActualValue = value; } 97 122 } 123 public DoubleValue Quality { 124 get { return QualityParameter.ActualValue; } 125 set { QualityParameter.ActualValue = value; } 126 } 127 public DoubleValue BestKnownQuality { 128 get { return BestKnownQualityParameter.ActualValue; } 129 set { BestKnownQualityParameter.ActualValue = value; } 130 } 131 public DoubleValue MoveQuality { 132 get { return MoveQualityParameter.ActualValue; } 133 set { MoveQualityParameter.ActualValue = value; } 134 } 98 135 public VariableCollection Results { 99 136 get { return ResultsParameter.ActualValue; } 100 137 set { ResultsParameter.ActualValue = value; } 138 } 139 public IOperator MoveEvaluator { 140 get { return MoveEvaluatorParameter.ActualValue; } 141 set { MoveEvaluatorParameter.ActualValue = value; } 142 } 143 public IOperator MoveGenerator { 144 get { return MoveGeneratorParameter.ActualValue; } 145 set { MoveGeneratorParameter.ActualValue = value; } 146 } 147 public IOperator MoveMaker { 148 get { return MoveMakerParameter.ActualValue; } 149 set { MoveMakerParameter.ActualValue = value; } 101 150 } 102 151 public IMultiAnalyzer Analyzer { … … 120 169 Parameters.Add(new LookupParameter<IntValue>("Iterations", "The number of iterations performed.")); 121 170 Parameters.Add(new LookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); 171 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 122 172 Parameters.Add(new LookupParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.")); 123 173 Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population.")); 124 174 Parameters.Add(new LookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set.")); 125 175 Parameters.Add(new LookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set.")); 176 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 177 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The problem's best known quality value found so far.")); 178 Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move.")); 126 179 Parameters.Add(new LookupParameter<IOperator>("SolutionCreator", "The operator which is used to create new solutions.")); 127 180 Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator which is used to evaluate new solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); … … 143 196 IntCounter interationsCounter = new IntCounter(); 144 197 LocalSearchImprovementOperator localImprovementOperator = new LocalSearchImprovementOperator(); 198 Placeholder analyzer = new Placeholder(); 145 199 Placeholder solutionImprover = new Placeholder(); 146 200 Placeholder solutionEvaluator = new Placeholder(); … … 204 258 interationsCounter.Successor = resultsCollector; 205 259 260 analyzer.Name = "Analyzer"; 261 analyzer.OperatorParameter.ActualName = "Analyzer"; 262 206 263 solutionImprover.Name = "SolutionImprover"; 207 264 solutionImprover.OperatorParameter.ActualName = "LocalImprovementOperator"; … … 214 271 populationRebuildMethod.Successor = subScopesProcessor3; 215 272 273 resultsCollector.CopyValue = new BoolValue(false); 216 274 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name)); 275 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(BestKnownQualityParameter.Name, null, BestKnownQualityParameter.Name)); 217 276 resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name; 218 277 resultsCollector.Successor = iterationsChecker; … … 221 280 222 281 solutionCombinationMethod.Successor = subScopesProcessor2; 282 283 solutionPoolUpdateMethod.Successor = analyzer; 223 284 224 285 solutionsCreator.Name = "DiversificationGenerationMethod"; … … 257 318 258 319 public override IOperation Apply() { 320 if (MoveGeneratorParameter.ActualValue == null || MoveEvaluatorParameter.ActualValue == null || MoveMakerParameter.ActualValue == null) 321 return null; 259 322 return base.Apply(); 260 323 } -
branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r7722 r7724 42 42 get { return (ValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; } 43 43 } 44 private ValueLookupParameter<IntValue> ReferenceSetSizeParameter { 45 get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; } 46 } 44 47 #endregion 45 48 46 49 #region Properties 47 p ublicIScope CurrentScope {50 private IScope CurrentScope { 48 51 get { return CurrentScopeParameter.ActualValue; } 49 52 } 50 p ublicBoolValue NewSolutions {53 private BoolValue NewSolutions { 51 54 get { return NewSolutionsParameter.ActualValue; } 55 } 56 private IntValue ReferenceSetSize { 57 get { return ReferenceSetSizeParameter.ActualValue; } 58 set { ReferenceSetSizeParameter.ActualValue = value; } 52 59 } 53 60 #endregion … … 64 71 private void Initialize() { 65 72 #region Create parameters 73 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes.")); 66 74 Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions", "Indicates if new solutions have been found.")); 67 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));75 Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set.")); 68 76 #endregion 69 77 … … 86 94 if ((offspring.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value 87 95 > (parents.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value) { 88 CurrentScope.SubScopes.Replace(CurrentScope.SubScopes.Union(offspring.SubScopes).OrderByDescending(o => o.Variables["Quality"].Value).Take( 10));96 CurrentScope.SubScopes.Replace(CurrentScope.SubScopes.Union(offspring.SubScopes).OrderByDescending(o => o.Variables["Quality"].Value).Take(ReferenceSetSize.Value)); 89 97 NewSolutions.Value = true; 90 98 }
Note: See TracChangeset
for help on using the changeset viewer.