diff options
Diffstat (limited to 'ordemo/polygon.py')
| -rw-r--r-- | ordemo/polygon.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ordemo/polygon.py b/ordemo/polygon.py new file mode 100644 index 0000000..6a157f4 --- /dev/null +++ b/ordemo/polygon.py @@ -0,0 +1,45 @@ +from ortools.linear_solver import pywraplp + + +def main(): + # Create the mip solver with the SCIP backend. + solver = pywraplp.Solver.CreateSolver('SCIP') + + infinity = solver.infinity() + # x and y are integer non-negative variables. + x = solver.IntVar(3, infinity, 'x') + y = solver.IntVar(0, infinity, 'y') + t = solver.IntVar(0, infinity, 't') + + print('Number of variables =', solver.NumVariables()) + + solver.Add(t == x-2) + # x + 7 * y <= 17.5. + solver.Add(y == 2*x/t) + + # x <= 3.5. + # solver.Add(x <= 3.5) + + print('Number of constraints =', solver.NumConstraints()) + + # Maximize x + 10 * y. + solver.Maximize(0) + + status = solver.Solve() + + if status == pywraplp.Solver.OPTIMAL: + print('Solution:') + print('Objective value =', solver.Objective().Value()) + print('x =', x.solution_value()) + print('y =', y.solution_value()) + else: + print('The problem does not have an optimal solution.') + + print('\nAdvanced usage:') + print('Problem solved in %f milliseconds' % solver.wall_time()) + print('Problem solved in %d iterations' % solver.iterations()) + print('Problem solved in %d branch-and-bound nodes' % solver.nodes()) + + +if __name__ == '__main__': + main()
\ No newline at end of file |
