I am trying to develop a customised branch and bound algorithm in Julia with the JuMP package. The problem only has binary variables.
What I do is relaxing the problem to its linear counterpart and getting the variable values from the linear model. I define a loop to detect the fractional values. At every fractional solution the following should be conducted.
If x
is a fractional variable, create two new branches (two new models) one with x >= 1
and one with x =< 0
constraints. I have error with this one and I put it below.
The created models should be stored somewhere (in a container or vector) with appropriate names so I can call them and if they violate the lower bound or upper bound they can be deleted. I’m not sure how to do this.
mp_linear = Model(Gurobi.Optimizer)
@variable(mp_linear, 0 ≤ ψ[1:H] ≤ 1 )
@variable(mp_linear, 0 ≤ χ[1:H , 1:J] ≤ 1 )
@objective(mp_linear, Min, sum( T*zᵖ[h]*ψ[h] for h in 1:H ) + sum(χ[h,j] * zᵐ[h,j] for h in 1:H for j in 1:J) )
@constraint(mp_linear, [h in 1:H , j in 1:J], χ[h,j] ≤ ψ[h])
@constraint(mp_linear, [h in 1:H , j in 1:J], s[h,j] + ψ[h] ≤ χ[h,j] + 1)
@constraint(mp_linear, 335*χ[1,1]+335*χ[2,1] + 335* χ[3,1] + 335* χ[1,2] + 335 *χ[2,2] +
335* χ[3,2] + 335* χ[1,3] + 335* χ[2,3] + 335 *χ[3,3] >= 380.0)
function initiate()
optimize!(mp_linear)
χᵃ = value.(χ)
@show χᵃ
for h in 1:H
for j in 1:J
if 0 < χᵃ[h,j] < 1
global m1 = copy(mp_linear)
@constraint(m1, χ[h,j] ≥ 1)
global m0 = copy(mp_linear)
@constraint(m0, χ[h,j] ≤ 1)
end
end
end
end
initiate()
and this is the error I see
Solved in 7 iterations and 0.00 seconds (0.00 work units)
Optimal objective 2.268656716e+01
User-callback calls 66, time in user-callback 0.00 sec
χᵃ = [0.0 0.0 0.0; 0.0 0.0 0.0; 0.3781094527363184 0.37810945273631835 0.37810945273631835]
VariableNotOwned{VariableRef}(χ[3,1])
Can you please help with this?
Is there a proper example somewhere? I am sure I will have heaaches for the rest of the algorithm lol.