/* lp_graph.h
 * Neil Moore <neil@cs.uky.edu>
 * 30 Mar 1999
 *
 * Part of liblp.  See COPYRIGHT for copyright information.
 */
#ifndef _LP_GRAPH_H_INCLUDED
#define _LP_GRAPH_H_INCLUDED

#include <lp.h>
#include <lp_lists.h>

/* Types for lp_vtx.data */
#define LP_DT_OTHER 0
#define LP_DT_RULE  1
#define LP_DT_ATOM  2

/* Vertex */
struct lp_vtx {
	void *data;                /* Pointer to an atom or rule */
	int type;                  /* Is this an atom or a rule? */
	struct lp_vlist *edges;    /* Edges from this vertex */
	struct lp_vtx *pred;       /* Parent in the DFS forest */
	int colour;                /* DFS colouring--white, grey, or black */
	int discover_time;         /* DFS discovery time */
	int finish_time;           /* DFS finishing time */
};


/* Directed graph */
struct lp_graph {
	struct lp_vtx *vertices;   /* Array of vertices */
	int nvertices;             /* Number of vertices */
};

/* Construct a dependency graph for a logic program */
struct lp_graph *lp_construct_depend_graph(struct lp *p);
/* Construct a stratification graph for a logic program */
struct lp_graph *lp_construct_strat_graph(struct lp *p);
/* Find the strongly-connected components of a graph (and topologically
 * order them).
 */
int lp_find_scc(struct lp_graph *graph, struct lp_vlist ***comps);
/* Free a graph and all associated data */
void lp_free_graph(struct lp_graph *g);

#endif /* _LP_GRAPH_H_INCLUDED */
