Changeset 14383 for branches/HeuristicLab.GoalSeekingProblem
- Timestamp:
- 11/10/16 15:26:17 (8 years ago)
- Location:
- branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/GoalSeekingOptimizer.cs
r14380 r14383 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 using System.Threading;26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; … … 31 31 32 32 namespace HeuristicLab.GoalSeeking { 33 internal enum GoalSeekingOptimizerAction { None, Prepare, Start, Stop, Pause } 34 33 35 [StorableClass] 34 36 [Item("GoalSeeking Optimizer", "A wrapper for the GoalSeekingProblem class to facilitate adding models and problem data.")] … … 90 92 } 91 93 94 private GoalSeekingOptimizerAction gsoAction; 95 92 96 public GoalSeekingOptimizer() { 93 97 Name = "Goal Seeking Optimizer"; … … 136 140 137 141 private int calculatedRows; 138 private readonly ManualResetEvent mutex = new ManualResetEvent(false);139 142 public void Start() { 140 143 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 141 144 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 142 145 if (optimizer == null) return; 143 144 Prepare(clearRuns: true); 145 146 calculatedRows = 0; 147 148 var row = problemData.TrainingIndices.Skip(calculatedRows).First(); 149 problem.Configure(problemData, row); 150 optimizer.Prepare(); 146 gsoAction = GoalSeekingOptimizerAction.Start; 147 if (Optimizer.ExecutionState == ExecutionState.Stopped) { 148 Optimizer.Prepare(clearRuns: true); 149 calculatedRows = 0; 150 151 var row = problemData.TrainingIndices.Skip(calculatedRows).First(); 152 problem.Configure(problemData, row); 153 optimizer.Prepare(); 154 } 151 155 optimizer.Start(); 152 156 } … … 156 160 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 157 161 if (optimizer == null) return; 162 gsoAction = GoalSeekingOptimizerAction.Pause; 158 163 if (optimizer.ExecutionState != ExecutionState.Started) return; 159 164 // a race-condition may occur when the algorithm has changed the state by itself in the meantime … … 166 171 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); 167 172 if (optimizer == null) return; 173 gsoAction = GoalSeekingOptimizerAction.Stop; 168 174 if (optimizer.ExecutionState != ExecutionState.Started && optimizer.ExecutionState != ExecutionState.Paused) { 169 175 OnStopped(); … … 185 191 ExecutionTime = TimeSpan.Zero; 186 192 if (clearRuns) optimizer.Runs.Clear(); 193 gsoAction = GoalSeekingOptimizerAction.Prepare; 187 194 // a race-condition may occur when the algorithm has changed the state by itself in the meantime 188 195 try { optimizer.Prepare(clearRuns); } … … 220 227 public string Filename { get; set; } 221 228 229 public new static Image StaticItemImage { 230 get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; } 231 } 232 public override Image ItemImage { 233 get { 234 if (ExecutionState == ExecutionState.Prepared) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunPrepared; 235 else if (ExecutionState == ExecutionState.Started) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunStarted; 236 else if (ExecutionState == ExecutionState.Paused) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunPaused; 237 else if (ExecutionState == ExecutionState.Stopped) return HeuristicLab.Common.Resources.VSImageLibrary.BatchRunStopped; 238 else return base.ItemImage; 239 } 240 } 241 222 242 #region Events 223 243 protected override void OnNameChanged() { … … 241 261 public event EventHandler Prepared; 242 262 private void OnPrepared() { 263 gsoAction = GoalSeekingOptimizerAction.None; 243 264 ExecutionState = ExecutionState.Prepared; 244 265 EventHandler handler = Prepared; … … 255 276 public event EventHandler Paused; 256 277 private void OnPaused() { 278 gsoAction = GoalSeekingOptimizerAction.None; 257 279 ExecutionState = ExecutionState.Paused; 258 280 EventHandler handler = Paused; … … 262 284 public event EventHandler Stopped; 263 285 private void OnStopped() { 286 gsoAction = GoalSeekingOptimizerAction.None; 264 287 ExecutionState = ExecutionState.Stopped; 265 288 EventHandler handler = Stopped; … … 326 349 327 350 private void Optimizer_Prepared(object sender, EventArgs e) { 328 if (ExecutionState == ExecutionState.Stopped) { 351 if (gsoAction == GoalSeekingOptimizerAction.Prepare || ExecutionState == ExecutionState.Stopped) { 352 calculatedRows = 0; 329 353 ExecutionTime = TimeSpan.Zero; 330 354 OnPrepared(); … … 341 365 calculatedRows++; 342 366 ExecutionTime += optimizer.ExecutionTime; 343 344 367 var remainingRows = problemData.TrainingIndices.Skip(calculatedRows); 345 if (remainingRows.Any()) { 368 369 if (gsoAction == GoalSeekingOptimizerAction.Stop) OnStopped(); 370 else if (!remainingRows.Any()) OnStopped(); 371 else if (gsoAction == GoalSeekingOptimizerAction.Pause) OnPaused(); 372 else if (gsoAction == GoalSeekingOptimizerAction.Start) { 346 373 var row = remainingRows.First(); 347 374 problem.Configure(problemData, row); 348 375 optimizer.Prepare(); 349 376 optimizer.Start(); 350 } else {351 On Stopped();352 } 377 } else if (ExecutionState == ExecutionState.Started) { 378 OnPaused(); 379 } else OnStopped(); 353 380 } 354 381 #endregion -
branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/GoalSeekingProblem.csproj
r14380 r14383 124 124 <SpecificVersion>False</SpecificVersion> 125 125 <HintPath>..\HeuristicLab trunk sources\binHeuristicLab.Common-3.3.dll</HintPath> 126 <Private>False</Private> 127 </Reference> 128 <Reference Include="HeuristicLab.Common.Resources-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 129 <SpecificVersion>False</SpecificVersion> 130 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath> 126 131 <Private>False</Private> 127 132 </Reference> -
branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/Properties/AssemblyInfo.cs
r14380 r14383 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 55 [assembly: AssemblyVersion("3.3.0.0")] 56 [assembly: AssemblyFileVersion("3.3.11.143 79")]56 [assembly: AssemblyFileVersion("3.3.11.14380")]
Note: See TracChangeset
for help on using the changeset viewer.