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

Nice reformulation output #1111

Merged
merged 1 commit into from
Nov 29, 2023
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
187 changes: 89 additions & 98 deletions src/MathProg/duties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"Master of a formulation decomposed using Benders."
struct BendersMaster <: AbstractMasterDuty end

mutable struct DwSp <: AbstractSpDuty
mutable struct DwSp <: AbstractSpDuty
setup_var::Union{VarId,Nothing}
lower_multiplicity_constr_id::Union{ConstrId,Nothing}
upper_multiplicity_constr_id::Union{ConstrId,Nothing}
Expand All @@ -30,140 +30,131 @@
"A pricing subproblem of a formulation decomposed using Dantzig-Wolfe."
function DwSp(setup_var, lower_multiplicity_constr_id, upper_multiplicity_constr_id, column_var_kind)
return DwSp(
setup_var, lower_multiplicity_constr_id, upper_multiplicity_constr_id,
setup_var, lower_multiplicity_constr_id, upper_multiplicity_constr_id,
column_var_kind,
Pool()
)
end
mutable struct BendersSp <: AbstractSpDuty
slack_to_first_stage::Dict{VarId, VarId}
mutable struct BendersSp <: AbstractSpDuty
slack_to_first_stage::Dict{VarId,VarId}
second_stage_cost_var::Union{VarId,Nothing}
pool::DualSolutionPool
end

"A Benders subproblem of a formulation decomposed using Benders."
BendersSp() = BendersSp(Dict{VarId, VarId}(), nothing, DualSolutionPool())
BendersSp() = BendersSp(Dict{VarId,VarId}(), nothing, DualSolutionPool())

############################################################################################
# Duties tree for a Variable
############################################################################################
@exported_nestedenum begin
Duty{Variable}
AbstractOriginalVar <= Duty{Variable}
OriginalVar <= AbstractOriginalVar
#OriginalExpression <= AbstractOriginalVar
AbstractMasterVar <= Duty{Variable}
AbstractOriginMasterVar <= AbstractMasterVar
MasterPureVar <= AbstractOriginMasterVar
MasterBendFirstStageVar <= AbstractOriginMasterVar
AbstractAddedMasterVar <= AbstractMasterVar
MasterCol <= AbstractAddedMasterVar
MasterArtVar <= AbstractAddedMasterVar
MasterBendSecondStageCostVar <= AbstractAddedMasterVar
AbstractImplicitMasterVar <= AbstractMasterVar
AbstractMasterRepDwSpVar <= AbstractImplicitMasterVar
MasterRepPricingVar <= AbstractMasterRepDwSpVar
MasterRepPricingSetupVar <= AbstractMasterRepDwSpVar
AbstractDwSpVar <= Duty{Variable}
DwSpPricingVar <= AbstractDwSpVar
DwSpSetupVar <= AbstractDwSpVar
#DwSpPureVar <= AbstractDwSpVar
DwSpPrimalSol <= AbstractDwSpVar
AbstractBendSpVar <= Duty{Variable}
AbstractBendSpSlackMastVar <= AbstractBendSpVar
BendSpSlackFirstStageVar <= AbstractBendSpSlackMastVar
BendSpPosSlackFirstStageVar <= BendSpSlackFirstStageVar
BendSpNegSlackFirstStageVar <= BendSpSlackFirstStageVar
BendSpSlackSecondStageCostVar <= AbstractBendSpSlackMastVar
BendSpSecondStageArtVar <= AbstractBendSpSlackMastVar
BendSpSepVar <= AbstractBendSpVar
BendSpFirstStageRepVar <= AbstractBendSpVar
BendSpCostRepVar <= AbstractBendSpVar
AbstractOriginalVar <= Duty{Variable}
OriginalVar <= AbstractOriginalVar
AbstractMasterVar <= Duty{Variable}
AbstractOriginMasterVar <= AbstractMasterVar
MasterPureVar <= AbstractOriginMasterVar
MasterBendFirstStageVar <= AbstractOriginMasterVar
AbstractAddedMasterVar <= AbstractMasterVar
MasterCol <= AbstractAddedMasterVar
MasterArtVar <= AbstractAddedMasterVar
MasterBendSecondStageCostVar <= AbstractAddedMasterVar
AbstractImplicitMasterVar <= AbstractMasterVar
AbstractMasterRepDwSpVar <= AbstractImplicitMasterVar
MasterRepPricingVar <= AbstractMasterRepDwSpVar
MasterRepPricingSetupVar <= AbstractMasterRepDwSpVar
AbstractDwSpVar <= Duty{Variable}
DwSpPricingVar <= AbstractDwSpVar
DwSpSetupVar <= AbstractDwSpVar
DwSpPrimalSol <= AbstractDwSpVar
AbstractBendSpVar <= Duty{Variable}
AbstractBendSpSlackMastVar <= AbstractBendSpVar
BendSpSlackFirstStageVar <= AbstractBendSpSlackMastVar
BendSpPosSlackFirstStageVar <= BendSpSlackFirstStageVar
BendSpNegSlackFirstStageVar <= BendSpSlackFirstStageVar
BendSpSlackSecondStageCostVar <= AbstractBendSpSlackMastVar
BendSpSecondStageArtVar <= AbstractBendSpSlackMastVar
BendSpSepVar <= AbstractBendSpVar
BendSpFirstStageRepVar <= AbstractBendSpVar
BendSpCostRepVar <= AbstractBendSpVar
end

