Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

diGraph.h

Go to the documentation of this file.
00001 /**< diGraph - Directed graph routines. */
00002 #ifndef DIGRAPH_H
00003 #define DIGRAPH_H
00004 
00005 #ifndef DLIST_H
00006 #include "dlist.h"
00007 #endif
00008 
00009 struct diGraph
00010 /**< A directed graph. */
00011     {
00012     struct dgNode *nodeList;
00013     struct hash *nodeHash;
00014     struct dlList *edgeList;
00015     };
00016 
00017 struct dgNode
00018 /**< A node on a directed graph */
00019     {
00020     struct dgNode *next;   /**< Next in master node list. */
00021     char *name;            /**< Name of node (allocated in hash). */
00022     void *val;             /**< Value of node. */
00023     struct dgConnection *nextList;  /**< Ways out of node. */
00024     struct dgConnection *prevList;  /**< Ways into node. */
00025     int topoOrder;      /**< Topographical order after call to dgTopoSort. */
00026     int component;      /**< Connected component number after call to dgConnectedComponents. */
00027     int priority;       /**< Node priority. */
00028     struct dgNode *tempEntry;  /**< Way in for breadth first search */
00029     bool visited;       /**< Visit order in depth first traversal. */
00030     bool conn;          /**< Flag for connection algorithms. */
00031     bool flagA;         /**< Flag used in rangeGraph algorithms. */
00032     bool flagB;         /**< Currently unused flag. */
00033     };
00034 
00035 struct dgEdge
00036 /**< An edge on graph */
00037     {
00038     void *val;      /**< Value of edge. */
00039     struct dgNode *a;   /**< Node on incoming side. */
00040     struct dgNode *b;   /**< Node on outgoing side. */
00041     };
00042 
00043 struct dgConnection
00044 /**< Connects one node to another. Linked to edge. */
00045     {
00046     struct dgConnection *next;  /**< Next in list. */
00047     struct dgNode *node;        /**< Node this connects to. */
00048     struct dlNode *edgeOnList;  /**< Associated edge. */
00049     };
00050 
00051 struct dgNodeRef
00052 /**< A reference to a node. */
00053     {
00054     struct dgNodeRef *next; /**< Next in list. */
00055     struct dgNode *node;        /**< Pointer to node. */
00056     };
00057 
00058 struct dgEdgeRef
00059 /**< A reference to an edge. */
00060     {
00061     struct dgEdgeRef *next; /**< Next in list. */
00062     struct dgEdge *edge;        /**< Reference to edge. */
00063     };
00064 
00065 struct diGraph *dgNew();
00066 /**< Return a new directed graph object. */
00067 
00068 void dgFree(struct diGraph **pGraph);
00069 /**< Free a directed graph. */
00070 
00071 struct dgNode *dgAddNode(struct diGraph *dg, char *name, void *val);
00072 /**< Create new node in graph. */
00073 
00074 struct dgNode *dgAddNumberedNode(struct diGraph *dg, int id, void *val);
00075 /**< Create new node with a number instead of a name. */
00076  
00077 struct dgNode *dgFindNode(struct diGraph *dg, char *name);
00078 /**< Find existing node in graph. */
00079 
00080 struct dgNode *dgFindNumberedNode(struct diGraph *dg, int id);
00081 /**< Find node given number. */
00082 
00083 void *dgNodeVal(struct dgNode *node);
00084 /**< Return value associated with node. */
00085 
00086 void *dgNodeName(struct dgNode *node);
00087 /**< Return name associated with node. */
00088 
00089 int dgNodeNumber(struct dgNode *node);
00090 /**< Return number of node.  (Will likely return 0 if node
00091  * was added with a name rather than a number). */
00092 
00093 struct dgEdge *dgConnect(struct diGraph *dg, struct dgNode *a, struct dgNode *b);
00094 /**< Connect node a to node b.  Returns connecting edge. */
00095 
00096 struct dgEdge *dgConnectWithVal(struct diGraph *dg, struct dgNode *a, struct dgNode *b, void *val);
00097 /**< Connect node a to node b and put val on edge. */
00098 
00099 void dgDisconnect(struct diGraph *dg, struct dgNode *a, struct dgNode *b);
00100 /**< Disconnect nodes a and b. */
00101 
00102 struct dgEdge *dgDirectlyFollows(struct diGraph *dg, struct dgNode *a, struct dgNode *b);
00103 /**< Return TRUE if b directly follows a. */
00104 
00105 boolean dgPathExists(struct diGraph *dg, struct dgNode *a, struct dgNode *b);
00106 /**< Return TRUE if there's a path from a to b. */
00107 
00108 struct dgNodeRef *dgFindPath(struct diGraph *dg, struct dgNode *a, struct dgNode *b);
00109 /**< Find shortest path from a to b.  Return NULL if can't be found. */
00110 
00111 struct dgNodeRef *dgFindConnectedToNode(struct diGraph *dg, struct dgNode *a);
00112 /**< Return reference list of all nodes connected to a, including a.
00113  * slFreeList this list when done. */
00114 
00115 struct dgNodeRef *dgFindNewConnected(struct diGraph *dg, struct dgNode *a);
00116 /**< Find a connected component guaranteed not to be covered before 
00117  * that includes a. */
00118 
00119 struct dgNodeRef *dgFindNewConnectedWithVals(struct diGraph *dg, struct dgNode *a);
00120 /**< Find a connected component guaranteed not to be covered before 
00121  * that includes a.  Connected components must have values*/
00122 
00123 struct dgNodeRef *dgFindNextConnected(struct diGraph *dg);
00124 /**< Return list of nodes that make up next connected component,
00125  * or NULL if no more components.  slFreeList this when
00126  * done.  Call "dgClearConnFlags" before first call to this.
00127  * Do not call dgFindConnectedToNode between dgFindFirstConnected 
00128  * and this as they use the same flag variables to keep track of
00129  * what vertices are used. */
00130 
00131 struct dgNodeRef *dgFindNextConnectedWithVals(struct diGraph *dg);
00132 /**< Like dgFindConnected, but only considers graph nodes that
00133  * have a val attatched. */
00134 
00135 int dgConnectedComponents(struct diGraph *dg);
00136 /**< Count number of connected components and set component field
00137  * of each node to reflect which component it is in. */
00138 
00139 int dgConnectedComponentsWithVals(struct diGraph *dg);
00140 /**< Count number of connected components and set component field
00141  * of each node to reflect which component it is in. Only
00142  * consider components with values. */
00143 
00144 void dgTopoSort(struct diGraph *dg);
00145 /**< Fill in topological order of nodes. */
00146 
00147 boolean dgHasCycles(struct diGraph *dg);
00148 /**< Return TRUE if directed graph has cycles. */
00149 
00150 boolean dgParentsAllVisited(struct dgNode *node);
00151 /**< Return TRUE if all parents of node have  been visited. */
00152 
00153 struct dgNodeRef *dgConstrainedPriorityOrder(struct diGraph *dg);
00154 /**< Return traversal of graph in priority order subject to
00155  * constraint that all parents must be output before
00156  * their children regardless of node priority. 
00157  * Graph must be cycle free. */
00158 
00159 boolean dgRangesConsistent(struct diGraph *rangeGraph,
00160    boolean (*findEdgeRange)(struct dgEdge *edge, int *retMin, int *retMax) );
00161 /**< Return TRUE if graph with a range of allowable distances associated
00162  * with each edge is internally consistent. */
00163 
00164 boolean dgAddedRangeConsistent(struct diGraph *rangeGraph,
00165    struct dgNode *a, struct dgNode *b, int abMin, int abMax,
00166    boolean (*findEdgeRange)(struct dgEdge *edge, int *retMin, int *retMax) );
00167 /**< Return TRUE if graph with a range of allowable distances associated
00168  * with each edge would be internally consistent if add edge from a to b
00169  * with given min/max values. */
00170 
00171 struct dgEdgeRef *dgFindSubEdges(struct diGraph *dg, struct dgNodeRef *subGraph);
00172 /**< Return list of edges in graph that connected together nodes in subGraph. */
00173 
00174 void dgSwapEdges(struct diGraph *dg, struct dgEdgeRef *erList);
00175 /**< Swap polarity of all edges in erList.  (Assumes you don't have
00176  * edges going both directions in graph.) */
00177 
00178 void dgClearConnFlags(struct diGraph *dg);
00179 /**< Clear out conn flags. */
00180 
00181 void dgClearVisitFlags(struct diGraph *dg);
00182 /**< Clear out visit order flags. */
00183 
00184 struct dgNodeRef *dgFindNodeInRefList(struct dgNodeRef *refList, struct dgNode *node);
00185 /**< Return reference to node if in list, or NULL if not. */
00186 
00187 struct dgConnection *dgFindNodeInConList(struct dgConnection *conList, struct dgNode *node);
00188 /**< Return connection to node if in list, or NULL if not. */
00189 
00190 struct dgConnection *dgNextList(struct dgNode *node);
00191 /**< Return list of connections out of this node. Don't free (or rearrange)
00192  * this list please. */
00193 
00194 struct dgConnection *dgPrevList(struct dgNode *node);
00195 /**< Return list of connections into this node. Don't free (or rearrange)
00196  * this list please. */
00197 
00198 void dgDumpGraph(struct diGraph *dg, FILE *out, boolean hideIsolated);
00199 /**< Dump info on graph to output. */
00200 
00201 #endif /**< DIGRAPH_H */
00202 

Generated on Fri Sep 17 09:09:05 2004 for UCSC Genome Browser by doxygen 1.3.6