Changeset 15721 for branches/1614_GeneralizedQAP
- Timestamp:
- 02/04/18 22:33:26 (7 years ago)
- Location:
- branches/1614_GeneralizedQAP
- Files:
-
- 12 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/1614_GeneralizedQAP/GeneralizedQAP.sln
r15719 r15721 29 29 EndProject 30 30 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Analysis.Views-3.3", "HeuristicLab.Analysis.Views\3.3\HeuristicLab.Analysis.Views-3.3.csproj", "{76945D76-CA61-4147-9DC2-0ACDCDDF87F9}" 31 EndProject 32 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.OptimizationExpertSystem.Common-3.3", "HeuristicLab.OptimizationExpertSystem.Common\3.3\HeuristicLab.OptimizationExpertSystem.Common-3.3.csproj", "{492CC257-E27C-4497-B2C1-09C45310C91C}" 33 EndProject 34 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.OptimizationExpertSystem-3.3", "HeuristicLab.OptimizationExpertSystem\3.3\HeuristicLab.OptimizationExpertSystem-3.3.csproj", "{6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}" 31 35 EndProject 32 36 Global … … 196 200 {76945D76-CA61-4147-9DC2-0ACDCDDF87F9}.Release|x86.ActiveCfg = Release|x86 197 201 {76945D76-CA61-4147-9DC2-0ACDCDDF87F9}.Release|x86.Build.0 = Release|x86 202 {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 203 {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|Any CPU.Build.0 = Debug|Any CPU 204 {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x64.ActiveCfg = Debug|x64 205 {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x64.Build.0 = Debug|x64 206 {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x86.ActiveCfg = Debug|x86 207 {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x86.Build.0 = Debug|x86 208 {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|Any CPU.ActiveCfg = Release|Any CPU 209 {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|Any CPU.Build.0 = Release|Any CPU 210 {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x64.ActiveCfg = Release|x64 211 {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x64.Build.0 = Release|x64 212 {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x86.ActiveCfg = Release|x86 213 {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x86.Build.0 = Release|x86 214 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 215 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|Any CPU.Build.0 = Debug|Any CPU 216 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x64.ActiveCfg = Debug|x64 217 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x64.Build.0 = Debug|x64 218 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x86.ActiveCfg = Debug|x86 219 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x86.Build.0 = Debug|x86 220 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|Any CPU.ActiveCfg = Release|Any CPU 221 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|Any CPU.Build.0 = Release|Any CPU 222 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x64.ActiveCfg = Release|x64 223 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x64.Build.0 = Release|x64 224 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x86.ActiveCfg = Release|x86 225 {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x86.Build.0 = Release|x86 198 226 EndGlobalSection 199 227 GlobalSection(SolutionProperties) = preSolution -
branches/1614_GeneralizedQAP/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj
r15720 r15721 147 147 <Reference Include="HeuristicLab.PluginInfrastructure-3.3"> 148 148 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath> 149 <Private>False</Private> 150 </Reference> 151 <Reference Include="HeuristicLab.Random-3.3"> 152 <SpecificVersion>False</SpecificVersion> 153 <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Random-3.3.dll</HintPath> 149 154 <Private>False</Private> 150 155 </Reference> -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/IOptimizerView.Designer.cs
r15605 r15721 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.components = new System.ComponentModel.Container();48 47 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(IOptimizerView)); 49 48 this.startButton = new System.Windows.Forms.Button(); … … 53 52 this.stopButton = new System.Windows.Forms.Button(); 54 53 this.resetButton = new System.Windows.Forms.Button(); 55 this.executionTimer = new System.Windows.Forms.Timer(this.components);56 54 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 57 55 this.SuspendLayout(); … … 134 132 this.resetButton.Click += new System.EventHandler(this.resetButton_Click); 135 133 // 136 // executionTimer137 //138 this.executionTimer.Interval = 200;139 this.executionTimer.Tick += new System.EventHandler(this.executionTimer_Tick);140 //141 134 // IOptimizerView 142 135 // … … 173 166 protected System.Windows.Forms.Button pauseButton; 174 167 protected System.Windows.Forms.Button stopButton; 175 protected System.Windows.Forms.Timer executionTimer;176 168 protected System.Windows.Forms.Button resetButton; 177 169 -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/IOptimizerView.cs
r15605 r15721 44 44 Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); 45 45 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); 46 Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged); 46 47 Content.Prepared -= new EventHandler(Content_Prepared); 47 48 Content.Started -= new EventHandler(Content_Started); … … 54 55 Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); 55 56 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); 57 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); 56 58 Content.Prepared += new EventHandler(Content_Prepared); 57 59 Content.Started += new EventHandler(Content_Started); … … 62 64 protected override void OnContentChanged() { 63 65 base.OnContentChanged(); 64 if (Content != null) { 66 if (Content == null) { 67 executionTimeTextBox.Text = "-"; 68 } else { 65 69 Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started; 70 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 66 71 } 67 UpdateExecutionTime();68 72 } 69 73 … … 86 90 else { 87 91 nameTextBox.Enabled = infoLabel.Enabled = true; 88 UpdateExecutionTime();89 92 ReadOnly = Locked = false; 90 93 SetEnabledStateOfExecutableButtons(); … … 95 98 Invoke(new EventHandler(Content_Started), sender, e); 96 99 else { 97 executionTimer.Start();98 100 nameTextBox.Enabled = infoLabel.Enabled = false; 99 101 ReadOnly = Locked = true; … … 105 107 Invoke(new EventHandler(Content_Paused), sender, e); 106 108 else { 107 executionTimer.Stop();108 UpdateExecutionTime();109 109 nameTextBox.Enabled = infoLabel.Enabled = true; 110 110 ReadOnly = Locked = false; … … 116 116 Invoke(new EventHandler(Content_Stopped), sender, e); 117 117 else { 118 executionTimer.Stop();119 UpdateExecutionTime();120 118 nameTextBox.Enabled = infoLabel.Enabled = true; 121 119 ReadOnly = Locked = false; … … 123 121 } 124 122 } 123 protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) { 124 if (InvokeRequired) 125 Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e); 126 else 127 executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString(); 128 } 125 129 protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) { 126 130 if (InvokeRequired) 127 131 Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e); 128 else { 129 executionTimer.Stop(); 130 UpdateExecutionTime(); 132 else 131 133 ErrorHandling.ShowErrorDialog(this, e.Value); 132 }133 134 } 134 135 #endregion … … 146 147 protected virtual void resetButton_Click(object sender, EventArgs e) { 147 148 Content.Prepare(false); 148 }149 private void executionTimer_Tick(object sender, EventArgs e) {150 UpdateExecutionTime();151 }152 153 private void UpdateExecutionTime() {154 executionTimeTextBox.Text = (Content == null ? "-" : Content.ExecutionTime.ToString());155 149 } 156 150 #endregion -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs
r15719 r15721 64 64 } 65 65 } 66 67 public abstract TimeSpan ExecutionTime { get; } 66 67 [Storable] 68 private TimeSpan executionTime; 69 public TimeSpan ExecutionTime { 70 get { return executionTime; } 71 protected set { 72 executionTime = value; 73 OnExecutionTimeChanged(); 74 } 75 } 68 76 69 77 public virtual Type ProblemType { … … 125 133 : base() { 126 134 executionState = ExecutionState.Stopped; 135 executionTime = TimeSpan.Zero; 127 136 storeAlgorithmInEachRun = false; 128 137 runsCounter = 0; … … 132 141 : base(name) { 133 142 executionState = ExecutionState.Stopped; 143 executionTime = TimeSpan.Zero; 134 144 storeAlgorithmInEachRun = false; 135 145 runsCounter = 0; … … 139 149 : base(name, parameters) { 140 150 executionState = ExecutionState.Stopped; 151 executionTime = TimeSpan.Zero; 141 152 storeAlgorithmInEachRun = false; 142 153 runsCounter = 0; … … 146 157 : base(name, description) { 147 158 executionState = ExecutionState.Stopped; 159 executionTime = TimeSpan.Zero; 148 160 storeAlgorithmInEachRun = false; 149 161 runsCounter = 0; … … 153 165 : base(name, description, parameters) { 154 166 executionState = ExecutionState.Stopped; 167 executionTime = TimeSpan.Zero; 155 168 storeAlgorithmInEachRun = false; 156 169 runsCounter = 0; … … 168 181 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 169 182 executionState = original.executionState; 183 executionTime = original.executionTime; 170 184 problem = cloner.Clone(original.problem); 171 185 storeAlgorithmInEachRun = original.storeAlgorithmInEachRun; … … 246 260 if (handler != null) handler(this, EventArgs.Empty); 247 261 } 262 public event EventHandler ExecutionTimeChanged; 263 protected virtual void OnExecutionTimeChanged() { 264 EventHandler handler = ExecutionTimeChanged; 265 if (handler != null) handler(this, EventArgs.Empty); 266 } 248 267 public event EventHandler ProblemChanged; 249 268 protected virtual void OnProblemChanged() { … … 258 277 public event EventHandler Prepared; 259 278 protected virtual void OnPrepared() { 279 ExecutionTime = TimeSpan.Zero; 260 280 foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet<object>() { Runs }).OfType<IStatefulItem>()) { 261 281 statefulObject.InitializeState(); … … 328 348 } 329 349 #endregion 330 331 [Obsolete("Deprecate, does nothing, needs to be removed from IExecutable")]332 public event EventHandler ExecutionTimeChanged;333 350 } 334 351 } -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs
r15605 r15721 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Threading; 24 25 using HeuristicLab.Common; … … 31 32 32 33 private bool pausePending; 33 private bool executionTimeActive;34 private DateTime lastUpdateTime; 34 35 35 36 public string Filename { get; set; } … … 51 52 } 52 53 53 [Storable]54 private TimeSpan executionTime;55 private DateTime startDate;56 public override TimeSpan ExecutionTime {57 get { return executionTime + (executionTimeActive ? DateTime.UtcNow - startDate : TimeSpan.Zero); }58 }59 60 54 [StorableConstructor] 61 55 protected BasicAlgorithm(bool deserializing) : base(deserializing) { } … … 64 58 results = cloner.Clone(original.Results); 65 59 initialized = original.initialized; 66 executionTime = original.executionTime;67 60 } 68 61 protected BasicAlgorithm() 69 62 : base() { 70 63 results = new ResultCollection(); 71 executionTime = TimeSpan.Zero;72 64 } 73 65 74 66 public override void Prepare() { 75 executionTime = TimeSpan.Zero;76 67 if (Problem == null) return; 77 68 base.Prepare(); … … 82 73 83 74 public override void Start(CancellationToken cancellationToken) { 84 startDate = DateTime.UtcNow;85 executionTimeActive = true;86 75 base.Start(cancellationToken); 87 76 CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); … … 125 114 private void Run(object state) { 126 115 CancellationToken cancellationToken = (CancellationToken)state; 127 if (!initialized) 128 Initialize(cancellationToken); 129 initialized = true; 130 Run(cancellationToken); 116 lastUpdateTime = DateTime.UtcNow; 117 System.Timers.Timer timer = new System.Timers.Timer(250); 118 timer.AutoReset = true; 119 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 120 timer.Start(); 121 try { 122 if (!initialized) 123 Initialize(cancellationToken); 124 initialized = true; 125 Run(cancellationToken); 126 } 127 finally { 128 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 129 timer.Stop(); 130 ExecutionTime += DateTime.UtcNow - lastUpdateTime; 131 } 131 132 } 132 133 … … 134 135 protected abstract void Run(CancellationToken cancellationToken); 135 136 136 protected override void OnPaused() { 137 executionTime += DateTime.UtcNow - startDate; 138 executionTimeActive = false; 139 base.OnPaused(); 137 #region Events 138 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 139 System.Timers.Timer timer = (System.Timers.Timer)sender; 140 timer.Enabled = false; 141 DateTime now = DateTime.UtcNow; 142 ExecutionTime += now - lastUpdateTime; 143 lastUpdateTime = now; 144 timer.Enabled = true; 140 145 } 146 #endregion 141 147 142 protected override void OnStopped() {143 if (executionTimeActive) { // don't do if going from pause to stop144 executionTime += DateTime.UtcNow - startDate;145 executionTimeActive = false;146 }147 base.OnStopped();148 }149 148 } 150 149 } -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs
r15719 r15721 71 71 } 72 72 73 public override TimeSpan ExecutionTime {74 get { return engine.ExecutionTime; }75 }76 77 73 public override ResultCollection Results { 78 74 get { … … 200 196 private void RegisterEngineEvents() { 201 197 Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 198 Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged); 202 199 Engine.Paused += new EventHandler(Engine_Paused); 203 200 Engine.Prepared += new EventHandler(Engine_Prepared); … … 207 204 private void DeregisterEngineEvents() { 208 205 Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 206 Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged); 209 207 Engine.Paused -= new EventHandler(Engine_Paused); 210 208 Engine.Prepared -= new EventHandler(Engine_Prepared); … … 214 212 private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) { 215 213 OnExceptionOccurred(e.Value); 214 } 215 private void Engine_ExecutionTimeChanged(object sender, EventArgs e) { 216 ExecutionTime = Engine.ExecutionTime; 216 217 } 217 218 private void Engine_Paused(object sender, EventArgs e) { -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/HeuristicOptimizationAlgorithm.cs
r15605 r15721 21 21 22 22 using System; 23 using System.Threading;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 38 37 } 39 38 40 [Storable] 41 private TimeSpan executionTime; 42 private DateTime startDate; 43 public override TimeSpan ExecutionTime { 44 get { return executionTime + (ExecutionState == ExecutionState.Started ? DateTime.UtcNow - startDate : TimeSpan.Zero); } 45 } 46 47 protected HeuristicOptimizationAlgorithm() : base() { 48 executionTime = TimeSpan.Zero; 49 } 50 protected HeuristicOptimizationAlgorithm(string name) : base(name) { 51 executionTime = TimeSpan.Zero; 52 } 53 protected HeuristicOptimizationAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) { 54 executionTime = TimeSpan.Zero; 55 } 56 protected HeuristicOptimizationAlgorithm(string name, string description) : base(name, description) { 57 executionTime = TimeSpan.Zero; 58 } 59 protected HeuristicOptimizationAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { 60 executionTime = TimeSpan.Zero; 61 } 39 protected HeuristicOptimizationAlgorithm() : base() { } 40 protected HeuristicOptimizationAlgorithm(string name) : base(name) { } 41 protected HeuristicOptimizationAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) { } 42 protected HeuristicOptimizationAlgorithm(string name, string description) : base(name, description) { } 43 protected HeuristicOptimizationAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { } 62 44 63 45 [StorableConstructor] 64 46 protected HeuristicOptimizationAlgorithm(bool deserializing) : base(deserializing) { } 65 protected HeuristicOptimizationAlgorithm(HeuristicOptimizationAlgorithm original, Cloner cloner) 66 : base(original, cloner) { 67 executionTime = original.executionTime; 68 } 69 70 public override void Prepare() { 71 executionTime = TimeSpan.Zero; 72 base.Prepare(); 73 } 74 75 public override void Start(CancellationToken cancellationToken) { 76 startDate = DateTime.UtcNow; 77 base.Start(cancellationToken); 78 } 47 protected HeuristicOptimizationAlgorithm(HeuristicOptimizationAlgorithm original, Cloner cloner) : base(original, cloner) { } 79 48 80 49 #region Events … … 93 62 protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { } 94 63 #endregion 95 96 protected override void OnPaused() {97 var elapsed = DateTime.UtcNow - startDate;98 executionTime += elapsed;99 base.OnPaused();100 }101 102 protected override void OnStopped() {103 if (ExecutionState == ExecutionState.Started) {104 var elapsed = DateTime.UtcNow - startDate;105 executionTime += elapsed;106 }107 base.OnStopped();108 }109 64 } 110 65 } -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs
r15605 r15721 68 68 } 69 69 } 70 70 71 71 [Storable] 72 72 private TimeSpan executionTime; 73 73 public TimeSpan ExecutionTime { 74 get { return executionTime + (Optimizer?.ExecutionTime ?? TimeSpan.Zero); } 75 } 74 get { 75 if ((Optimizer != null) && (Optimizer.ExecutionState != ExecutionState.Stopped)) 76 return executionTime + Optimizer.ExecutionTime; 77 else 78 return executionTime; 79 } 80 private set { 81 executionTime = value; 82 OnExecutionTimeChanged(); 83 } 84 } 85 86 [Storable] 87 private TimeSpan runsExecutionTime; 76 88 77 89 [Storable] … … 162 174 executionState = ExecutionState.Stopped; 163 175 executionTime = TimeSpan.Zero; 176 runsExecutionTime = TimeSpan.Zero; 164 177 repetitions = 10; 165 178 repetitionsCounter = 0; … … 171 184 executionState = ExecutionState.Stopped; 172 185 executionTime = TimeSpan.Zero; 186 runsExecutionTime = TimeSpan.Zero; 173 187 repetitions = 10; 174 188 repetitionsCounter = 0; … … 179 193 executionState = ExecutionState.Stopped; 180 194 executionTime = TimeSpan.Zero; 195 runsExecutionTime = TimeSpan.Zero; 181 196 repetitions = 10; 182 197 repetitionsCounter = 0; … … 194 209 executionState = original.executionState; 195 210 executionTime = original.executionTime; 211 runsExecutionTime = original.runsExecutionTime; 196 212 optimizer = cloner.Clone(original.optimizer); 197 213 repetitions = original.repetitions; … … 218 234 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 219 235 if (Optimizer != null) { 220 executionTime = TimeSpan.Zero;236 ExecutionTime = TimeSpan.Zero; 221 237 RepetitionsCounter = 0; 222 238 if (clearRuns) runs.Clear(); … … 282 298 if (handler != null) handler(this, EventArgs.Empty); 283 299 } 284 [Obsolete("Deprecated needs to be removed")]285 300 public event EventHandler ExecutionTimeChanged; 301 private void OnExecutionTimeChanged() { 302 EventHandler handler = ExecutionTimeChanged; 303 if (handler != null) handler(this, EventArgs.Empty); 304 } 286 305 public event EventHandler OptimizerChanged; 287 306 private void OnOptimizerChanged() { … … 335 354 private void RegisterOptimizerEvents() { 336 355 optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Optimizer_ExceptionOccurred); 356 optimizer.ExecutionTimeChanged += new EventHandler(Optimizer_ExecutionTimeChanged); 337 357 optimizer.Paused += new EventHandler(Optimizer_Paused); 338 358 optimizer.Prepared += new EventHandler(Optimizer_Prepared); … … 345 365 private void DeregisterOptimizerEvents() { 346 366 optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Optimizer_ExceptionOccurred); 367 optimizer.ExecutionTimeChanged -= new EventHandler(Optimizer_ExecutionTimeChanged); 347 368 optimizer.Paused -= new EventHandler(Optimizer_Paused); 348 369 optimizer.Prepared -= new EventHandler(Optimizer_Prepared); … … 356 377 OnExceptionOccurred(e.Value); 357 378 } 379 private void Optimizer_ExecutionTimeChanged(object sender, EventArgs e) { 380 OnExecutionTimeChanged(); 381 } 358 382 private void Optimizer_Paused(object sender, EventArgs e) { 359 383 if (ExecutionState == ExecutionState.Started) { … … 363 387 private void Optimizer_Prepared(object sender, EventArgs e) { 364 388 if (batchRunAction == BatchRunAction.Prepare || ExecutionState == ExecutionState.Stopped) { 389 ExecutionTime = TimeSpan.Zero; 390 runsExecutionTime = TimeSpan.Zero; 365 391 RepetitionsCounter = 0; 366 392 OnPrepared(); … … 373 399 private void Optimizer_Stopped(object sender, EventArgs e) { 374 400 RepetitionsCounter++; 401 ExecutionTime += runsExecutionTime; 402 runsExecutionTime = TimeSpan.Zero; 375 403 376 404 if (batchRunAction == BatchRunAction.Stop) OnStopped(); … … 407 435 private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 408 436 if (Optimizer != null) Optimizer.Runs.RemoveRange(e.OldItems); 409 executionTime += SumExecutionTimes(e.OldItems); 410 executionTime += SumExecutionTimes(e.Items); 437 foreach (IRun run in e.Items) { 438 IItem item; 439 run.Results.TryGetValue("Execution Time", out item); 440 TimeSpanValue executionTime = item as TimeSpanValue; 441 if (executionTime != null) ExecutionTime += executionTime.Value; 442 } 411 443 } 412 444 private void Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 413 executionTime += SumExecutionTimes(e.Items); 445 foreach (IRun run in e.Items) { 446 IItem item; 447 run.Results.TryGetValue("Execution Time", out item); 448 TimeSpanValue executionTime = item as TimeSpanValue; 449 if (executionTime != null) { 450 if (Optimizer.ExecutionState == ExecutionState.Started) 451 runsExecutionTime += executionTime.Value; 452 else 453 ExecutionTime += executionTime.Value; 454 } 455 } 414 456 } 415 457 private void Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 416 458 if (Optimizer != null) Optimizer.Runs.RemoveRange(e.Items); 417 executionTime -= SumExecutionTimes(e.Items);418 }419 private TimeSpan SumExecutionTimes(IEnumerable<IRun> runs) {420 var sum = TimeSpan.Zero;421 foreach (IRun run in runs) {422 IItem item;423 run.Results.TryGetValue("Execution Time", out item);424 TimeSpanValue exTime = item as TimeSpanValue;425 if (exTime != null) sum += exTime.Value;426 }427 return sum;428 459 } 429 460 #endregion -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs
r15605 r15721 70 70 private TimeSpan executionTime; 71 71 public TimeSpan ExecutionTime { 72 get { return executionTime + Optimizers.Aggregate(TimeSpan.Zero, (a, x) => a + x.ExecutionTime); } 72 get { return executionTime; } 73 private set { 74 executionTime = value; 75 OnExecutionTimeChanged(); 76 } 73 77 } 74 78 … … 278 282 if (handler != null) handler(this, EventArgs.Empty); 279 283 } 280 [Obsolete("deprecated needs to be removed")]281 284 public event EventHandler ExecutionTimeChanged; 285 private void OnExecutionTimeChanged() { 286 EventHandler handler = ExecutionTimeChanged; 287 if (handler != null) handler(this, EventArgs.Empty); 288 } 282 289 public event EventHandler Prepared; 283 290 private void OnPrepared() { … … 362 369 private void RegisterOptimizerEvents(IOptimizer optimizer) { 363 370 optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred); 371 optimizer.ExecutionTimeChanged += new EventHandler(optimizer_ExecutionTimeChanged); 364 372 optimizer.Paused += new EventHandler(optimizer_Paused); 365 373 optimizer.Prepared += new EventHandler(optimizer_Prepared); … … 372 380 private void DeregisterOptimizerEvents(IOptimizer optimizer) { 373 381 optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred); 382 optimizer.ExecutionTimeChanged -= new EventHandler(optimizer_ExecutionTimeChanged); 374 383 optimizer.Paused -= new EventHandler(optimizer_Paused); 375 384 optimizer.Prepared -= new EventHandler(optimizer_Prepared); … … 386 395 lock (locker) 387 396 OnExceptionOccurred(e.Value); 397 } 398 private void optimizer_ExecutionTimeChanged(object sender, EventArgs e) { 399 // only wait for maximally 100ms to acquire lock, otherwise return and don't update the execution time 400 var success = Monitor.TryEnter(locker, 100); 401 if (!success) return; 402 try { 403 ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime); 404 } finally { 405 Monitor.Exit(locker); 406 } 388 407 } 389 408 private void optimizer_Paused(object sender, EventArgs e) { -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs
r15605 r15721 214 214 215 215 private void Initialize() { 216 timer = new System.Timers.Timer();217 timer.Interval = 50;218 timer.Elapsed += Timer_Elapsed;219 216 if (algorithm != null) RegisterAlgorithmEvents(); 220 217 snapshotTimes.ItemsAdded += snapshotTimes_Changed; … … 258 255 } 259 256 260 private System.Timers.Timer timer;261 262 private void Timer_Elapsed(object sender, EventArgs e) {263 if (Algorithm.ExecutionState == ExecutionState.Started) {264 if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex]265 && !pausedForSnapshot) {266 pausedForSnapshot = true;267 Algorithm.Pause();268 }269 if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) {270 pausedForTermination = true;271 if (!pausedForSnapshot) Algorithm.Pause();272 }273 }274 }275 276 257 #region Events 277 258 protected override void OnNameChanged() { … … 292 273 if (handler != null) handler(this, EventArgs.Empty); 293 274 } 294 [Obsolete("Deprecated needs to be removed")]295 275 public event EventHandler ExecutionTimeChanged; 276 private void OnExecutionTimeChanged() { 277 var handler = ExecutionTimeChanged; 278 if (handler != null) handler(this, EventArgs.Empty); 279 } 296 280 public event EventHandler Prepared; 297 281 private void OnPrepared() { … … 301 285 public event EventHandler Started; 302 286 private void OnStarted() { 303 timer.Start();304 287 var handler = Started; 305 288 if (handler != null) handler(this, EventArgs.Empty); … … 307 290 public event EventHandler Paused; 308 291 private void OnPaused() { 309 timer.Stop();310 292 var handler = Paused; 311 293 if (handler != null) handler(this, EventArgs.Empty); … … 313 295 public event EventHandler Stopped; 314 296 private void OnStopped() { 315 timer.Stop();316 297 var handler = Stopped; 317 298 if (handler != null) handler(this, EventArgs.Empty); … … 327 308 private void RegisterAlgorithmEvents() { 328 309 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred; 310 algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged; 329 311 algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged; 330 312 algorithm.Paused += Algorithm_Paused; … … 335 317 private void DeregisterAlgorithmEvents() { 336 318 algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred; 319 algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged; 337 320 algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged; 338 321 algorithm.Paused -= Algorithm_Paused; … … 343 326 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 344 327 OnExceptionOccurred(e.Value); 328 } 329 private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) { 330 if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex] 331 && !pausedForSnapshot) { 332 pausedForSnapshot = true; 333 Algorithm.Pause(); 334 } 335 if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) { 336 pausedForTermination = true; 337 if (!pausedForSnapshot) Algorithm.Pause(); 338 } 339 OnExecutionTimeChanged(); 345 340 } 346 341 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) { -
branches/1614_GeneralizedQAP/HeuristicLab.OptimizationExpertSystem.Common/3.3/HeuristicLab.OptimizationExpertSystem.Common-3.3.csproj
r15694 r15721 170 170 <Private>False</Private> 171 171 </ProjectReference> 172 <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj">173 <Project>{DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA}</Project>174 <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name>175 <Private>False</Private>176 </ProjectReference>177 172 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 178 173 <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
Note: See TracChangeset
for help on using the changeset viewer.