Files
ortools-clone/cmake/samples/python/sample.py
Mizux Seiha e83cf08ce1 ci: Refactor CMake CI
* Update CMake doc
* Update Docker diagram
* Refactor CI Makefile
* Refactor and Fix <lang>.Dockerfile
* Refactor gh Docker CMake workflow
* gh CMake workflow disable fail-fast
* Remove manylinux
* Add Java samplei, generated using:
    $ mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
    -> com.google.ortools
    -> sample
  note: sample still not use ortools package yet
2020-04-15 15:22:41 +02:00

35 lines
1.0 KiB
Python

from ortools.linear_solver import pywraplp
from ortools.linear_solver import linear_solver_pb2
from ortools.constraint_solver import pywrapcp
from ortools.sat import pywrapsat
from ortools.graph import pywrapgraph
from ortools.algorithms import pywrapknapsack_solver
from ortools.data import pywraprcpsp
def lpsolver():
print('Test lpsolver...')
lpsolver = pywraplp.Solver(
'LinearTest',
pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
lpsolver.Solve()
print('Test lpsolver...DONE')
def cpsolver():
print('Test cpsolver...')
cpsolver = pywrapcp.Solver('ConstraintTest')
num_vals = 3
x = cpsolver.IntVar(0, num_vals - 1, "x")
y = cpsolver.IntVar(0, num_vals - 1, "y")
z = cpsolver.IntVar(0, num_vals - 1, "z")
cpsolver.Add(x != y)
db = cpsolver.Phase([x, y, z], cpsolver.CHOOSE_FIRST_UNBOUND, cpsolver.ASSIGN_MIN_VALUE)
cpsolver.Solve(db)
print('Test cpsolver...DONE')
def main():
lpsolver()
cpsolver()
if __name__ == "__main__":
main()