API for MinimumWeightTwoStageSpanningTree.jl
Exported functions
MinimumWeightTwoStageSpanningTree.benders_decomposition
— Methodbenders_decomposition(inst::TwoStageSpanningTreeInstance;
MILP_solver=GLPK.Optimizer,
tol=0.000001,
silent=false,
)
Computes an optimal solution (with tolerance tol) of the two stage spanning tree problem using a Benders approach.
MinimumWeightTwoStageSpanningTree.build_solve_and_encode_instance_as_maximum_weight_forest
— Methodbuild_solve_and_encode_instance_as_maximum_weight_forest(;
grid_size=3,
seed=0,
nb_scenarios=10,
first_max=10,
second_max=20,
solver=lagrangian_heuristic_solver,
load_and_save=true
)
Builds a two stage spanning tree instance with a square grid graph of width grid_size
, seed
for the random number generator, nb_scenarios
for the second stage, first_max
and second_max
as first and second stage maximum weight.
Solves it with solver
.
Encodes it for a pipeline with a maximum weight forest layer.
MinimumWeightTwoStageSpanningTree.column_generation
— Methodcolumn_generation(inst::TwoStageSpanningTreeInstance;MILP_solver=GLPK.Optimizer,tol=0.00001)
Solves the dual of the linear relaxation of the two stage spanning tree MILP using a constraint generation.
Returns objective_value
, duals
MinimumWeightTwoStageSpanningTree.cut_generation
— Methodcut_generation(inst::TwoStageSpanningTreeInstance;
MILP_solver=GLPK.Optimizer,
separate_constraint_function=separate_forest_polytope_constraint_vertex_set_using_min_cut_MILP_formulation!,
tol=0.000001,
silent=false,
)
Solve the TwoStageSpanningTree
instance inst
using a cut generation approach.
separate_constraint_function
indicates which method is used to separate the constraint on subsets of vertices. Two options are available
separate_forest_polytope_constraint_vertex_set_using_min_cut_MILP_formulation!
separate_forest_polytope_constraint_vertex_set_using_simple_MILP_formulation!
MinimumWeightTwoStageSpanningTree.evaluate_first_stage_solution
— Methodevaluate_first_stage_solution(inst::TwoStageSpanningTreeInstance, forest)
Returns the value of the solution of inst
with forest
as first stage solution.
MinimumWeightTwoStageSpanningTree.kruskal_maximum_weight_forest
— Methodkruskal_maximum_weight_forest(θ::AbstractVector;inst=inst)
Return a maximum weight forest on inst.g
using θ as edge weight (returns a vector of edges)
MinimumWeightTwoStageSpanningTree.lagrangian_relaxation
— Methodlagrangian_relaxation(inst::TwoStageSpanningTreeInstance; nb_epochs=100)
Runs
- a subgradient algorithm during nb_epochs to solve the Lagrangian relaxation of inst (with
θ
initialized to 0) - a lagrangian heuristic on the resulting solution
Returns lb
, ub
, forest
, θ
, training_losses
with
lb
: value of the Lagrangian relaxationub
: value of the solution computed by the lagrangian heuristicforest
: solution computed by the lagrangian heuristicθ
: second stage problem valuetraining_losses
: vector with the value of the training losses along the subgradient algorithm
MinimumWeightTwoStageSpanningTree.maximum_weight_forest_linear_maximizer
— Methodmaximum_weight_forest_linear_maximizer(θ::AbstractVector;inst=inst)
Wrapper around kruskalmaximumweightforest(edgeweights_vector::AbstractVector, inst::TwoStageSpanningTreeInstance) that returns the solution encoded as a vector.
Private types and functions
MinimumWeightTwoStageSpanningTree.TwoStageSpanningTreeInstance
— TypeTwoStageSpanningTreeInstance
Contains all the relevant information defining a two stage spanning-tree instance.
Fields
g::SimpleGraph{Int}
: the graphedge_index::SparseMatrixCSC{Int64, Int64}
: edge_index[src(e),dst(e)] contains the index of edgee
nb_scenarios::Int
: number of scenariosfirst_stage_weights_matrix::SparseMatrixCSC{Float64, Int64}
:first_stage_weights_vector::Vector{Float64}
:second_stage_weights::Vector{SparseMatrixCSC{Float64, Int64}}
:
MinimumWeightTwoStageSpanningTree.TwoStageSpanningTreeInstance
— MethodTwoStageSpanningTreeInstance(g::AbstractGraph;nb_scenarios=1, first_max=10, second_max=20)
Build a random TwoStageSpanningTreeInstance from graph g
.
nb_scenarios
scenarios are drawn, with first-stage weights drawn uniformly between 0 and first_max
, and second-stage weights drawn uniformly between 0 an dsecond_max
.
MinimumWeightTwoStageSpanningTree.build_flow_graph_for_constraint_pricing!
— Functionfunction build_flow_graph_for_constraint_pricing!(
g::MetaGraph,
flow_graph::MetaDiGraph,
base_graph_vertices_vertex_index_in_flow_graph = Dict(),
base_graph_edges_vertex_index_in_flow_graph = Dict()
)
Constraint separated: ∑{e in E(X)}xe <= |X| - 1 for any ∅ ⊊ X ⊊ V
`
- g is the undirected graph on which the forest polytope is manipulated.
- flow_graph is a MetaDiGraph. It should be empty in input. It is modified by the function and contains afterwards the MetaDiGraph used to separate the forest polytope constraint on f
MinimumWeightTwoStageSpanningTree.build_load_or_solve
— Methodbuild_load_or_solve(;
graph=grid(5,5),
seed=0,
nb_scenarios=10,
first_max=10,
second_max=20,
solver=lagrangian_heuristic_solver,
load_and_save=true
)
Three solvers available
cut_solver
benders_solver
lagrangian_heuristic_solver
Return inst
, val
, sol
with:
inst
: the instance generatedval
: value of the solution computedsolution_computed
: solution computed
MinimumWeightTwoStageSpanningTree.edge_index
— Methodfunction edge_index(inst::TwoStageSpanningTreeInstance, e::AbstractEdge)
Returns inst.edge_index[src(e),dst(e)]
.
MinimumWeightTwoStageSpanningTree.kruskal_mst_value
— Functionkruskal_mst_value(g, distmx=weights(g); minimize=true)
extends kruskal_mst to return also the mst value
returns (mst weight), (mst edges)
MinimumWeightTwoStageSpanningTree.kruskal_on_first_scenario_instance
— Methodkruskal_on_first_scenario_instance(instance::TwoStageSpanningTreeInstance)
Applies Kruskal algorithm with weight inst.firststageweights + inst.secondstageweights[1]
Return value, firststagevalue, firststagesolution
MinimumWeightTwoStageSpanningTree.lagrangian_dual
— Methodlagrangian_dual(θ::AbstractArray; inst::TwoStageSpanningTreeInstance)
Compute the value of the lagrangian dual function for TwoStageSpanningTreeInstance instance inst with duals θ
θ[edged_index(src(e),dst(e)),s]
contains the value of the Lagrangian dual corresponding to edge e for scenario s
ChainRulesCore.rrule automatic differentiation with respect to θ works.
Return (value of the solution computed),(edges in the solution computed)
MinimumWeightTwoStageSpanningTree.lagrangian_heuristic
— Methodlagrangian_heuristic(θ::AbstractArray; inst::TwoStageSpanningTreeInstance)
Performs a lagrangian heuristic on TwoStageSpanningTree instance inst with duals θ.
θ[edge_index(src(e),dst(e)),s] contains the value of the Lagrangian dual corresponding to edge e for scenario s.
Return (value of the solution computed),(edges in the solution computed).
MinimumWeightTwoStageSpanningTree.maximum_weight_forest_layer_linear_encoder
— Methodmaximum_weight_forest_layer_linear_encoder(inst::TwoStageSpanningTreeInstance)
Returns X::Array{Float64} with X[f,edge_index(inst,e),s]
containing the value of feature number f
for edge e
and scenario s
Features used: (all are homogeneous to a cost)
first_stage_cost
second_stage_cost_quantile
best_stage_cost_quantile
neighbors_first_stage_cost_quantile
neighbors_scenario_second_stage_cost_quantile
is_in_first_stage_x_first_stage_cost
is_in_second_stage_x_second_stage_cost_quantile
is_first_in_best_stage_x_best_stage_cost_quantile
is_second_in_best_stage_x_best_stage_cost_quantile
For features with quantiles, the following quantiles are used: 0:0.1:1.
MinimumWeightTwoStageSpanningTree.separate_forest_polytope_constraint_vertex_set_using_min_cut_MILP_formulation!
— Methodseparate_forest_polytope_constraint_vertex_set_using_min_cut_MILP_formulation!(g::MetaGraph; MILP_solver=GLPK.Optimizer)
Uses a simple MILP to separate the constraints Constraint separated: ∑{e in E(X)} xe <= |X| - 1 for any ∅ ⊊ X ⊊ V
`
- g is a MetaGraph,
:cb_val
property contains the value of x_e
returns: found, X
- found : boolean indicating if a violated constraint has been found
- X : vertex set corresponding to the violated constraint
MinimumWeightTwoStageSpanningTree.separate_mst_Benders_cut!
— Methodseparate_mst_Benders_cut!(g::MetaGraph ; MILP_solver=GLPK.Optimizer)
separates optimality and feasibility cuts for the Benders decomposition formulation of the MST problem
input: property :x_val
contains the value of the master property :weight
contains the value of the second stage
returns a boolean equals to true if the cut is a feasibility cut and false if it is an optimality cut (in that case, the cut might be satisfied)
The value of the duals μ and ν are stored in properties :mu
and :nu
of the g
Index
MinimumWeightTwoStageSpanningTree.TwoStageSpanningTreeInstance
MinimumWeightTwoStageSpanningTree.TwoStageSpanningTreeInstance
MinimumWeightTwoStageSpanningTree.benders_decomposition
MinimumWeightTwoStageSpanningTree.build_flow_graph_for_constraint_pricing!
MinimumWeightTwoStageSpanningTree.build_load_or_solve
MinimumWeightTwoStageSpanningTree.build_solve_and_encode_instance_as_maximum_weight_forest
MinimumWeightTwoStageSpanningTree.column_generation
MinimumWeightTwoStageSpanningTree.cut_generation
MinimumWeightTwoStageSpanningTree.edge_index
MinimumWeightTwoStageSpanningTree.evaluate_first_stage_solution
MinimumWeightTwoStageSpanningTree.kruskal_maximum_weight_forest
MinimumWeightTwoStageSpanningTree.kruskal_mst_value
MinimumWeightTwoStageSpanningTree.kruskal_on_first_scenario_instance
MinimumWeightTwoStageSpanningTree.lagrangian_dual
MinimumWeightTwoStageSpanningTree.lagrangian_heuristic
MinimumWeightTwoStageSpanningTree.lagrangian_relaxation
MinimumWeightTwoStageSpanningTree.maximum_weight_forest_layer_linear_encoder
MinimumWeightTwoStageSpanningTree.maximum_weight_forest_linear_maximizer
MinimumWeightTwoStageSpanningTree.separate_forest_polytope_constraint_vertex_set_using_min_cut_MILP_formulation!
MinimumWeightTwoStageSpanningTree.separate_mst_Benders_cut!