protocol
flow_network_protocol
Protocol for flow network construction and inspection. A flow network is a directed graph where each arc has a non-negative integer lower bound and capacity, with the lower bound not exceeding the capacity, and an integer cost.
logtalk_load(flow_networks(loader))staticPublic predicates
new/2
Constructs a flow network from a list of arcs. Arcs are arc(From, To, Capacity), arc(From, To, Capacity, Cost), or arc(From, To, Lower, Capacity, Cost) terms. The default cost and lower bound are zero. Vertices can be any ground term. Parallel, antiparallel, and self-loop arcs are allowed.
staticnew(Arcs,Network)new(+list(ground),--compound) - one_or_errorArcs is a partial list or a list with an element Element which is not ground:instantiation_errorArcs is neither a variable nor a list:type_error(list(ground),Arcs)Arc of Arcs list is not an arc/3, arc/4, or arc/5 term:domain_error(flow_arc,Arc)type_error(integer,Value)domain_error(non_negative_integer,Value)consistency_error(arc_lower_bound_and_capacity,Lower,Capacity)new/3
As new/2, also preserving explicitly listed vertices, including isolated vertices. The vertex set is the sorted, duplicate-free union of Vertices and arc endpoints.
staticnew(Vertices,Arcs,Network)new(+list(ground),+list(ground),--compound) - one_or_errorVertices is a partial list or a list with an element Element which is not ground:instantiation_errorVertices is neither a partial list nor a list:type_error(list(ground),Vertices)Arcs is a partial list or a list with an element Element which is not ground:instantiation_errorArcs is neither a variable nor a list:type_error(list(ground),Arcs)Arc of Arcs list is not an arc/3, arc/4, or arc/5 term:domain_error(flow_arc,Arc)type_error(integer,Value)domain_error(non_negative_integer,Value)consistency_error(arc_lower_bound_and_capacity,Lower,Capacity)from_graph/2
Constructs a flow network from a weighted directed graph (created using the graphs library with the same dictionary object). Edge weights are interpreted as capacities and all costs are zero.
staticfrom_graph(Graph,Network)from_graph(+compound,--compound) - one_or_errorvertices/2
Returns the sorted list of vertices of a flow network (including vertices that only occur in self-loops).
staticvertices(Network,Vertices)vertices(+compound,-list) - onearcs/2
Returns the arcs of a flow network as arc(From, To, Lower, Capacity, Cost) terms in the order they were given to new/2, including self-loops.
staticarcs(Network,Arcs)arcs(+compound,-list(compound)) - oneflow_cost/3
Computes the cost of a capacity-valid flow, without requiring conservation or optimality. Each entry must be a flow(ArcId, From, To, Amount) term with a unique one-based arc ID, matching endpoints, and a positive integer amount. Every arc lower and upper bound must be respected, including omitted mandatory arcs. Entries may be in any order. Self-loop flows contribute their full cost.
staticflow_cost(Network,Flow,Cost)flow_cost(+compound,+list(compound),-integer) - one_or_errorFlow is a variable or partial list, or an entry has a variable field:instantiation_errorFlow is neither a variable nor a list:type_error(list,Flow)flow/4 term:domain_error(flow,Term)type_error(integer,Value)domain_error(positive_integer,Value)existence_error(arc,ArcId)domain_error(flow_arc_endpoints,Term)domain_error(capacity_valid_flow,Flow)flow_balances/3
Returns sorted Vertex-NetOutflow pairs for every vertex, including zero balances. Positive balances indicate supplies and negative balances indicate demands. Self-loops contribute zero net outflow. Requires a capacity-valid flow with the same validation and exceptions as flow_cost/3, but does not require conservation against particular supplies.
staticflow_balances(Network,Flow,Balances)flow_balances(+compound,+list(compound),-list(pair)) - one_or_errorcut_capacity/3
Computes the capacity of the cut whose source side is the given vertex set and whose sink side is its complement. Input order is immaterial; vertices must be unique and belong to the network. Empty and full sets are allowed. Counts parallel crossing arcs individually and excludes self-loops. Requires zero lower bounds.
staticcut_capacity(Network,SourceSide,Capacity)cut_capacity(+compound,+list(ground),-integer) - one_or_errorSourceSide is a variable or partial list or contains a non-ground vertex:instantiation_errorSourceSide is neither a variable nor a list:type_error(list,SourceSide)existence_error(vertex,Vertex)domain_error(unique_cut_vertices,Vertex)domain_error(zero_lower_bounds,Network)valid_cut/5
Checks a ground cut(SourceSide, SinkSide, Arcs) candidate and its reported capacity. The sides must be sorted, duplicate-free lists forming a complete disjoint partition of the network vertices, with distinct existing source and sink on their respective sides. Arcs must list every positive-capacity crossing arc in network input order, including parallel arcs. Requires zero lower bounds and fails for invalid candidates. Cut validity does not imply minimum-cut optimality.
staticvalid_cut(Network,Source,Sink,Value,Cut)valid_cut(+compound,+ground,+ground,+integer,+compound) - zero_or_onedecompose_flow/3
Decomposes a feasible flow into a list of path(Vertices, ArcIds, Amount) and cycle(Vertices, ArcIds, Amount) terms. Path endpoints are inferred from the flow balances. Vertex lists for cycles repeat the first vertex at the end. Arc IDs are one-based input arc positions.
staticdecompose_flow(Network,Flow,Decomposition)decompose_flow(+compound,+list(compound),-list(compound)) - zero_or_onevalid_flow/3
Checks that Flow respects every arc lower and upper capacity bound and that vertex net outflows match the given supplies and demands. Duplicate supply entries are added.
staticvalid_flow(Network,Supplies,Flow)valid_flow(+compound,+list(pair),+list(compound)) - zero_or_onevalid_st_flow/5
Checks that Flow respects capacities and conservation for a source-to-sink flow of the given value. Fails if either terminal is not ground.
staticvalid_st_flow(Network,Source,Sink,Value,Flow)valid_st_flow(+compound,+ground,+ground,+integer,+list(compound)) - zero_or_onevalid_min_cost_flow/4
Checks flow feasibility, the reported cost, and min-cost optimality by checking for negative-cost cycles in the residual graph.
staticvalid_min_cost_flow(Network,Supplies,Flow,Cost)valid_min_cost_flow(+compound,+list(pair),+list(compound),+integer) - zero_or_onevalid_min_cost_flow/5
Checks flow feasibility and cost, and validates a potential certificate by verifying non-negative reduced costs on every positive-capacity residual arc.
staticvalid_min_cost_flow(Network,Supplies,Flow,Cost,Potentials)valid_min_cost_flow(+compound,+list(pair),+list(compound),+integer,+list(pair)) - zero_or_oneProtected predicates
(none)
Private predicates
(none)
Operators
(none)