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

Fix wrong duty for setupvar in master coeff matrix #316

Merged
merged 2 commits into from
Apr 24, 2020
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
3 changes: 1 addition & 2 deletions src/Algorithm/colgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ function solve_sp_to_gencol!(

recorded_solution_ids = Vector{VarId}()
sp_solution_ids_to_activate = Vector{VarId}()

sp_is_feasible = true

#dual_bound_contrib = 0 # Not used
Expand Down Expand Up @@ -240,7 +239,7 @@ function updatereducedcosts!(reform::Reformulation, redcostsvec::ReducedCostsVec
entry = crm.pcsc.pma.array[row_pos]
if entry !== nothing
row_varid, coeff = entry
if getduty(row_varid) <= AbstractMasterRepDwSpVar || getduty(row_varid) <= DwSpSetupVar
if getduty(row_varid) <= AbstractMasterRepDwSpVar
terms[row_varid] = get(terms, row_varid, 0.0) + val * coeff
end
end
Expand Down
10 changes: 5 additions & 5 deletions src/MathProg/decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function create_side_vars_constrs!(
setupvars = filter(v -> getduty(v.first) == DwSpSetupVar, getvars(spform))
@assert length(setupvars) == 1
setupvar = collect(values(setupvars))[1]
clonevar!(origform, masterform, spform, setupvar, MasterRepPricingSetupVar, is_explicit = false)
setuprepvar = clonevar!(origform, masterform, spform, setupvar, MasterRepPricingSetupVar, is_explicit = false)
# create convexity constraint
lb_mult = Float64(BD.getlowermultiplicity(ann))
name = string("sp_lb_", spuid)
Expand All @@ -169,7 +169,7 @@ function create_side_vars_constrs!(
rhs = lb_mult, kind = Core, sense = Greater, inc_val = 100.0
)
masterform.parent_formulation.dw_pricing_sp_lb[spuid] = getid(lb_conv_constr)
coefmatrix[getid(lb_conv_constr), getid(setupvar)] = 1.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duty of the id in the coefficient matrix of the master was DwSetupVar instead of MasterRepPricingSetupVar.

coefmatrix[getid(lb_conv_constr), getid(setuprepvar)] = 1.0

ub_mult = Float64(BD.getuppermultiplicity(ann))
name = string("sp_ub_", spuid)
Expand All @@ -178,7 +178,7 @@ function create_side_vars_constrs!(
kind = Core, sense = Less, inc_val = 100.0
)
masterform.parent_formulation.dw_pricing_sp_ub[spuid] = getid(ub_conv_constr)
coefmatrix[getid(ub_conv_constr), getid(setupvar)] = 1.0
coefmatrix[getid(ub_conv_constr), getid(setuprepvar)] = 1.0
end
return
end
Expand All @@ -200,8 +200,8 @@ function instantiate_orig_vars!(
vars = annotations.vars_per_ann[sp_ann]
masterform = spform.parent_formulation
for (id, var) in vars
# An original variable annoted in a subproblem is a DwSpPureVar
clonevar!(origform, spform, spform, var, DwSpPricingVar, is_explicit = true)
# An original variable annotated in a subproblem is a DwSpPricingVar
clonevar!(origform, spform, spform, var, DwSpPricingVar, is_explicit = true)
clonevar!(origform, masterform, spform, var, MasterRepPricingVar,
is_explicit = false)#, members = getcoefmatrix(origform)[:,id])
end
Expand Down
26 changes: 5 additions & 21 deletions src/MathProg/formulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function setvar!(form::Formulation,
return var
end


"Adds `Variable` `var` to `Formulation` `form`."
function _addvar!(form::Formulation, var::Variable)
_addvar!(form.manager, var)
Expand All @@ -136,9 +135,7 @@ function _addvar!(form::Formulation, var::Variable)

end

function _addprimalsol!(
form::Formulation, sol_id::VarId, sol::PrimalSolution, cost::Float64
)
function _addprimalsol!(form::Formulation, sol_id::VarId, sol::PrimalSolution, cost::Float64)
for (var_id, var_val) in sol
var = form.manager.vars[var_id]
if getduty(var_id) <= DwSpSetupVar || getduty(var_id) <= DwSpPricingVar
Expand All @@ -149,10 +146,7 @@ function _addprimalsol!(
return sol_id
end

function setprimalsol!(
form::Formulation,
new_primal_sol::PrimalSolution
)::Tuple{Bool,VarId}
function setprimalsol!(form::Formulation, new_primal_sol::PrimalSolution)::Tuple{Bool,VarId}
primal_sols = getprimalsolmatrix(form)
primal_sol_costs = getprimalsolcosts(form)

Expand All @@ -165,8 +159,7 @@ function setprimalsol!(
# look for an identical column
for (cur_sol_id, cur_cost) in primal_sol_costs
cur_primal_sol = primal_sols[:, cur_sol_id]
if isapprox(new_cost, cur_cost) &&
getsol(new_primal_sol) == cur_primal_sol
if isapprox(new_cost, cur_cost) && getsol(new_primal_sol) == cur_primal_sol
return (false, cur_sol_id)
end
end
Expand All @@ -177,12 +170,7 @@ function setprimalsol!(
return (true, new_sol_id)
end

function _adddualsol!(
form::Formulation,
dualsol::DualSolution,
dualsol_id::ConstrId
)

function _adddualsol!(form::Formulation, dualsol::DualSolution, dualsol_id::ConstrId)
rhs = 0.0
for (constrid, constrval) in dualsol
rhs += getperenerhs(form, constrid) * constrval
Expand All @@ -191,14 +179,10 @@ function _adddualsol!(
end
end
form.manager.dual_sol_rhss[dualsol_id] = rhs

return dualsol_id
end

function setdualsol!(
form::Formulation,
new_dual_sol::DualSolution
)::Tuple{Bool,ConstrId}
function setdualsol!(form::Formulation, new_dual_sol::DualSolution)::Tuple{Bool,ConstrId}
### check if dualsol exists take place here along the coeff update
dual_sols = getdualsolmatrix(form)
dual_sol_rhss = getdualsolrhss(form)
Expand Down