Changeset 5667 for branches/OKB (trunk integration)
- Timestamp:
- 03/12/11 13:14:11 (14 years ago)
- Location:
- branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs
r5640 r5667 24 24 using System.Drawing; 25 25 using System.IO; 26 using System.Linq; 26 27 using HeuristicLab.Collections; 27 28 using HeuristicLab.Common; … … 43 44 } 44 45 private IAlgorithm algorithm; 45 p ublicIAlgorithm Algorithm {46 private IAlgorithm Algorithm { 46 47 get { return algorithm; } 47 privateset {48 set { 48 49 if (value == null) throw new ArgumentNullException("Algorithm", "Algorithm cannot be null."); 49 50 if (value != algorithm) { … … 77 78 public IEnumerable<IOptimizer> NestedOptimizers { 78 79 get { 79 if (Algorithm == null) yield break; 80 yield return Algorithm; 81 foreach (IOptimizer optimizer in Algorithm.NestedOptimizers) 82 yield return optimizer; 80 // inner algorithm cannot be accessed directly 81 return Enumerable.Empty<IOptimizer>(); 83 82 } 84 83 } … … 135 134 set { Algorithm.StoreAlgorithmInEachRun = value; } 136 135 } 137 138 139 136 140 137 #region Persistence Properties … … 204 201 } 205 202 203 public IAlgorithm CloneAlgorithm() { 204 return (IAlgorithm)Algorithm.Clone(); 205 } 206 206 207 public void CollectParameterValues(IDictionary<string, IItem> values) { 207 208 Algorithm.CollectParameterValues(values); … … 287 288 private void OnStopped() { 288 289 runsCounter++; 289 runs.Add(new HeuristicLab.Optimization.Run(string.Format("{0} Run {1}", Name, runsCounter), this)); 290 if (Problem is OKBProblem) { 291 OKBProblem problem = (OKBProblem)Problem; 292 OKBRun run = new OKBRun(AlgorithmId, problem.ProblemId, new HeuristicLab.Optimization.Run(string.Format("{0} Run {1}", Name, runsCounter), this)); 293 runs.Add(run); 294 run.Store(); 295 } else { 296 runs.Add(new HeuristicLab.Optimization.Run(string.Format("{0} Run {1}", Name, runsCounter), this)); 297 } 290 298 var handler = Stopped; 291 299 if (handler != null) handler(this, EventArgs.Empty); -
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBProblem.cs
r5640 r5667 42 42 } 43 43 private IProblem problem; 44 p ublicIProblem Problem {44 protected IProblem Problem { 45 45 get { return problem; } 46 46 private set { … … 153 153 } 154 154 155 public IProblem CloneProblem() { 156 return (IProblem)Problem.Clone(); 157 } 158 155 159 public void CollectParameterValues(IDictionary<string, IItem> values) { 156 160 Problem.CollectParameterValues(values); -
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBRun.cs
r5640 r5667 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.IO; 26 using System.Linq; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Core; 27 29 using HeuristicLab.Optimization; 28 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Persistence.Default.Xml; 29 32 30 33 namespace HeuristicLab.Clients.OKB.RunCreation { … … 34 37 public string Filename { get; set; } 35 38 36 private long runId; 37 public long RunId { 38 get { return runId; } 39 private long algorithmId; 40 private long problemId; 41 private DateTime createdDate; 42 private bool stored; 43 public bool Stored { 44 get { return stored; } 39 45 } 40 46 … … 59 65 60 66 #region Persistence Properties 61 [Storable(Name = " RunId")]62 private long StorableRunId {63 get { return runId; }64 set { runId = value; }67 [Storable(Name = "Stored")] 68 private bool StorableStored { 69 get { return stored; } 70 set { stored = value; } 65 71 } 66 72 #endregion … … 70 76 private OKBRun(OKBRun original, Cloner cloner) 71 77 : base(original, cloner) { 72 runId = original.runId;78 stored = original.stored; 73 79 } 74 public OKBRun( IRun run)80 public OKBRun(long algorithmId, long problemId, IRun run) 75 81 : base(run) { 76 runId = -1; 82 this.algorithmId = algorithmId; 83 this.problemId = problemId; 84 this.createdDate = DateTime.Now; 85 this.stored = false; 77 86 } 78 87 79 88 public override IDeepCloneable Clone(Cloner cloner) { 80 89 return new OKBRun(this, cloner); 90 } 91 92 public void Store() { 93 if (stored) throw new InvalidOperationException("Cannot store already stored run."); 94 95 Run run = new Run(); 96 run.AlgorithmId = algorithmId; 97 run.ProblemId = problemId; 98 run.UserId = Guid.Empty; 99 run.ClientId = Guid.Empty; 100 run.CreatedDate = createdDate; 101 run.RandomSeed = Parameters.Where(x => (x.Key == "Seed") && (x.Value is Data.IntValue)).Select(x => ((Data.IntValue)x.Value).Value).FirstOrDefault(); 102 run.ParameterValues = ConvertToValues(Parameters); 103 run.ResultValues = ConvertToValues(Results); 104 RunCreationClient.Instance.AddRun(run); 105 106 stored = true; 81 107 } 82 108 … … 101 127 } 102 128 #endregion 129 130 #region Helpers 131 List<Value> ConvertToValues(IDictionary<string, IItem> items) { 132 List<Value> values = new List<Value>(); 133 foreach (var item in items) { 134 Value value; 135 if (item.Value is Data.BoolValue) { 136 BoolValue v = new BoolValue(); 137 v.Value = ((Data.BoolValue)item.Value).Value; 138 value = v; 139 } else if (item.Value is Data.IntValue) { 140 IntValue v = new IntValue(); 141 v.Value = ((Data.IntValue)item.Value).Value; 142 value = v; 143 } else if (item.Value is Data.DoubleValue) { 144 DoubleValue v = new DoubleValue(); 145 v.Value = ((Data.DoubleValue)item.Value).Value; 146 value = v; 147 } else if (item.Value is Data.StringValue) { 148 StringValue v = new StringValue(); 149 v.Value = ((Data.StringValue)item.Value).Value; 150 value = v; 151 } else if (item.Value is Data.IntValue) { 152 IntValue v = new IntValue(); 153 v.Value = ((Data.IntValue)item.Value).Value; 154 value = v; 155 } else { 156 BinaryValue v = new BinaryValue(); 157 using (MemoryStream stream = new MemoryStream()) { 158 XmlGenerator.Serialize(item.Value, stream); 159 stream.Close(); 160 v.Value = stream.ToArray(); 161 } 162 value = v; 163 } 164 value.Name = item.Key; 165 value.DataType = new DataType(); 166 value.DataType.Name = item.Value.GetType().Name; 167 value.DataType.TypeName = item.Value.GetType().AssemblyQualifiedName; 168 values.Add(value); 169 } 170 return values; 171 } 172 #endregion 103 173 } 104 174 } -
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBAlgorithmView.Designer.cs
r5660 r5667 415 415 #endregion 416 416 417 pr otectedHeuristicLab.MainForm.WindowsForms.DragOverTabControl tabControl;418 pr otectedSystem.Windows.Forms.TabPage parametersTabPage;419 pr otectedSystem.Windows.Forms.TabPage problemTabPage;420 pr otectedHeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView;421 pr otectedHeuristicLab.MainForm.WindowsForms.ViewHost problemViewHost;422 pr otectedSystem.Windows.Forms.Button newProblemButton;423 pr otectedSystem.Windows.Forms.Button openProblemButton;424 pr otectedSystem.Windows.Forms.Button startButton;425 pr otectedSystem.Windows.Forms.Button pauseButton;426 pr otectedSystem.Windows.Forms.Button resetButton;427 pr otectedSystem.Windows.Forms.Label executionTimeLabel;428 pr otectedSystem.Windows.Forms.TextBox executionTimeTextBox;429 pr otectedSystem.Windows.Forms.OpenFileDialog openFileDialog;430 pr otectedSystem.Windows.Forms.TabPage resultsTabPage;431 pr otectedHeuristicLab.Optimization.Views.ResultCollectionView resultsView;432 pr otectedSystem.Windows.Forms.Button stopButton;433 pr otectedSystem.Windows.Forms.TabPage runsTabPage;434 pr otectedRunCollectionView runsView;435 pr otectedSystem.Windows.Forms.CheckBox storeAlgorithmInEachRunCheckBox;417 private HeuristicLab.MainForm.WindowsForms.DragOverTabControl tabControl; 418 private System.Windows.Forms.TabPage parametersTabPage; 419 private System.Windows.Forms.TabPage problemTabPage; 420 private HeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView; 421 private HeuristicLab.MainForm.WindowsForms.ViewHost problemViewHost; 422 private System.Windows.Forms.Button newProblemButton; 423 private System.Windows.Forms.Button openProblemButton; 424 private System.Windows.Forms.Button startButton; 425 private System.Windows.Forms.Button pauseButton; 426 private System.Windows.Forms.Button resetButton; 427 private System.Windows.Forms.Label executionTimeLabel; 428 private System.Windows.Forms.TextBox executionTimeTextBox; 429 private System.Windows.Forms.OpenFileDialog openFileDialog; 430 private System.Windows.Forms.TabPage resultsTabPage; 431 private HeuristicLab.Optimization.Views.ResultCollectionView resultsView; 432 private System.Windows.Forms.Button stopButton; 433 private System.Windows.Forms.TabPage runsTabPage; 434 private RunCollectionView runsView; 435 private System.Windows.Forms.CheckBox storeAlgorithmInEachRunCheckBox; 436 436 private System.Windows.Forms.ComboBox algorithmComboBox; 437 437 private System.Windows.Forms.Label algorithmLabel; -
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBAlgorithmView.cs
r5660 r5667 34 34 [View("OKBAlgorithm View")] 35 35 [Content(typeof(OKBAlgorithm), true)] 36 public partial class OKBAlgorithmView : NamedItemView {36 public sealed partial class OKBAlgorithmView : NamedItemView { 37 37 private TypeSelectorDialog problemTypeSelectorDialog; 38 38 … … 124 124 base.SetEnabledStateOfControls(); 125 125 algorithmComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (algorithmComboBox.Items.Count > 0); 126 cloneAlgorithmButton.Enabled = (Content != null) && (Content. Problem != null) && !ReadOnly && !Locked;126 cloneAlgorithmButton.Enabled = (Content != null) && (Content.AlgorithmId != -1) && !ReadOnly && !Locked; 127 127 refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked; 128 128 parameterCollectionView.Enabled = Content != null; … … 174 174 if (InvokeRequired) 175 175 Invoke(new EventHandler(Content_AlgorithmChanged), sender, e); 176 else { 177 algorithmComboBox.SelectedItem = RunCreationClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId); 176 else 178 177 OnContentChanged(); 179 } 180 } 181 protected virtual void Content_ProblemChanged(object sender, EventArgs e) { 178 } 179 private void Content_ProblemChanged(object sender, EventArgs e) { 182 180 if (InvokeRequired) 183 181 Invoke(new EventHandler(Content_ProblemChanged), sender, e); … … 187 185 } 188 186 } 189 pr otected virtualvoid Content_ExecutionStateChanged(object sender, EventArgs e) {187 private void Content_ExecutionStateChanged(object sender, EventArgs e) { 190 188 if (InvokeRequired) 191 189 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); … … 193 191 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false; 194 192 } 195 pr otected virtualvoid Content_ExecutionTimeChanged(object sender, EventArgs e) {193 private void Content_ExecutionTimeChanged(object sender, EventArgs e) { 196 194 if (InvokeRequired) 197 195 Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e); … … 199 197 executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString(); 200 198 } 201 pr otected virtualvoid Content_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) {199 private void Content_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) { 202 200 if (InvokeRequired) 203 201 Invoke(new EventHandler(Content_StoreAlgorithmInEachRunChanged), sender, e); … … 205 203 storeAlgorithmInEachRunCheckBox.Checked = Content.StoreAlgorithmInEachRun; 206 204 } 207 pr otected virtualvoid Content_Prepared(object sender, EventArgs e) {205 private void Content_Prepared(object sender, EventArgs e) { 208 206 if (InvokeRequired) 209 207 Invoke(new EventHandler(Content_Prepared), sender, e); … … 214 212 } 215 213 } 216 pr otected virtualvoid Content_Started(object sender, EventArgs e) {214 private void Content_Started(object sender, EventArgs e) { 217 215 if (InvokeRequired) 218 216 Invoke(new EventHandler(Content_Started), sender, e); … … 222 220 } 223 221 } 224 pr otected virtualvoid Content_Paused(object sender, EventArgs e) {222 private void Content_Paused(object sender, EventArgs e) { 225 223 if (InvokeRequired) 226 224 Invoke(new EventHandler(Content_Paused), sender, e); … … 230 228 } 231 229 } 232 pr otected virtualvoid Content_Stopped(object sender, EventArgs e) {230 private void Content_Stopped(object sender, EventArgs e) { 233 231 if (InvokeRequired) 234 232 Invoke(new EventHandler(Content_Stopped), sender, e); … … 238 236 } 239 237 } 240 pr otected virtualvoid Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {238 private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) { 241 239 if (InvokeRequired) 242 240 Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e); … … 248 246 #region Control Events 249 247 private void cloneAlgorithmButton_Click(object sender, EventArgs e) { 250 MainFormManager.MainForm.ShowContent( (IContent)Content.Algorithm.Clone());248 MainFormManager.MainForm.ShowContent(Content.CloneAlgorithm()); 251 249 } 252 250 private void refreshButton_Click(object sender, System.EventArgs e) { … … 261 259 } 262 260 } 263 pr otected virtualvoid newProblemButton_Click(object sender, EventArgs e) {261 private void newProblemButton_Click(object sender, EventArgs e) { 264 262 if (problemTypeSelectorDialog == null) { 265 263 problemTypeSelectorDialog = new TypeSelectorDialog(); … … 277 275 } 278 276 } 279 pr otected virtualvoid openProblemButton_Click(object sender, EventArgs e) {277 private void openProblemButton_Click(object sender, EventArgs e) { 280 278 openFileDialog.Title = "Open Problem"; 281 279 if (openFileDialog.ShowDialog(this) == DialogResult.OK) { … … 308 306 } 309 307 } 310 pr otected virtualvoid storeAlgorithmInEachRunCheckBox_CheckedChanged(object sender, EventArgs e) {308 private void storeAlgorithmInEachRunCheckBox_CheckedChanged(object sender, EventArgs e) { 311 309 if (Content != null) Content.StoreAlgorithmInEachRun = storeAlgorithmInEachRunCheckBox.Checked; 312 310 } 313 pr otected virtualvoid startButton_Click(object sender, EventArgs e) {311 private void startButton_Click(object sender, EventArgs e) { 314 312 Content.Start(); 315 313 } 316 pr otected virtualvoid pauseButton_Click(object sender, EventArgs e) {314 private void pauseButton_Click(object sender, EventArgs e) { 317 315 Content.Pause(); 318 316 } 319 pr otected virtualvoid stopButton_Click(object sender, EventArgs e) {317 private void stopButton_Click(object sender, EventArgs e) { 320 318 Content.Stop(); 321 319 } 322 pr otected virtualvoid resetButton_Click(object sender, EventArgs e) {320 private void resetButton_Click(object sender, EventArgs e) { 323 321 Content.Prepare(false); 324 322 } 325 pr otected virtualvoid problemTabPage_DragEnterOver(object sender, DragEventArgs e) {323 private void problemTabPage_DragEnterOver(object sender, DragEventArgs e) { 326 324 e.Effect = DragDropEffects.None; 327 325 Type type = e.Data.GetData("Type") as Type; … … 334 332 } 335 333 } 336 pr otected virtualvoid problemTabPage_DragDrop(object sender, DragEventArgs e) {334 private void problemTabPage_DragDrop(object sender, DragEventArgs e) { 337 335 if (e.Effect != DragDropEffects.None) { 338 336 IProblem problem = e.Data.GetData("Value") as IProblem; -
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBProblemView.cs
r5660 r5667 30 30 [View("OKBProblem View")] 31 31 [Content(typeof(OKBProblem), true)] 32 public partial class OKBProblemView : NamedItemView {32 public sealed partial class OKBProblemView : NamedItemView { 33 33 public new OKBProblem Content { 34 34 get { return (OKBProblem)base.Content; } … … 70 70 base.SetEnabledStateOfControls(); 71 71 problemComboBox.Enabled = (Content != null) && !ReadOnly && !Locked && (problemComboBox.Items.Count > 0); 72 cloneProblemButton.Enabled = (Content != null) && (Content.Problem != null) && !ReadOnly && !Locked;72 cloneProblemButton.Enabled = (Content != null) && (Content.ProblemId != -1) && !ReadOnly && !Locked; 73 73 refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked; 74 74 parameterCollectionView.Enabled = Content != null; … … 86 86 } else { 87 87 Cursor = Cursors.AppStarting; 88 problemComboBox.Enabled = refreshButton.Enabled = false;88 problemComboBox.Enabled = cloneProblemButton.Enabled = refreshButton.Enabled = parameterCollectionView.Enabled = false; 89 89 } 90 90 } … … 103 103 if (InvokeRequired) 104 104 Invoke(new EventHandler(Content_ProblemChanged), sender, e); 105 else { 106 problemComboBox.SelectedItem = RunCreationClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId); 107 } 105 else 106 OnContentChanged(); 108 107 } 109 108 #endregion … … 111 110 #region Control Events 112 111 private void cloneProblemButton_Click(object sender, EventArgs e) { 113 MainFormManager.MainForm.ShowContent( (IContent)Content.Problem.Clone());112 MainFormManager.MainForm.ShowContent(Content.CloneProblem()); 114 113 } 115 114 private void refreshButton_Click(object sender, System.EventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.