DebugStringVector->JoinDebugStringPtr; fix overflow in disjunctive and path cumul; fix routing model inside the sequence var

This commit is contained in:
lperron@google.com
2013-10-17 08:58:26 +00:00
parent 4fec39f4d3
commit 936dad1e7f
37 changed files with 434 additions and 400 deletions

View File

@@ -32,7 +32,7 @@ FLAGS = gflags.FLAGS
# We disable the following warning because it is a false positive on constraints
# like: solver.Add(x == 0)
# pylint: disable-msg=C6403
# pylint: disable=g-explicit-bool-comparison
def main(unused_argv):

View File

@@ -24,12 +24,8 @@ from google.apputils import app
from graph import pywrapgraph
def RunAssignmentOn4x4Matrix(forward_graph):
def RunAssignmentOn4x4Matrix():
"""Test linear sum assignment on a 4x4 matrix.
Arguments:
forward_graph: if true uses a ForwardStarGraph or a StarGraph to model
the assignment problem.
"""
num_sources = 4
num_targets = 4
@@ -39,28 +35,28 @@ def RunAssignmentOn4x4Matrix(forward_graph):
[45, 110, 95, 115]]
expected_cost = cost[0][3] + cost[1][2] + cost[2][1] + cost[3][0]
if forward_graph:
graph = pywrapgraph.ForwardStarGraph(num_sources + num_targets,
num_sources * num_targets)
assignment = pywrapgraph.ForwardEbertLinearSumAssignment(graph, num_sources)
else:
graph = pywrapgraph.StarGraph(num_sources + num_targets,
num_sources * num_targets)
assignment = pywrapgraph.EbertLinearSumAssignment(graph, num_sources)
assignment = pywrapgraph.LinearSumAssignment()
for source in range (0, num_sources):
for target in range(0, num_targets):
arc = graph.AddArc(source, num_sources + target)
assignment.SetArcCost(arc, cost[source][target])
assignment.AddArcWithCost(source, target, cost[source][target])
assignment.ComputeAssignment()
total_cost = assignment.GetCost()
print 'total cost', total_cost, '/', expected_cost
solve_status = assignment.Solve()
if solve_status == assignment.OPTIMAL:
print 'Successful solve.'
print 'Total cost', assignment.OptimalCost(), '/', expected_cost
for i in range(0, assignment.NumNodes()):
print 'Left node %d assigned to right node %d with cost %d.' % (
i,
assignment.RightMate(i),
assignment.AssignmentCost(i))
elif solve_status == assignment.INFEASIBLE:
print 'No perfect matching exists.'
elif solve_status == assignment.POSSIBLE_OVERFLOW:
print 'Some input costs are too large and may cause an integer overflow.'
def main(unused_argv):
RunAssignmentOn4x4Matrix(True)
RunAssignmentOn4x4Matrix(False)
RunAssignmentOn4x4Matrix()
if __name__ == '__main__':
app.run()

View File

@@ -47,7 +47,7 @@ def main(unused_argv):
solver.Add(1000*s + 100*e + 10*n + d + 1000*m + 100*o + 10*r + e ==
10000*m + 1000*o + 100*n + 10*e + y)
# pylint: disable-msg=C6403
# pylint: disable=g-explicit-bool-comparison
solver.Add(s != 0)
solver.Add(m != 0)

View File

@@ -24,6 +24,8 @@
(forbidden arcs).
"""
import random
from google.apputils import app
@@ -33,11 +35,11 @@ from constraint_solver import pywraprouting
FLAGS = gflags.FLAGS
gflags.DEFINE_integer('tsp_size', 10,
'Size of Traveling Salesman Problem instance.')
'Size of Traveling Salesman Problem instance.')
gflags.DEFINE_boolean('tsp_use_random_matrix', True,
'Use random cost matrix.')
'Use random cost matrix.')
gflags.DEFINE_integer('tsp_random_forbidden_connections', 0,
'Number of random forbidden connections.')
'Number of random forbidden connections.')
gflags.DEFINE_integer('tsp_random_seed', 0, 'Random seed.')