Error Messages/42554
Error message
The constraint 'Market_clearance' in the NLP defined in 'opt' appears to be conditional on one or more decision variables. While the NLP was being solved, the constraint evaluated to the value 1. However, earlier during the solve or preliminary analysis, at a different search point, the same constraint held an enabled comparison. The presence or absence of constraints cannot be conditional on decision variables, but apparently is here.
Cause
Consider the following example from within an optimization model:
Decision X
..
Constraint C :=
If X < 0 Then True else Exp(-r*X) <= c
The problem is, obviously, non-linear, hence it is an NLP. Now, as the optimizer starts solving this, the search trace might look like this:
Try X = 5, C is 34 <= 10
Try X = 3, C is 6 <= 10
Try X = -1, C is 1
On the third evaluation, the inherent structure of the constraint changed. For the first two evaluations, it contained a comparison, but then on the third evaluation it was just true -- no comparison at all. It is this situation that the error is complaining about. The structure of the constraint cannot depend on the decision variable -- if it is a single comparison for some of the possible values of the decision variables, it must be a single constraint for all values.
The same applies to the number of comparisons. Hence, a constraint like this would also be problematic:
If X < 0 Then Exp(-r*X) > c Else c0 <= Exp(-r*X) <= c
In this case, the constraint changes from being two comparisons (a cascaded comparison) to being a single comparison when X
goes negative. Again, that is a structural change in the constraint, which is not allowed in an NLP.
Remedy
In the first example, you can simply replace the True
value with a vacuous constraint:
Constraint C :=
If X < 0 Then 0 <= 1 Else Exp(-r*X) <= c
While equivalent, this preserves the structure of the constraint.
Enable comment auto-refresher