Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExactOptimization/3.3/LinearProgramming/Templates/CompiledLinearProblemDefinition.cs @ 17915

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

#2931: solved the issues found during the review

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