diff options
| author | zhang <zch921005@126.com> | 2022-03-25 00:11:34 +0800 |
|---|---|---|
| committer | zhang <zch921005@126.com> | 2022-03-25 00:11:34 +0800 |
| commit | 3ed1c5d0e4018fc70012a6209a859a059f7127b5 (patch) | |
| tree | 2ca318fb2e23daf2964189a751fb61b20aa7515a /ordemo/polygon.py | |
| parent | 6f68e1818229e0d2dad760062e6b5bb137b88f5b (diff) | |
更新脚本
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 |
