-
Notifications
You must be signed in to change notification settings - Fork 94
Implement print for MOI.ModelLike #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Do you agree with the plan to redirect JuMP printing to printing of the backend (possibly setting some parameters so that the printing is the same) ? Currently, the printing of the MOI model is different from what we currently have in JuMP so we might at least need an option so that the printing is the same, or do you want the printing on JuMP to change ? |
There are a couple of differences we could discuss: MOI printing
JuMP printing
I'm in favor of this printing style, because it makes everything more explicit. (One problem is that I have seen questions on discourse asking why |
I understand that the default printing for a JuMP model and an MOI model might be different but there given that the JuMP model is completely represented by an MOI model and that someone could also want the JuMP printing style given an MOI model, we could have a printing function with option such as
I'm not saying this PR should implement all of these but it's best if we're on the same page. I always find myself wanting to print an MOI model and wanting such options and I think it's best if we don't keep twice almost the same code. |
Okay, adding options might be a good thing. Let's hold-off merging, and I'll have a play.
Yes. Particularly if you could print a model, and then the inner bridged model to see the difference. |
@blegat, this now allows: julia> print(model; simplify_coefficients = true, print_constraint_types = false)
Minimize: 2 + x + 3.1 y - 1.2 z
Subject to:
x - y == 0
2 x >= 1
2 x ∈ [1, 2]
y - z + 2 x² <= 1
┌ ┐
│x│
│y│
└ ┘ ∈ SecondOrderCone(2)
┌ ┐
│1│
│x│
│y│
└ ┘ ∈ SecondOrderCone(2)
┌ ┐
│x²│
│y │
│1 │
└ ┘ ∈ ExponentialCone()
┌ ┐
│1 │
│x²│
│y │
└ ┘ ∈ ExponentialCone()
x >= 0.1
z ∈ ℤ
x ∈ {0, 1}
y ∈ {0, 1}
julia> MOIU.latex_formulation(model; simplify_coefficients = true, print_constraint_types = false)
$$ \begin{aligned}
\min\quad & 2 + x + 3.1 y - 1.2 z \\
\text{Subject to}\\
& x - y = 0 \\
& 2 x \ge 1 \\
& 2 x \in \[1, 2\] \\
& y - z + 2 x^2 \le 1 \\
& \begin{bmatrix}
x\\
y\end{bmatrix} \in \text{SecondOrderCone(2)} \\
& \begin{bmatrix}
1\\
x\\
y\end{bmatrix} \in \text{SecondOrderCone(2)} \\
& \begin{bmatrix}
x^2\\
y\\
1\end{bmatrix} \in \text{ExponentialCone()} \\
& \begin{bmatrix}
1\\
x^2\\
y\end{bmatrix} \in \text{ExponentialCone()} \\
& x \ge 0.1 \\
& z \in \mathbb{Z} \\
& x \in \{0, 1\} \\
& y \in \{0, 1\} \\
\end{aligned} $$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So great we finally have this!
TODO
Utilities
.Example
Open to suggestions for improvements. Here is what it looks like at present. Since it's MOI, I wanted to explicitly state which function-set pairs were in the model. I'd also be in favor of adding these to JuMP to make it more explicit.
Closes #1144
Closes #1180