Changeset 16405


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

#2931:

  • moved views to separate plugin HeuristicLab.MathematicalOptimization.Views
  • added button in LinearProgrammingProblemView to select the problem definition type
  • added views for problem definitions
  • added ExportFile parameter to LinearProgrammingAlgorithm
  • extended FileValue and FileValueView by the option to save a file
  • code cleanup
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  
    5050    {F98A1740-9AC9-4D36-A582-6A2D0D06978D} = {F98A1740-9AC9-4D36-A582-6A2D0D06978D}
    5151    {B03C4E41-1D01-4C60-B0F4-DBB257D98CA8} = {B03C4E41-1D01-4C60-B0F4-DBB257D98CA8}
     52    {D1D69043-17E6-4B8C-BF41-0799C7E56032} = {D1D69043-17E6-4B8C-BF41-0799C7E56032}
    5253    {73F29D43-5714-4069-8FAB-0D18FEB5F175} = {73F29D43-5714-4069-8FAB-0D18FEB5F175}
    5354    {3E9E8944-44FF-40BB-A622-3A4A7DD0F198} = {3E9E8944-44FF-40BB-A622-3A4A7DD0F198}
     
    465466EndProject
    466467Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.MathematicalOptimization-3.3", "HeuristicLab.MathematicalOptimization\3.3\HeuristicLab.MathematicalOptimization-3.3.csproj", "{FA3B9270-48B7-4C77-9FEA-2A6EDE82E909}"
     468EndProject
     469Project("{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}"
    467470EndProject
    468471Global
     
    22642267    {FA3B9270-48B7-4C77-9FEA-2A6EDE82E909}.Release|x86.ActiveCfg = Release|x86
    22652268    {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
    22662281  EndGlobalSection
    22672282  GlobalSection(SolutionProperties) = preSolution
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data.Views/3.3/Path Views/FileValueView.Designer.cs

    r15583 r16405  
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FileValueView));
    4748      this.openButton = new System.Windows.Forms.Button();
    4849      this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    4950      this.stringConvertibleValueView = new HeuristicLab.Data.Views.StringConvertibleValueView();
     51      this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    5052      this.SuspendLayout();
    5153      //
     
    9092    protected System.Windows.Forms.OpenFileDialog openFileDialog;
    9193    protected StringConvertibleValueView stringConvertibleValueView;
     94    private System.Windows.Forms.SaveFileDialog saveFileDialog;
    9295  }
    9396}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data.Views/3.3/Path Views/FileValueView.cs

    r15583 r16405  
    5555
    5656    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;
    6061    }
    6162  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data/3.3/Path Types/FileValue.cs

    r15583 r16405  
    4040    }
    4141
     42    [Storable]
     43    public bool SaveFile { get; set; }
     44
    4245    [StorableConstructor]
    4346    protected FileValue(bool deserializing) : base(deserializing) { }
     
    4548      : base(original, cloner) {
    4649      fileDialogFilter = original.FileDialogFilter;
     50      SaveFile = original.SaveFile;
    4751    }
    4852    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.Data/3.3/Path Types/PathValue.cs

    r15583 r16405  
    2020#endregion
    2121
     22using System;
    2223using System.IO;
    2324using HeuristicLab.Common;
     
    2930  [StorableClass]
    3031  public abstract class PathValue : Item {
     32
     33    public EventHandler PathChanged;
    3134
    3235    [Storable]
     
    4245        value = value.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
    4346        stringValue.Value = value;
     47        OnPathChanged();
    4448      }
    4549    }
     
    5761    }
    5862
     63    protected virtual void OnPathChanged() {
     64      EventHandler handler = PathChanged;
     65      if (handler != null) handler(this, EventArgs.Empty);
     66    }
     67
    5968    [StorableHook(HookType.AfterDeserialization)]
    6069    private void AfterDeserialization() {
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/HeuristicLab.MathematicalOptimization-3.3.csproj

    r16373 r16405  
    121121    <Reference Include="System" />
    122122    <Reference Include="System.Core" />
    123     <Reference Include="System.Data" />
    124123    <Reference Include="System.Drawing" />
    125     <Reference Include="System.Windows.Forms" />
    126     <Reference Include="System.Xml" />
     124    <Reference Include="WindowsBase" />
    127125  </ItemGroup>
    128126  <ItemGroup>
    129127    <Compile Include="LinearProgramming\Algorithms\Solvers\BopSolver.cs" />
    130128    <Compile Include="LinearProgramming\Algorithms\Solvers\CoinOrSolver.cs" />
    131     <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ExternalSolver.cs" />
     129    <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ExternalLinearSolver.cs" />
    132130    <Compile Include="LinearProgramming\Algorithms\Solvers\GlopSolver.cs" />
    133131    <Compile Include="LinearProgramming\Algorithms\Solvers\GlpkSolver.cs" />
    134     <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IExternalSolver.cs" />
    135     <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IIncrementalSolver.cs" />
    136     <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ExternalIncrementalSolver.cs" />
    137     <Compile Include="LinearProgramming\Algorithms\Solvers\Base\IncrementalSolver.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" />
    138136    <Compile Include="LinearProgramming\Algorithms\ProblemType.cs" />
    139137    <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" />
    141142    <Compile Include="LinearProgramming\Algorithms\Solvers\CplexSolver.cs" />
    142143    <Compile Include="LinearProgramming\Algorithms\Solvers\GurobiSolver.cs" />
    143     <Compile Include="LinearProgramming\Algorithms\Solvers\Base\ISolver.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" />
    147148    <Compile Include="LinearProgramming\Problems\ILinearProgrammingProblemDefinition.cs" />
    148149    <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" />
    173158    <Compile Include="LinearProgramming\Templates\ScriptTemplates.Designer.cs">
    174159      <AutoGen>True</AutoGen>
     
    176161      <DependentUpon>ScriptTemplates.resx</DependentUpon>
    177162    </Compile>
    178     <Compile Include="LinearProgramming\Wrapper\SolverResponseStatus.cs" />
     163    <Compile Include="LinearProgramming\Algorithms\SolverResponseStatus.cs" />
    179164    <Compile Include="Properties\AssemblyInfo.cs" />
    180165    <Compile Include="Properties\Settings.Designer.cs">
     
    201186      <Generator>ResXFileCodeGenerator</Generator>
    202187      <LastGenOutput>ScriptTemplates.Designer.cs</LastGenOutput>
    203     </EmbeddedResource>
    204     <EmbeddedResource Include="LinearProgramming\Views\LinearProgrammingProblemView.resx">
    205       <DependentUpon>LinearProgrammingProblemView.cs</DependentUpon>
     188      <SubType>Designer</SubType>
    206189    </EmbeddedResource>
    207190  </ItemGroup>
     
    211194      <Name>HeuristicLab.Analysis-3.3</Name>
    212195    </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>
    217196    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
    218197      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     
    227206      <Name>HeuristicLab.Common-3.3</Name>
    228207    </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>
    233208    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
    234209      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
     
    239214      <Name>HeuristicLab.Data-3.3</Name>
    240215    </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>
    249216    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    250217      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
     
    266233      <Project>{EE07BFF8-B23D-41F5-8AD7-AC9598D7A2C9}</Project>
    267234      <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>
    272235    </ProjectReference>
    273236    <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  
    2727    IncrementalityOff = 0,
    2828
    29     // Reuse results from previous solve as much as the underlying
    30     // solver allows.
     29    // Reuse results from previous solve as much as the underlying solver allows.
    3130    IncrementalityOn = 1
    3231  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Algorithms/IntegerParam.cs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    r16383 r16405  
    2020#endregion
    2121
    22 using System;
    23 using HeuristicLab.Optimization;
     22namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2423
    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; }
    3526
    36     public dynamic vars { get; set; }
    3727    public abstract void Initialize();
    38 
    39     protected CompiledProblemDefinition() { }
    40     protected CompiledProblemDefinition(IEncoding encoding)
    41       : base() {
    42       Encoding = encoding;
    43     }
    4428  }
    4529}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/FileBasedLinearProgrammingProblemDefinition.cs

    r16368 r16405  
    2020#endregion
    2121
     22using System.Drawing;
     23using System.IO;
    2224using Google.OrTools.LinearSolver;
    23 using HeuristicLab.Problems.Programmable;
     25using HeuristicLab.Common;
     26using HeuristicLab.Common.Resources;
     27using HeuristicLab.Core;
     28using HeuristicLab.Data;
     29using HeuristicLab.Optimization;
     30using HeuristicLab.Parameters;
     31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2432
    25 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
     33namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2634
    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    }
    2878
    2979    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);
    3092    }
    3193
    32     public override void Initialize() {
    33     }
     94    public override IDeepCloneable Clone(Cloner cloner) => new FileBasedLinearProgrammingProblemDefinition(this, cloner);
    3495  }
    3596}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/ILinearProgrammingProblemDefinition.cs

    r16373 r16405  
    2121
    2222using Google.OrTools.LinearSolver;
     23using HeuristicLab.Common;
    2324using HeuristicLab.Optimization;
    2425
    25 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
     26namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    2627
    27   public interface ILinearProgrammingProblemDefinition {
    28 
    29     bool BuildModel(Solver solver);
     28  public interface ILinearProgrammingProblemDefinition : IContent {
    3029
    3130    void Analyze(Solver solver, ResultCollection results);
     31
     32    void BuildModel(Solver solver);
    3233  }
    3334}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/LinearProgrammingProblem.cs

    r16373 r16405  
    2020#endregion
    2121
    22 using System.Drawing;
     22using System;
    2323using HeuristicLab.Common;
    24 using HeuristicLab.Common.Resources;
    2524using HeuristicLab.Core;
    2625using HeuristicLab.Optimization;
    27 using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2927
    30 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
     28namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3129
    3230  [Item("Linear/Mixed Integer Programming Problem (LP/MIP)", "Represents a linear/mixed integer problem.")]
    33   [Creatable(CreatableAttribute.Categories.CombinatorialProblems)]
    3431  [StorableClass]
    35   public class LinearProgrammingProblem : Problem, IProgrammableItem {
     32  public sealed class LinearProgrammingProblem : Problem {
     33    [Storable]
     34    private ILinearProgrammingProblemDefinition problemDefinition;
    3635
    3736    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"]);
    4138    }
    4239
    43     protected LinearProgrammingProblem(LinearProgrammingProblem original, Cloner cloner)
     40    private LinearProgrammingProblem(LinearProgrammingProblem original, Cloner cloner)
    4441      : base(original, cloner) {
    45       RegisterEvents();
    4642    }
    4743
    4844    [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) {
    6046    }
    6147
    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      }
    6558    }
     59
     60    public override IDeepCloneable Clone(Cloner cloner) => new LinearProgrammingProblem(this, cloner);
    6661
    6762    [StorableHook(HookType.AfterDeserialization)]
    6863    private void AfterDeserialization() {
    69       RegisterEvents();
    7064    }
    7165
     
    7468      OnReset();
    7569    }
    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     }
    8570  }
    8671}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/ProgrammableLinearProgrammingProblemDefinition.cs

    r16404 r16405  
    3131using HeuristicLab.Scripting;
    3232
    33 namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
     33namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    3434
    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.")]
    3637  [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();
    3941
    40     [Storable]
    41     private readonly VariableStore variableStore;
     42    [Storable] private readonly VariableStore variableStore;
    4243
    43     public VariableStore VariableStore => variableStore;
     44    [Storable] private bool codeChanged;
    4445
    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    }
    4753
    4854    [StorableConstructor]
    49     private LinearProgrammingProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     55    private ProgrammableLinearProgrammingProblemDefinition(bool deserializing) : base(deserializing) {
     56    }
    5057
    51     private LinearProgrammingProblemDefinitionScript(LinearProgrammingProblemDefinitionScript original, Cloner cloner)
    52       : base(original, cloner) {
     58    private ProgrammableLinearProgrammingProblemDefinition(ProgrammableLinearProgrammingProblemDefinition original,
     59      Cloner cloner) : base(original, cloner) {
    5360      variableStore = cloner.Clone(original.variableStore);
    5461      codeChanged = original.codeChanged;
    5562    }
    5663
    57     public LinearProgrammingProblemDefinitionScript()
    58       : base(ScriptTemplates.CompiledLinearProgrammingProblemDefinition) {
    59       variableStore = new VariableStore();
    60     }
     64    public event EventHandler ProblemDefinitionChanged;
    6165
    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;
    6469
    6570    private ILinearProgrammingProblemDefinition CompiledProblemDefinition {
     
    7580          }
    7681        }
     82
    7783        return compiledProblemDefinition;
    7884      }
    7985    }
    8086
    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    }
    8296
    8397    public override Assembly Compile() => Compile(true);
     98
     99    protected override void OnCodeChanged() {
     100      base.OnCodeChanged();
     101      compiledProblemDefinition = null;
     102      codeChanged = true;
     103    }
    84104
    85105    private Assembly Compile(bool fireChanged) {
     
    87107      var types = assembly.GetTypes();
    88108      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 +
    91110                                                   "The problem definition must be a subclass of CompiledProblemDefinition.");
    92111      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 +
    95113                                                   "Only one subclass of CompiledProblemDefinition is allowed.");
    96114
     
    128146    }
    129147
    130     protected override void OnCodeChanged() {
    131       base.OnCodeChanged();
    132       compiledProblemDefinition = null;
    133       codeChanged = true;
    134     }
    135 
    136     public event EventHandler ProblemDefinitionChanged;
    137 
    138148    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);
    149149  }
    150150}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/CompiledLinearProgrammingProblemDefinition.cs

    r16373 r16405  
    66using HeuristicLab.Core;
    77using HeuristicLab.Data;
    8 using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
    98using HeuristicLab.Optimization;
    10 using HeuristicLab.Problems.Programmable;
    119using Variable = Google.OrTools.LinearSolver.Variable;
    1210
     
    2220    }
    2321
    24     public bool BuildModel(Solver solver) {
     22    public void BuildModel(Solver solver) {
    2523      // 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
    2625      // Example model taken from https://developers.google.com/optimization/mip/integer_opt
    2726      // Define the decision variables
     
    3231      // Define the objective
    3332      solver.Maximize(x + 10 * y);
    34       return true;
    3533    }
    3634
    3735    public void Analyze(Solver solver, ResultCollection results) {
    3836      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    39       // Write or update results given the solution variables of the decision variables
     37      // Write or update results given the solution values of the decision variables
    4038      results.AddOrUpdateResult("x", new DoubleValue(x.SolutionValue()));
    4139      results.AddOrUpdateResult("y", new DoubleValue(y.SolutionValue()));
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/ScriptTemplates.Designer.cs

    r16233 r16405  
    6060
    6161    /// <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;
    6368    ///using HeuristicLab.Data;
    6469    ///using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
    6570    ///using HeuristicLab.Optimization;
    66     ///using HeuristicLab.Problems.Programmable;
     71    ///using Variable = Google.OrTools.LinearSolver.Variable;
    6772    ///
    6873    ///namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
    69     ///  public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILinearProgrammingProblemDefinition {
    7074    ///
    71     ///    private Variable x;
    72     ///    private Variable y;
    73     ///
    74     ///    public override void Initialize() {
    75     ///      // [rest of string was truncated]&quot;;.
     75    ///  public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILi [rest of string was truncated]&quot;;.
    7676    /// </summary>
    7777    internal static string CompiledLinearProgrammingProblemDefinition {
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/ScriptTemplates.resx

    r16233 r16405  
    6060            : and then encoded with base64 encoding.
    6161    -->
    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" />
    6464    <xsd:element name="root" msdata:IsDataSet="true">
    6565      <xsd:complexType>
     
    120120  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    121121  <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>
    123123  </data>
    124124</root>
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/Plugin.cs.frame

    r16373 r16405  
    2828  [PluginFile("HeuristicLab.MathematicalOptimization-3.3.dll", PluginFileType.Assembly)]
    2929  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    30   [PluginDependency("HeuristicLab.CodeEditor", "3.4")]
    3130  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3231  [PluginDependency("HeuristicLab.Common", "3.3")]
    3332  [PluginDependency("HeuristicLab.Common.Resources", "3.3")]
    3433  [PluginDependency("HeuristicLab.Core", "3.3")]
    35   [PluginDependency("HeuristicLab.Core.Views", "3.3")]
    3634  [PluginDependency("HeuristicLab.Data", "3.3")]
    37   [PluginDependency("HeuristicLab.MainForm", "3.3")]
    38   [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
    3935  [PluginDependency("HeuristicLab.Optimization", "3.3")]
    4036  [PluginDependency("HeuristicLab.OrTools", "6.10")]
     
    4339  [PluginDependency("HeuristicLab.Problems.Programmable", "3.3")]
    4440  [PluginDependency("HeuristicLab.Scripting", "3.3")]
    45   [PluginDependency("HeuristicLab.Scripting.Views", "3.3")]
    4641  public class HeuristicLabMathematicalOptimizationPlugin : PluginBase {
    4742  }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/Properties/Settings.Designer.cs

    r16288 r16405  
    1313   
    1414    [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")]
    1616    public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    1717       
     
    3333            set {
    3434                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;
    4735            }
    4836        }
     
    7159            }
    7260        }
     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        }
    7373    }
    7474}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/Properties/Settings.settings

    r16288 r16405  
    66      <Value Profile="(Default)">scip.dll</Value>
    77    </Setting>
    8     <Setting Name="GurobiLibraryName" Type="System.String" Scope="User">
    9       <Value Profile="(Default)">gurobi80.dll</Value>
    10     </Setting>
    118    <Setting Name="CplexLibraryName" Type="System.String" Scope="User">
    129      <Value Profile="(Default)">cplex1280.dll</Value>
     
    1512      <Value Profile="(Default)">glpk_4_65.dll</Value>
    1613    </Setting>
     14    <Setting Name="GurobiLibraryName" Type="System.String" Scope="User">
     15      <Value Profile="(Default)">gurobi81.dll</Value>
     16    </Setting>
    1717  </Settings>
    1818</SettingsFile>
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/app.config

    r16373 r16405  
    1111        <value>scip.dll</value>
    1212      </setting>
    13       <setting name="GurobiLibraryName" serializeAs="String">
    14         <value>gurobi81.dll</value>
    15       </setting>
    1613      <setting name="CplexLibraryName" serializeAs="String">
    1714        <value>cplex1280.dll</value>
     
    2017        <value>glpk_4_65.dll</value>
    2118      </setting>
     19      <setting name="GurobiLibraryName" serializeAs="String">
     20        <value>gurobi81.dll</value>
     21      </setting>
    2222    </HeuristicLab.MathematicalOptimization.Properties.Settings>
    2323  </userSettings>
Note: See TracChangeset for help on using the changeset viewer.