Error from adding too many variables with addVars()
I'm trying to add a set of variables, 'x_jkjk' which has 7 indices.
When I run the model, it gives me the below error message.
-----------
Traceback (most recent call last):
File "model.py", line 321, in <module>
model_built = buildModel(computer, dict_input_path, dict_input_param, instance_paths, input_tuning_param)
File "model.py", line 172, in buildModel
x_jkjk = m.addVars(sender, receiver, sender, receiver, vehicle, type, scenario, vtype=GRB.INTEGER, name='x_jkjk')
File "model.pxi", line 2638, in gurobipy.Model.addVars
OverflowError: value too large to convert to int
-----------
I think the number of x_jkjk variable (20 * 20 * 20 * 20 * 2 * 2 * 40 = 25.6MM) is too large to handle.
Any suggestions to resolve this issue?
Thank you,
Kyoung
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
I cannot reproduce the error by adding this amount of variables. I tried
x_jkjk = m.addVars(20, 20, 20, 20, 2, 2, 40, vtype=GRB.INTEGER, name='x_jkjk')
and I don't get an error.
Could you post a minimal code example to reproduce the error?
0 -
Yes. I tried the line you provided and it works.
It is when I provide certain names to the set, addVars() gives an error.
For example, the below lines run okay.
-------------
import gurobipy as gp
from gurobipy import GRBscenario = ['wsw305i2_5-1', 'wsw305i2_5-2', 'wsw305i2_5-3', 'wsw305i2_5-4', 'wsw305i2_5-5', 'w305i2_5-1', 'w305i2_5-2', 'w305i2_5-3', 'w305i2_5-4', 'w305i2_5-5', 'wnw305i2_5-1', 'wnw305i2_5-2', 'wnw305i2_5-3', 'wnw305i2_5-4', 'wnw305i2_5-5', 'nw305i2_5-1', 'nw305i2_5-2', 'nw305i2_5-3', 'nw305i2_5-4', 'nw305i2_5-5', 'nnw305i2_5-1', 'nnw305i2_5-2', 'nnw305i2_5-3', 'nnw305i2_5-4', 'nnw305i2_5-5', 'n305i2_5-1', 'n305i2_5-2', 'n305i2_5-3', 'n305i2_5-4', 'n305i2_5-5', 'nne305i2_5-1', 'nne305i2_5-2', 'nne305i2_5-3', 'nne305i2_5-4', 'nne305i2_5-5', 'ne305i2_5-1', 'ne305i2_5-2', 'ne305i2_5-3', 'ne305i2_5-4', 'ne305i2_5-5']
sender = ['s002_GALVESTON', 's006_PORTARTHUR', 's007_PORTARTHUR', 's010_BAYTOWN', 's014_NASSAUBAY', 's015_LAKEJACKSON', 's020_HOUSTON', 's023_BEAUMONT', 's027_WEBSTER', 's029_HOUSTON', 's030_SUGARLAND', 's036_LEAGUECITY', 's044_RICHMOND', 's056_HOUSTON', 's058_THEWOODLANDS', 's060_HOUSTON', 's062_SUGARLAND', 's065_SUGARLAND', 's066_HOUSTON', 's071_NEDERLAND']
receiver = ['r001_HOUSTON', 'r002_GRANBURY', 'r003_HOUSTON', 'r004_GONZALES', 'r005_KINGWOOD', 'r006_BEAUMONT', 'r007_TOMBALL', 'r008_THEWOODLANDS', 'r009_PASADENA', 'r010_CONROE', 'r011_SUGARLAND', 'r012_HUMBLE', 'r013_THEWOODLANDS', 'r014_KATY', 'r015_RICHMOND', 'r016_SUGARLAND', 'r017_CYPRESS', 'r018_THEWOODLANDS', 'r019_HUNTSVILLE', 'r020_SUGARLAND']
ptype = ['p1', 'p2']
vehicle = ['v1', 'v2']print(len(sender), len(receiver), len(sender), len(receiver), len(vehicle), len(ptype), len(scenario))
m = gp.Model('model')
x_jkjk = m.addVars(sender, receiver, sender, receiver, vehicle, ptype, scenario, vtype=GRB.INTEGER, name='x_jkjk')-------------
These give an error.
------------
import gurobipy as gp
from gurobipy import GRBscenario = ['wsw305i2_5-1', 'wsw305i2_5-2', 'wsw305i2_5-3', 'wsw305i2_5-4', 'wsw305i2_5-5', 'w305i2_5-1', 'w305i2_5-2', 'w305i2_5-3', 'w305i2_5-4', 'w305i2_5-5', 'wnw305i2_5-1', 'wnw305i2_5-2', 'wnw305i2_5-3', 'wnw305i2_5-4', 'wnw305i2_5-5', 'nw305i2_5-1', 'nw305i2_5-2', 'nw305i2_5-3', 'nw305i2_5-4', 'nw305i2_5-5', 'nnw305i2_5-1', 'nnw305i2_5-2', 'nnw305i2_5-3', 'nnw305i2_5-4', 'nnw305i2_5-5', 'n305i2_5-1', 'n305i2_5-2', 'n305i2_5-3', 'n305i2_5-4', 'n305i2_5-5', 'nne305i2_5-1', 'nne305i2_5-2', 'nne305i2_5-3', 'nne305i2_5-4', 'nne305i2_5-5', 'ne305i2_5-1', 'ne305i2_5-2', 'ne305i2_5-3', 'ne305i2_5-4', 'ne305i2_5-5']
sender = ['s002_GALVESTON', 's006_PORTARTHUR', 's007_PORTARTHUR', 's010_BAYTOWN', 's014_NASSAUBAY', 's015_LAKEJACKSON', 's020_HOUSTON', 's023_BEAUMONT', 's027_WEBSTER', 's029_HOUSTON', 's030_SUGARLAND', 's036_LEAGUECITY', 's044_RICHMOND', 's056_HOUSTON', 's058_THEWOODLANDS', 's060_HOUSTON', 's062_SUGARLAND', 's065_SUGARLAND', 's066_HOUSTON', 's071_NEDERLAND']
receiver = ['r001_HOUSTON', 'r002_GRANBURY', 'r003_HOUSTON', 'r004_GONZALES', 'r005_KINGWOOD', 'r006_BEAUMONT', 'r007_TOMBALL', 'r008_THEWOODLANDS', 'r009_PASADENA', 'r010_CONROE', 'r011_SUGARLAND', 'r012_HUMBLE', 'r013_THEWOODLANDS', 'r014_KATY', 'r015_RICHMOND', 'r016_SUGARLAND', 'r017_CYPRESS', 'r018_THEWOODLANDS', 'r019_HUNTSVILLE', 'r020_SUGARLAND']
ptype = ['critical', 'non-crit']
vehicle = ['type00', 'type20']print(len(sender), len(receiver), len(sender), len(receiver), len(vehicle), len(ptype), len(scenario))
m = gp.Model('model')
x_jkjk = m.addVars(sender, receiver, sender, receiver, vehicle, ptype, scenario, vtype=GRB.INTEGER, name='x_jkjk')------------
The only change here is that I switched ptype from ['p1', 'p2'] to ['critical', 'non-crit'] and vehicle from ['v1', 'v2'] to ['type00', 'type20'].
It is interesting that in this unique case, the method generates the error. It seems there's a limit on the length of indexes.
0
Post is closed for comments.
Comments
3 comments