use tuples instead of lists for arcs in CP-SAT AddCircuit
This commit is contained in:
@@ -102,16 +102,16 @@ def jobshop_ft06_distance():
|
||||
for j1 in range(len(job_intervals)):
|
||||
# Initial arc from the dummy node (0) to a task.
|
||||
start_lit = model.NewBoolVar("%i is first job" % j1)
|
||||
arcs.append([0, j1 + 1, start_lit])
|
||||
arcs.append((0, j1 + 1, start_lit))
|
||||
# Final arc from an arc to the dummy node.
|
||||
arcs.append([j1 + 1, 0, model.NewBoolVar("%i is last job" % j1)])
|
||||
arcs.append((j1 + 1, 0, model.NewBoolVar("%i is last job" % j1)))
|
||||
|
||||
for j2 in range(len(job_intervals)):
|
||||
if j1 == j2:
|
||||
continue
|
||||
|
||||
lit = model.NewBoolVar("%i follows %i" % (j2, j1))
|
||||
arcs.append([j1 + 1, j2 + 1, lit])
|
||||
arcs.append((j1 + 1, j2 + 1, lit))
|
||||
|
||||
# We add the reified precedence to link the literal with the
|
||||
# times of the two tasks.
|
||||
|
||||
@@ -1762,7 +1762,7 @@ def prize_collecting_tsp():
|
||||
arcs = []
|
||||
for i in all_nodes:
|
||||
is_visited = model.NewBoolVar(f"{i} is visited")
|
||||
arcs.append([i, i, is_visited.Not()])
|
||||
arcs.append((i, i, is_visited.Not()))
|
||||
|
||||
obj_vars.append(is_visited)
|
||||
obj_coeffs.append(VISIT_VALUES[i])
|
||||
@@ -1773,7 +1773,7 @@ def prize_collecting_tsp():
|
||||
used_arcs[i, j] = is_visited.Not()
|
||||
continue
|
||||
arc_is_used = model.NewBoolVar(f"{j} follows {i}")
|
||||
arcs.append([i, j, arc_is_used])
|
||||
arcs.append((i, j, arc_is_used))
|
||||
|
||||
obj_vars.append(arc_is_used)
|
||||
obj_coeffs.append(-DISTANCE_MATRIX[i][j])
|
||||
|
||||
@@ -1776,7 +1776,7 @@ def prize_collecting_vrp():
|
||||
arcs = []
|
||||
for i in all_nodes:
|
||||
is_visited = model.NewBoolVar(f"{i} is visited")
|
||||
arcs.append([i, i, is_visited.Not()])
|
||||
arcs.append((i, i, is_visited.Not()))
|
||||
|
||||
obj_vars.append(is_visited)
|
||||
obj_coeffs.append(VISIT_VALUES[i])
|
||||
@@ -1787,7 +1787,7 @@ def prize_collecting_vrp():
|
||||
used_arcs[v][i, j] = is_visited.Not()
|
||||
continue
|
||||
arc_is_used = model.NewBoolVar(f"{j} follows {i}")
|
||||
arcs.append([i, j, arc_is_used])
|
||||
arcs.append((i, j, arc_is_used))
|
||||
|
||||
obj_vars.append(arc_is_used)
|
||||
obj_coeffs.append(-DISTANCE_MATRIX[i][j])
|
||||
|
||||
@@ -449,19 +449,19 @@ def single_machine_scheduling():
|
||||
for i in all_jobs:
|
||||
# Initial arc from the dummy node (0) to a task.
|
||||
start_lit = model.NewBoolVar("")
|
||||
arcs.append([0, i + 1, start_lit])
|
||||
arcs.append((0, i + 1, start_lit))
|
||||
# If this task is the first, set to minimum starting time.
|
||||
min_start_time = max(release_dates[i], setup_times[0][i])
|
||||
model.Add(starts[i] == min_start_time).OnlyEnforceIf(start_lit)
|
||||
# Final arc from an arc to the dummy node.
|
||||
arcs.append([i + 1, 0, model.NewBoolVar("")])
|
||||
arcs.append((i + 1, 0, model.NewBoolVar("")))
|
||||
|
||||
for j in all_jobs:
|
||||
if i == j:
|
||||
continue
|
||||
|
||||
lit = model.NewBoolVar("%i follows %i" % (j, i))
|
||||
arcs.append([i + 1, j + 1, lit])
|
||||
arcs.append((i + 1, j + 1, lit))
|
||||
|
||||
# We add the reified precedence to link the literal with the times of the
|
||||
# two tasks.
|
||||
|
||||
@@ -1721,7 +1721,7 @@ def main():
|
||||
continue
|
||||
|
||||
lit = model.NewBoolVar("%i follows %i" % (j, i))
|
||||
arcs.append([i, j, lit])
|
||||
arcs.append((i, j, lit))
|
||||
arc_literals[i, j] = lit
|
||||
|
||||
obj_vars.append(lit)
|
||||
|
||||
Reference in New Issue
Block a user