Changeset 16405
- Timestamp:
- 12/19/18 14:15:49 (6 years ago)
- Location:
- branches/2931_OR-Tools_LP_MIP
- Files:
-
- 17 added
- 3 deleted
- 23 edited
- 8 copied
- 9 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab 3.3.sln
r16373 r16405 50 50 {F98A1740-9AC9-4D36-A582-6A2D0D06978D} = {F98A1740-9AC9-4D36-A582-6A2D0D06978D} 51 51 {B03C4E41-1D01-4C60-B0F4-DBB257D98CA8} = {B03C4E41-1D01-4C60-B0F4-DBB257D98CA8} 52 {D1D69043-17E6-4B8C-BF41-0799C7E56032} = {D1D69043-17E6-4B8C-BF41-0799C7E56032} 52 53 {73F29D43-5714-4069-8FAB-0D18FEB5F175} = {73F29D43-5714-4069-8FAB-0D18FEB5F175} 53 54 {3E9E8944-44FF-40BB-A622-3A4A7DD0F198} = {3E9E8944-44FF-40BB-A622-3A4A7DD0F198} … … 465 466 EndProject 466 467 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.MathematicalOptimization-3.3", "HeuristicLab.MathematicalOptimization\3.3\HeuristicLab.MathematicalOptimization-3.3.csproj", "{FA3B9270-48B7-4C77-9FEA-2A6EDE82E909}" 468 EndProject 469 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.MathematicalOptimization.Views-3.3", "HeuristicLab.MathematicalOptimization.Views\3.3\HeuristicLab.MathematicalOptimization.Views-3.3.csproj", "{D1D69043-17E6-4B8C-BF41-0799C7E56032}" 467 470 EndProject 468 471 Global … … 2264 2267 {FA3B9270-48B7-4C77-9FEA-2A6EDE82E909}.Release|x86.ActiveCfg = Release|x86 2265 2268 {FA3B9270-48B7-4C77-9FEA-2A6EDE82E909}.Release|x86.Build.0 = Release|x86 2269 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 2270 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Debug|Any CPU.Build.0 = Debug|Any CPU 2271 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Debug|x64.ActiveCfg = Debug|x64 2272 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Debug|x64.Build.0 = Debug|x64 2273 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Debug|x86.ActiveCfg = Debug|x86 2274 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Debug|x86.Build.0 = Debug|x86 2275 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Release|Any CPU.ActiveCfg = Release|Any CPU 2276 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Release|Any CPU.Build.0 = Release|Any CPU 2277 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Release|x64.ActiveCfg = Release|x64 2278 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Release|x64.Build.0 = Release|x64 2279 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Release|x86.ActiveCfg = Release|x86 2280 {D1D69043-17E6-4B8C-BF41-0799C7E56032}.Release|x86.Build.0 = Release|x86 2266 2281 EndGlobalSection 2267 2282 GlobalSection(SolutionProperties) = preSolution -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data.Views/3.3/Path Views/FileValueView.Designer.cs
r15583 r16405 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FileValueView)); 47 48 this.openButton = new System.Windows.Forms.Button(); 48 49 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 49 50 this.stringConvertibleValueView = new HeuristicLab.Data.Views.StringConvertibleValueView(); 51 this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); 50 52 this.SuspendLayout(); 51 53 // … … 90 92 protected System.Windows.Forms.OpenFileDialog openFileDialog; 91 93 protected StringConvertibleValueView stringConvertibleValueView; 94 private System.Windows.Forms.SaveFileDialog saveFileDialog; 92 95 } 93 96 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data.Views/3.3/Path Views/FileValueView.cs
r15583 r16405 55 55 56 56 protected virtual void openButton_Click(object sender, EventArgs e) { 57 openFileDialog.Filter = Content.FileDialogFilter; 58 if (openFileDialog.ShowDialog(this) != DialogResult.OK) return; 59 Content.Value = openFileDialog.FileName; 57 var fileDialog = Content.SaveFile ? (FileDialog)saveFileDialog : openFileDialog; 58 fileDialog.Filter = Content.FileDialogFilter; 59 if (fileDialog.ShowDialog(this) != DialogResult.OK) return; 60 Content.Value = fileDialog.FileName; 60 61 } 61 62 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data/3.3/Path Types/FileValue.cs
r15583 r16405 40 40 } 41 41 42 [Storable] 43 public bool SaveFile { get; set; } 44 42 45 [StorableConstructor] 43 46 protected FileValue(bool deserializing) : base(deserializing) { } … … 45 48 : base(original, cloner) { 46 49 fileDialogFilter = original.FileDialogFilter; 50 SaveFile = original.SaveFile; 47 51 } 48 52 public override IDeepCloneable Clone(Cloner cloner) { -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data/3.3/Path Types/PathValue.cs
r15583 r16405 20 20 #endregion 21 21 22 using System; 22 23 using System.IO; 23 24 using HeuristicLab.Common; … … 29 30 [StorableClass] 30 31 public abstract class PathValue : Item { 32 33 public EventHandler PathChanged; 31 34 32 35 [Storable] … … 42 45 value = value.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); 43 46 stringValue.Value = value; 47 OnPathChanged(); 44 48 } 45 49 } … … 57 61 } 58 62 63 protected virtual void OnPathChanged() { 64 EventHandler handler = PathChanged; 65 if (handler != null) handler(this, EventArgs.Empty); 66 } 67 59 68 [StorableHook(HookType.AfterDeserialization)] 60 69 private void AfterDeserialization() { -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/HeuristicLab.MathematicalOptimization-3.3.csproj
r16373 r16405 121 121 <Reference Include="System" /> 122 122 <Reference Include="System.Core" /> 123 <Reference Include="System.Data" />124 123 <Reference Include="System.Drawing" /> 125 <Reference Include="System.Windows.Forms" /> 126 <Reference Include="System.Xml" /> 124 <Reference Include="WindowsBase" /> 127 125 </ItemGroup> 128 126 <ItemGroup> 129 127 <Compile Include="LinearProgramming\Algorithms\Solvers\BopSolver.cs" /> 130 128 <Compile Include="LinearProgramming\Algorithms\Solvers\CoinOrSolver.cs" /> 131 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\External Solver.cs" />129 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ExternalLinearSolver.cs" /> 132 130 <Compile Include="LinearProgramming\Algorithms\Solvers\GlopSolver.cs" /> 133 131 <Compile Include="LinearProgramming\Algorithms\Solvers\GlpkSolver.cs" /> 134 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IExternal Solver.cs" />135 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IIncremental Solver.cs" />136 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ExternalIncremental Solver.cs" />137 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\Incremental Solver.cs" />132 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IExternalLinearSolver.cs" /> 133 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IIncrementalLinearSolver.cs" /> 134 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ExternalIncrementalLinearSolver.cs" /> 135 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IncrementalLinearSolver.cs" /> 138 136 <Compile Include="LinearProgramming\Algorithms\ProblemType.cs" /> 139 137 <Compile Include="LinearProgramming\Algorithms\Solvers\ScipSolver.cs" /> 140 <Compile Include="LinearProgramming\Wrapper\BasisStatus.cs" /> 138 <Compile Include="LinearProgramming\Problems\CompiledProblemDefinition.cs" /> 139 <Compile Include="LinearProgramming\Problems\FileBasedLinearProgrammingProblemDefinition.cs" /> 140 <Compile Include="LinearProgramming\Problems\LinearProgrammingProblem.cs" /> 141 <Compile Include="LinearProgramming\Algorithms\BasisStatus.cs" /> 141 142 <Compile Include="LinearProgramming\Algorithms\Solvers\CplexSolver.cs" /> 142 143 <Compile Include="LinearProgramming\Algorithms\Solvers\GurobiSolver.cs" /> 143 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\I Solver.cs" />144 <Compile Include="LinearProgramming\ Wrapper\IncrementalityValues.cs" />145 <Compile Include="LinearProgramming\ Wrapper\IntegerParam.cs" />146 <Compile Include="LinearProgramming\ Wrapper\LpAlgorithmValues.cs" />144 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ILinearSolver.cs" /> 145 <Compile Include="LinearProgramming\Algorithms\IncrementalityValues.cs" /> 146 <Compile Include="LinearProgramming\Algorithms\IntegerParam.cs" /> 147 <Compile Include="LinearProgramming\Algorithms\LpAlgorithmValues.cs" /> 147 148 <Compile Include="LinearProgramming\Problems\ILinearProgrammingProblemDefinition.cs" /> 148 149 <Compile Include="LinearProgramming\Algorithms\LinearProgrammingAlgorithm.cs" /> 149 <Compile Include="LinearProgramming\Problems\LinearProgrammingProblem.cs" /> 150 <Compile Include="LinearProgramming\Wrapper\LinearSolverExtensions.cs" /> 151 <Compile Include="LinearProgramming\Wrapper\LinearSolver.cs" /> 152 <Compile Include="LinearProgramming\Problems\LinearProgrammingProblemDefintion.cs" /> 153 <Compile Include="LinearProgramming\Wrapper\OptimizationProblemType.cs" /> 154 <Compile Include="LinearProgramming\Problems\ProblemDefinitionScriptException.cs" /> 155 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\Solver.cs" /> 156 <Compile Include="LinearProgramming\Wrapper\DoubleParam.cs" /> 157 <Compile Include="LinearProgramming\Views\LinearProgrammingProblemDefinitionScriptView.cs"> 158 <SubType>UserControl</SubType> 159 </Compile> 160 <Compile Include="LinearProgramming\Views\LinearProgrammingProblemDefinitionScriptView.Designer.cs"> 161 <DependentUpon>LinearProgrammingProblemDefinitionScriptView.cs</DependentUpon> 162 </Compile> 163 <Compile Include="LinearProgramming\Wrapper\ProtoWriteFormat.cs" /> 164 <Compile Include="LinearProgramming\Wrapper\ResultStatus.cs" /> 165 <Compile Include="LinearProgramming\Views\LinearProgrammingProblemView.cs"> 166 <SubType>UserControl</SubType> 167 </Compile> 168 <Compile Include="LinearProgramming\Views\LinearProgrammingProblemView.Designer.cs"> 169 <DependentUpon>LinearProgrammingProblemView.cs</DependentUpon> 170 </Compile> 171 <Compile Include="LinearProgramming\Problems\LinearProgrammingProblemDefinitionScript.cs" /> 172 <Compile Include="LinearProgramming\Templates\CompiledLinearProgrammingProblemDefinition.cs" /> 150 <Compile Include="LinearProgramming\Algorithms\LinearSolverExtensions.cs" /> 151 <Compile Include="LinearProgramming\Algorithms\OptimizationProblemType.cs" /> 152 <Compile Include="LinearProgramming\Algorithms\Solvers\Base\LinearSolver.cs" /> 153 <Compile Include="LinearProgramming\Algorithms\DoubleParam.cs" /> 154 <Compile Include="LinearProgramming\Algorithms\ProtoWriteFormat.cs" /> 155 <Compile Include="LinearProgramming\Algorithms\ResultStatus.cs" /> 156 <Compile Include="LinearProgramming\Problems\ProgrammableLinearProgrammingProblemDefinition.cs" /> 157 <Resource Include="LinearProgramming\Templates\CompiledLinearProgrammingProblemDefinition.cs" /> 173 158 <Compile Include="LinearProgramming\Templates\ScriptTemplates.Designer.cs"> 174 159 <AutoGen>True</AutoGen> … … 176 161 <DependentUpon>ScriptTemplates.resx</DependentUpon> 177 162 </Compile> 178 <Compile Include="LinearProgramming\ Wrapper\SolverResponseStatus.cs" />163 <Compile Include="LinearProgramming\Algorithms\SolverResponseStatus.cs" /> 179 164 <Compile Include="Properties\AssemblyInfo.cs" /> 180 165 <Compile Include="Properties\Settings.Designer.cs"> … … 201 186 <Generator>ResXFileCodeGenerator</Generator> 202 187 <LastGenOutput>ScriptTemplates.Designer.cs</LastGenOutput> 203 </EmbeddedResource> 204 <EmbeddedResource Include="LinearProgramming\Views\LinearProgrammingProblemView.resx"> 205 <DependentUpon>LinearProgrammingProblemView.cs</DependentUpon> 188 <SubType>Designer</SubType> 206 189 </EmbeddedResource> 207 190 </ItemGroup> … … 211 194 <Name>HeuristicLab.Analysis-3.3</Name> 212 195 </ProjectReference> 213 <ProjectReference Include="..\..\HeuristicLab.CodeEditor\3.4\HeuristicLab.CodeEditor-3.4.csproj">214 <Project>{C38691AE-ECB4-489A-A05D-B035554E0168}</Project>215 <Name>HeuristicLab.CodeEditor-3.4</Name>216 </ProjectReference>217 196 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 218 197 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> … … 227 206 <Name>HeuristicLab.Common-3.3</Name> 228 207 </ProjectReference> 229 <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">230 <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project>231 <Name>HeuristicLab.Core.Views-3.3</Name>232 </ProjectReference>233 208 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 234 209 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> … … 239 214 <Name>HeuristicLab.Data-3.3</Name> 240 215 </ProjectReference> 241 <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.3\HeuristicLab.MainForm.WindowsForms-3.3.csproj">242 <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project>243 <Name>HeuristicLab.MainForm.WindowsForms-3.3</Name>244 </ProjectReference>245 <ProjectReference Include="..\..\HeuristicLab.MainForm\3.3\HeuristicLab.MainForm-3.3.csproj">246 <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project>247 <Name>HeuristicLab.MainForm-3.3</Name>248 </ProjectReference>249 216 <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj"> 250 217 <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project> … … 266 233 <Project>{EE07BFF8-B23D-41F5-8AD7-AC9598D7A2C9}</Project> 267 234 <Name>HeuristicLab.Problems.Programmable-3.3</Name> 268 </ProjectReference>269 <ProjectReference Include="..\..\HeuristicLab.Scripting.Views\3.3\HeuristicLab.Scripting.Views-3.3.csproj">270 <Project>{0C2917C8-7AA8-4E18-800A-C4D064F992ED}</Project>271 <Name>HeuristicLab.Scripting.Views-3.3</Name>272 235 </ProjectReference> 273 236 <ProjectReference Include="..\..\HeuristicLab.Scripting\3.3\HeuristicLab.Scripting-3.3.csproj"> -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/IncrementalityValues.cs
r16404 r16405 27 27 IncrementalityOff = 0, 28 28 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. 31 30 IncrementalityOn = 1 32 31 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/IntegerParam.cs
r16404 r16405 20 20 #endregion 21 21 22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming {22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms { 23 23 24 24 // 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 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers;29 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;30 using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;31 28 using HeuristicLab.Optimization; 32 29 using HeuristicLab.Parameters; 33 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 31 35 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms{32 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 36 33 37 34 [Item("Linear/Mixed Integer Programming (LP/MIP)", "Linear/mixed integer programming implemented in several solvers. " + … … 45 42 46 43 [Storable] 44 private readonly IFixedValueParameter<FileValue> exportModelParam; 45 46 [Storable] 47 47 private readonly IFixedValueParameter<EnumValue<LpAlgorithmValues>> lpAlgorithmParam; 48 48 … … 60 60 61 61 [Storable] 62 private IConstrainedValueParameter<ISolver> solverParam;63 64 [Storable]65 62 private readonly IFixedValueParameter<TimeSpanValue> timeLimitParam; 66 63 67 public IConstrainedValueParameter<ISolver> SolverParameter { 68 get => solverParam; 69 set => solverParam = value; 70 } 64 [Storable] 65 private IConstrainedValueParameter<ILinearSolver> linearSolverParam; 71 66 72 67 public LinearProgrammingAlgorithm() { 73 Parameters.Add( solverParam =74 new ConstrainedValueParameter<I Solver>(nameof(Solver), "The solver used to solve the model."));75 76 I Solver 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; 85 80 86 81 Parameters.Add(relativeGapToleranceParam = new FixedValueParameter<PercentValue>(nameof(RelativeGapTolerance), … … 102 97 Parameters.Add(scalingParam = new FixedValueParameter<BoolValue>(nameof(Scaling), 103 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 })); 104 109 105 110 Problem = new LinearProgrammingProblem(); … … 113 118 protected LinearProgrammingAlgorithm(LinearProgrammingAlgorithm original, Cloner cloner) 114 119 : base(original, cloner) { 115 solverParam = cloner.Clone(original.solverParam);120 linearSolverParam = cloner.Clone(original.linearSolverParam); 116 121 relativeGapToleranceParam = cloner.Clone(original.relativeGapToleranceParam); 117 122 timeLimitParam = cloner.Clone(original.timeLimitParam); … … 121 126 primalToleranceParam = cloner.Clone(original.primalToleranceParam); 122 127 scalingParam = cloner.Clone(original.scalingParam); 128 exportModelParam = cloner.Clone(original.exportModelParam); 123 129 } 124 130 … … 128 134 } 129 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 130 151 public LpAlgorithmValues LpAlgorithm { 131 152 get => lpAlgorithmParam.Value.Value; … … 162 183 } 163 184 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; 172 188 173 189 public TimeSpan TimeLimit { … … 180 196 public override void Pause() { 181 197 base.Pause(); 182 Solver.InterruptSolve();198 LinearSolver.InterruptSolve(); 183 199 } 184 200 … … 187 203 Results.Clear(); 188 204 189 foreach (var solver in solverParam.ValidValues) {205 foreach (var solver in linearSolverParam.ValidValues) { 190 206 solver.Reset(); 191 207 } … … 194 210 public override void Stop() { 195 211 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 } 200 228 } 201 229 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/ProblemType.cs
r16373 r16405 20 20 #endregion 21 21 22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms{22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 23 23 24 24 public enum ProblemType { -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/ExternalIncrementalLinearSolver.cs
r16404 r16405 20 20 #endregion 21 21 22 using Google.OrTools.LinearSolver; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers.Base{28 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 28 29 29 30 [StorableClass] 30 public class ExternalIncremental Solver : IncrementalSolver, IExternalSolver {31 public class ExternalIncrementalLinearSolver : IncrementalLinearSolver, IExternalLinearSolver { 31 32 protected const string FileDialogFilter = "Dynamic-Link Library (*.dll)|*.dll|All Files (*.*)|*.*"; 32 33 … … 34 35 protected IFixedValueParameter<FileValue> libraryNameParam; 35 36 36 public ExternalIncremental Solver() {37 public ExternalIncrementalLinearSolver() { 37 38 } 38 39 39 40 [StorableConstructor] 40 protected ExternalIncremental Solver(bool deserializing)41 protected ExternalIncrementalLinearSolver(bool deserializing) 41 42 : base(deserializing) { 42 43 } 43 44 44 protected ExternalIncremental Solver(ExternalIncrementalSolver original, Cloner cloner)45 protected ExternalIncrementalLinearSolver(ExternalIncrementalLinearSolver original, Cloner cloner) 45 46 : base(original, cloner) { 46 47 libraryNameParam = cloner.Clone(original.libraryNameParam); … … 51 52 set => libraryNameParam.Value.Value = value; 52 53 } 54 55 protected override Solver CreateSolver(OptimizationProblemType optimizationProblemType, 56 string libraryName = null) => base.CreateSolver(optimizationProblemType, LibraryName); 53 57 } 54 58 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/ExternalLinearSolver.cs
r16404 r16405 20 20 #endregion 21 21 22 using Google.OrTools.LinearSolver; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers.Base{28 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 28 29 29 30 [StorableClass] 30 public class External Solver : Solver, IExternalSolver {31 public class ExternalLinearSolver : LinearSolver, IExternalLinearSolver { 31 32 protected const string FileDialogFilter = "Dynamic-Link Library (*.dll)|*.dll|All Files (*.*)|*.*"; 32 33 … … 34 35 protected IFixedValueParameter<FileValue> libraryNameParam; 35 36 36 public External Solver() {37 public ExternalLinearSolver() { 37 38 } 38 39 39 40 [StorableConstructor] 40 protected External Solver(bool deserializing)41 protected ExternalLinearSolver(bool deserializing) 41 42 : base(deserializing) { 42 43 } 43 44 44 protected External Solver(ExternalSolver original, Cloner cloner)45 protected ExternalLinearSolver(ExternalLinearSolver original, Cloner cloner) 45 46 : base(original, cloner) { 46 47 libraryNameParam = cloner.Clone(original.libraryNameParam); … … 51 52 set => libraryNameParam.Value.Value = value; 52 53 } 54 55 protected override Solver CreateSolver(OptimizationProblemType optimizationProblemType, 56 string libraryName = null) => base.CreateSolver(optimizationProblemType, LibraryName); 53 57 } 54 58 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/IExternalLinearSolver.cs
r16404 r16405 20 20 #endregion 21 21 22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers.Base{22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 23 23 24 public interface IExternal Solver : ISolver {24 public interface IExternalLinearSolver : ILinearSolver { 25 25 string LibraryName { get; set; } 26 26 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/IIncrementalLinearSolver.cs
r16404 r16405 22 22 using System; 23 23 24 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers.Base{24 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 25 25 26 public interface IIncremental Solver : ISolver {26 public interface IIncrementalLinearSolver : ILinearSolver { 27 27 TimeSpan QualityUpdateInterval { get; set; } 28 28 bool SupportsQualityUpdate { get; } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/ILinearSolver.cs
r16404 r16405 20 20 #endregion 21 21 22 using System; 22 23 using System.Threading; 23 24 using HeuristicLab.Core; 25 using HeuristicLab.Optimization; 24 26 25 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers.Base{27 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 26 28 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 29 48 bool SupportsPause { get; } 49 30 50 bool SupportsStop { get; } 51 52 TimeSpan TimeLimit { get; set; } 31 53 32 54 bool InterruptSolve(); … … 34 56 void Reset(); 35 57 36 void Solve( LinearProgrammingAlgorithm algorithm);58 void Solve(ILinearProgrammingProblemDefinition problemDefintion, ref TimeSpan executionTime, ResultCollection results); 37 59 38 void Solve(LinearProgrammingAlgorithm algorithm, CancellationToken cancellationToken); 60 void Solve(ILinearProgrammingProblemDefinition problemDefintion, ref TimeSpan executionTime, 61 ResultCollection results, CancellationToken cancellationToken); 39 62 } 40 63 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/IncrementalLinearSolver.cs
r16404 r16405 27 27 using HeuristicLab.Core; 28 28 using HeuristicLab.Data; 29 using HeuristicLab.Optimization; 29 30 using HeuristicLab.Parameters; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 32 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers.Base{33 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 33 34 34 35 [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; 39 38 40 39 private IndexedDataRow<double> bpcRow; … … 42 41 private IndexedDataRow<double> qpcRow; 43 42 44 [Storable] 45 private IndexedDataTable<double> qualityPerClock; 43 [Storable] private IndexedDataTable<double> qualityPerClock; 46 44 47 [StorableConstructor] 48 protected IncrementalSolver(bool deserializing) 49 : base(deserializing) { 50 } 51 52 public IncrementalSolver() { 45 public IncrementalLinearSolver() { 53 46 Parameters.Add(qualityUpdateIntervalParam = 54 47 new ValueParameter<TimeSpanValue>(nameof(QualityUpdateInterval), … … 66 59 } 67 60 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) { 70 68 problemTypeParam = cloner.Clone(original.problemTypeParam); 71 69 qualityUpdateIntervalParam = cloner.Clone(original.qualityUpdateIntervalParam); … … 74 72 } 75 73 76 public virtual bool SupportsQualityUpdate => true;77 78 74 public TimeSpan QualityUpdateInterval { 79 75 get => qualityUpdateIntervalParam.Value.Value; … … 81 77 } 82 78 83 protected virtual TimeSpan TimeLimit => QualityUpdateInterval; 79 public virtual bool SupportsQualityUpdate => true; 80 protected virtual TimeSpan IntermediateTimeLimit => QualityUpdateInterval; 84 81 85 public override void Solve(LinearProgrammingAlgorithm algorithm, CancellationToken cancellationToken) { 82 public override void Solve(ILinearProgrammingProblemDefinition problemDefinition, ref TimeSpan executionTime, 83 ResultCollection results, CancellationToken cancellationToken) { 86 84 if (!SupportsQualityUpdate || QualityUpdateInterval == TimeSpan.Zero) { 87 base.Solve( algorithm, cancellationToken);85 base.Solve(problemDefinition, ref executionTime, results, cancellationToken); 88 86 return; 89 87 } 90 88 91 var timeLimit = algorithm.TimeLimit;89 var timeLimit = TimeLimit; 92 90 var unlimitedRuntime = timeLimit == TimeSpan.Zero; 93 91 94 92 if (!unlimitedRuntime) { 95 timeLimit -= algorithm.ExecutionTime;93 timeLimit -= executionTime; 96 94 } 97 95 … … 104 102 return; 105 103 106 base.Solve(algorithm,TimeLimit);107 UpdateQuality( algorithm);104 Solve(problemDefinition, results, IntermediateTimeLimit); 105 UpdateQuality(results, executionTime); 108 106 109 var resultStatus = ((EnumValue<ResultStatus>) algorithm.Results[nameof(solver.ResultStatus)].Value).Value;107 var resultStatus = ((EnumValue<ResultStatus>)results["ResultStatus"].Value).Value; 110 108 if (!validResultStatuses.Contains(resultStatus)) 111 109 return; … … 116 114 117 115 if (remaining > TimeSpan.Zero) { 118 base.Solve(algorithm, remaining);119 UpdateQuality( algorithm);116 Solve(problemDefinition, results, remaining); 117 UpdateQuality(results, executionTime); 120 118 } 121 119 } 122 120 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")) { 125 123 qualityPerClock = new IndexedDataTable<double>("Quality per Clock"); 126 124 qpcRow = new IndexedDataRow<double>("Objective Value"); 127 125 bpcRow = new IndexedDataRow<double>("Bound"); 128 algorithm.Results.AddOrUpdateResult("QualityPerClock", qualityPerClock);126 results.AddOrUpdateResult("QualityPerClock", qualityPerClock); 129 127 } 130 128 131 var resultStatus = ((EnumValue<ResultStatus>) algorithm.Results[nameof(solver.ResultStatus)].Value).Value;129 var resultStatus = ((EnumValue<ResultStatus>)results["ResultStatus"].Value).Value; 132 130 133 131 if (new[] { ResultStatus.Abnormal, ResultStatus.NotSolved, ResultStatus.Unbounded }.Contains(resultStatus)) 134 132 return; 135 133 136 var objective = ((DoubleValue) algorithm.Results[$"Best{nameof(solver.ObjectiveValue)}"].Value).Value;137 var bound = solver.IsM ip ? ((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; 139 137 140 138 if (!qpcRow.Values.Any()) { … … 143 141 qpcRow.Values.Add(Tuple.Create(time, objective)); 144 142 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))); 146 144 } 147 145 } else { … … 150 148 if (!objective.IsAlmost(previousBest)) { 151 149 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))); 153 151 } 154 152 } 155 153 156 if (!solver.IsM ip)154 if (!solver.IsMIP()) 157 155 return; 158 156 -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/Base/LinearSolver.cs
r16404 r16405 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.IO; 25 using System.Linq; 26 using System.Reflection; 23 27 using System.Threading; 28 using Google.OrTools.LinearSolver; 24 29 using HeuristicLab.Common; 25 30 using HeuristicLab.Core; 26 31 using HeuristicLab.Data; 32 using HeuristicLab.Optimization; 27 33 using HeuristicLab.Parameters; 28 34 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 35 30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers.Base{36 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 31 37 32 38 [StorableClass] 33 public class Solver : ParameterizedNamedItem, ISolver, IDisposable {39 public class LinearSolver : ParameterizedNamedItem, ILinearSolver, IDisposable { 34 40 35 41 [Storable] 36 42 protected IValueParameter<EnumValue<ProblemType>> problemTypeParam; 37 43 38 protected LinearSolver solver;44 protected Solver solver; 39 45 40 46 [Storable] 41 47 protected IFixedValueParameter<TextValue> solverSpecificParametersParam; 42 48 43 public Solver() {49 public LinearSolver() { 44 50 Parameters.Add(problemTypeParam = 45 51 new ValueParameter<EnumValue<ProblemType>>(nameof(ProblemType), new EnumValue<ProblemType>())); … … 49 55 50 56 [StorableConstructor] 51 protected Solver(bool deserializing)57 protected LinearSolver(bool deserializing) 52 58 : base(deserializing) { 53 59 } 54 60 55 protected Solver(Solver original, Cloner cloner)61 protected LinearSolver(LinearSolver original, Cloner cloner) 56 62 : base(original, cloner) { 57 63 problemTypeParam = cloner.Clone(original.problemTypeParam); … … 59 65 } 60 66 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 61 80 public ProblemType ProblemType { 62 81 get => problemTypeParam.Value.Value; … … 64 83 } 65 84 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 } 67 93 68 94 public virtual bool SupportsPause => true; 69 95 public virtual bool SupportsStop => true; 96 public virtual TimeSpan TimeLimit { get; set; } = TimeSpan.Zero; 70 97 protected virtual OptimizationProblemType OptimizationProblemType { get; } 71 98 72 public override IDeepCloneable Clone(Cloner cloner) => new Solver(this, cloner);99 public override IDeepCloneable Clone(Cloner cloner) => new LinearSolver(this, cloner); 73 100 74 101 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); 75 129 76 130 public bool InterruptSolve() => solver?.InterruptSolve() ?? false; … … 81 135 } 82 136 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) { 94 147 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; 137 268 } 138 269 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/BopSolver.cs
r16373 r16405 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;27 26 using HeuristicLab.Parameters; 28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers{29 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 31 30 32 31 [Item("BOP", "BOP (https://developers.google.com/optimization/reference/bop/bop_solver/) can be used out of the box.")] 33 32 [StorableClass] 34 public class BopSolver : Incremental Solver {33 public class BopSolver : IncrementalLinearSolver { 35 34 36 35 public BopSolver() { 37 36 Parameters.Remove(problemTypeParam); 38 37 Parameters.Add(new FixedValueParameter<StringValue>(nameof(ProblemType), new StringValue("ZeroOneProgramming").AsReadOnly())); 39 SolverSpecificParameters .Value=38 SolverSpecificParameters = 40 39 "# for file format, see Protocol Buffers text format (https://developers.google.com/protocol-buffers/docs/overview#whynotxml)" + Environment.NewLine + 41 40 "# 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 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 using HeuristicLab. MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 27 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers{28 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 28 29 29 30 [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.")] 30 31 [StorableClass] 31 public class CoinOrSolver : Incremental Solver {32 public class CoinOrSolver : IncrementalLinearSolver { 32 33 33 34 public CoinOrSolver() { … … 54 55 ? OptimizationProblemType.ClpLinearProgramming 55 56 : 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 } 56 62 } 57 63 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/CplexSolver.cs
r16373 r16405 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;27 26 using HeuristicLab.Parameters; 28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers{29 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 31 30 32 31 [Item("CPLEX", "CPLEX (https://www.ibm.com/analytics/cplex-optimizer) must be installed and licenced.")] 33 32 [StorableClass] 34 public class CplexSolver : ExternalIncremental Solver {33 public class CplexSolver : ExternalIncrementalLinearSolver { 35 34 36 35 public CplexSolver() { 37 36 Parameters.Add(libraryNameParam = new FixedValueParameter<FileValue>(nameof(LibraryName), 38 37 new FileValue { FileDialogFilter = FileDialogFilter, Value = Properties.Settings.Default.CplexLibraryName })); 39 SolverSpecificParameters .Value=38 SolverSpecificParameters = 40 39 "CPLEX Parameter File Version 12.8.0" + Environment.NewLine + 41 40 "# 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 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 29 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers{28 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 30 29 31 30 [Item("Glop", "Glop (https://developers.google.com/optimization/lp/glop) can be used out of the box.")] 32 31 [StorableClass] 33 public class GlopSolver : Incremental Solver {32 public class GlopSolver : IncrementalLinearSolver { 34 33 35 34 public GlopSolver() { 36 35 problemTypeParam.Value = (EnumValue<ProblemType>)problemTypeParam.Value.AsReadOnly(); 37 SolverSpecificParameters .Value=36 SolverSpecificParameters = 38 37 "# for file format, see Protocol Buffers text format (https://developers.google.com/protocol-buffers/docs/overview#whynotxml)" + Environment.NewLine + 39 38 "# 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 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;26 25 using HeuristicLab.Parameters; 27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 29 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers{28 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 30 29 31 30 [Item("GLPK", "GLPK (https://www.gnu.org/software/glpk/) can be used out of the box.")] 32 31 [StorableClass] 33 public class GlpkSolver : External IncrementalSolver {32 public class GlpkSolver : ExternalLinearSolver { 34 33 35 34 public GlpkSolver() { … … 48 47 } 49 48 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; 53 50 54 51 protected override OptimizationProblemType OptimizationProblemType => -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/Solvers/GurobiSolver.cs
r16373 r16405 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;27 26 using HeuristicLab.Parameters; 28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers{29 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 31 30 32 31 [Item("Gurobi", "Gurobi (http://www.gurobi.com/) must be installed and licenced.")] 33 32 [StorableClass] 34 public class GurobiSolver : ExternalIncremental Solver {33 public class GurobiSolver : ExternalIncrementalLinearSolver { 35 34 36 35 public GurobiSolver() { 37 36 Parameters.Add(libraryNameParam = new FixedValueParameter<FileValue>(nameof(LibraryName), 38 37 new FileValue { FileDialogFilter = FileDialogFilter, Value = Properties.Settings.Default.GurobiLibraryName })); 39 SolverSpecificParameters .Value=38 SolverSpecificParameters = 40 39 "# for file format, see http://www.gurobi.com/documentation/8.1/refman/prm_format.html" + Environment.NewLine + 41 40 "# 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 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab. MathematicalOptimization.LinearProgramming.Algorithms.Solvers.Base;27 using HeuristicLab.Optimization; 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Algorithms.Solvers{31 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 32 32 33 33 [Item("SCIP", "SCIP (http://scip.zib.de/) must be installed and licenced.")] 34 34 [StorableClass] 35 public class ScipSolver : ExternalIncrementalSolver { 36 35 public class ScipSolver : ExternalIncrementalLinearSolver { 37 36 private TimeSpan timeLimit = TimeSpan.Zero; 38 37 … … 42 41 problemTypeParam.Value = 43 42 (EnumValue<ProblemType>)new EnumValue<ProblemType>(ProblemType.MixedIntegerProgramming).AsReadOnly(); 44 SolverSpecificParameters .Value=43 SolverSpecificParameters = 45 44 "# for file format and parameters, see https://scip.zib.de/doc/html/PARAMETERS.php" + Environment.NewLine + 46 45 "# example:" + Environment.NewLine + … … 57 56 } 58 57 58 protected override TimeSpan IntermediateTimeLimit => timeLimit += QualityUpdateInterval; 59 59 60 protected override OptimizationProblemType OptimizationProblemType => 60 OptimizationProblemType.ScipMixedIntegerProgramming; 61 protected override TimeSpan TimeLimit => timeLimit += QualityUpdateInterval; 61 OptimizationProblemType.ScipMixedIntegerProgramming; 62 62 63 public override void Solve( LinearProgrammingAlgorithm algorithm, CancellationToken cancellationToken) {63 public override void Solve(ILinearProgrammingProblemDefinition problemDefintion, ref TimeSpan executionTime, ResultCollection results, CancellationToken cancellationToken) { 64 64 timeLimit = TimeSpan.Zero; 65 base.Solve( algorithm, cancellationToken);65 base.Solve(problemDefintion, ref executionTime, results, cancellationToken); 66 66 } 67 67 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/CompiledProblemDefinition.cs
r16383 r16405 20 20 #endregion 21 21 22 using System; 23 using HeuristicLab.Optimization; 22 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 24 23 25 namespace HeuristicLab.Problems.Programmable { 26 public abstract class CompiledProblemDefinition : IProblemDefinition { 27 private IEncoding encoding; 28 public IEncoding Encoding { 29 get { return encoding; } 30 protected set { 31 if (value == null) throw new ArgumentNullException("The encoding must not be null."); 32 encoding = value; 33 } 34 } 24 public abstract class CompiledProblemDefinition { 25 public dynamic vars { get; set; } 35 26 36 public dynamic vars { get; set; }37 27 public abstract void Initialize(); 38 39 protected CompiledProblemDefinition() { }40 protected CompiledProblemDefinition(IEncoding encoding)41 : base() {42 Encoding = encoding;43 }44 28 } 45 29 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/FileBasedLinearProgrammingProblemDefinition.cs
r16368 r16405 20 20 #endregion 21 21 22 using System.Drawing; 23 using System.IO; 22 24 using Google.OrTools.LinearSolver; 23 using HeuristicLab.Problems.Programmable; 25 using HeuristicLab.Common; 26 using HeuristicLab.Common.Resources; 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 29 using HeuristicLab.Optimization; 30 using HeuristicLab.Parameters; 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 32 25 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Problems{33 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 26 34 27 public class LinearProgrammingProblemDefintion : CompiledProblemDefinition { 35 [Item("File-Based Linear/Mixed Integer Programming Problem Definition", "File that defines the model for linear/mixed integer programming problem.")] 36 [StorableClass] 37 public sealed class FileBasedLinearProgrammingProblemDefinition : ParameterizedNamedItem, ILinearProgrammingProblemDefinition { 38 39 [Storable] 40 private readonly IFixedValueParameter<FileValue> fileNameParam; 41 42 [Storable] 43 private byte[] fileContent; 44 45 public FileBasedLinearProgrammingProblemDefinition() { 46 Parameters.Add(fileNameParam = new FixedValueParameter<FileValue>(nameof(FileName), new FileValue())); 47 fileNameParam.Value.FileDialogFilter = 48 "All Supported Files (*.mps;*.bin;*.prototxt)|*.mps;*.bin;*.prototxt|" + 49 "Mathematical Programming System Files (*.mps)|*.mps|" + 50 "Google OR-Tools Protocol Buffers Files (*.bin;*.prototxt)|*.bin;*.prototxt|" + 51 "All Files (*.*)|*.*"; 52 fileNameParam.Value.PathChanged += (o, e) => { 53 if (File.Exists(FileName)) { 54 fileContent = File.ReadAllBytes(FileName); 55 } 56 }; 57 } 58 59 private FileBasedLinearProgrammingProblemDefinition(FileBasedLinearProgrammingProblemDefinition original, Cloner cloner) 60 : base(original, cloner) { 61 fileNameParam = cloner.Clone(original.fileNameParam); 62 } 63 64 [StorableConstructor] 65 private FileBasedLinearProgrammingProblemDefinition(bool deserializing) : base(deserializing) { } 66 67 public new static Image StaticItemImage => VSImageLibrary.File; 68 69 public string FileName { 70 get => fileNameParam.Value.Value; 71 set => fileNameParam.Value.Value = value; 72 } 73 74 public IFixedValueParameter<FileValue> FileNameParam => fileNameParam; 75 76 public void Analyze(Solver solver, ResultCollection results) { 77 } 28 78 29 79 public void BuildModel(Solver solver) { 80 var fileInfo = new FileInfo(FileName); 81 var tempFileName = Path.GetTempFileName(); 82 File.WriteAllBytes(tempFileName, fileContent); 83 84 var status = (SolverResponseStatus)(fileInfo.Extension == ".mps" 85 ? solver.ImportModelFromMpsFormat(tempFileName) 86 : solver.ImportModelFromProtoFormat(tempFileName)); 87 88 if (status == SolverResponseStatus.Abnormal) 89 throw new FileFormatException($"'{FileName}' is not a valid MPS or Google OR-Tools Protocol Buffers file."); 90 91 File.Delete(tempFileName); 30 92 } 31 93 32 public override void Initialize() { 33 } 94 public override IDeepCloneable Clone(Cloner cloner) => new FileBasedLinearProgrammingProblemDefinition(this, cloner); 34 95 } 35 96 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/ILinearProgrammingProblemDefinition.cs
r16373 r16405 21 21 22 22 using Google.OrTools.LinearSolver; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Optimization; 24 25 25 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Problems{26 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 26 27 27 public interface ILinearProgrammingProblemDefinition { 28 29 bool BuildModel(Solver solver); 28 public interface ILinearProgrammingProblemDefinition : IContent { 30 29 31 30 void Analyze(Solver solver, ResultCollection results); 31 32 void BuildModel(Solver solver); 32 33 } 33 34 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/LinearProgrammingProblem.cs
r16373 r16405 20 20 #endregion 21 21 22 using System .Drawing;22 using System; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Common.Resources;25 24 using HeuristicLab.Core; 26 25 using HeuristicLab.Optimization; 27 using HeuristicLab.Parameters;28 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 27 30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Problems{28 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 31 29 32 30 [Item("Linear/Mixed Integer Programming Problem (LP/MIP)", "Represents a linear/mixed integer problem.")] 33 [Creatable(CreatableAttribute.Categories.CombinatorialProblems)]34 31 [StorableClass] 35 public class LinearProgrammingProblem : Problem, IProgrammableItem { 32 public sealed class LinearProgrammingProblem : Problem { 33 [Storable] 34 private ILinearProgrammingProblemDefinition problemDefinition; 36 35 37 36 public LinearProgrammingProblem() { 38 Parameters.Add(new FixedValueParameter<LinearProgrammingProblemDefinitionScript>("ProblemScript", 39 "Defines the problem.", new LinearProgrammingProblemDefinitionScript { Name = Name }) { GetsCollected = false }); 40 RegisterEvents(); 37 Parameters.Remove(Parameters["Operators"]); 41 38 } 42 39 43 pr otectedLinearProgrammingProblem(LinearProgrammingProblem original, Cloner cloner)40 private LinearProgrammingProblem(LinearProgrammingProblem original, Cloner cloner) 44 41 : base(original, cloner) { 45 RegisterEvents();46 42 } 47 43 48 44 [StorableConstructor] 49 protected LinearProgrammingProblem(bool deserializing) : base(deserializing) { } 50 51 public new static Image StaticItemImage => VSImageLibrary.Script; 52 public ILinearProgrammingProblemDefinition ProblemDefinition => LinearProgrammingProblemScriptParameter.Value; 53 public LinearProgrammingProblemDefinitionScript ProblemScript => LinearProgrammingProblemScriptParameter.Value; 54 55 private FixedValueParameter<LinearProgrammingProblemDefinitionScript> LinearProgrammingProblemScriptParameter => 56 (FixedValueParameter<LinearProgrammingProblemDefinitionScript>)Parameters["ProblemScript"]; 57 58 public override IDeepCloneable Clone(Cloner cloner) { 59 return new LinearProgrammingProblem(this, cloner); 45 private LinearProgrammingProblem(bool deserializing) : base(deserializing) { 60 46 } 61 47 62 protected override void OnNameChanged() { 63 base.OnNameChanged(); 64 ProblemScript.Name = Name; 48 public event EventHandler ProblemDefinitionChanged; 49 50 public ILinearProgrammingProblemDefinition ProblemDefinition { 51 get => problemDefinition; 52 set { 53 if (problemDefinition == value) 54 return; 55 problemDefinition = value; 56 ProblemDefinitionChanged?.Invoke(this, EventArgs.Empty); 57 } 65 58 } 59 60 public override IDeepCloneable Clone(Cloner cloner) => new LinearProgrammingProblem(this, cloner); 66 61 67 62 [StorableHook(HookType.AfterDeserialization)] 68 63 private void AfterDeserialization() { 69 RegisterEvents();70 64 } 71 65 … … 74 68 OnReset(); 75 69 } 76 77 private void OnProblemScriptNameChanged() {78 Name = ProblemScript.Name;79 }80 81 private void RegisterEvents() {82 ProblemScript.ProblemDefinitionChanged += (o, e) => OnProblemDefinitionChanged();83 ProblemScript.NameChanged += (o, e) => OnProblemScriptNameChanged();84 }85 70 } 86 71 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/ProgrammableLinearProgrammingProblemDefinition.cs
r16404 r16405 31 31 using HeuristicLab.Scripting; 32 32 33 namespace HeuristicLab.MathematicalOptimization.LinearProgramming .Problems{33 namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 34 34 35 [Item("Linear/Mixed Integer Programming Problem Definition Script", "Script that defines the model and evaluates the solution for a linear/mixed integer programming problem.")] 35 [Item("Programmable Linear/Mixed Integer Programming Problem Definition", 36 "Script that defines the model and evaluates the solution for a linear/mixed integer programming problem.")] 36 37 [StorableClass] 37 public sealed class LinearProgrammingProblemDefinitionScript : Script, ILinearProgrammingProblemDefinition, IStorableContent { 38 private bool SuppressEvents { get; set; } 38 public sealed class ProgrammableLinearProgrammingProblemDefinition : Script, ILinearProgrammingProblemDefinition, 39 IStorableContent { 40 private readonly object compileLock = new object(); 39 41 40 [Storable] 41 private readonly VariableStore variableStore; 42 [Storable] private readonly VariableStore variableStore; 42 43 43 public VariableStore VariableStore => variableStore;44 [Storable] private bool codeChanged; 44 45 45 [Storable] 46 private bool codeChanged; 46 private volatile ILinearProgrammingProblemDefinition compiledProblemDefinition; 47 48 public ProgrammableLinearProgrammingProblemDefinition() 49 : base(ScriptTemplates.CompiledLinearProgrammingProblemDefinition) { 50 Name = "Programmable Linear/Mixed Integer Programming Problem Definition"; 51 variableStore = new VariableStore(); 52 } 47 53 48 54 [StorableConstructor] 49 private LinearProgrammingProblemDefinitionScript(bool deserializing) : base(deserializing) { } 55 private ProgrammableLinearProgrammingProblemDefinition(bool deserializing) : base(deserializing) { 56 } 50 57 51 private LinearProgrammingProblemDefinitionScript(LinearProgrammingProblemDefinitionScript original, Cloner cloner)52 : base(original, cloner) {58 private ProgrammableLinearProgrammingProblemDefinition(ProgrammableLinearProgrammingProblemDefinition original, 59 Cloner cloner) : base(original, cloner) { 53 60 variableStore = cloner.Clone(original.variableStore); 54 61 codeChanged = original.codeChanged; 55 62 } 56 63 57 public LinearProgrammingProblemDefinitionScript() 58 : base(ScriptTemplates.CompiledLinearProgrammingProblemDefinition) { 59 variableStore = new VariableStore(); 60 } 64 public event EventHandler ProblemDefinitionChanged; 61 65 62 private readonly object compileLock = new object(); 63 private volatile ILinearProgrammingProblemDefinition compiledProblemDefinition; 66 public string Filename { get; set; } 67 public dynamic Instance => compiledProblemDefinition; 68 public VariableStore VariableStore => variableStore; 64 69 65 70 private ILinearProgrammingProblemDefinition CompiledProblemDefinition { … … 75 80 } 76 81 } 82 77 83 return compiledProblemDefinition; 78 84 } 79 85 } 80 86 81 public dynamic Instance => compiledProblemDefinition; 87 private bool SuppressEvents { get; set; } 88 89 public void Analyze(Solver solver, ResultCollection results) => CompiledProblemDefinition.Analyze(solver, results); 90 91 public void BuildModel(Solver solver) => CompiledProblemDefinition.BuildModel(solver); 92 93 public override IDeepCloneable Clone(Cloner cloner) { 94 return new ProgrammableLinearProgrammingProblemDefinition(this, cloner); 95 } 82 96 83 97 public override Assembly Compile() => Compile(true); 98 99 protected override void OnCodeChanged() { 100 base.OnCodeChanged(); 101 compiledProblemDefinition = null; 102 codeChanged = true; 103 } 84 104 85 105 private Assembly Compile(bool fireChanged) { … … 87 107 var types = assembly.GetTypes(); 88 108 if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x))) 89 throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + 90 Environment.NewLine + 109 throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + 91 110 "The problem definition must be a subclass of CompiledProblemDefinition."); 92 111 if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1) 93 throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + 94 Environment.NewLine + 112 throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + 95 113 "Only one subclass of CompiledProblemDefinition is allowed."); 96 114 … … 128 146 } 129 147 130 protected override void OnCodeChanged() {131 base.OnCodeChanged();132 compiledProblemDefinition = null;133 codeChanged = true;134 }135 136 public event EventHandler ProblemDefinitionChanged;137 138 148 private void OnProblemDefinitionChanged() => ProblemDefinitionChanged?.Invoke(this, EventArgs.Empty); 139 140 public string Filename { get; set; }141 142 public override IDeepCloneable Clone(Cloner cloner) {143 return new LinearProgrammingProblemDefinitionScript(this, cloner);144 }145 146 public bool BuildModel(Solver solver) => CompiledProblemDefinition.BuildModel(solver);147 148 public void Analyze(Solver solver, ResultCollection results) => CompiledProblemDefinition.Analyze(solver, results);149 149 } 150 150 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/CompiledLinearProgrammingProblemDefinition.cs
r16373 r16405 6 6 using HeuristicLab.Core; 7 7 using HeuristicLab.Data; 8 using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;9 8 using HeuristicLab.Optimization; 10 using HeuristicLab.Problems.Programmable;11 9 using Variable = Google.OrTools.LinearSolver.Variable; 12 10 … … 22 20 } 23 21 24 public boolBuildModel(Solver solver) {22 public void BuildModel(Solver solver) { 25 23 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 24 // How to define a model using Google OR-Tools: https://developers.google.com/optimization/introduction/cs 26 25 // Example model taken from https://developers.google.com/optimization/mip/integer_opt 27 26 // Define the decision variables … … 32 31 // Define the objective 33 32 solver.Maximize(x + 10 * y); 34 return true;35 33 } 36 34 37 35 public void Analyze(Solver solver, ResultCollection results) { 38 36 // Use vars.yourVariable to access variables in the variable store i.e. yourVariable 39 // Write or update results given the solution va riables of the decision variables37 // Write or update results given the solution values of the decision variables 40 38 results.AddOrUpdateResult("x", new DoubleValue(x.SolutionValue())); 41 39 results.AddOrUpdateResult("y", new DoubleValue(y.SolutionValue())); -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/ScriptTemplates.Designer.cs
r16233 r16405 60 60 61 61 /// <summary> 62 /// Looks up a localized string similar to using Google.OrTools.LinearSolver; 62 /// Looks up a localized string similar to using System; 63 ///using System.Linq; 64 ///using System.Collections.Generic; 65 ///using Google.OrTools.LinearSolver; 66 ///using HeuristicLab.Common; 67 ///using HeuristicLab.Core; 63 68 ///using HeuristicLab.Data; 64 69 ///using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems; 65 70 ///using HeuristicLab.Optimization; 66 ///using HeuristicLab.Problems.Programmable;71 ///using Variable = Google.OrTools.LinearSolver.Variable; 67 72 /// 68 73 ///namespace HeuristicLab.MathematicalOptimization.LinearProgramming { 69 /// public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILinearProgrammingProblemDefinition {70 74 /// 71 /// private Variable x; 72 /// private Variable y; 73 /// 74 /// public override void Initialize() { 75 /// // [rest of string was truncated]";. 75 /// public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILi [rest of string was truncated]";. 76 76 /// </summary> 77 77 internal static string CompiledLinearProgrammingProblemDefinition { -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/ScriptTemplates.resx
r16233 r16405 60 60 : and then encoded with base64 encoding. 61 61 --> 62 <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/ QualityUpdateIntervalMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">63 <xsd:import namespace="http://www.w3.org/ QualityUpdateIntervalML/1998/namespace" />62 <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 63 <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> 64 64 <xsd:element name="root" msdata:IsDataSet="true"> 65 65 <xsd:complexType> … … 120 120 <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 121 121 <data name="CompiledLinearProgrammingProblemDefinition" type="System.Resources.ResXFileRef, System.Windows.Forms"> 122 <value> CompiledLinearProgrammingProblemDefinition.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>122 <value>compiledlinearprogrammingproblemdefinition.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value> 123 123 </data> 124 124 </root> -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/Plugin.cs.frame
r16373 r16405 28 28 [PluginFile("HeuristicLab.MathematicalOptimization-3.3.dll", PluginFileType.Assembly)] 29 29 [PluginDependency("HeuristicLab.Analysis", "3.3")] 30 [PluginDependency("HeuristicLab.CodeEditor", "3.4")]31 30 [PluginDependency("HeuristicLab.Collections", "3.3")] 32 31 [PluginDependency("HeuristicLab.Common", "3.3")] 33 32 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] 34 33 [PluginDependency("HeuristicLab.Core", "3.3")] 35 [PluginDependency("HeuristicLab.Core.Views", "3.3")]36 34 [PluginDependency("HeuristicLab.Data", "3.3")] 37 [PluginDependency("HeuristicLab.MainForm", "3.3")]38 [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]39 35 [PluginDependency("HeuristicLab.Optimization", "3.3")] 40 36 [PluginDependency("HeuristicLab.OrTools", "6.10")] … … 43 39 [PluginDependency("HeuristicLab.Problems.Programmable", "3.3")] 44 40 [PluginDependency("HeuristicLab.Scripting", "3.3")] 45 [PluginDependency("HeuristicLab.Scripting.Views", "3.3")]46 41 public class HeuristicLabMathematicalOptimizationPlugin : PluginBase { 47 42 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/Properties/Settings.Designer.cs
r16288 r16405 13 13 14 14 [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15. 8.0.0")]15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] 16 16 public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 17 … … 33 33 set { 34 34 this["ScipLibraryName"] = value; 35 }36 }37 38 [global::System.Configuration.UserScopedSettingAttribute()]39 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]40 [global::System.Configuration.DefaultSettingValueAttribute("gurobi80.dll")]41 public string GurobiLibraryName {42 get {43 return ((string)(this["GurobiLibraryName"]));44 }45 set {46 this["GurobiLibraryName"] = value;47 35 } 48 36 } … … 71 59 } 72 60 } 61 62 [global::System.Configuration.UserScopedSettingAttribute()] 63 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 64 [global::System.Configuration.DefaultSettingValueAttribute("gurobi81.dll")] 65 public string GurobiLibraryName { 66 get { 67 return ((string)(this["GurobiLibraryName"])); 68 } 69 set { 70 this["GurobiLibraryName"] = value; 71 } 72 } 73 73 } 74 74 } -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/Properties/Settings.settings
r16288 r16405 6 6 <Value Profile="(Default)">scip.dll</Value> 7 7 </Setting> 8 <Setting Name="GurobiLibraryName" Type="System.String" Scope="User">9 <Value Profile="(Default)">gurobi80.dll</Value>10 </Setting>11 8 <Setting Name="CplexLibraryName" Type="System.String" Scope="User"> 12 9 <Value Profile="(Default)">cplex1280.dll</Value> … … 15 12 <Value Profile="(Default)">glpk_4_65.dll</Value> 16 13 </Setting> 14 <Setting Name="GurobiLibraryName" Type="System.String" Scope="User"> 15 <Value Profile="(Default)">gurobi81.dll</Value> 16 </Setting> 17 17 </Settings> 18 18 </SettingsFile> -
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/app.config
r16373 r16405 11 11 <value>scip.dll</value> 12 12 </setting> 13 <setting name="GurobiLibraryName" serializeAs="String">14 <value>gurobi81.dll</value>15 </setting>16 13 <setting name="CplexLibraryName" serializeAs="String"> 17 14 <value>cplex1280.dll</value> … … 20 17 <value>glpk_4_65.dll</value> 21 18 </setting> 19 <setting name="GurobiLibraryName" serializeAs="String"> 20 <value>gurobi81.dll</value> 21 </setting> 22 22 </HeuristicLab.MathematicalOptimization.Properties.Settings> 23 23 </userSettings>
Note: See TracChangeset
for help on using the changeset viewer.