mostly reindent of examples

This commit is contained in:
Laurent Perron
2019-05-06 10:31:03 +02:00
parent 9b8a26beee
commit cd6bf20fe5
10 changed files with 77 additions and 91 deletions

View File

@@ -32,8 +32,8 @@ def build_pairs(rows, cols):
cols: the number of columns in the grid
"""
return [
(x * cols + y, (x + dx) * cols + (y + dy))
for x in range(rows) for y in range(cols) for dx in (-1, 0, 1)
(x * cols + y, (x + dx) * cols + (y + dy)) for x in range(rows)
for y in range(cols) for dx in (-1, 0, 1)
for dy in (-1, 0, 1)
if (x + dx >= 0 and x + dx < rows and y + dy >= 0 and y + dy < cols and
(dx != 0 or dy != 0))

View File

@@ -12,6 +12,8 @@
# limitations under the License.
"""Integer programming examples that show how to use the APIs."""
from __future__ import print_function
from ortools.linear_solver import pywraplp
@@ -54,8 +56,8 @@ def RunIntegerExampleCppStyleAPI(optimization_problem_type):
def SolveAndPrint(solver, variable_list):
"""Solve the problem and print the solution."""
print(('Number of variables = %d' % solver.NumVariables()))
print(('Number of constraints = %d' % solver.NumConstraints()))
print('Number of variables = %d' % solver.NumVariables())
print('Number of constraints = %d' % solver.NumConstraints())
result_status = solver.Solve()
@@ -66,22 +68,22 @@ def SolveAndPrint(solver, variable_list):
# GLOP_LINEAR_PROGRAMMING, verifying the solution is highly recommended!).
assert solver.VerifySolution(1e-7, True)
print(('Problem solved in %f milliseconds' % solver.wall_time()))
print('Problem solved in %f milliseconds' % solver.wall_time())
# The objective value of the solution.
print(('Optimal objective value = %f' % solver.Objective().Value()))
print('Optimal objective value = %f' % solver.Objective().Value())
# The value of each variable in the solution.
for variable in variable_list:
print(('%s = %f' % (variable.name(), variable.solution_value())))
print('%s = %f' % (variable.name(), variable.solution_value()))
print('Advanced usage:')
print(('Problem solved in %d branch-and-bound nodes' % solver.nodes()))
print('Problem solved in %d branch-and-bound nodes' % solver.nodes())
def Announce(solver, api_type):
print(('---- Integer programming example with ' + solver + ' (' + api_type +
') -----'))
print('---- Integer programming example with ' + solver + ' (' + api_type +
') -----')
def RunAllIntegerExampleNaturalLanguageAPI():