Skip to content

Conversation

@dnguyen227
Copy link
Contributor

@dnguyen227 dnguyen227 commented Oct 31, 2025

This PR extends JuMP.copy_extension_data in order to allow GDPModels to be an input to JuMP.copy_model().
JuMP.copy_extension_data does not receive a reference map as one of it's argument so it's impossible to recover disjunct constraints. Therefore another function was made to be called (DP.copy_gdp_data()) in order to populate the new model's GDPData. The workflow goes sequentiallty as in the example below.

using HiGHS, JuMP
import DisjunctiveProgramming as DP  
m = DP.GDPModel(HiGHS.Optimizer)
@variable(m, 0  x[1:2]  20)
@variable(m, Y[1:2], DP.Logical)
@constraint(m, [i = 1:2], [2,5][i]  x[i]  [6,9][i], DP.Disjunct(Y[1]))
@constraint(m, [i = 1:2], [8,10][i]  x[i]  [11,15][i], DP.Disjunct(Y[2]))
DP.@disjunction(m, Y)
@objective(m, Max, sum(x))

m_copy, ref_map = JuMP.copy_model(m)
lv_map = DP.copy_gdp_data(m, m_copy, ref_map)
set_optimizer(m, HiGHS.Optimizer)
set_optimizer_attribute(m, "output_flag", false) 

set_optimizer(m_copy, HiGHS.Optimizer)
set_optimizer_attribute(m_copy, "output_flag", false)

optimize!(m, gdp_method = DP.BigM())
optimize!(m_copy, gdp_method = DP.Hull())

In addition there is also copy_model_and_gdp_data to do both
An alternative would be to extend JuMP.copy_model itself but at a glance I believe there might be consequences when we want to have DP coexist with other packages and have the ability to copy.

@dnguyen227
Copy link
Contributor Author

@pulsipher this is ready for review.

@dnguyen227 dnguyen227 marked this pull request as draft November 2, 2025 22:09
@dnguyen227 dnguyen227 marked this pull request as ready for review November 2, 2025 22:52
Copy link
Collaborator

@pulsipher pulsipher 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, just some minor points to address

created more tests accordingly.
addition of test to check that model instances do not affect each other.
@dnguyen227 dnguyen227 requested a review from pulsipher November 3, 2025 18:54
Copy link
Collaborator

@pulsipher pulsipher left a comment

Choose a reason for hiding this comment

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

Looks good, just one more thing. Please add some comments make the code more readable. For example, a comment for each for loop in copy_gdp_data and some comments for the dispatch functions. Also, the new public functions should each have a docstring.

@dnguyen227 dnguyen227 requested a review from pulsipher November 3, 2025 21:52
Copy link
Collaborator

@pulsipher pulsipher left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@pulsipher pulsipher merged commit 5709764 into infiniteopt:master Nov 3, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants