简体   繁体   中英

Cplex Decision Expression value limit

I have a decision expression in cplex opl,

dexpr float A = x[i]-b[i];

And i want A take values of 0 and bigger, what would be the syntax to do that?

The maxl() function is used for this purpose:

range I = 1..2;
dvar float+ x[I];
dvar float+ b[I];
dexpr float A[i in I] = maxl(x[i] - b[i], 0);

However, depending on how you use A it might be better to use a decision variable rather than a decision expression. Assuming your model is formulated so that A will always take values as small as possible (for example because non-negative values are penalized in the objective function) then you can use dvar float+ A[I] and add a constraint forall(i in I) A[i] >= x[i] - b[i] . This will implicitly make sure that A[i] is always the maximum between 0 and the difference. In some cases this can lead to more efficient solver behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM