Changeset 15507
- Timestamp:
- 12/11/17 15:42:12 (7 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Algorithms.GRASP/3.3/GRASPWithPathRelinking.cs
r15492 r15507 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Operators; 28 29 using HeuristicLab.Optimization; 29 30 using HeuristicLab.Optimization.Operators; … … 111 112 get { return (RandomCreator)OperatorGraph.InitialOperator; } 112 113 } 114 private VariableCreator VariableCreator { 115 get { return (VariableCreator)RandomCreator.Successor; } 116 } 113 117 private SolutionsCreator SolutionsCreator { 114 get { return (SolutionsCreator)RandomCreator.Successor; } 118 get { return (SolutionsCreator)VariableCreator.Successor; } 119 } 120 private SubScopesCounter SubScopesCounter { 121 get { return (SubScopesCounter)SolutionsCreator.Successor; } 122 } 123 private ResultsCollector ResultsCollector { 124 get { return (ResultsCollector)SubScopesCounter.Successor; } 115 125 } 116 126 private GRASPWithPathRelinkingMainLoop MainLoop { 117 get { return SolutionsCreator.Successor as GRASPWithPathRelinkingMainLoop; }127 get { return (GRASPWithPathRelinkingMainLoop)ResultsCollector.Successor; } 118 128 } 119 129 #endregion … … 153 163 randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name; 154 164 randomCreator.SetSeedRandomlyParameter.Value = null; 155 165 166 var variableCreator = new VariableCreator(); 167 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0))); 168 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 169 randomCreator.Successor = variableCreator; 170 156 171 var solutionsCreator = new SolutionsCreator(); 157 172 solutionsCreator.NumberOfSolutionsParameter.ActualName = MinimumEliteSetSizeParameter.Name; 158 173 solutionsCreator.ParallelParameter.Value = new BoolValue(true); 159 randomCreator.Successor = solutionsCreator; 174 variableCreator.Successor = solutionsCreator; 175 176 var subscopesCounter = new SubScopesCounter(); 177 subscopesCounter.Name = "EvaluatedSolutions++"; 178 subscopesCounter.AccumulateParameter.Value.Value = true; 179 subscopesCounter.ValueParameter.ActualName = "EvaluatedSolutions"; 180 solutionsCreator.Successor = subscopesCounter; 181 182 var resultsCollector = new ResultsCollector(); 183 resultsCollector.CopyValue.Value = false; 184 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "Counter for the number of times the evaluation function is called.")); 185 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations", "The algorithm's current iteration")); 186 subscopesCounter.Successor = resultsCollector; 160 187 161 188 var mainLoop = new GRASPWithPathRelinkingMainLoop(); … … 168 195 mainLoop.PathRelinkingParameter.ActualName = PathRelinkingParameter.Name; 169 196 mainLoop.ResultsParameter.ActualName = "Results"; 170 solutionsCreator.Successor = mainLoop;197 resultsCollector.Successor = mainLoop; 171 198 172 199 InitializeOperators(); -
branches/GeneralizedQAP/HeuristicLab.Algorithms.GRASP/3.3/GRASPWithPathRelinkingMainLoop.cs
r15492 r15507 37 37 [StorableClass] 38 38 public class GRASPWithPathRelinkingMainLoop : AlgorithmOperator { 39 public IValueLookupParameter<IntValue> IterationsParameter { 40 get { return (IValueLookupParameter<IntValue>)Parameters["Iterations"]; } 41 } 39 42 public IValueLookupParameter<IOperator> SolutionCreatorParameter { 40 43 get { return (IValueLookupParameter<IOperator>)Parameters["SolutionCreator"]; } … … 74 77 public GRASPWithPathRelinkingMainLoop() 75 78 : base() { 79 Parameters.Add(new ValueLookupParameter<IntValue>("Iterations", "The algorithm's current iteration.")); 76 80 Parameters.Add(new ValueLookupParameter<IOperator>("SolutionCreator", "The solution creation procedure which ideally should be a greedy initialization heuristic.")); 77 81 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The evaluator which calculates the fitness of a solutions.")); … … 85 89 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The analyzer that is to be applied.")); 86 90 87 var variableCreator1 = new VariableCreator(); 88 variableCreator1.Name = "Iterations = 0"; 89 variableCreator1.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 90 91 var resultsCollector = new ResultsCollector(); 92 resultsCollector.CopyValue = new BoolValue(false); 93 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations")); 91 var analyzer1 = new Placeholder() { Name = "(Analyzer)" }; 92 analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; 94 93 95 94 var selector1 = new RandomSelector(); … … 111 110 var eo2 = new EmptyOperator(); 112 111 113 var placeholder1 = new Placeholder(); 114 placeholder1.Name = "(LocalImprovement)"; 112 var placeholder1 = new Placeholder() { Name = "(LocalImprovement)" }; 115 113 placeholder1.OperatorParameter.ActualName = LocalImprovementParameter.Name; 116 114 … … 120 118 var ssp3 = new SubScopesProcessor(); 121 119 122 var placeholder2 = new Placeholder(); 123 placeholder2.Name = "(PathRelinking)"; 120 var placeholder2 = new Placeholder() { Name = "(PathRelinking)" }; 124 121 placeholder2.OperatorParameter.ActualName = PathRelinkingParameter.Name; 125 122 126 var placeholder3 = new Placeholder(); 127 placeholder3.Name = "(Evaluator)"; 123 var placeholder3 = new Placeholder() { Name = "(Evaluator)" }; 128 124 placeholder3.OperatorParameter.ActualName = EvaluatorParameter.Name; 129 125 … … 137 133 placeholder4.OperatorParameter.ActualName = LocalImprovementParameter.Name; 138 134 139 var placeholder5 = new Placeholder(); 140 placeholder5.Name = "(EliteSetReplacer)"; 135 var placeholder5 = new Placeholder() { Name = "(EliteSetReplacer)" }; 141 136 placeholder5.OperatorParameter.ActualName = EliteSetReducerParameter.Name; 142 137 143 var counter = new IntCounter(); 144 counter.Name = "Iterations++"; 145 counter.ValueParameter.ActualName = "Iterations"; 138 var counter = new IntCounter() { Name = "Iterations++" }; 139 counter.ValueParameter.ActualName = IterationsParameter.Name; 146 140 counter.Increment = new IntValue(1); 147 141 148 var analyzer1 = new Placeholder(); 149 analyzer1.Name = "(Analyzer)"; 150 analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; 151 152 var comparator3 = new Comparator(); 153 comparator3.Name = "Iterations >= MaximumIterations"; 142 var analyzer2 = new Placeholder() { Name = "(Analyzer)" }; 143 analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name; 144 145 var comparator3 = new Comparator() { Name = "Iterations >= MaximumIterations" }; 154 146 comparator3.Comparison.Value = ComparisonType.GreaterOrEqual; 155 comparator3.LeftSideParameter.ActualName = "Iterations";147 comparator3.LeftSideParameter.ActualName = IterationsParameter.Name; 156 148 comparator3.RightSideParameter.ActualName = MaximumIterationsParameter.Name; 157 149 comparator3.ResultParameter.ActualName = "TerminatedByIteration"; 158 150 159 var conditionalBranch3 = new ConditionalBranch(); 160 conditionalBranch3.Name = "Terminate by Iterations?"; 151 var conditionalBranch3 = new ConditionalBranch() { Name = "Terminate by Iterations?" }; 161 152 conditionalBranch3.ConditionParameter.ActualName = "TerminatedByIteration"; 162 153 163 OperatorGraph.InitialOperator = variableCreator1; 164 variableCreator1.Successor = resultsCollector; 165 resultsCollector.Successor = selector1; 154 OperatorGraph.InitialOperator = analyzer1; 155 analyzer1.Successor = selector1; 166 156 selector1.Successor = ssp1; 167 157 ssp1.Operators.Add(eo1); … … 183 173 placeholder4.Successor = null; 184 174 placeholder5.Successor = counter; 185 counter.Successor = analyzer 1;186 analyzer 1.Successor = comparator3;175 counter.Successor = analyzer2; 176 analyzer2.Successor = comparator3; 187 177 comparator3.Successor = conditionalBranch3; 188 178 conditionalBranch3.TrueBranch = null; -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Evaluation/GQAPNMoveEvaluator.cs
r15506 r15507 130 130 131 131 MoveEvaluationParameter.ActualValue = moveEvaluation; 132 MoveQualityParameter.ActualValue = new DoubleValue(problemInstance.ToSingleObjective(moveEvaluation)); 132 133 return base.Apply(); 133 134 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/HeuristicLab.Problems.GeneralizedQuadraticAssignment-3.3.csproj
r15504 r15507 102 102 <Compile Include="GQAPAssignment.cs" /> 103 103 <Compile Include="GQAPInstance.cs" /> 104 <Compile Include="Interfaces\Parameter\IAssignmentAwareGQAPOperator.cs" /> 104 105 <Compile Include="Operators\Crossovers\CordeauCrossover.cs" /> 105 106 <Compile Include="SolutionCreators\SlackMinimizationSolutionCreator.cs" /> -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Operators/LocalImprovers/ApproximateLocalSearch.cs
r15506 r15507 106 106 /// <param name="maximumIterations">The maximum number of iterations that should be performed each time the candidate list is generated.</param> 107 107 /// <param name="problemInstance">The problem instance that contains the data.</param> 108 /// <param name="evaluatedSolutions">The number of evaluated solutions.</param> 108 109 /// <param name="oneMoveProbability">The probability for performing a 1-move, which is the opposite of performing a 2-move.</param> 109 110 public static void Apply(IRandom random, IntegerVector assignment, 110 111 DoubleValue quality, ref Evaluation evaluation, IntValue maxCLS, IntValue maximumIterations, 111 GQAPInstance problemInstance, PercentValue oneMoveProbability) {112 GQAPInstance problemInstance, IntValue evaluatedSolutions, PercentValue oneMoveProbability) { 112 113 var capacities = problemInstance.Capacities; 113 114 var demands = problemInstance.Demands; 114 //var weights = problemInstance.Weights; 115 //var distances = problemInstance.Distances; 116 //var installationCosts = problemInstance.InstallationCosts; 115 var evaluations = 0.0; 116 var deltaEvaluationFactor = 1.0 / assignment.Length; 117 117 while (true) { 118 118 int count = 0; … … 126 126 127 127 var moveEval = GQAPNMoveEvaluator.Evaluate(move, assignment, evaluation, problemInstance); 128 evaluations += move.NewAssignments.Count * deltaEvaluationFactor; 128 129 double moveQuality = problemInstance.ToSingleObjective(moveEval); 129 130 130 if (moveEval.ExcessDemand <= 0.0 && moveQuality < 0.0) {131 if (moveEval.ExcessDemand <= 0.0 && moveQuality < quality.Value) { 131 132 CLS.Add(Tuple.Create(move, moveQuality, moveEval)); 132 133 sum += 1.0 / moveQuality; … … 135 136 } while (CLS.Count < maxCLS.Value && count < maximumIterations.Value); 136 137 137 if (CLS.Count == 0) 138 if (CLS.Count == 0) { 139 evaluatedSolutions.Value += (int)Math.Ceiling(evaluations); 138 140 return; // END 139 else {141 } else { 140 142 var ball = random.NextDouble() * sum; 141 143 var selected = CLS.Last(); … … 148 150 } 149 151 NMoveMaker.Apply(assignment, selected.Item1); 150 quality.Value += selected.Item2;152 quality.Value = selected.Item2; 151 153 evaluation = selected.Item3; 152 154 } … … 163 165 MaximumIterationsParameter.ActualValue, 164 166 ProblemInstanceParameter.ActualValue, 167 EvaluatedSolutionsParameter.ActualValue, 165 168 OneMoveProbabilityParameter.ActualValue); 166 169 EvaluationParameter.ActualValue = evaluation; -
branches/GeneralizedQAP/UnitTests/CordeauCrossoverTest.cs
r15504 r15507 45 45 46 46 try { 47 CordeauCrossover.Apply(random, gqap.Maximization,47 CordeauCrossover.Apply(random, 48 48 parent1, 49 49 new DoubleValue(gqap.Evaluate(parent1)),
Note: See TracChangeset
for help on using the changeset viewer.