Free cookie consent management tool by TermsFeed Policy Generator

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

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

#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
File size: 2.1 KB
RevLine 
[16288]1using System;
2using System.Linq;
3using System.Collections.Generic;
4using Google.OrTools.LinearSolver;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
[11753]7using HeuristicLab.Data;
8using HeuristicLab.Optimization;
[16288]9using Variable = Google.OrTools.LinearSolver.Variable;
[11753]10
[16172]11namespace HeuristicLab.MathematicalOptimization.LinearProgramming {
[16233]12
[16172]13  public class CompiledLinearProgrammingProblemDefinition : CompiledProblemDefinition, ILinearProgrammingProblemDefinition {
14    private Variable x;
15    private Variable y;
[16373]16
[11753]17    public override void Initialize() {
[11880]18      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
19      // Add additional initialization code e.g. private variables that you need for evaluating
[11753]20    }
[16373]21
[16405]22    public void BuildModel(Solver solver) {
[11880]23      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
[16405]24      // How to define a model using Google OR-Tools: https://developers.google.com/optimization/introduction/cs
[16233]25      // Example model taken from https://developers.google.com/optimization/mip/integer_opt
[16172]26      // Define the decision variables
27      x = solver.MakeIntVar(0, 3.5, "x");
28      y = solver.MakeIntVar(0, double.PositiveInfinity, "y");
29      // Define the constraints
30      solver.Add(x + 7 * y <= 17.5);
31      // Define the objective
32      solver.Maximize(x + 10 * y);
[11753]33    }
[16373]34
[16172]35    public void Analyze(Solver solver, ResultCollection results) {
[11880]36      // Use vars.yourVariable to access variables in the variable store i.e. yourVariable
[16405]37      // Write or update results given the solution values of the decision variables
[16172]38      results.AddOrUpdateResult("x", new DoubleValue(x.SolutionValue()));
39      results.AddOrUpdateResult("y", new DoubleValue(y.SolutionValue()));
40      // The decision variables can also be retrieved from the solver
41      //results.AddOrUpdateResult("x", new DoubleValue(solver.LookupVariableOrNull("x").SolutionValue()));
42      //results.AddOrUpdateResult("y", new DoubleValue(solver.LookupVariableOrNull("y").SolutionValue()));
[11753]43    }
[16373]44
[11880]45    // Implement further classes and methods
[11753]46  }
[16288]47}
48
Note: See TracBrowser for help on using the repository browser.