Ignore:
Timestamp:
12/19/18 14:15:49 (3 months ago)
Author:
ddorfmei
Message:

#2931:

  • moved views to separate plugin HeuristicLab.MathematicalOptimization.Views
  • added button in LinearProgrammingProblemView to select the problem definition type
  • added views for problem definitions
  • added ExportFile parameter to LinearProgrammingAlgorithm
  • extended FileValue and FileValueView by the option to save a file
  • code cleanup
File:
1 moved

Legend:

Unmodified
Added
Removed
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/IncrementalLinearSolver.cs

    r16404 r16405  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Data;
     29using HeuristicLab.Optimization;
    2930using HeuristicLab.Parameters;
    3031using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3132
    32 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base {
     33namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3334
    3435  [StorableClass]
    35   public class IncrementalSolver : Solver, IIncrementalSolver {
    36 
    37     [Storable]
    38     protected readonly IValueParameter<TimeSpanValue> qualityUpdateIntervalParam;
     36  public class IncrementalLinearSolver : LinearSolver, IIncrementalLinearSolver {
     37    [Storable] protected readonly IValueParameter<TimeSpanValue> qualityUpdateIntervalParam;
    3938
    4039    private IndexedDataRow<double> bpcRow;
     
    4241    private IndexedDataRow<double> qpcRow;
    4342
    44     [Storable]
    45     private IndexedDataTable<double> qualityPerClock;
     43    [Storable] private IndexedDataTable<double> qualityPerClock;
    4644
    47     [StorableConstructor]
    48     protected IncrementalSolver(bool deserializing)
    49       : base(deserializing) {
    50     }
    51 
    52     public IncrementalSolver() {
     45    public IncrementalLinearSolver() {
    5346      Parameters.Add(qualityUpdateIntervalParam =
    5447        new ValueParameter<TimeSpanValue>(nameof(QualityUpdateInterval),
     
    6659    }
    6760
    68     protected IncrementalSolver(IncrementalSolver original, Cloner cloner)
    69         : base(original, cloner) {
     61    [StorableConstructor]
     62    protected IncrementalLinearSolver(bool deserializing)
     63      : base(deserializing) {
     64    }
     65
     66    protected IncrementalLinearSolver(IncrementalLinearSolver original, Cloner cloner)
     67      : base(original, cloner) {
    7068      problemTypeParam = cloner.Clone(original.problemTypeParam);
    7169      qualityUpdateIntervalParam = cloner.Clone(original.qualityUpdateIntervalParam);
     
    7472    }
    7573
    76     public virtual bool SupportsQualityUpdate => true;
    77 
    7874    public TimeSpan QualityUpdateInterval {
    7975      get => qualityUpdateIntervalParam.Value.Value;
     
    8177    }
    8278
    83     protected virtual TimeSpan TimeLimit => QualityUpdateInterval;
     79    public virtual bool SupportsQualityUpdate => true;
     80    protected virtual TimeSpan IntermediateTimeLimit => QualityUpdateInterval;
    8481
    85     public override void Solve(LinearProgrammingAlgorithm algorithm, CancellationToken cancellationToken) {
     82    public override void Solve(ILinearProgrammingProblemDefinition problemDefinition, ref TimeSpan executionTime,
     83      ResultCollection results, CancellationToken cancellationToken) {
    8684      if (!SupportsQualityUpdate || QualityUpdateInterval == TimeSpan.Zero) {
    87         base.Solve(algorithm, cancellationToken);
     85        base.Solve(problemDefinition, ref executionTime, results, cancellationToken);
    8886        return;
    8987      }
    9088
    91       var timeLimit = algorithm.TimeLimit;
     89      var timeLimit = TimeLimit;
    9290      var unlimitedRuntime = timeLimit == TimeSpan.Zero;
    9391
    9492      if (!unlimitedRuntime) {
    95         timeLimit -= algorithm.ExecutionTime;
     93        timeLimit -= executionTime;
    9694      }
    9795
     
    104102          return;
    105103
    106         base.Solve(algorithm, TimeLimit);
    107         UpdateQuality(algorithm);
     104        Solve(problemDefinition, results, IntermediateTimeLimit);
     105        UpdateQuality(results, executionTime);
    108106
    109         var resultStatus = ((EnumValue<ResultStatus>)algorithm.Results[nameof(solver.ResultStatus)].Value).Value;
     107        var resultStatus = ((EnumValue<ResultStatus>)results["ResultStatus"].Value).Value;
    110108        if (!validResultStatuses.Contains(resultStatus))
    111109          return;
     
    116114
    117115      if (remaining > TimeSpan.Zero) {
    118         base.Solve(algorithm, remaining);
    119         UpdateQuality(algorithm);
     116        Solve(problemDefinition, results, remaining);
     117        UpdateQuality(results, executionTime);
    120118      }
    121119    }
    122120
    123     private void UpdateQuality(LinearProgrammingAlgorithm algorithm) {
    124       if (!algorithm.Results.Exists(r => r.Name == "QualityPerClock")) {
     121    private void UpdateQuality(ResultCollection results, TimeSpan executionTime) {
     122      if (!results.Exists(r => r.Name == "QualityPerClock")) {
    125123        qualityPerClock = new IndexedDataTable<double>("Quality per Clock");
    126124        qpcRow = new IndexedDataRow<double>("Objective Value");
    127125        bpcRow = new IndexedDataRow<double>("Bound");
    128         algorithm.Results.AddOrUpdateResult("QualityPerClock", qualityPerClock);
     126        results.AddOrUpdateResult("QualityPerClock", qualityPerClock);
    129127      }
    130128
    131       var resultStatus = ((EnumValue<ResultStatus>)algorithm.Results[nameof(solver.ResultStatus)].Value).Value;
     129      var resultStatus = ((EnumValue<ResultStatus>)results["ResultStatus"].Value).Value;
    132130
    133131      if (new[] { ResultStatus.Abnormal, ResultStatus.NotSolved, ResultStatus.Unbounded }.Contains(resultStatus))
    134132        return;
    135133
    136       var objective = ((DoubleValue)algorithm.Results[$"Best{nameof(solver.ObjectiveValue)}"].Value).Value;
    137       var bound = solver.IsMip ? ((DoubleValue)algorithm.Results[$"Best{nameof(solver.ObjectiveBound)}"].Value).Value : double.NaN;
    138       var time = algorithm.ExecutionTime.TotalSeconds;
     134      var objective = ((DoubleValue)results["BestObjectiveValue"].Value).Value;
     135      var bound = solver.IsMIP() ? ((DoubleValue)results["BestObjectiveBound"].Value).Value : double.NaN;
     136      var time = executionTime.TotalSeconds;
    139137
    140138      if (!qpcRow.Values.Any()) {
     
    143141          qpcRow.Values.Add(Tuple.Create(time, objective));
    144142          qualityPerClock.Rows.Add(qpcRow);
    145           algorithm.Results.AddOrUpdateResult($"Best{nameof(solver.ObjectiveValue)}FoundAt", new TimeSpanValue(TimeSpan.FromSeconds(time)));
     143          results.AddOrUpdateResult("BestObjectiveValueFoundAt", new TimeSpanValue(TimeSpan.FromSeconds(time)));
    146144        }
    147145      } else {
     
    150148        if (!objective.IsAlmost(previousBest)) {
    151149          qpcRow.Values.Add(Tuple.Create(time, objective));
    152           algorithm.Results.AddOrUpdateResult($"Best{nameof(solver.ObjectiveValue)}FoundAt", new TimeSpanValue(TimeSpan.FromSeconds(time)));
     150          results.AddOrUpdateResult("BestObjectiveValueFoundAt", new TimeSpanValue(TimeSpan.FromSeconds(time)));
    153151        }
    154152      }
    155153
    156       if (!solver.IsMip)
     154      if (!solver.IsMIP())
    157155        return;
    158156
Note: See TracChangeset for help on using the changeset viewer.