Network Flow Model
FlowGenerator.NetworkFlowModel.ArcFlowSolution
— Typestruct ArcFlowSolution
A solution object for network flow problems that maps arcs to their flows.
Fields
arc_to_flow_map::Dict{Arc,Float64}
: A dictionary that mapsArc
objects toFloat64
flow values.source::Vertex
: The source of the flow.sink::Vertex
: The destination of of the flow.
Constructor
ArcFlowSolution(c::Commodity)
Constructs an ArcFlowSolution
with an empty flow map and specified source and sink vertices based on a given Commodity
.
FlowGenerator.NetworkFlowModel.Problem
— Typestruct Problem
Encapsulates the data needed to define and solve a network flow optimization problem.
Fields
network::Network
: Represents the flow network with nodes and arcs.objective_function::ObjectiveFunction
: A linear function defining the objective of the optimization.arc_to_capacity_map::IndexedMap{Arc,Float64}
: A mapping from arcs to their capacities.arc_to_var_type_map::IndexedMap{Arc,VarType}
: A mapping from arcs to their variable types, eitherINTEGER
orCONTINUOUS
.constraints::Vector{Constraint}
: A vector of generic linear side-constraints.commodities::Vector{Commodity}
: A vector of commodities to be sent through the network.arc_to_side_constr_coeffs::LinkedListMap{Tuple{Int,Float64}}
: An auxiliary mapping for side constraints coefficients for enhanced solution computation. To be computed by constructors.
Constructors
Problem(network, arc_to_cost, arc_to_capacity, arc_to_var_type, constraints, commodities)
: Constructs aProblem
instance given network parameters and functions to define arc costs, capacities, variable types, constraints, and commodities.Problem(problem, network)
: Constructs a newProblem
instance based on an existing problem but with a different network structure.
Methods
get_network(problem)
: Returns the network of the problem.get_arcs(problem)
: Returns the arcs of the problem's network.get_vertices(problem)
: Returns the vertices of the problem's network.get_constraints(problem)
: Returns the constraints of the problem.get_commodities(problem)
: Returns the commodities of the problem.get_cost(problem, arc)
: Returns the cost of an arc.get_cost(problem, path)
: Returns the cost of a path.get_capacity(problem, arc)
: Returns the capacity of an arc.get_var_type(problem, arc)
: Returns the variable type of an arc.get_constr_coeff_list(problem, arc)
: Returns the list of constraint coefficients for an arc.push_constraint!(problem, constraint)
: Adds a new constraint to the problem.pop_constraint!(problem)
: Removes the most recently added constraint from the problem._get_arc_to_side_constr_coeffs(arcs, constraints)
: Internal function to initialize the mapping of arcs to their side constraint coefficients.is_problem_integer(problem)
: Returns true if the objective is integer for any feasible solution satisfying integrality constraints.filter_arcs(problem, pred)
: Returns a new instance ofProblem
where only the arcs satisfying the predicatepred
are kept.
FlowGenerator.NetworkFlowModel.VarType
— Type@enum VarType
An Enum type representing different variable types for arcs in a flow network problem.
Values
INTEGER
: Indicates that the variable is restricted to integer values.CONTINUOUS
: Indicates that the variable can take any continuous real value.
Base.in
— MethodBase.in(arc::Arc, network::Network)
Check if an arc is in the network.
Base.in
— MethodBase.in(hyper_tree::HyperTree, network::Network)
Check if a hyper-tree is in the network.
Base.in
— MethodBase.in(path::Path, network::Network)
Check if a path is in the network.
FlowGenerator.NetworkFlowModel.convert_to_path_flow_solution
— Methodconvert_to_path_flow_solution(network::Network, arc_flow_solution::ArcFlowSolution)
Convert an ArcFlowSolution to a PathFlowSolution using a flow decomposition algorithm.
FlowGenerator.NetworkFlowModel.fill_arc_to_reduced_cost_map!
— Methodfill_arc_to_reduced_cost_map!(arc_to_reduced_cost_map::AbstractDict{Arc,Float64}, problem::Problem, dual_solution::DualSolution)
Fill the arc_to_reduced_cost_map
with the reduced cost of each arc.
FlowGenerator.NetworkFlowModel.filter_arcs
— Methodfilter_arcs(network::Network, predicate::Function)
Return a copy of the network with only the arcs that satisfy a given predicate.
FlowGenerator.NetworkFlowModel.filter_arcs
— Methodfilter_arcs(problem::Problem, predicate::Function) -> Problem
Creates a new Problem
instance by filtering out arcs in the original problem's network that do not satisfy a given predicate function.
FlowGenerator.NetworkFlowModel.find_path
— Methodfind_path(network::Network, source::Vertex, sink::Vertex, arc_to_flow::Function)
Returns a path from source to sink in a network with positive flow capacity. If no such path exists, returns nothing
.
FlowGenerator.NetworkFlowModel.get_arc_flow_solution
— Methodget_arc_flow_solution(primal_solution::PrimalSolution, commodity::Commodity)
Return the arc flow solution for a specific commodity in the given primal solution.
FlowGenerator.NetworkFlowModel.get_arc_reduced_cost
— Methodget_arc_reduced_cost(problem::Problem, dual_solution::DualSolution, arc::Arc; capacity_dual = get_arc_capacity_dual(problem, dual_solution, arc))
Get the reduced cost of an arc based on the dual solution. The reduced cost is computed based on side constraint and capacity dual values, but not on commodity and flow conservation dual values.
FlowGenerator.NetworkFlowModel.get_arc_to_flow_map
— Methodget_arc_to_flow_map(primal_solution::PrimalSolution, commodity::Commodity)
Return the arc to flow map for a specific commodity in the given primal solution.
FlowGenerator.NetworkFlowModel.get_arcs
— Methodget_arcs(network::Network)
Return the list of arcs in the network.
FlowGenerator.NetworkFlowModel.get_commodity_dual
— Methodget_commodity_dual(dual_solution::DualSolution, commodity::Commodity)
Get the dual value associated with a commodity.
FlowGenerator.NetworkFlowModel.get_flow_conservation_balance
— Methodget_flow_conservation_balance(arc_to_flow_map::Dict{Arc,Float64})
Calculates the flow conservation balance for each vertex based on a given arc_to_flow_map
.
Returns
- A dictionary mapping each vertex to its flow conservation balance.
FlowGenerator.NetworkFlowModel.get_flow_conservation_balance
— Methodget_flow_conservation_balance(sol::ArcFlowSolution)
Calculates the flow conservation balance for each vertex in an ArcFlowSolution
.
Returns
- A dictionary mapping each vertex to its flow conservation balance.
FlowGenerator.NetworkFlowModel.get_flow_cost
— Methodget_flow_cost(problem::Problem, arc_to_flow_map::Dict{Arc,Float64})
Returns the total flow cost for a given problem.
FlowGenerator.NetworkFlowModel.get_incoming_flow
— Methodget_incoming_flow(arc_flow_solution::ArcFlowSolution, vertex::Vertex)
Returns the total incoming flow to a specified vertex in an ArcFlowSolution
.
FlowGenerator.NetworkFlowModel.get_obj_val
— Methodget_obj_val(problem::Problem, dual_solution::DualSolution)
Return objective value of dual solution. Dual feasibility is not taken into account.
FlowGenerator.NetworkFlowModel.get_obj_val
— Methodget_obj_val(problem::Problem, solution::PrimalSolution)
Calculate the objective value of a primal solution for a given problem. The objective consists of: flow cost and constraint/commodity violation penalty costs
FlowGenerator.NetworkFlowModel.get_outgoing_arcs
— Methodgetoutgoingarcs(n::Network, v::Vertex)
Return the list of outgoing arcs from a given vertex in the network.
FlowGenerator.NetworkFlowModel.get_path_flow
— Methodget_path_flow(sol::PathFlowSolution, path::Path)
Get the flow associated with a specific path in a PathFlowSolution. If the path is not present in the solution, returns 0.0.
FlowGenerator.NetworkFlowModel.get_path_to_flow_map
— Methodget_path_to_flow_map(sol::PathFlowSolution)
Get the path to flow map in a PathFlowSolution.
FlowGenerator.NetworkFlowModel.get_side_constraint_dual
— Methodget_side_constraint_dual(dual_solution::DualSolution, constraint::Constraint)
Get the dual value associated with a side constraint.
FlowGenerator.NetworkFlowModel.get_vertices
— Methodget_vertices(arc::Arc)
Return all vertices in the arc.
FlowGenerator.NetworkFlowModel.get_vertices
— Methodget_vertices(network::Network)
Return the list of vertices in the network.
FlowGenerator.NetworkFlowModel.get_vertices
— Methodget_vertices(arcs::Vector{Arc})
Return all vertices in the list of arcs.
FlowGenerator.NetworkFlowModel.is_flow_conservation_feasible
— Methodis_flow_conservation_feasible(sol::ArcFlowSolution)
Checks if flow conservation is feasible for an ArcFlowSolution
.
Flow conservation is feasible if the flow conservation balance of all intermediate nodes is zero
Returns
true
if flow conservation is feasible,false
otherwise.
FlowGenerator.NetworkFlowModel.is_hyper_graph
— Methodishypergraph(n::Network)
Check if the network is a hypergraph.
FlowGenerator.NetworkFlowModel.is_integrality_feasible
— Methodis_integrality_feasible(problem::Problem, solution::ArcFlowSolution)
Checks if flow integrality of an ArcFlowSolution
is satisfied for a given Problem
.
Returns
true
if the solution is integrality feasible,false
otherwise.
FlowGenerator.NetworkFlowModel.is_integrality_feasible
— Methodis_integrality_feasible(problem::Problem, solution::PrimalSolution)
Checks if flow integrality of a PrimalSolution
is satisfied for a given Problem
.
FlowGenerator.NetworkFlowModel.is_problem_integer
— Methodis_problem_integer(problem::Problem) -> Bool
Determines whether the problem has an integer objective function for any feasible solution that meets all integrality constraints on the variables.
FlowGenerator.NetworkFlowModel.new_network
— Methodnew_network(vertices::Vector{Vertex}, arcs::Vector{Arc})
Create a new Network
object with the given vertices and arcs.
FlowGenerator.NetworkFlowModel.propagate_costs
— Methodfunction propagate_costs(hyper_tree::HyperTree; arc_to_cost::Function, tail_to_cost::Function)
Propagate costs along the hyper tree from tails towards the head.
FlowGenerator.NetworkFlowModel.topological_sort
— Methodtopological_sort(network::Network, sources::Vector{Vertex})
Perform a topological sort on the network starting from the given source vertices.