- Timestamp:
- 01/31/18 18:14:33 (7 years ago)
- Location:
- branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/CPLEX/CplexSolver.cs
r15698 r15700 22 22 using System; 23 23 using System.Threading; 24 using HeuristicLab.Analysis;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 28 27 using HeuristicLab.Encodings.IntegerVectorEncoding; 29 28 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters;31 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 30 using ILOG.CPLEX; … … 50 48 } 51 49 52 [Storable]53 private ValueParameter<DateTimeValue> lastUpdateTimeParameter;54 public IValueParameter<DateTimeValue> LastUpdateTimeParameter {55 get { return lastUpdateTimeParameter; }56 }57 58 50 [StorableConstructor] 59 51 protected CplexSolver(bool deserializing) : base(deserializing) { } 60 52 protected CplexSolver(CplexSolver original, Cloner cloner) 61 53 : base(original, cloner) { 62 lastUpdateTimeParameter = cloner.Clone(original.lastUpdateTimeParameter);63 54 } 64 55 public CplexSolver() { 65 56 Problem = new GQAP(); 66 Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime", "") { Hidden = true });67 var qpc = new QualityPerClockAnalyzer();68 qpc.LastUpdateTimeParameter.ActualName = LastUpdateTimeParameter.Name;69 ((MultiAnalyzer)Analyzer).AddOperator(qpc);70 57 } 71 58 72 59 protected override void Run(CancellationToken cancellationToken) { 60 base.Run(cancellationToken); 73 61 var factory = new OplFactory(); 74 62 var cplex = factory.CreateCplex(); … … 80 68 opl.AddDataSource(dataSource); 81 69 opl.Generate(); 82 LastUpdateTimeParameter.Value = new DateTimeValue(DateTime.UtcNow);83 70 cplex.Solve(); 84 71 cplex.End(); -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary/EvolutionStrategy.cs
r15574 r15700 118 118 119 119 Context.NormalRand = new NormalDistributedRandom(Context.Random, 0, 1); 120 Context.Problem = Problem; 121 Context.BestQuality = double.NaN; 120 Context.Problem = Problem; 122 121 Context.BestSolution = null; 123 122 … … 149 148 150 149 protected override void Run(CancellationToken cancellationToken) { 150 base.Run(cancellationToken); 151 151 var lastUpdate = ExecutionTime; 152 152 var eq = new IntegerVectorEqualityComparer(); -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Evolutionary/OSGA.cs
r15574 r15700 92 92 93 93 Context.Problem = Problem; 94 Context.BestQuality = double.NaN;95 94 Context.BestSolution = null; 96 95 … … 122 121 123 122 protected override void Run(CancellationToken cancellationToken) { 123 base.Run(cancellationToken); 124 124 var lastUpdate = ExecutionTime; 125 125 -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASP/GRASP.cs
r15616 r15700 153 153 base.Initialize(cancellationToken); 154 154 155 Context.Problem = Problem; 156 Context.BestQuality = double.NaN; 155 Context.Problem = Problem; 157 156 Context.BestSolution = null; 158 157 … … 164 163 165 164 protected override void Run(CancellationToken cancellationToken) { 165 base.Run(cancellationToken); 166 166 var eq = new IntegerVectorEqualityComparer(); 167 167 var lastUpdate = ExecutionTime; -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Algorithms/ContextAlgorithm.cs
r15574 r15700 21 21 22 22 using System; 23 using System.Diagnostics; 24 using System.Linq; 23 25 using System.Threading; 24 26 using HeuristicLab.Analysis; … … 98 100 set { stopAtBestKnownQualityParameter.Value.Value = value; } 99 101 } 102 103 private Stopwatch stopwatch; 104 [Storable] 105 private TimeSpan elapsed; 106 [Storable] 107 private IndexedDataTable<double> qualityPerClock; 108 [Storable] 109 private IndexedDataRow<double> firstHitGraph; 100 110 101 111 [StorableConstructor] … … 109 119 maximumRuntimeParameter = cloner.Clone(original.maximumRuntimeParameter); 110 120 stopAtBestKnownQualityParameter = cloner.Clone(original.stopAtBestKnownQualityParameter); 121 elapsed = original.elapsed; 122 qualityPerClock = cloner.Clone(original.qualityPerClock); 123 firstHitGraph = cloner.Clone(original.firstHitGraph); 124 if (context != null) 125 context.BestQualityChanged += ContextOnBestQualityChanged; 111 126 } 112 127 protected ContextAlgorithm() … … 123 138 context = new TContext(); 124 139 context.Scope.Variables.Add(new Variable("Results", Results)); 140 context.BestQualityChanged += ContextOnBestQualityChanged; 125 141 126 142 IExecutionContext ctxt = null; … … 133 149 context.EvaluatedSolutions = 0; 134 150 context.BestQuality = double.NaN; 151 152 qualityPerClock = new IndexedDataTable<double>("Quality Per Clock"); 153 firstHitGraph = new IndexedDataRow<double>("First-hit Graph"); 154 qualityPerClock.Rows.Add(firstHitGraph); 155 Results.Add(new Result("QualityPerClock", qualityPerClock)); 156 157 elapsed = TimeSpan.Zero; 158 stopwatch = Stopwatch.StartNew(); 159 } 160 161 protected override void Run(CancellationToken cancellationToken) { 162 if (stopwatch == null || !stopwatch.IsRunning) stopwatch = Stopwatch.StartNew(); 163 } 164 165 private void ContextOnBestQualityChanged(object sender, EventArgs e) { 166 if (double.IsNaN(Context.BestQuality)) return; 167 var newEntry = Tuple.Create((elapsed + stopwatch.Elapsed).TotalSeconds, Context.BestQuality); 168 169 if (firstHitGraph.Values.Count == 0) { 170 firstHitGraph.Values.Add(newEntry); // record the first data 171 firstHitGraph.Values.Add(Tuple.Create(newEntry.Item1, newEntry.Item2)); // last entry records max number of evaluations 172 return; 173 } 174 175 var improvement = firstHitGraph.Values.Last().Item2 != newEntry.Item2; 176 if (improvement) { 177 firstHitGraph.Values[firstHitGraph.Values.Count - 1] = newEntry; // record the improvement 178 firstHitGraph.Values.Add(Tuple.Create(newEntry.Item1, newEntry.Item2)); // last entry records max number of evaluations 179 } else { 180 firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(newEntry.Item1, newEntry.Item2); 181 } 135 182 } 136 183 137 184 public override void Prepare() { 138 context = null; 185 if (context != null) { 186 context.BestQualityChanged -= ContextOnBestQualityChanged; 187 context = null; 188 } 139 189 base.Prepare(); 190 } 191 192 protected override void OnPaused() { 193 base.OnPaused(); 194 elapsed += stopwatch.Elapsed; 195 stopwatch.Reset(); 196 firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(elapsed.TotalSeconds, Context.BestQuality); 197 } 198 199 protected override void OnStopped() { 200 base.OnStopped(); 201 if (stopwatch.IsRunning) { 202 elapsed += stopwatch.Elapsed; 203 stopwatch.Reset(); 204 firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(elapsed.TotalSeconds, Context.BestQuality); 205 } 206 } 207 208 [StorableHook(HookType.AfterDeserialization)] 209 private void AfterDeserialization() { 210 if (context != null) context.BestQualityChanged += ContextOnBestQualityChanged; 140 211 } 141 212 -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Contexts/BasicContext.cs
r15616 r15700 69 69 public double BestQuality { 70 70 get { return bestQuality.Value.Value; } 71 set { bestQuality.Value.Value = value; } 71 set { 72 if (bestQuality.Value.Value == value) return; 73 bestQuality.Value.Value = value; 74 OnBestQualityChanged(); 75 } 72 76 } 73 77 … … 142 146 } 143 147 148 public event EventHandler BestQualityChanged; 149 private void OnBestQualityChanged() { 150 BestQualityChanged?.Invoke(this, EventArgs.Empty); 151 } 152 144 153 #region IExecutionContext members 145 154 IAtomicOperation IExecutionContext.CreateOperation(IOperator op) { -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Interfaces.cs
r15572 r15700 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Core; 23 24 … … 33 34 int EvaluatedSolutions { get; set; } 34 35 double BestQuality { get; set; } 36 37 event EventHandler BestQualityChanged; 35 38 } 36 39 -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/LAHC.cs
r15574 r15700 107 107 108 108 protected override void Run(CancellationToken cancellationToken) { 109 base.Run(cancellationToken); 109 110 var lastUpdate = ExecutionTime; 110 111 while (!StoppingCriterion()) { -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LAHC/pLAHC.cs
r15574 r15700 119 119 120 120 protected override void Run(CancellationToken cancellationToken) { 121 base.Run(cancellationToken); 121 122 var lastUpdate = ExecutionTime; 122 123 for (var i = 0; i <= MaximumExponent; i++) { -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSearch/IteratedLS.cs
r15629 r15700 80 80 81 81 Context.Problem = Problem; 82 Context.BestQuality = double.NaN;83 82 Context.BestSolution = null; 84 83 … … 108 107 109 108 protected override void Run(CancellationToken cancellationToken) { 109 base.Run(cancellationToken); 110 110 var lastUpdate = ExecutionTime; 111 111 -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSearch/MultistartLS.cs
r15574 r15700 66 66 67 67 Context.Problem = Problem; 68 Context.BestQuality = double.NaN;69 68 Context.BestSolution = null; 70 69 } 71 70 72 71 protected override void Run(CancellationToken cancellationToken) { 72 base.Run(cancellationToken); 73 73 var lastUpdate = ExecutionTime; 74 74 -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSolverNet/GQAPBinarySolver.cs
r15698 r15700 21 21 22 22 using System; 23 using System.Linq;24 23 using System.Threading; 25 using HeuristicLab.Analysis;26 24 using HeuristicLab.Common; 27 25 using HeuristicLab.Core; … … 63 61 } 64 62 public GQAPBinarySolver() { 63 Problem = new GQAP(); 64 MaximumEvaluationsParameter.Hidden = true; 65 MaximumIterationsParameter.Hidden = true; 65 66 } 66 67 … … 117 118 118 119 Context.RunOperator(Analyzer, CancellationToken.None); 120 121 if (StoppingCriterion()) localSolver.Stop(); 119 122 } 120 123 … … 126 129 127 130 protected override void Run(CancellationToken cancellationToken) { 128 var qpc = ((MultiAnalyzer)Analyzer).Operators.OfType<QualityPerClockAnalyzer>().FirstOrDefault(); 129 if (qpc != null) { 130 qpc.LastUpdateTimeParameter.ActualName = Context.LastUpdateTimeParameter.Name; 131 } 131 base.Run(cancellationToken); 132 132 token = cancellationToken; 133 133 lastUpdate = DateTime.UtcNow.AddSeconds(-1); … … 211 211 localSolver.AddCallback(LSCallbackType.IterationTicked, LocalSolverOnIterationTicked); 212 212 213 Context.LastUpdateTimeParameter.Value = new DateTimeValue(DateTime.UtcNow);214 215 213 localSolver.Solve(); 216 214 -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSolverNet/GQAPIntegerSolver.cs
r15698 r15700 21 21 22 22 using System; 23 using System.Linq;24 23 using System.Threading; 25 using HeuristicLab.Analysis;26 24 using HeuristicLab.Common; 27 25 using HeuristicLab.Core; … … 62 60 } 63 61 public GQAPIntegerSolver() { 62 Problem = new GQAP(); 63 MaximumEvaluationsParameter.Hidden = true; 64 MaximumIterationsParameter.Hidden = true; 64 65 } 65 66 … … 111 112 112 113 Context.RunOperator(Analyzer, CancellationToken.None); 114 115 if (StoppingCriterion()) localSolver.Stop(); 113 116 } 114 117 … … 120 123 121 124 protected override void Run(CancellationToken cancellationToken) { 122 var qpc = ((MultiAnalyzer)Analyzer).Operators.OfType<QualityPerClockAnalyzer>().FirstOrDefault(); 123 if (qpc != null) { 124 qpc.LastUpdateTimeParameter.ActualName = Context.LastUpdateTimeParameter.Name; 125 } 125 base.Run(cancellationToken); 126 126 token = cancellationToken; 127 127 lastUpdate = DateTime.UtcNow.AddSeconds(-1); … … 183 183 localSolver.AddCallback(LSCallbackType.IterationTicked, LocalSolverOnIterationTicked); 184 184 185 Context.LastUpdateTimeParameter.Value = new DateTimeValue(DateTime.UtcNow);186 187 185 localSolver.Solve(); 188 186 } finally { -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/LocalSolverNet/LocalSolverContext.cs
r15698 r15700 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Parameters; 26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 45 44 } 46 45 47 [Storable]48 private ValueParameter<DateTimeValue> lastUpdateTimeParameter;49 public IValueParameter<DateTimeValue> LastUpdateTimeParameter {50 get { return lastUpdateTimeParameter; }51 }52 53 46 [StorableConstructor] 54 47 protected LocalSolverContext(bool deserializing) : base(deserializing) { } … … 57 50 problem = cloner.Clone(original.problem); 58 51 bestSolution = cloner.Clone(original.bestSolution); 59 lastUpdateTimeParameter = cloner.Clone(original.lastUpdateTimeParameter);60 52 } 61 53 public LocalSolverContext() : base() { 62 54 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 63 55 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); 64 Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));65 56 } 66 57 public LocalSolverContext(string name) : base(name) { 67 58 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 68 59 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); 69 Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));70 60 } 71 61 public LocalSolverContext(string name, ParameterCollection parameters) : base(name, parameters) { 72 62 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 73 63 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); 74 Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));75 64 } 76 65 public LocalSolverContext(string name, string description) : base(name, description) { 77 66 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 78 67 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); 79 Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));80 68 } 81 69 public LocalSolverContext(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { 82 70 Parameters.Add(problem = new ValueParameter<GQAP>("Problem")); 83 71 Parameters.Add(bestSolution = new ValueParameter<GQAPSolution>("BestFoundSolution")); 84 Parameters.Add(lastUpdateTimeParameter = new ValueParameter<DateTimeValue>("LastUpdateTime"));85 72 } 86 73 -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/RandomSearch/RandomSearch.cs
r15698 r15700 54 54 } 55 55 public RandomSearch() { 56 57 56 Problem = new GQAP(); 58 57 } … … 66 65 67 66 Context.Problem = Problem; 68 Context.BestQuality = double.NaN;69 67 Context.BestSolution = null; 70 68 } 71 69 72 70 protected override void Run(CancellationToken cancellationToken) { 71 base.Run(cancellationToken); 73 72 var lastUpdate = ExecutionTime; 74 73
Note: See TracChangeset
for help on using the changeset viewer.