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.
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?
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))
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.ZeroOne constraints 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?
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.
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.