2022-10-05 15:56:33 +02:00
|
|
|
#!/usr/bin/env python3
|
2025-01-10 11:35:44 +01:00
|
|
|
# Copyright 2010-2025 Google LLC
|
2022-10-05 15:56:33 +02:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
2022-09-30 18:08:44 +02:00
|
|
|
"""Sample to test or-tools installation."""
|
2025-07-23 15:07:49 +02:00
|
|
|
|
2022-04-11 18:04:49 +02:00
|
|
|
import ortools
|
2025-06-16 11:47:36 +02:00
|
|
|
|
2023-07-03 12:46:51 +02:00
|
|
|
# from ortools.algorithms import knapsack_solver
|
2020-04-01 14:27:33 +02:00
|
|
|
from ortools.constraint_solver import pywrapcp
|
2025-06-16 11:47:36 +02:00
|
|
|
|
2022-09-30 18:08:44 +02:00
|
|
|
# from ortools.graph.python import linear_sum_assignment
|
|
|
|
|
# from ortools.graph.python import max_flow
|
|
|
|
|
# from ortools.graph.python import min_cost_flow
|
|
|
|
|
from ortools.linear_solver import pywraplp
|
2025-06-16 11:47:36 +02:00
|
|
|
|
2022-09-30 18:08:44 +02:00
|
|
|
# from ortools.linear_solver import linear_solver_pb2
|
2025-01-15 13:51:40 +01:00
|
|
|
# from ortools.sat.python import cp_model_helper
|
2022-09-30 18:08:44 +02:00
|
|
|
# from ortools.sat.python import cp_model
|
2023-07-03 12:46:51 +02:00
|
|
|
# from ortools.scheduling import rcpsp
|
2022-09-30 18:08:44 +02:00
|
|
|
# from ortools.util.python import sorted_interval_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lpsolver_test():
|
2025-06-16 11:47:36 +02:00
|
|
|
"""Test pywraplp."""
|
|
|
|
|
print("Test lpsolver...")
|
|
|
|
|
lpsolver = pywraplp.Solver("LinearTest", pywraplp.Solver.GLOP_LINEAR_PROGRAMMING)
|
|
|
|
|
lpsolver.Solve()
|
|
|
|
|
print("Test lpsolver...DONE")
|
2022-09-30 18:08:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def cpsolver_test():
|
2025-06-16 11:47:36 +02:00
|
|
|
"""Test pywrapcp."""
|
|
|
|
|
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")
|
2022-09-30 18:08:44 +02:00
|
|
|
|
2020-04-01 14:27:33 +02:00
|
|
|
|
|
|
|
|
def main():
|
2025-06-16 11:47:36 +02:00
|
|
|
print(ortools.__version__)
|
|
|
|
|
lpsolver_test()
|
|
|
|
|
cpsolver_test()
|
2022-09-30 18:08:44 +02:00
|
|
|
|
2020-04-01 14:27:33 +02:00
|
|
|
|
2025-06-16 11:47:36 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|