Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType > Class Template Reference

Encapsulates the complete state of the weighted matching algorithm. More...

#include <blossom_weighted_mwmatching.H>

Collaboration diagram for Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >:
[legend]

Classes

struct  DeltaStep
 A candidate step for dual variable modification. More...
 

Public Types

using EdgeT = Edge< WeightType >
 
using BlossomT = Blossom< WeightType >
 
using NonTrivialBlossomT = NonTrivialBlossom< WeightType >
 

Public Member Functions

 MatchingContext (const Array< EdgeT > &edges_in)
 Initialize context from an edge array.
 
 MatchingContext (const MatchingContext &)=delete
 
MatchingContextoperator= (const MatchingContext &)=delete
 
WeightType edge_slack (const EdgeT &edge) const
 Calculate edge slack.
 
void lset_reset ()
 Reset least-slack edge tracking.
 
void lset_add_vertex_edge (VertexId y, const EdgeT *edge, WeightType slack)
 Add edge "e" from an S-vertex to unlabeled vertex or T-vertex "y".
 
std::pair< const EdgeT *, WeightTypelset_get_best_vertex_edge ()
 Return the index and slack of the least-slack edge between any S-vertex and unlabeled vertex.
 
void lset_add_blossom_edge (BlossomT *blossom, const EdgeT *edge, WeightType slack)
 Add edge "e" between the specified S-blossom and another S-blossom.
 
void lset_merge_blossoms (NonTrivialBlossomT *blossom)
 Update least-slack edge tracking after merging sub-blossoms into a new S-blossom.
 
std::pair< const EdgeT *, WeightTypelset_get_best_blossom_edge ()
 Return the index and slack of the least-slack edge between any pair of top-level S-blossoms.
 
AlternatingPath trace_alternating_paths (VertexId x, VertexId y)
 Trace back through the alternating trees from vertices "x" and "y".
 
void make_blossom (const AlternatingPath &path)
 Create a new blossom from an alternating cycle.
 
void erase_nontrivial_blossom (NonTrivialBlossomT *blossom)
 Erase the specified non-trivial blossom.
 
void expand_t_blossom (NonTrivialBlossomT *blossom)
 Expand the specified T-blossom.
 
void expand_unlabeled_blossom (NonTrivialBlossomT *blossom)
 Expand the specified unlabeled blossom.
 
void augment_blossom_rec (NonTrivialBlossomT *blossom, BlossomT *entry, DynListStack< std::pair< NonTrivialBlossomT *, BlossomT * > > &rec_stack)
 Augment along an alternating path through the specified blossom, from sub-blossom "entry" to the base vertex of the blossom.
 
void augment_blossom (NonTrivialBlossomT *blossom, BlossomT *entry)
 Augment along an alternating path through the specified blossom, from sub-blossom "entry" to the base vertex of the blossom.
 
void augment_matching (const AlternatingPath &path)
 Augment the matching through the specified augmenting path.
 
void assign_label_s (VertexId x)
 Assign label S to the unlabeled blossom that contains vertex "x".
 
void assign_label_t (VertexId x, VertexId y)
 Assign label T to the unlabeled blossom that contains vertex "y".
 
bool add_s_to_s_edge (VertexId x, VertexId y)
 Add the edge between S-vertices "x" and "y".
 
bool substage_scan ()
 Scan queued S-vertices to expand the alternating trees.
 
DeltaStep substage_calc_dual_delta ()
 Calculate a delta step in the dual LPP problem.
 
void substage_apply_delta_step (WeightType delta)
 Apply a delta step to the dual LPP variables.
 
void reset_stage ()
 Reset data which are only valid during a stage.
 
bool run_stage ()
 Run one stage of the matching algorithm.
 
void run ()
 Run the matching algorithm.
 

Static Public Member Functions

static void lset_new_blossom (BlossomT *blossom)
 Start tracking edges for a new S-blossom.
 

Public Attributes

const Problem_Data< WeightTypegraph
 Internal graph representation.
 
Array< VertexIdvertex_mate
 The current mate of each vertex, or NO_VERTEX.
 
Array< BlossomTtrivial_blossom
 All trivial (single vertex) blossoms.
 
DynDlist< NonTrivialBlossomTnontrivial_blossom
 Currently active non-trivial blossoms.
 
Array< BlossomT * > vertex_top_blossom
 Maps each vertex to its highest-level containing blossom.
 
