# Which JuMP solvers support compute\_conflict!?

**URL:** <https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, optimization\
**Created:** [March 8, 2023, 1:06pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733 "2023-03-08T13:06:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [March 8, 2023, 1:06pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/1 "2023-03-08T13:06:18Z")

</div>

I am trying to show the constraints of an infeasible problem in a human-readable format and found compute\_conflict! in the docs:

[Solutions · JuMP](https://jump.dev/JuMP.jl/stable/reference/solutions/#JuMP.compute_conflict)!

The COSMO.jl solver doesn’t support the function. Is there any other pure Julia solver that supports the function? My optimization problem is very simple (linear objective + linear/interval constraints).

---

<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:** [March 8, 2023, 5:22pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/2 "2023-03-08T17:22:29Z")

</div>

Essentially just cplex and gurobi. Its a niche feature.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [March 8, 2023, 5:54pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/3 "2023-03-08T17:54:45Z")

</div>

Thank you @odow for the quick reply. Can you elaborate on what it does exactly? I understand that it shows all constraints that “conflict” with each other causing the infeasibility of the problem, is that right?

Do you have suggestions on how to report to end users the constraints that are problematic? I also found ` primal_feasibility_report(model)` but it returns a long list of constraints and the excesses for each. I wonder if there is a simple function that can suggest users to relax a few constraints of the problem.

---

<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:** [March 8, 2023, 6:06pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/4 "2023-03-08T18:06:54Z")

</div>

Its a heuristic that removes contraints and variables while keeping the model infeasible. The resulting system can still be very large, and might be one of many possible systems that could have been returned.

You probably want instead [Debugging · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/debugging/#Penalty-relaxation)

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [March 22, 2023, 12:59pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/5 "2023-03-22T12:59:45Z")

</div>

@mtanneau helped to write a function that returns all violations of an infeasible model:

```julia
function violations(model, tol=1e-4)
	res = []
	if termination_status(model) == INFEASIBLE &&
	   dual_status(model) == INFEASIBILITY_CERTIFICATE
		for (F, S) in list_of_constraint_types(model)
			cons = all_constraints(model, F, S)
			for i in eachindex(cons)
				if isassigned(cons, i)
					con = cons[i]
					if abs(dual(con)) > tol
						push!(res, con)
					end
				end
			end
		end
	end
	res
end

```

This function works well with the Tulip.jl and COSMO.jl solvers, but it doesn’t work with HiGHS.jl which is the solver that was more stable for my application.

Any idea on how to make it work with HiGHS.jl as well? Any help is appreciated.

Here is a [MWE](https://github.com/ds4dm/Tulip.jl/issues/134#issuecomment-1462442204) model to test.

---

<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:** [March 22, 2023, 7:16pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/6 "2023-03-22T19:16:07Z")

</div>

HiGHS can prove infeasibility in presolve, which means it doesn’t find an infeasibility certificate. If you turn off presolve, it can find an infeasibility certificate.

```plaintext
julia> optimize!(model)
Running HiGHS 1.5.1 [date: 1970-01-01, git hash: 93f1876e4]
Copyright (c) 2023 HiGHS under MIT licence terms
Presolving model
Problem status detected on presolve: Infeasible
Model status : Infeasible
Objective value : 0.0000000000e+00
HiGHS run time : 0.00
ERROR: No invertible representation for getDualRay

julia> solution_summary(model)
* Solver : HiGHS

* Status
  Result count : 0
  Termination status : INFEASIBLE
  Message from the solver:
  "kHighsModelStatusInfeasible"

* Candidate solution (result #1)
  Primal status : NO_SOLUTION
  Dual status : NO_SOLUTION
  Objective bound : 0.00000e+00
  Relative gap : Inf

* Work counters
  Solve time (sec) : 2.24088e-04
  Simplex iterations : 0
  Barrier iterations : 0
  Node count : -1

julia> set_attribute(model, "presolve", "off")

julia> optimize!(model)
Solving LP without presolve or with basis
Using EKK dual simplex solver - serial
  Iteration Objective Infeasibilities num(sum)
          0 -9.0000000000e+03 Ph1: 20(22998); Du: 9(9) 0s
         26 6.0000000000e+02 0s
Model status : Infeasible
Simplex iterations: 26
Objective value : 6.0000000000e+02
HiGHS run time : 0.00

julia> solution_summary(model)
* Solver : HiGHS

* Status
  Result count : 1
  Termination status : INFEASIBLE
  Message from the solver:
  "kHighsModelStatusInfeasible"

* Candidate solution (result #1)
  Primal status : NO_SOLUTION
  Dual status : INFEASIBILITY_CERTIFICATE
  Objective value : 6.00000e+02
  Objective bound : 0.00000e+00
  Relative gap : Inf
  Dual objective value : 1.00000e+02

* Work counters
  Solve time (sec) : 3.47093e-03
  Simplex iterations : 26
  Barrier iterations : 0
  Node count : -1

```

A few other comments:

I posted this above, but it seems that you probably want to use `relax_with_penalty!` instead: [Debugging · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/debugging/#Penalty-relaxation)

Your modeling can be improved. Instead of adding bounds using `@constraint`, add them in the `@variable` macro. So instead of:

```julia
@variable(model, Vp[pset])
@constraint(model, [0.,0.] .≤ Vp .≤ [100.,100.])

```

do

```julia
@variable(model, 0 <= Vp[pset] <= 100)

```

The former adds two new rows to the constraint matrix, and leaves the variables unbounded. The latter explicitly sets the variable bounds, which the solver has special support for.

Also, terms like `rcosts = sum(Vr[r] for r in rset)` can be slow to construct outside the macros. You’re better off calling `@objective(model, Min, sum(Vr) + sum(Vb) - sum(Vc))`.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [March 23, 2023, 1:53pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/7 "2023-03-23T13:53:34Z")

</div>

> [@odow](#):
>
> Your modeling can be improved. Instead of adding bounds using `@constraint`, add them in the `@variable` macro. So instead of:
> 
> ```julia
> @variable(model, Vp[pset])
> @constraint(model, [0.,0.] .≤ Vp .≤ [100.,100.])
> 
> ```
> 
> do
> 
> ```julia
> @variable(model, 0 <= Vp[pset] <= 100)
> 
> ```

Thanks for the advise 🙂 In my real case I have a pset that is a vector of tuples of strings. I then have two dictionaries mapping these tuples of strings to lower and upper bounds:

```julia
pmin = Dict(zip(ids, prods) .=> mins)
pmax = Dict(zip(ids, prods) .=> maxs)
@variable(model, Vp[pset])
for (id, prod) in pset
	@constraint(model, pmin[(id,prod)] ≤ Vp[(id,prod)] ≤ pmax[(id,prod)])
end

```

How would you rewrite it to use the bounds directly in the `@variable` macro?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [March 23, 2023, 2:00pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/8 "2023-03-23T14:00:43Z")

</div>

> [@odow](#):
>
> I posted this above, but it seems that you probably want to use `relax_with_penalty!` instead: [Debugging · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/debugging/#Penalty-relaxation)

I tried copying the example in the docs but the resulting lines all showed violations = 1.0, which is not what I would expect from the bounds and values of the optimization variables. Maybe I am misinterpreting what is being printed?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [March 23, 2023, 2:02pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/9 "2023-03-23T14:02:14Z")

</div>

> [@odow](#):
>
> HiGHS can prove infeasibility in presolve, which means it doesn’t find an infeasibility certificate. If you turn off presolve, it can find an infeasibility certificate.

Can you please clarify what the `presolve` option does? Is it safe to turn it off in general?

---

<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:** [March 23, 2023, 7:12pm UTC](https://discourse.julialang.org/t/which-jump-solvers-support-compute-conflict/95733/10 "2023-03-23T19:12:45Z")

</div>

> How would you rewrite it to use the bounds directly in the `@variable` macro?

```Julia
pmin = Dict(zip(ids, prods) .=> mins)
pmax = Dict(zip(ids, prods) .=> maxs)
@variable(model, pmin[(id,prod)] <= Vp[(id, prod) in pset] <= pmax[(id,prod)])

```

> Maybe I am misinterpreting what is being printed?

It should print a solution with the minimal L1-norm violation of your constraints. That isn’t the same as a solution with the minimal number of constraints violated.

> Can you please clarify what the `presolve` option does? Is it safe to turn it off in general?

Solvers use heuristics to partially solve the problem without using a full algorithm like simplex or interior point. Common techniques in presolve include tightening variable bounds, removing fixed variables, removing co-linear or redundant constraints, etc.

It’s safe to turn off in general, but it can lead to increased solving times. You could just solve, then if you get infeasibility and no infeasibility certificate, turn off presolve and re-solve.