############################################################################################
# Duties tree for a Constraint
############################################################################################
@exported_nestedenum begin
Duty{Constraint}
AbstractOriginalConstr <= Duty{Constraint}
OriginalConstr <= AbstractOriginalConstr
AbstractMasterConstr <= Duty{Constraint}
AbstractMasterOriginConstr <= AbstractMasterConstr
MasterPureConstr <= AbstractMasterOriginConstr
MasterMixedConstr <= AbstractMasterOriginConstr
AbstractMasterAddedConstr <= AbstractMasterConstr
MasterConvexityConstr <= AbstractMasterAddedConstr
#MasterSecondStageCostConstr <= AbstractMasterAddedConstr
#AbstractMasterImplicitConstr <= AbstractMasterConstr
#AbstractMasterRepBendSpConstr <= AbstractMasterImplicitConstr
#MasterRepBendSpSecondStageCostConstr <= AbstractMasterRepBendSpConstr
#MasterRepBendSpTechnologicalConstr <= AbstractMasterRepBendSpConstr
AbstractMasterCutConstr <= AbstractMasterConstr
MasterBendCutConstr <= AbstractMasterCutConstr
MasterUserCutConstr <= AbstractMasterCutConstr
AbstractMasterBranchingConstr <= AbstractMasterConstr
MasterBranchOnOrigVarConstr <= AbstractMasterBranchingConstr
AbstractDwSpConstr <= Duty{Constraint}
DwSpPureConstr <= AbstractDwSpConstr
# <= AbstractDwSpConstr
#DwSpRepMastBranchConstr <= AbstractDwSpConstr
#AbstractBendSpPureConstr <= Duty{Constraint}
AbstractBendSpConstr <= Duty{Constraint}
AbstractBendSpMasterConstr <= AbstractBendSpConstr
BendSpSecondStageCostConstr <= AbstractBendSpMasterConstr
BendSpTechnologicalConstr <= AbstractBendSpMasterConstr
BendSpPureConstr <= AbstractBendSpConstr
BendSpDualSol <= AbstractBendSpConstr
AbstractOriginalConstr <= Duty{Constraint}
OriginalConstr <= AbstractOriginalConstr
AbstractMasterConstr <= Duty{Constraint}
AbstractMasterOriginConstr <= AbstractMasterConstr
MasterPureConstr <= AbstractMasterOriginConstr
MasterMixedConstr <= AbstractMasterOriginConstr
AbstractMasterAddedConstr <= AbstractMasterConstr
MasterConvexityConstr <= AbstractMasterAddedConstr
AbstractMasterCutConstr <= AbstractMasterConstr
MasterBendCutConstr <= AbstractMasterCutConstr
MasterUserCutConstr <= AbstractMasterCutConstr
AbstractMasterBranchingConstr <= AbstractMasterConstr
MasterBranchOnOrigVarConstr <= AbstractMasterBranchingConstr
AbstractDwSpConstr <= Duty{Constraint}
DwSpPureConstr <= AbstractDwSpConstr
AbstractBendSpConstr <= Duty{Constraint}
AbstractBendSpMasterConstr <= AbstractBendSpConstr
BendSpSecondStageCostConstr <= AbstractBendSpMasterConstr
BendSpTechnologicalConstr <= AbstractBendSpMasterConstr
BendSpPureConstr <= AbstractBendSpConstr
BendSpDualSol <= AbstractBendSpConstr
end