Array< WeightTypevertex_dual
 Dual variable \(y_i\) for each vertex.
 
Array< const EdgeT * > vertex_best_edge
 
DynListQueue< VertexIdqueue
 
Array< boolvertex_marker
 
Array< VertexIdmarked_vertex
 

Static Public Attributes

static constexpr WeightType weight_factor
 Integer scaling factor for weight calculations.
 

Detailed Description

template<typename WeightType>
class Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >

Encapsulates the complete state of the weighted matching algorithm.

Includes dual variables, blossom hierarchy, and the current matching state.

Definition at line 496 of file blossom_weighted_mwmatching.H.

Member Typedef Documentation

◆ BlossomT

◆ EdgeT

◆ NonTrivialBlossomT

Constructor & Destructor Documentation

◆ MatchingContext() [1/2]

◆ MatchingContext() [2/2]

Member Function Documentation

◆ add_s_to_s_edge()

◆ assign_label_s()

Assign label S to the unlabeled blossom that contains vertex "x".

If vertex "x" is matched, it becomes attached to the alternating tree via its matched edge. If vertex "x" is unmatched, it becomes the root of an alternating tree.

All vertices in the newly labeled blossom are added to the scan queue.

Precondition
"x" is an unlabeled vertex, either unmatched or matched to a T-vertex via a tight edge.

Definition at line 1340 of file blossom_weighted_mwmatching.H.

