This implementation allows uses of diferent numbers as supported by EGlpNum module. And follows the philosophy of embeded structures as in EGalgPushRelabel module. Also, much of the approach used in this implementation come from CONCORDE's implementation.
It is usually the case that the Minimum Cut Problem is just a sub-problem of some larger problem, is for that reason that we implement (just as in CONCORDE) a callback function that is called whenever an improving solution is found, so that the user can do something with the given node-cutset and value. for more details see the definition of EGalgMCcbk_t .
.
Files | |
| file | eg_min_cut.c |
| file | eg_min_cut.ex.c |
| file | eg_min_cut.h |
Data Structures | |
| struct | EGalgMCcbk_t |
| Call-back structure for use when an improving minimum cut is found. More... | |
| struct | EGalgMCedge_t |
| Edge structure for the Minimum Cut. More... | |
| struct | EGalgMCgraph_t |
| Graph Structure for Minimum Cut. More... | |
| struct | EGalgMCnode_t |
| Node structure for Minimum Cut. More... | |
| struct | mc_all_cuts_t |
| structure to store a set of cuts More... | |
| #define | EGalgMCprofile |
Defines | |
| #define | __MC_DEBUG_ 100 |
| Level of profiling in the code. | |
| #define | __MC_PROFILE_ 100 |
| Level of profiling in the code. | |
| #define | __MC_VRBLVL_ 100 |
| Verbosity Level. | |
| #define | _EGalgMChitNeighbours(NODE) |
| Set all EGalgMCnode_t::hit fields of all neighbours of the given node. | |
| #define | _EGalgMCunhitNeighbours(NODE) |
| Set all EGalgMCnode_t::hit fields of all neighbours of the given node. | |
| #define | EGalgMCcbkClear(cb) EGlpNumClearVar((cb)->cutoff) |
| Free all internal memory asociated with this structure (not allocated by the user). | |
| #define | EGalgMCcbkInit(cb) |
| Initialize a call-back structure. | |
| #define | EGalgMCedgeClear(E) EGsrkEdgeClear(&((E)->edge)) |
| Clear any internal memory (not allocated by the user) used by this structure. | |
| #define | EGalgMCedgeInit(E) |
| Initialize an edge structure for use. | |
| #define | EGalgMCgraphClear(Graph) |
| Clear internal memory (not allocated by the user) of a graph structure. | |
| #define | EGalgMCgraphInit(Graph) |
| Initialize a graph structure for use. | |
| #define | EGalgMCidentifyNodes(Graph, N, M) |
| Shrink two nodes in the graph, and update internal structures. | |
| #define | EGalgMCnodeClear(N) EGsrkNodeClear(&((N)->node)) |
| Clear any internal memory (not allocated by the user) used by this structure. | |
| #define | EGalgMCnodeInit(N) |
| Initialize a node structure for use. | |
| #define | UPDATE(counter) |
| variables and macros to do the profiling for the algorithm, it include counting the impact of all shrinking steps, the number of improvements cuts found along the way, and how many times where the main functions called. | |
Typedefs | |
| typedef EGalgMCcbk_t | EGalgMCcbk_t |
| Call-back structure for use when an improving minimum cut is found. | |
| typedef int(* | EGalgMCdo_f )(EGlpNum_t, const unsigned int, const unsigned int *const, void *) |
| Call-back function, it receives as input the weight of the cut, the size of the newly found cut, an array containing the cut (of length at least the number of elements in the cut) as integers (as defined by the EGalgMCnode_t::id field), and a pointer to some internal data (as stored in EGalgMCcbk_t::param). The function should return zero on success, and non-zero if an error ocours, this error will be propagated through the calling functions. | |
| typedef EGalgMCedge_t | EGalgMCedge_t |
| Edge structure for the Minimum Cut. | |
| typedef EGalgMCgraph_t | EGalgMCgraph_t |
| Graph Structure for Minimum Cut. | |
| typedef EGalgMCnode_t | EGalgMCnode_t |
| Node structure for Minimum Cut. | |
| typedef mc_all_cuts_t | mc_all_cuts_t |
| structure to store a set of cuts | |
Functions | |
| int | EGalgMC (EGalgMCgraph_t *const G, EGalgMCcbk_t *const cb, const unsigned int max_lvl) |
| Compute a minimum cut on the given graph. | |
| static int | EGalgMCbuildPRgraph (EGalgMCgraph_t *const mcG, EGalgPRgraph_t *const prG, EGalgMCnode_t **const node_map, EGalgPRnode_t *const all_pr_nodes, EGalgPRedge_t *const all_pr_edges) |
| Given a current min cut graph, build a Push-Relabel graph. | |
| static int | EGalgMCcomputeT (EGalgPRgraph_t *const prG, EGalgPRnode_t *const S, EGalgPRnode_t **const T) |
| Compute the farthest node in the push-relabel graph from the given starting point. | |
| static int | EGalgMCexpandNode (unsigned int *const cut, EGalgMCnode_t *const N) |
| Expand all nodes shrinked within a node, and store their id-s (EGalgMCnode_t::id) in the given array (including the node itself ). | |
| int | EGalgMCidentifyPRedges (EGalgMCgraph_t *const G, EGalgMCcbk_t *const cb, const unsigned int max_lvl) |
| Identify all Padberg and Rinaldy edges. i.e. shrink all edges that satisfy the conditions in their paper. we choose to make tests over pair of nodes linked by an edge. | |
| static int | EGalgMCtestNode (EGalgMCgraph_t *const G, EGalgMCcbk_t *const cb, EGalgMCnode_t *const N) |
| Given a node, test if the node is a better cut (by itself) then the currently found, and if so, update the current best cut, and call the callback if it is non-NULL. | |
| int | main (int argc, char **argv) |
| example of usage of the Min Cut algorithm as implemented in (EGalgMinCut). | |
| static int | mc_parseargs (int argc, char **argv) |
| parse input | |
| int | mc_store_cuts (EGlpNum_t value, const unsigned int c_sz, const unsigned int *const cut, void *data) |
| call-back function to store all cuts fund during the execution of the min-cut algorithm. | |
| static void | mc_usage (char **argv) |
| display usage of this program | |
Variables | |
| static char * | file_name = 0 |
| static unsigned int | lvl = 5 |
|
|
Level of profiling in the code.
Definition at line 81 of file eg_min_cut.h. |
|
|
Level of profiling in the code.
Definition at line 85 of file eg_min_cut.h. |
|
|
Verbosity Level.
Definition at line 77 of file eg_min_cut.h. |
|
|
Value: {\
e_end = &((NODE)->node.node.edges);\
for( e_it = e_end->next; e_it != e_end; e_it = e_it->next)\
{\
lep = EGcontainerOf(e_it, EGeUgraphEP_t,cn);\
o_type = lep->type ? 0U : 1U;\
E = EGcontainerOf(lep, EGalgMCedge_t, edge.edge.ep[lep->type]);\
M = EGcontainerOf(E->edge.edge.ep[o_type].node, EGalgMCnode_t, node.node);\
M->hit = &(E->edge);\
}}
Definition at line 122 of file eg_min_cut.c. |
|
|
Value: {\
e_end = &((NODE)->node.node.edges);\
for( e_it = e_end->next; e_it != e_end; e_it = e_it->next)\
{\
lep = EGcontainerOf(e_it, EGeUgraphEP_t,cn);\
o_type = lep->type ? 0U : 1U;\
E = EGcontainerOf(lep, EGalgMCedge_t, edge.edge.ep[lep->type]);\
M = EGcontainerOf(E->edge.edge.ep[o_type].node, EGalgMCnode_t, node.node);\
M->hit = 0;\
}}
Definition at line 141 of file eg_min_cut.c. |
|
|
Free all internal memory asociated with this structure (not allocated by the user).
Definition at line 149 of file eg_min_cut.h. |
|
|
Value: ({\
EGalgMCcbk_t*const _EGalgMCcb = (cb);\
EGlpNumInitVar(_EGalgMCcb->cutoff);\
_EGalgMCcb->param = 0;\
_EGalgMCcb->do_fn = 0;})
Definition at line 139 of file eg_min_cut.h. |
|
|
Clear any internal memory (not allocated by the user) used by this structure.
Definition at line 203 of file eg_min_cut.h. |
|
|
Value: ({\
EGalgMCedge_t*const _EGalgMCe = (E);\
EGsrkEdgeInit(&(_EGalgMCe->edge));\
_EGalgMCe->id = UINT_MAX;})
Definition at line 194 of file eg_min_cut.h. |
|
|
Value: ({\
EGsrkGraphClear(&((Graph)->G));\
EGlpNumClearVar((Graph)->epsilon);\
EGlpNumClearVar((Graph)->cut_val);})
Definition at line 263 of file eg_min_cut.h. |
|
|
Value: ({\
EGalgMCgraph_t*const _EGalgMCg = (Graph);\
EGsrkGraphInit(&(_EGalgMCg->G));\
EGlpNumInitVar(_EGalgMCg->epsilon);\
EGlpNumZero(_EGalgMCg->epsilon);\
EGlpNumInitVar(_EGalgMCg->cut_val);\
EGlpNumZero(_EGalgMCg->cut_val);\
_EGalgMCg->cut_sz = 0;\
EGeListInit(_EGalgMCg->lvl_list);\
EGeListInit(_EGalgMCg->lvl_list+1);\
EGeListInit(_EGalgMCg->lvl_list+2);\
EGeListInit(_EGalgMCg->lvl_list+3);\
EGeListInit(_EGalgMCg->lvl_list+4);\
_EGalgMCg->cut = 0;\
_EGalgMCg->all_nodes = 0;\
_EGalgMCg->all_edges = 0;})
Definition at line 242 of file eg_min_cut.h. |
|
|
Value: ({\
EGalgMCgraph_t*const _EGalgMCg = (Graph);\
EGalgMCnode_t*const _EGalgMCn = (N), *const _EGalgMCm = (M);\
MESSAGE(__MC_DEBUG_,"Shrinking nodes with weight %lf %lf", \
EGlpNumToLf(_EGalgMCn->node.weight), \
EGlpNumToLf(_EGalgMCm->node.weight));\
EGsrkIdentifyNodes(&(_EGalgMCg->G), &(_EGalgMCn->node), &(_EGalgMCm->node));\
if(_EGalgMCn->lvl < 5)\
{\
EGeListDel(&(_EGalgMCm->lvl_cn));\
EGeListMoveAfter(&(_EGalgMCn->lvl_cn), _EGalgMCg->lvl_list);\
}\
else EGeListAddAfter(&(_EGalgMCn->lvl_cn), _EGalgMCg->lvl_list);\
_EGalgMCn->lvl = 0;})
Definition at line 273 of file eg_min_cut.h. |
|
|
Clear any internal memory (not allocated by the user) used by this structure.
Definition at line 180 of file eg_min_cut.h. |
|
|
Value: ({\
EGalgMCnode_t*const _EGalgMCn = (N);\
EGsrkNodeInit(&(_EGalgMCn->node));\
_EGalgMCn->lvl_cn = (EGeList_t){0,0};\
_EGalgMCn->lvl = 0;\
_EGalgMCn->id = UINT_MAX;\
_EGalgMCn->new_id = UINT_MAX;\
_EGalgMCn->hit = 0;})
Definition at line 167 of file eg_min_cut.h. |
|
|
If profiling is enable (i.e. __MC_PROFILE_ <= DEBUG), print some profiling information of the min cut used up to now, and reset all internal counters to zero, if profiling is not enabled, nothing happen.
Definition at line 106 of file eg_min_cut.h. |
|
|
variables and macros to do the profiling for the algorithm, it include counting the impact of all shrinking steps, the number of improvements cuts found along the way, and how many times where the main functions called.
Definition at line 39 of file eg_min_cut.c. |
|
|
Call-back structure for use when an improving minimum cut is found.
|
|
|
Call-back function, it receives as input the weight of the cut, the size of the newly found cut, an array containing the cut (of length at least the number of elements in the cut) as integers (as defined by the EGalgMCnode_t::id field), and a pointer to some internal data (as stored in EGalgMCcbk_t::param). The function should return zero on success, and non-zero if an error ocours, this error will be propagated through the calling functions.
Definition at line 118 of file eg_min_cut.h. |
|
|
Edge structure for the Minimum Cut.
|
|
|
Graph Structure for Minimum Cut. Note that this structure also holds some parameters as the epsilon to use in the comparisons, the current best cut found (or bound), and the current cut found so-far. As well as an array containing all edges and nodes in thee graph (remember that when we Identify two nodes, we loose any reference to the shrinked node in the graph structure as discussed in EGsrkIdentifyNodes ) |
|
|
Node structure for Minimum Cut.
|
|
|
structure to store a set of cuts
|
|
||||||||||||||||
|
Compute a minimum cut on the given graph.
Note that the graph should have all fields properly initialized.
Definition at line 655 of file eg_min_cut.c. Here is the call graph for this function: ![]() |
|
||||||||||||||||||||||||
|
Given a current min cut graph, build a Push-Relabel graph.
Definition at line 510 of file eg_min_cut.c. |
|
||||||||||||||||
|
Compute the farthest node in the push-relabel graph from the given starting point.
Definition at line 594 of file eg_min_cut.c. |
|
||||||||||||
|
Expand all nodes shrinked within a node, and store their id-s (EGalgMCnode_t::id) in the given array (including the node itself ).
Definition at line 50 of file eg_min_cut.c. |
|
||||||||||||||||
|
Identify all Padberg and Rinaldy edges. i.e. shrink all edges that satisfy the conditions in their paper. we choose to make tests over pair of nodes linked by an edge.
The original theorem (for local conditions on shrinking) is the following: Let
where
And the original theorem (in fact is the corollary 3.5 in the paper) regarding global conditions for shrinking is the following: Let The actual tests that we perform (for every edge) are the following:
We make thiese tests in order, i.e. first we perform all level 1 tests, then level2, and so on, and whenever two nodes are Identify (shrinked) we set the level of the node to 1 (i.e. in the next test we will test the first condition). This is done using an array of (5) lists, where all nodes are distributed. Originally all nodes should be in the first lists (i.e. all nodes should be tested to improve the current best cut by themselves). Definition at line 153 of file eg_min_cut.c. Here is the call graph for this function: ![]() |
|
||||||||||||||||
|
Given a node, test if the node is a better cut (by itself) then the currently found, and if so, update the current best cut, and call the callback if it is non-NULL.
Definition at line 75 of file eg_min_cut.c. Here is the call graph for this function: ![]() |
|
||||||||||||
|
example of usage of the Min Cut algorithm as implemented in (EGalgMinCut). We read a file from the input whose two first numbers are the number of nodes and edges (we assume that the graph is undirected ), and then a 3-tupla with head tail capacity. we use the last field (capacity) as the capacity of the algorithm, and compute the minimum global cut. Definition at line 139 of file eg_min_cut.ex.c. Here is the call graph for this function: ![]() |
|
||||||||||||
|
parse input
Definition at line 100 of file eg_min_cut.ex.c. Here is the call graph for this function: ![]() |
|
||||||||||||||||||||
|
call-back function to store all cuts fund during the execution of the min-cut algorithm.
Definition at line 55 of file eg_min_cut.ex.c. |
|
|
display usage of this program
Definition at line 32 of file eg_min_cut.ex.c. |
|
|
Definition at line 28 of file eg_min_cut.ex.c. |
|
|
Definition at line 29 of file eg_min_cut.ex.c. |
1.4.5