0

I need to define a constraint as follows:

mdl.add_constraints(p_pg[plan, segment] == np.exp(u_pg[plan, segment] for plan in range(1, p+1) for segment in range(1, g+1))

In this constraint both p_pg and u_pg are variable and are defined as mdl.continuous_var_dict. However I get the following error: loop of ufunc does not support argument 0 of type Var which has no callable exp method

Can anyone help how to define this constraint?

1 Answers1

0

exp is not linear so you could either try to do a piecewise linear approximation or use Constraint Programming within CPLEX.

See this example in Easy optimization with python

from docplex.cp.model import CpoModel

mdl = CpoModel(name='buses')
nbbus40 = mdl.integer_var(0,1000,name='nbBus40')
nbbus30 = mdl.integer_var(0,1000,name='nbBus30')
mdl.add(nbbus40*40 + nbbus30*30 >= 300)

#non linear objective
mdl.minimize(mdl.exponent(nbbus40)*500 + mdl.exponent(nbbus30)*400)

msol=mdl.solve()

print(msol[nbbus40]," buses 40 seats")
print(msol[nbbus30]," buses 30 seats") 
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15