# I added 1 Million constraints to an LP unwittingly

**URL:** <https://discourse.julialang.org/t/i-added-1-million-constraints-to-an-lp-unwittingly/127668>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump, examples, gurobi, experience\
**Created:** [April 3, 2025, 11:12am UTC](https://discourse.julialang.org/t/i-added-1-million-constraints-to-an-lp-unwittingly/127668 "2025-04-03T11:12:09Z")\
**Posts on this page:** 1\
**Showing post:** 9

<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 4, 2025, 12:33am UTC](https://discourse.julialang.org/t/i-added-1-million-constraints-to-an-lp-unwittingly/127668/9 "2025-04-04T00:33:05Z")

</div>

Have you benchmarked the different forms? I would assume this depends on the sparsity of `r` and `c`.

I would do:

```julia
using JuMP, SparseArrays
model = Model()
@variable(model, x[1:101, 1:170])
X = 1.0 .* x
r = SparseArrays.sprand(101, 0.1)
c = SparseArrays.sprand(170, 0.1)
# @constraint(model, r' * X * c >= 0)
(r_I, r_V), (c_I, c_V) = SparseArrays.findnz(r), SparseArrays.findnz(c)
@constraint(
    model, 
    sum(
        r_v * X[r_i, c_i] * c_v for
        (c_i, c_v) in zip(c_I, c_V), (r_i, r_v) in zip(r_I, r_V)
    ) >= 0
)

```

---

_[View the full topic](https://discourse.julialang.org/t/i-added-1-million-constraints-to-an-lp-unwittingly/127668)._
