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

getters & doc for Reformulation #367

Merged
merged 1 commit into from
Jun 4, 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: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ makedocs(
],
"Reference" => Any[
"Algorithms" => "dev/algorithms.md",
"Formulation" => "dev/formulation.md"
"Formulation" => "dev/formulation.md",
"Reformulation" => "dev/reformulation.md"
]
]
)
Expand Down
20 changes: 20 additions & 0 deletions docs/src/dev/reformulation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```@meta
CurrentModule = Coluna.MathProg
DocTestSetup = quote
using Coluna.MathProg
end
```

# Reformulation

```@docs
Reformulation
getobjsense
getmaster
add_dw_pricing_sp!
add_benders_sep_sp!
get_dw_pricing_sps
get_benders_sep_sps
get_dw_pricing_sp_ub_constrid
get_dw_pricing_sp_lb_constrid
```
6 changes: 3 additions & 3 deletions src/Algorithm/preprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function PreprocessData(reform::Reformulation)
master = getmaster(reform)
for (spuid, spform) in get_dw_pricing_sps(reform)
cur_sp_bounds[spuid] = (
getcurrhs(master, reform.dw_pricing_sp_lb[spuid]),
getcurrhs(master, reform.dw_pricing_sp_ub[spuid])
)
getcurrhs(master, get_dw_pricing_sp_lb_constrid(reform, spuid)),
getcurrhs(master, get_dw_pricing_sp_ub_constrid(reform, spuid))
)
end
return PreprocessData(
reform, Dict{ConstrId,Bool}(),
Expand Down
22 changes: 9 additions & 13 deletions src/MathProg/MathProg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export no_optimizer_builder, set_original_formulation!,
computereducedrhs,
unsafe_getbestprimalsol,
find_owner_formulation,
get_dw_pricing_sps,
getsortuid,
get_benders_sep_sps,
contains, setprimalbound!

# Below this line, clean up has been done :
Expand All @@ -75,18 +73,16 @@ export reformulate!, optimize!
export Problem, set_initial_dual_bound!, set_initial_primal_bound!,
get_initial_dual_bound, get_initial_primal_bound

# Methods related to Reformulation
export Reformulation, getmaster, add_dw_pricing_sp!, add_benders_sep_sp!, get_dw_pricing_sps,
get_benders_sep_sps, get_dw_pricing_sp_ub_constrid, get_dw_pricing_sp_lb_constrid

# Methods related to formulations
export AbstractFormulation, Reformulation, Formulation, getmaster, getreformulation,
getvar, getvars, getconstr, getconstrs, getelem,
getcoefmatrix,
getprimalsolmatrix,
getprimalsolcosts,
getdualsolmatrix,
getdualsolrhss,
setvar!, setconstr!,
setprimalsol!, setdualsol!,
set_robust_constr_generator!, get_robust_constr_generators,
setcol_from_sp_primalsol!, setcut_from_sp_dualsol! # TODO : merge with setvar! & setconstr!
export AbstractFormulation, Formulation, getreformulation, getvar, getvars, getconstr,
getconstrs, getelem, getcoefmatrix, getprimalsolmatrix, getprimalsolcosts,
getdualsolmatrix, getdualsolrhss, setvar!, setconstr!, setprimalsol!, setdualsol!,
set_robust_constr_generator!, get_robust_constr_generators,
setcol_from_sp_primalsol!, setcut_from_sp_dualsol! # TODO : merge with setvar! & setconstr!

# Methods related to duties
export isanArtificialDuty, isaStaticDuty, isaDynamicDuty, isanOriginalRepresentatives
Expand Down
2 changes: 1 addition & 1 deletion src/MathProg/decomposition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ function reformulate!(prob::Problem, annotations::Annotations)
decomposition_tree = annotations.tree
root = BD.getroot(decomposition_tree)
# Create reformulation
reform = Reformulation(prob)
reform = Reformulation()
set_re_formulation!(prob, reform)
buildformulations!(prob, annotations, reform, reform, root)

Expand Down
83 changes: 72 additions & 11 deletions src/MathProg/reformulation.jl
Original file line number Diff line number Diff line change
@@ -1,36 +1,97 @@
# TODO make immutable
mutable struct Reformulation <: AbstractFormulation
parent::Union{Nothing, AbstractFormulation} # reference to (pointer to) ancestor: Formulation or Reformulation
master::Union{Nothing, Formulation}
parent::Union{Nothing, AbstractFormulation} # reference to (pointer to) ancestor: Formulation or Reformulation (TODO rm Nothing)
master::Union{Nothing, Formulation} # TODO : rm Nothing
dw_pricing_subprs::Dict{FormId, AbstractModel}
benders_sep_subprs::Dict{FormId, AbstractModel}
dw_pricing_sp_lb::Dict{FormId, Id} # Attribute has ambiguous name
dw_pricing_sp_ub::Dict{FormId, Id}
dw_pricing_sp_lb::Dict{FormId, ConstrId}
dw_pricing_sp_ub::Dict{FormId, ConstrId}
end

"""
`Reformulation` is a representation of a formulation which is solved by Coluna
using a decomposition approach.

Reformulation(prob::AbstractProblem)
Reformulation()

Construct a `Reformulation` for problem `prob`.
Construct an empty `Reformulation`.
"""
function Reformulation(prob::AbstractProblem)
function Reformulation()
return Reformulation(nothing,
nothing,
Dict{FormId, AbstractModel}(),
Dict{FormId, AbstractModel}(),
Dict{FormId, Int}(),
Dict{FormId, Int}())
Dict{FormId, ConstrId}(),
Dict{FormId, ConstrId}())
end

