Skip to content

Added functions to interact with JuMP#17

Merged
guilhermebodin merged 5 commits intojump-dev:masterfrom
caioluke:master
Jul 6, 2021
Merged

Added functions to interact with JuMP#17
guilhermebodin merged 5 commits intojump-dev:masterfrom
caioluke:master

Conversation

@caioluke
Copy link
Copy Markdown
Contributor

@caioluke caioluke commented Jun 23, 2021

closes #1

  • Creation of necessary functions in order to interact with the JuMP interface, e.g MOI.is_empty, MOI.get, MOI.set, MOI.supports

  • Creation of mutable struct 'ParameterValue' which is used to assign value to parameters

  • Correction of a bug in which a ScalarQuadraticFunction was not treated as a ScalarAffineFunction when the quadratic term was a product of 2 parameters

  • Added some tests with JuMP

optimizer = POI.ParametricOptimizer(GLPK.Optimizer())
    

c = [4.0, 3.0]
A1 = [2.0, 1.0, 1.0]
A2 = [1.0, 2.0, 1.0]
b1 = 4.0
b2 = 4.0

# ===== Create model with parameters =====
model = direct_model(optimizer)

@variable(model, x[i=1:2] >= 0)

# Parameters set to 0
@variable(model, y in POI.Parameter(0))
@variable(model, w in POI.Parameter(0))
@variable(model, z in POI.Parameter(0))

@constraint(model, 2*x[1] + x[2] + y <= 4)
@constraint(model, x[1] + 2*x[2] + z <= 4)

@objective(model, Max, sum(c[i]*x[i] for i=1:2) + w)

optimize!(model)
println(model)

Max 4 x[1] + 3 x[2]
Subject to
 x[1] >= 0.0
 x[2] >= 0.0
 x[2] + 2 x[1] <= 4.0
 2 x[2] + x[1] <= 4.0

# ===== Set parameter y to 2 =====
# A better way of assigning values to parameters
MOI.set(model, POI.ParameterValue(), y, 2.0)

optimize!(model)
println(model)

Max 4 x[1] + 3 x[2]
Subject to
 x[1] >= 0.0
 x[2] >= 0.0
 x[2] + 2 x[1] <= 2.0
 3 x[1] + 2 x[2] <= 4.0

…nterface, e.g MOI.is_empty, MOI.get, MOI.set, MOI.supports

	Creation of attribute 'parameters_name' in 'ParametricOptimizer'

	Creation of mutable struct 'ParameterRef'
@joaquimg
Copy link
Copy Markdown
Member

@caioluke

I have an ideia to make it better.
We can make a:
struct ParameterValue <: MOI.AbstractVariableAttribute end
Then we can simply call:

MOI.set(model, POI.ParameterValue(), y, 2.0)

instead of:

cy = MOI.get(backend(model), POI.ParameterRef(), index(y))
MOI.set(backend(model), MOI.ConstraintSet(), cy, POI.Parameter(2.0))

@odow @blegat

some questions for you too...

should we add JuMP as a Test/Doc dependency and avoid as much as we can add it as an actual dependency?

Other suggestions?

@joaquimg joaquimg requested review from blegat and odow June 23, 2021 18:44
@odow
Copy link
Copy Markdown
Member

odow commented Jun 23, 2021

struct ParameterValue <: MOI.AbstractVariableAttribute end
Then we can simply call:

MOI.set(model, POI.ParameterValue(), y, 2.0)

👍 Yeah this would be better.

caioluke added 3 commits June 25, 2021 12:14
- Corrected a bug in which a ScalarQuadraticFunction was not treated as a ScalarAffineFunction when the quadratic term was a product of 2 parameters
- Added tests interacting with JuMP
- JuMP model with linear constraints now supports POI.Parameter if the parameter is not multiplying a variable
Copy link
Copy Markdown
Member

@blegat blegat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good overall, thanks! There are however a few that are currently incorrect, I would recommend at least leaving at TODO explaining why it's incorrect

@caioluke
Copy link
Copy Markdown
Contributor Author

caioluke commented Jul 5, 2021

@blegat with @guilhermebodin we addressed most of your comments and we left some TODO's for the future. If you have any tips on how to implement those changes that would be great.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 5, 2021

Codecov Report

Merging #17 (fd38e5b) into master (d81ab0c) will decrease coverage by 3.85%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
- Coverage   94.24%   90.38%   -3.86%     
==========================================
  Files           1        1              
  Lines         330      416      +86     
==========================================
+ Hits          311      376      +65     
- Misses         19       40      +21     
Impacted Files Coverage Δ
src/ParametricOptInterface.jl 90.38% <71.42%> (-3.86%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d81ab0c...fd38e5b. Read the comment docs.

@guilhermebodin guilhermebodin merged commit 2d1cf47 into jump-dev:master Jul 6, 2021
ianfiske pushed a commit to ianfiske/ParametricOptInterface.jl that referenced this pull request Oct 12, 2023
Added functions to interact with JuMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Test JuMP

6 participants