Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2931_OR-Tools_LP_MIP/HeuristicLab.MathematicalOptimization/3.3/LinearProgramming/Templates/CompiledLinearProgrammingProblemDefinition.cs @ 16172

Last change on this file since 16172 was 16172, checked in by ddorfmei, 6 years ago

#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
File size: 1.9 KB
Line 
1using Google.OrTools.LinearSolver;
2using HeuristicLab.Data;
3using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
4using HeuristicLab.Optimization;
5using HeuristicLab.Problems.Programmable;
6
7namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
8  public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILinearProgrammingProblemDefinition {
9
10    private Variable x;
11    private Variable y;
12
13    public override void Initialize() {
14      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
15      // Add additional initialization code e.g. private variables that you need for evaluating
16    }
17
18    public void BuildModel(Solver solver) {
19      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
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);
28    }
29
30    public void Analyze(Solver solver, ResultCollection results) {
31      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
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()));
38    }
39
40    // Implement further classes and methods
41  }
42}
Note: See TracBrowser for help on using the repository browser.