"""
getobjsense(reformulation)

Return the objective sense of the master problem of the reformulation.
If the master problem has not been defined, it throws an error.
"""
function getobjsense(r::Reformulation)
r.master !== nothing && return getobjsense(r.master)
error("Undefined master in the reformulation, cannot return the objective sense.")
end

"""
getmaster(reformulation)

Return the formulation of the master problem.
"""
getmaster(r::Reformulation) = r.master
setmaster!(r::Reformulation, f) = r.master = f

# TODO : remove
setmaster!(r::Reformulation, f::Formulation) = r.master = f

"""
add_dw_pricing_sp!(reformulation, abstractmodel)

Add a Dantzig-Wolfe pricing subproblem in the reformulation.
"""
add_dw_pricing_sp!(r::Reformulation, f) = r.dw_pricing_subprs[getuid(f)] = f

"""
add_benders_sep_sp!(reformulation, abstractmodel)

Add a Benders separation subproblem in the reformulation.
"""
add_benders_sep_sp!(r::Reformulation, f) = r.benders_sep_subprs[getuid(f)] = f

"""
get_dw_pricing_sps(reformulation)

Return a `Dict{FormId, AbstractModel}` containing all Dabtzig-Wolfe pricing subproblems of
the reformulation.
"""
get_dw_pricing_sps(r::Reformulation) = r.dw_pricing_subprs

"""
get_benders_sep_sps(reformulation)

Return a `Dict{FormId, AbstractModel}` containing all Benders separation subproblems of the
reformulation.
"""
get_benders_sep_sps(r::Reformulation) = r.benders_sep_subprs
getobjsense(r::Reformulation) = getobjsense(r.master)

"""
get_dw_pricing_sp_ub_constrid(reformulation, spid::FormId)

Return the `ConstrId` of the upper bounded convexity constraint of Dantzig-Wolfe pricing
subproblem with id `spid`.
"""
get_dw_pricing_sp_ub_constrid(r::Reformulation, spid::FormId) = r.dw_pricing_sp_ub[spid]

"""
get_dw_pricing_sp_lb_constrid(reformulation, spid::FormId)

Return the `ConstrId` of the lower bounded convexity constraint of Dantzig-Wolfe pricing
subproblem with id `spid`.
"""
get_dw_pricing_sp_lb_constrid(r::Reformulation, spid::FormId) = r.dw_pricing_sp_lb[spid]

# Following two functions are temporary, we must store a pointer to the vc
# being represented by a representative vc
function vc_belongs_to_formulation(form::Formulation, vc::AbstractVarConstr)
Expand Down