############################################################################################
# Methods to get extra information about duties
############################################################################################
function isaStaticDuty(duty::NestedEnum)
return duty <= OriginalVar ||
#duty <= OriginalExpression ||
duty <= MasterPureVar ||
duty <= MasterArtVar ||
duty <= MasterBendSecondStageCostVar ||
duty <= MasterBendFirstStageVar ||
duty <= MasterRepPricingVar ||
duty <= MasterRepPricingSetupVar ||
duty <= DwSpPricingVar ||
duty <= DwSpSetupVar ||
#duty <= DwSpPureVar ||
duty <= DwSpPrimalSol ||
#duty <= DwSpDualSol ||
duty <= BendSpSepVar ||
#duty <= BendSpPureVar ||
duty <= BendSpSlackFirstStageVar ||
duty <= BendSpSlackSecondStageCostVar ||
duty <= OriginalConstr ||
duty <= MasterPureConstr ||
duty <= MasterMixedConstr ||
duty <= MasterConvexityConstr ||
#duty <= MasterSecondStageCostConstr ||
duty <= DwSpPureConstr ||
duty <= BendSpPureConstr ||
duty <= BendSpDualSol ||
duty <= BendSpSecondStageCostConstr ||
duty <= BendSpTechnologicalConstr
duty <= MasterPureVar ||
duty <= MasterArtVar ||
duty <= MasterBendSecondStageCostVar ||
duty <= MasterBendFirstStageVar ||
duty <= MasterRepPricingVar ||
duty <= MasterRepPricingSetupVar ||
duty <= DwSpPricingVar ||
duty <= DwSpSetupVar ||
duty <= DwSpPrimalSol ||
duty <= BendSpSepVar ||
duty <= BendSpSlackFirstStageVar ||
duty <= BendSpSlackSecondStageCostVar ||
duty <= OriginalConstr ||
duty <= MasterPureConstr ||
duty <= MasterMixedConstr ||
duty <= MasterConvexityConstr ||
duty <= DwSpPureConstr ||
duty <= BendSpPureConstr ||
duty <= BendSpDualSol ||
duty <= BendSpSecondStageCostConstr ||
duty <= BendSpTechnologicalConstr
end

function isaDynamicDuty(duty::NestedEnum)
duty <= MasterCol ||
duty <= MasterBranchOnOrigVarConstr ||
duty <= MasterBendCutConstr ||
duty <= MasterBranchOnOrigVarConstr
#duty <= DwSpRepMastBranchConstr ||
#duty <= DwSpRepMastBranchConstr
return duty <= MasterCol ||

Check warning on line 139 in src/MathProg/duties.jl

View check run for this annotation

Codecov / codecov/patch

src/MathProg/duties.jl#L139

Added line #L139 was not covered by tests
duty <= MasterBranchOnOrigVarConstr ||
duty <= MasterBendCutConstr ||
duty <= MasterBranchOnOrigVarConstr
end

function isanOriginalRepresentatives(duty::NestedEnum)
duty <= MasterPureVar ||
duty <= MasterRepPricingVar
return duty <= MasterPureVar ||
duty <= MasterRepPricingVar
end

function isanArtificialDuty(duty::NestedEnum)
return duty <= MasterArtVar || duty <= BendSpSecondStageArtVar
end

function isaNonUserDefinedDuty(duty::NestedEnum)
return duty <= MasterArtVar ||
duty <= MasterRepPricingSetupVar ||
duty <= MasterCol ||
duty <= DwSpSetupVar ||
duty <= MasterConvexityConstr
end
Loading
Loading