# Relaxing binary variable

**URL:** <https://discourse.julialang.org/t/relaxing-binary-variable/52965>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization\
**Created:** [January 6, 2021, 11:03pm UTC](https://discourse.julialang.org/t/relaxing-binary-variable/52965 "2021-01-06T23:03:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [January 6, 2021, 11:03pm UTC](https://discourse.julialang.org/t/relaxing-binary-variable/52965/1 "2021-01-06T23:03:05Z")

</div>

In a model, I want to relax one binary variable.

`relax_integrality(model)` relaxes all variables of the model, so I think the right way to go will be to use `unset_binary` as shown in the example below.

```julia
model = Model()
@variable(model, x[1:2], Bin)
@objective(model, Min, x[1] + x[2])
unset_binary(x[2])
set_lower_bound(x[2],0)
set_upper_bound(x[2],1)

```

What is the correct way to use `unset_binary` when working with DenisAxisArrays? For example, assume that indices of the vector x, are x[A1] and x[A2] and I want to relax x[A2]. Using the above code unset\_binary(x[A2]) throws an error that x[A2] is not defined.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [January 6, 2021, 11:39pm UTC](https://discourse.julialang.org/t/relaxing-binary-variable/52965/2 "2021-01-06T23:39:14Z")

</div>

`A2` is a vector of indexes you mean?

Use

```julia
unset_binary.(x[A2])
set_lower_bound.(x[A2], 0)
set_upper_bound.(x[A2], 1)

```

Note the dots.

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [January 6, 2021, 11:55pm UTC](https://discourse.julialang.org/t/relaxing-binary-variable/52965/3 "2021-01-06T23:55:35Z")

</div>

> [@Henrique\_Becker](#):
>
> `A2` is a vector of indexes you mean?

No, it is a single index. I have given a more detailed example below:

```julia
using JuMP, Cbc, DataFrames
function get_data()
    ID_t = collect(1:15)
    ID = Vector{String}(undef,15)
    for i in 1:15
        ID[i]="A".*string(ID_t[i])
    end

    PRICE = rand(10.0:100.0,15)
    Data = DataFrame(ID = ID,PRICE = PRICE)
    return Data
end

    Data = get_data()
    price = Data.PRICE
    model = Model(Cbc.Optimizer)
    @variable(model, x[Data.ID],Bin)
    @objective(model,Min,sum(price*x[id] for (id, price) in zip(Data.ID, Data.PRICE)))

```

`unset_binary` does not work, e.g.

```julia
   unset_binary(x[A2])
    set_lower_bound(x[A2], 0)
    set_upper_bound(x[A2], 1)

```

throws an error and also if you use broadcast.

---

<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:** [January 7, 2021, 12:20am UTC](https://discourse.julialang.org/t/relaxing-binary-variable/52965/4 "2021-01-07T00:20:11Z")

</div>

You probably mean `unset_binary(x["A2"])`. `A2` (without quotes) as a variable doesn’t exist.

---

<div class="post-metadata">

**Author:** ![JohnZ](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@JohnZ](https://discourse.julialang.org/u/JohnZ)\
**Post date:** [January 7, 2021, 12:22am UTC](https://discourse.julialang.org/t/relaxing-binary-variable/52965/5 "2021-01-07T00:22:52Z")

</div>

Thank you.
