Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/11 13:14:11 (14 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

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  
    2424using System.Drawing;
    2525using System.IO;
     26using System.Linq;
    2627using HeuristicLab.Collections;
    2728using HeuristicLab.Common;
     
    4344    }
    4445    private IAlgorithm algorithm;
    45     public IAlgorithm Algorithm {
     46    private IAlgorithm Algorithm {
    4647      get { return algorithm; }
    47       private set {
     48      set {
    4849        if (value == null) throw new ArgumentNullException("Algorithm", "Algorithm cannot be null.");
    4950        if (value != algorithm) {
     
    7778    public IEnumerable<IOptimizer> NestedOptimizers {
    7879      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>();
    8382      }
    8483    }
     
    135134      set { Algorithm.StoreAlgorithmInEachRun = value; }
    136135    }
    137 
    138 
    139136
    140137    #region Persistence Properties
     
    204201    }
    205202
     203    public IAlgorithm CloneAlgorithm() {
     204      return (IAlgorithm)Algorithm.Clone();
     205    }
     206
    206207    public void CollectParameterValues(IDictionary<string, IItem> values) {
    207208      Algorithm.CollectParameterValues(values);
     
    287288    private void OnStopped() {
    288289      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      }
    290298      var handler = Stopped;
    291299      if (handler != null) handler(this, EventArgs.Empty);
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBProblem.cs

    r5640 r5667  
    4242    }
    4343    private IProblem problem;
    44     public IProblem Problem {
     44    protected IProblem Problem {
    4545      get { return problem; }
    4646      private set {
     
    153153    }
    154154
     155    public IProblem CloneProblem() {
     156      return (IProblem)Problem.Clone();
     157    }
     158
    155159    public void CollectParameterValues(IDictionary<string, IItem> values) {
    156160      Problem.CollectParameterValues(values);
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBRun.cs

    r5640 r5667  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.IO;
     26using System.Linq;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core;
    2729using HeuristicLab.Optimization;
    2830using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Persistence.Default.Xml;
    2932
    3033namespace HeuristicLab.Clients.OKB.RunCreation {
     
    3437    public string Filename { get; set; }
    3538
    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; }
    3945    }
    4046
     
    5965
    6066    #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; }
    6571    }
    6672    #endregion
     
    7076    private OKBRun(OKBRun original, Cloner cloner)
    7177      : base(original, cloner) {
    72       runId = original.runId;
     78      stored = original.stored;
    7379    }
    74     public OKBRun(IRun run)
     80    public OKBRun(long algorithmId, long problemId, IRun run)
    7581      : base(run) {
    76       runId = -1;
     82      this.algorithmId = algorithmId;
     83      this.problemId = problemId;
     84      this.createdDate = DateTime.Now;
     85      this.stored = false;
    7786    }
    7887
    7988    public override IDeepCloneable Clone(Cloner cloner) {
    8089      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;
    81107    }
    82108
     
    101127    }
    102128    #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
    103173  }
    104174}
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBAlgorithmView.Designer.cs

    r5660 r5667  
    415415    #endregion
    416416
    417     protected HeuristicLab.MainForm.WindowsForms.DragOverTabControl tabControl;
    418     protected System.Windows.Forms.TabPage parametersTabPage;
    419     protected System.Windows.Forms.TabPage problemTabPage;
    420     protected HeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView;
    421     protected HeuristicLab.MainForm.WindowsForms.ViewHost problemViewHost;
    422     protected System.Windows.Forms.Button newProblemButton;
    423     protected System.Windows.Forms.Button openProblemButton;
    424     protected System.Windows.Forms.Button startButton;
    425     protected System.Windows.Forms.Button pauseButton;
    426     protected System.Windows.Forms.Button resetButton;
    427     protected System.Windows.Forms.Label executionTimeLabel;
    428     protected System.Windows.Forms.TextBox executionTimeTextBox;
    429     protected System.Windows.Forms.OpenFileDialog openFileDialog;
    430     protected System.Windows.Forms.TabPage resultsTabPage;
    431     protected HeuristicLab.Optimization.Views.ResultCollectionView resultsView;
    432     protected System.Windows.Forms.Button stopButton;
    433     protected System.Windows.Forms.TabPage runsTabPage;
    434     protected RunCollectionView runsView;
    435     protected System.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;
    436436    private System.Windows.Forms.ComboBox algorithmComboBox;
    437437    private System.Windows.Forms.Label algorithmLabel;
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBAlgorithmView.cs

    r5660 r5667  
    3434  [View("OKBAlgorithm View")]
    3535  [Content(typeof(OKBAlgorithm), true)]
    36   public partial class OKBAlgorithmView : NamedItemView {
     36  public sealed partial class OKBAlgorithmView : NamedItemView {
    3737    private TypeSelectorDialog problemTypeSelectorDialog;
    3838
     
    124124      base.SetEnabledStateOfControls();
    125125      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;
    127127      refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked;
    128128      parameterCollectionView.Enabled = Content != null;
     
    174174      if (InvokeRequired)
    175175        Invoke(new EventHandler(Content_AlgorithmChanged), sender, e);
    176       else {
    177         algorithmComboBox.SelectedItem = RunCreationClient.Instance.Algorithms.FirstOrDefault(x => x.Id == Content.AlgorithmId);
     176      else
    178177        OnContentChanged();
    179       }
    180     }
    181     protected virtual void Content_ProblemChanged(object sender, EventArgs e) {
     178    }
     179    private void Content_ProblemChanged(object sender, EventArgs e) {
    182180      if (InvokeRequired)
    183181        Invoke(new EventHandler(Content_ProblemChanged), sender, e);
     
    187185      }
    188186    }
    189     protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) {
     187    private void Content_ExecutionStateChanged(object sender, EventArgs e) {
    190188      if (InvokeRequired)
    191189        Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
     
    193191        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
    194192    }
    195     protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
     193    private void Content_ExecutionTimeChanged(object sender, EventArgs e) {
    196194      if (InvokeRequired)
    197195        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
     
    199197        executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
    200198    }
    201     protected virtual void Content_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) {
     199    private void Content_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) {
    202200      if (InvokeRequired)
    203201        Invoke(new EventHandler(Content_StoreAlgorithmInEachRunChanged), sender, e);
     
    205203        storeAlgorithmInEachRunCheckBox.Checked = Content.StoreAlgorithmInEachRun;
    206204    }
    207     protected virtual void Content_Prepared(object sender, EventArgs e) {
     205    private void Content_Prepared(object sender, EventArgs e) {
    208206      if (InvokeRequired)
    209207        Invoke(new EventHandler(Content_Prepared), sender, e);
     
    214212      }
    215213    }
    216     protected virtual void Content_Started(object sender, EventArgs e) {
     214    private void Content_Started(object sender, EventArgs e) {
    217215      if (InvokeRequired)
    218216        Invoke(new EventHandler(Content_Started), sender, e);
     
    222220      }
    223221    }
    224     protected virtual void Content_Paused(object sender, EventArgs e) {
     222    private void Content_Paused(object sender, EventArgs e) {
    225223      if (InvokeRequired)
    226224        Invoke(new EventHandler(Content_Paused), sender, e);
     
    230228      }
    231229    }
    232     protected virtual void Content_Stopped(object sender, EventArgs e) {
     230    private void Content_Stopped(object sender, EventArgs e) {
    233231      if (InvokeRequired)
    234232        Invoke(new EventHandler(Content_Stopped), sender, e);
     
    238236      }
    239237    }
    240     protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
     238    private void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    241239      if (InvokeRequired)
    242240        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
     
    248246    #region Control Events
    249247    private void cloneAlgorithmButton_Click(object sender, EventArgs e) {
    250       MainFormManager.MainForm.ShowContent((IContent)Content.Algorithm.Clone());
     248      MainFormManager.MainForm.ShowContent(Content.CloneAlgorithm());
    251249    }
    252250    private void refreshButton_Click(object sender, System.EventArgs e) {
     
    261259      }
    262260    }
    263     protected virtual void newProblemButton_Click(object sender, EventArgs e) {
     261    private void newProblemButton_Click(object sender, EventArgs e) {
    264262      if (problemTypeSelectorDialog == null) {
    265263        problemTypeSelectorDialog = new TypeSelectorDialog();
     
    277275      }
    278276    }
    279     protected virtual void openProblemButton_Click(object sender, EventArgs e) {
     277    private void openProblemButton_Click(object sender, EventArgs e) {
    280278      openFileDialog.Title = "Open Problem";
    281279      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
     
    308306      }
    309307    }
    310     protected virtual void storeAlgorithmInEachRunCheckBox_CheckedChanged(object sender, EventArgs e) {
     308    private void storeAlgorithmInEachRunCheckBox_CheckedChanged(object sender, EventArgs e) {
    311309      if (Content != null) Content.StoreAlgorithmInEachRun = storeAlgorithmInEachRunCheckBox.Checked;
    312310    }
    313     protected virtual void startButton_Click(object sender, EventArgs e) {
     311    private void startButton_Click(object sender, EventArgs e) {
    314312      Content.Start();
    315313    }
    316     protected virtual void pauseButton_Click(object sender, EventArgs e) {
     314    private void pauseButton_Click(object sender, EventArgs e) {
    317315      Content.Pause();
    318316    }
    319     protected virtual void stopButton_Click(object sender, EventArgs e) {
     317    private void stopButton_Click(object sender, EventArgs e) {
    320318      Content.Stop();
    321319    }
    322     protected virtual void resetButton_Click(object sender, EventArgs e) {
     320    private void resetButton_Click(object sender, EventArgs e) {
    323321      Content.Prepare(false);
    324322    }
    325     protected virtual void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {
     323    private void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    326324      e.Effect = DragDropEffects.None;
    327325      Type type = e.Data.GetData("Type") as Type;
     
    334332      }
    335333    }
    336     protected virtual void problemTabPage_DragDrop(object sender, DragEventArgs e) {
     334    private void problemTabPage_DragDrop(object sender, DragEventArgs e) {
    337335      if (e.Effect != DragDropEffects.None) {
    338336        IProblem problem = e.Data.GetData("Value") as IProblem;
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/Views/OKBProblemView.cs

    r5660 r5667  
    3030  [View("OKBProblem View")]
    3131  [Content(typeof(OKBProblem), true)]
    32   public partial class OKBProblemView : NamedItemView {
     32  public sealed partial class OKBProblemView : NamedItemView {
    3333    public new OKBProblem Content {
    3434      get { return (OKBProblem)base.Content; }
     
    7070      base.SetEnabledStateOfControls();
    7171      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;
    7373      refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked;
    7474      parameterCollectionView.Enabled = Content != null;
     
    8686      } else {
    8787        Cursor = Cursors.AppStarting;
    88         problemComboBox.Enabled = refreshButton.Enabled = false;
     88        problemComboBox.Enabled = cloneProblemButton.Enabled = refreshButton.Enabled = parameterCollectionView.Enabled = false;
    8989      }
    9090    }
     
    103103      if (InvokeRequired)
    104104        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();
    108107    }
    109108    #endregion
     
    111110    #region Control Events
    112111    private void cloneProblemButton_Click(object sender, EventArgs e) {
    113       MainFormManager.MainForm.ShowContent((IContent)Content.Problem.Clone());
     112      MainFormManager.MainForm.ShowContent(Content.CloneProblem());
    114113    }
    115114    private void refreshButton_Click(object sender, System.EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.