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

Added relax_constraint, similar to relax_integrality #3113

Closed
wants to merge 5 commits into from

Conversation

this-josh
Copy link

I've added a method to relax the specified constraints, here is how it works:

    model = Model()
    @variable(model, x)
    @constraint(model, c1, x1)
    @test is_valid(model, c1)
    unrelax = relax_constraint(model, c1)
    @test !is_valid(model, c1)
    unrelax()
    @test is_valid(model, model[:c1])

Currently I haven't documented it, if you're interesting in merging this I can add some docs and more thorough testing (e.g. with Non linear constraints).

@odow
Copy link
Member

odow commented Oct 24, 2022

Hi @this-josh, a good first step, before opening a PR, is to open an issue to discuss a proposed change (see step 1: https://jump.dev/JuMP.jl/stable/developers/contributing/#Contribute-code-to-JuMP).

What is the motivation for this? Why is something like delete not sufficient?

The unregister logic is a bit tricky to get right. It won't work for something like

model = Model()
@variable(model, x)
@constraint(model, c[i=1:2], x <= i)
@test is_valid(model, c[1])
unrelax = relax_constraint(model, c[1])
@test !is_valid(model, c[1])
unrelax()
@test is_valid(model, model[:c][1])

Instead of deleting the constraint, and then re-adding, you might be interested in relaxing the feasibility of the problem: jump-dev/MathOptInterface.jl#1995 and #3034.

@codecov
Copy link

codecov bot commented Oct 24, 2022

Codecov Report

Base: 97.63% // Head: 97.62% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (c114e30) compared to base (b4eee84).
Patch coverage: 94.11% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3113      +/-   ##
==========================================
- Coverage   97.63%   97.62%   -0.02%     
==========================================
  Files          32       32              
  Lines        4364     4381      +17     
==========================================
+ Hits         4261     4277      +16     
- Misses        103      104       +1     
Impacted Files Coverage Δ
src/constraints.jl 96.24% <94.11%> (-0.15%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@this-josh
Copy link
Author

HI, I appreciate that but in this case I had to write the code for my own purposes. With the code written it seemed clearer to open this PR and combine discussion into the PR. In hindsight I could have just included the code snippet in an Issue.

This was useful for me when doing a feasibility pump. I have some non-linear constraints, and my own linear relaxation. Using this I can selectively choose between them.

You're right, I would prefer to avoid deleting constraints. After looking at your links I expect #1995 should cover this in a more elegant way.

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.

2 participants