Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16373 was 16373, checked in by ddorfmei, 5 years ago

#2931:

  • upgraded Google OR-Tools to version 6.10
  • added TextValue and TextValueView to be able to display and edit a multiline string
  • added parameter to set solver specific parameters for supported solvers
  • added support for the Protocol Buffers representation of models (import/export)
  • added import of MPS models
  • added pause/stop functionality to CplexSolver and GlpkSolver
  • refactored wrapper (LinearSolver and related enums)
  • added new algorithm category Exact for LinearProgrammingAlgorithm
File size: 2.1 KB
Line 
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using Google.OrTools.LinearSolver;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8using HeuristicLab.MathematicalOptimization.LinearProgramming.Problems;
9using HeuristicLab.Optimization;
10using HeuristicLab.Problems.Programmable;
11using Variable = Google.OrTools.LinearSolver.Variable;
12
13namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
14
15  public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILinearProgrammingProblemDefinition {
16    private Variable x;
17    private Variable y;
18
19    public override void Initialize() {
20      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
21      // Add additional initialization code e.g. private variables that you need for evaluating
22    }
23
24    public bool BuildModel(Solver solver) {
25      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
26      // Example model taken from https://developers.google.com/optimization/mip/integer_opt
27      // Define the decision variables
28      x = solver.MakeIntVar(0, 3.5, "x");
29      y = solver.MakeIntVar(0, double.PositiveInfinity, "y");
30      // Define the constraints
31      solver.Add(x + 7 * y <= 17.5);
32      // Define the objective
33      solver.Maximize(x + 10 * y);
34      return true;
35    }
36
37    public void Analyze(Solver solver, ResultCollection results) {
38      // 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
40      results.AddOrUpdateResult("x", new DoubleValue(x.SolutionValue()));
41      results.AddOrUpdateResult("y", new DoubleValue(y.SolutionValue()));
42      // The decision variables can also be retrieved from the solver
43      //results.AddOrUpdateResult("x", new DoubleValue(solver.LookupVariableOrNull("x").SolutionValue()));
44      //results.AddOrUpdateResult("y", new DoubleValue(solver.LookupVariableOrNull("y").SolutionValue()));
45    }
46
47    // Implement further classes and methods
48  }
49}
50
Note: See TracBrowser for help on using the repository browser.