- Timestamp:
- 03/22/11 16:45:46 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.LocalSearch/3.3
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.LocalSearch/3.3/HeuristicLab.Algorithms.LocalSearch-3.3.csproj
r5163 r5796 12 12 <AssemblyName>HeuristicLab.Algorithms.LocalSearch-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> … … 107 108 <ItemGroup> 108 109 <Compile Include="HeuristicLabAlgorithmsLocalSearchPlugin.cs" /> 110 <Compile Include="LocalSearchImprovementOperator.cs" /> 109 111 <Compile Include="LocalSearchMainLoop.cs" /> 110 112 <Compile Include="Properties\AssemblyInfo.cs" /> -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
r5644 r5796 168 168 variableCreator.Name = "Initialize EvaluatedMoves"; 169 169 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue())); 170 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 171 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0))); 170 172 variableCreator.Successor = resultsCollector; 171 173 … … 182 184 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 183 185 mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves"; 186 mainLoop.IterationsParameter.ActualName = "Iterations"; 187 mainLoop.BestQualityParameter.ActualName = "BestQuality"; 184 188 185 189 moveQualityAnalyzer = new BestAverageWorstQualityAnalyzer(); -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchImprovementOperator.cs
r5792 r5796 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Text; 25 using HeuristicLab.Analysis; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 using HeuristicLab. Persistence.Default.CompositeSerializers.Storable;28 using HeuristicLab.Data; 28 29 using HeuristicLab.Operators; 29 using HeuristicLab.Common;30 using HeuristicLab.Parameters;31 using HeuristicLab.Algorithms.LocalSearch;32 using HeuristicLab.Data;33 30 using HeuristicLab.Optimization; 34 31 using HeuristicLab.Optimization.Operators; 35 using HeuristicLab.Analysis; 32 using HeuristicLab.Parameters; 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 36 34 37 35 namespace HeuristicLab.Algorithms.LocalSearch { … … 41 39 [Item("LocalSearchImprovementOperator", "A local search improvement operator.")] 42 40 [StorableClass] 43 public class LocalSearchImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator {41 public class LocalSearchImprovementOperator : SingleSuccessorOperator, ILocalImprovementOperator { 44 42 [Storable] 45 43 private LocalSearchMainLoop loop; … … 47 45 [Storable] 48 46 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 49 47 50 48 private ConstrainedValueParameter<IMoveGenerator> MoveGeneratorParameter { 51 49 get { return (ConstrainedValueParameter<IMoveGenerator>)Parameters["MoveGenerator"]; } … … 88 86 89 87 [StorableConstructor] 90 protected LocalSearchImprovementOperator(bool deserializing) : base(deserializing) { }88 protected LocalSearchImprovementOperator(bool deserializing) : base(deserializing) { } 91 89 [StorableHook(HookType.AfterDeserialization)] 92 90 private void AfterDeserialization() { … … 95 93 protected LocalSearchImprovementOperator(LocalSearchImprovementOperator original, Cloner cloner) 96 94 : base(original, cloner) { 97 98 99 95 this.loop = cloner.Clone(original.loop); 96 this.qualityAnalyzer = cloner.Clone(original.qualityAnalyzer); 97 Initialize(); 100 98 } 101 99 public override IDeepCloneable Clone(Cloner cloner) { … … 104 102 public LocalSearchImprovementOperator() 105 103 : base() { 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 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 Parameters.Add(new ConstrainedValueParameter<IMoveGenerator>("MoveGenerator", "The operator used to generate moves to the neighborhood of the current solution.")); 112 Parameters.Add(new ConstrainedValueParameter<IMoveMaker>("MoveMaker", "The operator used to perform a move.")); 113 Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveMoveEvaluator>("MoveEvaluator", "The operator used to evaluate a move.")); 114 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.", new IntValue(150))); 115 Parameters.Add(new ValueParameter<IntValue>("SampleSize", "Number of moves that MultiMoveGenerators should create. This is ignored for Exhaustive- and SingleMoveGenerators.", new IntValue(1500))); 116 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated moves.")); 117 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the solution.", new MultiAnalyzer())); 118 119 Initialize(); 122 120 } 123 121 … … 130 128 ChooseMoveOperators(); 131 129 132 ParameterizeMoveGenerators(problem as ISingleObjective Problem);133 ParameterizeMoveEvaluators(problem as ISingleObjective Problem);134 ParameterizeMoveMakers(problem as ISingleObjective Problem);135 136 ParameterizeAnalyzers(problem as ISingleObjective Problem);137 UpdateAnalyzers(problem as ISingleObjective Problem);138 } 139 140 void ParameterizeAnalyzers(ISingleObjective Problem problem) {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) { 141 139 qualityAnalyzer.ResultsParameter.ActualName = "Results"; 142 140 if (problem != null) { … … 148 146 } 149 147 150 void UpdateAnalyzers(ISingleObjective Problem problem) {148 void UpdateAnalyzers(ISingleObjectiveHeuristicOptimizationProblem problem) { 151 149 Analyzer.Operators.Clear(); 152 150 if (problem != null) { … … 228 226 if (mm != null) MoveMaker = mm; 229 227 else MoveMaker = validMoveMakers.FirstOrDefault(); 230 } 228 } 231 229 232 230 if (oldMoveEvaluator != null) { … … 234 232 if (me != null) MoveEvaluator = me; 235 233 else MoveEvaluator = validMoveEvaluators.FirstOrDefault(); 236 } 234 } 237 235 } 238 236 } … … 244 242 } 245 243 246 private void ParameterizeMoveGenerators(ISingleObjective Problem problem) {244 private void ParameterizeMoveGenerators(ISingleObjectiveHeuristicOptimizationProblem problem) { 247 245 if (problem != null) { 248 246 foreach (IMultiMoveGenerator generator in problem.Operators.OfType<IMultiMoveGenerator>()) … … 250 248 } 251 249 } 252 private void ParameterizeMoveEvaluators(ISingleObjective Problem problem) {250 private void ParameterizeMoveEvaluators(ISingleObjectiveHeuristicOptimizationProblem problem) { 253 251 foreach (ISingleObjectiveMoveEvaluator op in problem.Operators.OfType<ISingleObjectiveMoveEvaluator>()) { 254 252 op.QualityParameter.ActualName = problem.Evaluator.QualityParameter.ActualName; 255 253 } 256 254 } 257 private void ParameterizeMoveMakers(ISingleObjective Problem problem) {255 private void ParameterizeMoveMakers(ISingleObjectiveHeuristicOptimizationProblem problem) { 258 256 foreach (IMoveMaker op in problem.Operators.OfType<IMoveMaker>()) { 259 257 op.QualityParameter.ActualName = problem.Evaluator.QualityParameter.ActualName; -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs
r5445 r5796 46 46 get { return (LookupParameter<DoubleValue>)Parameters["Quality"]; } 47 47 } 48 public LookupParameter<DoubleValue> BestQualityParameter { 49 get { return (LookupParameter<DoubleValue>)Parameters["BestLocalQuality"]; } 50 } 48 51 public ValueLookupParameter<DoubleValue> BestKnownQualityParameter { 49 52 get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } … … 51 54 public LookupParameter<DoubleValue> MoveQualityParameter { 52 55 get { return (LookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 56 } 57 public LookupParameter<IntValue> IterationsParameter { 58 get { return (LookupParameter<IntValue>)Parameters["LocalIterations"]; } 53 59 } 54 60 public ValueLookupParameter<IntValue> MaximumIterationsParameter { … … 79 85 public LocalSearchMainLoop() 80 86 : base() { 81 Initialize();87 Initialize(); 82 88 } 83 89 private LocalSearchMainLoop(LocalSearchMainLoop original, Cloner cloner) … … 93 99 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 94 100 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 101 Parameters.Add(new LookupParameter<DoubleValue>("BestLocalQuality", "The value which represents the best quality found so far.")); 95 102 Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); 96 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.")); 97 105 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed.")); 98 106 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); … … 107 115 108 116 #region Create operators 109 VariableCreator variableCreator = new VariableCreator();110 117 SubScopesProcessor subScopesProcessor0 = new SubScopesProcessor(); 111 118 Assigner bestQualityInitializer = new Assigner(); … … 124 131 Placeholder moveMaker = new Placeholder(); 125 132 Assigner bestQualityUpdater = new Assigner(); 133 ResultsCollector resultsCollector2 = new ResultsCollector(); 126 134 MergingReducer mergingReducer = new MergingReducer(); 127 135 Placeholder analyzer2 = new Placeholder(); … … 131 139 ConditionalBranch iterationsTermination = new ConditionalBranch(); 132 140 133 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); // Class LocalSearch expects this to be called Iterations134 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0)));135 136 141 bestQualityInitializer.Name = "Initialize BestQuality"; 137 bestQualityInitializer.LeftSideParameter.ActualName = "BestQuality";142 bestQualityInitializer.LeftSideParameter.ActualName = BestQualityParameter.Name; 138 143 bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name; 139 144 … … 142 147 143 148 resultsCollector1.CopyValue = new BoolValue(false); 144 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>( "Iterations"));145 resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>( "Best Quality", null, "BestQuality"));149 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>(IterationsParameter.Name)); 150 resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>(BestQualityParameter.Name, null, BestQualityParameter.Name)); 146 151 resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name; 147 152 … … 172 177 173 178 bestQualityUpdater.Name = "Update BestQuality"; 174 bestQualityUpdater.LeftSideParameter.ActualName = "BestQuality";179 bestQualityUpdater.LeftSideParameter.ActualName = BestQualityParameter.Name; 175 180 bestQualityUpdater.RightSideParameter.ActualName = QualityParameter.Name; 181 182 resultsCollector2.CopyValue = new BoolValue(false); 183 resultsCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>(BestQualityParameter.Name, null, BestQualityParameter.Name)); 184 resultsCollector2.ResultsParameter.ActualName = ResultsParameter.Name; 176 185 177 186 analyzer2.Name = "Analyzer (placeholder)"; … … 182 191 iterationsCounter.Name = "Iterations Counter"; 183 192 iterationsCounter.Increment = new IntValue(1); 184 iterationsCounter.ValueParameter.ActualName = "Iterations";193 iterationsCounter.ValueParameter.ActualName = IterationsParameter.Name; 185 194 186 195 iterationsComparator.Name = "Iterations >= MaximumIterations"; 187 196 iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); 188 iterationsComparator.LeftSideParameter.ActualName = "Iterations";197 iterationsComparator.LeftSideParameter.ActualName = IterationsParameter.Name; 189 198 iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name; 190 199 iterationsComparator.ResultParameter.ActualName = "Terminate"; … … 195 204 196 205 #region Create operator graph 197 OperatorGraph.InitialOperator = variableCreator; 198 variableCreator.Successor = subScopesProcessor0; 206 OperatorGraph.InitialOperator = subScopesProcessor0; 199 207 subScopesProcessor0.Operators.Add(bestQualityInitializer); 200 208 subScopesProcessor0.Successor = resultsCollector1;
Note: See TracChangeset
for help on using the changeset viewer.