References Aleph::divide_and_conquer_partition_dp(), Aleph::blossom_weighted_detail::mwmatching::impl::for_vertices_in_blossom(), Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_NONE, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_S, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_T, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_new_blossom(), Aleph::blossom_weighted_detail::mwmatching::impl::NO_VERTEX, Aleph::DynListQueue< T >::put(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::queue, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_mate, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_top_blossom, and y.

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::assign_label_t(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::expand_t_blossom(), and Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::run_stage().

◆ assign_label_t()

◆ augment_blossom()

Augment along an alternating path through the specified blossom, from sub-blossom "entry" to the base vertex of the blossom.

Recursively handle sub-blossoms as needed.

This function takes time O(n).

Definition at line 1247 of file blossom_weighted_mwmatching.H.

References Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::augment_blossom_rec(), Aleph::divide_and_conquer_partition_dp(), Aleph::blossom_weighted_detail::mwmatching::impl::Blossom< WeightType >::parent, and Aleph::DynListStack< T >::put().

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::augment_matching().

◆ augment_blossom_rec()

◆ augment_matching()

◆ edge_slack()

◆ erase_nontrivial_blossom()

◆ expand_t_blossom()

◆ expand_unlabeled_blossom()

◆ lset_add_blossom_edge()

◆ lset_add_vertex_edge()

◆ lset_get_best_blossom_edge()

template<typename WeightType >
std::pair< const EdgeT *, WeightType > Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_get_best_blossom_edge ( )
inline

Return the index and slack of the least-slack edge between any pair of top-level S-blossoms.

This function takes time O(n) per call. This function takes total time O(n**2) per stage.

Returns
Pair (edge, slack) if there is a least-slack edge, or (nullptr, 0) if there is no suitable edge.

Definition at line 841 of file blossom_weighted_mwmatching.H.

References Aleph::and, Aleph::divide_and_conquer_partition_dp(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::edge_slack(), Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_S, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::nontrivial_blossom, and Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::trivial_blossom.

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::substage_calc_dual_delta().

◆ lset_get_best_vertex_edge()

◆ lset_merge_blossoms()

◆ lset_new_blossom()

◆ lset_reset()

◆ make_blossom()

◆ operator=()

◆ reset_stage()

◆ run()

◆ run_stage()

Run one stage of the matching algorithm.

The stage searches a maximum-weight augmenting path. If this path is found, it is used to augment the matching, thereby increasing the number of matched edges by 1. If no such path is found, the matching must already be optimal.

This function takes time O(n**2).

Returns
True if the matching was successfully augmented; false if no further improvement is possible.

Definition at line 1670 of file blossom_weighted_mwmatching.H.

References Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::add_s_to_s_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::assign_label_s(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::assign_label_t(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::blossom, Aleph::divide_and_conquer_partition_dp(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::edge, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::expand_t_blossom(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::graph, Aleph::DynListQueue< T >::is_empty(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::kind, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_S, Aleph::blossom_weighted_detail::mwmatching::impl::NO_VERTEX, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::queue, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::reset_stage(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::substage_apply_delta_step(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::substage_calc_dual_delta(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::substage_scan(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::value, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_mate, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_top_blossom, and y.

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::run().

◆ substage_apply_delta_step()

◆ substage_calc_dual_delta()

Calculate a delta step in the dual LPP problem.

This function returns the minimum of the 4 types of delta values, and the type of delta which obtain the minimum, and the edge or blossom that produces the minimum delta, if applicable.

This function takes time O(n).

Precondition
There is at least one S-vertex.
Returns
Tuple (delta_type, delta_value, delta_edge, delta_blossom)

Definition at line 1554 of file blossom_weighted_mwmatching.H.

References Aleph::and, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::blossom, Aleph::divide_and_conquer_partition_dp(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::edge, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::graph, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::kind, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_S, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_T, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_get_best_blossom_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_get_best_vertex_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::nontrivial_blossom, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::DeltaStep::value, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_dual, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_top_blossom, and Aleph::blossom_weighted_detail::mwmatching::Edge< WeightType >::vt.

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::run_stage().

◆ substage_scan()

Scan queued S-vertices to expand the alternating trees.

The scan proceeds until either an augmenting path is found, or the queue of S-vertices becomes empty. If an augmenting path is found, it is used to augment the matching.

New blossoms may be created during the scan.

Returns
True if the matching was augmented; otherwise false.

Definition at line 1463 of file blossom_weighted_mwmatching.H.

References Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::add_s_to_s_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::assign_label_t(), Aleph::divide_and_conquer_partition_dp(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::edge_slack(), Aleph::DynListQueue< T >::get(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::graph, Aleph::DynListQueue< T >::is_empty(), Aleph::blossom_weighted_detail::mwmatching::impl::Blossom< WeightType >::label, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_NONE, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_S, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_add_blossom_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_add_vertex_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::queue, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_top_blossom, Aleph::blossom_weighted_detail::mwmatching::Edge< WeightType >::vt, and y.

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::run_stage().

◆ trace_alternating_paths()

Trace back through the alternating trees from vertices "x" and "y".

If both vertices are part of the same alternating tree, this function discovers a new blossom. In this case it returns an alternating path through the blossom that starts and ends in the same sub-blossom.

If the vertices are part of different alternating trees, this function discovers an augmenting path. In this case it returns an alternating path that starts and ends in an unmatched vertex.

This function takes time O(k) to discover a blossom, where "k" is the number of sub-blossoms, or time O(n) to discover an augmenting path.

Definition at line 887 of file blossom_weighted_mwmatching.H.

References Aleph::Array< T >::append(), Aleph::DynDlist< T >::append(), Aleph::divide_and_conquer_partition_dp(), Aleph::blossom_weighted_detail::mwmatching::impl::AlternatingPath::edges, Aleph::Array< T >::empty(), Aleph::DynDlist< T >::get_first(), Aleph::DynDlist< T >::get_last(), Aleph::DynDlist< T >::insert(), k, Aleph::blossom_weighted_detail::mwmatching::impl::LABEL_S, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::marked_vertex, Aleph::blossom_weighted_detail::mwmatching::impl::NO_VERTEX, Aleph::DynDlist< T >::remove_first(), Aleph::DynDlist< T >::remove_last(), Aleph::DynDlist< T >::size(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_marker, Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::vertex_top_blossom, and y.

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::add_s_to_s_edge().

Member Data Documentation

◆ graph

◆ marked_vertex

◆ nontrivial_blossom

◆ queue

◆ trivial_blossom

◆ vertex_best_edge

◆ vertex_dual

◆ vertex_marker

◆ vertex_mate

◆ vertex_top_blossom

Maps each vertex to its highest-level containing blossom.

Definition at line 536 of file blossom_weighted_mwmatching.H.

Referenced by Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::MatchingContext(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::add_s_to_s_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::assign_label_s(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::assign_label_t(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::augment_matching(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::edge_slack(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::expand_t_blossom(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::expand_unlabeled_blossom(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_get_best_vertex_edge(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::lset_merge_blossoms(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::make_blossom(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::run_stage(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::substage_apply_delta_step(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::substage_calc_dual_delta(), Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::substage_scan(), and Aleph::blossom_weighted_detail::mwmatching::impl::MatchingContext< WeightType >::trace_alternating_paths().

◆ weight_factor


The documentation for this class was generated from the following file: