Changeset 16582 for branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/LinearProgrammingAlgorithm.cs
- Timestamp:
- 01/29/19 17:45:06 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/LinearProgrammingAlgorithm.cs
r16405 r16582 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 31 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 link32 namespace 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")] 36 36 [Creatable(CreatableAttribute.Categories.ExactAlgorithms)] 37 37 [StorableClass] 38 public class LinearProgrammingAlgorithm : BasicAlgorithm {38 public sealed class LinearProgrammingAlgorithm : BasicAlgorithm { 39 39 40 40 [Storable] … … 42 42 43 43 [Storable] 44 private readonly IFixedValueParameter<FileValue> exportModelParam;45 46 [Storable]47 private readonly IFixedValueParameter<EnumValue<LpAlgorithmValues>> lpAlgorithmParam;48 49 [Storable]50 44 private readonly IFixedValueParameter<BoolValue> presolveParam; 51 45 … … 64 58 [Storable] 65 59 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 66 123 67 124 public LinearProgrammingAlgorithm() { … … 70 127 71 128 ILinearSolver defaultSolver; 72 linearSolverParam.ValidValues.Add(new BopSolver());73 129 linearSolverParam.ValidValues.Add(defaultSolver = new CoinOrSolver()); 74 130 linearSolverParam.ValidValues.Add(new CplexSolver()); 75 131 linearSolverParam.ValidValues.Add(new GlopSolver()); 76 linearSolverParam.ValidValues.Add(new GlpkSolver());77 132 linearSolverParam.ValidValues.Add(new GurobiSolver()); 78 133 linearSolverParam.ValidValues.Add(new ScipSolver()); … … 80 135 81 136 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))); 83 138 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)))); 85 141 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 }); 89 144 Parameters.Add(dualToleranceParam = new FixedValueParameter<DoubleValue>(nameof(DualTolerance), 90 145 "Advanced usage: tolerance for dual feasibility of basic solutions.", 91 new DoubleValue( MPSolverParameters.kDefaultDualTolerance)));146 new DoubleValue(SolverParameters.DefaultDualTolerance)) { Hidden = true }); 92 147 Parameters.Add(primalToleranceParam = new FixedValueParameter<DoubleValue>(nameof(PrimalTolerance), 93 148 "Advanced usage: tolerance for primal feasibility of basic solutions. " + 94 149 "This does not control the integer feasibility tolerance of integer " + 95 150 "solutions for MIP or the tolerance used during presolve.", 96 new DoubleValue( MPSolverParameters.kDefaultPrimalTolerance)));151 new DoubleValue(SolverParameters.DefaultPrimalTolerance)) { Hidden = true }); 97 152 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(); 111 156 } 112 157 113 158 [StorableConstructor] 114 pr otectedLinearProgrammingAlgorithm(bool deserializing)159 private LinearProgrammingAlgorithm(bool deserializing) 115 160 : base(deserializing) { 116 161 } 117 162 118 pr otectedLinearProgrammingAlgorithm(LinearProgrammingAlgorithm original, Cloner cloner)163 private LinearProgrammingAlgorithm(LinearProgrammingAlgorithm original, Cloner cloner) 119 164 : base(original, cloner) { 120 165 linearSolverParam = cloner.Clone(original.linearSolverParam); … … 122 167 timeLimitParam = cloner.Clone(original.timeLimitParam); 123 168 presolveParam = cloner.Clone(original.presolveParam); 124 lpAlgorithmParam = cloner.Clone(original.lpAlgorithmParam);125 169 dualToleranceParam = cloner.Clone(original.dualToleranceParam); 126 170 primalToleranceParam = cloner.Clone(original.primalToleranceParam); 127 171 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;192 172 } 193 173 … … 216 196 LinearSolver.PrimalTolerance = PrimalTolerance; 217 197 LinearSolver.DualTolerance = DualTolerance; 218 LinearSolver.LpAlgorithm = LpAlgorithm;219 198 LinearSolver.Presolve = Presolve; 220 199 LinearSolver.RelativeGapTolerance = RelativeGapTolerance; 221 200 LinearSolver.Scaling = Scaling; 222 201 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); 227 203 } 228 204 }
Note: See TracChangeset
for help on using the changeset viewer.