Skip to content

Commit

Permalink
rename StorageState -> RecordState (#470)
Browse files Browse the repository at this point in the history
* rename StorageState -> RecordState

* additional updates
  • Loading branch information
guimarqu authored Mar 18, 2021
1 parent ead01f1 commit f1941be
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 114 deletions.
10 changes: 5 additions & 5 deletions src/Algorithm/colgenstabilization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ smoothing_is_active(storage::ColGenStabilizationStorage) = !iszero(storage.cural
subgradient_is_needed(storage::ColGenStabilizationStorage, smoothparam::Float64) =
smoothparam == 1.0 && storage.nb_misprices == 0

mutable struct ColGenStabStorageState <: AbstractStorageState
mutable struct ColGenStabRecordState <: AbstractRecordState
alpha::Float64
dualbound::DualBound
stabcenter::Union{Nothing, DualSolution}
end

function ColGenStabStorageState(master::Formulation, storage::ColGenStabilizationStorage)
function ColGenStabRecordState(master::Formulation, storage::ColGenStabilizationStorage)
alpha = storage.basealpha < 0.5 ? 0.5 : storage.basealpha
return ColGenStabStorageState(alpha, storage.valid_dual_bound, storage.basestabcenter)
return ColGenStabRecordState(alpha, storage.valid_dual_bound, storage.basestabcenter)
end

function restorefromstate!(
master::Formulation, storage::ColGenStabilizationStorage, state::ColGenStabStorageState
master::Formulation, storage::ColGenStabilizationStorage, state::ColGenStabRecordState
)
storage.basealpha = state.alpha
storage.valid_dual_bound = state.dualbound
storage.basestabcenter = state.stabcenter
return
end

const ColGenStabilizationStoragePair = (ColGenStabilizationStorage => ColGenStabStorageState)
const ColGenStabilizationStoragePair = (ColGenStabilizationStorage => ColGenStabRecordState)

function init_stab_before_colgen_loop!(storage::ColGenStabilizationStorage)
storage.stabcenter = storage.basestabcenter
Expand Down
8 changes: 4 additions & 4 deletions src/Algorithm/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract type AbstractData end
getstoragedict(::AbstractData) = nothing
getmodel(::AbstractData) = nothing
get_model_storage_dict(::AbstractData, ::AbstractModel) = nothing
store_states!(::AbstractData, ::StorageStatesVector) = nothing
store_states!(::AbstractData, ::RecordStatesVector) = nothing
check_storage_states_participation(::AbstractData) = nothing

function getnicename(data::AbstractData)
Expand Down Expand Up @@ -63,7 +63,7 @@ function get_model_storage_dict(data::ModelData, model::AbstractModel)
return nothing
end

function store_states!(data::ModelData, states::StorageStatesVector)
function store_states!(data::ModelData, states::RecordStatesVector)
storagedict = getstoragedict(data)
for (FullType, storagecont) in storagedict
stateid = storestate!(storagecont)
Expand Down Expand Up @@ -142,7 +142,7 @@ function get_model_storage_dict(data::ReformData, model::AbstractModel)
return nothing
end

function store_states!(data::ReformData, states::StorageStatesVector)
function store_states!(data::ReformData, states::RecordStatesVector)
storagedict = getstoragedict(data)
for (FullType, storagecont) in storagedict
stateid = storestate!(storagecont)
Expand All @@ -159,7 +159,7 @@ end

function store_states!(data::ReformData)
TO.@timeit Coluna._to "Store states" begin
states = StorageStatesVector()
states = RecordStatesVector()
store_states!(data, states)
end
return states
Expand Down
48 changes: 24 additions & 24 deletions src/Algorithm/formstorages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
Formulation storage is empty and it is used to implicitely keep
the data which is changed inside the model
(for example, dynamic variables and constraints of a formulaiton)
in order to store it to the storage state and restore it afterwards.
in order to store it to the record state and restore it afterwards.
"""

struct FormulationStorage <: AbstractStorage end
Expand All @@ -65,24 +65,24 @@ FormulationStorage(form::Formulation) = FormulationStorage()
MasterBranchConstrsStoragePair
Storage pair for master branching constraints.
Consists of FormulationStorage and MasterBranchConstrsStorageState.
Consists of FormulationStorage and MasterBranchConstrsRecordState.
"""

mutable struct MasterBranchConstrsStorageState <: AbstractStorageState
mutable struct MasterBranchConstrsRecordState <: AbstractRecordState
constrs::Dict{ConstrId, ConstrState}
end

function Base.show(io::IO, state::MasterBranchConstrsStorageState)
function Base.show(io::IO, state::MasterBranchConstrsRecordState)
print(io, "[")
for (id, constr) in state.constrs
print(io, " ", MathProg.getuid(id))
end
print(io, "]")
end

function MasterBranchConstrsStorageState(form::Formulation, storage::FormulationStorage)
function MasterBranchConstrsRecordState(form::Formulation, storage::FormulationStorage)
@logmsg LogLevel(-2) "Storing branching constraints"
state = MasterBranchConstrsStorageState(Dict{ConstrId, ConstrState}())
state = MasterBranchConstrsRecordState(Dict{ConstrId, ConstrState}())
for (id, constr) in getconstrs(form)
if getduty(id) <= AbstractMasterBranchingConstr &&
iscuractive(form, constr) && isexplicit(form, constr)
Expand All @@ -95,7 +95,7 @@ function MasterBranchConstrsStorageState(form::Formulation, storage::Formulation
end

function restorefromstate!(
form::Formulation, storage::FormulationStorage, state::MasterBranchConstrsStorageState
form::Formulation, storage::FormulationStorage, state::MasterBranchConstrsRecordState
)
@logmsg LogLevel(-2) "Restoring branching constraints"
for (id, constr) in getconstrs(form)
Expand All @@ -120,7 +120,7 @@ function restorefromstate!(
end
end

const MasterBranchConstrsStoragePair = (FormulationStorage => MasterBranchConstrsStorageState)
const MasterBranchConstrsStoragePair = (FormulationStorage => MasterBranchConstrsRecordState)

"""
MasterColumnsStoragePair
Expand All @@ -129,7 +129,7 @@ const MasterBranchConstrsStoragePair = (FormulationStorage => MasterBranchConstr
Consists of EmptyStorage and MasterColumnsState.
"""

mutable struct MasterColumnsState <: AbstractStorageState
mutable struct MasterColumnsState <: AbstractRecordState
cols::Dict{VarId, VarState}
end

Expand Down Expand Up @@ -188,7 +188,7 @@ const MasterColumnsStoragePair = (FormulationStorage => MasterColumnsState)
Consists of EmptyStorage and MasterCutsState.
"""

mutable struct MasterCutsState <: AbstractStorageState
mutable struct MasterCutsState <: AbstractRecordState
cuts::Dict{ConstrId, ConstrState}
end

Expand Down Expand Up @@ -244,17 +244,17 @@ const MasterCutsStoragePair = (FormulationStorage => MasterCutsState)
StaticVarConstrStoragePair
Storage pair for static variables and constraints of a formulation.
Consists of EmptyStorage and StaticVarConstrStorageState.
Consists of EmptyStorage and StaticVarConstrRecordState.
"""

mutable struct StaticVarConstrStorageState <: AbstractStorageState
mutable struct StaticVarConstrRecordState <: AbstractRecordState
constrs::Dict{ConstrId, ConstrState}
vars::Dict{VarId, VarState}
end

#TO DO: we need to keep here only the difference with the initial data

function Base.show(io::IO, state::StaticVarConstrStorageState)
function Base.show(io::IO, state::StaticVarConstrRecordState)
print(io, "[vars:")
for (id, var) in state.vars
print(io, " ", MathProg.getuid(id))
Expand All @@ -266,9 +266,9 @@ function Base.show(io::IO, state::StaticVarConstrStorageState)
print(io, "]")
end

function StaticVarConstrStorageState(form::Formulation, storage::FormulationStorage)
function StaticVarConstrRecordState(form::Formulation, storage::FormulationStorage)
@logmsg LogLevel(-2) string("Storing static vars and consts")
state = StaticVarConstrStorageState(Dict{ConstrId, ConstrState}(), Dict{VarId, VarState}())
state = StaticVarConstrRecordState(Dict{ConstrId, ConstrState}(), Dict{VarId, VarState}())
for (id, constr) in getconstrs(form)
if isaStaticDuty(getduty(id)) && iscuractive(form, constr) && isexplicit(form, constr)
constrstate = ConstrState(getcurrhs(form, constr))
Expand All @@ -285,7 +285,7 @@ function StaticVarConstrStorageState(form::Formulation, storage::FormulationStor
end

function restorefromstate!(
form::Formulation, storage::FormulationStorage, state::StaticVarConstrStorageState
form::Formulation, storage::FormulationStorage, state::StaticVarConstrRecordState
)
@logmsg LogLevel(-2) "Restoring static vars and consts"
for (id, constr) in getconstrs(form)
Expand Down Expand Up @@ -326,13 +326,13 @@ function restorefromstate!(
end
end

const StaticVarConstrStoragePair = (FormulationStorage => StaticVarConstrStorageState)
const StaticVarConstrStoragePair = (FormulationStorage => StaticVarConstrRecordState)

"""
PartialSolutionStoragePair
Storage pair for partial solution of a formulation.
Consists of PartialSolutionStorage and PartialSolutionStorageState.
Consists of PartialSolutionStorage and PartialSolutionRecordState.
"""

# TO DO : to replace dictionaries by PrimalSolution
Expand Down Expand Up @@ -363,21 +363,21 @@ function PartialSolutionStorage(form::Formulation)
return PartialSolutionStorage(Dict{VarId, Float64}())
end

# the storage state is the same as the storage here
mutable struct PartialSolutionStorageState <: AbstractStorageState
# the record state is the same as the storage here
mutable struct PartialSolutionRecordState <: AbstractRecordState
solution::Dict{VarId, Float64}
end

function PartialSolutionStorageState(form::Formulation, storage::PartialSolutionStorage)
function PartialSolutionRecordState(form::Formulation, storage::PartialSolutionStorage)
@logmsg LogLevel(-2) "Storing partial solution"
return PartialSolutionStorageState(copy(storage.solution))
return PartialSolutionRecordState(copy(storage.solution))
end

function restorefromstate!(
form::Formulation, storage::PartialSolutionStorage, state::PartialSolutionStorageState
form::Formulation, storage::PartialSolutionStorage, state::PartialSolutionRecordState
)
@logmsg LogLevel(-2) "Restoring partial solution"
storage.solution = copy(state.solution)
end

const PartialSolutionStoragePair = (PartialSolutionStorage => PartialSolutionStorageState)
const PartialSolutionStoragePair = (PartialSolutionStorage => PartialSolutionRecordState)
4 changes: 2 additions & 2 deletions src/Algorithm/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ function initialize_storages!(data::AbstractData, algo::AbstractOptimizationAlgo
)
end
for type_pair in type_pair_set
(StorageType, StorageStateType) = type_pair
(StorageType, RecordStateType) = type_pair
storagedict[type_pair] =
StorageContainer{ModelType, StorageType, StorageStateType}(model)
StorageContainer{ModelType, StorageType, RecordStateType}(model)
end
end
end
6 changes: 3 additions & 3 deletions src/Algorithm/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ mutable struct Node
optstate::OptimizationState
#branch::Union{Nothing, Branch} # branch::Id{Constraint}
branchdescription::String
stateids::StorageStatesVector
stateids::RecordStatesVector
conquerwasrun::Bool
end

function RootNode(
form::AbstractFormulation, optstate::OptimizationState, storagestateids::StorageStatesVector, skipconquer::Bool
form::AbstractFormulation, optstate::OptimizationState, storagestateids::RecordStatesVector, skipconquer::Bool
)
nodestate = OptimizationState(form, optstate, false, skipconquer)
tree_order = skipconquer ? 0 : -1
Expand All @@ -25,7 +25,7 @@ function RootNode(
end

function Node(
form::AbstractFormulation, parent::Node, branchdescription::String, storagestateids::StorageStatesVector
form::AbstractFormulation, parent::Node, branchdescription::String, storagestateids::RecordStatesVector
)
depth = getdepth(parent) + 1
nodestate = OptimizationState(form, getoptstate(parent), false, false)
Expand Down
12 changes: 6 additions & 6 deletions src/Algorithm/preprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ function add_to_stack!(
end

"""
PreprocessingStorageState
PreprocessingRecordState
Stores the global part of preprocessing storage
"""

mutable struct PreprocessingStorageState <: AbstractStorageState
mutable struct PreprocessingRecordState <: AbstractRecordState
cur_min_slack::Dict{ConstrId,Float64}
cur_max_slack::Dict{ConstrId,Float64}
nb_inf_sources_for_min_slack::Dict{ConstrId,Int}
Expand All @@ -114,8 +114,8 @@ mutable struct PreprocessingStorageState <: AbstractStorageState
local_partial_sol::Dict{VarId, Float64}
end

function PreprocessingStorageState(reform::Reformulation, storage::PreprocessingStorage)
return PreprocessingStorageState(
function PreprocessingRecordState(reform::Reformulation, storage::PreprocessingStorage)
return PreprocessingRecordState(
copy(storage.cur_min_slack), copy(storage.cur_max_slack),
copy(storage.nb_inf_sources_for_min_slack),
copy(storage.nb_inf_sources_for_max_slack),
Expand All @@ -124,7 +124,7 @@ function PreprocessingStorageState(reform::Reformulation, storage::Preprocessing
end

function restorefromstate!(
form::Reformulation, storage::PreprocessingStorage, state::PreprocessingStorageState
form::Reformulation, storage::PreprocessingStorage, state::PreprocessingRecordState
)
storage.cur_min_slack = copy(state.cur_min_slack)
storage.cur_max_slack = copy(state.cur_max_slack)
Expand All @@ -136,7 +136,7 @@ function restorefromstate!(
storage.local_partial_sol = copy(state.local_partial_sol)
end

const PreprocessingStoragePair = (PreprocessingStorage => PreprocessingStorageState)
const PreprocessingStoragePair = (PreprocessingStorage => PreprocessingRecordState)


"""
Expand Down
Loading

0 comments on commit f1941be

Please sign in to comment.