is there a way to run a function only under certain conditions? For example, I have the following model:

using JuMP, Gurobi;
model = Model(Gurobi.Optimizer); @variable(model, x[1:t] >= 0, Int); @variable(model, y[1:h] >= 0, Int);

Is it possible to tell the model that the function should only be run if x is not equal to y? The problem is that I cannot add another decision variable to the function, otherwise the following error appears:

The solver does not support an objective function of type MathOptInterface.ScalarNonlinearFunction.

Else you could simply initialize a binary variable that is 0 when x=y. Is there another way?

ItÂ´s a storage cost function. x and y are different production steps. x stands for the end of the first step, y for the beginning of the 2nd step.

they do have upper bounds: If the production horizon is 1 day, then every production step needs to be between 0 and 24 hours.

if x ends at the same time as y starts. there is no need to park the product in between which leads to storage costs per hour. So the higher the gap, the larger the costs. If the gap is 0, the storage costs are 0.

So my @expression should basically look like this: q*(x-y)*price

q is a binary variable that indicates whether production takes place (=1) or not (=0). It should work like this. But now I have also added the price as a decision variable. So there is one variable too much.

Thatâ€™s why I thought about defining the costs regardless of how long they are stored. Then there is a variable less in the function.

Then I would only have to add that if x and y take place at the same time, no costs are incurred. Here is where I struggle.

Can you do anything with this? Iâ€™m on the road and unfortunately canâ€™t post any code. Thank you!