Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/18 09:50:12 (6 years ago)
Author:
ddorfmei
Message:

#2931:

  • created LinearProgrammingAlgorithm
    • created definitions for all LP/MIP solvers supported by OR-Tools
  • created LinearProgrammingProblem
    • created classes required for scripting: LinearProgrammingProblemDefinition, LinearProgrammingProblemDefinitionScript, CompiledLinearProgrammingProblemDefinition
    • created views: LinearProgrammingProblemView, LinearProgrammingProblemDefinitionScriptView
  • updated OR-Tools version in ExtLibs to 6.9
Location:
branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3
Files:
18 added
2 deleted
3 edited
9 copied

Legend:

Unmodified
Added
Removed
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/HeuristicLab.MathematicalOptimization-3.3.csproj

    r16138 r16172  
    115115      <HintPath>..\..\bin\Google.OrTools.dll</HintPath>
    116116    </Reference>
    117     <Reference Include="Google.Protobuf, Version=3.5.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL">
     117    <Reference Include="HeuristicLab.OrTools-6.9.0-pre, Version=6.8.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    118118      <SpecificVersion>False</SpecificVersion>
    119       <HintPath>..\..\bin\Google.Protobuf.dll</HintPath>
    120       <Private>False</Private>
     119      <HintPath>..\..\bin\HeuristicLab.OrTools-6.9.0-pre.dll</HintPath>
    121120    </Reference>
    122121    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=x86">
     
    127126    <Reference Include="System.Core" />
    128127    <Reference Include="System.Data" />
    129   </ItemGroup>
    130   <ItemGroup>
     128    <Reference Include="System.Drawing" />
     129    <Reference Include="System.Windows.Forms" />
     130    <Reference Include="System.Xml" />
     131  </ItemGroup>
     132  <ItemGroup>
     133    <Compile Include="LinearProgramming\Algorithms\BopSolver.cs" />
     134    <Compile Include="LinearProgramming\Algorithms\CoinOrSolver.cs" />
     135    <Compile Include="LinearProgramming\Algorithms\GlopSolver.cs" />
     136    <Compile Include="LinearProgramming\Algorithms\GlpkSolver.cs" />
     137    <Compile Include="LinearProgramming\Algorithms\LinearProgrammingType.cs" />
     138    <Compile Include="LinearProgramming\Algorithms\ScipSolver.cs" />
    131139    <Compile Include="LinearProgramming\BasisStatus.cs" />
     140    <Compile Include="LinearProgramming\Algorithms\CplexSolver.cs" />
     141    <Compile Include="LinearProgramming\Algorithms\GurobiSolver.cs" />
     142    <Compile Include="LinearProgramming\Algorithms\ISolver.cs" />
     143    <Compile Include="LinearProgramming\Problems\ILinearProgrammingProblemDefinition.cs" />
     144    <Compile Include="LinearProgramming\Algorithms\LinearProgrammingAlgorithm.cs" />
     145    <Compile Include="LinearProgramming\Problems\LinearProgrammingProblem.cs" />
    132146    <Compile Include="LinearProgramming\LinearSolverExtensions.cs" />
    133147    <Compile Include="LinearProgramming\LinearSolver.cs" />
     148    <Compile Include="LinearProgramming\Problems\LinearProgrammingProblemDefintion.cs" />
    134149    <Compile Include="LinearProgramming\OptimizationProblemType.cs" />
     150    <Compile Include="LinearProgramming\Problems\ProblemDefinitionScriptException.cs" />
     151    <Compile Include="LinearProgramming\Algorithms\Solver.cs" />
     152    <Compile Include="LinearProgramming\Views\LinearProgrammingProblemDefinitionScriptView.cs">
     153      <SubType>UserControl</SubType>
     154    </Compile>
     155    <Compile Include="LinearProgramming\Views\LinearProgrammingProblemDefinitionScriptView.Designer.cs">
     156      <DependentUpon>LinearProgrammingProblemDefinitionScriptView.cs</DependentUpon>
     157    </Compile>
    135158    <Compile Include="LinearProgramming\ResultStatus.cs" />
     159    <Compile Include="LinearProgramming\Views\LinearProgrammingProblemView.cs">
     160      <SubType>UserControl</SubType>
     161    </Compile>
     162    <Compile Include="LinearProgramming\Views\LinearProgrammingProblemView.Designer.cs">
     163      <DependentUpon>LinearProgrammingProblemView.cs</DependentUpon>
     164    </Compile>
     165    <Compile Include="LinearProgramming\Problems\LinearProgrammingProblemDefinitionScript.cs" />
     166    <Compile Include="LinearProgramming\Templates\CompiledLinearProgrammingProblemDefinition.cs" />
     167    <Compile Include="LinearProgramming\Templates\ScriptTemplates.Designer.cs">
     168      <AutoGen>True</AutoGen>
     169      <DesignTime>True</DesignTime>
     170      <DependentUpon>ScriptTemplates.resx</DependentUpon>
     171    </Compile>
    136172    <Compile Include="Properties\AssemblyInfo.cs" />
    137173    <None Include="Plugin.cs.frame" />
     
    142178    <None Include="HeuristicLab.snk" />
    143179  </ItemGroup>
    144   <ItemGroup />
     180  <ItemGroup>
     181    <ProjectReference Include="..\..\HeuristicLab.Clients.OKB\3.3\HeuristicLab.Clients.OKB-3.3.csproj">
     182      <Project>{73857A9C-9706-4B72-8D9C-210B5B6A5691}</Project>
     183      <Name>HeuristicLab.Clients.OKB-3.3</Name>
     184    </ProjectReference>
     185    <ProjectReference Include="..\..\HeuristicLab.CodeEditor\3.4\HeuristicLab.CodeEditor-3.4.csproj">
     186      <Project>{C38691AE-ECB4-489A-A05D-B035554E0168}</Project>
     187      <Name>HeuristicLab.CodeEditor-3.4</Name>
     188    </ProjectReference>
     189    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
     190      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     191      <Name>HeuristicLab.Collections-3.3</Name>
     192    </ProjectReference>
     193    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.3\HeuristicLab.Common.Resources-3.3.csproj">
     194      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
     195      <Name>HeuristicLab.Common.Resources-3.3</Name>
     196    </ProjectReference>
     197    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
     198      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     199      <Name>HeuristicLab.Common-3.3</Name>
     200    </ProjectReference>
     201    <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">
     202      <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project>
     203      <Name>HeuristicLab.Core.Views-3.3</Name>
     204    </ProjectReference>
     205    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
     206      <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project>
     207      <Name>HeuristicLab.Core-3.3</Name>
     208    </ProjectReference>
     209    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     210      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     211      <Name>HeuristicLab.Data-3.3</Name>
     212    </ProjectReference>
     213    <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.3\HeuristicLab.MainForm.WindowsForms-3.3.csproj">
     214      <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project>
     215      <Name>HeuristicLab.MainForm.WindowsForms-3.3</Name>
     216    </ProjectReference>
     217    <ProjectReference Include="..\..\HeuristicLab.MainForm\3.3\HeuristicLab.MainForm-3.3.csproj">
     218      <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project>
     219      <Name>HeuristicLab.MainForm-3.3</Name>
     220    </ProjectReference>
     221    <ProjectReference Include="..\..\HeuristicLab.Optimization.Operators\3.3\HeuristicLab.Optimization.Operators-3.3.csproj">
     222      <Project>{25087811-F74C-4128-BC86-8324271DA13E}</Project>
     223      <Name>HeuristicLab.Optimization.Operators-3.3</Name>
     224    </ProjectReference>
     225    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
     226      <Project>{14AB8D24-25BC-400C-A846-4627AA945192}</Project>
     227      <Name>HeuristicLab.Optimization-3.3</Name>
     228    </ProjectReference>
     229    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     230      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
     231      <Name>HeuristicLab.Parameters-3.3</Name>
     232    </ProjectReference>
     233    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
     234      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
     235      <Name>HeuristicLab.Persistence-3.3</Name>
     236    </ProjectReference>
     237    <ProjectReference Include="..\..\HeuristicLab.Problems.Programmable\3.3\HeuristicLab.Problems.Programmable-3.3.csproj">
     238      <Project>{EE07BFF8-B23D-41F5-8AD7-AC9598D7A2C9}</Project>
     239      <Name>HeuristicLab.Problems.Programmable-3.3</Name>
     240    </ProjectReference>
     241    <ProjectReference Include="..\..\HeuristicLab.Scripting.Views\3.3\HeuristicLab.Scripting.Views-3.3.csproj">
     242      <Project>{0C2917C8-7AA8-4E18-800A-C4D064F992ED}</Project>
     243      <Name>HeuristicLab.Scripting.Views-3.3</Name>
     244    </ProjectReference>
     245    <ProjectReference Include="..\..\HeuristicLab.Scripting\3.3\HeuristicLab.Scripting-3.3.csproj">
     246      <Project>{21977CC3-1757-4B3B-87BD-FF817AAA900F}</Project>
     247      <Name>HeuristicLab.Scripting-3.3</Name>
     248    </ProjectReference>
     249  </ItemGroup>
     250  <ItemGroup>
     251    <EmbeddedResource Include="LinearProgramming\Templates\ScriptTemplates.resx">
     252      <Generator>ResXFileCodeGenerator</Generator>
     253      <LastGenOutput>ScriptTemplates.Designer.cs</LastGenOutput>
     254    </EmbeddedResource>
     255    <EmbeddedResource Include="LinearProgramming\Views\LinearProgrammingProblemView.resx">
     256      <DependentUpon>LinearProgrammingProblemView.cs</DependentUpon>
     257    </EmbeddedResource>
     258  </ItemGroup>
    145259  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    146260  <PropertyGroup>
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/ILinearProgrammingProblemDefinition.cs

    r16138 r16172  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using HeuristicLab.Core;
     22using Google.OrTools.LinearSolver;
     23using HeuristicLab.Optimization;
    2424
    25 namespace HeuristicLab.Optimization {
    26   public interface ISingleObjectiveProblemDefinition : IProblemDefinition {
    27     bool Maximization { get; }
    28     double Evaluate(Individual individual, IRandom random);
    29     void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random);
    30     IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random);
     25namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
     26  public interface ILinearProgrammingProblemDefinition {
     27    void BuildModel(Solver solver);
     28    void Analyze(Solver solver, ResultCollection results);
    3129  }
    3230}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/LinearProgrammingProblemDefinitionScript.cs

    r16138 r16172  
    2020#endregion
    2121
    22 using System.Collections.Generic;
     22using System;
     23using System.Linq;
     24using System.Reflection;
     25using Google.OrTools.LinearSolver;
    2326using HeuristicLab.Common;
    2427using HeuristicLab.Core;
    2528using HeuristicLab.Optimization;
    2629using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Problems.Programmable;
     31using HeuristicLab.Scripting;
    2732
    28 namespace HeuristicLab.Problems.Programmable {
     33namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
    2934  [Item("Single-objective Problem Definition Script", "Script that defines the parameter vector and evaluates the solution for a programmable problem.")]
    3035  [StorableClass]
    31   public sealed class SingleObjectiveProblemDefinitionScript : ProblemDefinitionScript, ISingleObjectiveProblemDefinition, IStorableContent {
     36  public sealed class LinearProgrammingProblemDefinitionScript : Script, ILinearProgrammingProblemDefinition, IStorableContent {
     37    protected bool SuppressEvents { get; set; }
     38
     39    [Storable]
     40    private VariableStore variableStore;
     41    public VariableStore VariableStore => variableStore;
     42
     43    [Storable]
     44    private bool codeChanged;
     45
     46    [StorableConstructor]
     47    protected LinearProgrammingProblemDefinitionScript(bool deserializing) : base(deserializing) { }
     48    protected LinearProgrammingProblemDefinitionScript(LinearProgrammingProblemDefinitionScript original, Cloner cloner)
     49      : base(original, cloner) {
     50      variableStore = cloner.Clone(original.variableStore);
     51      codeChanged = original.codeChanged;
     52    }
     53
     54    public LinearProgrammingProblemDefinitionScript()
     55      : base(ScriptTemplates.CompiledLinearProgrammingProblemDefinition) {
     56      variableStore = new VariableStore();
     57    }
     58
     59    private readonly object compileLock = new object();
     60    private volatile ILinearProgrammingProblemDefinition compiledProblemDefinition;
     61    protected ILinearProgrammingProblemDefinition CompiledProblemDefinition {
     62      get {
     63        // double checked locking pattern
     64        if (compiledProblemDefinition == null) {
     65          lock (compileLock) {
     66            if (compiledProblemDefinition == null) {
     67              if (codeChanged) throw new ProblemDefinitionScriptException("The code has been changed, but was not recompiled.");
     68              Compile(false);
     69            }
     70          }
     71        }
     72        return compiledProblemDefinition;
     73      }
     74    }
     75    public dynamic Instance => compiledProblemDefinition;
     76
     77    public override Assembly Compile() {
     78      return Compile(true);
     79    }
     80
     81    private Assembly Compile(bool fireChanged) {
     82      var assembly = base.Compile();
     83      var types = assembly.GetTypes();
     84      if (!types.Any(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)))
     85        throw new ProblemDefinitionScriptException("The compiled code doesn't contain a problem definition." + Environment.NewLine + "The problem definition must be a subclass of CompiledProblemDefinition.");
     86      if (types.Count(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)) > 1)
     87        throw new ProblemDefinitionScriptException("The compiled code contains multiple problem definitions." + Environment.NewLine + "Only one subclass of CompiledProblemDefinition is allowed.");
     88
     89      CompiledProblemDefinition inst;
     90      try {
     91        inst = (CompiledProblemDefinition)Activator.CreateInstance(types.Single(x => typeof(CompiledProblemDefinition).IsAssignableFrom(x)));
     92      } catch (Exception e) {
     93        compiledProblemDefinition = null;
     94        throw new ProblemDefinitionScriptException("Instantiating the problem definition failed." + Environment.NewLine + "Check your default constructor.", e);
     95      }
     96
     97      try {
     98        inst.vars = new Variables(VariableStore);
     99        inst.Initialize();
     100      } catch (Exception e) {
     101        compiledProblemDefinition = null;
     102        throw new ProblemDefinitionScriptException("Initializing the problem definition failed." + Environment.NewLine + "Check your Initialize() method.", e);
     103      }
     104
     105      try {
     106        compiledProblemDefinition = (ILinearProgrammingProblemDefinition)inst;
     107        if (fireChanged) OnProblemDefinitionChanged();
     108      } catch (Exception e) {
     109        compiledProblemDefinition = null;
     110        throw new ProblemDefinitionScriptException("Using the problem definition in the problem failed." + Environment.NewLine + "Examine this error message carefully (often there is an issue with the defined encoding).", e);
     111      }
     112
     113      codeChanged = false;
     114      return assembly;
     115    }
     116
     117    protected override void OnCodeChanged() {
     118      base.OnCodeChanged();
     119      compiledProblemDefinition = null;
     120      codeChanged = true;
     121    }
     122
     123    public event EventHandler ProblemDefinitionChanged;
     124    private void OnProblemDefinitionChanged() {
     125      var handler = ProblemDefinitionChanged;
     126      if (handler != null) handler(this, EventArgs.Empty);
     127    }
     128
    32129    public string Filename { get; set; }
    33130
    34     private new ISingleObjectiveProblemDefinition CompiledProblemDefinition {
    35       get { return (ISingleObjectiveProblemDefinition)base.CompiledProblemDefinition; }
     131    public override IDeepCloneable Clone(Cloner cloner) {
     132      return new LinearProgrammingProblemDefinitionScript(this, cloner);
    36133    }
    37134
    38     [StorableConstructor]
    39     private SingleObjectiveProblemDefinitionScript(bool deserializing) : base(deserializing) { }
    40     private SingleObjectiveProblemDefinitionScript(SingleObjectiveProblemDefinitionScript original, Cloner cloner) : base(original, cloner) { }
    41     public SingleObjectiveProblemDefinitionScript() : base(ScriptTemplates.CompiledSingleObjectiveProblemDefinition) { }
     135    public void BuildModel(Solver solver) => CompiledProblemDefinition.BuildModel(solver);
    42136
    43     public override IDeepCloneable Clone(Cloner cloner) {
    44       return new SingleObjectiveProblemDefinitionScript(this, cloner);
    45     }
    46 
    47     bool ISingleObjectiveProblemDefinition.Maximization {
    48       get { return CompiledProblemDefinition.Maximization; }
    49     }
    50 
    51     double ISingleObjectiveProblemDefinition.Evaluate(Individual individual, IRandom random) {
    52       return CompiledProblemDefinition.Evaluate(individual, random);
    53     }
    54 
    55     void ISingleObjectiveProblemDefinition.Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    56       CompiledProblemDefinition.Analyze(individuals, qualities, results, random);
    57     }
    58     IEnumerable<Individual> ISingleObjectiveProblemDefinition.GetNeighbors(Individual individual, IRandom random) {
    59       return CompiledProblemDefinition.GetNeighbors(individual, random);
    60     }
     137    public void Analyze(Solver solver, ResultCollection results) => CompiledProblemDefinition.Analyze(solver, results);
    61138  }
    62139}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Problems/ProblemDefinitionScriptException.cs

    r16138 r16172  
    2323using System.Runtime.Serialization;
    2424
    25 namespace HeuristicLab.Problems.Programmable {
     25namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Problems {
    2626  [Serializable]
    2727  public class ProblemDefinitionScriptException : Exception {
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/CompiledLinearProgrammingProblemDefinition.cs

    r16138 r16172  
    1 using System;
    2 using System.Linq;
    3 using System.Collections.Generic;
    4 using HeuristicLab.Common;
    5 using HeuristicLab.Core;
     1using Google.OrTools.LinearSolver;
    62using HeuristicLab.Data;
    7 using HeuristicLab.Encodings.BinaryVectorEncoding;
    8 using HeuristicLab.Encodings.IntegerVectorEncoding;
    9 using HeuristicLab.Encodings.RealVectorEncoding;
    10 using HeuristicLab.Encodings.PermutationEncoding;
    11 using HeuristicLab.Encodings.LinearLinkageEncoding;
    12 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     3using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
    134using HeuristicLab.Optimization;
    145using HeuristicLab.Problems.Programmable;
    156
    16 namespace HeuristicLab.Problems.Programmable {
    17   public class CompiledSingleObjectiveProblemDefinition : CompiledProblemDefinition, ISingleObjectiveProblemDefinition {
    18     public bool Maximization { get { return false; } }
     7namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
     8  public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILinearProgrammingProblemDefinition {
     9
     10    private Variable x;
     11    private Variable y;
    1912
    2013    public override void Initialize() {
    2114      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    22       // Define the solution encoding which can also consist of multiple vectors, examples below
    23       //Encoding = new BinaryVectorEncoding("b", length: 5);
    24       //Encoding = new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 2);
    25       //Encoding = new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0);
    26       //Encoding = new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute);
    27       //Encoding = new LinearLinkageEncoding("l", length: 5);
    28       //Encoding = new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12);
    29       // The encoding can also be a combination
    30       //Encoding = new MultiEncoding()
    31       //.Add(new BinaryVectorEncoding("b", length: 5))
    32       //.Add(new IntegerVectorEncoding("i", length: 5, min: 2, max: 14, step: 4))
    33       //.Add(new RealVectorEncoding("r", length: 5, min: -1.0, max: 1.0))
    34       //.Add(new PermutationEncoding("p", length: 5, type: PermutationTypes.Absolute))
    35       //.Add(new LinearLinkageEncoding("l", length: 5))
    36       //.Add(new SymbolicExpressionTreeEncoding("s", new SimpleSymbolicExpressionGrammar(), 50, 12))
    37       ;
    3815      // Add additional initialization code e.g. private variables that you need for evaluating
    3916    }
    4017
    41     public double Evaluate(Individual individual, IRandom random) {
     18    public void BuildModel(Solver solver) {
    4219      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    43       var quality = 0.0;
    44       //quality = individual.RealVector("r").Sum(x => x * x);
    45       return quality;
     20      // Example model taken from https://developers.google.com/optimization/mip/integer_opt
     21      // Define the decision variables
     22      x = solver.MakeIntVar(0, 3.5, "x");
     23      y = solver.MakeIntVar(0, double.PositiveInfinity, "y");
     24      // Define the constraints
     25      solver.Add(x + 7 * y <= 17.5);
     26      // Define the objective
     27      solver.Maximize(x + 10 * y);
    4628    }
    4729
    48     public void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     30    public void Analyze(Solver solver, ResultCollection results) {
    4931      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    50       // Write or update results given the range of vectors and resulting qualities
    51       // Uncomment the following lines if you want to retrieve the best individual
    52 
    53       //var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality);
    54       //var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual;
    55 
    56       //if (!results.ContainsKey("Best Solution")) {
    57       //  results.Add(new Result("Best Solution", typeof(RealVector)));
    58       //}
    59       //results["Best Solution"].Value = (IItem)best.RealVector("r").Clone();
    60     }
    61 
    62     public IEnumerable<Individual> GetNeighbors(Individual individual, IRandom random) {
    63       // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
    64       // Create new vectors, based on the given one that represent small changes
    65       // This method is only called from move-based algorithms (Local Search, Simulated Annealing, etc.)
    66       while (true) {
    67         // Algorithm will draw only a finite amount of samples
    68         // Change to a for-loop to return a concrete amount of neighbors
    69         var neighbor = individual.Copy();
    70         // For instance, perform a single bit-flip in a binary parameter
    71         //var bIndex = random.Next(neighbor.BinaryVector("b").Length);
    72         //neighbor.BinaryVector("b")[bIndex] = !neighbor.BinaryVector("b")[bIndex];
    73         yield return neighbor;
    74       }
     32      // Write or update results given the solution variables of the decision variables
     33      results.AddOrUpdateResult("x", new DoubleValue(x.SolutionValue()));
     34      results.AddOrUpdateResult("y", new DoubleValue(y.SolutionValue()));
     35      // The decision variables can also be retrieved from the solver
     36      //results.AddOrUpdateResult("x", new DoubleValue(solver.LookupVariableOrNull("x").SolutionValue()));
     37      //results.AddOrUpdateResult("y", new DoubleValue(solver.LookupVariableOrNull("y").SolutionValue()));
    7538    }
    7639
     
    7841  }
    7942}
    80 
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/ScriptTemplates.resx

    r11753 r16172  
    119119  </resheader>
    120120  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    121   <data name="CompiledMultiObjectiveProblemDefinition" type="System.Resources.ResXFileRef, System.Windows.Forms">
    122     <value>CompiledMultiObjectiveProblemDefinition.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
    123   </data>
    124   <data name="CompiledSingleObjectiveProblemDefinition" type="System.Resources.ResXFileRef, System.Windows.Forms">
    125     <value>CompiledSingleObjectiveProblemDefinition.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
     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>
    126123  </data>
    127124</root>
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Views/LinearProgrammingProblemDefinitionScriptView.Designer.cs

    r16138 r16172  
    2121
    2222
    23 namespace HeuristicLab.Problems.Programmable.Views {
    24   partial class ProblemDefinitionScriptView {
     23using System.ComponentModel;
     24using System.Windows.Forms;
     25using HeuristicLab.Scripting.Views;
     26
     27namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Views {
     28  partial class LinearProgrammingProblemDefinitionScriptView {
    2529    /// <summary>
    2630    /// Required designer variable.
    2731    /// </summary>
    28     private System.ComponentModel.IContainer components = null;
     32    private IContainer components = null;
    2933
    3034    /// <summary>
     
    4650    /// </summary>
    4751    private void InitializeComponent() {
    48       System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ProblemDefinitionScriptView));
     52      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LinearProgrammingProblemDefinitionScriptView));
    4953      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    5054      this.variableStoreView = new HeuristicLab.Scripting.Views.VariableStoreView();
     
    168172    #endregion
    169173
    170     private System.Windows.Forms.SplitContainer splitContainer2;
    171     private Scripting.Views.VariableStoreView variableStoreView;
     174    private SplitContainer splitContainer2;
     175    private VariableStoreView variableStoreView;
    172176  }
    173177}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Views/LinearProgrammingProblemDefinitionScriptView.cs

    r16138 r16172  
    2323using System.Drawing;
    2424using HeuristicLab.MainForm;
     25using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
     26using HeuristicLab.PluginInfrastructure;
    2527using HeuristicLab.Scripting.Views;
    2628
    27 namespace HeuristicLab.Problems.Programmable.Views {
    28   [View("ProblemDefinitionScriptView")]
    29   [Content(typeof(ProblemDefinitionScript), IsDefaultView = true)]
    30   public partial class ProblemDefinitionScriptView : ScriptView {
     29namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Views {
     30  [View("LinearProgrammingProblemDefinitionScriptView")]
     31  [Content(typeof(LinearProgrammingProblemDefinitionScript), IsDefaultView = true)]
     32  public partial class LinearProgrammingProblemDefinitionScriptView : ScriptView {
    3133
    32     public new ProblemDefinitionScript Content {
    33       get { return (ProblemDefinitionScript)base.Content; }
    34       set { base.Content = value; }
     34    public new LinearProgrammingProblemDefinitionScript Content {
     35      get => (LinearProgrammingProblemDefinitionScript)base.Content;
     36      set => base.Content = value;
    3537    }
    3638
    37     public ProblemDefinitionScriptView() {
     39    public LinearProgrammingProblemDefinitionScriptView() {
    3840      InitializeComponent();
    3941    }
     
    4143    protected override void OnContentChanged() {
    4244      base.OnContentChanged();
    43       variableStoreView.Content = Content == null ? null : Content.VariableStore;
     45      variableStoreView.Content = Content?.VariableStore;
    4446    }
    4547
     
    5355        base.Compile();
    5456      } catch (ProblemDefinitionScriptException e) {
    55         PluginInfrastructure.ErrorHandling.ShowErrorDialog(e);
     57        ErrorHandling.ShowErrorDialog(e);
    5658        return false;
    5759      }
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Views/LinearProgrammingProblemView.Designer.cs

    r16138 r16172  
    2020#endregion
    2121
    22 namespace HeuristicLab.Problems.Programmable.Views {
    23   partial class SingleObjectiveProgrammableProblemView {
     22using System.ComponentModel;
     23
     24namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Views {
     25  partial class LinearProgrammingProblemView {
    2426    /// <summary>
    2527    /// Required designer variable.
    2628    /// </summary>
    27     private System.ComponentModel.IContainer components = null;
     29    private IContainer components = null;
    2830
    2931    /// <summary>
     
    4749      this.SuspendLayout();
    4850      //
    49       // ProgrammableProblemView
     51      // LinearProgrammingProblemView
    5052      //
    51       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    52       this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    53       this.Name = "ProgrammableProblemView";
    54       this.Size = new System.Drawing.Size(626, 413);
     53      this.Name = "LinearProgrammingProblemView";
     54      this.Load += new System.EventHandler(this.LinearProgrammingProblemView_Load);
    5555      this.ResumeLayout(false);
    5656
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Views/LinearProgrammingProblemView.cs

    r16138 r16172  
    2525using HeuristicLab.MainForm;
    2626using HeuristicLab.MainForm.WindowsForms;
     27using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
    2728
    28 namespace HeuristicLab.Problems.Programmable.Views {
    29   [View("Single-Objective Scriptable Problem View")]
    30   [Content(typeof(SingleObjectiveProgrammableProblem), true)]
    31   public partial class SingleObjectiveProgrammableProblemView : ItemView {
     29namespace HeuristicLab.MathematicalOptimization.LinearProgramming.Views {
     30  [View("Linear Programming Problem View")]
     31  [Content(typeof(LinearProgrammingProblem), true)]
     32  public partial class LinearProgrammingProblemView : ItemView {
    3233    protected ViewHost ScriptView;
    3334
    34     public new SingleObjectiveProgrammableProblem Content {
    35       get { return (SingleObjectiveProgrammableProblem)base.Content; }
    36       set { base.Content = value; }
     35    public new LinearProgrammingProblem Content {
     36      get => (LinearProgrammingProblem)base.Content;
     37      set => base.Content = value;
    3738    }
    3839
    39     public SingleObjectiveProgrammableProblemView() {
     40    public LinearProgrammingProblemView() {
    4041      InitializeComponent();
    41       ScriptView = new ViewHost() { ViewsLabelVisible = false, Dock = DockStyle.Fill };
     42      ScriptView = new ViewHost { ViewsLabelVisible = false, Dock = DockStyle.Fill };
    4243      Controls.Add(ScriptView);
    4344    }
     
    7273      Caption = Content.Name;
    7374    }
     75
     76    private void LinearProgrammingProblemView_Load(object sender, EventArgs e) {
     77
     78    }
    7479  }
    7580}
  • branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/Plugin.cs.frame

    r16070 r16172  
    2525  [Plugin("HeuristicLab.MathematicalOptimization", "Provides support for mathematical optimization based on Google OR-Tools", "3.3.15.$WCREV$")]
    2626  [PluginFile("HeuristicLab.MathematicalOptimization-3.3.dll", PluginFileType.Assembly)]
    27   [PluginDependency("HeuristicLab.OrTools", "6.8.0")]
     27  [PluginDependency("HeuristicLab.Core", "3.3")]
     28  [PluginDependency("HeuristicLab.Collections", "3.3")]
     29  [PluginDependency("HeuristicLab.Data", "3.3")]
     30  [PluginDependency("HeuristicLab.Optimization", "3.3")]
     31  [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")]
     32  [PluginDependency("HeuristicLab.Problems.Programmable", "3.3")]
     33  [PluginDependency("HeuristicLab.Scripting", "3.3")]
     34  [PluginDependency("HeuristicLab.OrTools", "6.9")]
    2835  public class HeuristicLabMathematicalOptimizationPlugin : PluginBase {
    2936  }
Note: See TracChangeset for help on using the changeset viewer.