Changeset 15563 for branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC
- Timestamp:
- 12/30/17 23:10:29 (6 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC
- Files:
-
- 1 added
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/LAHC.cs
r15562 r15563 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Threading; 24 25 using HeuristicLab.Common; … … 27 28 using HeuristicLab.Encodings.IntegerVectorEncoding; 28 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 32 31 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.L ocalSearch{32 [Item(" Iterated Local Search (GQAP)", "Iterated local searchfor the GQAP.")]33 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC { 34 [Item("LAHC (GQAP)", "Late-acceptance hill climber for the GQAP.")] 33 35 [Creatable(CreatableAttribute.Categories.SingleSolutionAlgorithms)] 34 36 [StorableClass] 35 public sealed class IteratedLS : ContextAlgorithm<LocalSearchContext> {37 public sealed class LAHC : StochasticAlgorithm<LAHCContext> { 36 38 37 39 public override bool SupportsPause { … … 48 50 } 49 51 52 [Storable] 53 private FixedValueParameter<IntValue> memorySizeParameter; 54 public IFixedValueParameter<IntValue> MemorySizeParameter { 55 get { return memorySizeParameter; } 56 } 57 58 public int MemorySize { 59 get { return memorySizeParameter.Value.Value; } 60 set { memorySizeParameter.Value.Value = value; } 61 } 62 50 63 [StorableConstructor] 51 private IteratedLS(bool deserializing) : base(deserializing) { }52 private IteratedLS(IteratedLSoriginal, Cloner cloner)64 private LAHC(bool deserializing) : base(deserializing) { } 65 private LAHC(LAHC original, Cloner cloner) 53 66 : base(original, cloner) { 67 memorySizeParameter = cloner.Clone(original.memorySizeParameter); 54 68 } 55 public IteratedLS() { 69 public LAHC() { 70 Parameters.Add(memorySizeParameter = new FixedValueParameter<IntValue>("MemorySize", "The size of the memory, the shorter the more greedy LAHC performs.", new IntValue(100))); 56 71 57 72 Problem = new GQAP(); … … 59 74 60 75 public override IDeepCloneable Clone(Cloner cloner) { 61 return new IteratedLS(this, cloner);76 return new LAHC(this, cloner); 62 77 } 63 78 … … 66 81 67 82 Context.Problem = Problem; 68 Context.BestQuality = double.NaN; 69 Context.BestSolution = null; 70 71 var assign = GreedyRandomizedSolutionCreator.CreateSolution(Context.Random, Problem.ProblemInstance, 10, true, token); 83 Context.LastSuccess = 0; 84 85 var assign = new IntegerVector(Problem.ProblemInstance.Demands.Length, Context.Random, 0, Problem.ProblemInstance.Capacities.Length); 72 86 var eval = Problem.ProblemInstance.Evaluate(assign); 73 87 var fit = Problem.ProblemInstance.ToSingleObjective(eval); … … 75 89 76 90 var candidate = new GQAPSolution(assign, eval); 77 var lsevaluations = 0; 78 OneOptLocalSearch.Apply(Context.Random, candidate, Problem.ProblemInstance, out lsevaluations); 79 Context.EvaluatedSolutions += lsevaluations; 80 91 81 92 Context.ReplaceIncumbent(Context.ToScope(candidate, fit)); 82 93 Context.BestQuality = fit; 83 94 Context.BestSolution = (GQAPSolution)candidate.Clone(); 95 96 Context.Memory = new DoubleArray(Enumerable.Repeat(Context.BestQuality, MemorySize).ToArray()); 84 97 85 98 Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); … … 92 105 93 106 protected override void Run(CancellationToken cancellationToken) { 107 var lastUpdate = ExecutionTime; 94 108 while (!StoppingCriterion()) { 95 var lsevaluations = 0; 96 var candidate = (GQAPSolution)Context.Incumbent.Solution.Clone(); 97 RandomWalk(Context.Random, candidate.Assignment, Problem.ProblemInstance.Capacities.Length, candidate.Assignment.Length); 98 candidate.Evaluation = Problem.ProblemInstance.Evaluate(candidate.Assignment); 99 Context.EvaluatedSolutions++; 100 OneOptLocalSearch.Apply(Context.Random, candidate, Problem.ProblemInstance, out lsevaluations); 101 Context.EvaluatedSolutions += lsevaluations; 109 var move = StochasticNMoveSingleMoveGenerator.GenerateOneMove(Context.Random, 110 Context.Incumbent.Solution.Assignment, Problem.ProblemInstance.Capacities); 111 var moveEval = GQAPNMoveEvaluator.Evaluate(move, 112 Context.Incumbent.Solution.Assignment, 113 Context.Incumbent.Solution.Evaluation, Problem.ProblemInstance); 114 if (Context.Iterations % Problem.ProblemInstance.Demands.Length == 0) 115 Context.EvaluatedSolutions++; 116 var nextFit = Problem.ProblemInstance.ToSingleObjective(moveEval); 117 var nextVec = new IntegerVector(Context.Incumbent.Solution.Assignment); 118 NMoveMaker.Apply(nextVec, move); 119 120 var v = Context.Iterations % Context.Memory.Length; 121 Context.Iterations++; 122 var prevFit = Context.Memory[v]; 102 123 103 var candidateFit = Problem.ProblemInstance.ToSingleObjective(candidate.Evaluation); 104 if (candidateFit < Context.Incumbent.Fitness) { 105 Context.ReplaceIncumbent(Context.ToScope(candidate, candidateFit)); 106 Context.BestQuality = candidateFit; 107 Context.BestSolution = (GQAPSolution)candidate.Clone(); 124 var accept = nextFit <= Context.Incumbent.Fitness 125 || nextFit <= prevFit; 126 127 if (accept && nextFit < Context.Incumbent.Fitness) 128 Context.LastSuccess = Context.Iterations; 129 130 if (accept) { 131 Context.ReplaceIncumbent(Context.ToScope(new GQAPSolution(nextVec, moveEval), nextFit)); 132 if (nextFit < Context.BestQuality) { 133 Context.BestSolution = (GQAPSolution)Context.Incumbent.Solution.Clone(); 134 Context.BestQuality = nextFit; 135 } 108 136 } 109 137 138 if (Context.Incumbent.Fitness < prevFit) 139 Context.Memory[v] = Context.Incumbent.Fitness; 140 110 141 IResult result; 111 if (Results.TryGetValue("Iterations", out result)) 112 ((IntValue)result.Value).Value = Context.Iterations; 113 else Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 114 if (Results.TryGetValue("EvaluatedSolutions", out result)) 115 ((IntValue)result.Value).Value = Context.EvaluatedSolutions; 116 else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions))); 142 if (ExecutionTime - lastUpdate > TimeSpan.FromSeconds(1)) { 143 if (Results.TryGetValue("Iterations", out result)) 144 ((IntValue)result.Value).Value = Context.Iterations; 145 else Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 146 if (Results.TryGetValue("EvaluatedSolutions", out result)) 147 ((IntValue)result.Value).Value = Context.EvaluatedSolutions; 148 else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions))); 149 lastUpdate = ExecutionTime; 150 } 117 151 if (Results.TryGetValue("BestQuality", out result)) 118 152 ((DoubleValue)result.Value).Value = Context.BestQuality; … … 123 157 124 158 Context.RunOperator(Analyzer, Context.Scope, cancellationToken); 125 126 Context.Iterations++; 159 127 160 if (cancellationToken.IsCancellationRequested) break; 128 161 } 129 } 130 131 private static void RandomWalk(IRandom random, IntegerVector assignment, int locations, int walkLength) { 132 for (int i = 0; i < walkLength; i++) { 133 var equipment = random.Next(assignment.Length); 134 assignment[equipment] = random.Next(locations); 135 if (random.NextDouble() < 1.0 / walkLength) break; 136 } 162 IResult result2; 163 if (Results.TryGetValue("Iterations", out result2)) 164 ((IntValue)result2.Value).Value = Context.Iterations; 165 else Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 166 if (Results.TryGetValue("EvaluatedSolutions", out result2)) 167 ((IntValue)result2.Value).Value = Context.EvaluatedSolutions; 168 else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions))); 137 169 } 138 170 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/LAHCContext.cs
r15562 r15563 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Parameters; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.L ocalSearch{28 public sealed class L ocalSearchContext : SingleObjectiveSingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {28 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC { 29 public sealed class LAHCContext : SingleObjectiveSingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> { 29 30 [Storable] 30 31 private IValueParameter<GQAP> problem; … … 40 41 set { bestSolution.Value = value; } 41 42 } 43 44 [Storable] 45 private IValueParameter<DoubleArray> memory; 46 public DoubleArray Memory { 47 get { return memory.Value; } 48 set { memory.Value = value; } 49 } 50 51 [Storable] 52 private IValueParameter<IntValue> lastSuccess; 53 public int LastSuccess { 54 get { return lastSuccess.Value.Value; } 55 set { lastSuccess.Value.Value = value; } 56 } 42 57 43 58 [StorableConstructor] 44 private L ocalSearchContext(bool deserializing) : base(deserializing) { }45 private L ocalSearchContext(LocalSearchContext original, Cloner cloner)59 private LAHCContext(bool deserializing) : base(deserializing) { } 60 private LAHCContext(LAHCContext original, Cloner cloner) 46 61 : base(original, cloner) { 47 62 problem = cloner.Clone(original.problem); 48 63 bestSolution = cloner.Clone(original.bestSolution); 64 memory = cloner.Clone(original.memory); 65 lastSuccess = cloner.Clone(original.lastSuccess); 49 66 } 50 public L ocalSearchContext() {67 public LAHCContext() { 51 68 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 52 69 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); 70 Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory")); 71 Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess")); 53 72 } 54 73 55 74 public override IDeepCloneable Clone(Cloner cloner) { 56 return new L ocalSearchContext(this, cloner);75 return new LAHCContext(this, cloner); 57 76 } 58 77 -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/pLAHC.cs
r15562 r15563 27 27 using HeuristicLab.Encodings.IntegerVectorEncoding; 28 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 31 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.L ocalSearch{32 [Item(" Iterated Local Search (GQAP)", "Iterated local searchfor the GQAP.")]32 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC { 33 [Item("pLAHC-s (GQAP)", "Parameterless Late-acceptance hill climber for the GQAP.")] 33 34 [Creatable(CreatableAttribute.Categories.SingleSolutionAlgorithms)] 34 35 [StorableClass] 35 public sealed class IteratedLS : ContextAlgorithm<LocalSearchContext> {36 public sealed class PLAHCS : StochasticAlgorithm<PLAHCContext> { 36 37 37 38 public override bool SupportsPause { … … 48 49 } 49 50 51 [Storable] 52 private FixedValueParameter<IntValue> maximumExponentParameter; 53 public IFixedValueParameter<IntValue> MaximumExponentParameter { 54 get { return maximumExponentParameter; } 55 } 56 57 [Storable] 58 private FixedValueParameter<IntValue> minimumSprintIterationsParameter; 59 public IFixedValueParameter<IntValue> MinimumSprintIterationsParameter { 60 get { return minimumSprintIterationsParameter; } 61 } 62 63 public int MaximumExponent { 64 get { return maximumExponentParameter.Value.Value; } 65 set { maximumExponentParameter.Value.Value = value; } 66 } 67 68 public int MinimumSprintIterations { 69 get { return minimumSprintIterationsParameter.Value.Value; } 70 set { minimumSprintIterationsParameter.Value.Value = value; } 71 } 72 50 73 [StorableConstructor] 51 private IteratedLS(bool deserializing) : base(deserializing) { }52 private IteratedLS(IteratedLS original, Cloner cloner)74 private PLAHCS(bool deserializing) : base(deserializing) { } 75 private PLAHCS(PLAHCS original, Cloner cloner) 53 76 : base(original, cloner) { 54 } 55 public IteratedLS() { 77 maximumExponentParameter = cloner.Clone(original.maximumExponentParameter); 78 minimumSprintIterationsParameter = cloner.Clone(original.minimumSprintIterationsParameter); 79 } 80 public PLAHCS() { 81 Parameters.Add(maximumExponentParameter = new FixedValueParameter<IntValue>("MaximumExponent", "The maximum power to which memory sizes should be tried (2^x). Do not set higher than 31", new IntValue(24))); 82 Parameters.Add(minimumSprintIterationsParameter = new FixedValueParameter<IntValue>("MinimumSprintIterations", "The minimum amount of iterations per sprint.", new IntValue(100000))); 56 83 57 84 Problem = new GQAP(); … … 59 86 60 87 public override IDeepCloneable Clone(Cloner cloner) { 61 return new IteratedLS(this, cloner);88 return new PLAHCS(this, cloner); 62 89 } 63 90 … … 66 93 67 94 Context.Problem = Problem; 68 Context.BestQuality = double.NaN; 69 Context.BestSolution = null; 70 71 var assign = GreedyRandomizedSolutionCreator.CreateSolution(Context.Random, Problem.ProblemInstance, 10, true, token); 95 Context.LastSuccess = 0; 96 97 var assign = new IntegerVector(Problem.ProblemInstance.Demands.Length, Context.Random, 0, Problem.ProblemInstance.Capacities.Length); 72 98 var eval = Problem.ProblemInstance.Evaluate(assign); 73 99 var fit = Problem.ProblemInstance.ToSingleObjective(eval); … … 75 101 76 102 var candidate = new GQAPSolution(assign, eval); 77 var lsevaluations = 0;78 OneOptLocalSearch.Apply(Context.Random, candidate, Problem.ProblemInstance, out lsevaluations);79 Context.EvaluatedSolutions += lsevaluations;80 103 81 104 Context.ReplaceIncumbent(Context.ToScope(candidate, fit)); … … 83 106 Context.BestSolution = (GQAPSolution)candidate.Clone(); 84 107 108 Context.BestList = new ItemList<DoubleValue>(new[] { new DoubleValue(Context.BestQuality) }); 109 110 Results.Add(new Result("Sprint Iterations", new IntValue(Context.SprintIterations))); 85 111 Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 86 112 Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions))); 87 Results.Add(new Result("BestQuality", new DoubleValue(Context.BestQuality))); 88 Results.Add(new Result("BestSolution", Context.BestSolution)); 89 90 Context.RunOperator(Analyzer, Context.Scope, token); 113 Results.Add(new Result("CurrentMemorySize", new IntValue(0))); 91 114 } 92 115 93 116 protected override void Run(CancellationToken cancellationToken) { 94 while (!StoppingCriterion()) { 95 var lsevaluations = 0; 96 var candidate = (GQAPSolution)Context.Incumbent.Solution.Clone(); 97 RandomWalk(Context.Random, candidate.Assignment, Problem.ProblemInstance.Capacities.Length, candidate.Assignment.Length); 98 candidate.Evaluation = Problem.ProblemInstance.Evaluate(candidate.Assignment); 99 Context.EvaluatedSolutions++; 100 OneOptLocalSearch.Apply(Context.Random, candidate, Problem.ProblemInstance, out lsevaluations); 101 Context.EvaluatedSolutions += lsevaluations; 102 103 var candidateFit = Problem.ProblemInstance.ToSingleObjective(candidate.Evaluation); 104 if (candidateFit < Context.Incumbent.Fitness) { 105 Context.ReplaceIncumbent(Context.ToScope(candidate, candidateFit)); 106 Context.BestQuality = candidateFit; 107 Context.BestSolution = (GQAPSolution)candidate.Clone(); 117 var lastUpdate = ExecutionTime; 118 for (var i = 0; i <= MaximumExponent; i++) { 119 var l = (int)Math.Pow(2, i); 120 var memory = new double[l]; 121 for (var vv = 0; vv < l; vv++) 122 memory[vv] = Context.BestList[Context.BestList.Count - 1 - (vv % Context.BestList.Count)].Value; 123 Array.Sort(memory); 124 Context.Memory = new DoubleArray(memory); 125 if (i > 0) Context.ReplaceIncumbent(Context.ToScope((GQAPSolution)Context.BestSolution.Clone(), Context.BestQuality)); 126 IResult memorySizeResult; 127 if (Results.TryGetValue("CurrentMemorySize", out memorySizeResult)) 128 ((IntValue)memorySizeResult.Value).Value = Context.Memory.Length; 129 else Results.Add(new Result("CurrentMemorySize", new IntValue(Context.Memory.Length))); 130 131 Context.SprintIterations = 0; 132 while (!StoppingCriterion() 133 && (Context.SprintIterations < MinimumSprintIterations 134 || (Context.SprintIterations - Context.LastSuccess) < Context.SprintIterations * 0.02)) { 135 136 var move = StochasticNMoveSingleMoveGenerator.GenerateOneMove(Context.Random, 137 Context.Incumbent.Solution.Assignment, Problem.ProblemInstance.Capacities); 138 var moveEval = GQAPNMoveEvaluator.Evaluate(move, 139 Context.Incumbent.Solution.Assignment, 140 Context.Incumbent.Solution.Evaluation, Problem.ProblemInstance); 141 if (Context.SprintIterations % Problem.ProblemInstance.Demands.Length == 0) 142 Context.EvaluatedSolutions++; 143 var nextFit = Problem.ProblemInstance.ToSingleObjective(moveEval); 144 var nextVec = new IntegerVector(Context.Incumbent.Solution.Assignment); 145 NMoveMaker.Apply(nextVec, move); 146 147 var v = Context.Iterations % Context.Memory.Length; 148 Context.Iterations++; 149 Context.SprintIterations++; 150 var prevFit = Context.Memory[v]; 151 152 var accept = nextFit <= Context.Incumbent.Fitness 153 || nextFit <= prevFit; 154 155 if (accept && nextFit < Context.Incumbent.Fitness) 156 Context.LastSuccess = Context.SprintIterations; 157 158 if (accept) { 159 Context.ReplaceIncumbent(Context.ToScope(new GQAPSolution(nextVec, moveEval), nextFit)); 160 if (nextFit < Context.BestQuality) { 161 Context.BestSolution = (GQAPSolution)Context.Incumbent.Solution.Clone(); 162 Context.BestQuality = nextFit; 163 Context.BestList.Add(new DoubleValue(Context.BestQuality)); 164 } 165 } 166 167 if (Context.Incumbent.Fitness < prevFit) 168 Context.Memory[v] = Context.Incumbent.Fitness; 169 170 IResult result; 171 if (ExecutionTime - lastUpdate > TimeSpan.FromSeconds(1)) { 172 if (Results.TryGetValue("Iterations", out result)) 173 ((IntValue)result.Value).Value = Context.Iterations; 174 else Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 175 if (Results.TryGetValue("Sprint Iterations", out result)) 176 ((IntValue)result.Value).Value = Context.SprintIterations; 177 else Results.Add(new Result("Total Iterations", new IntValue(Context.SprintIterations))); 178 if (Results.TryGetValue("EvaluatedSolutions", out result)) 179 ((IntValue)result.Value).Value = Context.EvaluatedSolutions; 180 else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions))); 181 lastUpdate = ExecutionTime; 182 } 183 if (Results.TryGetValue("BestQuality", out result)) 184 ((DoubleValue)result.Value).Value = Context.BestQuality; 185 else Results.Add(new Result("BestQuality", new DoubleValue(Context.BestQuality))); 186 if (Results.TryGetValue("BestSolution", out result)) 187 result.Value = Context.BestSolution; 188 else Results.Add(new Result("BestSolution", Context.BestSolution)); 189 Context.RunOperator(Analyzer, Context.Scope, cancellationToken); 190 191 if (cancellationToken.IsCancellationRequested) break; 108 192 } 109 110 IResult result; 111 if (Results.TryGetValue("Iterations", out result)) 112 ((IntValue)result.Value).Value = Context.Iterations; 113 else Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 114 if (Results.TryGetValue("EvaluatedSolutions", out result)) 115 ((IntValue)result.Value).Value = Context.EvaluatedSolutions; 116 else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions))); 117 if (Results.TryGetValue("BestQuality", out result)) 118 ((DoubleValue)result.Value).Value = Context.BestQuality; 119 else Results.Add(new Result("BestQuality", new DoubleValue(Context.BestQuality))); 120 if (Results.TryGetValue("BestSolution", out result)) 121 result.Value = Context.BestSolution; 122 else Results.Add(new Result("BestSolution", Context.BestSolution)); 123 124 Context.RunOperator(Analyzer, Context.Scope, cancellationToken); 125 126 Context.Iterations++; 127 if (cancellationToken.IsCancellationRequested) break; 193 if (StoppingCriterion() || cancellationToken.IsCancellationRequested) break; 128 194 } 129 } 130 131 private static void RandomWalk(IRandom random, IntegerVector assignment, int locations, int walkLength) { 132 for (int i = 0; i < walkLength; i++) { 133 var equipment = random.Next(assignment.Length); 134 assignment[equipment] = random.Next(locations); 135 if (random.NextDouble() < 1.0 / walkLength) break; 136 } 195 196 IResult result2; 197 if (Results.TryGetValue("Iterations", out result2)) 198 ((IntValue)result2.Value).Value = Context.Iterations; 199 else Results.Add(new Result("Iterations", new IntValue(Context.Iterations))); 200 if (Results.TryGetValue("Sprint Iterations", out result2)) 201 ((IntValue)result2.Value).Value = Context.SprintIterations; 202 else Results.Add(new Result("Sprint Iterations", new IntValue(Context.SprintIterations))); 203 if (Results.TryGetValue("EvaluatedSolutions", out result2)) 204 ((IntValue)result2.Value).Value = Context.EvaluatedSolutions; 205 else Results.Add(new Result("EvaluatedSolutions", new IntValue(Context.EvaluatedSolutions))); 137 206 } 138 207 } -
branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/pLAHCContext.cs
r15562 r15563 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Parameters; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.L ocalSearch{28 public sealed class LocalSearchContext : SingleObjectiveSingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> {28 namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms.LAHC { 29 public sealed class PLAHCContext : SingleObjectiveSingleSolutionContext<ISingleObjectiveSolutionScope<GQAPSolution>> { 29 30 [Storable] 30 31 private IValueParameter<GQAP> problem; … … 40 41 set { bestSolution.Value = value; } 41 42 } 43 44 [Storable] 45 private IValueParameter<IntValue> sprintIterations; 46 public int SprintIterations { 47 get { return sprintIterations.Value.Value; } 48 set { sprintIterations.Value.Value = value; } 49 } 50 51 [Storable] 52 private IValueParameter<DoubleArray> memory; 53 public DoubleArray Memory { 54 get { return memory.Value; } 55 set { memory.Value = value; } 56 } 57 58 [Storable] 59 private IValueParameter<IntValue> lastSuccess; 60 public int LastSuccess { 61 get { return lastSuccess.Value.Value; } 62 set { lastSuccess.Value.Value = value; } 63 } 64 65 [Storable] 66 private IValueParameter<ItemList<DoubleValue>> bestList; 67 public ItemList<DoubleValue> BestList { 68 get { return bestList.Value; } 69 set { bestList.Value = value; } 70 } 42 71 43 72 [StorableConstructor] 44 private LocalSearchContext(bool deserializing) : base(deserializing) { }45 private LocalSearchContext(LocalSearchContext original, Cloner cloner)73 private PLAHCContext(bool deserializing) : base(deserializing) { } 74 private PLAHCContext(PLAHCContext original, Cloner cloner) 46 75 : base(original, cloner) { 47 76 problem = cloner.Clone(original.problem); 48 77 bestSolution = cloner.Clone(original.bestSolution); 78 sprintIterations = cloner.Clone(original.sprintIterations); 79 memory = cloner.Clone(original.memory); 80 lastSuccess = cloner.Clone(original.lastSuccess); 81 bestList = cloner.Clone(original.bestList); 49 82 } 50 public LocalSearchContext() {83 public PLAHCContext() { 51 84 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 52 85 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); 86 Parameters.Add(sprintIterations = new ValueParameter<IntValue>("SprintIterations")); 87 Parameters.Add(memory = new ValueParameter<DoubleArray>("Memory")); 88 Parameters.Add(lastSuccess = new ValueParameter<IntValue>("LastSuccess")); 89 Parameters.Add(bestList = new ValueParameter<ItemList<DoubleValue>>("BestList")); 53 90 } 54 91 55 92 public override IDeepCloneable Clone(Cloner cloner) { 56 return new LocalSearchContext(this, cloner);93 return new PLAHCContext(this, cloner); 57 94 } 58 95
Note: See TracChangeset
for help on using the changeset viewer.