Changeset 3226


Ignore:
Timestamp:
03/28/10 04:11:23 (12 years ago)
Author:
swagner
Message:

Implemented first version of algorithm batch processing (#947).

Location:
trunk/sources
Files:
13 added
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearchMainLoop.cs

    r3195 r3226  
    2424using HeuristicLab.Data;
    2525using HeuristicLab.Operators;
     26using HeuristicLab.Optimization.Operators;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
  • trunk/sources/HeuristicLab.Core/3.3/Engine.cs

    r3017 r3226  
    7575    public bool Running {
    7676      get { return running; }
     77      private set {
     78        if (running != value) {
     79          running = value;
     80          OnRunningChanged();
     81        }
     82      }
    7783    }
    7884
     
    126132
    127133    public void Prepare(IOperation initialOperation) {
    128       Canceled = false;
    129       running = false;
    130134      ExecutionTime = new TimeSpan();
    131135      executionStack.Clear();
     
    138142    /// of class <see cref="ThreadPool"/>.</remarks>
    139143    public void Start() {
    140       running = true;
     144      Running = true;
    141145      Canceled = false;
    142146      ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null);
     
    146150    /// of class <see cref="ThreadPool"/>.</remarks>
    147151    public void Step() {
    148       running = true;
     152      Running = true;
    149153      Canceled = false;
    150154      ThreadPool.QueueUserWorkItem(new WaitCallback(RunStep), null);
     
    167171      }
    168172      ExecutionTime += DateTime.Now - start;
    169       running = false;
    170173      OnStopped();
    171174    }
     
    176179        ProcessNextOperator();
    177180      ExecutionTime += DateTime.Now - start;
    178       running = false;
    179181      OnStopped();
    180182    }
     
    197199    }
    198200    /// <summary>
     201    /// Occurs when the running flag changed.
     202    /// </summary>
     203    public event EventHandler RunningChanged;
     204    /// <summary>
     205    /// Fires a new <c>RunningChanged</c> event.
     206    /// </summary>
     207    protected virtual void OnRunningChanged() {
     208      if (RunningChanged != null)
     209        RunningChanged(this, EventArgs.Empty);
     210    }
     211    /// <summary>
    199212    /// Occurs when the execution is prepared for a new run.
    200213    /// </summary>
     
    228241      if (Stopped != null)
    229242        Stopped(this, EventArgs.Empty);
     243      Canceled = false;
     244      Running = false;
    230245    }
    231246    protected virtual void OnCanceledChanged() { }
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IEngine.cs

    r2916 r3226  
    6666    event EventHandler ExecutionTimeChanged;
    6767    /// <summary>
     68    /// Occurs when the running flag was changed.
     69    /// </summary>
     70    event EventHandler RunningChanged;
     71    /// <summary>
    6872    /// Occurs when the engine is prepared for a new run.
    6973    /// </summary>
  • trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r3193 r3226  
    9191    <Compile Include="Assigner.cs" />
    9292    <Compile Include="AlgorithmOperator.cs" />
    93     <Compile Include="ResultsCollector.cs" />
    9493    <Compile Include="MultipleCallsOperator.cs" />
    9594    <Compile Include="Operator.cs" />
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj

    r3094 r3226  
    8282  <ItemGroup>
    8383    <Compile Include="ProbabilisticQualityComparator.cs" />
     84    <Compile Include="ResultsCollector.cs" />
    8485    <Compile Include="SquareRootDiscreteDoubleValueModifier.cs" />
    8586    <Compile Include="DiscreteDoubleValueModifier.cs" />
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/ResultsCollector.cs

    r3225 r3226  
    2121
    2222using HeuristicLab.Core;
     23using HeuristicLab.Operators;
    2324using HeuristicLab.Parameters;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
    26 namespace HeuristicLab.Operators {
     27namespace HeuristicLab.Optimization.Operators {
    2728  /// <summary>
    28   /// An operator which collects the actual values of parameters and adds them to a collection of variables.
     29  /// An operator which collects the actual values of parameters and adds them to a collection of results.
    2930  /// </summary>
    30   [Item("ResultsCollector", "An operator which collects the actual values of parameters and adds them to a collection of variables.")]
     31  [Item("ResultsCollector", "An operator which collects the actual values of parameters and adds them to a collection of results.")]
    3132  [StorableClass]
    3233  public class ResultsCollector : ValuesCollector {
    33     public ValueLookupParameter<VariableCollection> ResultsParameter {
    34       get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
     34    public ValueLookupParameter<ResultCollection> ResultsParameter {
     35      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    3536    }
    3637
    3738    public ResultsCollector()
    3839      : base() {
    39       Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where the collected values should be stored."));
     40      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the collected values should be stored."));
    4041    }
    4142
    4243    public override IOperation Apply() {
    43       VariableCollection results = ResultsParameter.ActualValue;
    44       IVariable var;
     44      ResultCollection results = ResultsParameter.ActualValue;
     45      IResult result;
    4546      foreach (IParameter param in CollectedValues) {
    4647        IItem value = param.ActualValue;
    4748        if (value != null) {
    48           results.TryGetValue(param.Name, out var);
    49           if (var != null)
    50             var.Value = value;
     49          results.TryGetValue(param.Name, out result);
     50          if (result != null)
     51            result.Value = value;
    5152          else
    52             results.Add(new Variable(param.Name, param.Description, value));
     53            results.Add(new Result(param.Name, param.Description, value));
    5354        }
    5455      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.Designer.cs

    r3225 r3226  
    5555      this.problemViewHost = new HeuristicLab.Core.Views.ViewHost();
    5656      this.resultsTabPage = new System.Windows.Forms.TabPage();
    57       this.resultsView = new HeuristicLab.Core.Views.VariableCollectionView();
     57      this.resultsView = new HeuristicLab.Optimization.Views.ResultCollectionView();
    5858      this.startButton = new System.Windows.Forms.Button();
    5959      this.stopButton = new System.Windows.Forms.Button();
     
    192192                  | System.Windows.Forms.AnchorStyles.Left)
    193193                  | System.Windows.Forms.AnchorStyles.Right)));
    194       this.resultsView.Caption = "VariableCollection";
     194      this.resultsView.Caption = "ResultsCollection";
    195195      this.resultsView.Content = null;
    196196      this.resultsView.Location = new System.Drawing.Point(6, 6);
     
    319319    protected System.Windows.Forms.SaveFileDialog saveFileDialog;
    320320    protected System.Windows.Forms.TabPage resultsTabPage;
    321     protected HeuristicLab.Core.Views.VariableCollectionView resultsView;
     321    protected HeuristicLab.Optimization.Views.ResultCollectionView resultsView;
    322322
    323323  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r3177 r3226  
    108108        problemViewHost.ViewType = null;
    109109        problemViewHost.Content = Content.Problem;
    110         resultsView.Content = Content.Results;
     110        resultsView.Content = Content.Results.AsReadOnly();
    111111        tabControl.Enabled = true;
    112112        startButton.Enabled = !Content.Finished;
     
    127127        Invoke(new EventHandler(Content_Prepared), sender, e);
    128128      else {
    129         resultsView.Content = Content.Results;
     129        resultsView.Content = Content.Results.AsReadOnly();
    130130        startButton.Enabled = !Content.Finished;
    131131        UpdateExecutionTimeTextBox();
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r2900 r3226  
    9292      <DependentUpon>AlgorithmView.cs</DependentUpon>
    9393    </Compile>
     94    <Compile Include="BatchRunView.cs">
     95      <SubType>UserControl</SubType>
     96    </Compile>
     97    <Compile Include="BatchRunView.Designer.cs">
     98      <DependentUpon>BatchRunView.cs</DependentUpon>
     99    </Compile>
     100    <Compile Include="ResultCollectionListView.cs">
     101      <SubType>UserControl</SubType>
     102    </Compile>
     103    <Compile Include="ResultCollectionListView.Designer.cs">
     104      <DependentUpon>ResultCollectionListView.cs</DependentUpon>
     105    </Compile>
    94106    <Compile Include="UserDefinedAlgorithmView.cs">
    95107      <SubType>UserControl</SubType>
     
    112124    </Compile>
    113125    <Compile Include="Properties\AssemblyInfo.cs" />
     126    <Compile Include="ResultCollectionView.cs">
     127      <SubType>UserControl</SubType>
     128    </Compile>
     129    <Compile Include="ResultCollectionView.Designer.cs">
     130      <DependentUpon>ResultCollectionView.cs</DependentUpon>
     131    </Compile>
     132    <Compile Include="ResultView.cs">
     133      <SubType>UserControl</SubType>
     134    </Compile>
     135    <Compile Include="ResultView.Designer.cs">
     136      <DependentUpon>ResultView.cs</DependentUpon>
     137    </Compile>
    114138  </ItemGroup>
    115139  <ItemGroup>
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs

    r3107 r3226  
    6666    }
    6767
    68     public abstract IObservableKeyedCollection<string, IVariable> Results { get; }
     68    public abstract ResultCollection Results { get; }
    6969
    7070    public abstract TimeSpan ExecutionTime { get; }
     
    7373    public bool Running {
    7474      get { return running; }
     75      protected set {
     76        if (running != value) {
     77          running = value;
     78          OnRunningChanged();
     79        }
     80      }
    7581    }
    7682
     
    98104      clone.Problem = (IProblem)cloner.Clone(problem);
    99105      clone.running = running;
    100       clone.Canceled = canceled;
     106      clone.canceled = canceled;
    101107      return clone;
    102108    }
    103109
    104110    public void Prepare() {
    105       running = false;
    106       Canceled = false;
    107111      OnPrepared();
    108112    }
    109113    public void Start() {
    110       running = true;
     114      Running = true;
    111115      Canceled = false;
    112116      OnStarted();
     
    127131        ExecutionTimeChanged(this, EventArgs.Empty);
    128132    }
     133    public event EventHandler RunningChanged;
     134    protected virtual void OnRunningChanged() {
     135      if (RunningChanged != null)
     136        RunningChanged(this, EventArgs.Empty);
     137    }
    129138    public event EventHandler Prepared;
    130139    protected virtual void OnPrepared() {
     
    141150      if (Stopped != null)
    142151        Stopped(this, EventArgs.Empty);
     152      Canceled = false;
     153      Running = false;
    143154    }
    144155    protected virtual void OnCanceledChanged() { }
  • trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r3017 r3226  
    8888    }
    8989
    90     private ReadOnlyObservableKeyedCollection<string, IVariable> readOnlyResults;
    91     public override IObservableKeyedCollection<string, IVariable> Results {
     90    public override ResultCollection Results {
    9291      get {
    93         if (readOnlyResults == null)
    94           readOnlyResults = ((VariableCollection)globalScope.Variables["Results"].Value).AsReadOnly();
    95         return readOnlyResults;
     92        return (ResultCollection)globalScope.Variables["Results"].Value;
    9693      }
    9794    }
     
    114111      : base() {
    115112      globalScope = new Scope("Global Scope");
    116       globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
     113      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    117114      OperatorGraph = new OperatorGraph();
    118115      InitializeEngine();
     
    121118      : base(name) {
    122119      globalScope = new Scope("Global Scope");
    123       globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
     120      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    124121      OperatorGraph = new OperatorGraph();
    125122      InitializeEngine();
     
    128125      : base(name, parameters) {
    129126      globalScope = new Scope("Global Scope");
    130       globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
     127      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    131128      OperatorGraph = new OperatorGraph();
    132129      InitializeEngine();
     
    135132      : base(name, description) {
    136133      globalScope = new Scope("Global Scope");
    137       globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
     134      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    138135      OperatorGraph = new OperatorGraph();
    139136      InitializeEngine();
     
    142139      : base(name, description, parameters) {
    143140      globalScope = new Scope("Global Scope");
    144       globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
     141      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    145142      OperatorGraph = new OperatorGraph();
    146143      InitializeEngine();
     
    181178    protected override void OnPrepared() {
    182179      globalScope.Clear();
    183       globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
    184       readOnlyResults = null;
     180      globalScope.Variables.Add(new Variable("Results", new ResultCollection()));
    185181
    186182      if (engine != null) {
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3107 r3226  
    8686    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
    8787    <Compile Include="Algorithm.cs" />
     88    <Compile Include="BatchRun.cs" />
     89    <Compile Include="ResultCollectionList.cs" />
    8890    <Compile Include="Interfaces\IMultiObjectiveSolutionsVisualizer.cs" />
     91    <Compile Include="Interfaces\IResult.cs" />
    8992    <Compile Include="Interfaces\ISingleObjectiveSolutionsVisualizer.cs" />
    9093    <Compile Include="Interfaces\ISolutionsVisualizer.cs" />
     
    114117    <Compile Include="Interfaces\ITabuMoveEvaluator.cs" />
    115118    <Compile Include="Interfaces\ITabuMoveMaker.cs" />
     119    <Compile Include="Result.cs" />
    116120    <Compile Include="TabuMoveMaker.cs" />
    117121    <Compile Include="UserDefinedAlgorithm.cs" />
     
    119123    <Compile Include="HeuristicLabOptimizationPlugin.cs" />
    120124    <Compile Include="Properties\AssemblyInfo.cs" />
     125    <Compile Include="ResultCollection.cs" />
    121126  </ItemGroup>
    122127  <ItemGroup>
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IAlgorithm.cs

    r2882 r3226  
    3232    Type ProblemType { get; }
    3333    IProblem Problem { get; set; }
    34     IObservableKeyedCollection<string, IVariable> Results { get; }
     34    ResultCollection Results { get; }
    3535    TimeSpan ExecutionTime { get; }
    3636    bool Running { get; }
     
    4343    event EventHandler ProblemChanged;
    4444    event EventHandler ExecutionTimeChanged;
     45    event EventHandler RunningChanged;
    4546    event EventHandler Prepared;
    4647    event EventHandler Started;
  • trunk/sources/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj

    r3202 r3226  
    137137    <None Include="app.config" />
    138138    <EmbeddedResource Include="Documents\FirstSteps.rtf" />
    139     <EmbeddedResource Include="Documents\GA_TSP.hl" />
    140     <EmbeddedResource Include="Documents\LS_OneMax.hl" />
    141     <EmbeddedResource Include="Documents\SA_Rastrigin.hl" />
    142139    <None Include="HeuristicLab.snk" />
    143140    <None Include="Properties\AssemblyInfo.frame" />
     
    178175  </ItemGroup>
    179176  <ItemGroup>
     177    <EmbeddedResource Include="Documents\GA_TSP.hl" />
    180178    <EmbeddedResource Include="Properties\Resources.resx">
    181179      <Generator>ResXFileCodeGenerator</Generator>
  • trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs

    r3017 r3226  
    6060        catch (Exception ex) {
    6161          ExecutionStack.Push(operation);
     62          OnExceptionOccurred(ex);
    6263          Stop();
    63           OnExceptionOccurred(ex);
    6464        }
    6565        if (operation.Operator.Breakpoint)
Note: See TracChangeset for help on using the changeset viewer.