64 Arc * blocked =
nullptr;
72 bool operator()(
Arc * arc)
const noexcept
74 return arc != blocked;
98 cout << title <<
'\n';
102 cout <<
" no directed cycle\n\n";
106 cout << fixed << setprecision(6);
107 cout <<
" minimum mean = " <<
r.minimum_mean <<
'\n';
109 if (
r.cycle_length == 0)
111 cout <<
" witness cycle unavailable\n\n";
118 const long double witness_mean =
static_cast<long double>(
r.cycle_total_cost)
119 /
static_cast<long double>(
r.cycle_length);
121 if (std::abs(
witness_mean -
static_cast<long double>(
r.minimum_mean)) > 1e-9)
124 <<
" != minimum mean " <<
r.minimum_mean <<
endl;
128 cout <<
" witness cycle: cost=" <<
r.cycle_total_cost
129 <<
", length=" <<
r.cycle_length
134 for (
auto it =
r.cycle_nodes.get_it(); it.has_curr(); it.next_ne())
139 cout << it.get_curr()->get_info();
145 for (
auto it =
r.cycle_arcs.get_it(); it.has_curr(); it.next_ne())
147 Arc * arc = it.get_curr();
155 <<
"(" << arc->get_info() <<
")";
202 cout <<
"Minimum mean cycle with Karp (Aleph graphs)\n";
203 cout <<
"---------------------------------------------\n\n";
209 cout <<
"Value-only API (full graph): ";
211 cout <<
"minimum mean = " <<
value_only.minimum_mean <<
"\n\n";
213 cout <<
"no directed cycle\n\n";
Minimum mean cycle in directed graphs (Karp algorithm).
Generic directed graph (digraph) wrapper template.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Min_Mean_Cycle_Value_Result karp_minimum_mean_cycle_value(const GT &g, Distance distance=Distance(), SA sa=SA())
Compute only the minimum mean value (without witness walk).
Min_Mean_Cycle_Result< GT, typename Distance::Distance_Type > karp_minimum_mean_cycle(const GT &g, Distance distance=Distance(), SA sa=SA())
Compute minimum mean cycle by Karp's algorithm.
int main()
Example program demonstrating Karp's minimum mean cycle algorithm on Aleph digraphs.
void print_result(const string &label, const Multipoly &poly)
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Arc of graph implemented with double-linked adjacency lists.
Result of minimum mean cycle computation.
Generic graph and digraph implementations.