# Semi-continuous variables: JuMP and Cplex solver

**URL:** <https://discourse.julialang.org/t/semi-continuous-variables-jump-and-cplex-solver/24966>\
**Category:** Optimization (Mathematical)\
**Created:** [June 5, 2019, 2:52pm UTC](https://discourse.julialang.org/t/semi-continuous-variables-jump-and-cplex-solver/24966 "2019-06-05T14:52:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bienpierre](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bienpierre](https://discourse.julialang.org/u/bienpierre)\
**Post date:** [June 5, 2019, 2:52pm UTC](https://discourse.julialang.org/t/semi-continuous-variables-jump-and-cplex-solver/24966/1 "2019-06-05T14:52:56Z")

</div>

Hello,  
I have a semi-continuous variable, the domain is {0} U [l,u]. Example is:

```julia
using JuMP
using CPLEX

MyModel = Model(with_optimizer(CPLEX.Optimizer))
@variable(MyModel, zz)
@constraint(MyModel, zz in MOI.Semicontinuous(2.5, 3.5))

```

It didn’t work. Error was:

> ERROR: Constraints of type MathOptInterface.SingleVariable-in-MathOptInterface.Semicontinuous{Float64} are not supported by the solver and there are no bridges that can reformulate it into supported constraints.

I tried without solver:

```julia
MyModel2 = Model()
@variable(MyModel2, zz)
@constraint(MyModel2, zz in MOI.Semicontinuous(2.5, 3.5));

```

There was no error.

I had a look inside the Cplex solver [user guide](https://www.ibm.com/support/knowledgecenter/SSSA5P_12.6.1/ilog.odms.cplex.help/CPLEX/UsrMan/topics/discr_optim/semi_cont_var/02_SemiCont_defn.html), then it is possible to create a semi continuous variable.

I have two questions:

- What are the juMP available solvers that can take into account semi-continuous variable?
- Is it possible to reformulate the constraint to keep semi-continuous variable and Cplex solver?

Thank you in advance!  
Warmest Regards.

JuMP: v0.19.1  
Cplex studio : v12.8.0  
Julia v1.1.0

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [June 5, 2019, 4:05pm UTC](https://discourse.julialang.org/t/semi-continuous-variables-jump-and-cplex-solver/24966/2 "2019-06-05T16:05:22Z")

</div>

The MathOptInterface wrapper is claiming that it is not supported. See [https://github.com/JuliaOpt/CPLEX.jl/issues/241](https://github.com/JuliaOpt/CPLEX.jl/issues/241) for an idea how to fix it.

---

<div class="post-metadata">

**Author:** ![bienpierre](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bienpierre](https://discourse.julialang.org/u/bienpierre)\
**Post date:** [June 6, 2019, 4:08pm UTC](https://discourse.julialang.org/t/semi-continuous-variables-jump-and-cplex-solver/24966/3 "2019-06-06T16:08:17Z")

</div>

Thank you, it works well with Cplex.

I also tried to do it with[Cbc](https://github.com/JuliaOpt/Cbc.jl/blob/master/src/MOI_wrapper.jl), however I’ve got the same issue. I do not know exatly where to modify the MOI.Wrapper. I added `MOI.Semicontinuous[Float64}` inside:

> function MOI.supports\_constraint(  
> ::Optimizer, ::Type{MOI.SingleVariable}, ::Type{\<:Union{  
> MOI.EqualTo{Float64}, MOI.LessThan{Float64},  
> MOI.GreaterThan{Float64}, MOI.Interval{Float64},  
> MOI.ZeroOne, MOI.Integer}})  
> return true  
> end

Do I need to add it in an other function?

Regards
