Skip to content

Commit

Permalink
Views for columns and constraints & rm MembersMatrix (#371)
Browse files Browse the repository at this point in the history
* use of view in colgen

* view everywhere it is possible

* move matrix in DynamicSparseArrays

* update deps version
  • Loading branch information
guimarqu authored Jun 13, 2020
1 parent 7e21eda commit d292b48
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 173 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[compat]
BlockDecomposition = "1.2.0"
BlockDecomposition = "1.2.1"
DataStructures = "0.17"
DynamicSparseArrays = "0.2.2"
MathOptInterface = "0.9"
DynamicSparseArrays = "0.2.4"
MathOptInterface = "0.9.10"
TimerOutputs = "0.5"
julia = "1"

Expand Down
116 changes: 58 additions & 58 deletions src/Algorithm/colgen.jl

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions src/ColunaBase/ColunaBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ export NestedEnum, @nestedenum, @exported_nestedenum
# solsandbounds.jl
export Bound, Solution, getvalue, isbetter, diff, gap, printbounds, getsol, remove_until_last_point

# members.jl
export MembersMatrix

include("interface.jl")
include("nestedenum.jl")
include("solsandbounds.jl")
include("members.jl")

end
end
22 changes: 0 additions & 22 deletions src/ColunaBase/members.jl

This file was deleted.

93 changes: 46 additions & 47 deletions src/MathProg/decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ function create_global_art_vars!(masterform::Formulation)
end

function instantiatemaster!(
prob::Problem, reform::Reformulation, ::Type{BD.Master},
prob::Problem, reform::Reformulation, ::Type{BD.Master},
::Type{BD.DantzigWolfe}
)
form = Formulation{DwMaster}(
prob.form_counter;
prob.form_counter;
parent_formulation = reform,
obj_sense = getobjsense(get_original_formulation(prob))
)
Expand All @@ -43,7 +43,7 @@ function instantiatemaster!(
prob::Problem, reform::Reformulation, ::Type{BD.Master}, ::Type{BD.Benders}
)
masterform = Formulation{BendersMaster}(
prob.form_counter;
prob.form_counter;
parent_formulation = reform,
obj_sense = getobjsense(get_original_formulation(prob))
)
Expand All @@ -52,11 +52,11 @@ function instantiatemaster!(
end

function instantiatesp!(
prob::Problem, reform::Reformulation, masterform::Formulation{DwMaster},
prob::Problem, reform::Reformulation, masterform::Formulation{DwMaster},
::Type{BD.DwPricingSp}, ::Type{BD.DantzigWolfe}
)
spform = Formulation{DwSp}(
prob.form_counter;
prob.form_counter;
parent_formulation = masterform,
obj_sense = getobjsense(masterform)
)
Expand All @@ -65,11 +65,11 @@ function instantiatesp!(
end

function instantiatesp!(
prob::Problem, reform::Reformulation, masterform::Formulation{BendersMaster},
prob::Problem, reform::Reformulation, masterform::Formulation{BendersMaster},
::Type{BD.BendersSepSp}, ::Type{BD.Benders}
)
spform = Formulation{BendersSp}(
prob.form_counter;
prob.form_counter;
parent_formulation = masterform,
obj_sense = getobjsense(masterform)
)
Expand All @@ -80,7 +80,7 @@ end
# Master of Dantzig-Wolfe decomposition
function instantiate_orig_vars!(
masterform::Formulation{DwMaster},
origform::Formulation,
origform::Formulation,
annotations::Annotations,
mast_ann
)
Expand All @@ -100,7 +100,7 @@ end

function instantiate_orig_constrs!(
masterform::Formulation{DwMaster},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
mast_ann
)
Expand All @@ -120,7 +120,7 @@ end

function create_side_vars_constrs!(
masterform::Formulation{DwMaster},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations
)
coefmatrix = getcoefmatrix(masterform)
Expand All @@ -134,7 +134,7 @@ function create_side_vars_constrs!(
lb_mult = Float64(BD.getlowermultiplicity(ann))
name = string("sp_lb_", spuid)
lb_conv_constr = setconstr!(
masterform, name, MasterConvexityConstr;
masterform, name, MasterConvexityConstr;
rhs = lb_mult, kind = Essential, sense = Greater, inc_val = 100.0, loc_art_var = true
)
masterform.parent_formulation.dw_pricing_sp_lb[spuid] = getid(lb_conv_constr)
Expand All @@ -143,10 +143,10 @@ function create_side_vars_constrs!(
ub_mult = Float64(BD.getuppermultiplicity(ann))
name = string("sp_ub_", spuid)
ub_conv_constr = setconstr!(
masterform, name, MasterConvexityConstr; rhs = ub_mult,
masterform, name, MasterConvexityConstr; rhs = ub_mult,
kind = Essential, sense = Less, inc_val = 100.0, loc_art_var = true
)
masterform.parent_formulation.dw_pricing_sp_ub[spuid] = getid(ub_conv_constr)
masterform.parent_formulation.dw_pricing_sp_ub[spuid] = getid(ub_conv_constr)
coefmatrix[getid(ub_conv_constr), getid(setuprepvar)] = 1.0
end
return
Expand All @@ -160,7 +160,7 @@ end
# Pricing subproblem of Danztig-Wolfe decomposition
function instantiate_orig_vars!(
spform::Formulation{DwSp},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
sp_ann
)
Expand All @@ -178,7 +178,7 @@ end

function instantiate_orig_constrs!(
spform::Formulation{DwSp},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
sp_ann
)
Expand All @@ -192,25 +192,25 @@ end

function create_side_vars_constrs!(
spform::Formulation{DwSp},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations
)
name = "PricingSetupVar_sp_$(getuid(spform))"
setvar!(
spform, name, DwSpSetupVar; cost = 0.0, lb = 1.0, ub = 1.0, kind = Integ,
is_explicit = true
)
)
return
end

function _dutyexpofbendmastvar(
var::Variable, annotations::Annotations, origform::Formulation{Original}
)
orig_coef = getcoefmatrix(origform)
for (constrid, coef) in orig_coef[:, getid(var)]
for (constrid, coef) in @view orig_coef[:, getid(var)]
constr_ann = annotations.ann_per_constr[constrid]
#if coef != 0 && BD.getformulation(constr_ann) == BD.Benders # TODO use haskey instead testing != 0
if BD.getformulation(constr_ann) == BD.BendersSepSp
if BD.getformulation(constr_ann) == BD.BendersSepSp
return MasterBendFirstStageVar, true
end
end
Expand All @@ -221,7 +221,7 @@ end

function instantiate_orig_vars!(
masterform::Formulation{BendersMaster},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
mast_ann
)
Expand All @@ -236,7 +236,7 @@ end

function instantiate_orig_constrs!(
masterform::Formulation{BendersMaster},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
mast_ann
)
Expand All @@ -251,27 +251,27 @@ end

function create_side_vars_constrs!(
masterform::Formulation{BendersMaster},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations
)
coefmatrix = getcoefmatrix(masterform)

for (spuid, spform) in get_benders_sep_sps(masterform.parent_formulation)
nu_var = collect(values(filter(
v -> getduty(v.first) == BendSpSlackSecondStageCostVar,
v -> getduty(v.first) == BendSpSlackSecondStageCostVar,
getvars(spform)
)))[1]

name = "η[$(split(getname(spform, nu_var), "[")[end])"
setvar!(
masterform, name, MasterBendSecondStageCostVar;
masterform, name, MasterBendSecondStageCostVar;
cost = 1.0,
lb = getperenlb(spform, nu_var),
ub = getperenub(spform, nu_var),
lb = getperenlb(spform, nu_var),
ub = getperenub(spform, nu_var),
kind = Continuous,
is_explicit = true,
is_explicit = true,
id = Id{Variable}(MasterBendSecondStageCostVar, getid(nu_var), getuid(masterform))
)
)
end
return
end
Expand All @@ -280,7 +280,7 @@ create_artificial_vars!(masterform::Formulation{BendersMaster}) = return

function instantiate_orig_vars!(
spform::Formulation{BendersSp},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
sp_ann
)
Expand Down Expand Up @@ -326,7 +326,7 @@ end

function instantiate_orig_constrs!(
spform::Formulation{BendersSp},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
sp_ann
)
Expand All @@ -341,7 +341,7 @@ end

function create_side_vars_constrs!(
spform::Formulation{BendersSp},
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations
)
sp_has_second_stage_cost = false
Expand All @@ -351,16 +351,16 @@ function create_side_vars_constrs!(
getduty(varid) == BendSpSepVar || continue
orig_var = getvar(origform, varid)
cost = getperencost(origform, orig_var)
if cost > 0.00001
if cost > 0.00001
global_costprofit_ub += cost * getcurub(origform, orig_var)
global_costprofit_lb += cost * getcurlb(origform, orig_var)
elseif cost < - 0.00001
elseif cost < - 0.00001
global_costprofit_ub += cost * getcurlb(origform, orig_var)
global_costprofit_lb += cost * getcurub(origform, orig_var)
end
end

if global_costprofit_ub > 0.00001 || global_costprofit_lb < - 0.00001
if global_costprofit_ub > 0.00001 || global_costprofit_lb < - 0.00001
sp_has_second_stage_cost = true
end

Expand All @@ -376,29 +376,29 @@ function create_side_vars_constrs!(
kind = Continuous,
is_explicit = true
)
setcurlb!(spform, nu, 0.0)
setcurub!(spform, nu, Inf)
setcurlb!(spform, nu, 0.0)
setcurub!(spform, nu, Inf)

cost = setconstr!(
spform, "cost[$sp_id]", BendSpSecondStageCostConstr;
rhs = 0.0,
kind = Essential,
sense = Greater,
spform, "cost[$sp_id]", BendSpSecondStageCostConstr;
rhs = 0.0,
kind = Essential,
sense = Greater,
is_explicit = true
)
sp_coef[getid(cost), getid(nu)] = 1.0

for (varid, var) in getvars(spform)
getduty(varid) == BendSpSepVar || continue
sp_coef[getid(cost), varid] = - getperencost(origform, varid)
sp_coef[getid(cost), varid] = - getperencost(origform, varid)
end
end
return
end

function assign_orig_vars_constrs!(
destform::Formulation,
origform::Formulation{Original},
origform::Formulation{Original},
annotations::Annotations,
ann
)
Expand All @@ -418,7 +418,7 @@ function getoptbuilder(prob::Problem, ann::BD.Annotation)
end

function buildformulations!(
prob::Problem, annotations::Annotations, reform::Reformulation, parent,
prob::Problem, annotations::Annotations, reform::Reformulation, parent,
node::BD.Root
)
ann = BD.annotation(node)
Expand All @@ -439,7 +439,7 @@ function buildformulations!(
end

function buildformulations!(
prob::Problem, annotations::Annotations, reform::Reformulation,
prob::Problem, annotations::Annotations, reform::Reformulation,
parent, node::BD.Leaf
)
ann = BD.annotation(node)
Expand Down Expand Up @@ -469,4 +469,3 @@ function reformulate!(prob::Problem, annotations::Annotations)
# end
return
end

Loading

0 comments on commit d292b48

Please sign in to comment.