Skip to content
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

Print constraints/variables in set form instead of scalarized #2171

Closed
odow opened this issue Feb 19, 2020 · 3 comments
Closed

Print constraints/variables in set form instead of scalarized #2171

odow opened this issue Feb 19, 2020 · 3 comments

Comments

@odow
Copy link
Member

odow commented Feb 19, 2020

Currently, we get

model = Model()
@variable(model, x[1:2] >= 0)
@constraint(model, c[i = 1:2], x[i] + i >= 0)
print(model)
# gives
Feasibility
Subject to
 c[1] : x[1]  -1.0
 c[2] : x[2]  -2.0
 x[1]  0.0
 x[2]  0.0

@claytonpbarrows suggests that we simplify this printing to

Feasibility
Subject to
 c[i=1:2] : x[i] + i ≥ 0
 x[i=1:2] ≥ 0.0

where the expressions are taken directly from the macro form.

This is particularly useful in large models, where the number of unique (parameterized) constraints is small, but each constraint is indexed over a large set.

@mlubin
Copy link
Member

mlubin commented Feb 19, 2020

This requires a ton of finicky infrastructure that we previously removed (see, e.g., #795) and I think it's useful primarily for a narrow range of models where the code itself should be similarly simple to read, so the printing doesn't add much information.

As soon as you have programmatic generation of the model and/or anonymous variables, it becomes a lot more complex to decide how to compress and print the index sets. Should we be remembering and presenting sums as the user entered them? What if the constraints had sub-expressions, should we print the names of the expressions or their contents? Do any other modeling interfaces as flexible as JuMP have similar fancy printing like this?

I'd prefer to not print the model or come up with more concise summaries when the full print-out is too large to be readable: #957.

@odow
Copy link
Member Author

odow commented Feb 19, 2020

I guess the "concise summary" is what we're after. I'm aware of the code complexity issue.

The motivation is, given a PowerSimulations.jl model, print a summary for the user showing what algebraic model they are solving.

@odow
Copy link
Member Author

odow commented Oct 11, 2021

Closing because explicit printing now only happens with print(model). To print a concise summary, use show(model).

julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(model, x[1:2] >= 0)
2-element Vector{VariableRef}:
 x[1]
 x[2]

julia> @constraint(model, c[i = 1:2], x[i] + i >= 0)
2-element Vector{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.GreaterThan{Float64}}, ScalarShape}}:
 c[1] : x[1]  -1.0
 c[2] : x[2]  -2.0

julia> print(model)
Feasibility
Subject to
 c[1] : x[1]  -1.0
 c[2] : x[2]  -2.0
 x[1]  0.0
 x[2]  0.0

julia> show(model)
A JuMP Model
Feasibility problem with:
Variables: 2
`AffExpr`-in-`MathOptInterface.GreaterThan{Float64}`: 2 constraints
`VariableRef`-in-`MathOptInterface.GreaterThan{Float64}`: 2 constraints
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: c, x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants