Eldon Gunn
unread,May 24, 2010, 11:50:11 PM5/24/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Gurobi Optimization
I am trying to extract a small model from a larger model. I started
with a model "mod " and am trying to create a smaller model "
smallm". However, the smallm.AddVar() is giving me an error when I
try to include a column object in the add. If I don't include the
column object, I can do the addVar but I end up with a model with no
coefficients.
I am attaching the script that I am running along with the run
results . The run shows the error message
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "model.pxi", line 1237, in gurobipy.Model.addVar (../../src/
python/gurobipy.c:23217)
gurobipy.GurobiError: Problem adding variables
It looks to me as if this is an internal Gurobi error but I don't know
what it means
If I run the script with the "column =" commented out, it runs fine
but I end up with no coefficients in the model.
I am new to both Python and Gurobi so I may just be doing something
stupid. If you can see what it is, please let me know and excuse my
ignorance.
As you can see from the runs, I am using Python 2.6.1 on a Mac
powerbook running Snow Leopard 10.6.3
Thanks for any help you can give me
Eldon Gunn
Script
import sys
import math
from gurobipy import *
mod=read("500_1.mps")
mod.ModelSense=-1
smallm=Model("Small Model")
mod.printStats()
cons = mod.getConstrs()
nrows=mod.NumConstrs
nvars=mod.NumVars
numGub=0
for i in range(nrows):
if cons[i].ConstrName[0:3] == 'ARE' :
numGub=numGub+1
else:
smallm.addConstr(0,cons[i].Sense, cons[i].RHS,
cons[i].ConstrName)
smallm.update()
numGub
vars=mod.getVars()
lastP=0
for i in range(nvars):
if vars[i].VarName[0] =='P' :
lastP=lastP+1
else:
colob=mod.getCol(vars[i])
newvar= smallm.addVar(lb=vars[i].LB, ub=vars[i].UB,
obj=vars[i].Obj, \
vtype=vars[i].Vtype, name=vars[i].VarName),
column=colob)
lastP
smallm.update()
smallm
Run results:
Last login: Sun May 23 11:32:06 on ttys000
Macintosh-140:~ eldongunn1$
Macintosh-140:~ eldongunn1$ bash
bash-3.2$ cd Doc*/500*y
bash-3.2$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import math
>>> from gurobipy import *
>>>
>>> mod=read("500_1.mps")
Read MPS format model from file 500_1.mps
Reading time = 0.01 seconds
FORESTLP: 584 Rows, 4779 Columns, 23889 NonZeros
>>> mod.ModelSense=-1
>>> smallm=Model("Small Model")
>>>
>>> mod.printStats()
Statistics for model FORESTLP :
Sizes : 584 Constrs, 4779 Vars, 23889 NZs
Matrix coefficient range : [ 1, 416.91 ]
Objective coefficient range : [ 0.52033, 10000 ]
RHS coefficient range : [ 0.01, 600935 ]
>>> cons = mod.getConstrs()
>>> nrows=mod.NumConstrs
>>>
>>> nvars=mod.NumVars
>>> numGub=0
>>>
>>>
>>> for i in range(nrows):
... if cons[i].ConstrName[0:3] == 'ARE' :
... numGub=numGub+1
... else:
... smallm.addConstr(0,cons[i].Sense, cons[i].RHS,
cons[i].ConstrName)
...
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
<gurobi.Constr Not Yet Added>
>>> smallm.update()
>>> numGub
500
>>>
>>> vars=mod.getVars()
>>>
>>> lastP=0
>>> for i in range(nvars):
... if vars[i].VarName[0] =='P' :
... lastP=lastP+1
... else:
... colob=mod.getCol(vars[i])
... newvar= smallm.addVar(lb=vars[i].LB, ub=vars[i].UB,
obj=vars[i].Obj, \
... vtype=vars[i].Vtype, name=vars[i].VarName,
column=colob)
...
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "model.pxi", line 1237, in gurobipy.Model.addVar (../../src/
python/gurobipy.c:23217)
gurobipy.GurobiError: Problem adding variables
>>> lastP
4735
>>>
>>> smallm.update()
>>> smallm
<gurobi.Model Continuous instance Small Model: 84 constrs, 0 vars,
Parameter changes: LogFile=gurobi.log>
>>>
>>>
>>>
>>>
>>>