Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/29/19 17:45:06 (5 years ago)
Author:
ddorfmei
Message:

#2931: solved the issues found during the review

File:
1 edited

Legend:

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

    r16405 r16582  
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3131
    32 namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    33 
    34   [Item("Linear/Mixed Integer Programming (LP/MIP)", "Linear/mixed integer programming implemented in several solvers. " +
    35     "See also https://dev.heuristiclab.com/trac.fcgi/wiki/Documentation/Howto/LinearMixedIntegerProgramming")] // TODO: update link
     32namespace HeuristicLab.ExactOptimization.LinearProgramming {
     33
     34  [Item("Mixed-Integer Linear Programming (LP, MIP)", "Linear/mixed integer programming implemented in several solvers. " +
     35    "See also https://dev.heuristiclab.com/trac.fcgi/wiki/Documentation/Reference/ExactOptimization")]
    3636  [Creatable(CreatableAttribute.Categories.ExactAlgorithms)]
    3737  [StorableClass]
    38   public class LinearProgrammingAlgorithm : BasicAlgorithm {
     38  public sealed class LinearProgrammingAlgorithm : BasicAlgorithm {
    3939
    4040    [Storable]
     
    4242
    4343    [Storable]
    44     private readonly IFixedValueParameter<FileValue> exportModelParam;
    45 
    46     [Storable]
    47     private readonly IFixedValueParameter<EnumValue<LpAlgorithmValues>> lpAlgorithmParam;
    48 
    49     [Storable]
    5044    private readonly IFixedValueParameter<BoolValue> presolveParam;
    5145
     
    6458    [Storable]
    6559    private IConstrainedValueParameter<ILinearSolver> linearSolverParam;
     60
     61    #region Problem Properties
     62
     63    public new LinearProblem Problem {
     64      get => (LinearProblem)base.Problem;
     65      set => base.Problem = value;
     66    }
     67
     68    public override Type ProblemType { get; } = typeof(LinearProblem);
     69
     70    #endregion
     71    #region Parameter Properties
     72
     73    public IFixedValueParameter<DoubleValue> DualToleranceParameter => dualToleranceParam;
     74    public IConstrainedValueParameter<ILinearSolver> LinearSolverParameter => linearSolverParam;
     75    public IFixedValueParameter<BoolValue> PresolveParameter => presolveParam;
     76    public IFixedValueParameter<DoubleValue> PrimalToleranceParameter => primalToleranceParam;
     77    public IFixedValueParameter<PercentValue> RelativeGapToleranceParameter => relativeGapToleranceParam;
     78    public IFixedValueParameter<BoolValue> ScalingParameter => scalingParam;
     79    public IFixedValueParameter<TimeSpanValue> TimeLimitParameter => timeLimitParam;
     80
     81    #endregion
     82    #region Properties
     83
     84    public double DualTolerance {
     85      get => dualToleranceParam.Value.Value;
     86      set => dualToleranceParam.Value.Value = value;
     87    }
     88
     89    public ILinearSolver LinearSolver {
     90      get => linearSolverParam.Value;
     91      set => linearSolverParam.Value = value;
     92    }
     93
     94    public bool Presolve {
     95      get => presolveParam.Value.Value;
     96      set => presolveParam.Value.Value = value;
     97    }
     98
     99    public double PrimalTolerance {
     100      get => primalToleranceParam.Value.Value;
     101      set => primalToleranceParam.Value.Value = value;
     102    }
     103
     104    public double RelativeGapTolerance {
     105      get => relativeGapToleranceParam.Value.Value;
     106      set => relativeGapToleranceParam.Value.Value = value;
     107    }
     108
     109    public bool Scaling {
     110      get => scalingParam.Value.Value;
     111      set => scalingParam.Value.Value = value;
     112    }
     113
     114    public override bool SupportsPause => LinearSolver.SupportsPause;
     115    public override bool SupportsStop => LinearSolver.SupportsStop;
     116
     117    public TimeSpan TimeLimit {
     118      get => timeLimitParam.Value.Value;
     119      set => timeLimitParam.Value.Value = value;
     120    }
     121
     122    #endregion
    66123
    67124    public LinearProgrammingAlgorithm() {
     
    70127
    71128      ILinearSolver defaultSolver;
    72       linearSolverParam.ValidValues.Add(new BopSolver());
    73129      linearSolverParam.ValidValues.Add(defaultSolver = new CoinOrSolver());
    74130      linearSolverParam.ValidValues.Add(new CplexSolver());
    75131      linearSolverParam.ValidValues.Add(new GlopSolver());
    76       linearSolverParam.ValidValues.Add(new GlpkSolver());
    77132      linearSolverParam.ValidValues.Add(new GurobiSolver());
    78133      linearSolverParam.ValidValues.Add(new ScipSolver());
     
    80135
    81136      Parameters.Add(relativeGapToleranceParam = new FixedValueParameter<PercentValue>(nameof(RelativeGapTolerance),
    82         "Limit for relative MIP gap.", new PercentValue(MPSolverParameters.kDefaultRelativeMipGap)));
     137        "Limit for relative MIP gap.", new PercentValue(SolverParameters.DefaultRelativeMipGap)));
    83138      Parameters.Add(timeLimitParam = new FixedValueParameter<TimeSpanValue>(nameof(TimeLimit),
    84         "Limit for runtime. Set to zero for unlimited runtime.", new TimeSpanValue()));
     139        "Limit for runtime. Set to zero for unlimited runtime.",
     140        new TimeSpanValue(new TimeSpan(0, 1, 0))));
    85141      Parameters.Add(presolveParam =
    86         new FixedValueParameter<BoolValue>(nameof(Presolve), "Advanced usage: presolve mode.", new BoolValue()));
    87       Parameters.Add(lpAlgorithmParam = new FixedValueParameter<EnumValue<LpAlgorithmValues>>(nameof(LpAlgorithm),
    88         "Algorithm to solve linear programs.", new EnumValue<LpAlgorithmValues>(LpAlgorithmValues.DualSimplex)));
     142        new FixedValueParameter<BoolValue>(nameof(Presolve), "Advanced usage: presolve mode.",
     143          new BoolValue(SolverParameters.DefaultPresolve == SolverParameters.PresolveValues.PresolveOn)) { Hidden = true });
    89144      Parameters.Add(dualToleranceParam = new FixedValueParameter<DoubleValue>(nameof(DualTolerance),
    90145        "Advanced usage: tolerance for dual feasibility of basic solutions.",
    91         new DoubleValue(MPSolverParameters.kDefaultDualTolerance)));
     146        new DoubleValue(SolverParameters.DefaultDualTolerance)) { Hidden = true });
    92147      Parameters.Add(primalToleranceParam = new FixedValueParameter<DoubleValue>(nameof(PrimalTolerance),
    93148        "Advanced usage: tolerance for primal feasibility of basic solutions. " +
    94149        "This does not control the integer feasibility tolerance of integer " +
    95150        "solutions for MIP or the tolerance used during presolve.",
    96         new DoubleValue(MPSolverParameters.kDefaultPrimalTolerance)));
     151        new DoubleValue(SolverParameters.DefaultPrimalTolerance)) { Hidden = true });
    97152      Parameters.Add(scalingParam = new FixedValueParameter<BoolValue>(nameof(Scaling),
    98         "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           }));
    109 
    110       Problem = new LinearProgrammingProblem();
     153        "Advanced usage: enable or disable matrix scaling.", new BoolValue()) { Hidden = true });
     154
     155      Problem = new LinearProblem();
    111156    }
    112157
    113158    [StorableConstructor]
    114     protected LinearProgrammingAlgorithm(bool deserializing)
     159    private LinearProgrammingAlgorithm(bool deserializing)
    115160      : base(deserializing) {
    116161    }
    117162
    118     protected LinearProgrammingAlgorithm(LinearProgrammingAlgorithm original, Cloner cloner)
     163    private LinearProgrammingAlgorithm(LinearProgrammingAlgorithm original, Cloner cloner)
    119164      : base(original, cloner) {
    120165      linearSolverParam = cloner.Clone(original.linearSolverParam);
     
    122167      timeLimitParam = cloner.Clone(original.timeLimitParam);
    123168      presolveParam = cloner.Clone(original.presolveParam);
    124       lpAlgorithmParam = cloner.Clone(original.lpAlgorithmParam);
    125169      dualToleranceParam = cloner.Clone(original.dualToleranceParam);
    126170      primalToleranceParam = cloner.Clone(original.primalToleranceParam);
    127171      scalingParam = cloner.Clone(original.scalingParam);
    128       exportModelParam = cloner.Clone(original.exportModelParam);
    129     }
    130 
    131     public double DualTolerance {
    132       get => dualToleranceParam.Value.Value;
    133       set => dualToleranceParam.Value.Value = value;
    134     }
    135 
    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 
    151     public LpAlgorithmValues LpAlgorithm {
    152       get => lpAlgorithmParam.Value.Value;
    153       set => lpAlgorithmParam.Value.Value = value;
    154     }
    155 
    156     public bool Presolve {
    157       get => presolveParam.Value.Value;
    158       set => presolveParam.Value.Value = value;
    159     }
    160 
    161     public double PrimalTolerance {
    162       get => primalToleranceParam.Value.Value;
    163       set => primalToleranceParam.Value.Value = value;
    164     }
    165 
    166     public new LinearProgrammingProblem Problem {
    167       get => (LinearProgrammingProblem)base.Problem;
    168       set => base.Problem = value;
    169     }
    170 
    171     public override Type ProblemType { get; } = typeof(LinearProgrammingProblem);
    172 
    173     public double RelativeGapTolerance {
    174       get => relativeGapToleranceParam.Value.Value;
    175       set => relativeGapToleranceParam.Value.Value = value;
    176     }
    177 
    178     public override ResultCollection Results { get; } = new ResultCollection();
    179 
    180     public bool Scaling {
    181       get => scalingParam.Value.Value;
    182       set => scalingParam.Value.Value = value;
    183     }
    184 
    185     public override bool SupportsPause => LinearSolver.SupportsPause;
    186 
    187     public override bool SupportsStop => LinearSolver.SupportsStop;
    188 
    189     public TimeSpan TimeLimit {
    190       get => timeLimitParam.Value.Value;
    191       set => timeLimitParam.Value.Value = value;
    192172    }
    193173
     
    216196      LinearSolver.PrimalTolerance = PrimalTolerance;
    217197      LinearSolver.DualTolerance = DualTolerance;
    218       LinearSolver.LpAlgorithm = LpAlgorithm;
    219198      LinearSolver.Presolve = Presolve;
    220199      LinearSolver.RelativeGapTolerance = RelativeGapTolerance;
    221200      LinearSolver.Scaling = Scaling;
    222201      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);
     202      LinearSolver.Solve(Problem.ProblemDefinition, Results, cancellationToken);
    227203    }
    228204  }
Note: See TracChangeset for help on using the changeset viewer.