# Complementarity.jl supports equality constraints?

**URL:** <https://discourse.julialang.org/t/complementarity-jl-supports-equality-constraints/82214>\
**Category:** Optimization (Mathematical)\
**Tags:** complementarity\
**Created:** [June 3, 2022, 10:19pm UTC](https://discourse.julialang.org/t/complementarity-jl-supports-equality-constraints/82214 "2022-06-03T22:19:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vicentemunozlh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vicentemunozlh/32/36766_2.png) [@vicentemunozlh](https://discourse.julialang.org/u/vicentemunozlh)\
**Post date:** [June 3, 2022, 10:19pm UTC](https://discourse.julialang.org/t/complementarity-jl-supports-equality-constraints/82214/1 "2022-06-03T22:19:11Z")

</div>

Hello, I have been unable to finish my MCP model because I cant find the way to add a constraint that is an equality. When I try combining and adding that constraint as @constraint or @NLconstraint and the others with @mapping, it does not work.

Any advise would be great!

---

<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:** [June 4, 2022, 5:45am UTC](https://discourse.julialang.org/t/complementarity-jl-supports-equality-constraints/82214/2 "2022-06-04T05:45:29Z")

</div>

Mixed complementarity problems don’t support equality constraints.

Did you try formulating as an MPEC?

> **[GitHub - chkwon/Complementarity.jl: provides a modeling interface for mixed...](https://github.com/chkwon/Complementarity.jl#mathematical-programs-with-equilibrium-constraints-mpec)**
>
> provides a modeling interface for mixed complementarity problems (MCP) and math programs with equilibrium problems (MPEC) via JuMP - GitHub - chkwon/Complementarity.jl: provides a modeling interfa...

Note that you need `m = Model(Ipopt.Optimizer)` instead of `m = Model(solver=IpoptSolver())`. I opened a PR to fix: [Fix syntax in README by odow · Pull Request #65 · chkwon/Complementarity.jl · GitHub](https://github.com/chkwon/Complementarity.jl/pull/65)

If you’re still stuck, please provide reproducible code of what you’ve tried so far: [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![vicentemunozlh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vicentemunozlh/32/36766_2.png) [@vicentemunozlh](https://discourse.julialang.org/u/vicentemunozlh)\
**Post date:** [June 4, 2022, 9:35pm UTC](https://discourse.julialang.org/t/complementarity-jl-supports-equality-constraints/82214/3 "2022-06-04T21:35:19Z")

</div>

Thank you. By using this solver Ipopt.Optimizer, Path cant be used to solve the model? My model has over 1000 variables …

---

<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:** [June 4, 2022, 10:42pm UTC](https://discourse.julialang.org/t/complementarity-jl-supports-equality-constraints/82214/4 "2022-06-04T22:42:20Z")

</div>

If you want to use PATH, you’d have to reformulate your problem as a MCP, for example, by adding a dual variable:

```julia
using JuMP, PATHSolver
model = Model(PATHSolver.Optimizer)
@variable(model, x)
@variable(model, μ)
# @constraint(model, 2x == 1)
@constraint(model, 2x - 1 ⟂ μ)
optimize!(model)
solution_summary(model; verbose = true)

```

but you might need to be a bit careful, depending on the formulation of rest of your model. (In the model above, there’s effectively a hidden constraint that `@constraint(model, 0 * x ⟂ x)`.)

Ipopt will have no trouble with 1000 variables.
