Practice JuMP problem - scheduling LP questions

I am practising by translating a python LP scheduling example using JuMP.

I have been using a combination of the SteelT3 example and some older notebooks I found as guiding references, but have not been able to get everything working. I have also found this discourse thread but it didn’t help me.

I have been able to add variables and constraints to the model, but cannot figure out the objective function syntax. If my understanding is correct, it is good practice to use dictionaries to store everything but I am getting confused on how the dictionaries should be referenced throughout the problem.

I created a gist with my attempt so far, any help is appreciated.

What do you mean by “not working”?

There are two issues:

  1. you have some brackets in the wrong place. You need something like:
@objective(model, Min,
   sum(status[m,f] * production[m,f] * fixed_cost[m,f] * var_cost[m,f] for m in months,f in facts)
)
  1. status[m, f] * production[m, f] is variable * variable. Cbc can only solve mixed-integer linear problems.
1 Like

By not working, I meant I am able to successfully add variables and constraints to the model, but not an objective.

I went back and both my previous example as well as your code from point 1 result in the message:

ERROR: The solver does not support an objective function of type MathOptInterface.ScalarQuadraticFunction{Float64}.

I realize the problem is integer and have a Bin and Int flag in my variables, perhaps my title was misworded. I chose Cbc as I was following a previous exercise in the repo where they note the use of Cbc for the python examples.

Now that I am looking at it, something else must be going wrong, since it is showing a Float64 error but none of the dictionaries are showing as any kind of Float?

This error has nothing to do with Floats.

As @odow said you are multiplying two variables hence you get a quadratic function of the variables. The solver you have chosen, Cbc, does not support quadratic functions (like status[m, f] * production[m, f]) in the objective. That’s why you got the error saying that you solver (Cbc) does not support ScalarQuadraticFunctions:

You can solve this by selecting another solver, for Gurobi, CPLEX, Xpress will support quadratic functions in the objective, and will try to solve the problem if the objective function is convex.
If the objective function is not convex you can try Knitro for instance.

OK, I don’t have access to any of the commercial solvers, so I tried a new model using Ipopt since that has QP listed in the docs.
The objective function worked was added to the model.

@objective(model2, Min, sum(status[m,f] * production[m,f] * fixed_cost[m,f] * var_cost[m,f] for m in months,f in facts))

5000 status[1,A]*production[1,A] + 3000 status[1,B]*production[1,B] + 5500 status[2,A]*production[2,A] + 2400 status[2,B]*production[2,B] + 6000 status[3,A]*production[3,A] + 1800 status[3,B]*production[3,B] + ...

I then tried to run a preliminary solve!() before moving on and got an error flag on the Bin variable:

ERROR: MathOptInterface.UnsupportedConstraint{MathOptInterface.SingleVariable,MathOptInterface.ZeroOne}:MathOptInterface.SingleVariable-in-MathOptInterface.ZeroOneconstraints is not supported by the model

Is there a way for me to re-write the expressions to avoid the quadratic expression and be able to use Cbc?

My guess is that since you talked about solving an LP, you actually want

@objective(model, Min, sum(
    fixed_cost[m,f] * status[m,f] + var_cost[m,f] * production[m,f] 
    for m in months, f in facts))

This model can be solved using Cbc.

Just so this is clear, the original Python example is a mixed-integer LP which you could solve using CBC, but in your JuMP translation you’re using a completely different objective function. If the goal is truly to translate the Python example, you should be fixing the objective function rather than changing solvers, as @odow mentioned.

1 Like

Ahh ok, now that I am looking at them side by side I clearly see where my mistake was. I used the modified objective function above and the Cbc solver model happily accepted that.

While I am thinking about it , is there somewhere I can contribute finished problems as examples?

I spent a lot of time clicking through the JuliaOpt notebooks page but it seems like they are written using pre 0.19 syntax.

1 Like

is there somewhere I can contribute finished problems as examples?

Yes, please! https://github.com/JuliaOpt/JuMP.jl/tree/master/examples. Please pay attention to the structure of the existing examples: they get run in JuMP’s automated tests. (You can run the tests using this command https://github.com/JuliaOpt/JuMP.jl/blob/fd5ea00cb602145b677c136295b07cab6791f1b0/examples/run_examples.jl#L12)

I spent a lot of time clicking through the JuliaOpt notebooks page but it seems like they are written using pre 0.19 syntax.

We will have some news to share on this front soon.