Apply yapf on examples/python/*.py

This commit is contained in:
Corentin Le Molgat
2018-11-28 10:56:33 +01:00
parent f2573d33b1
commit c2ae098d34
39 changed files with 1168 additions and 1408 deletions

View File

@@ -133,11 +133,10 @@ def get_optimal_schedule(demand, args):
"""Computes the optimal schedule for the appointment selection problem."""
combinations = find_combinations([a[2] for a in demand], args.load_min,
args.load_max, args.commute_time)
print(
'found %d possible combinations of appointements' % len(combinations))
print('found %d possible combinations of appointements' % len(combinations))
cost, selection = select(combinations, [a[0] for a in demand],
args.num_workers)
cost, selection = select(combinations, [a[0]
for a in demand], args.num_workers)
output = [(selection[i], [(combinations[i][t], demand[t][1])
for t in range(len(demand))
if combinations[i][t] != 0])
@@ -152,8 +151,7 @@ def main(args):
for a in demand:
print(' %d * %s : %d min' % (a[0], a[1], a[2]))
print('commute time = %d' % args.commute_time)
print(
'accepted total duration = [%d..%d]' % (args.load_min, args.load_max))
print('accepted total duration = [%d..%d]' % (args.load_min, args.load_max))
print('%d workers' % args.num_workers)
cost, selection = get_optimal_schedule(demand, args)
print('Optimal solution as a cost of %d' % cost)

View File

@@ -17,16 +17,15 @@ from ortools.sat.python import cp_model
def main():
# Instantiate a cp model.
cost = [[90, 76, 75, 70, 50, 74, 12,
68], [35, 85, 55, 65, 48, 101, 70, 83],
[125, 95, 90, 105, 59, 120, 36, 73],
[45, 110, 95, 115, 104, 83, 37, 71],
[60, 105, 80, 75, 59, 62, 93,
88], [45, 65, 110, 95, 47, 31, 81, 34],
[38, 51, 107, 41, 69, 99, 115, 48],
[47, 85, 57, 71, 92, 77, 109, 36],
[39, 63, 97, 49, 118, 56, 92, 61],
[47, 101, 71, 60, 88, 109, 52, 90]]
cost = [[90, 76, 75, 70, 50, 74, 12, 68], [35, 85, 55, 65, 48, 101, 70, 83],
[125, 95, 90, 105, 59,
120, 36, 73], [45, 110, 95, 115, 104, 83, 37,
71], [60, 105, 80, 75, 59, 62, 93,
88], [45, 65, 110, 95, 47, 31, 81, 34],
[38, 51, 107, 41, 69, 99, 115,
48], [47, 85, 57, 71, 92, 77, 109,
36], [39, 63, 97, 49, 118, 56,
92, 61], [47, 101, 71, 60, 88, 109, 52, 90]]
sizes = [10, 7, 3, 12, 15, 4, 11, 5]
total_size_max = 15
@@ -55,8 +54,8 @@ def main():
model.Add(sum(sizes[j] * x[i][j] for j in all_tasks) <= total_size_max)
# Total cost
model.Add(total_cost == sum(
x[i][j] * cost[i][j] for j in all_tasks for i in all_workers))
model.Add(total_cost == sum(x[i][j] * cost[i][j]
for j in all_tasks for i in all_workers))
model.Minimize(total_cost)
solver = cp_model.CpSolver()

View File

@@ -20,12 +20,14 @@ from ortools.sat.python import cp_model
def solve_assignment():
"""Solve the assignment problem."""
# Data.
cost = [[90, 76, 75, 70, 50, 74], [35, 85, 55, 65, 48, 101],
[125, 95, 90, 105, 59, 120], [45, 110, 95, 115, 104, 83],
[60, 105, 80, 75, 59, 62], [45, 65, 110, 95, 47, 31],
[38, 51, 107, 41, 69, 99], [47, 85, 57, 71, 92, 77],
[39, 63, 97, 49, 118, 56], [47, 101, 71, 60, 88, 109],
[17, 39, 103, 64, 61, 92], [101, 45, 83, 59, 92, 27]]
cost = [[90, 76, 75, 70, 50, 74], [35, 85, 55, 65, 48,
101], [125, 95, 90, 105, 59, 120],
[45, 110, 95, 115, 104, 83], [60, 105, 80, 75, 59, 62], [
45, 65, 110, 95, 47, 31
], [38, 51, 107, 41, 69, 99], [47, 85, 57, 71,
92, 77], [39, 63, 97, 49, 118, 56],
[47, 101, 71, 60, 88, 109], [17, 39, 103, 64, 61,
92], [101, 45, 83, 59, 92, 27]]
group1 = [
[0, 0, 1, 1], # Workers 2, 3
@@ -79,8 +81,7 @@ def solve_assignment():
# Total task size for each worker is at most total_size_max
for i in all_workers:
model.Add(
sum(sizes[j] * selected[i][j]
for j in all_tasks) <= total_size_max)
sum(sizes[j] * selected[i][j] for j in all_tasks) <= total_size_max)
# Group constraints.
model.AddAllowedAssignments([works[0], works[1], works[2], works[3]],

View File

@@ -102,8 +102,8 @@ def main():
item_in_group = {}
for i in all_items:
for g in all_groups:
item_in_group[(i, g)] = model.NewBoolVar(
'item %d in group %d' % (i, g))
item_in_group[(i, g)] = model.NewBoolVar('item %d in group %d' %
(i, g))
# Each group must have the same size.
for g in all_groups:

View File

@@ -30,9 +30,9 @@ max_quantities = [["N_Total", 1944], ["P2O5", 1166.4], ["K2O", 1822.5],
["CaO", 1458], ["MgO", 486], ["Fe", 9.7], ["B", 2.4]]
chemical_set = [["A", 0, 0, 510, 540, 0, 0, 0], ["B", 110, 0, 0, 0, 160, 0, 0],
["C", 61, 149, 384, 0, 30, 1, 0.2],
["D", 148, 70, 245, 0, 15, 1, 0.2],
["E", 160, 158, 161, 0, 10, 1, 0.2]]
["C", 61, 149, 384, 0, 30, 1,
0.2], ["D", 148, 70, 245, 0, 15, 1,
0.2], ["E", 160, 158, 161, 0, 10, 1, 0.2]]
num_products = len(max_quantities)
all_products = range(num_products)
@@ -87,6 +87,6 @@ for s in all_sets:
for p in all_products:
name = max_quantities[p][0]
max_quantity = max_quantities[p][1]
quantity = sum(set_vars[s].solution_value() * chemical_set[s][p + 1]
for s in all_sets)
quantity = sum(
set_vars[s].solution_value() * chemical_set[s][p + 1] for s in all_sets)
print("%s: %f out of %f" % (name, quantity, max_quantity))

View File

@@ -29,9 +29,9 @@ max_quantities = [["N_Total", 1944], ["P2O5", 1166.4], ["K2O", 1822.5],
["CaO", 1458], ["MgO", 486], ["Fe", 9.7], ["B", 2.4]]
chemical_set = [["A", 0, 0, 510, 540, 0, 0, 0], ["B", 110, 0, 0, 0, 160, 0, 0],
["C", 61, 149, 384, 0, 30, 1, 0.2],
["D", 148, 70, 245, 0, 15, 1, 0.2],
["E", 160, 158, 161, 0, 10, 1, 0.2]]
["C", 61, 149, 384, 0, 30, 1,
0.2], ["D", 148, 70, 245, 0, 15, 1,
0.2], ["E", 160, 158, 161, 0, 10, 1, 0.2]]
num_products = len(max_quantities)
all_products = range(num_products)

View File

@@ -76,8 +76,8 @@ def create_data_model():
#######################
def manhattan_distance(position_1, position_2):
"""Computes the Manhattan distance between two points"""
return (abs(position_1[0] - position_2[0]) +
abs(position_1[1] - position_2[1]))
return (
abs(position_1[0] - position_2[0]) + abs(position_1[1] - position_2[1]))
def create_distance_evaluator(data):

View File

@@ -114,8 +114,8 @@ def create_data_model():
#######################
def manhattan_distance(position_1, position_2):
"""Computes the Manhattan distance between two points"""
return (abs(position_1[0] - position_2[0]) +
abs(position_1[1] - position_2[1]))
return (
abs(position_1[0] - position_2[0]) + abs(position_1[1] - position_2[1]))
def create_distance_evaluator(data):
@@ -198,9 +198,8 @@ def create_time_evaluator(data):
if from_node == to_node:
travel_time = 0
else:
travel_time = manhattan_distance(
data['locations'][from_node],
data['locations'][to_node]) / data['vehicle_speed']
travel_time = manhattan_distance(data['locations'][from_node], data[
'locations'][to_node]) / data['vehicle_speed']
return travel_time
_total_time = {}
@@ -212,8 +211,8 @@ def create_time_evaluator(data):
_total_time[from_node][to_node] = 0
else:
_total_time[from_node][to_node] = int(
service_time(data, from_node) +
travel_time(data, from_node, to_node))
service_time(data, from_node) + travel_time(
data, from_node, to_node))
def time_evaluator(manager, from_node, to_node):
"""Returns the total time between the two nodes"""
@@ -279,7 +278,8 @@ def print_solution(data, manager, routing, assignment): # pylint:disable=too-ma
load_var = capacity_dimension.CumulVar(index)
time_var = time_dimension.CumulVar(index)
plan_output += ' {0} Load({1}) Time({2},{3}) ->'.format(
manager.IndexToNode(index), assignment.Value(load_var),
manager.IndexToNode(index),
assignment.Value(load_var),
assignment.Min(time_var), assignment.Max(time_var))
previous_index = index
index = assignment.Value(routing.NextVar(index))
@@ -288,7 +288,8 @@ def print_solution(data, manager, routing, assignment): # pylint:disable=too-ma
load_var = capacity_dimension.CumulVar(index)
time_var = time_dimension.CumulVar(index)
plan_output += ' {0} Load({1}) Time({2},{3})\n'.format(
manager.IndexToNode(index), assignment.Value(load_var),
manager.IndexToNode(index),
assignment.Value(load_var),
assignment.Min(time_var), assignment.Max(time_var))
plan_output += 'Distance of the route: {}m\n'.format(distance)
plan_output += 'Load of the route: {}\n'.format(

View File

@@ -88,8 +88,8 @@ def create_data_model():
#######################
def manhattan_distance(position_1, position_2):
"""Computes the Manhattan distance between two points"""
return (abs(position_1[0] - position_2[0]) +
abs(position_1[1] - position_2[1]))
return (
abs(position_1[0] - position_2[0]) + abs(position_1[1] - position_2[1]))
def create_distance_evaluator(data):
@@ -147,9 +147,8 @@ def create_time_evaluator(data):
if from_node == to_node:
travel_time = 0
else:
travel_time = manhattan_distance(
data['locations'][from_node],
data['locations'][to_node]) / data['vehicle_speed']
travel_time = manhattan_distance(data['locations'][from_node], data[
'locations'][to_node]) / data['vehicle_speed']
return travel_time
_total_time = {}
@@ -161,8 +160,8 @@ def create_time_evaluator(data):
_total_time[from_node][to_node] = 0
else:
_total_time[from_node][to_node] = int(
service_time(data, from_node) +
travel_time(data, from_node, to_node))
service_time(data, from_node) + travel_time(
data, from_node, to_node))
def time_evaluator(manager, from_node, to_node):
"""Returns the total time between the two nodes"""
@@ -222,8 +221,10 @@ def print_solution(data, manager, routing, assignment): # pylint:disable=too-ma
time_var = time_dimension.CumulVar(index)
slack_var = time_dimension.SlackVar(index)
plan_output += ' {0} Load({1}) Time({2},{3}) Slack({4},{5}) ->'.format(
manager.IndexToNode(index), assignment.Value(load_var),
assignment.Min(time_var), assignment.Max(time_var),
manager.IndexToNode(index),
assignment.Value(load_var),
assignment.Min(time_var),
assignment.Max(time_var),
assignment.Min(slack_var), assignment.Max(slack_var))
previous_index = index
index = assignment.Value(routing.NextVar(index))
@@ -233,7 +234,8 @@ def print_solution(data, manager, routing, assignment): # pylint:disable=too-ma
time_var = time_dimension.CumulVar(index)
slack_var = time_dimension.SlackVar(index)
plan_output += ' {0} Load({1}) Time({2},{3})\n'.format(
manager.IndexToNode(index), assignment.Value(load_var),
manager.IndexToNode(index),
assignment.Value(load_var),
assignment.Min(time_var), assignment.Max(time_var))
plan_output += 'Distance of the route: {0}m\n'.format(distance)
plan_output += 'Load of the route: {}\n'.format(

View File

@@ -92,10 +92,10 @@ class Customers():
self.extents = extents #: The lower left and upper right points
#: Location[lat,lon]: the centre point of the area.
self.center = Location(
extents['urcrnrlat'] -
0.5 * (extents['urcrnrlat'] - extents['llcrnrlat']),
extents['urcrnrlon'] -
0.5 * (extents['urcrnrlon'] - extents['llcrnrlon']))
extents['urcrnrlat'] - 0.5 *
(extents['urcrnrlat'] - extents['llcrnrlat']),
extents['urcrnrlon'] - 0.5 *
(extents['urcrnrlon'] - extents['llcrnrlon']))
else:
#: Location[lat,lon]: the centre point of the area.
(clat, clon) = self.center = Location(center[0], center[1])
@@ -103,14 +103,12 @@ class Customers():
circ_earth = np.pi * rad_earth
#: The lower left and upper right points
self.extents = {
'llcrnrlon':
(clon -
180 * box_size / (circ_earth * np.cos(np.deg2rad(clat)))),
'llcrnrlon': (clon - 180 * box_size /
(circ_earth * np.cos(np.deg2rad(clat)))),
'llcrnrlat':
clat - 180 * box_size / circ_earth,
'urcrnrlon':
(clon +
180 * box_size / (circ_earth * np.cos(np.deg2rad(clat)))),
'urcrnrlon': (clon + 180 * box_size /
(circ_earth * np.cos(np.deg2rad(clat)))),
'urcrnrlat':
clat + 180 * box_size / circ_earth
}

View File

@@ -38,9 +38,9 @@ def flexible_jobshop():
jobs = [[[(3, 0), (1, 1), (5, 2)], [(2, 0), (4, 1), (6, 2)],
[(2, 0), (3, 1), (1, 2)]],
[[(2, 0), (3, 1), (4, 2)], [(1, 0), (5, 1), (4, 2)],
[(2, 0), (1, 1), (4, 2)]],
[[(2, 0), (1, 1), (4, 2)], [(2, 0), (3, 1), (4, 2)],
[(3, 0), (1, 1), (5, 2)]]]
[(2, 0), (1, 1), (4, 2)]], [[(2, 0), (1, 1),
(4, 2)], [(2, 0), (3, 1), (4, 2)],
[(3, 0), (1, 1), (5, 2)]]]
num_jobs = len(jobs)
all_jobs = range(num_jobs)

View File

@@ -51,8 +51,7 @@ def main():
start = model.NewIntVar(0, horizon, 'start_%i' % i)
duration = jobs[i][0]
end = model.NewIntVar(0, horizon, 'end_%i' % i)
interval = model.NewIntervalVar(start, duration, end,
'interval_%i' % i)
interval = model.NewIntervalVar(start, duration, end, 'interval_%i' % i)
starts.append(start)
intervals.append(interval)
ends.append(end)
@@ -114,8 +113,7 @@ def main():
d_y = jobs[i][1]
s_y = performed_machine * (max_length - d_y)
output.AddRectangle(start, s_y, d_x, d_y,
color_manager.RandomColor(), 'black',
'j%i' % i)
color_manager.RandomColor(), 'black', 'j%i' % i)
output.AddXScale()
output.AddYScale()
@@ -126,8 +124,8 @@ def main():
for i in all_jobs:
performed_machine = 1 - solver.Value(performed[i])
start = solver.Value(starts[i])
print(' - Job %i starts at %i on machine %i' %
(i, start, performed_machine))
print(' - Job %i starts at %i on machine %i' % (i, start,
performed_machine))
print('Statistics')
print(' - conflicts : %i' % solver.NumConflicts())
print(' - branches : %i' % solver.NumBranches())

View File

@@ -42,8 +42,8 @@ def main():
solver.Add(marks[0] == 0)
solver.Add(
solver.AllDifferent([
marks[j] - marks[i] for i in range(0, size - 1)
for j in range(i + 1, size)
marks[j] - marks[i]
for i in range(0, size - 1) for j in range(i + 1, size)
]))
solver.Add(marks[size - 1] - marks[size - 2] > marks[1] - marks[0])

View File

@@ -31,10 +31,13 @@ def build_pairs(rows, cols):
rows: the number of rows in the grid
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) 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))]
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)
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))
]
def print_solution(positions, rows, cols):
@@ -80,8 +83,8 @@ def build_puzzle(problem):
elif problem == 2:
puzzle = [[0, 44, 41, 0, 0, 0, 0], [0, 43, 0, 28, 29, 0, 0],
[0, 1, 0, 0, 0, 33, 0], [0, 2, 25, 4, 34, 0, 36],
[49, 16, 0, 23, 0, 0, 0], [0, 19, 0, 0, 12, 7, 0],
[0, 0, 0, 14, 0, 0, 0]]
[49, 16, 0, 23, 0, 0, 0], [0, 19, 0, 0, 12, 7,
0], [0, 0, 0, 14, 0, 0, 0]]
elif problem == 3:
# Problems from the book:
@@ -103,9 +106,10 @@ def build_puzzle(problem):
elif problem == 6:
# Problem 15 (Intermediate)
puzzle = [[64, 0, 0, 0, 0, 0, 0, 0], [1, 63, 0, 59, 15, 57, 53, 0],
[0, 4, 0, 14, 0, 0, 0, 0], [3, 0, 11, 0, 20, 19, 0, 50],
[0, 0, 0, 0, 22, 0, 48, 40], [9, 0, 0, 32, 23, 0, 0, 41],
[27, 0, 0, 0, 36, 0, 46, 0], [28, 30, 0, 35, 0, 0, 0, 0]]
[0, 4, 0, 14, 0, 0, 0, 0], [3, 0, 11, 0, 20, 19, 0,
50], [0, 0, 0, 0, 22, 0, 48, 40],
[9, 0, 0, 32, 23, 0, 0, 41], [27, 0, 0, 0, 36, 0, 46,
0], [28, 30, 0, 35, 0, 0, 0, 0]]
return puzzle
@@ -168,8 +172,8 @@ def solve_hidato(puzzle, index):
output.AddRectangle(x, r - y - 1, 1, 1, color, 'black',
str(i + 1))
output.AddTitle(
'Puzzle %i solved in %f s' % (index, solver.WallTime()))
output.AddTitle('Puzzle %i solved in %f s' % (index,
solver.WallTime()))
output.Display()
else:
print_solution(

View File

@@ -80,8 +80,8 @@ def SolveAndPrint(solver, variable_list):
def Announce(solver, api_type):
print(('---- Integer programming example with ' + solver + ' (' + api_type
+ ') -----'))
print(('---- Integer programming example with ' + solver + ' (' + api_type +
') -----'))
def RunAllIntegerExampleNaturalLanguageAPI():

View File

@@ -102,8 +102,8 @@ def jobshop_ft06_distance():
# We add the reified precedence to link the literal with the
# times of the two tasks.
min_distance = distance_between_jobs(j1, j2)
model.Add(job_starts[j2] >= job_ends[j1] +
min_distance).OnlyEnforceIf(lit)
model.Add(job_starts[j2] >=
job_ends[j1] + min_distance).OnlyEnforceIf(lit)
model.AddCircuit(arcs)

View File

@@ -21,23 +21,23 @@ def main():
pywrapknapsack_solver.KnapsackSolver.
KNAPSACK_MULTIDIMENSION_BRANCH_AND_BOUND_SOLVER, 'test')
profits = [
360, 83, 59, 130, 431, 67, 230, 52, 93, 125, 670, 892, 600, 38, 48,
147, 78, 256, 63, 17, 120, 164, 432, 35, 92, 110, 22, 42, 50, 323, 514,
28, 87, 73, 78, 15, 26, 78, 210, 36, 85, 189, 274, 43, 33, 10, 19, 389,
276, 312
360, 83, 59, 130, 431, 67, 230, 52, 93, 125, 670, 892, 600, 38, 48, 147,
78, 256, 63, 17, 120, 164, 432, 35, 92, 110, 22, 42, 50, 323, 514, 28,
87, 73, 78, 15, 26, 78, 210, 36, 85, 189, 274, 43, 33, 10, 19, 389, 276,
312
]
weights = [[
7, 0, 30, 22, 80, 94, 11, 81, 70, 64, 59, 18, 0, 36, 3, 8, 15, 42, 9,
0, 42, 47, 52, 32, 26, 48, 55, 6, 29, 84, 2, 4, 18, 56, 7, 29, 93, 44,
71, 3, 86, 66, 31, 65, 0, 79, 20, 65, 52, 13
7, 0, 30, 22, 80, 94, 11, 81, 70, 64, 59, 18, 0, 36, 3, 8, 15, 42, 9, 0,
42, 47, 52, 32, 26, 48, 55, 6, 29, 84, 2, 4, 18, 56, 7, 29, 93, 44, 71,
3, 86, 66, 31, 65, 0, 79, 20, 65, 52, 13
]]
capacities = [850]
optimal_profit = 7534
solver.Init(profits, weights, capacities)
computed_profit = solver.Solve()
print(('optimal profit = ' + str(computed_profit) + '/' +
str(optimal_profit)))
print((
'optimal profit = ' + str(computed_profit) + '/' + str(optimal_profit)))
if __name__ == '__main__':

View File

@@ -46,8 +46,7 @@ def RunAssignmentOn4x4Matrix():
print('No perfect matching exists.')
elif solve_status == assignment.POSSIBLE_OVERFLOW:
print(
'Some input costs are too large and may cause an integer overflow.'
)
'Some input costs are too large and may cause an integer overflow.')
def main():

View File

@@ -70,12 +70,15 @@ def main():
print('x: reduced cost =', x.reduced_cost())
print('y: reduced cost =', y.reduced_cost())
activities = solver.ComputeConstraintActivities()
print('constraint0: dual value =', constraint0.dual_value(),
' activities =', activities[constraint0.index()])
print('constraint1: dual value =', constraint1.dual_value(),
' activities =', activities[constraint1.index()])
print('constraint2: dual value =', constraint2.dual_value(),
' activities =', activities[constraint2.index()])
print('constraint0: dual value =',
constraint0.dual_value(), ' activities =',
activities[constraint0.index()])
print('constraint1: dual value =',
constraint1.dual_value(), ' activities =',
activities[constraint1.index()])
print('constraint2: dual value =',
constraint2.dual_value(), ' activities =',
activities[constraint2.index()])
if __name__ == '__main__':

View File

@@ -53,8 +53,7 @@ def main(board_size):
# Creates the variables.
# The array index is the column, and the value is the row.
queens = [
model.NewIntVar(0, board_size - 1, 'x%i' % i)
for i in range(board_size)
model.NewIntVar(0, board_size - 1, 'x%i' % i) for i in range(board_size)
]
# Creates the constraints.

View File

@@ -63,8 +63,8 @@ def main():
for n in all_nurses:
for d in all_days:
for s in all_shifts:
shifts[(n, d,
s)] = model.NewBoolVar('shift_n%id%is%i' % (n, d, s))
shifts[(n, d, s)] = model.NewBoolVar('shift_n%id%is%i' % (n, d,
s))
# Makes assignments different on each day, that is each shift is assigned at
# most one nurse. As we have the same number of nurses and shifts, then each
@@ -88,8 +88,8 @@ def main():
works_shift = {}
for n in all_nurses:
for s in all_shifts:
works_shift[(n,
s)] = model.NewBoolVar('works_shift_n%is%i' % (n, s))
works_shift[(n, s)] = model.NewBoolVar('works_shift_n%is%i' % (n,
s))
model.AddMaxEquality(works_shift[(n, s)],
[shifts[(n, d, s)] for d in all_days])

View File

@@ -63,9 +63,10 @@ def MinCostFlow():
print('Total flow', min_cost_flow.OptimalCost(), '/', expected_cost)
for i in range(0, min_cost_flow.NumArcs()):
if min_cost_flow.Flow(i) > 0:
print('From source %d to target %d: cost %d' % (
min_cost_flow.Tail(i), min_cost_flow.Head(i) - num_sources,
min_cost_flow.UnitCost(i)))
print('From source %d to target %d: cost %d' %
(min_cost_flow.Tail(i),
min_cost_flow.Head(i) - num_sources,
min_cost_flow.UnitCost(i)))
else:
print('There was an issue with the min cost flow input.')

File diff suppressed because it is too large Load Diff

View File

@@ -80,8 +80,8 @@ class RandomMatrix(object):
distance_max)
def Distance(self, manager, from_index, to_index):
return self.matrix[manager.IndexToNode(from_index)][
manager.IndexToNode(to_index)]
return self.matrix[manager.IndexToNode(from_index)][manager.IndexToNode(
to_index)]
def main(args):

View File

@@ -81,8 +81,7 @@ def solve_rcpsp(problem, proto_file, params):
horizon = problem.deadline if problem.deadline != -1 else problem.horizon
if horizon == -1: # Naive computation.
horizon = sum(
max(r.duration for r in t.recipes) for t in problem.tasks)
horizon = sum(max(r.duration for r in t.recipes) for t in problem.tasks)
if problem.is_rcpsp_max:
for t in problem.tasks:
for sd in t.successor_delays:
@@ -116,8 +115,7 @@ def solve_rcpsp(problem, proto_file, params):
if len(task.recipes) == 1:
# Create interval.
recipe = task.recipes[0]
task_starts[t] = model.NewIntVar(0, horizon,
'start_of_task_%i' % t)
task_starts[t] = model.NewIntVar(0, horizon, 'start_of_task_%i' % t)
task_ends[t] = model.NewIntVar(0, horizon, 'end_of_task_%i' % t)
interval = model.NewIntervalVar(task_starts[t], recipe.duration,
task_ends[t], 'interval_%i' % t)
@@ -173,8 +171,7 @@ def solve_rcpsp(problem, proto_file, params):
presences_per_resource[res].append(is_present)
# Create the master interval for the task.
task_starts[t] = model.NewIntVar(0, horizon,
'start_of_task_%i' % t)
task_starts[t] = model.NewIntVar(0, horizon, 'start_of_task_%i' % t)
task_ends[t] = model.NewIntVar(0, horizon, 'end_of_task_%i' % t)
duration = model.NewIntVar(min_size, max_size,
'duration_of_task_%i' % t)
@@ -187,8 +184,7 @@ def solve_rcpsp(problem, proto_file, params):
model.Add(
task_starts[t] == starts_per_task[t][r]).OnlyEnforceIf(p)
model.Add(task_ends[t] == ends_per_task[t][r]).OnlyEnforceIf(p)
model.Add(
duration == task.recipes[r].duration).OnlyEnforceIf(p)
model.Add(duration == task.recipes[r].duration).OnlyEnforceIf(p)
model.Add(sum(presences_per_task[t]) == 1)
# Create makespan variable
@@ -261,9 +257,8 @@ def solve_rcpsp(problem, proto_file, params):
# Objective.
if problem.is_resource_investment:
objective = model.NewIntVar(0, max_cost, 'capacity_costs')
model.Add(objective == sum(
problem.resources[i].unit_cost * capacities[i]
for i in range(len(capacities))))
model.Add(objective == sum(problem.resources[i].unit_cost * capacities[
i] for i in range(len(capacities))))
else:
objective = makespan

View File

@@ -308,8 +308,8 @@ def solve_shift_scheduling(params, output_proto):
works = [work[e, shift, d] for d in range(num_days)]
variables, coeffs = add_soft_sequence_constraint(
model, works, hard_min, soft_min, min_cost, soft_max, hard_max,
max_cost,
'shift_constraint(employee %i, shift %i)' % (e, shift))
max_cost, 'shift_constraint(employee %i, shift %i)' % (e,
shift))
obj_bool_vars.extend(variables)
obj_bool_coeffs.extend(coeffs)
@@ -367,9 +367,9 @@ def solve_shift_scheduling(params, output_proto):
# Objective
model.Minimize(
sum(obj_bool_vars[i] * obj_bool_coeffs[i]
for i in range(len(obj_bool_vars))) + sum(
obj_int_vars[i] * obj_int_coeffs[i]
for i in range(len(obj_int_vars))))
for i in range(len(obj_bool_vars)))
+ sum(obj_int_vars[i] * obj_int_coeffs[i]
for i in range(len(obj_int_vars))))
if output_proto:
print('Writing proto to %s' % output_proto)

View File

@@ -198,8 +198,7 @@ def main(args):
name_suffix = '_%i' % job_id
start = model.NewIntVar(release_date, due_date, 's' + name_suffix)
end = model.NewIntVar(release_date, due_date, 'e' + name_suffix)
interval = model.NewIntervalVar(start, duration, end,
'i' + name_suffix)
interval = model.NewIntervalVar(start, duration, end, 'i' + name_suffix)
starts.append(start)
ends.append(end)
intervals.append(interval)
@@ -235,8 +234,8 @@ def main(args):
model.Add(starts[j] == ends[i] +
setup_times[i + 1][j]).OnlyEnforceIf(lit)
else:
model.Add(starts[j] >= ends[i] +
setup_times[i + 1][j]).OnlyEnforceIf(lit)
model.Add(starts[j] >=
ends[i] + setup_times[i + 1][j]).OnlyEnforceIf(lit)
model.AddCircuit(arcs)
@@ -269,9 +268,9 @@ def main(args):
solver.SolveWithSolutionCallback(model, solution_printer)
print(solver.ResponseStats())
for job_id in all_jobs:
print(
'job %i starts at %i end ends at %i' %
(job_id, solver.Value(starts[job_id]), solver.Value(ends[job_id])))
print('job %i starts at %i end ends at %i' %
(job_id, solver.Value(starts[job_id]),
solver.Value(ends[job_id])))
if __name__ == '__main__':

View File

@@ -347,14 +347,12 @@ def steel_mill_slab(problem, break_symmetries, output_proto):
for s in all_slabs
]
color_is_in_slab = [[
model.NewBoolVar('color_%i_in_slab_%i' % (c + 1, s))
for c in all_colors
model.NewBoolVar('color_%i_in_slab_%i' % (c + 1, s)) for c in all_colors
] for s in all_slabs]
# Compute load of all slabs.
for s in all_slabs:
model.Add(
sum(assign[o][s] * widths[o] for o in all_orders) == loads[s])
model.Add(sum(assign[o][s] * widths[o] for o in all_orders) == loads[s])
# Orders are assigned to one slab.
for o in all_orders:
@@ -444,8 +442,9 @@ def steel_mill_slab(problem, break_symmetries, output_proto):
### Output the solution.
if status == cp_model.OPTIMAL:
print('Loss = %i, time = %f s, %i conflicts' % (
solver.ObjectiveValue(), solver.WallTime(), solver.NumConflicts()))
print('Loss = %i, time = %f s, %i conflicts' %
(solver.ObjectiveValue(), solver.WallTime(),
solver.NumConflicts()))
else:
print('No solution')
@@ -477,9 +476,7 @@ def collect_valid_slabs(capacities, colors, widths, loss_array, all_colors):
assign = [model.NewBoolVar('assign_%i' % o) for o in all_orders]
load = model.NewIntVar(0, max_capacity, 'load')
color_in_slab = [
model.NewBoolVar('color_%i' % (c + 1)) for c in all_colors
]
color_in_slab = [model.NewBoolVar('color_%i' % (c + 1)) for c in all_colors]
# Compute load.
model.Add(sum(assign[o] * widths[o] for o in all_orders) == load)
@@ -538,9 +535,7 @@ def steel_mill_slab_with_valid_slabs(problem, break_symmetries, output_proto):
assign = [[
model.NewBoolVar('assign_%i_to_slab_%i' % (o, s)) for s in all_slabs
] for o in all_orders]
loads = [
model.NewIntVar(0, max_capacity, 'load_%i' % s) for s in all_slabs
]
loads = [model.NewIntVar(0, max_capacity, 'load_%i' % s) for s in all_slabs]
losses = [model.NewIntVar(0, max_loss, 'loss_%i' % s) for s in all_slabs]
unsorted_valid_slabs = collect_valid_slabs(capacities, colors, widths,
@@ -553,8 +548,8 @@ def steel_mill_slab_with_valid_slabs(problem, break_symmetries, output_proto):
for s in all_slabs:
model.AddAllowedAssignments(
[assign[o][s] for o in all_orders] + [losses[s], loads[s]],
valid_slabs)
[assign[o][s]
for o in all_orders] + [losses[s], loads[s]], valid_slabs)
# Orders are assigned to one slab.
for o in all_orders:
@@ -595,8 +590,7 @@ def steel_mill_slab_with_valid_slabs(problem, break_symmetries, output_proto):
for w, os in local_width_to_order.items():
if len(os) > 1:
for p in range(len(os) - 1):
ordered_equivalent_orders.append((os[p],
os[p + 1]))
ordered_equivalent_orders.append((os[p], os[p + 1]))
for w, os in width_to_unique_color_order.items():
if len(os) > 1:
for p in range(len(os) - 1):
@@ -640,8 +634,9 @@ def steel_mill_slab_with_valid_slabs(problem, break_symmetries, output_proto):
### Output the solution.
if status == cp_model.OPTIMAL:
print('Loss = %i, time = %f s, %i conflicts' % (
solver.ObjectiveValue(), solver.WallTime(), solver.NumConflicts()))
print('Loss = %i, time = %f s, %i conflicts' %
(solver.ObjectiveValue(), solver.WallTime(),
solver.NumConflicts()))
else:
print('No solution')
@@ -685,8 +680,7 @@ def steel_mill_slab_with_column_generation(problem, output_proto):
for o in all_orders:
model.Add(
sum(selected[i] for i in all_valid_slabs
if valid_slabs[i][o]) == 1)
sum(selected[i] for i in all_valid_slabs if valid_slabs[i][o]) == 1)
# Redundant constraint (sum of loads == sum of widths).
model.Add(
@@ -696,8 +690,8 @@ def steel_mill_slab_with_column_generation(problem, output_proto):
# Objective.
max_loss = max(valid_slabs[i][-2] for i in all_valid_slabs)
obj = model.NewIntVar(0, num_slabs * max_loss, 'obj')
model.Add(obj == sum(
selected[i] * valid_slabs[i][-2] for i in all_valid_slabs))
model.Add(
obj == sum(selected[i] * valid_slabs[i][-2] for i in all_valid_slabs))
model.Minimize(obj)
print('Model created')
@@ -715,8 +709,9 @@ def steel_mill_slab_with_column_generation(problem, output_proto):
### Output the solution.
if status == cp_model.OPTIMAL:
print('Loss = %i, time = %f s, %i conflicts' % (
solver.ObjectiveValue(), solver.WallTime(), solver.NumConflicts()))
print('Loss = %i, time = %f s, %i conflicts' %
(solver.ObjectiveValue(), solver.WallTime(),
solver.NumConflicts()))
else:
print('No solution')

View File

@@ -22,203 +22,156 @@ from ortools.linear_solver import pywraplp
def main():
"""Entry point of the program"""
# Nutrient minimums.
nutrients = [['Calories (kcal)', 3], ['Protein (g)', 70],
['Calcium (g)', 0.8], ['Iron (mg)', 12],
['Vitamin A (KIU)', 5], ['Vitamin B1 (mg)', 1.8],
['Vitamin B2 (mg)', 2.7], ['Niacin (mg)', 18],
['Vitamin C (mg)', 75]]
nutrients = [['Calories (kcal)', 3], ['Protein (g)', 70], [
'Calcium (g)', 0.8
], ['Iron (mg)', 12], ['Vitamin A (KIU)', 5], ['Vitamin B1 (mg)', 1.8],
['Vitamin B2 (mg)', 2.7], ['Niacin (mg)',
18], ['Vitamin C (mg)', 75]]
# Commodity, Unit, 1939 price (cents), Calories (kcal), Protein (g), Calcium (g), Iron (mg),
# Vitamin A (KIU), Vitamin B1 (mg), Vitamin B2 (mg), Niacin (mg), Vitamin C (mg)
data = [
[
'Wheat Flour (Enriched)', '10 lb.', 36, 44.7, 1411, 2, 365, 0,
55.4, 33.3, 441, 0
], ['Macaroni', '1 lb.', 14.1, 11.6, 418, 0.7, 54, 0, 3.2, 1.9, 68, 0],
[
'Wheat Cereal (Enriched)', '28 oz.', 24.2, 11.8, 377, 14.4, 175, 0,
14.4, 8.8, 114, 0
],
['Corn Flakes', '8 oz.', 7.1, 11.4, 252, 0.1, 56, 0, 13.5, 2.3, 68, 0],
[
'Corn Meal', '1 lb.', 4.6, 36.0, 897, 1.7, 99, 30.9, 17.4, 7.9,
106, 0
],
[
'Hominy Grits', '24 oz.', 8.5, 28.6, 680, 0.8, 80, 0, 10.6, 1.6,
110, 0
], ['Rice', '1 lb.', 7.5, 21.2, 460, 0.6, 41, 0, 2, 4.8, 60, 0],
[
'Rolled Oats', '1 lb.', 7.1, 25.3, 907, 5.1, 341, 0, 37.1, 8.9, 64,
0
],
[
'White Bread (Enriched)', '1 lb.', 7.9, 15.0, 488, 2.5, 115, 0,
13.8, 8.5, 126, 0
],
[
'Whole Wheat Bread', '1 lb.', 9.1, 12.2, 484, 2.7, 125, 0, 13.9,
6.4, 160, 0
], ['Rye Bread', '1 lb.', 9.1, 12.4, 439, 1.1, 82, 0, 9.9, 3, 66, 0],
['Pound Cake', '1 lb.', 24.8, 8.0, 130, 0.4, 31, 18.9, 2.8, 3, 17, 0],
['Soda Crackers', '1 lb.', 15.1, 12.5, 288, 0.5, 50, 0, 0, 0, 0, 0],
['Milk', '1 qt.', 11, 6.1, 310, 10.5, 18, 16.8, 4, 16, 7, 177],
[
'Evaporated Milk (can)', '14.5 oz.', 6.7, 8.4, 422, 15.1, 9, 26, 3,
23.5, 11, 60
], ['Butter', '1 lb.', 30.8, 10.8, 9, 0.2, 3, 44.2, 0, 0.2, 2, 0],
['Oleomargarine', '1 lb.', 16.1, 20.6, 17, 0.6, 6, 55.8, 0.2, 0, 0, 0],
['Eggs', '1 doz.', 32.6, 2.9, 238, 1.0, 52, 18.6, 2.8, 6.5, 1, 0],
[
'Cheese (Cheddar)', '1 lb.', 24.2, 7.4, 448, 16.4, 19, 28.1, 0.8,
10.3, 4, 0
], ['Cream', '1/2 pt.', 14.1, 3.5, 49, 1.7, 3, 16.9, 0.6, 2.5, 0, 17],
[
'Peanut Butter', '1 lb.', 17.9, 15.7, 661, 1.0, 48, 0, 9.6, 8.1,
471, 0
],
['Mayonnaise', '1/2 pt.', 16.7, 8.6, 18, 0.2, 8, 2.7, 0.4, 0.5, 0, 0],
['Crisco', '1 lb.', 20.3, 20.1, 0, 0, 0, 0, 0, 0, 0, 0],
['Lard', '1 lb.', 9.8, 41.7, 0, 0, 0, 0.2, 0, 0.5, 5, 0],
[
'Sirloin Steak', '1 lb.', 39.6, 2.9, 166, 0.1, 34, 0.2, 2.1, 2.9,
69, 0
],
[
'Round Steak', '1 lb.', 36.4, 2.2, 214, 0.1, 32, 0.4, 2.5, 2.4, 87,
0
], ['Rib Roast', '1 lb.', 29.2, 3.4, 213, 0.1, 33, 0, 0, 2, 0, 0],
['Chuck Roast', '1 lb.', 22.6, 3.6, 309, 0.2, 46, 0.4, 1, 4, 120, 0],
['Plate', '1 lb.', 14.6, 8.5, 404, 0.2, 62, 0, 0.9, 0, 0, 0],
[
'Liver (Beef)', '1 lb.', 26.8, 2.2, 333, 0.2, 139, 169.2, 6.4,
50.8, 316, 525
],
['Leg of Lamb', '1 lb.', 27.6, 3.1, 245, 0.1, 20, 0, 2.8, 3.9, 86, 0],
[
'Lamb Chops (Rib)', '1 lb.', 36.6, 3.3, 140, 0.1, 15, 0, 1.7, 2.7,
54, 0
], [
'Pork Chops', '1 lb.', 30.7, 3.5, 196, 0.2, 30, 0, 17.4, 2.7, 60, 0
],
[
'Pork Loin Roast', '1 lb.', 24.2, 4.4, 249, 0.3, 37, 0, 18.2, 3.6,
79, 0
], ['Bacon', '1 lb.', 25.6, 10.4, 152, 0.2, 23, 0, 1.8, 1.8, 71, 0],
['Ham, smoked', '1 lb.', 27.4, 6.7, 212, 0.2, 31, 0, 9.9, 3.3, 50, 0],
['Salt Pork', '1 lb.', 16, 18.8, 164, 0.1, 26, 0, 1.4, 1.8, 0, 0],
[
'Roasting Chicken', '1 lb.', 30.3, 1.8, 184, 0.1, 30, 0.1, 0.9,
1.8, 68, 46
],
['Veal Cutlets', '1 lb.', 42.3, 1.7, 156, 0.1, 24, 0, 1.4, 2.4, 57, 0],
[
'Salmon, Pink (can)', '16 oz.', 13, 5.8, 705, 6.8, 45, 3.5, 1, 4.9,
209, 0
], ['Apples', '1 lb.', 4.4, 5.8, 27, 0.5, 36, 7.3, 3.6, 2.7, 5, 544],
['Bananas', '1 lb.', 6.1, 4.9, 60, 0.4, 30, 17.4, 2.5, 3.5, 28, 498],
['Lemons', '1 doz.', 26, 1.0, 21, 0.5, 14, 0, 0.5, 0, 4, 952],
[
'Oranges', '1 doz.', 30.9, 2.2, 40, 1.1, 18, 11.1, 3.6, 1.3, 10,
1998
],
[
'Green Beans', '1 lb.', 7.1, 2.4, 138, 3.7, 80, 69, 4.3, 5.8, 37,
862
], ['Cabbage', '1 lb.', 3.7, 2.6, 125, 4.0, 36, 7.2, 9, 4.5, 26, 5369],
[
'Carrots', '1 bunch', 4.7, 2.7, 73, 2.8, 43, 188.5, 6.1, 4.3, 89,
608
], ['Celery', '1 stalk', 7.3, 0.9, 51, 3.0, 23, 0.9, 1.4, 1.4, 9, 313],
['Lettuce', '1 head', 8.2, 0.4, 27, 1.1, 22, 112.4, 1.8, 3.4, 11, 449],
['Onions', '1 lb.', 3.6, 5.8, 166, 3.8, 59, 16.6, 4.7, 5.9, 21, 1184],
[
'Potatoes', '15 lb.', 34, 14.3, 336, 1.8, 118, 6.7, 29.4, 7.1, 198,
2522
],
[
'Spinach', '1 lb.', 8.1, 1.1, 106, 0, 138, 918.4, 5.7, 13.8, 33,
2755
],
[
'Sweet Potatoes', '1 lb.', 5.1, 9.6, 138, 2.7, 54, 290.7, 8.4, 5.4,
83, 1912
],
[
'Peaches (can)', 'No. 2 1/2', 16.8, 3.7, 20, 0.4, 10, 21.5, 0.5, 1,
31, 196
],
[
'Pears (can)', 'No. 2 1/2', 20.4, 3.0, 8, 0.3, 8, 0.8, 0.8, 0.8, 5,
81
],
[
'Pineapple (can)', 'No. 2 1/2', 21.3, 2.4, 16, 0.4, 8, 2, 2.8, 0.8,
7, 399
],
[
'Asparagus (can)', 'No. 2', 27.7, 0.4, 33, 0.3, 12, 16.3, 1.4, 2.1,
17, 272
],
[
'Green Beans (can)', 'No. 2', 10, 1.0, 54, 2, 65, 53.9, 1.6, 4.3,
32, 431
],
[
'Pork and Beans (can)', '16 oz.', 7.1, 7.5, 364, 4, 134, 3.5, 8.3,
7.7, 56, 0
],
[
'Corn (can)', 'No. 2', 10.4, 5.2, 136, 0.2, 16, 12, 1.6, 2.7, 42,
218
],
[
'Peas (can)', 'No. 2', 13.8, 2.3, 136, 0.6, 45, 34.9, 4.9, 2.5, 37,
370
],
[
'Tomatoes (can)', 'No. 2', 8.6, 1.3, 63, 0.7, 38, 53.2, 3.4, 2.5,
36, 1253
],
[
'Tomato Soup (can)', '10 1/2 oz.', 7.6, 1.6, 71, 0.6, 43, 57.9,
3.5, 2.4, 67, 862
],
[
'Peaches, Dried', '1 lb.', 15.7, 8.5, 87, 1.7, 173, 86.8, 1.2, 4.3,
55, 57
],
[
'Prunes, Dried', '1 lb.', 9, 12.8, 99, 2.5, 154, 85.7, 3.9, 4.3,
65, 257
],
[
'Raisins, Dried', '15 oz.', 9.4, 13.5, 104, 2.5, 136, 4.5, 6.3,
1.4, 24, 136
],
[
'Peas, Dried', '1 lb.', 7.9, 20.0, 1367, 4.2, 345, 2.9, 28.7, 18.4,
162, 0
],
[
'Lima Beans, Dried', '1 lb.', 8.9, 17.4, 1055, 3.7, 459, 5.1, 26.9,
38.2, 93, 0
],
[
'Navy Beans, Dried', '1 lb.', 5.9, 26.9, 1691, 11.4, 792, 0, 38.4,
24.6, 217, 0
], ['Coffee', '1 lb.', 22.4, 0, 0, 0, 0, 0, 4, 5.1, 50, 0],
['Tea', '1/4 lb.', 17.4, 0, 0, 0, 0, 0, 0, 2.3, 42, 0],
['Cocoa', '8 oz.', 8.6, 8.7, 237, 3, 72, 0, 2, 11.9, 40, 0],
['Chocolate', '8 oz.', 16.2, 8.0, 77, 1.3, 39, 0, 0.9, 3.4, 14, 0],
['Sugar', '10 lb.', 51.7, 34.9, 0, 0, 0, 0, 0, 0, 0, 0],
['Corn Syrup', '24 oz.', 13.7, 14.7, 0, 0.5, 74, 0, 0, 0, 5, 0],
['Molasses', '18 oz.', 13.6, 9.0, 0, 10.3, 244, 0, 1.9, 7.5, 146, 0],
[
'Strawberry Preserves', '1 lb.', 20.5, 6.4, 11, 0.4, 7, 0.2, 0.2,
0.4, 3, 0
]
]
data = [[
'Wheat Flour (Enriched)', '10 lb.', 36, 44.7, 1411, 2, 365, 0, 55.4,
33.3, 441, 0
], ['Macaroni', '1 lb.', 14.1, 11.6, 418, 0.7, 54, 0, 3.2, 1.9, 68, 0], [
'Wheat Cereal (Enriched)', '28 oz.', 24.2, 11.8, 377, 14.4, 175, 0,
14.4, 8.8, 114, 0
], ['Corn Flakes', '8 oz.', 7.1, 11.4, 252, 0.1, 56, 0, 13.5, 2.3, 68, 0], [
'Corn Meal', '1 lb.', 4.6, 36.0, 897, 1.7, 99, 30.9, 17.4, 7.9, 106, 0
], [
'Hominy Grits', '24 oz.', 8.5, 28.6, 680, 0.8, 80, 0, 10.6, 1.6, 110, 0
], ['Rice', '1 lb.', 7.5, 21.2, 460, 0.6, 41, 0, 2, 4.8, 60, 0], [
'Rolled Oats', '1 lb.', 7.1, 25.3, 907, 5.1, 341, 0, 37.1, 8.9, 64, 0
], [
'White Bread (Enriched)', '1 lb.', 7.9, 15.0, 488, 2.5, 115, 0, 13.8,
8.5, 126, 0
], [
'Whole Wheat Bread', '1 lb.', 9.1, 12.2, 484, 2.7, 125, 0, 13.9, 6.4,
160, 0
], ['Rye Bread', '1 lb.', 9.1, 12.4, 439, 1.1, 82, 0, 9.9, 3, 66, 0], [
'Pound Cake', '1 lb.', 24.8, 8.0, 130, 0.4, 31, 18.9, 2.8, 3, 17, 0
], ['Soda Crackers', '1 lb.', 15.1, 12.5, 288, 0.5, 50, 0, 0, 0, 0, 0], [
'Milk', '1 qt.', 11, 6.1, 310, 10.5, 18, 16.8, 4, 16, 7, 177
], [
'Evaporated Milk (can)', '14.5 oz.', 6.7, 8.4, 422, 15.1, 9, 26, 3,
23.5, 11, 60
], ['Butter', '1 lb.', 30.8, 10.8, 9, 0.2, 3, 44.2, 0, 0.2, 2, 0], [
'Oleomargarine', '1 lb.', 16.1, 20.6, 17, 0.6, 6, 55.8, 0.2, 0, 0, 0
], ['Eggs', '1 doz.', 32.6, 2.9, 238, 1.0, 52, 18.6, 2.8, 6.5, 1, 0], [
'Cheese (Cheddar)', '1 lb.', 24.2, 7.4, 448, 16.4, 19, 28.1, 0.8, 10.3,
4, 0
], ['Cream', '1/2 pt.', 14.1, 3.5, 49, 1.7, 3, 16.9, 0.6, 2.5, 0, 17], [
'Peanut Butter', '1 lb.', 17.9, 15.7, 661, 1.0, 48, 0, 9.6, 8.1, 471, 0
], ['Mayonnaise', '1/2 pt.', 16.7, 8.6, 18, 0.2, 8, 2.7, 0.4, 0.5, 0, 0], [
'Crisco', '1 lb.', 20.3, 20.1, 0, 0, 0, 0, 0, 0, 0, 0
], ['Lard', '1 lb.', 9.8, 41.7, 0, 0, 0, 0.2, 0, 0.5, 5, 0], [
'Sirloin Steak', '1 lb.', 39.6, 2.9, 166, 0.1, 34, 0.2, 2.1, 2.9, 69, 0
], ['Round Steak', '1 lb.', 36.4, 2.2, 214, 0.1, 32, 0.4, 2.5, 2.4, 87, 0
], ['Rib Roast', '1 lb.', 29.2, 3.4, 213, 0.1, 33, 0, 0, 2, 0, 0], [
'Chuck Roast', '1 lb.', 22.6, 3.6, 309, 0.2, 46, 0.4, 1, 4, 120, 0
], ['Plate', '1 lb.', 14.6, 8.5, 404, 0.2, 62, 0, 0.9, 0, 0, 0], [
'Liver (Beef)', '1 lb.', 26.8, 2.2, 333, 0.2, 139, 169.2, 6.4, 50.8,
316, 525
], [
'Leg of Lamb', '1 lb.', 27.6, 3.1, 245, 0.1, 20, 0, 2.8, 3.9, 86, 0
], [
'Lamb Chops (Rib)',
'1 lb.', 36.6, 3.3, 140, 0.1, 15, 0, 1.7, 2.7, 54, 0
], [
'Pork Chops', '1 lb.', 30.7, 3.5, 196, 0.2, 30, 0, 17.4, 2.7, 60, 0
], [
'Pork Loin Roast',
'1 lb.', 24.2, 4.4, 249, 0.3, 37, 0, 18.2, 3.6, 79, 0
], ['Bacon', '1 lb.', 25.6, 10.4, 152, 0.2, 23, 0, 1.8, 1.8, 71, 0], [
'Ham, smoked', '1 lb.', 27.4, 6.7, 212, 0.2, 31, 0, 9.9, 3.3, 50, 0
], ['Salt Pork', '1 lb.', 16, 18.8, 164, 0.1, 26, 0, 1.4, 1.8, 0, 0], [
'Roasting Chicken', '1 lb.', 30.3, 1.8, 184, 0.1, 30, 0.1, 0.9, 1.8,
68, 46
], [
'Veal Cutlets', '1 lb.', 42.3, 1.7, 156, 0.1, 24, 0, 1.4, 2.4, 57, 0
], [
'Salmon, Pink (can)', '16 oz.', 13, 5.8, 705, 6.8, 45, 3.5,
1, 4.9, 209, 0
], ['Apples', '1 lb.', 4.4, 5.8, 27, 0.5, 36, 7.3, 3.6, 2.7, 5, 544], [
'Bananas', '1 lb.', 6.1, 4.9, 60, 0.4, 30, 17.4, 2.5, 3.5, 28, 498
], ['Lemons', '1 doz.', 26, 1.0, 21, 0.5, 14, 0, 0.5, 0, 4, 952], [
'Oranges', '1 doz.', 30.9, 2.2, 40, 1.1, 18, 11.1, 3.6, 1.3, 10, 1998
], [
'Green Beans', '1 lb.', 7.1, 2.4, 138, 3.7, 80, 69, 4.3, 5.8, 37, 862
], ['Cabbage', '1 lb.', 3.7, 2.6, 125, 4.0, 36, 7.2, 9, 4.5, 26, 5369], [
'Carrots', '1 bunch', 4.7, 2.7, 73, 2.8, 43, 188.5, 6.1, 4.3, 89, 608
], ['Celery', '1 stalk', 7.3, 0.9, 51, 3.0, 23, 0.9, 1.4, 1.4, 9, 313], [
'Lettuce', '1 head', 8.2, 0.4, 27, 1.1, 22, 112.4, 1.8, 3.4, 11, 449
], ['Onions', '1 lb.', 3.6, 5.8, 166, 3.8, 59, 16.6, 4.7, 5.9, 21,
1184], [
'Potatoes', '15 lb.', 34, 14.3, 336, 1.8, 118, 6.7, 29.4, 7.1,
198, 2522
], [
'Spinach', '1 lb.', 8.1, 1.1, 106, 0, 138, 918.4, 5.7, 13.8, 33,
2755
], [
'Sweet Potatoes', '1 lb.', 5.1, 9.6, 138, 2.7, 54, 290.7, 8.4,
5.4, 83, 1912
], [
'Peaches (can)', 'No. 2 1/2', 16.8, 3.7, 20, 0.4, 10, 21.5, 0.5,
1, 31, 196
], [
'Pears (can)', 'No. 2 1/2', 20.4, 3.0, 8, 0.3, 8, 0.8, 0.8, 0.8,
5, 81
], [
'Pineapple (can)', 'No. 2 1/2', 21.3, 2.4, 16, 0.4, 8, 2, 2.8,
0.8, 7, 399
], [
'Asparagus (can)', 'No. 2', 27.7, 0.4, 33, 0.3, 12, 16.3, 1.4,
2.1, 17, 272
], [
'Green Beans (can)', 'No. 2', 10, 1.0, 54, 2, 65, 53.9, 1.6, 4.3,
32, 431
], [
'Pork and Beans (can)', '16 oz.', 7.1, 7.5, 364, 4, 134, 3.5,
8.3, 7.7, 56, 0
], [
'Corn (can)', 'No. 2', 10.4, 5.2, 136, 0.2, 16, 12, 1.6, 2.7, 42,
218
], [
'Peas (can)', 'No. 2', 13.8, 2.3, 136, 0.6, 45, 34.9, 4.9, 2.5,
37, 370
], [
'Tomatoes (can)', 'No. 2', 8.6, 1.3, 63, 0.7, 38, 53.2, 3.4, 2.5,
36, 1253
], [
'Tomato Soup (can)', '10 1/2 oz.', 7.6, 1.6, 71, 0.6, 43, 57.9,
3.5, 2.4, 67, 862
], [
'Peaches, Dried', '1 lb.', 15.7, 8.5, 87, 1.7, 173, 86.8, 1.2,
4.3, 55, 57
], [
'Prunes, Dried', '1 lb.', 9, 12.8, 99, 2.5, 154, 85.7, 3.9, 4.3,
65, 257
], [
'Raisins, Dried', '15 oz.', 9.4, 13.5, 104, 2.5, 136, 4.5, 6.3,
1.4, 24, 136
], [
'Peas, Dried', '1 lb.', 7.9, 20.0, 1367, 4.2, 345, 2.9, 28.7,
18.4, 162, 0
], [
'Lima Beans, Dried', '1 lb.', 8.9, 17.4, 1055, 3.7, 459, 5.1,
26.9, 38.2, 93, 0
], [
'Navy Beans, Dried', '1 lb.', 5.9, 26.9, 1691, 11.4, 792, 0,
38.4, 24.6, 217, 0
], ['Coffee', '1 lb.', 22.4, 0, 0, 0, 0, 0, 4, 5.1, 50,
0], ['Tea', '1/4 lb.', 17.4, 0, 0, 0, 0, 0, 0, 2.3, 42, 0],
['Cocoa', '8 oz.', 8.6, 8.7, 237, 3, 72, 0, 2, 11.9, 40, 0], [
'Chocolate', '8 oz.', 16.2, 8.0, 77, 1.3, 39, 0, 0.9, 3.4, 14, 0
], ['Sugar', '10 lb.', 51.7, 34.9, 0, 0, 0, 0, 0, 0, 0, 0],
['Corn Syrup', '24 oz.', 13.7, 14.7, 0, 0.5, 74, 0, 0, 0, 5, 0], [
'Molasses', '18 oz.', 13.6, 9.0, 0, 10.3, 244, 0, 1.9, 7.5, 146,
0
], [
'Strawberry Preserves', '1 lb.', 20.5, 6.4, 11, 0.4, 7, 0.2,
0.2, 0.4, 3, 0
]]
# Instantiate a Glop solver, naming it LinearExample.
solver = pywraplp.Solver('StiglerDietExample',

View File

@@ -28,10 +28,10 @@ def solve_sudoku():
cell = list(range(0, cell_size))
initial_grid = [[0, 6, 0, 0, 5, 0, 0, 2, 0], [0, 0, 0, 3, 0, 0, 0, 9, 0],
[7, 0, 0, 6, 0, 0, 0, 1, 0], [0, 0, 6, 0, 3, 0, 4, 0, 0],
[0, 0, 4, 0, 7, 0, 1, 0, 0], [0, 0, 5, 0, 9, 0, 8, 0, 0],
[0, 4, 0, 0, 0, 1, 0, 0, 6], [0, 3, 0, 0, 0, 8, 0, 0, 0],
[0, 2, 0, 0, 4, 0, 0, 5, 0]]
[7, 0, 0, 6, 0, 0, 0, 1, 0], [0, 0, 6, 0, 3, 0, 4, 0, 0], [
0, 0, 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, 0, 0, 0,
0, 0
], [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
], [
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
], [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
], [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
], [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0
], [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0
]]
ntasks = len(available)
nslots = len(available[0])

View File

@@ -78,8 +78,7 @@ def tasks_and_workers_assignment_sat():
model.Add(n == sum(x[i, j] for i in all_workers))
c = model.NewIntVar(0, sum_of_costs * scaling,
'sum_of_costs_of_group_%i' % j)
model.Add(c == sum(
y[k, j] * task_cost[k] * scaling for k in all_tasks))
model.Add(c == sum(y[k, j] * task_cost[k] * scaling for k in all_tasks))
a = model.NewIntVar(0, sum_of_costs * scaling,
'average_cost_of_group_%i' % j)
model.AddDivisionEquality(a, c, n)

View File

@@ -147,8 +147,8 @@ class DataProblem():
#######################
def manhattan_distance(position_1, position_2):
"""Computes the Manhattan distance between two points"""
return (abs(position_1[0] - position_2[0]) +
abs(position_1[1] - position_2[1]))
return (
abs(position_1[0] - position_2[0]) + abs(position_1[1] - position_2[1]))
class CreateTimeEvaluator(object):
@@ -165,9 +165,8 @@ class CreateTimeEvaluator(object):
if from_node == to_node:
travel_time = 0
else:
travel_time = manhattan_distance(
data.locations[from_node],
data.locations[to_node]) / data.vehicle.speed
travel_time = manhattan_distance(data.locations[
from_node], data.locations[to_node]) / data.vehicle.speed
return travel_time
def __init__(self, data):
@@ -181,8 +180,8 @@ class CreateTimeEvaluator(object):
self._total_time[from_node][to_node] = 0
else:
self._total_time[from_node][to_node] = int(
self.service_time(data, from_node) +
self.travel_time(data, from_node, to_node))
self.service_time(data, from_node) + self.travel_time(
data, from_node, to_node))
def time_evaluator(self, from_node, to_node):
"""Returns the total time between the two nodes"""
@@ -209,8 +208,7 @@ def main():
# Print Transit Time
time_evaluator = CreateTimeEvaluator(data).time_evaluator
print('Route 0:')
print_transit_time([[0, 5], [5, 8], [8, 6], [6, 2], [2, 0]],
time_evaluator)
print_transit_time([[0, 5], [5, 8], [8, 6], [6, 2], [2, 0]], time_evaluator)
print('Route 1:')
print_transit_time([[0, 9], [9, 14], [14, 16], [16, 10], [10, 0]],
@@ -221,8 +219,7 @@ def main():
time_evaluator)
print('Route 3:')
print_transit_time([[0, 7], [7, 4], [4, 3], [3, 1], [1, 0]],
time_evaluator)
print_transit_time([[0, 7], [7, 4], [4, 3], [3, 1], [1, 0]], time_evaluator)
if __name__ == '__main__':

View File

@@ -65,8 +65,8 @@ def create_data_model():
#######################
def manhattan_distance(position_1, position_2):
"""Computes the Manhattan distance between two points"""
return (abs(position_1[0] - position_2[0]) +
abs(position_1[1] - position_2[1]))
return (
abs(position_1[0] - position_2[0]) + abs(position_1[1] - position_2[1]))
def create_distance_evaluator(data):

View File

@@ -39,9 +39,8 @@ class SolutionPrinter(cp_model.CpSolverSolutionCallback):
print('Solution %i: ', self.__solution_count)
print(' min vendors:', self.__min_vendors)
for i in range(self.__num_vendors):
print(
' - vendor %i: ' % i, self.__possible_schedules[self.Value(
self.__selected_schedules[i])])
print(' - vendor %i: ' % i, self.__possible_schedules[self.Value(
self.__selected_schedules[i])])
print()
for j in range(self.__num_hours):
@@ -73,12 +72,12 @@ def main():
# Last columns are :
# index_of_the_schedule, sum of worked hours (per work type).
# The index is useful for branching.
possible_schedules = [[1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 8],
[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 4],
[0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 2, 5],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3, 4],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 4, 3],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0]]
possible_schedules = [[1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0,
8], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1,
4], [0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 2,
5], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 3, 4],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 4,
3], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0]]
num_possible_schedules = len(possible_schedules)
selected_schedules = []
@@ -137,8 +136,8 @@ def main():
print(' - conflicts : %i' % solver.NumConflicts())
print(' - branches : %i' % solver.NumBranches())
print(' - wall time : %f s' % solver.WallTime())
print(' - number of solutions found: %i' %
solution_printer.solution_count())
print(
' - number of solutions found: %i' % solution_printer.solution_count())
if __name__ == '__main__':

View File

@@ -65,8 +65,8 @@ def create_data_model():
#######################
def manhattan_distance(position_1, position_2):
"""Computes the Manhattan distance between two points"""
return (abs(position_1[0] - position_2[0]) +
abs(position_1[1] - position_2[1]))
return (
abs(position_1[0] - position_2[0]) + abs(position_1[1] - position_2[1]))
def create_distance_evaluator(data):

View File

@@ -65,8 +65,8 @@ def create_data_model():
#######################
def manhattan_distance(position_1, position_2):
"""Computes the Manhattan distance between two points"""
return (abs(position_1[0] - position_2[0]) +
abs(position_1[1] - position_2[1]))
return (
abs(position_1[0] - position_2[0]) + abs(position_1[1] - position_2[1]))
def create_distance_evaluator(data):

View File

@@ -88,23 +88,23 @@ def BuildData():
# Connection matrix: who knows who, and how strong
# is the relation
C = [[1, 50, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[50, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 50, 1, 1, 1, 1, 10, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 50, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 50, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 50, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 50, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 50, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 10, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 50, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,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1, 1, 1, 1, 1, 1, 1, 1], [
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1
], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]]
# Names of the guests. B: Bride side, G: Groom side
names = [
@@ -133,8 +133,8 @@ def solve_with_discrete_model():
seats = {}
for t in all_tables:
for g in all_guests:
seats[(t, g)] = model.NewBoolVar(
"guest %i seats on table %i" % (g, t))
seats[(t, g)] = model.NewBoolVar("guest %i seats on table %i" % (g,
t))
colocated = {}
for g1 in range(num_guests - 1):
@@ -151,8 +151,9 @@ def solve_with_discrete_model():
# Objective
model.Maximize(
sum(C[g1][g2] * colocated[g1, g2] for g1 in range(num_guests - 1)
for g2 in range(g1 + 1, num_guests) if C[g1][g2] > 0))
sum(C[g1][g2] * colocated[g1, g2]
for g1 in range(num_guests - 1) for g2 in range(g1 + 1, num_guests)
if C[g1][g2] > 0))
#
# Constraints
@@ -186,17 +187,17 @@ def solve_with_discrete_model():
# Min known neighbors rule.
for t in all_tables:
model.Add(
sum(same_table[(g1, g2, t)] for g1 in range(num_guests - 1)
for g2 in range(g1 + 1, num_guests)
for t in all_tables if C[g1][g2] > 0) >= min_known_neighbors)
sum(same_table[(g1, g2, t)]
for g1 in range(num_guests - 1)
for g2 in range(g1 + 1, num_guests) for t in all_tables
if C[g1][g2] > 0) >= min_known_neighbors)
# Symmetry breaking. First guest seats on the first table.
model.Add(seats[(0, 0)] == 1)
### Solve model.
solver = cp_model.CpSolver()
solution_printer = WeddingChartPrinter(seats, names, num_tables,
num_guests)
solution_printer = WeddingChartPrinter(seats, names, num_tables, num_guests)
solver.SolveWithSolutionCallback(model, solution_printer)
print("Statistics")

View File

@@ -19,14 +19,13 @@ def schedule():
# Input data.
positions = [
1, 2, 8, 10, 5, 3, 4, 3, 6, 6, 4, 5, 4, 3, 4, 4, 3, 4, 2, 1, 0, 0, 0,
0, 1, 2, 9, 9, 4, 3, 4, 3,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