Quicker data import for problems already defined in the standardized format

32 views
Skip to first unread message

Volkan Özcan

unread,
Jan 31, 2024, 12:57:22 AMJan 31
to Pyomo Forum
Hello,

I have the optimization problem defined already in the standard format (there is an objective vector, A_ineq inequality and A_eq equality matrices with the corresponding b_ineq and b_eq vectors). 

I can import them as a pyomo model with the following code, but it takes too much time if matrices are big. I guess this is because of the loops; is there a way to make this import more quickly?

Best wishes

# Create a model
model = pyo.ConcreteModel()
# Number of variables
n_vars = len(f_obj)
# Define variables, all binary
model.x = pyo.Var(range(n_vars), domain=pyo.Binary)
# Objective function
model.objective = pyo.Objective(expr=sum(f_obj[i] * model.x[i] for i in range(n_vars)), sense=pyo.minimize)
# Adding inequality constraints
model.ineq_constraints = pyo.ConstraintList()
for i in range(len(Aineq)):
    model.ineq_constraints.add(sum(Aineq[i][j] * model.x[j] for j in range(n_vars)) <= bineq[i])

# Adding equality constraints
model.eq_constraints = pyo.ConstraintList()
for i in range(len(Aeq)):
    model.eq_constraints.add(sum(Aeq[i][j] * model.x[j] for j in range(n_vars)) == beq[i])

Reply all
Reply to author
Forward
0 new messages