55 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
class Graph    83     Graph(
int node_num_max, 
int edge_num_max, 
void (*err_function)(
const char *) = NULL);
    95     void add_edge(node_id i, node_id j, captype cap, captype rev_cap);
   102     void add_tweights(node_id i, tcaptype cap_source, tcaptype cap_sink);
   180     void set_trcap(node_id i, tcaptype trcap); 
   181     void set_rcap(arc* a, captype rcap);
   246         assert(i>=0 && i<node_num && nodes[i].is_in_changed_list); 
   247         nodes[i].is_in_changed_list = 0;
   273         int         is_in_changed_list : 1; 
   294     static const int NODEPTR_BLOCK_SIZE = 128;
   296     node                *nodes, *node_last, *node_max; 
   297     arc                 *arcs, *arc_last, *arc_max; 
   303     void    (*error_function)(
const char *);    
   310     int                 maxflow_iteration; 
   315     node                *queue_first[2], *queue_last[2];    
   316     nodeptr             *orphan_first, *orphan_last;        
   321     void reallocate_nodes(
int num); 
   322     void reallocate_arcs();
   325     void set_active(node *i);
   329     void set_orphan_front(node* i); 
   330     void set_orphan_rear(node* i);  
   332     void add_to_changed_list(node* i);
   335     void maxflow_reuse_trees_init(); 
   336     void augment(arc *middle_arc);
   337     void process_source_orphan(node *i);
   338     void process_sink_orphan(node *i);
   340     void test_consistency(node* current_node=NULL); 
   359 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   364     if (node_last + num > node_max) reallocate_nodes(num);
   368         node_last -> first = NULL;
   369         node_last -> tr_cap = 0;
   370         node_last -> is_marked = 0;
   371         node_last -> is_in_changed_list = 0;
   378         memset(node_last, 0, num*
sizeof(node));
   380         node_id i = node_num;
   387 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   390     assert(i >= 0 && i < node_num);
   392     tcaptype delta = nodes[i].tr_cap;
   393     if (delta > 0) cap_source += delta;
   394     else           cap_sink   -= delta;
   395     flow += (cap_source < cap_sink) ? cap_source : cap_sink;
   396     nodes[i].tr_cap = cap_source - cap_sink;
   399 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   402     assert(_i >= 0 && _i < node_num);
   403     assert(_j >= 0 && _j < node_num);
   406     assert(rev_cap >= 0);
   408     if (arc_last == arc_max) reallocate_arcs();
   410     arc *a = arc_last ++;
   411     arc *a_rev = arc_last ++;
   413     node* i = nodes + _i;
   414     node* j = nodes + _j;
   418     a -> next = i -> first;
   420     a_rev -> next = j -> first;
   425     a_rev -> r_cap = rev_cap;
   428 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   434 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   440 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   443     assert(a >= arcs && a < arc_last);
   444     i = (
node_id) (a->sister->head - nodes);
   445     j = (
node_id) (a->head - nodes);
   448 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   451     assert(i>=0 && i<node_num);
   452     return nodes[i].tr_cap;
   455 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   458     assert(a >= arcs && a < arc_last);
   462 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   465     assert(i>=0 && i<node_num); 
   466     nodes[i].tr_cap = trcap;
   469 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   472     assert(a >= arcs && a < arc_last);
   477 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   490 template <
typename captype, 
typename tcaptype, 
typename flowtype> 
   493     node* i = nodes + _i;
   497         if (queue_last[1]) queue_last[1] -> next = i;
   498         else               queue_first[1]        = i;
 arc_id get_next_arc(arc_id a)
Definition: graph.h:435
 
void set_rcap(arc *a, captype rcap)
Definition: graph.h:470
 
arc_id get_first_arc()
Definition: graph.h:429
 
void add_edge(node_id i, node_id j, captype cap, captype rev_cap)
Definition: graph.h:400
 
arc * arc_id
Definition: graph.h:156
 
node_id add_node(int num=1)
Definition: graph.h:360
 
int get_node_num()
Definition: graph.h:161
 
void set_trcap(node_id i, tcaptype trcap)
Definition: graph.h:463
 
void reset()
Definition: graph.cpp:45
 
int node_id
Definition: graph.h:63
 
void Copy(Graph< captype, tcaptype, flowtype > *g0)
Definition: maxflow.cpp:688
 
void remove_from_changed_list(node_id i)
Definition: graph.h:244
 
captype get_rcap(arc *a)
Definition: graph.h:456
 
void add_tweights(node_id i, tcaptype cap_source, tcaptype cap_sink)
Definition: graph.h:388
 
void get_arc_ends(arc_id a, node_id &i, node_id &j)
Definition: graph.h:441
 
termtype
Definition: graph.h:58
 
int get_arc_num()
Definition: graph.h:162
 
~Graph()
Definition: graph.cpp:33
 
tcaptype get_trcap(node_id i)
Definition: graph.h:449
 
flowtype maxflow(bool reuse_trees=false, Block< node_id > *changed_list=NULL)
Definition: maxflow.cpp:475
 
Graph(int node_num_max, int edge_num_max, void(*err_function)(const char *)=NULL)
Definition: graph.cpp:11
 
termtype what_segment(node_id i, termtype default_segm=SOURCE)
Definition: graph.h:478
 
void mark_node(node_id i)
Definition: graph.h:491