This class provides an efficient implementation of the Minimum Cost Arborescence algorithm. The arborescence is a tree which is directed from a given source node of the digraph. One or more sources should be given to the algorithm and it will calculate the minimum cost subgraph that is the union of arborescences with the given sources and spans all the nodes which are reachable from the sources. The time complexity of the algorithm is O(n2+e).
The algorithm also provides an optimal dual solution, therefore the optimality of the solution can be checked.
GR | The digraph type the algorithm runs on. |
CM | A read-only arc map storing the costs of the arcs. It is read once for each arc, so the map may involve in relatively time consuming process to compute the arc costs if it is necessary. The default map type is Digraph::ArcMap<int>. |
TR | The traits class that defines various types used by the algorithm. By default, it is MinCostArborescenceDefaultTraits<GR, CM>. In most cases, this parameter should not be set directly, consider to use the named template parameters instead. |
#include <lemon/min_cost_arborescence.h>
Classes | |
class | DualIt |
LEMON iterator for getting a dual variable. More... | |
struct | SetArborescenceMap |
Named parameter for setting ArborescenceMap type More... | |
struct | SetPredMap |
Named parameter for setting PredMap type More... | |
Public Types | |
typedef TR | Traits |
The traits class of the algorithm. | |
typedef Traits::Digraph | Digraph |
The type of the underlying digraph. | |
typedef Traits::CostMap | CostMap |
The type of the map that stores the arc costs. | |
typedef Traits::Value | Value |
The type of the costs of the arcs. | |
typedef Traits::PredMap | PredMap |
The type of the predecessor map. | |
typedef Traits::ArborescenceMap | ArborescenceMap |
The type of the map that stores which arcs are in the arborescence. | |
Public Member Functions | |
MinCostArborescence (const Digraph &digraph, const CostMap &cost) | |
Constructor. | |
~MinCostArborescence () | |
Destructor. | |
MinCostArborescence & | arborescenceMap (ArborescenceMap &m) |
Sets the arborescence map. | |
MinCostArborescence & | predMap (PredMap &m) |
Sets the predecessor map. | |
Execution Control | |
The simplest way to execute the algorithm is to use one of the member functions called | |
void | init () |
void | addSource (Node source) |
Adds a new source node. | |
Node | processNextNode () |
Processes the next node in the priority queue. | |
int | queueSize () const |
Returns the number of the nodes to be processed. | |
bool | emptyQueue () const |
void | start () |
Executes the algorithm. | |
void | run (Node s) |
Runs MinCostArborescence algorithm from node s . | |
Query Functions | |
Value | arborescenceCost () const |
bool | arborescence (Arc arc) const |
Returns true if the arc is in the arborescence. | |
const ArborescenceMap & | arborescenceMap () const |
Returns a const reference to the arborescence map. | |
Arc | pred (Node node) const |
Returns the predecessor arc of the given node. | |
const PredMap & | predMap () const |
Returns a const reference to the pred map. | |
bool | reached (Node node) const |
bool | processed (Node node) const |
Indicates that a node is processed. | |
int | dualNum () const |
Value | dualValue () const |
Returns the value of the dual solution. | |
int | dualSize (int k) const |
Value | dualValue (int k) const |
Returns the value of the dual variable. | |
|
inline |
digraph | The digraph the algorithm will run on. |
cost | The cost map used by the algorithm. |
|
inline |
Sets the arborescence map.
(*this)
|
inline |
Sets the predecessor map.
(*this)
|
inline |
Initializes the internal data structures.
|
inline |
Adds a new source node to the algorithm.
|
inline |
Processes the next node in the priority queue.
|
inline |
Returns the number of the nodes to be processed in the priority queue.
|
inline |
Returns false
if there are nodes to be processed.
|
inline |
Executes the algorithm.
|
inline |
This method runs the MinCostArborescence algorithm from a root node s
.
|
inline |
Returns the cost of the arborescence.
|
inline |
Returns true
if the given arc is in the arborescence.
arc | An arc of the digraph. |
|
inline |
Returns a const reference to the arborescence map.
|
inline |
Returns the predecessor arc of the given node.
|
inline |
Returns a const reference to the pred map.
|
inline |
Indicates that a node is reachable from the sources.
|
inline |
Indicates that a node is processed. The arborescence path exists from the source to the given node.
|
inline |
Returns the number of the dual variables in basis.
|
inline |
Returns the value of the dual solution. It should be equal to the arborescence value.
|
inline |
Returns the number of the nodes in the dual variable.
|
inline |
Returns the the value of the dual variable.