Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/19/18 14:15:49 (5 years 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
Location:
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms
Files:
9 edited
6 copied
7 moved

Legend:

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

    r16404 r16405  
    2727    IncrementalityOff = 0,
    2828
    29     // Reuse results from previous solve as much as the underlying
    30     // solver allows.
     29    // Reuse results from previous solve as much as the underlying solver allows.
    3130    IncrementalityOn = 1
    3231  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/IntegerParam.cs

    r16404 r16405  
    2020#endregion
    2121
    22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
     22namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms {
    2323
    2424  // Enumeration of parameters that take integer or categorical values.
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/LinearProgrammingAlgorithm.cs

    r16373 r16405  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
    28 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers;
    29 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
    30 using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
    3128using HeuristicLab.Optimization;
    3229using HeuristicLab.Parameters;
    3330using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3431
    35 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms {
     32namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3633
    3734  [Item("Linear/Mixed Integer Programming (LP/MIP)", "Linear/mixed integer programming implemented in several solvers. " +
     
    4542
    4643    [Storable]
     44    private readonly IFixedValueParameter<FileValue> exportModelParam;
     45
     46    [Storable]
    4747    private readonly IFixedValueParameter<EnumValue<LpAlgorithmValues>> lpAlgorithmParam;
    4848
     
    6060
    6161    [Storable]
    62     private IConstrainedValueParameter<ISolver> solverParam;
    63 
    64     [Storable]
    6562    private readonly IFixedValueParameter<TimeSpanValue> timeLimitParam;
    6663
    67     public IConstrainedValueParameter<ISolver> SolverParameter {
    68       get => solverParam;
    69       set => solverParam = value;
    70     }
     64    [Storable]
     65    private IConstrainedValueParameter<ILinearSolver> linearSolverParam;
    7166
    7267    public LinearProgrammingAlgorithm() {
    73       Parameters.Add(solverParam =
    74         new ConstrainedValueParameter<ISolver>(nameof(Solver), "The solver used to solve the model."));
    75 
    76       ISolver defaultSolver;
    77       solverParam.ValidValues.Add(new BopSolver());
    78       solverParam.ValidValues.Add(defaultSolver = new CoinOrSolver());
    79       solverParam.ValidValues.Add(new CplexSolver());
    80       solverParam.ValidValues.Add(new GlopSolver());
    81       solverParam.ValidValues.Add(new GlpkSolver());
    82       solverParam.ValidValues.Add(new GurobiSolver());
    83       solverParam.ValidValues.Add(new ScipSolver());
    84       solverParam.Value = defaultSolver;
     68      Parameters.Add(linearSolverParam =
     69        new ConstrainedValueParameter<ILinearSolver>(nameof(LinearSolver), "The solver used to solve the model."));
     70
     71      ILinearSolver defaultSolver;
     72      linearSolverParam.ValidValues.Add(new BopSolver());
     73      linearSolverParam.ValidValues.Add(defaultSolver = new CoinOrSolver());
     74      linearSolverParam.ValidValues.Add(new CplexSolver());
     75      linearSolverParam.ValidValues.Add(new GlopSolver());
     76      linearSolverParam.ValidValues.Add(new GlpkSolver());
     77      linearSolverParam.ValidValues.Add(new GurobiSolver());
     78      linearSolverParam.ValidValues.Add(new ScipSolver());
     79      linearSolverParam.Value = defaultSolver;
    8580
    8681      Parameters.Add(relativeGapToleranceParam = new FixedValueParameter<PercentValue>(nameof(RelativeGapTolerance),
     
    10297      Parameters.Add(scalingParam = new FixedValueParameter<BoolValue>(nameof(Scaling),
    10398        "Advanced usage: enable or disable matrix scaling.", new BoolValue()));
     99      Parameters.Add(exportModelParam =
     100        new FixedValueParameter<FileValue>(nameof(ExportModel),
     101          "Path of the file the model should be exported to. Run the algorithm to export the model.",
     102          new FileValue {
     103            SaveFile = true,
     104            FileDialogFilter = "CPLEX LP File (*.lp)|*.lp|" +
     105                               "Mathematical Programming System File (*.mps)|*.mps|" +
     106                               "Google OR-Tools Protocol Buffers Text File (*.prototxt)|*.prototxt|" +
     107                               "Google OR-Tools Protocol Buffers Binary File (*.bin)|*.bin"
     108          }));
    104109
    105110      Problem = new LinearProgrammingProblem();
     
    113118    protected LinearProgrammingAlgorithm(LinearProgrammingAlgorithm original, Cloner cloner)
    114119      : base(original, cloner) {
    115       solverParam = cloner.Clone(original.solverParam);
     120      linearSolverParam = cloner.Clone(original.linearSolverParam);
    116121      relativeGapToleranceParam = cloner.Clone(original.relativeGapToleranceParam);
    117122      timeLimitParam = cloner.Clone(original.timeLimitParam);
     
    121126      primalToleranceParam = cloner.Clone(original.primalToleranceParam);
    122127      scalingParam = cloner.Clone(original.scalingParam);
     128      exportModelParam = cloner.Clone(original.exportModelParam);
    123129    }
    124130
     
    128134    }
    129135
     136    public string ExportModel {
     137      get => exportModelParam.Value.Value;
     138      set => exportModelParam.Value.Value = value;
     139    }
     140
     141    public ILinearSolver LinearSolver {
     142      get => linearSolverParam.Value;
     143      set => linearSolverParam.Value = value;
     144    }
     145
     146    public IConstrainedValueParameter<ILinearSolver> LinearSolverParameter {
     147      get => linearSolverParam;
     148      set => linearSolverParam = value;
     149    }
     150
    130151    public LpAlgorithmValues LpAlgorithm {
    131152      get => lpAlgorithmParam.Value.Value;
     
    162183    }
    163184
    164     public ISolver Solver {
    165       get => solverParam.Value;
    166       set => solverParam.Value = value;
    167     }
    168 
    169     public override bool SupportsPause => Solver.SupportsPause;
    170 
    171     public override bool SupportsStop => Solver.SupportsStop;
     185    public override bool SupportsPause => LinearSolver.SupportsPause;
     186
     187    public override bool SupportsStop => LinearSolver.SupportsStop;
    172188
    173189    public TimeSpan TimeLimit {
     
    180196    public override void Pause() {
    181197      base.Pause();
    182       Solver.InterruptSolve();
     198      LinearSolver.InterruptSolve();
    183199    }
    184200
     
    187203      Results.Clear();
    188204
    189       foreach (var solver in solverParam.ValidValues) {
     205      foreach (var solver in linearSolverParam.ValidValues) {
    190206        solver.Reset();
    191207      }
     
    194210    public override void Stop() {
    195211      base.Stop();
    196       Solver.InterruptSolve();
    197     }
    198 
    199     protected override void Run(CancellationToken cancellationToken) => Solver.Solve(this, cancellationToken);
     212      LinearSolver.InterruptSolve();
     213    }
     214
     215    protected override void Run(CancellationToken cancellationToken) {
     216      LinearSolver.PrimalTolerance = PrimalTolerance;
     217      LinearSolver.DualTolerance = DualTolerance;
     218      LinearSolver.LpAlgorithm = LpAlgorithm;
     219      LinearSolver.Presolve = Presolve;
     220      LinearSolver.RelativeGapTolerance = RelativeGapTolerance;
     221      LinearSolver.Scaling = Scaling;
     222      LinearSolver.TimeLimit = TimeLimit;
     223      LinearSolver.ExportModel = ExportModel;
     224      var executionTime = ExecutionTime;
     225      ExecutionTimeChanged += (sender, args) => executionTime = ExecutionTime;
     226      LinearSolver.Solve(Problem.ProblemDefinition, ref executionTime, Results, cancellationToken);
     227    }
    200228  }
    201229}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/ProblemType.cs

    r16373 r16405  
    2020#endregion
    2121
    22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms {
     22namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2323
    2424  public enum ProblemType {
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/ExternalIncrementalLinearSolver.cs

    r16404 r16405  
    2020#endregion
    2121
     22using Google.OrTools.LinearSolver;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    27 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base {
     28namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2829
    2930  [StorableClass]
    30   public class ExternalIncrementalSolver : IncrementalSolver, IExternalSolver {
     31  public class ExternalIncrementalLinearSolver : IncrementalLinearSolver, IExternalLinearSolver {
    3132    protected const string FileDialogFilter = "Dynamic-Link Library (*.dll)|*.dll|All Files (*.*)|*.*";
    3233
     
    3435    protected IFixedValueParameter<FileValue> libraryNameParam;
    3536
    36     public ExternalIncrementalSolver() {
     37    public ExternalIncrementalLinearSolver() {
    3738    }
    3839
    3940    [StorableConstructor]
    40     protected ExternalIncrementalSolver(bool deserializing)
     41    protected ExternalIncrementalLinearSolver(bool deserializing)
    4142      : base(deserializing) {
    4243    }
    4344
    44     protected ExternalIncrementalSolver(ExternalIncrementalSolver original, Cloner cloner)
     45    protected ExternalIncrementalLinearSolver(ExternalIncrementalLinearSolver original, Cloner cloner)
    4546      : base(original, cloner) {
    4647      libraryNameParam = cloner.Clone(original.libraryNameParam);
     
    5152      set => libraryNameParam.Value.Value = value;
    5253    }
     54
     55    protected override Solver CreateSolver(OptimizationProblemType optimizationProblemType,
     56      string libraryName = null) => base.CreateSolver(optimizationProblemType, LibraryName);
    5357  }
    5458}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/ExternalLinearSolver.cs

    r16404 r16405  
    2020#endregion
    2121
     22using Google.OrTools.LinearSolver;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    27 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base {
     28namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2829
    2930  [StorableClass]
    30   public class ExternalSolver : Solver, IExternalSolver {
     31  public class ExternalLinearSolver : LinearSolver, IExternalLinearSolver {
    3132    protected const string FileDialogFilter = "Dynamic-Link Library (*.dll)|*.dll|All Files (*.*)|*.*";
    3233
     
    3435    protected IFixedValueParameter<FileValue> libraryNameParam;
    3536
    36     public ExternalSolver() {
     37    public ExternalLinearSolver() {
    3738    }
    3839
    3940    [StorableConstructor]
    40     protected ExternalSolver(bool deserializing)
     41    protected ExternalLinearSolver(bool deserializing)
    4142      : base(deserializing) {
    4243    }
    4344
    44     protected ExternalSolver(ExternalSolver original, Cloner cloner)
     45    protected ExternalLinearSolver(ExternalLinearSolver original, Cloner cloner)
    4546      : base(original, cloner) {
    4647      libraryNameParam = cloner.Clone(original.libraryNameParam);
     
    5152      set => libraryNameParam.Value.Value = value;
    5253    }
     54
     55    protected override Solver CreateSolver(OptimizationProblemType optimizationProblemType,
     56      string libraryName = null) => base.CreateSolver(optimizationProblemType, LibraryName);
    5357  }
    5458}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/IExternalLinearSolver.cs

    r16404 r16405  
    2020#endregion
    2121
    22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base {
     22namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2323
    24   public interface IExternalSolver : ISolver {
     24  public interface IExternalLinearSolver : ILinearSolver {
    2525    string LibraryName { get; set; }
    2626  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/IIncrementalLinearSolver.cs

    r16404 r16405  
    2222using System;
    2323
    24 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base {
     24namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2525
    26   public interface IIncrementalSolver : ISolver {
     26  public interface IIncrementalLinearSolver : ILinearSolver {
    2727    TimeSpan QualityUpdateInterval { get; set; }
    2828    bool SupportsQualityUpdate { get; }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/ILinearSolver.cs

    r16404 r16405  
    2020#endregion
    2121
     22using System;
    2223using System.Threading;
    2324using HeuristicLab.Core;
     25using HeuristicLab.Optimization;
    2426
    25 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base {
     27namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2628
    27   public interface ISolver : IParameterizedNamedItem {
    28     ProblemType ProblemType { get; set; }
     29  public interface ILinearSolver : IParameterizedNamedItem {
     30    double DualTolerance { get; set; }
     31
     32    string ExportModel { get; set; }
     33
     34    bool Incrementality { get; set; }
     35
     36    LpAlgorithmValues LpAlgorithm { get; set; }
     37
     38    bool Presolve { get; set; }
     39
     40    double PrimalTolerance { get; set; }
     41
     42    ProblemType ProblemType { get; }
     43
     44    double RelativeGapTolerance { get; set; }
     45
     46    bool Scaling { get; set; }
     47
    2948    bool SupportsPause { get; }
     49
    3050    bool SupportsStop { get; }
     51
     52    TimeSpan TimeLimit { get; set; }
    3153
    3254    bool InterruptSolve();
     
    3456    void Reset();
    3557
    36     void Solve(LinearProgrammingAlgorithm algorithm);
     58    void Solve(ILinearProgrammingProblemDefinition problemDefintion, ref TimeSpan executionTime, ResultCollection results);
    3759
    38     void Solve(LinearProgrammingAlgorithm algorithm, CancellationToken cancellationToken);
     60    void Solve(ILinearProgrammingProblemDefinition problemDefintion, ref TimeSpan executionTime,
     61      ResultCollection results, CancellationToken cancellationToken);
    3962  }
    4063}
  • 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
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/LinearSolver.cs

    r16404 r16405  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.IO;
     25using System.Linq;
     26using System.Reflection;
    2327using System.Threading;
     28using Google.OrTools.LinearSolver;
    2429using HeuristicLab.Common;
    2530using HeuristicLab.Core;
    2631using HeuristicLab.Data;
     32using HeuristicLab.Optimization;
    2733using HeuristicLab.Parameters;
    2834using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2935
    30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base {
     36namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3137
    3238  [StorableClass]
    33   public class Solver : ParameterizedNamedItem, ISolver, IDisposable {
     39  public class LinearSolver : ParameterizedNamedItem, ILinearSolver, IDisposable {
    3440
    3541    [Storable]
    3642    protected IValueParameter<EnumValue<ProblemType>> problemTypeParam;
    3743
    38     protected LinearSolver solver;
     44    protected Solver solver;
    3945
    4046    [Storable]
    4147    protected IFixedValueParameter<TextValue> solverSpecificParametersParam;
    4248
    43     public Solver() {
     49    public LinearSolver() {
    4450      Parameters.Add(problemTypeParam =
    4551        new ValueParameter<EnumValue<ProblemType>>(nameof(ProblemType), new EnumValue<ProblemType>()));
     
    4955
    5056    [StorableConstructor]
    51     protected Solver(bool deserializing)
     57    protected LinearSolver(bool deserializing)
    5258      : base(deserializing) {
    5359    }
    5460
    55     protected Solver(Solver original, Cloner cloner)
     61    protected LinearSolver(LinearSolver original, Cloner cloner)
    5662      : base(original, cloner) {
    5763      problemTypeParam = cloner.Clone(original.problemTypeParam);
     
    5965    }
    6066
     67    public double DualTolerance { get; set; } = MPSolverParameters.kDefaultDualTolerance;
     68
     69    public string ExportModel { get; set; }
     70
     71    public bool Incrementality { get; set; } =
     72          MPSolverParameters.kDefaultIncrementality == MPSolverParameters.INCREMENTALITY_ON;
     73
     74    public LpAlgorithmValues LpAlgorithm { get; set; }
     75
     76    public bool Presolve { get; set; } = MPSolverParameters.kDefaultPresolve == MPSolverParameters.PRESOLVE_ON;
     77
     78    public double PrimalTolerance { get; set; } = MPSolverParameters.kDefaultPrimalTolerance;
     79
    6180    public ProblemType ProblemType {
    6281      get => problemTypeParam.Value.Value;
     
    6483    }
    6584
    66     public TextValue SolverSpecificParameters => solverSpecificParametersParam.Value;
     85    public double RelativeGapTolerance { get; set; } = MPSolverParameters.kDefaultRelativeMipGap;
     86
     87    public bool Scaling { get; set; }
     88
     89    public string SolverSpecificParameters {
     90      get => solverSpecificParametersParam.Value.Value;
     91      set => solverSpecificParametersParam.Value.Value = value;
     92    }
    6793
    6894    public virtual bool SupportsPause => true;
    6995    public virtual bool SupportsStop => true;
     96    public virtual TimeSpan TimeLimit { get; set; } = TimeSpan.Zero;
    7097    protected virtual OptimizationProblemType OptimizationProblemType { get; }
    7198
    72     public override IDeepCloneable Clone(Cloner cloner) => new Solver(this, cloner);
     99    public override IDeepCloneable Clone(Cloner cloner) => new LinearSolver(this, cloner);
    73100
    74101    public void Dispose() => solver?.Dispose();
     102
     103    public bool ExportAsLp(string fileName, bool obfuscated = false) {
     104      var lpFormat = solver?.ExportModelAsLpFormat(obfuscated);
     105      if (string.IsNullOrEmpty(lpFormat))
     106        return false;
     107      File.WriteAllText(fileName, lpFormat);
     108      return true;
     109    }
     110
     111    public bool ExportAsMps(string fileName, bool fixedFormat = false, bool obfuscated = false) {
     112      var mpsFormat = solver?.ExportModelAsMpsFormat(fixedFormat, obfuscated);
     113      if (string.IsNullOrEmpty(mpsFormat))
     114        return false;
     115      File.WriteAllText(fileName, mpsFormat);
     116      return true;
     117    }
     118
     119    public bool ExportAsProto(string fileName, ProtoWriteFormat writeFormat = ProtoWriteFormat.ProtoBinary) =>
     120      solver != null && solver.ExportModelAsProtoFormat(fileName, (int)writeFormat);
     121
     122    public SolverResponseStatus ImportFromMps(string fileName, bool? fixedFormat) => solver == null
     123      ? SolverResponseStatus.Abnormal
     124      : (SolverResponseStatus)solver.ImportModelFromMpsFormat(fileName, fixedFormat.HasValue, fixedFormat ?? false);
     125
     126    public SolverResponseStatus ImportFromProto(string fileName) => solver == null
     127      ? SolverResponseStatus.Abnormal
     128      : (SolverResponseStatus)solver.ImportModelFromProtoFormat(fileName);
    75129
    76130    public bool InterruptSolve() => solver?.InterruptSolve() ?? false;
     
    81135    }
    82136
    83     public virtual void Solve(LinearProgrammingAlgorithm algorithm, CancellationToken cancellationToken) =>
    84       Solve(algorithm);
    85 
    86     public virtual void Solve(LinearProgrammingAlgorithm algorithm) =>
    87       Solve(algorithm, algorithm.TimeLimit);
    88 
    89     public virtual void Solve(LinearProgrammingAlgorithm algorithm, TimeSpan timeLimit) {
    90       string libraryName = null;
    91       if (this is IExternalSolver externalSolver)
    92         libraryName = externalSolver.LibraryName;
    93 
     137    public virtual void Solve(ILinearProgrammingProblemDefinition problemDefintion, ref TimeSpan executionTime,
     138      ResultCollection results, CancellationToken cancellationToken) =>
     139      Solve(problemDefintion, ref executionTime, results);
     140
     141    public virtual void Solve(ILinearProgrammingProblemDefinition problemDefinition, ref TimeSpan executionTime,
     142      ResultCollection results) =>
     143      Solve(problemDefinition, results, TimeLimit);
     144
     145    public virtual void Solve(ILinearProgrammingProblemDefinition problemDefinition, ResultCollection results,
     146      TimeSpan timeLimit) {
    94147      if (solver == null) {
    95         solver = new LinearSolver(OptimizationProblemType, s => algorithm.Problem.ProblemDefinition.BuildModel(s), Name,
    96           libraryName);
    97       }
    98 
    99       solver.TimeLimit = timeLimit;
    100       solver.RelativeGapTolerance = algorithm.RelativeGapTolerance;
    101       solver.PrimalTolerance = algorithm.PrimalTolerance;
    102       solver.DualTolerance = algorithm.DualTolerance;
    103       solver.Presolve = algorithm.Presolve;
    104       solver.Scaling = algorithm.Scaling;
    105       solver.LpAlgorithm = algorithm.LpAlgorithm;
    106       solver.Incrementality = true;
    107 
    108       if (!solver.SetSolverSpecificParameters(SolverSpecificParameters.Value))
    109         throw new ArgumentException("Solver specific parameters could not be set.");
    110 
    111       solver.Solve();
    112 
    113       algorithm.Problem.ProblemDefinition.Analyze(solver.Solver, algorithm.Results);
    114       algorithm.Results.AddOrUpdateResult(nameof(solver.ResultStatus),
    115         new EnumValue<ResultStatus>(solver.ResultStatus));
    116       algorithm.Results.AddOrUpdateResult($"Best{nameof(solver.ObjectiveValue)}",
    117         new DoubleValue(solver.ObjectiveValue ?? double.NaN));
    118 
    119       if (solver.IsMip) {
    120         algorithm.Results.AddOrUpdateResult($"Best{nameof(solver.ObjectiveBound)}",
    121           new DoubleValue(solver.ObjectiveBound ?? double.NaN));
    122         algorithm.Results.AddOrUpdateResult(nameof(solver.AbsoluteGap),
    123           new DoubleValue(solver.AbsoluteGap ?? double.NaN));
    124         algorithm.Results.AddOrUpdateResult(nameof(solver.RelativeGap),
    125           new PercentValue(solver.RelativeGap ?? double.NaN));
    126       }
    127 
    128       algorithm.Results.AddOrUpdateResult(nameof(solver.NumberOfConstraints), new IntValue(solver.NumberOfConstraints));
    129       algorithm.Results.AddOrUpdateResult(nameof(solver.NumberOfVariables), new IntValue(solver.NumberOfVariables));
    130 
    131       if (solver.IsMip) {
    132         algorithm.Results.AddOrUpdateResult(nameof(solver.NumberOfNodes), new DoubleValue(solver.NumberOfNodes));
    133       }
    134 
    135       algorithm.Results.AddOrUpdateResult(nameof(solver.Iterations), new DoubleValue(solver.Iterations));
    136       algorithm.Results.AddOrUpdateResult(nameof(solver.SolverVersion), new StringValue(solver.SolverVersion));
     148        solver = CreateSolver(OptimizationProblemType);
     149        problemDefinition.BuildModel(solver);
     150      }
     151
     152      if (timeLimit > TimeSpan.Zero) {
     153        solver.SetTimeLimit((long)timeLimit.TotalMilliseconds);
     154      } else {
     155        solver.SetTimeLimit(0);
     156      }
     157
     158      ResultStatus resultStatus;
     159
     160      using (var parameters = new MPSolverParameters()) {
     161        parameters.SetDoubleParam(MPSolverParameters.RELATIVE_MIP_GAP, RelativeGapTolerance);
     162        parameters.SetDoubleParam(MPSolverParameters.PRIMAL_TOLERANCE, PrimalTolerance);
     163        parameters.SetDoubleParam(MPSolverParameters.DUAL_TOLERANCE, DualTolerance);
     164        parameters.SetIntegerParam(MPSolverParameters.PRESOLVE,
     165          Presolve ? MPSolverParameters.PRESOLVE_ON : MPSolverParameters.PRESOLVE_OFF);
     166        parameters.SetIntegerParam(MPSolverParameters.LP_ALGORITHM, (int)LpAlgorithm);
     167        parameters.SetIntegerParam(MPSolverParameters.INCREMENTALITY,
     168          Incrementality ? MPSolverParameters.INCREMENTALITY_ON : MPSolverParameters.INCREMENTALITY_OFF);
     169        parameters.SetIntegerParam(MPSolverParameters.SCALING,
     170          Scaling ? MPSolverParameters.SCALING_ON : MPSolverParameters.SCALING_OFF);
     171
     172        if (!solver.SetSolverSpecificParametersAsString(SolverSpecificParameters))
     173          throw new ArgumentException("Solver specific parameters could not be set.");
     174
     175        if (!string.IsNullOrWhiteSpace(ExportModel)) {
     176          var fileInfo = new FileInfo(ExportModel);
     177
     178          if (!fileInfo.Directory?.Exists ?? false) {
     179            Directory.CreateDirectory(fileInfo.Directory.FullName);
     180          }
     181
     182          bool exportSuccessful;
     183          switch (fileInfo.Extension) {
     184            case ".lp":
     185              exportSuccessful = ExportAsLp(ExportModel);
     186              break;
     187
     188            case ".mps":
     189              exportSuccessful = ExportAsMps(ExportModel);
     190              break;
     191
     192            case ".prototxt":
     193              exportSuccessful = ExportAsProto(ExportModel, ProtoWriteFormat.ProtoText);
     194              break;
     195
     196            case ".bin": // remove file extension as it is added by OR-Tools
     197              exportSuccessful = ExportAsProto(Path.ChangeExtension(ExportModel, null));
     198              break;
     199
     200            default:
     201              throw new NotSupportedException("File format selected to export model is not supported.");
     202          }
     203        }
     204
     205        // TODO: show warning if file export didn't work (if exportSuccessful is false)
     206
     207        resultStatus = (ResultStatus)solver.Solve(parameters);
     208      }
     209
     210      var objectiveValue = solver.Objective()?.Value();
     211
     212      problemDefinition.Analyze(solver, results);
     213      results.AddOrUpdateResult("ResultStatus", new EnumValue<ResultStatus>(resultStatus));
     214      results.AddOrUpdateResult("BestObjectiveValue", new DoubleValue(objectiveValue ?? double.NaN));
     215
     216      if (solver.IsMIP()) {
     217        var objectiveBound = solver.Objective()?.BestBound();
     218        var absoluteGap = objectiveValue.HasValue && objectiveBound.HasValue
     219          ? Math.Abs(objectiveBound.Value - objectiveValue.Value)
     220          : (double?)null;
     221        // https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.1/ilog.odms.cplex.help/CPLEX/Parameters/topics/EpGap.html
     222        var relativeGap = absoluteGap.HasValue && objectiveValue.HasValue
     223          ? absoluteGap.Value / (1e-10 + Math.Abs(objectiveValue.Value))
     224          : (double?)null;
     225
     226        results.AddOrUpdateResult("BestObjectiveBound", new DoubleValue(objectiveBound ?? double.NaN));
     227        results.AddOrUpdateResult("AbsoluteGap", new DoubleValue(absoluteGap ?? double.NaN));
     228        results.AddOrUpdateResult("RelativeGap", new PercentValue(relativeGap ?? double.NaN));
     229      }
     230
     231      results.AddOrUpdateResult("NumberOfConstraints", new IntValue(solver.NumConstraints()));
     232      results.AddOrUpdateResult("NumberOfVariables", new IntValue(solver.NumVariables()));
     233
     234      if (solver.IsMIP() && solver.Nodes() >= 0) {
     235        results.AddOrUpdateResult(nameof(solver.Nodes), new DoubleValue(solver.Nodes()));
     236      }
     237
     238      if (solver.Iterations() >= 0) {
     239        results.AddOrUpdateResult(nameof(solver.Iterations), new DoubleValue(solver.Iterations()));
     240      }
     241
     242      results.AddOrUpdateResult(nameof(solver.SolverVersion), new StringValue(solver.SolverVersion()));
     243    }
     244
     245    protected virtual Solver CreateSolver(OptimizationProblemType optimizationProblemType, string libraryName = null) {
     246      if (!string.IsNullOrEmpty(libraryName) && !File.Exists(libraryName)) {
     247        var paths = new List<string> {
     248          Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath)
     249        };
     250        var path = Environment.GetEnvironmentVariable("PATH");
     251        if (path != null)
     252          paths.AddRange(path.Split(';'));
     253        if (!paths.Any(p => File.Exists(Path.Combine(p, libraryName))))
     254          throw new FileNotFoundException($"Could not find library {libraryName} in PATH.", libraryName);
     255      }
     256
     257      try {
     258        solver = new Solver(Name, (int)optimizationProblemType, libraryName ?? string.Empty);
     259      } catch {
     260        throw new InvalidOperationException($"Could not create {optimizationProblemType}.");
     261      }
     262
     263      if (solver == null)
     264        throw new InvalidOperationException($"Could not create {optimizationProblemType}.");
     265
     266      solver.SuppressOutput();
     267      return solver;
    137268    }
    138269  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/BopSolver.cs

    r16373 r16405  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
    26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
    2726using HeuristicLab.Parameters;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers {
     29namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3130
    3231  [Item("BOP", "BOP (https://developers.google.com/optimization/reference/bop/bop_solver/) can be used out of the box.")]
    3332  [StorableClass]
    34   public class BopSolver : IncrementalSolver {
     33  public class BopSolver : IncrementalLinearSolver {
    3534
    3635    public BopSolver() {
    3736      Parameters.Remove(problemTypeParam);
    3837      Parameters.Add(new FixedValueParameter<StringValue>(nameof(ProblemType), new StringValue("ZeroOneProgramming").AsReadOnly()));
    39       SolverSpecificParameters.Value =
     38      SolverSpecificParameters =
    4039        "# for file format, see Protocol Buffers text format (https://developers.google.com/protocol-buffers/docs/overview#whynotxml)" + Environment.NewLine +
    4140        "# for parameters, see https://github.com/google/or-tools/blob/v6.10/ortools/bop/bop_parameters.proto" + Environment.NewLine +
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/CoinOrSolver.cs

    r16373 r16405  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    24 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
     25using HeuristicLab.Optimization;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2627
    27 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers {
     28namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2829
    2930  [Item("Clp/Cbc", "Clp (https://projects.coin-or.org/Clp) and Cbc (https://projects.coin-or.org/Cbc) can be used out of the box.")]
    3031  [StorableClass]
    31   public class CoinOrSolver : IncrementalSolver {
     32  public class CoinOrSolver : IncrementalLinearSolver {
    3233
    3334    public CoinOrSolver() {
     
    5455        ? OptimizationProblemType.ClpLinearProgramming
    5556        : OptimizationProblemType.CbcMixedIntegerProgramming;
     57
     58    public override void Solve(ILinearProgrammingProblemDefinition problemDefinition, ResultCollection results, TimeSpan timeLimit) {
     59      // TODO: warning that solver cannot be stopped or paused
     60      base.Solve(problemDefinition, results, timeLimit);
     61    }
    5662  }
    5763}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/CplexSolver.cs

    r16373 r16405  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
    26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
    2726using HeuristicLab.Parameters;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers {
     29namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3130
    3231  [Item("CPLEX", "CPLEX (https://www.ibm.com/analytics/cplex-optimizer) must be installed and licenced.")]
    3332  [StorableClass]
    34   public class CplexSolver : ExternalIncrementalSolver {
     33  public class CplexSolver : ExternalIncrementalLinearSolver {
    3534
    3635    public CplexSolver() {
    3736      Parameters.Add(libraryNameParam = new FixedValueParameter<FileValue>(nameof(LibraryName),
    3837        new FileValue { FileDialogFilter = FileDialogFilter, Value = Properties.Settings.Default.CplexLibraryName }));
    39       SolverSpecificParameters.Value =
     38      SolverSpecificParameters =
    4039        "CPLEX Parameter File Version 12.8.0" + Environment.NewLine +
    4140        "# for file format, see https://www.ibm.com/support/knowledgecenter/SSSA5P_12.8.0/ilog.odms.cplex.help/CPLEX/FileFormats/topics/PRM.html" + Environment.NewLine +
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/GlopSolver.cs

    r16373 r16405  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
    26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827
    29 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers {
     28namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3029
    3130  [Item("Glop", "Glop (https://developers.google.com/optimization/lp/glop) can be used out of the box.")]
    3231  [StorableClass]
    33   public class GlopSolver : IncrementalSolver {
     32  public class GlopSolver : IncrementalLinearSolver {
    3433
    3534    public GlopSolver() {
    3635      problemTypeParam.Value = (EnumValue<ProblemType>)problemTypeParam.Value.AsReadOnly();
    37       SolverSpecificParameters.Value =
     36      SolverSpecificParameters =
    3837        "# for file format, see Protocol Buffers text format (https://developers.google.com/protocol-buffers/docs/overview#whynotxml)" + Environment.NewLine +
    3938        "# for parameters, see https://github.com/google/or-tools/blob/v6.10/ortools/glop/parameters.proto" + Environment.NewLine +
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/GlpkSolver.cs

    r16373 r16405  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Data;
    25 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
    2625using HeuristicLab.Parameters;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827
    29 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers {
     28namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3029
    3130  [Item("GLPK", "GLPK (https://www.gnu.org/software/glpk/) can be used out of the box.")]
    3231  [StorableClass]
    33   public class GlpkSolver : ExternalIncrementalSolver {
     32  public class GlpkSolver : ExternalLinearSolver {
    3433
    3534    public GlpkSolver() {
     
    4847    }
    4948
    50     public override bool SupportsPause => ProblemType == ProblemType.LinearProgramming; // TODO: pause working for linear programs?
    51 
    52     public override bool SupportsQualityUpdate => ProblemType == ProblemType.LinearProgramming;
     49    public override bool SupportsPause => false;
    5350
    5451    protected override OptimizationProblemType OptimizationProblemType =>
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/GurobiSolver.cs

    r16373 r16405  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
    26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
    2726using HeuristicLab.Parameters;
    2827using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2928
    30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers {
     29namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3130
    3231  [Item("Gurobi", "Gurobi (http://www.gurobi.com/) must be installed and licenced.")]
    3332  [StorableClass]
    34   public class GurobiSolver : ExternalIncrementalSolver {
     33  public class GurobiSolver : ExternalIncrementalLinearSolver {
    3534
    3635    public GurobiSolver() {
    3736      Parameters.Add(libraryNameParam = new FixedValueParameter<FileValue>(nameof(LibraryName),
    3837        new FileValue { FileDialogFilter = FileDialogFilter, Value = Properties.Settings.Default.GurobiLibraryName }));
    39       SolverSpecificParameters.Value =
     38      SolverSpecificParameters =
    4039        "# for file format, see http://www.gurobi.com/documentation/8.1/refman/prm_format.html" + Environment.NewLine +
    4140        "# for parameters, see http://www.gurobi.com/documentation/8.1/refman/parameters.html" + Environment.NewLine +
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/ScipSolver.cs

    r16373 r16405  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;
     27using HeuristicLab.Optimization;
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    31 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers {
     31namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3232
    3333  [Item("SCIP", "SCIP (http://scip.zib.de/) must be installed and licenced.")]
    3434  [StorableClass]
    35   public class ScipSolver : ExternalIncrementalSolver {
    36 
     35  public class ScipSolver : ExternalIncrementalLinearSolver {
    3736    private TimeSpan timeLimit = TimeSpan.Zero;
    3837
     
    4241      problemTypeParam.Value =
    4342        (EnumValue<ProblemType>)new EnumValue<ProblemType>(ProblemType.MixedIntegerProgramming).AsReadOnly();
    44       SolverSpecificParameters.Value =
     43      SolverSpecificParameters =
    4544        "# for file format and parameters, see https://scip.zib.de/doc/html/PARAMETERS.php" + Environment.NewLine +
    4645        "# example:" + Environment.NewLine +
     
    5756    }
    5857
     58    protected override TimeSpan IntermediateTimeLimit => timeLimit += QualityUpdateInterval;
     59
    5960    protected override OptimizationProblemType OptimizationProblemType =>
    60       OptimizationProblemType.ScipMixedIntegerProgramming;
    61     protected override TimeSpan TimeLimit => timeLimit += QualityUpdateInterval;
     61          OptimizationProblemType.ScipMixedIntegerProgramming;
    6262
    63     public override void Solve(LinearProgrammingAlgorithm algorithm, CancellationToken cancellationToken) {
     63    public override void Solve(ILinearProgrammingProblemDefinition problemDefintion, ref TimeSpan executionTime, ResultCollection results, CancellationToken cancellationToken) {
    6464      timeLimit = TimeSpan.Zero;
    65       base.Solve(algorithm, cancellationToken);
     65      base.Solve(problemDefintion, ref executionTime, results, cancellationToken);
    6666    }
    6767  }
Note: See TracChangeset for help on using the changeset viewer.