Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12804


Ignore:
Timestamp:
07/26/15 21:32:52 (9 years ago)
Author:
abeham
Message:

#2431:

  • worked on IRRRun (early abort still troublesome)
  • Updated RLD view to allow defining targets
  • Attempting to handle maximization/minimization
Location:
branches/PerformanceComparison
Files:
7 edited
2 copied
1 moved

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r12771 r12804  
    199199    <Compile Include="MultiObjective\RankBasedParetoFrontAnalyzer.cs" />
    200200    <Compile Include="MultiObjective\ParetoFrontAnalyzer.cs" />
     201    <Compile Include="Optimizers\IRRestarter.cs" />
    201202    <Compile Include="Plugin.cs" />
    202203    <Compile Include="PopulationSimilarityAnalysis\PopulationDiversityAnalyzer.cs" />
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Optimizers/IRRestarter.cs

    r12803 r12804  
    3737  /// A run in which an algorithm is executed for a certain maximum time only.
    3838  /// </summary>
    39   [Item("Independent Random Restart Run", "A run in which an optimizer is repeated until either a certain target value is reached or a maximum budget is exceeded.")]
     39  [Item("Independent Random Restarter", "An optimizer that repeats an algorithm until either a certain target value is reached or a maximum budget is exceeded.")]
    4040  [Creatable(CreatableAttribute.Categories.TestingAndAnalysis, Priority = 117)]
    4141  [StorableClass]
    42   public sealed class IndepdentRandomRestartRun : NamedItem, IOptimizer, IStorableContent, INotifyPropertyChanged {
     42  public sealed class IndepdentRandomRestarter : NamedItem, IOptimizer, IStorableContent, INotifyPropertyChanged {
     43    private const string ExecutionTimeResultName = "Execution Time";
     44    private const string BestQualityResultName = "BestQuality";
     45
    4346    public string Filename { get; set; }
    4447
     
    100103    public bool Maximization {
    101104      get { return maximization; }
    102       private set {
     105      set {
    103106        if (maximization == value) return;
    104107        maximization = value;
     
    114117        if (moveCostPerSolution == value) return;
    115118        moveCostPerSolution = value;
     119        perEvaluationsAnalyzer.MoveCostPerSolutionParameter.Value = new DoubleValue(moveCostPerSolution);
    116120        OnPropertyChanged("MoveCostPerSolution");
    117121      }
    118122    }
    119123
    120 
     124    [Storable]
     125    private QualityPerClockAnalyzer perClockAnalyzer;
     126    [Storable]
     127    private QualityPerEvaluationsAnalyzer perEvaluationsAnalyzer;
     128
     129    [Storable]
     130    private ExecutionState executionState;
    121131    public ExecutionState ExecutionState {
    122       get { return (Algorithm != null) ? Algorithm.ExecutionState : ExecutionState.Stopped; }
     132      get { return executionState; }
     133      private set {
     134        if (executionState != value) {
     135          executionState = value;
     136          OnExecutionStateChanged();
     137          OnItemImageChanged();
     138        }
     139      }
    123140    }
    124141
     
    176193      get { return algorithm; }
    177194      set {
     195        if (value != null && !typeof(ISingleObjectiveHeuristicOptimizationProblem).IsAssignableFrom(value.ProblemType))
     196          throw new ArgumentException("Algorithm is not single-objective!");
    178197        if (algorithm == value) return;
    179         if (algorithm != null) DeregisterAlgorithmEvents();
     198        if (algorithm != null) {
     199          DeregisterAlgorithmEvents();
     200          RemoveAlgorithmAnalyzers();
     201        }
    180202        algorithm = value;
    181203        if (algorithm != null) {
    182204          RegisterAlgorithmEvents();
     205          AddAlgorithmAnalyzers();
    183206        }
    184207        OnPropertyChanged("Algorithm");
     
    228251    }
    229252
     253    private ISingleObjectiveHeuristicOptimizationProblem problem;
     254
    230255    [StorableConstructor]
    231     private IndepdentRandomRestartRun(bool deserializing) : base(deserializing) { }
    232     private IndepdentRandomRestartRun(IndepdentRandomRestartRun original, Cloner cloner)
     256    private IndepdentRandomRestarter(bool deserializing) : base(deserializing) { }
     257    private IndepdentRandomRestarter(IndepdentRandomRestarter original, Cloner cloner)
    233258      : base(original, cloner) {
    234259      terminationCriterium = original.terminationCriterium;
    235260      maximumExecutionTime = original.maximumExecutionTime;
    236261      maximumEvaluations = original.maximumEvaluations;
     262      moveCostPerSolution = original.moveCostPerSolution;
    237263      targetValue = original.targetValue;
     264      maximization = original.maximization;
    238265      executionTime = original.executionTime;
    239266      evaluations = original.evaluations;
     
    243270      lastAlgorithmEvaluatedMoves = original.lastAlgorithmEvaluatedMoves;
    244271
     272      perClockAnalyzer = cloner.Clone(original.perClockAnalyzer);
     273      perEvaluationsAnalyzer = cloner.Clone(original.perEvaluationsAnalyzer);
     274
    245275      algorithm = cloner.Clone(original.algorithm);
    246276      runs = cloner.Clone(original.runs);
    247277
     278      ExecutionState = original.ExecutionState;
     279
    248280      Initialize();
    249281    }
    250     public IndepdentRandomRestartRun()
     282    public IndepdentRandomRestarter()
    251283      : base() {
    252284      name = ItemName;
    253285      description = ItemDescription;
    254       terminationCriterium = TerminationCriterium.OnlyByEvaluations;
     286      terminationCriterium = TerminationCriterium.ByTargetAndEvaluations;
    255287      maximumExecutionTime = TimeSpan.FromMinutes(1);
    256288      maximumEvaluations = 10000000; // 10 mio
     289      moveCostPerSolution = 1;
    257290      targetValue = 0;
     291      maximization = false;
    258292      executionTime = TimeSpan.Zero;
    259293      evaluations = 0;
     
    263297      lastAlgorithmEvaluatedMoves = 0;
    264298
     299      perClockAnalyzer = new QualityPerClockAnalyzer();
     300      perEvaluationsAnalyzer = new QualityPerEvaluationsAnalyzer();
     301
    265302      Runs = new RunCollection { OptimizerName = Name };
    266303      Initialize();
    267304    }
    268     public IndepdentRandomRestartRun(string name)
     305    public IndepdentRandomRestarter(string name)
    269306      : base(name) {
    270307      description = ItemDescription;
    271       terminationCriterium = TerminationCriterium.OnlyByEvaluations;
     308      terminationCriterium = TerminationCriterium.ByTargetAndEvaluations;
    272309      maximumExecutionTime = TimeSpan.FromMinutes(1);
    273310      maximumEvaluations = 10000000; // 10 mio
     311      moveCostPerSolution = 1;
    274312      targetValue = 0;
     313      maximization = false;
    275314      executionTime = TimeSpan.Zero;
    276315      evaluations = 0;
     
    280319      lastAlgorithmEvaluatedMoves = 0;
    281320
     321      perClockAnalyzer = new QualityPerClockAnalyzer();
     322      perEvaluationsAnalyzer = new QualityPerEvaluationsAnalyzer();
     323
    282324      Runs = new RunCollection { OptimizerName = Name };
    283325      Initialize();
    284326    }
    285     public IndepdentRandomRestartRun(string name, string description)
     327    public IndepdentRandomRestarter(string name, string description)
    286328      : base(name, description) {
    287       terminationCriterium = TerminationCriterium.OnlyByEvaluations;
     329      terminationCriterium = TerminationCriterium.ByTargetAndEvaluations;
    288330      maximumExecutionTime = TimeSpan.FromMinutes(1);
    289331      maximumEvaluations = 10000000; // 10 mio
     332      moveCostPerSolution = 1;
    290333      targetValue = 0;
     334      maximization = false;
    291335      executionTime = TimeSpan.Zero;
    292336      evaluations = 0;
     
    296340      lastAlgorithmEvaluatedMoves = 0;
    297341
     342      perClockAnalyzer = new QualityPerClockAnalyzer();
     343      perEvaluationsAnalyzer = new QualityPerEvaluationsAnalyzer();
     344
    298345      Runs = new RunCollection { OptimizerName = Name };
    299346      Initialize();
     
    302349    public override IDeepCloneable Clone(Cloner cloner) {
    303350      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    304       return new IndepdentRandomRestartRun(this, cloner);
     351      return new IndepdentRandomRestarter(this, cloner);
    305352    }
    306353
     
    314361    }
    315362
     363    private void Reset() {
     364      ExecutionTime = TimeSpan.Zero;
     365      Evaluations = 0;
     366      BestSoFar = double.NaN;
     367      lastAlgorithmExecutionTime = TimeSpan.Zero;
     368      lastAlgorithmEvaluatedSolutions = 0;
     369      lastAlgorithmEvaluatedMoves = 0;
     370
     371      CurrentRun = null;
     372    }
     373
    316374    public void Prepare() {
    317375      Prepare(false);
    318376    }
    319377    public void Prepare(bool clearRuns) {
    320       executionTime = TimeSpan.Zero;
    321       evaluations = 0;
    322       lastAlgorithmExecutionTime = TimeSpan.Zero;
    323       lastAlgorithmEvaluatedSolutions = 0;
    324 
    325       Algorithm.Prepare(clearRuns);
     378      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped))
     379        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
     380      Reset();
     381
     382      if (Algorithm != null) {
     383        Algorithm.Prepare(clearRuns);
     384        ExecutionState = ExecutionState.Prepared;
     385        OnPrepared();
     386      }
    326387    }
    327388    public void Start() {
     389      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
     390        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     391
    328392      if (ExecutionState == ExecutionState.Prepared) {
    329         currentRun = new Run(Algorithm) {
     393        CurrentRun = new Run(Algorithm) {
    330394          Name = Algorithm.Name + " IRRRun" + Runs.Count
    331395        };
     396        if (!CurrentRun.Results.ContainsKey(ExecutionTimeResultName))
     397          CurrentRun.Results.Add(ExecutionTimeResultName, new TimeSpanValue(TimeSpan.Zero));
     398        CurrentRun.Results.Add(perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName, new IntValue(0));
     399        CurrentRun.Results.Add(perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName, new IntValue(0));
     400        CurrentRun.Results.Add(BestQualityResultName, new DoubleValue(Maximization ? double.MinValue : double.MaxValue));
    332401      }
    333402      Algorithm.Start();
     403      ExecutionState = ExecutionState.Started;
     404      OnStarted();
    334405    }
    335406    public void Pause() {
     407      if (ExecutionState != ExecutionState.Started)
     408        throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState));
    336409      Algorithm.Pause();
    337     }
     410      ExecutionState = ExecutionState.Paused;
     411      OnPaused();
     412    }
     413
     414    private bool forceStop = false;
    338415    public void Stop() {
     416      if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused))
     417        throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState));
     418      forceStop = true;
    339419      Algorithm.Stop();
     420    }
     421
     422    private void AddAlgorithmAnalyzers() {
     423      if (!Algorithm.Parameters.ContainsKey("Analyzer")) return;
     424      var analyzerParam = Algorithm.Parameters["Analyzer"] as IValueParameter<MultiAnalyzer>;
     425      if (analyzerParam == null) return;
     426      if (!analyzerParam.Value.Operators.Contains(perClockAnalyzer))
     427        analyzerParam.Value.Operators.Add(perClockAnalyzer);
     428      if (!analyzerParam.Value.Operators.Contains(perEvaluationsAnalyzer))
     429        analyzerParam.Value.Operators.Add(perEvaluationsAnalyzer);
     430    }
     431
     432    private void RemoveAlgorithmAnalyzers() {
     433      if (!Algorithm.Parameters.ContainsKey("Analyzer")) return;
     434      var analyzerParam = Algorithm.Parameters["Analyzer"] as IValueParameter<MultiAnalyzer>;
     435      if (analyzerParam == null) return;
     436      analyzerParam.Value.Operators.Remove(perClockAnalyzer);
     437      analyzerParam.Value.Operators.Remove(perEvaluationsAnalyzer);
    340438    }
    341439
     
    400498      algorithm.Stopped += Algorithm_Stopped;
    401499      algorithm.ProblemChanged += Algorithm_ProblemChanged;
     500      Algorithm_ProblemChanged(algorithm, EventArgs.Empty);
    402501    }
    403502    private void DeregisterAlgorithmEvents() {
     
    415514    }
    416515    private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {
    417       ExecutionTime += Algorithm.ExecutionTime - lastAlgorithmExecutionTime;
    418       lastAlgorithmExecutionTime = Algorithm.ExecutionTime;
    419 
    420       UpdateAlgorithmResults();
    421 
    422       if (IsFinished) {
     516      if (Algorithm.ExecutionState != ExecutionState.Started) return;
     517
     518      if (ExecutionState == ExecutionState.Started)
     519        UpdateAlgorithmResults();
     520
     521      if (IsFinished && ExecutionState != ExecutionState.Stopped) {
    423522        Algorithm.Stop();
    424523      }
     
    427526
    428527    private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {
    429       OnExecutionStateChanged();
     528      //OnExecutionStateChanged();
    430529    }
    431530    private void Algorithm_Paused(object sender, EventArgs e) {
    432       ExecutionTime += Algorithm.ExecutionTime - lastAlgorithmExecutionTime;
    433       lastAlgorithmExecutionTime = Algorithm.ExecutionTime;
    434 
    435531      UpdateAlgorithmResults();
    436532      OnPaused();
    437533    }
    438534    private void Algorithm_Prepared(object sender, EventArgs e) {
    439       OnPrepared();
     535      lastAlgorithmEvaluatedSolutions = 0;
     536      lastAlgorithmEvaluatedMoves = 0;
     537      lastAlgorithmExecutionTime = TimeSpan.Zero;
    440538    }
    441539    private void Algorithm_Started(object sender, EventArgs e) {
    442       OnStarted();
     540      //OnStarted();
    443541    }
    444542    private void Algorithm_Stopped(object sender, EventArgs e) {
    445       ExecutionTime += Algorithm.ExecutionTime - lastAlgorithmExecutionTime;
    446       lastAlgorithmExecutionTime = Algorithm.ExecutionTime;
    447 
    448543      var bestQuality = UpdateAlgorithmResults();
    449544
     545      var execTime = ((TimeSpanValue)currentRun.Results[ExecutionTimeResultName]).Value;
    450546      foreach (var result in Algorithm.Results) {
    451         if (result.Name == "QualityPerClock") {
     547        if (result.Name == perClockAnalyzer.QualityPerClockParameter.ResultName) {
    452548          if (!currentRun.Results.ContainsKey(result.Name))
    453549            currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    454550          else {
    455551            var dt = (IndexedDataTable<double>)currentRun.Results[result.Name];
    456             var execTime = ((TimeSpanValue)currentRun.Results["ExecutionTime"]).Value.TotalSeconds;
    457552            var best = dt.Rows.First().Values.Last().Item2;
    458553            var resultDt = (IndexedDataTable<double>)result.Value;
    459554            foreach (var tupl in resultDt.Rows.First().Values) {
    460555              if (Maximization && tupl.Item2 > best || !Maximization && tupl.Item2 < best) {
    461                 dt.Rows.First().Values.Add(Tuple.Create(execTime + tupl.Item1, tupl.Item2));
     556                dt.Rows.First().Values.Add(Tuple.Create(execTime.TotalSeconds + tupl.Item1, tupl.Item2));
    462557                best = tupl.Item2;
    463558              }
    464559            }
    465560          }
    466         } else if (result.Name == "QualityPerEvaluations") {
     561        } else if (result.Name == perEvaluationsAnalyzer.QualityPerEvaluationsParameter.ResultName) {
    467562          if (!currentRun.Results.ContainsKey(result.Name))
    468563            currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    469564          else {
    470565            var dt = (IndexedDataTable<double>)currentRun.Results[result.Name];
    471             var evalSols = ((DoubleValue)currentRun.Results["EvaluatedSolutions"]).Value;
    472             var evalMoves = ((DoubleValue)currentRun.Results["EvaluatedMoves"]).Value;
     566            var evalSols = ((IntValue)currentRun.Results[perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName]).Value;
     567            var evalMoves = ((IntValue)currentRun.Results[perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName]).Value;
    473568            var best = dt.Rows.First().Values.Last().Item2;
    474569            var resultDt = (IndexedDataTable<double>)result.Value;
     
    480575            }
    481576          }
    482         } else if (result.Name == "EvaluatedSolutions") {
    483           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    484         } else if (result.Name == "EvaluatedMoves") {
    485           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    486         } else if (result.Name == "ExecutionTime") {
    487           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    488         } else if (result.Name == "BestQuality") {
    489           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
     577        } else if (result.Name == perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName) {
     578          var evalSols = ((IntValue)currentRun.Results[perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName]);
     579          evalSols.Value += ((IntValue)result.Value).Value;
     580        } else if (result.Name == perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName) {
     581          var evalMoves = ((IntValue)currentRun.Results[perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName]);
     582          evalMoves.Value += ((IntValue)result.Value).Value;
     583        } else if (result.Name == perEvaluationsAnalyzer.BestQualityParameter.ActualName) {
     584          var best = ((DoubleValue)currentRun.Results[BestQualityResultName]).Value;
     585          if (Maximization && best < bestQuality || !Maximization && best > bestQuality)
     586            currentRun.Results[BestQualityResultName] = new DoubleValue(bestQuality);
    490587        } else if (result.Name.ToLower().EndsWith("solution") && BestSoFar == bestQuality) {
    491           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
     588          if (currentRun.Results.ContainsKey(result.Name))
     589            currentRun.Results[result.Name] = (IItem)result.Value.Clone();
     590          else currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    492591        }
    493592      }
    494       foreach (var result in Algorithm.Results) {
    495         if (result.Name == "QualityPerClock") {
    496 
    497         } else if (result.Name == "QualityPerEvaluations") {
    498         } else if (result.Name == "EvaluatedSolutions") {
    499           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    500         } else if (result.Name == "EvaluatedMoves") {
    501           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    502         } else if (result.Name == "ExecutionTime") {
    503           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    504         } else if (result.Name == "BestQuality") {
    505           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    506         } else if (result.Name.ToLower().EndsWith("solution") && BestSoFar == bestQuality) {
    507           currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());
    508         }
    509       }
    510 
    511 
    512       if (IsFinished) {
    513 
    514       }
    515 
    516       // TODO
    517       var cloner = new Cloner();
    518       var algRun = cloner.Clone(Algorithm.Runs.Last());
    519       Runs.Add(algRun);
    520       Algorithm.Runs.Clear();
    521       OnStopped();
     593      currentRun.Results[ExecutionTimeResultName] = new TimeSpanValue(execTime + Algorithm.ExecutionTime);
     594
     595      if (!forceStop && !IsFinished) {
     596        Algorithm.Prepare();
     597        Algorithm.Start();
     598      } else {
     599        forceStop = false;
     600        Runs.Add(currentRun);
     601        currentRun = null;
     602        Algorithm.Prepare(true);
     603        ExecutionState = ExecutionState.Stopped;
     604        OnStopped();
     605      }
    522606    }
    523607
    524608    private double UpdateAlgorithmResults() {
     609      ExecutionTime += Algorithm.ExecutionTime - lastAlgorithmExecutionTime;
     610      lastAlgorithmExecutionTime = Algorithm.ExecutionTime;
     611
    525612      IResult evaluationsResult;
    526       if (Algorithm.Results.TryGetValue("EvaluatedSolutions", out evaluationsResult)) {
     613      if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName, out evaluationsResult)) {
    527614        var evals = ((IntValue)evaluationsResult.Value).Value;
    528615        Evaluations += evals - lastAlgorithmEvaluatedSolutions;
    529616        lastAlgorithmEvaluatedSolutions = evals;
    530617      }
    531       if (Algorithm.Results.TryGetValue("EvaluatedMoves", out evaluationsResult)) {
     618      if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName, out evaluationsResult)) {
    532619        var evals = ((IntValue)evaluationsResult.Value).Value;
    533620        Evaluations += moveCostPerSolution * (evals - lastAlgorithmEvaluatedMoves);
    534621        lastAlgorithmEvaluatedMoves = evals;
    535622      }
    536       if (Algorithm.Results.TryGetValue("BestQuality", out evaluationsResult)) {
    537         var bestQuality = ((DoubleValue)evaluationsResult).Value;
     623      if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.BestQualityParameter.ActualName, out evaluationsResult)) {
     624        var bestQuality = ((DoubleValue)evaluationsResult.Value).Value;
    538625        if (double.IsNaN(BestSoFar)
    539626            || Maximization && bestQuality > BestSoFar
     
    546633
    547634    private void Algorithm_ProblemChanged(object sender, EventArgs e) {
    548       var soProblem = Algorithm.Problem as ISingleObjectiveHeuristicOptimizationProblem;
    549       if (soProblem == null) return;
    550       var maxParam = soProblem.MaximizationParameter as IValueParameter<BoolValue>;
     635      if (problem != null) DeregisterProblemEvents();
     636
     637      problem = Algorithm.Problem as ISingleObjectiveHeuristicOptimizationProblem;
     638      if (problem == null) return;
     639      RegisterProblemEvents();
     640
     641      AddAlgorithmAnalyzers();
     642
     643      var maxParam = problem.MaximizationParameter as IValueParameter<BoolValue>;
    551644      if (maxParam != null)
    552645        Maximization = maxParam.Value.Value;
    553       var bkParam = soProblem.BestKnownQualityParameter as IValueParameter<DoubleValue>;
     646      var bkParam = problem.BestKnownQualityParameter as IValueParameter<DoubleValue>;
    554647      if (bkParam != null && bkParam.Value != null)
    555648        TargetValue = bkParam.Value.Value;
     649
     650      Reset();
     651    }
     652
     653    private void RegisterProblemEvents() {
     654      problem.Reset += ProblemOnReset;
     655      problem.OperatorsChanged += ProblemOnOperatorsChanged;
     656    }
     657
     658    private void DeregisterProblemEvents() {
     659      problem.Reset -= ProblemOnReset;
     660      problem.OperatorsChanged -= ProblemOnOperatorsChanged;
     661    }
     662
     663    private void ProblemOnReset(object sender, EventArgs eventArgs) {
     664      AddAlgorithmAnalyzers();
     665    }
     666
     667    private void ProblemOnOperatorsChanged(object sender, EventArgs eventArgs) {
     668      AddAlgorithmAnalyzers();
    556669    }
    557670    #endregion
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityPerClockAnalyzer.cs

    r12803 r12804  
    7575
    7676    public override IOperation Apply() {
    77       var lastUpdateTime = LastUpdateTimeParameter.ActualValue;
    78       if (lastUpdateTime == null) {
    79         lastUpdateTime = new DateTimeValue(DateTime.UtcNow.AddMilliseconds(-1));
    80         LastUpdateTimeParameter.ActualValue = lastUpdateTime;
    81       }
    82       var now = DateTime.UtcNow;
    83 
    8477      var bestQuality = BestQualityParameter.ActualValue.Value;
    85 
    8678      var dataTable = QualityPerClockParameter.ResultValue;
    8779      var values = dataTable.Rows["First-hit Graph"].Values;
    88       if (values.Count == 0 || values.Last().Item2 != bestQuality)
    89         dataTable.Rows["First-hit Graph"].Values.Add(Tuple.Create((now - lastUpdateTime.Value).TotalSeconds, bestQuality));
    9080
    91       lastUpdateTime.Value = now;
     81      if (values.Count == 0 || values.Last().Item2 != bestQuality) {
     82        var lastUpdateTime = LastUpdateTimeParameter.ActualValue;
     83        if (lastUpdateTime == null) {
     84          lastUpdateTime = new DateTimeValue(DateTime.UtcNow.AddMilliseconds(-1));
     85          LastUpdateTimeParameter.ActualValue = lastUpdateTime;
     86        }
     87
     88        var now = DateTime.UtcNow;
     89        var runtimeSoFar = (now - lastUpdateTime.Value).TotalSeconds + (values.Count > 0 ? values.Last().Item1 : 0);
     90        dataTable.Rows["First-hit Graph"].Values.Add(Tuple.Create(runtimeSoFar, bestQuality));
     91        lastUpdateTime.Value = now;
     92      }
    9293      return base.Apply();
    9394    }
  • branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/QualityPerEvaluationsAnalyzer.cs

    r12774 r12804  
    4444      get { return (ILookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
    4545    }
     46    public ILookupParameter<IntValue> EvaluatedMovesParameter {
     47      get { return (ILookupParameter<IntValue>)Parameters["EvaluatedMoves"]; }
     48    }
     49    public IValueLookupParameter<DoubleValue> MoveCostPerSolutionParameter {
     50      get { return (IValueLookupParameter<DoubleValue>)Parameters["MoveCostPerSolution"]; }
     51    }
    4652    public IResultParameter<IndexedDataTable<double>> QualityPerEvaluationsParameter {
    4753      get { return (IResultParameter<IndexedDataTable<double>>)Parameters["QualityPerEvaluations"]; }
     
    5460      : base() {
    5561      Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "The quality value that should be compared."));
    56       Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The quality value that should be compared."));
     62      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of evaluated solutions."));
     63      Parameters.Add(new LookupParameter<IntValue>("EvaluatedMoves", "The number of evaluated moves."));
     64      Parameters.Add(new ValueLookupParameter<DoubleValue>("MoveCostPerSolution", "The cost to evaluate a move as a ratio to the cost of evaluating a solution.", new DoubleValue(1)));
    5765      Parameters.Add(new ResultParameter<IndexedDataTable<double>>("QualityPerEvaluations", "Data table containing the first hitting graph with evaluations as the x-axis."));
    5866      QualityPerEvaluationsParameter.DefaultValue = new IndexedDataTable<double>("Quality per Evaluations") {
     
    7482    public override IOperation Apply() {
    7583      var bestQuality = BestQualityParameter.ActualValue.Value;
    76       var evaluations = Math.Max(EvaluatedSolutionsParameter.ActualValue.Value, 1);
     84      var evalSols = EvaluatedSolutionsParameter.ActualValue;
     85      var evalMoves = EvaluatedMovesParameter.ActualValue;
     86      var evaluations = 0.0;
     87      if (evalSols != null) evaluations += evalSols.Value;
     88      if (evalMoves != null) evaluations += evalMoves.Value * MoveCostPerSolutionParameter.ActualValue.Value;
    7789
    7890      var dataTable = QualityPerEvaluationsParameter.ResultValue;
    7991      var values = dataTable.Rows["First-hit Graph"].Values;
     92      if (evaluations == 0 || values.Count > 0 && evaluations < values.Last().Item1) evaluations = 1;
    8093      if (values.Count == 0 || values.Last().Item2 != bestQuality)
    8194        values.Add(Tuple.Create((double)evaluations, bestQuality));
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r12803 r12804  
    223223      <DependentUpon>CreateNewSingleEncodingDialog.cs</DependentUpon>
    224224    </Compile>
     225    <Compile Include="IRRestarterView.cs">
     226      <SubType>UserControl</SubType>
     227    </Compile>
     228    <Compile Include="IRRestarterView.Designer.cs">
     229      <DependentUpon>IRRestarterView.cs</DependentUpon>
     230    </Compile>
    225231    <Compile Include="ISolutionSimilarityCalculatorView.cs">
    226232      <SubType>UserControl</SubType>
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/IRRestarterView.Designer.cs

    r12764 r12804  
    2121
    2222namespace HeuristicLab.Optimization.Views {
    23   partial class TimeLimitRunView {
     23  partial class IndependentRandomRestarterView {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    3434    /// </summary>
    3535    private void InitializeComponent() {
    36       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TimeLimitRunView));
     36      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(IndependentRandomRestarterView));
    3737      this.timeLimitLabel = new System.Windows.Forms.Label();
    38       this.timeLimitTextBox = new System.Windows.Forms.TextBox();
    39       this.label1 = new System.Windows.Forms.Label();
    40       this.snapshotsTextBox = new System.Windows.Forms.TextBox();
    41       this.storeAlgorithmInEachSnapshotCheckBox = new System.Windows.Forms.CheckBox();
     38      this.maxExecutionTimeTextBox = new System.Windows.Forms.TextBox();
     39      this.evaluationsLimitabel = new System.Windows.Forms.Label();
     40      this.maxEvaluationsTextBox = new System.Windows.Forms.TextBox();
    4241      this.tabControl = new HeuristicLab.MainForm.WindowsForms.DragOverTabControl();
    4342      this.algorithmTabPage = new System.Windows.Forms.TabPage();
     
    4544      this.openAlgorithmButton = new System.Windows.Forms.Button();
    4645      this.newAlgorithmButton = new System.Windows.Forms.Button();
    47       this.snapshotsTabPage = new System.Windows.Forms.TabPage();
    48       this.snapshotsView = new HeuristicLab.Optimization.Views.RunCollectionView();
     46      this.currentRunTabPage = new System.Windows.Forms.TabPage();
     47      this.currentRunView = new HeuristicLab.Optimization.Views.RunView();
    4948      this.runsTabPage = new System.Windows.Forms.TabPage();
    5049      this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
    5150      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    52       this.snapshotButton = new System.Windows.Forms.Button();
    53       this.sequenceButton = new System.Windows.Forms.Button();
     51      this.targetValueTextBox = new System.Windows.Forms.TextBox();
     52      this.targetValueLabel = new System.Windows.Forms.Label();
     53      this.terminationComboBox = new System.Windows.Forms.ComboBox();
     54      this.terminationLabel = new System.Windows.Forms.Label();
     55      this.moveCostPerSolutionTextBox = new System.Windows.Forms.TextBox();
     56      this.moveCostPerSolutionLabel = new System.Windows.Forms.Label();
     57      this.maximizationLabel = new System.Windows.Forms.Label();
     58      this.maximizationCheckBox = new System.Windows.Forms.CheckBox();
    5459      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5560      this.tabControl.SuspendLayout();
    5661      this.algorithmTabPage.SuspendLayout();
    57       this.snapshotsTabPage.SuspendLayout();
     62      this.currentRunTabPage.SuspendLayout();
    5863      this.runsTabPage.SuspendLayout();
    5964      this.SuspendLayout();
     
    95100      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    96101      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    97       this.nameTextBox.Location = new System.Drawing.Point(69, 0);
    98       this.nameTextBox.Size = new System.Drawing.Size(455, 20);
     102      this.nameTextBox.Location = new System.Drawing.Point(115, 0);
     103      this.nameTextBox.Size = new System.Drawing.Size(409, 20);
    99104      //
    100105      // infoLabel
     
    107112      this.timeLimitLabel.Location = new System.Drawing.Point(3, 29);
    108113      this.timeLimitLabel.Name = "timeLimitLabel";
    109       this.timeLimitLabel.Size = new System.Drawing.Size(53, 13);
     114      this.timeLimitLabel.Size = new System.Drawing.Size(106, 13);
    110115      this.timeLimitLabel.TabIndex = 3;
    111       this.timeLimitLabel.Text = "Time limit:";
    112       //
    113       // timeLimitTextBox
    114       //
    115       this.timeLimitTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     116      this.timeLimitLabel.Text = "Max Execution Time:";
     117      //
     118      // maxExecutionTimeTextBox
     119      //
     120      this.maxExecutionTimeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    116121            | System.Windows.Forms.AnchorStyles.Right)));
    117       this.timeLimitTextBox.Location = new System.Drawing.Point(69, 26);
    118       this.timeLimitTextBox.Name = "timeLimitTextBox";
    119       this.timeLimitTextBox.Size = new System.Drawing.Size(455, 20);
    120       this.timeLimitTextBox.TabIndex = 4;
    121       this.timeLimitTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.timeLimitTextBox_Validating);
    122       //
    123       // label1
    124       //
    125       this.label1.AutoSize = true;
    126       this.label1.Location = new System.Drawing.Point(3, 55);
    127       this.label1.Name = "label1";
    128       this.label1.Size = new System.Drawing.Size(60, 13);
    129       this.label1.TabIndex = 5;
    130       this.label1.Text = "Snapshots:";
    131       //
    132       // snapshotsTextBox
    133       //
    134       this.snapshotsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    135             | System.Windows.Forms.AnchorStyles.Right)));
    136       this.snapshotsTextBox.Location = new System.Drawing.Point(69, 52);
    137       this.snapshotsTextBox.Name = "snapshotsTextBox";
    138       this.snapshotsTextBox.Size = new System.Drawing.Size(175, 20);
    139       this.snapshotsTextBox.TabIndex = 6;
    140       this.snapshotsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.snapshotsTextBox_Validating);
    141       //
    142       // storeAlgorithmInEachSnapshotCheckBox
    143       //
    144       this.storeAlgorithmInEachSnapshotCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    145       this.storeAlgorithmInEachSnapshotCheckBox.AutoSize = true;
    146       this.storeAlgorithmInEachSnapshotCheckBox.Location = new System.Drawing.Point(340, 54);
    147       this.storeAlgorithmInEachSnapshotCheckBox.Name = "storeAlgorithmInEachSnapshotCheckBox";
    148       this.storeAlgorithmInEachSnapshotCheckBox.Size = new System.Drawing.Size(184, 17);
    149       this.storeAlgorithmInEachSnapshotCheckBox.TabIndex = 7;
    150       this.storeAlgorithmInEachSnapshotCheckBox.Text = "Store Algorithm in Each Snapshot";
    151       this.storeAlgorithmInEachSnapshotCheckBox.UseVisualStyleBackColor = true;
    152       this.storeAlgorithmInEachSnapshotCheckBox.CheckedChanged += new System.EventHandler(this.storeAlgorithmInEachSnapshotCheckBox_CheckedChanged);
     122      this.maxExecutionTimeTextBox.Location = new System.Drawing.Point(115, 26);
     123      this.maxExecutionTimeTextBox.Name = "maxExecutionTimeTextBox";
     124      this.maxExecutionTimeTextBox.Size = new System.Drawing.Size(409, 20);
     125      this.maxExecutionTimeTextBox.TabIndex = 4;
     126      this.maxExecutionTimeTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.maxExecutionTimeTextBox_Validating);
     127      //
     128      // evaluationsLimitabel
     129      //
     130      this.evaluationsLimitabel.AutoSize = true;
     131      this.evaluationsLimitabel.Location = new System.Drawing.Point(3, 55);
     132      this.evaluationsLimitabel.Name = "evaluationsLimitabel";
     133      this.evaluationsLimitabel.Size = new System.Drawing.Size(88, 13);
     134      this.evaluationsLimitabel.TabIndex = 5;
     135      this.evaluationsLimitabel.Text = "Max Evaluations:";
     136      //
     137      // maxEvaluationsTextBox
     138      //
     139      this.maxEvaluationsTextBox.Location = new System.Drawing.Point(115, 52);
     140      this.maxEvaluationsTextBox.Name = "maxEvaluationsTextBox";
     141      this.maxEvaluationsTextBox.Size = new System.Drawing.Size(157, 20);
     142      this.maxEvaluationsTextBox.TabIndex = 6;
     143      this.maxEvaluationsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.maxEvaluationsTextBox_Validating);
    153144      //
    154145      // tabControl
     
    159150            | System.Windows.Forms.AnchorStyles.Right)));
    160151      this.tabControl.Controls.Add(this.algorithmTabPage);
    161       this.tabControl.Controls.Add(this.snapshotsTabPage);
     152      this.tabControl.Controls.Add(this.currentRunTabPage);
    162153      this.tabControl.Controls.Add(this.runsTabPage);
    163       this.tabControl.Location = new System.Drawing.Point(0, 78);
     154      this.tabControl.Location = new System.Drawing.Point(0, 132);
    164155      this.tabControl.Name = "tabControl";
    165156      this.tabControl.SelectedIndex = 0;
    166       this.tabControl.Size = new System.Drawing.Size(546, 356);
     157      this.tabControl.Size = new System.Drawing.Size(546, 302);
    167158      this.tabControl.TabIndex = 8;
    168159      //
     
    176167      this.algorithmTabPage.Name = "algorithmTabPage";
    177168      this.algorithmTabPage.Padding = new System.Windows.Forms.Padding(3);
    178       this.algorithmTabPage.Size = new System.Drawing.Size(538, 330);
     169      this.algorithmTabPage.Size = new System.Drawing.Size(538, 276);
    179170      this.algorithmTabPage.TabIndex = 1;
    180171      this.algorithmTabPage.Text = "Algorithm";
     
    195186      this.algorithmViewHost.Name = "algorithmViewHost";
    196187      this.algorithmViewHost.ReadOnly = false;
    197       this.algorithmViewHost.Size = new System.Drawing.Size(526, 288);
     188      this.algorithmViewHost.Size = new System.Drawing.Size(526, 234);
    198189      this.algorithmViewHost.TabIndex = 2;
    199190      this.algorithmViewHost.ViewsLabelVisible = true;
     
    202193      // openAlgorithmButton
    203194      //
    204       this.openAlgorithmButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Open;
     195      this.openAlgorithmButton.Image = ((System.Drawing.Image)(resources.GetObject("openAlgorithmButton.Image")));
    205196      this.openAlgorithmButton.Location = new System.Drawing.Point(36, 6);
    206197      this.openAlgorithmButton.Name = "openAlgorithmButton";
     
    213204      // newAlgorithmButton
    214205      //
    215       this.newAlgorithmButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.NewDocument;
     206      this.newAlgorithmButton.Image = ((System.Drawing.Image)(resources.GetObject("newAlgorithmButton.Image")));
    216207      this.newAlgorithmButton.Location = new System.Drawing.Point(6, 6);
    217208      this.newAlgorithmButton.Name = "newAlgorithmButton";
     
    222213      this.newAlgorithmButton.Click += new System.EventHandler(this.newAlgorithmButton_Click);
    223214      //
    224       // snapshotsTabPage
    225       //
    226       this.snapshotsTabPage.Controls.Add(this.snapshotsView);
    227       this.snapshotsTabPage.Location = new System.Drawing.Point(4, 22);
    228       this.snapshotsTabPage.Name = "snapshotsTabPage";
    229       this.snapshotsTabPage.Padding = new System.Windows.Forms.Padding(3);
    230       this.snapshotsTabPage.Size = new System.Drawing.Size(538, 330);
    231       this.snapshotsTabPage.TabIndex = 2;
    232       this.snapshotsTabPage.Text = "Snapshots";
    233       this.snapshotsTabPage.UseVisualStyleBackColor = true;
    234       //
    235       // snapshotsView
    236       //
    237       this.snapshotsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    238             | System.Windows.Forms.AnchorStyles.Left)
    239             | System.Windows.Forms.AnchorStyles.Right)));
    240       this.snapshotsView.Caption = "RunCollection View";
    241       this.snapshotsView.Content = null;
    242       this.snapshotsView.Location = new System.Drawing.Point(6, 6);
    243       this.snapshotsView.Name = "snapshotsView";
    244       this.snapshotsView.ReadOnly = false;
    245       this.snapshotsView.Size = new System.Drawing.Size(526, 317);
    246       this.snapshotsView.TabIndex = 0;
     215      // currentRunTabPage
     216      //
     217      this.currentRunTabPage.Controls.Add(this.currentRunView);
     218      this.currentRunTabPage.Location = new System.Drawing.Point(4, 22);
     219      this.currentRunTabPage.Name = "currentRunTabPage";
     220      this.currentRunTabPage.Padding = new System.Windows.Forms.Padding(6);
     221      this.currentRunTabPage.Size = new System.Drawing.Size(538, 276);
     222      this.currentRunTabPage.TabIndex = 4;
     223      this.currentRunTabPage.Text = "Current Run";
     224      this.currentRunTabPage.UseVisualStyleBackColor = true;
     225      //
     226      // currentRunView
     227      //
     228      this.currentRunView.Caption = "Run View";
     229      this.currentRunView.Content = null;
     230      this.currentRunView.Dock = System.Windows.Forms.DockStyle.Fill;
     231      this.currentRunView.Location = new System.Drawing.Point(6, 6);
     232      this.currentRunView.Name = "currentRunView";
     233      this.currentRunView.ReadOnly = false;
     234      this.currentRunView.Size = new System.Drawing.Size(526, 264);
     235      this.currentRunView.TabIndex = 0;
    247236      //
    248237      // runsTabPage
     
    251240      this.runsTabPage.Location = new System.Drawing.Point(4, 22);
    252241      this.runsTabPage.Name = "runsTabPage";
    253       this.runsTabPage.Size = new System.Drawing.Size(538, 330);
     242      this.runsTabPage.Padding = new System.Windows.Forms.Padding(6);
     243      this.runsTabPage.Size = new System.Drawing.Size(538, 276);
    254244      this.runsTabPage.TabIndex = 3;
    255245      this.runsTabPage.Text = "Runs";
     
    258248      // runsView
    259249      //
    260       this.runsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    261             | System.Windows.Forms.AnchorStyles.Left)
    262             | System.Windows.Forms.AnchorStyles.Right)));
    263250      this.runsView.Caption = "RunCollection View";
    264251      this.runsView.Content = null;
     252      this.runsView.Dock = System.Windows.Forms.DockStyle.Fill;
    265253      this.runsView.Location = new System.Drawing.Point(6, 6);
    266254      this.runsView.Name = "runsView";
    267255      this.runsView.ReadOnly = false;
    268       this.runsView.Size = new System.Drawing.Size(526, 317);
     256      this.runsView.Size = new System.Drawing.Size(526, 264);
    269257      this.runsView.TabIndex = 1;
    270258      //
     
    276264      this.openFileDialog.Title = "Open Optimizer";
    277265      //
    278       // snapshotButton
    279       //
    280       this.snapshotButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    281       this.snapshotButton.Location = new System.Drawing.Point(120, 440);
    282       this.snapshotButton.Name = "snapshotButton";
    283       this.snapshotButton.Size = new System.Drawing.Size(24, 24);
    284       this.snapshotButton.TabIndex = 13;
    285       this.snapshotButton.Text = "Snapshot";
    286       this.toolTip.SetToolTip(this.snapshotButton, "Create Snapshot");
    287       this.snapshotButton.UseVisualStyleBackColor = true;
    288       this.snapshotButton.Click += new System.EventHandler(this.snapshotButton_Click);
    289       //
    290       // sequenceButton
    291       //
    292       this.sequenceButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    293       this.sequenceButton.Location = new System.Drawing.Point(250, 50);
    294       this.sequenceButton.Name = "sequenceButton";
    295       this.sequenceButton.Size = new System.Drawing.Size(75, 23);
    296       this.sequenceButton.TabIndex = 16;
    297       this.sequenceButton.Text = "Sequence...";
    298       this.sequenceButton.UseVisualStyleBackColor = true;
    299       this.sequenceButton.Click += new System.EventHandler(this.sequenceButton_Click);
    300       //
    301       // TimeLimitRunView
     266      // targetValueTextBox
     267      //
     268      this.targetValueTextBox.Location = new System.Drawing.Point(115, 78);
     269      this.targetValueTextBox.Name = "targetValueTextBox";
     270      this.targetValueTextBox.Size = new System.Drawing.Size(157, 20);
     271      this.targetValueTextBox.TabIndex = 6;
     272      this.targetValueTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.targetValueTextBox_Validating);
     273      //
     274      // targetValueLabel
     275      //
     276      this.targetValueLabel.AutoSize = true;
     277      this.targetValueLabel.Location = new System.Drawing.Point(3, 81);
     278      this.targetValueLabel.Name = "targetValueLabel";
     279      this.targetValueLabel.Size = new System.Drawing.Size(71, 13);
     280      this.targetValueLabel.TabIndex = 5;
     281      this.targetValueLabel.Text = "Target Value:";
     282      //
     283      // terminationComboBox
     284      //
     285      this.terminationComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     286            | System.Windows.Forms.AnchorStyles.Right)));
     287      this.terminationComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     288      this.terminationComboBox.FormattingEnabled = true;
     289      this.terminationComboBox.Location = new System.Drawing.Point(115, 105);
     290      this.terminationComboBox.Name = "terminationComboBox";
     291      this.terminationComboBox.Size = new System.Drawing.Size(409, 21);
     292      this.terminationComboBox.TabIndex = 16;
     293      this.terminationComboBox.SelectedIndexChanged += new System.EventHandler(this.terminationComboBox_SelectedIndexChanged);
     294      //
     295      // terminationLabel
     296      //
     297      this.terminationLabel.AutoSize = true;
     298      this.terminationLabel.Location = new System.Drawing.Point(3, 108);
     299      this.terminationLabel.Name = "terminationLabel";
     300      this.terminationLabel.Size = new System.Drawing.Size(65, 13);
     301      this.terminationLabel.TabIndex = 5;
     302      this.terminationLabel.Text = "Termination:";
     303      //
     304      // moveCostPerSolutionTextBox
     305      //
     306      this.moveCostPerSolutionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     307            | System.Windows.Forms.AnchorStyles.Right)));
     308      this.moveCostPerSolutionTextBox.Location = new System.Drawing.Point(401, 52);
     309      this.moveCostPerSolutionTextBox.Name = "moveCostPerSolutionTextBox";
     310      this.moveCostPerSolutionTextBox.Size = new System.Drawing.Size(123, 20);
     311      this.moveCostPerSolutionTextBox.TabIndex = 6;
     312      this.moveCostPerSolutionTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.moveCostPerSolutionTextBox_Validating);
     313      //
     314      // moveCostPerSolutionLabel
     315      //
     316      this.moveCostPerSolutionLabel.AutoSize = true;
     317      this.moveCostPerSolutionLabel.Location = new System.Drawing.Point(278, 55);
     318      this.moveCostPerSolutionLabel.Name = "moveCostPerSolutionLabel";
     319      this.moveCostPerSolutionLabel.Size = new System.Drawing.Size(117, 13);
     320      this.moveCostPerSolutionLabel.TabIndex = 5;
     321      this.moveCostPerSolutionLabel.Text = "Move cost per solution:";
     322      //
     323      // maximizationLabel
     324      //
     325      this.maximizationLabel.AutoSize = true;
     326      this.maximizationLabel.Location = new System.Drawing.Point(278, 81);
     327      this.maximizationLabel.Name = "maximizationLabel";
     328      this.maximizationLabel.Size = new System.Drawing.Size(70, 13);
     329      this.maximizationLabel.TabIndex = 5;
     330      this.maximizationLabel.Text = "Maximization:";
     331      //
     332      // maximizationCheckBox
     333      //
     334      this.maximizationCheckBox.AutoSize = true;
     335      this.maximizationCheckBox.Location = new System.Drawing.Point(401, 80);
     336      this.maximizationCheckBox.Name = "maximizationCheckBox";
     337      this.maximizationCheckBox.Size = new System.Drawing.Size(15, 14);
     338      this.maximizationCheckBox.TabIndex = 17;
     339      this.maximizationCheckBox.UseVisualStyleBackColor = true;
     340      this.maximizationCheckBox.CheckedChanged += new System.EventHandler(this.maximizationCheckBox_CheckedChanged);
     341      //
     342      // IndependentRandomRestarterView
    302343      //
    303344      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    304       this.Controls.Add(this.sequenceButton);
    305       this.Controls.Add(this.snapshotButton);
     345      this.Controls.Add(this.maximizationCheckBox);
     346      this.Controls.Add(this.terminationComboBox);
    306347      this.Controls.Add(this.tabControl);
    307       this.Controls.Add(this.timeLimitTextBox);
     348      this.Controls.Add(this.maxExecutionTimeTextBox);
    308349      this.Controls.Add(this.timeLimitLabel);
    309       this.Controls.Add(this.label1);
    310       this.Controls.Add(this.snapshotsTextBox);
    311       this.Controls.Add(this.storeAlgorithmInEachSnapshotCheckBox);
    312       this.Name = "TimeLimitRunView";
     350      this.Controls.Add(this.terminationLabel);
     351      this.Controls.Add(this.targetValueLabel);
     352      this.Controls.Add(this.maximizationLabel);
     353      this.Controls.Add(this.moveCostPerSolutionLabel);
     354      this.Controls.Add(this.evaluationsLimitabel);
     355      this.Controls.Add(this.moveCostPerSolutionTextBox);
     356      this.Controls.Add(this.targetValueTextBox);
     357      this.Controls.Add(this.maxEvaluationsTextBox);
     358      this.Name = "IndependentRandomRestarterView";
    313359      this.Size = new System.Drawing.Size(549, 464);
    314       this.Controls.SetChildIndex(this.storeAlgorithmInEachSnapshotCheckBox, 0);
    315       this.Controls.SetChildIndex(this.snapshotsTextBox, 0);
    316       this.Controls.SetChildIndex(this.label1, 0);
     360      this.Controls.SetChildIndex(this.maxEvaluationsTextBox, 0);
     361      this.Controls.SetChildIndex(this.targetValueTextBox, 0);
     362      this.Controls.SetChildIndex(this.moveCostPerSolutionTextBox, 0);
     363      this.Controls.SetChildIndex(this.evaluationsLimitabel, 0);
     364      this.Controls.SetChildIndex(this.moveCostPerSolutionLabel, 0);
     365      this.Controls.SetChildIndex(this.maximizationLabel, 0);
     366      this.Controls.SetChildIndex(this.targetValueLabel, 0);
     367      this.Controls.SetChildIndex(this.terminationLabel, 0);
    317368      this.Controls.SetChildIndex(this.timeLimitLabel, 0);
    318       this.Controls.SetChildIndex(this.timeLimitTextBox, 0);
     369      this.Controls.SetChildIndex(this.maxExecutionTimeTextBox, 0);
    319370      this.Controls.SetChildIndex(this.tabControl, 0);
    320371      this.Controls.SetChildIndex(this.nameLabel, 0);
     
    327378      this.Controls.SetChildIndex(this.executionTimeTextBox, 0);
    328379      this.Controls.SetChildIndex(this.startButton, 0);
    329       this.Controls.SetChildIndex(this.snapshotButton, 0);
    330       this.Controls.SetChildIndex(this.sequenceButton, 0);
     380      this.Controls.SetChildIndex(this.terminationComboBox, 0);
     381      this.Controls.SetChildIndex(this.maximizationCheckBox, 0);
    331382      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    332383      this.tabControl.ResumeLayout(false);
    333384      this.algorithmTabPage.ResumeLayout(false);
    334       this.snapshotsTabPage.ResumeLayout(false);
     385      this.currentRunTabPage.ResumeLayout(false);
    335386      this.runsTabPage.ResumeLayout(false);
    336387      this.ResumeLayout(false);
     
    342393
    343394    private System.Windows.Forms.Label timeLimitLabel;
    344     private System.Windows.Forms.TextBox timeLimitTextBox;
    345     private System.Windows.Forms.Label label1;
    346     private System.Windows.Forms.TextBox snapshotsTextBox;
    347     private System.Windows.Forms.CheckBox storeAlgorithmInEachSnapshotCheckBox;
     395    private System.Windows.Forms.TextBox maxExecutionTimeTextBox;
     396    private System.Windows.Forms.Label evaluationsLimitabel;
     397    private System.Windows.Forms.TextBox maxEvaluationsTextBox;
    348398    private MainForm.WindowsForms.DragOverTabControl tabControl;
     399    private System.Windows.Forms.TabPage runsTabPage;
     400    private RunCollectionView runsView;
     401    private System.Windows.Forms.OpenFileDialog openFileDialog;
     402    private System.Windows.Forms.TextBox targetValueTextBox;
     403    private System.Windows.Forms.Label targetValueLabel;
     404    private System.Windows.Forms.ComboBox terminationComboBox;
     405    private System.Windows.Forms.Label terminationLabel;
     406    private System.Windows.Forms.TextBox moveCostPerSolutionTextBox;
     407    private System.Windows.Forms.Label moveCostPerSolutionLabel;
     408    private System.Windows.Forms.Label maximizationLabel;
     409    private System.Windows.Forms.CheckBox maximizationCheckBox;
    349410    private System.Windows.Forms.TabPage algorithmTabPage;
    350411    private MainForm.WindowsForms.ViewHost algorithmViewHost;
    351412    private System.Windows.Forms.Button openAlgorithmButton;
    352413    private System.Windows.Forms.Button newAlgorithmButton;
    353     private System.Windows.Forms.TabPage snapshotsTabPage;
    354     private RunCollectionView snapshotsView;
    355     private System.Windows.Forms.TabPage runsTabPage;
    356     private RunCollectionView runsView;
    357     private System.Windows.Forms.OpenFileDialog openFileDialog;
    358     private System.Windows.Forms.Button snapshotButton;
    359     private System.Windows.Forms.Button sequenceButton;
     414    private System.Windows.Forms.TabPage currentRunTabPage;
     415    private RunView currentRunView;
    360416  }
    361417}
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/IRRestarterView.cs

    r12764 r12804  
    2222using System;
    2323using System.ComponentModel;
     24using System.Globalization;
    2425using System.Linq;
    25 using System.Text.RegularExpressions;
    2626using System.Windows.Forms;
    27 using HeuristicLab.Collections;
     27using HeuristicLab.Analysis;
    2828using HeuristicLab.Common;
    29 using HeuristicLab.Common.Resources;
    3029using HeuristicLab.Core;
    3130using HeuristicLab.Core.Views;
    3231using HeuristicLab.MainForm;
    33 using HeuristicLab.MainForm.WindowsForms;
    3432using HeuristicLab.PluginInfrastructure;
    3533
    3634namespace HeuristicLab.Optimization.Views {
    37   [View("TimeLimit Run View")]
    38   [Content(typeof(TimeLimitRun), IsDefaultView = true)]
    39   public partial class TimeLimitRunView : IOptimizerView {
     35  [View("Independent Random Restarter View")]
     36  [Content(typeof(IndepdentRandomRestarter), IsDefaultView = true)]
     37  public partial class IndependentRandomRestarterView : IOptimizerView {
    4038    protected TypeSelectorDialog algorithmTypeSelectorDialog;
    4139    protected virtual bool SuppressEvents { get; set; }
    4240
    43     public new TimeLimitRun Content {
    44       get { return (TimeLimitRun)base.Content; }
     41    public new IndepdentRandomRestarter Content {
     42      get { return (IndepdentRandomRestarter)base.Content; }
    4543      set { base.Content = value; }
    4644    }
    4745
    48     public TimeLimitRunView() {
     46    public IndependentRandomRestarterView() {
    4947      InitializeComponent();
    50       snapshotButton.Text = String.Empty;
    51       snapshotButton.Image = VSImageLibrary.Camera;
     48      terminationComboBox.Items.AddRange(Enum.GetValues(typeof(TerminationCriterium)).Cast<object>().ToArray());
    5249    }
    5350
     
    6259    protected override void DeregisterContentEvents() {
    6360      Content.PropertyChanged -= Content_PropertyChanged;
    64       Content.SnapshotTimes.ItemsAdded -= Content_SnapshotTimes_Changed;
    65       Content.SnapshotTimes.ItemsMoved -= Content_SnapshotTimes_Changed;
    66       Content.SnapshotTimes.ItemsRemoved -= Content_SnapshotTimes_Changed;
    67       Content.SnapshotTimes.ItemsReplaced -= Content_SnapshotTimes_Changed;
    68       Content.SnapshotTimes.CollectionReset -= Content_SnapshotTimes_Changed;
    6961      base.DeregisterContentEvents();
    7062    }
     
    7264      base.RegisterContentEvents();
    7365      Content.PropertyChanged += Content_PropertyChanged;
    74       Content.SnapshotTimes.ItemsAdded += Content_SnapshotTimes_Changed;
    75       Content.SnapshotTimes.ItemsMoved += Content_SnapshotTimes_Changed;
    76       Content.SnapshotTimes.ItemsRemoved += Content_SnapshotTimes_Changed;
    77       Content.SnapshotTimes.ItemsReplaced += Content_SnapshotTimes_Changed;
    78       Content.SnapshotTimes.CollectionReset += Content_SnapshotTimes_Changed;
    7966    }
    8067
     
    8471      try {
    8572        if (Content == null) {
    86           timeLimitTextBox.Text = TimeSpanHelper.FormatNatural(TimeSpan.FromSeconds(60));
    87           snapshotsTextBox.Text = String.Empty;
    88           storeAlgorithmInEachSnapshotCheckBox.Checked = false;
     73          maxExecutionTimeTextBox.Text = String.Empty;
     74          maxEvaluationsTextBox.Text = String.Empty;
     75          moveCostPerSolutionTextBox.Text = String.Empty;
     76          targetValueTextBox.Text = String.Empty;
     77          maximizationCheckBox.CheckState = CheckState.Indeterminate;
     78          terminationComboBox.SelectedIndex = -1;
     79
    8980          algorithmViewHost.Content = null;
    90           snapshotsView.Content = null;
     81          currentRunView.Content = null;
    9182          runsView.Content = null;
    9283        } else {
    93           timeLimitTextBox.Text = TimeSpanHelper.FormatNatural(Content.MaximumExecutionTime);
    94           snapshotsTextBox.Text = String.Join(" ; ", Content.SnapshotTimes.Select(x => TimeSpanHelper.FormatNatural(x, true)));
    95           storeAlgorithmInEachSnapshotCheckBox.Checked = Content.StoreAlgorithmInEachSnapshot;
     84          maxExecutionTimeTextBox.Text = TimeSpanHelper.FormatNatural(Content.MaximumExecutionTime);
     85          maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString();
     86          moveCostPerSolutionTextBox.Text = Content.MoveCostPerSolution.ToString(CultureInfo.CurrentCulture.NumberFormat);
     87          targetValueTextBox.Text = Content.TargetValue.ToString(CultureInfo.CurrentCulture.NumberFormat);
     88          maximizationCheckBox.Checked = Content.Maximization;
     89          terminationComboBox.SelectedItem = Content.TerminationCriterium;
     90
    9691          algorithmViewHost.Content = Content.Algorithm;
    97           snapshotsView.Content = Content.Snapshots;
     92          currentRunView.Content = Content.CurrentRun;
    9893          runsView.Content = Content.Runs;
    9994        }
     
    10398    protected override void SetEnabledStateOfControls() {
    10499      base.SetEnabledStateOfControls();
    105       timeLimitTextBox.Enabled = Content != null && !ReadOnly;
    106       snapshotsTextBox.Enabled = Content != null && !ReadOnly;
    107       storeAlgorithmInEachSnapshotCheckBox.Enabled = Content != null && !ReadOnly;
     100      maxExecutionTimeTextBox.Enabled = Content != null && !ReadOnly && !Locked;
     101      maxEvaluationsTextBox.Enabled = Content != null && !ReadOnly && !Locked;
     102      moveCostPerSolutionTextBox.Enabled = Content != null && !ReadOnly && !Locked;
     103      targetValueTextBox.Enabled = Content != null && !ReadOnly && !Locked;
     104      maximizationCheckBox.Enabled = Content != null && !ReadOnly && !Locked;
     105      terminationComboBox.Enabled = Content != null && !ReadOnly && !Locked;
    108106      newAlgorithmButton.Enabled = Content != null && !ReadOnly;
    109107      openAlgorithmButton.Enabled = Content != null && !ReadOnly;
    110108      algorithmViewHost.Enabled = Content != null;
    111       snapshotsView.Enabled = Content != null;
     109      currentRunView.Enabled = Content != null;
    112110      runsView.Enabled = Content != null;
    113     }
    114 
    115     protected override void SetEnabledStateOfExecutableButtons() {
    116       base.SetEnabledStateOfExecutableButtons();
    117       snapshotButton.Enabled = Content != null && Content.Algorithm != null && Content.ExecutionState == ExecutionState.Paused;
    118111    }
    119112
     
    133126    #region Content events
    134127    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    135       switch (e.PropertyName) {
    136         case "MaximumExecutionTime":
    137           SuppressEvents = true;
    138           try {
    139             timeLimitTextBox.Text = TimeSpanHelper.FormatNatural(Content.MaximumExecutionTime);
    140           } finally { SuppressEvents = false; }
    141           break;
    142         case "SnapshotTimes":
    143           SuppressEvents = true;
    144           try {
    145             if (Content.SnapshotTimes.Any())
    146               snapshotsTextBox.Text = String.Join(" ; ", Content.SnapshotTimes.Select(x => TimeSpanHelper.FormatNatural(x, true)));
    147             else snapshotsTextBox.Text = String.Empty;
    148             Content.SnapshotTimes.ItemsAdded += Content_SnapshotTimes_Changed;
    149             Content.SnapshotTimes.ItemsMoved += Content_SnapshotTimes_Changed;
    150             Content.SnapshotTimes.ItemsRemoved += Content_SnapshotTimes_Changed;
    151             Content.SnapshotTimes.ItemsReplaced += Content_SnapshotTimes_Changed;
    152             Content.SnapshotTimes.CollectionReset += Content_SnapshotTimes_Changed;
    153           } finally { SuppressEvents = false; }
    154           break;
    155         case "StoreAlgorithmInEachSnapshot":
    156           SuppressEvents = true;
    157           try {
    158             storeAlgorithmInEachSnapshotCheckBox.Checked = Content.StoreAlgorithmInEachSnapshot;
    159           } finally { SuppressEvents = false; }
    160           break;
    161         case "Algorithm":
    162           SuppressEvents = true;
    163           try {
    164             algorithmViewHost.Content = Content.Algorithm;
    165           } finally { SuppressEvents = false; }
    166           break;
    167         case "Snapshots":
    168           SuppressEvents = true;
    169           try {
    170             snapshotsView.Content = Content.Snapshots;
    171           } finally { SuppressEvents = false; }
    172           break;
    173         case "Runs":
    174           SuppressEvents = true;
    175           try {
    176             runsView.Content = Content.Runs;
    177           } finally { SuppressEvents = false; }
    178           break;
    179       }
    180     }
    181 
    182     private void Content_SnapshotTimes_Changed(object sender, EventArgs e) {
    183128      SuppressEvents = true;
    184129      try {
    185         if (Content.SnapshotTimes.Any())
    186           snapshotsTextBox.Text = string.Join(" ; ", Content.SnapshotTimes.Select(x => TimeSpanHelper.FormatNatural(x, true)));
    187         else snapshotsTextBox.Text = String.Empty;
     130        switch (e.PropertyName) {
     131          case "TerminationCriterium": terminationComboBox.SelectedItem = Content.TerminationCriterium; break;
     132          case "MaximumExecutionTime": maxExecutionTimeTextBox.Text = TimeSpanHelper.FormatNatural(Content.MaximumExecutionTime); break;
     133          case "MaximumEvaluations": maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString(); break;
     134          case "TargetValue": targetValueTextBox.Text = Content.TargetValue.ToString(CultureInfo.CurrentCulture.NumberFormat); break;
     135          case "Maximization": maximizationCheckBox.Checked = Content.Maximization; break;
     136          case "MoveCostPerSolution": moveCostPerSolutionTextBox.Text = Content.MoveCostPerSolution.ToString(CultureInfo.CurrentCulture.NumberFormat); break;
     137          case "Algorithm": algorithmViewHost.Content = Content.Algorithm; break;
     138          case "CurrentRun": currentRunView.Content = Content.CurrentRun; break;
     139          case "Runs": runsView.Content = Content.Runs; break;
     140        }
    188141      } finally { SuppressEvents = false; }
    189142    }
     
    191144
    192145    #region Control events
    193     private void timeLimitTextBox_Validating(object sender, CancelEventArgs e) {
    194       if (SuppressEvents) return;
     146    private void maxExecutionTimeTextBox_Validating(object sender, CancelEventArgs e) {
     147      if (SuppressEvents) return;
     148      if (InvokeRequired) {
     149        Invoke((Action<object, CancelEventArgs>)maxExecutionTimeTextBox_Validating, sender, e);
     150        return;
     151      }
    195152      TimeSpan ts;
    196       if (!TimeSpanHelper.TryGetFromNaturalFormat(timeLimitTextBox.Text, out ts)) {
    197         e.Cancel = !timeLimitTextBox.ReadOnly && timeLimitTextBox.Enabled;
    198         errorProvider.SetError(timeLimitTextBox, "Please enter a valid time span, e.g. 20 seconds ; 45s ; 4min ; 1h ; 3 hours ; 2 days ; 4d");
     153      if (!TimeSpanHelper.TryGetFromNaturalFormat(maxExecutionTimeTextBox.Text, out ts)) {
     154        e.Cancel = !maxExecutionTimeTextBox.ReadOnly && maxExecutionTimeTextBox.Enabled;
     155        errorProvider.SetError(maxExecutionTimeTextBox, "Please enter a valid time span, e.g. 20 seconds ; 45s ; 4min ; 1h ; 3 hours ; 2 days ; 4d");
    199156      } else {
    200157        Content.MaximumExecutionTime = ts;
    201158        e.Cancel = false;
    202         errorProvider.SetError(timeLimitTextBox, null);
    203       }
    204     }
    205 
    206     private void snapshotsTextBox_Validating(object sender, CancelEventArgs e) {
    207       if (SuppressEvents) return;
    208       e.Cancel = false;
    209       errorProvider.SetError(snapshotsTextBox, null);
    210 
    211       var snapshotTimes = new ObservableList<TimeSpan>();
    212       var matches = Regex.Matches(snapshotsTextBox.Text, @"(\d+[ ;,\t]*\w+)");
    213       foreach (Match m in matches) {
    214         TimeSpan value;
    215         if (!TimeSpanHelper.TryGetFromNaturalFormat(m.Value, out value)) {
    216           e.Cancel = !snapshotsTextBox.ReadOnly && snapshotsTextBox.Enabled; // don't cancel an operation that cannot be edited
    217           errorProvider.SetError(snapshotsTextBox, "Error parsing " + m.Value + ", please provide a valid time span, e.g. 20 seconds ; 45s ; 4min ; 1h ; 3 hours ; 2 days ; 4d");
    218           return;
    219         } else {
    220           snapshotTimes.Add(value);
    221         }
    222       }
    223       Content.SnapshotTimes = snapshotTimes;
    224     }
    225 
    226     private void storeAlgorithmInEachSnapshotCheckBox_CheckedChanged(object sender, EventArgs e) {
    227       if (SuppressEvents) return;
    228       SuppressEvents = true;
    229       try {
    230         Content.StoreAlgorithmInEachSnapshot = storeAlgorithmInEachSnapshotCheckBox.Checked;
    231       } finally { SuppressEvents = false; }
     159        errorProvider.SetError(maxExecutionTimeTextBox, null);
     160      }
     161    }
     162
     163    private void maxEvaluationsTextBox_Validating(object sender, CancelEventArgs e) {
     164      if (SuppressEvents) return;
     165      if (InvokeRequired) {
     166        Invoke((Action<object, CancelEventArgs>)maxEvaluationsTextBox_Validating, sender, e);
     167        return;
     168      }
     169      int value;
     170      if (!int.TryParse(maxEvaluationsTextBox.Text, out value)) {
     171        e.Cancel = !maxEvaluationsTextBox.ReadOnly && maxEvaluationsTextBox.Enabled;
     172        errorProvider.SetError(maxEvaluationsTextBox, "Please enter a valid integer number.");
     173      } else {
     174        Content.MaximumEvaluations = value;
     175        e.Cancel = false;
     176        errorProvider.SetError(maxEvaluationsTextBox, null);
     177      }
     178    }
     179
     180    private void moveCostPerSolutionTextBox_Validating(object sender, CancelEventArgs e) {
     181      if (SuppressEvents) return;
     182      if (InvokeRequired) {
     183        Invoke((Action<object, CancelEventArgs>)moveCostPerSolutionTextBox_Validating, sender, e);
     184        return;
     185      }
     186      double value;
     187      if (!double.TryParse(moveCostPerSolutionTextBox.Text, out value)) {
     188        e.Cancel = !moveCostPerSolutionTextBox.ReadOnly && moveCostPerSolutionTextBox.Enabled;
     189        errorProvider.SetError(moveCostPerSolutionTextBox, "Please enter a valid integer number.");
     190      } else {
     191        Content.MoveCostPerSolution = value;
     192        e.Cancel = false;
     193        errorProvider.SetError(moveCostPerSolutionTextBox, null);
     194      }
     195    }
     196
     197    private void targetValueTextBox_Validating(object sender, CancelEventArgs e) {
     198      if (SuppressEvents) return;
     199      if (InvokeRequired) {
     200        Invoke((Action<object, CancelEventArgs>)targetValueTextBox_Validating, sender, e);
     201        return;
     202      }
     203      double value;
     204      if (!double.TryParse(targetValueTextBox.Text, out value)) {
     205        e.Cancel = !targetValueTextBox.ReadOnly && targetValueTextBox.Enabled;
     206        errorProvider.SetError(targetValueTextBox, "Please enter a valid integer number.");
     207      } else {
     208        Content.TargetValue = value;
     209        e.Cancel = false;
     210        errorProvider.SetError(targetValueTextBox, null);
     211      }
     212    }
     213
     214    private void maximizationCheckBox_CheckedChanged(object sender, EventArgs e) {
     215      if (SuppressEvents) return;
     216      if (InvokeRequired) {
     217        Invoke((Action<object, EventArgs>)maximizationCheckBox_CheckedChanged, sender, e);
     218        return;
     219      }
     220      Content.Maximization = maximizationCheckBox.Checked;
     221    }
     222
     223    private void terminationComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     224      if (SuppressEvents) return;
     225      if (InvokeRequired) {
     226        Invoke((Action<object, EventArgs>)terminationComboBox_SelectedIndexChanged, sender, e);
     227        return;
     228      }
     229      Content.TerminationCriterium = (TerminationCriterium)terminationComboBox.SelectedItem;
    232230    }
    233231
     
    236234        algorithmTypeSelectorDialog = new TypeSelectorDialog { Caption = "Select Algorithm" };
    237235        algorithmTypeSelectorDialog.TypeSelector.Caption = "Available Algorithms";
    238         algorithmTypeSelectorDialog.TypeSelector.Configure(typeof(IAlgorithm), false, true);
     236        algorithmTypeSelectorDialog.TypeSelector.Configure(typeof(IAlgorithm)
     237          , showNotInstantiableTypes: false, showGenericTypes: false);
    239238      }
    240239      if (algorithmTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
     
    275274    private void algorithmTabPage_DragEnterOver(object sender, DragEventArgs e) {
    276275      e.Effect = DragDropEffects.None;
    277       if (!ReadOnly && (e.Data.GetData(Constants.DragDropDataFormat) is IAlgorithm)) {
     276      var alg = e.Data.GetData(Constants.DragDropDataFormat) as IAlgorithm;
     277      if (!ReadOnly && alg != null) {
     278        if (!typeof(ISingleObjectiveHeuristicOptimizationProblem).IsAssignableFrom(alg.ProblemType))
     279          return;
    278280        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    279281        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
     
    291293      }
    292294    }
    293 
    294     private void snapshotButton_Click(object sender, EventArgs e) {
    295       Content.Snapshot();
    296     }
    297 
    298     private void sequenceButton_Click(object sender, EventArgs e) {
    299       using (var dialog = new DefineArithmeticTimeSpanProgressionDialog(TimeSpan.FromSeconds(1), Content.MaximumExecutionTime, TimeSpan.FromSeconds(1))) {
    300         if (dialog.ShowDialog() == DialogResult.OK) {
    301           if (dialog.Values.Any())
    302             Content.SnapshotTimes = new ObservableList<TimeSpan>(dialog.Values);
    303           else Content.SnapshotTimes = new ObservableList<TimeSpan>();
    304         }
    305       }
    306     }
    307295    #endregion
    308296    #endregion
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.Designer.cs

    r12803 r12804  
    4444    /// </summary>
    4545    private void InitializeComponent() {
     46      this.components = new System.ComponentModel.Container();
    4647      this.dataTableComboBox = new System.Windows.Forms.ComboBox();
    4748      this.label1 = new System.Windows.Forms.Label();
     
    5051      this.groupComboBox = new System.Windows.Forms.ComboBox();
    5152      this.logScalingCheckBox = new System.Windows.Forms.CheckBox();
     53      this.targetsTextBox = new System.Windows.Forms.TextBox();
     54      this.label3 = new System.Windows.Forms.Label();
     55      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
     56      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5257      this.SuspendLayout();
    5358      //
     
    8186      this.viewHost.Content = null;
    8287      this.viewHost.Enabled = false;
    83       this.viewHost.Location = new System.Drawing.Point(4, 57);
     88      this.viewHost.Location = new System.Drawing.Point(4, 90);
    8489      this.viewHost.Name = "viewHost";
    8590      this.viewHost.ReadOnly = false;
    86       this.viewHost.Size = new System.Drawing.Size(520, 291);
     91      this.viewHost.Size = new System.Drawing.Size(520, 258);
    8792      this.viewHost.TabIndex = 2;
    8893      this.viewHost.ViewsLabelVisible = true;
     
    122127      this.logScalingCheckBox.CheckedChanged += new System.EventHandler(this.logScalingCheckBox_CheckedChanged);
    123128      //
    124       // RunCollectionECDFView
     129      // targetsTextBox
     130      //
     131      this.targetsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     132            | System.Windows.Forms.AnchorStyles.Right)));
     133      this.targetsTextBox.Location = new System.Drawing.Point(69, 57);
     134      this.targetsTextBox.Name = "targetsTextBox";
     135      this.targetsTextBox.Size = new System.Drawing.Size(455, 20);
     136      this.targetsTextBox.TabIndex = 6;
     137      this.targetsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.targetsTextBox_Validating);
     138      //
     139      // label3
     140      //
     141      this.label3.AutoSize = true;
     142      this.label3.Location = new System.Drawing.Point(3, 60);
     143      this.label3.Name = "label3";
     144      this.label3.Size = new System.Drawing.Size(46, 13);
     145      this.label3.TabIndex = 1;
     146      this.label3.Text = "Targets:";
     147      //
     148      // errorProvider
     149      //
     150      this.errorProvider.ContainerControl = this;
     151      //
     152      // RunCollectionRLDView
    125153      //
    126154      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     155      this.Controls.Add(this.targetsTextBox);
    127156      this.Controls.Add(this.logScalingCheckBox);
    128157      this.Controls.Add(this.groupComboBox);
    129158      this.Controls.Add(this.label2);
    130159      this.Controls.Add(this.viewHost);
     160      this.Controls.Add(this.label3);
    131161      this.Controls.Add(this.label1);
    132162      this.Controls.Add(this.dataTableComboBox);
    133       this.Name = "RunCollectionECDFView";
     163      this.Name = "RunCollectionRLDView";
    134164      this.Size = new System.Drawing.Size(527, 374);
     165      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    135166      this.ResumeLayout(false);
    136167      this.PerformLayout();
     
    146177    private System.Windows.Forms.ComboBox groupComboBox;
    147178    private System.Windows.Forms.CheckBox logScalingCheckBox;
     179    private System.Windows.Forms.TextBox targetsTextBox;
     180    private System.Windows.Forms.Label label3;
     181    protected System.Windows.Forms.ErrorProvider errorProvider;
    148182  }
    149183}
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs

    r12803 r12804  
    4242    }
    4343
     44    private double[] levels;
     45
    4446    private bool suppressUpdates;
    4547    private readonly IndexedDataTable<double> combinedDataTable;
     
    167169        var table = (string)dataTableComboBox.SelectedItem;
    168170        if (string.IsNullOrEmpty(table)) return;
    169         var maximum = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item2)).Max();
    170         var minimum = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item2)).Min();
    171         var levels = Enumerable.Range(0, 51).Select(x => maximum - (x / 50.0) * (maximum - minimum)).ToArray();
     171        if (levels == null) {
     172          var worst = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item2)).First();
     173          var best = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item2)).Last();
     174          levels = Enumerable.Range(0, 51).Select(x => worst + (x / 50.0) * (best - worst)).ToArray();
     175          suppressTargetsEvents = true;
     176          targetsTextBox.Text = string.Join(" ; ", levels);
     177          suppressTargetsEvents = false;
     178        }
    172179        var selectedGroup = (string)groupComboBox.SelectedItem;
    173180        if (string.IsNullOrEmpty(selectedGroup)) return;
     
    184191            var resultsTable = (IndexedDataTable<double>)run.Results[table];
    185192            xAxisTitles.Add(resultsTable.VisualProperties.XAxisTitle);
    186             var graph = new LinkedList<Tuple<double, double>>(resultsTable.Rows.First().Values);
    187             var current = graph.First.Next;
    188             // prune convergence graph to obtain first hit times only
    189             while (current != null) {
    190               if (current.Value.Item2.IsAlmost(current.Previous.Value.Item2)) {
    191                 var h = current;
    192                 current = current.Previous;
    193                 graph.Remove(h);
    194               }
    195               current = current.Next;
    196             }
     193            var values = resultsTable.Rows.First().Values;
     194            var maximization = values.First().Item2 < values.Last().Item2;
    197195            var i = 0;
    198             current = graph.First;
    199             while (i < levels.Length && current != null) {
    200               if (current.Value.Item2 < levels[i]) {
    201                 if (hits.ContainsKey(current.Value.Item1))
    202                   hits[current.Value.Item1]++;
    203                 else hits[current.Value.Item1] = 1;
     196            var j = 0;
     197            var current = values[j];
     198            var prev = Tuple.Create(-1.0, double.NaN);
     199            while (i < levels.Length) {
     200              if ((double.IsNaN(prev.Item2) || prev.Item2 != current.Item2)
     201                  && (maximization && current.Item2 >= levels[i]
     202                  || !maximization && current.Item2 <= levels[i])) {
     203                if (hits.ContainsKey(current.Item1))
     204                  hits[current.Item1]++;
     205                else hits[current.Item1] = 1;
    204206                i++;
    205207              } else {
    206                 current = current.Next;
     208                j++;
     209                if (j >= values.Count) break;
     210                prev = current;
     211                current = values[j];
    207212              }
    208213            }
     
    266271      combinedDataTable.VisualProperties.XAxisLogScale = logScalingCheckBox.Checked;
    267272    }
     273
     274    private bool suppressTargetsEvents;
     275    private void targetsTextBox_Validating(object sender, CancelEventArgs e) {
     276      if (suppressTargetsEvents) return;
     277      var targetStrings = targetsTextBox.Text.Split(new[] { ';', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
     278      var targetList = new List<double>();
     279      foreach (var ts in targetStrings) {
     280        double t;
     281        if (!double.TryParse(ts, out t)) {
     282          errorProvider.SetError(targetsTextBox, "Not all targets can be parsed: " + ts);
     283          e.Cancel = true;
     284          return;
     285        }
     286        targetList.Add(t);
     287      }
     288      if (targetList.Count == 0) {
     289        errorProvider.SetError(targetsTextBox, "Give at least one target value!");
     290        e.Cancel = true;
     291        return;
     292      }
     293      e.Cancel = false;
     294      errorProvider.SetError(targetsTextBox, null);
     295      levels = targetList.ToArray();
     296    }
    268297  }
    269298}
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunView.cs

    r12012 r12804  
    9797
    9898    private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     99      if (InvokeRequired) {
     100        Invoke((Action<object, PropertyChangedEventArgs>)Content_PropertyChanged, sender, e);
     101        return;
     102      }
    99103      if (e.PropertyName == "Color") {
    100104        if (InvokeRequired) this.Invoke((Action)UpdateColor, null);
     
    112116
    113117    private void ParametersOnItemsChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     118      if (InvokeRequired) {
     119        Invoke((Action<object, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>>>)ParametersOnItemsChanged, sender, e);
     120        return;
     121      }
    114122      foreach (var item in e.OldItems) {
    115123        listView.Items.Remove(parametersItemToListViewItem[item.Key]);
     
    124132
    125133    private void ParametersOnItemsRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     134      if (InvokeRequired) {
     135        Invoke((Action<object, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>>>)ParametersOnItemsRemoved, sender, e);
     136        return;
     137      }
    126138      foreach (var item in e.Items) {
    127139        listView.Items.Remove(parametersItemToListViewItem[item.Key]);
     
    131143
    132144    private void ResultsOnItemsChanged(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     145      if (InvokeRequired) {
     146        Invoke((Action<object, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>>>)ResultsOnItemsChanged, sender, e);
     147        return;
     148      }
    133149      foreach (var item in e.OldItems) {
    134150        listView.Items.Remove(resultsItemToListViewItem[item.Key]);
     
    143159
    144160    private void ResultsOnItemsRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>> e) {
     161      if (InvokeRequired) {
     162        Invoke((Action<object, CollectionItemsChangedEventArgs<KeyValuePair<string, IItem>>>)ResultsOnItemsRemoved, sender, e);
     163        return;
     164      }
    145165      foreach (var item in e.Items) {
    146166        listView.Items.Remove(resultsItemToListViewItem[item.Key]);
Note: See TracChangeset for help on using the changeset viewer.