google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
11k stars 2.1k forks source link

DuplicateFlagError when running Google or-tools TSP constraint solver on multiple collectsions #87

Closed orwant closed 8 years ago

orwant commented 9 years ago

Originally reported on Google Code with ID 71

While attempting to solve the TSP for multiple sets of points (by looping over all the
sets and calling the the constraint solver on each set), an error is thrown: gflags.DuplicateFlagError:
The flag 'tsp_size' is defined twice.

This is because I have the following code re-defining the gflag tsp_size depending
on the size of a particular problem (not all sets are the same size): `gflags.DEFINE_integer('tsp_size',
len(points), 'Size of Traveling Salesman Problem instance.')`

Everything works fine on the first set; the error is thrown upon processing the second
set

How can I make separate instances of the constraint solver within the same run of a
program, considering I have multiple graphs to loop over?

Reported by s.gonzalez.garza on 2015-06-28 20:15:24

orwant commented 9 years ago
Solved my problem:

for graph in graphs:
    import shp
    shp.run(graph)
    del sys.modules['shp']

Reported by s.gonzalez.garza on 2015-06-29 04:19:05