Originally posted by: SystemAdmin
Do you read the data into the Python script and then create the model from within Python or do you turn the data directly into an LP file and then read that into Python.
In the first case you could just clean up things before submitting them to CPLEX as in this code snippet (note that 'ind' has duplicate names):
import cplex;
def cleanup(ind,val):
clean = dict()
for (i,v) in zip(ind,val):
if i in clean:
clean[i] = clean[i] + v
else:
clean[i] = v
return cplex.SparsePair(clean.keys(), clean.values())
ind = [ "x1", "x2", "x3", "x1" ]
val = [ 1.0, 2.0, 3.0, 4.0 ]
c = cplex.Cplex()
c.variables.add(names = [ "x1", "x2", "x3", "x4" ])
c.linear_constraints.add(lin_expr = [ cleanup(ind, val) ],
senses = "L",
rhs = [ 5.0 ])
c.write("test.lp")
#CPLEXOptimizers#DecisionOptimization