# Access infeasible optimization results ( GLPK with semicontinuous variable )

**URL:** <https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [April 25, 2021, 5:32am UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972 "2021-04-25T05:32:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Runhong\_Huang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/runhong_huang/32/16663_2.png) [@Runhong\_Huang](https://discourse.julialang.org/u/Runhong_Huang)\
**Post date:** [April 25, 2021, 5:32am UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972/1 "2021-04-25T05:32:55Z")

</div>

Hi all,

I have a question regarding accessing infeasible optimization results.

For example, the following optimization does not have a feasible solution. However, despite the infeasibility, it is still able to give the value of x and y.

```julia
model = Model()
set_optimizer(model, GLPK.Optimizer)
@variable(model, x >= 6.0)
@variable(model, y >= 6.0)
@objective(model, Max, 2* x + y )
@constraint(model, x+y <= 11.0)
@constraint(model, x >= 1.0)
optimize!(model)
value.(x)

```

When there is a semicontinuous variable, it returns the following errors when I was trying to get the variable value.

![image (14)](https://global.discourse-cdn.com/julialang/original/3X/1/d/1d684d24847e138c5e88ebff07b22f923d70424f.png)

```julia
model = Model()
set_optimizer(model, GLPK.Optimizer)
@variable(model, x in MOI.Semicontinuous(6.0, 12.0))
@variable(model, y >= 6.0)
@objective(model, Max, 2* x + y )
@constraint(model, x >= 1.0)
@constraint(model, x+y <= 11.0)
optimize!(model)
value.(y)

```

Can someone help me to understand why I am able to get “comprised” results when there is no feasible solution? However, when I use semicontinuous variables, I cannot get the value of those variables?

Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 25, 2021, 8:52am UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972/2 "2021-04-25T08:52:04Z")

</div>

Read [Solutions · JuMP](https://jump.dev/JuMP.jl/stable/manual/solutions/#Primal-solution-status)

You need to check the solution statuses.

---

<div class="post-metadata">

**Author:** ![cvanaret](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cvanaret/32/11594_2.png) [@cvanaret](https://discourse.julialang.org/u/cvanaret)\
**Post date:** [April 25, 2021, 3:19pm UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972/3 "2021-04-25T15:19:21Z")

</div>

It depends on the solvers, but some revert to minimizing the constraint violation when they detect that the problem is infeasible. In this case, the point that you retrieve may be a minimizer of the constraint violation.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 25, 2021, 9:55pm UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972/4 "2021-04-25T21:55:49Z")

</div>

To be clear, you should never rely on a solver returning an infeasible point, or that the infeasible point represents some minimal constraint violation.

The correct way to handle this is to use the status reporting mechanisms.

```nohighlight
if termination_status(model) == MOI.INFEASIBLE
    if primal_status(model) == MOI.NO_SOLUTION
        # No solution is available. Calling `value(x)` may thrown an error or return arbitrary values.
    elseif primal_status(model) == MOI.INFEASIBLE_POINT
        # We know only that the point is infeasible. There are no guarantees of quality.
    end
end

```

---

<div class="post-metadata">

**Author:** ![Runhong\_Huang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/runhong_huang/32/16663_2.png) [@Runhong\_Huang](https://discourse.julialang.org/u/Runhong_Huang)\
**Post date:** [April 25, 2021, 10:40pm UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972/5 "2021-04-25T22:40:38Z")

</div>

Thank you very much for your explanation. Despite the infeasibility, it sometimes is helpful to be able to get points where minimize the constraint violation. However, when I use semicontinuous variables, it seems that I cannot get the values.

---

<div class="post-metadata">

**Author:** ![Runhong\_Huang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/runhong_huang/32/16663_2.png) [@Runhong\_Huang](https://discourse.julialang.org/u/Runhong_Huang)\
**Post date:** [April 25, 2021, 10:55pm UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972/6 "2021-04-25T22:55:47Z")

</div>

Hi, oscar,

Thank you very much for your reply!

I understand that we should not rely on infeasible results, however, it sometimes really helpful to be able to obtain minimal constraint violation points. It really helps me to further analyze the problem.

Is there any way I can obtain the “minimal constraint violation point” when I have semicontinuous variables?

Thank you very much,

Best regards,

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 28, 2021, 9:29pm UTC](https://discourse.julialang.org/t/access-infeasible-optimization-results-glpk-with-semicontinuous-variable/59972/7 "2021-04-28T21:29:03Z")

</div>

> Is there any way I can obtain the “minimal constraint violation point” when I have semicontinuous variables?

Formulate a new optimization problem, where you add slack variables to the constraints and minimize their sum.
