# Redundant and non-redundant constraints

**URL:** https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314
**Category:** Optimization (Mathematical)
**Created:** [November 17, 2020, 5:48pm UTC](https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314 "2020-11-17T17:48:33Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kat\_mt](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kat\_mt](https://discourse.julialang.org/u/kat_mt)
#### Post date: [November 17, 2020, 5:48pm UTC](https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314/1 "2020-11-17T17:48:33Z")

</div>

Hello! I need to solve a LP model with CPLEX and find which of constraints are non redundant. After solving, it gives me the following message:

**Tried aggregator 1 time.**  
**LP Presolve eliminated 22 rows and 0 columns.**  
**Reduced LP has 10 rows, 3 columns, and 26 nonzeros.**  
**Presolve time = 0.00 sec. (0.01 ticks)**  
**Initializing dual steep norms . . .**

How can i find which constraints have eliminated?

---

<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: [November 17, 2020, 8:52pm UTC](https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314/2 "2020-11-17T20:52:21Z")

</div>

This requires you to use the CPLEX C API: [IBM Documentation](https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/refcallablelibrary/cpxapi/getredlp.html)

Doing so is non-trivial, I strongly encourage you to consider if you need to do this. Here is some code to get you started:

```julia
using JuMP, CPLEX
model = direct_model(CPLEX.Optimizer())
# ... build model ...
optimize!(model)
cpx = backend(model)
redlp_p = Ref{Ptr{Cvoid}}()
CPXgetredlp(cpx.env, cpx.lp, redlp_p)
lp = redlp_p[] # Use this pointer with CPX functions

```

Depending on what you mean by “non redundant,” there are better ways of doing this. For example, you could check the slack of each constraint to see if it is binding, or you could look for constraints with a dual of `0.0`.

---

<div class="post-metadata">

### Author: ![mbesancon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbesancon/32/6528_2.png) [@mbesancon](https://discourse.julialang.org/u/mbesancon)
#### Post date: [November 17, 2020, 9:05pm UTC](https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314/3 "2020-11-17T21:05:53Z")

</div>

> [@odow](#):
>
> `redlp_p = Ref{Ptr{Covid}}()`

I think you meant `Ref{Ptr{Cvoid}}()`? 😅

---

<div class="post-metadata">

### Author: ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)
#### Post date: [November 18, 2020, 1:48am UTC](https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314/4 "2020-11-18T01:48:37Z")

</div>

> [@kat\_mt](#):
>
> I need to solve a LP model with CPLEX and find which of constraints are non redundant.

Are you looking for the presolved model, or for a set of non-redundant constraints from the original LP?

Couple of remarks (which may or may not be relevant based on the above question):

1. In general, the presolved model may still contain some redundant constraints.

2. Presolve may eliminate constraints that are non redundant. For instance, consider the following LP:

3. CPLEX also makes use of _dual reductions_. These are transformations that may remove some feasible solution, but keeps all optimal ones. Again, these may eliminate non-redundant constraints.

Finally, if you want a set of non-redundant constraints that are active at the optimum, you are looking for a _basis_, which you should be able to query from CPLEX without needing to go through the presolved model.

---

<div class="post-metadata">

### Author: ![kat\_mt](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kat\_mt](https://discourse.julialang.org/u/kat_mt)
#### Post date: [November 19, 2020, 7:49pm UTC](https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314/5 "2020-11-19T19:49:16Z")

</div>

Thank you all for your advices!  
@odow i follow your code but now i have this message. Have you any ideas what’ s wrong with it? ![png1](https://global.discourse-cdn.com/julialang/original/3X/8/9/895b8716689a0201b5afe8ea2d6ccba13cd51fa3.png)

---

<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: [November 19, 2020, 9:20pm UTC](https://discourse.julialang.org/t/redundant-and-non-redundant-constraints/50314/6 "2020-11-19T21:20:14Z")

</div>

> Have you any ideas what’ s wrong with it?

You probably need to update to the latest version of CPLEX.jl.

Check

```Julia
julia> import Pkg; Pkg.status("CPLEX")
Status `/private/tmp/jump/Project.toml`
  [a076750e] CPLEX v0.7.3

```

and if it’s not 0.7.3, run `Pkg.update()`.
