Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of variable branching priorities in the branching algorithm #528

Merged
merged 1 commit into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/dev/formulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ activate!
deactivate!
isexplicit
getname
getbranchingpriority
```

```@meta
Expand Down
4 changes: 2 additions & 2 deletions src/Algorithm/branching/branchingalgo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function run!(algo::StrongBranching, env::Env, data::ReformData, input::DivideIn
# generate candidates
output = run!(rule, env, data, BranchingRuleInput(
original_solution, true, nb_candidates_needed, algo.selection_criterion,
local_id, algo.int_tol
local_id, algo.int_tol, min_priority
))
nb_candidates_found += length(output.groups)
append!(kept_branch_groups, output.groups)
Expand All @@ -262,7 +262,7 @@ function run!(algo::StrongBranching, env::Env, data::ReformData, input::DivideIn
if projection_is_possible(master) && extended_solution !== nothing
output = run!(rule, env, data, BranchingRuleInput(
extended_solution, false, nb_candidates_needed, algo.selection_criterion,
local_id, algo.int_tol
local_id, algo.int_tol, min_priority
))
nb_candidates_found += length(output.groups)
append!(kept_branch_groups, output.groups)
Expand Down
1 change: 1 addition & 0 deletions src/Algorithm/branching/branchingrule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct BranchingRuleInput <: AbstractInput
criterion::SelectionCriterion
local_id::Int64
int_tol::Float64
minimum_priority::Float64
end

"""
Expand Down
1 change: 1 addition & 0 deletions src/Algorithm/branching/varbranching.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function run!(
for (var_id, val) in input.solution
# Do not consider continuous variables as branching candidates
getperenkind(master, var_id) == Continuous && continue
getbranchingpriority(master, var_id) < input.minimum_priority && continue
if !isinteger(val, input.int_tol)
#description string is just the variable name
candidate = VarBranchingCandidate(getname(master, var_id), var_id)
Expand Down
7 changes: 5 additions & 2 deletions src/Algorithm/treesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,15 @@ function run_conquer_algorithm!(

algo.print_node_info && print_node_info_before_conquer(tsdata, env, node)

node.conquerwasrun && return

treestate = getoptstate(tsdata)
nodestate = getoptstate(node)
update_ip_primal!(nodestate, treestate, tsdata.exploitsprimalsolutions)

# in the case the conquer was already run (in strong branching),
# we still need to update the node IP primal bound before exiting
# (to possibly avoid branching)
node.conquerwasrun && return

apply_conquer_alg_to_node!(
node, algo.conqueralg, env, rfdata, tsdata.conquer_units_to_restore,
algo.opt_rtol, algo.opt_atol
Expand Down
2 changes: 1 addition & 1 deletion src/MOIwrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function MOI.set(
model::Coluna.Optimizer, ::BD.VarBranchingPriority, varid::MOI.VariableIndex, branching_priority::Int
)
var = model.vars[varid]
var.branching_priority = branching_priority
var.branching_priority = Float64(branching_priority)
return
end

Expand Down
2 changes: 1 addition & 1 deletion src/MathProg/MathProg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export Variable, Constraint, VarId, ConstrId, VarMembership, ConstrMembership,
getperenub, getcurub, setcurub!, getperenrhs, getcurrhs, setcurrhs!, getperensense,
getcursense, setcursense!, getperenkind, getcurkind, setcurkind!, getperenincval,
getcurincval, setcurincval!, isperenactive, iscuractive, activate!, deactivate!,
isexplicit, getname, reset!, getreducedcost
isexplicit, getname, getbranchingpriority, reset!, getreducedcost

# Types & methods related to solutions & bounds
export PrimalBound, DualBound, PrimalSolution, DualSolution, ObjValues,
Expand Down
3 changes: 2 additions & 1 deletion src/MathProg/clone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ function clonevar!(
inc_val::Float64 = getperenincval(originform, var),
is_active::Bool = isperenactive(originform, var),
is_explicit::Bool = isexplicit(originform, var),
branching_priority::Float64 = getbranchingpriority(originform, var),
members::Union{ConstrMembership,Nothing} = nothing
)
return setvar!(
destform, name, duty;
cost = cost, lb = lb, ub = ub, kind = kind,
inc_val = inc_val, is_active = is_active, is_explicit = is_explicit,
members = members,
branching_priority = branching_priority, members = members,
id = Id{Variable}(duty, getid(var), getuid(assignedform))
)
end
Expand Down
2 changes: 1 addition & 1 deletion src/MathProg/formulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function setvar!(
moi_index::MoiVarIndex = MoiVarIndex(),
members::Union{ConstrMembership,Nothing} = nothing,
id = generatevarid(duty, form),
branching_priority::Int = 1
branching_priority::Float64 = 1.0
)
if kind == Binary
lb = (lb < 0.0) ? 0.0 : lb
Expand Down
10 changes: 10 additions & 0 deletions src/MathProg/varconstr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,16 @@ getname(form::Formulation, var::Variable) = var.name
getname(form::Formulation, constrid::ConstrId) = getconstr(form, constrid).name
getname(form::Formulation, constr::Constraint) = constr.name

## branching_priority
"""
getbranchingpriority(formulation, var)
getbranchingpriority(formulation, varid)

Return the branching priority of a variable
"""
getbranchingpriority(form::Formulation, varid::VarId) = getvar(form, varid).branching_priority
getbranchingpriority(form::Formulation, var::Variable) = var.branching_priority

# Reset
"""
reset!(form, var)
Expand Down
4 changes: 2 additions & 2 deletions src/MathProg/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mutable struct Variable <: AbstractVarConstr
name::String
perendata::VarData
curdata::VarData
branching_priority::Int
branching_priority::Float64
moirecord::MoiVarRecord
end

Expand All @@ -85,7 +85,7 @@ const VarId = Id{Variable}
getid(var::Variable) = var.id

function Variable(
id::VarId, name::String; var_data = VarData(), branching_priority::Int = 1,
id::VarId, name::String; var_data = VarData(), branching_priority::Float64 = 1.0,
moi_index::MoiVarIndex = MoiVarIndex()
)
return Variable(
Expand Down
17 changes: 13 additions & 4 deletions test/full_instances_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ function generalized_assignment_tests()
colgen = ClA.ColumnGeneration(cleanup_threshold = 150, smoothing_stabilization = 1.0)
)

branching = ClA.StrongBranching()
push!(branching.phases, ClA.BranchingPhase(5, ClA.RestrMasterLPConquer()))
push!(branching.phases, ClA.BranchingPhase(1, conquer_with_small_cleanup_threshold))
push!(branching.rules, ClA.PrioritisedBranchingRule(ClA.VarBranchingRule(), 1.0, 1.0))
branching = ClA.StrongBranching(
phases = [ClA.BranchingPhase(5, ClA.RestrMasterLPConquer()),
ClA.BranchingPhase(1, conquer_with_small_cleanup_threshold)],
rules = [ClA.PrioritisedBranchingRule(ClA.VarBranchingRule(), 2.0, 2.0),
ClA.PrioritisedBranchingRule(ClA.VarBranchingRule(), 1.0, 1.0)]
)

coluna = JuMP.optimizer_with_attributes(
CL.Optimizer,
Expand All @@ -79,6 +81,13 @@ function generalized_assignment_tests()

model, x, dec = CLD.GeneralizedAssignment.model(data, coluna)

# we increase the branching priority of variables which assign jobs to the first two machines
for machine in 1:2
for job in data.jobs
BD.branchingpriority!(model, x[machine,job], 2)
end
end

BD.objectiveprimalbound!(model, 2000.0)
BD.objectivedualbound!(model, 0.0)

Expand Down