Relaxing binary variable

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.

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.

A2 is a vector of indexes you mean?

Use

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

Note the dots.

1 Like

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

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.

   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.

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

2 Likes

Thank you.