Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
mfmc.h
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 #ifndef MFMC_H_INCLUDED
00037 #define MFMC_H_INCLUDED "mfmc.h"
00038 /* ======================================================================
00039  *
00040  *
00041  * Revision history:
00042  * 17-Jul-96 - Original version
00043  *
00044  * Description:
00045  *
00046  * This package provides a functional interface to a fast
00047  * implementation of one of the best practical algorithms to solve
00048  * maximum flow and minimum s-t cut problems.
00049  *
00050  * The algorithm works in the push-relabel framework of Goldberg, and
00051  * uses the maximum distance (i.e., highest level) node selection
00052  * strategy, along with global relabeling and gap relabeling
00053  * heuristics. This combination of techniques is the best known in
00054  * practice for a wide variety of classes of maximum flow problem
00055  * instances.
00056  *
00057  * The interface functions visible to users are divided into three
00058  * classes: setup, query, and other.
00059  *
00060  * Setup functions (mfmc_setup.c)
00061  * ===============
00062  * Setup functions are called by the user to describe the particular
00063  * flow/cut problem instance.
00064  *
00065  *      MFMC_HANDLE MFMC_Init_problem(MEM_POOL *mem_pool,
00066  *                                    BOOL      trace,
00067  *                                    INT32     n,
00068  *                                    INT32     m,
00069  *                                    INT32     n_sources,
00070  *                                    INT32     n_sinks)
00071  *
00072  *          Perform initialization to begin setting up a particular
00073  *          problem instance, and return a handle that will refer to
00074  *          the problem instance in subsequent MFMC interface function
00075  *          calls.
00076  *
00077  *              mem_pool  - a pointer to a MEM_POOL from which the
00078  *                          MFMC package should allocate memory
00079  *                          required to solve the problem.
00080  *              trace     - (for future use) whether or not to print
00081  *                          tracing information during problem setup
00082  *                          and solution. Currently no tracing output
00083  *                          is implemented.
00084  *              n         - the number of nodes in the problem
00085  *                          instance. The nodes of the problem
00086  *                          instance will be referred to by integers
00087  *                          in the range [0 .. n-1].
00088  *              m         - the number of arcs (directed edges) in the
00089  *                          problem instance.
00090  *              n_sources - the number of source nodes in the problem
00091  *                          instance. This value must fall between 1
00092  *                          and n-1, inclusive.
00093  *              n_sinks   - the number of sink nodes in the problem
00094  *                          instance. This value must fall between 1
00095  *                          and n-1, inclusive.
00096  *
00097  *          This routine returns NULL if and only if it is unable to
00098  *          allocate some of the resources required to solve the
00099  *          problem. At present, no MEM_POOL resources are allocated
00100  *          by the MFMC package outside this function, but please
00101  *          don't assume this will always be the case.
00102  *
00103  *      MFMC_EC MFMC_Set_source(MFMC_HANDLE handle,
00104  *                              INT32       s)
00105  *
00106  *              handle - the handle for a particular flow/cut problem
00107  *              s      - a source node in the problem referred to by
00108  *                       handle
00109  *
00110  *          This routine tells the MFMC package that node s is a
00111  *          source in the problem referred to by handle.
00112  *
00113  *          Possible error returns:
00114  *              MFMC_NO_ERROR    - all is well
00115  *              MFMC_S_T_OVERLAP - node s has already been mentioned
00116  *                                 along with handle in a call to
00117  *                                 MFMC_Set_source or MFMC_Set_sink.
00118  *
00119  *      MFMC_EC MFMC_Set_sink(MFMC_HANDLE handle,
00120  *                            INT32       t)
00121  *
00122  *              handle - the handle for a particular flow/cut problem
00123  *              t      - a sink node in the problem referred to by
00124  *                       handle
00125  *
00126  *          This routine tells the MFMC package that node t is a sink
00127  *          in the problem referred to by handle.
00128  *
00129  *          Possible error returns:
00130  *              same as for MFMC_Set_source
00131  *
00132  *      MFMC_EC MFMC_Place_arc(MFMC_HANDLE      handle,
00133  *                             INT32            tail,
00134  *                             INT32            head,
00135  *                             INT64            lower_cap,
00136  *                             INT64            upper_cap,
00137  *                             MFMC_ARC_HANDLE *arc_handle)
00138  *
00139  *          Place an arc from node tail to node head; the arc has
00140  *          forward capacity equal to upper_cap, and backward capacity
00141  *          equal to -lower_cap. In a future refinement of the
00142  *          implementation, if arc_handle is non-null MFMC_Place_arc
00143  *          will store a unique identifier for the arc in *arc_handle
00144  *          so it can be referred to later in query functions.
00145  *
00146  *              handle     - the handle for a particular flow/cut
00147  *                           problem
00148  *              tail       - the origin of the arc being placed
00149  *              head       - the destination of the arc being placed
00150  *              lower_cap  - lower bound on the flow through the arc;
00151  *                           in the present implementation this value
00152  *                           must be nonpositive
00153  *              upper_cap  - upper bound on the flow through the arc;
00154  *                           in the present implementation this value
00155  *                           must be nonnegative
00156  *              arc_handle - if non-NULL, a pointer to where a future
00157  *                           implementation will store a unique
00158  *                           identifier for the placed arc; must be
00159  *                           NULL in the present implementation
00160  *
00161  *          Possible error returns:
00162  *              MFMC_NO_ERROR        - all is well
00163  *              MFMC_INFEASIBLE      - upper_cap < lower_cap
00164  *              MFMC_ZERO_INFEASIBLE - zero flow is infeasible; this
00165  *                                     will not be an error in a
00166  *                                     future version
00167  *              MFMC_BAD_ARC_COUNT   - more arcs have been placed than
00168  *                                     were promised in the call to
00169  *                                     MFMC_Init_problem
00170  *              MFMC_NOT_IMPLEMENTED - arc_handle is non-NULL; arc
00171  *                                     handles are not currently
00172  *                                     implemented
00173  *
00174  *      MFMC_EC MFMC_Solve_problem(MFMC_HANDLE handle)
00175  *
00176  *              handle - the handle for a particular flow/cut problem
00177  *
00178  *          This routine tells the MFMC package that the problem setup
00179  *          phase is finished for handle, and that the package should
00180  *          proceed with finding a max flow/min cut pair.
00181  *
00182  *          Possible error returns:
00183  *              MFMC_NO_ERROR      - all is well
00184  *              MFMC_UNSEEN_S_T    - the number of sources or sinks
00185  *                                   set via calls to MFMC_Set_source
00186  *                                   and/or MFMC_Set_sink does not
00187  *                                   match the number promised in the
00188  *                                   call to MFMC_Init_problem
00189  *              MFMC_BAD_ARC_COUNT - the number of arcs placed via
00190  *                                   calls to MFMC_Place_arc does not
00191  *                                   match the number promised in the
00192  *                                   call to MFMC_Init_problem
00193  *
00194  * Query functions (mfmc_query.c)
00195  * ===============
00196  * Query functions are called by the user when a problem has been
00197  * solved and the user wants to learn details of the solution and/or
00198  * of the solution process.
00199  *
00200  *      INT64 MFMC_Objective_value(MFMC_HANDLE handle)
00201  *
00202  *          Returns the value of the minimum cut (equal to the value
00203  *          of the maximum flow) in the problem referred to by handle.
00204  *
00205  *      BOOL MFMC_Min_cut_lhs(MFMC_HANDLE handle,
00206  *                            INT32 i)
00207  *
00208  *          Returns TRUE iff node i is on the left-hand (i.e., source)
00209  *          side of the minimum cut found by the algorithm.
00210  *
00211  *      INT64 MFMC_Max_flow_arc_flow(MFMC_HANDLE handle,
00212  *                                   MFMC_ARC_HANDLE arc_handle)
00213  *
00214  *          Returns the value of the flow on the arc specified by
00215  *          arc_handle in the maximum flow found by the
00216  *          algorithm. This function is not implemented yet, and 
00217  *          always asserts FALSE in the present version.
00218  *
00219  *      MFMC_STATS *MFMC_Stats(MFMC_HANDLE handle)
00220  *
00221  *          Returns a pointer to a structure describing statistics
00222  *          collected during the process of solving the problem
00223  *          referred to by handle. Typically these statistics count
00224  *          either process time or the number of times particular
00225  *          operations were executed.
00226  *
00227  * ======================================================================
00228  */
00229 #include "defs.h"
00230 #include "mempool.h"
00231 #include "errors.h"
00232 
00233 typedef struct mfmc_handle *MFMC_HANDLE;
00234 typedef struct mfmc_arc    *MFMC_ARC_HANDLE;
00235 
00236 typedef struct mfmc_stats {
00237   INT32         n_push;
00238   INT32         n_rel;
00239   INT32         n_up;
00240   INT32         n_gap;
00241   INT32         n_gnode;
00242   float         time;
00243 } MFMC_STATS;
00244 
00245 typedef enum {
00246   MFMC_NO_ERROR,                /* Everything OK so far. */
00247   MFMC_S_T_OVERLAP,             /* Source and sink sets intersect, or
00248                                  * some source/sink set twice.
00249                                  */
00250   MFMC_INFEASIBLE,              /* Upper capacity < lower capacity. */
00251   MFMC_ZERO_INFEASIBLE,         /* (Lower capacity > 0 or
00252                                  *  upper capacity < 0).
00253                                  * Relax this restriction later?
00254                                  */
00255   MFMC_UNSEEN_S_T,              /* Promised number of sources/sinks
00256                                  * doesn't match the number actually
00257                                  * set.
00258                                  */
00259   MFMC_BAD_ARC_COUNT,           /* Promised number of arcs doesn't
00260                                  * match the number actually placed.
00261                                  */
00262   MFMC_NOT_IMPLEMENTED          /* User asked for something legitimate
00263                                  * that we're too stupid or lazy to do.
00264                                  */
00265 } MFMC_EC;
00266 
00267 #ifdef __cplusplus
00268 extern "C" {
00269 #endif
00270 
00271 /* Setup interface functions */
00272 
00273 MFMC_HANDLE     MFMC_Init_problem(MEM_POOL *, BOOL, INT32, INT32,
00274                                   INT32, INT32);
00275 MFMC_EC         MFMC_Place_arc(MFMC_HANDLE, INT32, INT32,
00276                                INT64, INT64, MFMC_ARC_HANDLE *);
00277 MFMC_EC         MFMC_Set_source(MFMC_HANDLE, INT32);
00278 MFMC_EC         MFMC_Set_sink(MFMC_HANDLE, INT32);
00279 MFMC_EC         MFMC_Solve_problem(MFMC_HANDLE);
00280 
00281 /* Query interface functions */
00282 
00283 extern BOOL             MFMC_Min_cut_lhs(MFMC_HANDLE, INT32);
00284 #if 0
00285 /* --- NOT IMPLEMENTED YET --- */
00286 extern INT64            MFMC_Max_flow_arc_flow(MFMC_HANDLE, MFMC_ARC_HANDLE);
00287 #else
00288 inline INT64    MFMC_Max_flow_arc_flow(MFMC_HANDLE h, MFMC_ARC_HANDLE ah)
00289 {
00290   FmtAssert(FALSE, ("MFMC_Max_flow_arc_flow: arc handles not implemented"));
00291   /*NOTREACHED*/
00292 
00293 // Solaris CC workaround
00294 // A return is required by the compiler
00295    return 0;
00296 }
00297 #endif
00298 
00299 INT64
00300 MFMC_Objective_value(MFMC_HANDLE);
00301 
00302 /* Other interface functions */
00303 extern char *MFMC_msgs[];
00304 
00305 inline void
00306 MFMC_Print_error(FILE *f, MFMC_EC err)
00307 {
00308   (void) fprintf(f, "%s\n", MFMC_msgs[err]);
00309 }
00310 
00311 MFMC_STATS *
00312 MFMC_Stats(MFMC_HANDLE);
00313 
00314 #ifdef __cplusplus
00315 }
00316 #endif
00317 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines