JuMP: MathOptInterface.ScalarNonlinearFunction

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?

Hi @a_jae, welcome to the forum

A few questions:

  • What is the “function” in this context?
  • Do x and y have upper bounds?
  • What does if x is not equal to y mean? x and y are vectors with different length.

Thanks!

  • 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.

What about a formulation like this:

model = Model()
@variable(model, x_start[1:3] >= 0, Int)
@variable(model, x_length[1:3] >= 0, Int)
@variable(model, x_gap[1:3] >= 0, Int)
@constraints(model, begin
    # Sequence of jobs
    [j in 1:2], x_start[j+1] == x_start[j] + x_length[j] + x_gap[j]
    # Time horizon
    x_start[end] + x_length[end] <= 24
end)

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!

Instead of multiplying three terms together, define

@variable(model, z)
@constraint(model, z == q * (x - y))

and then have z * price in your objective.

1 Like