Exemplo n.º 1
0
 string toposort(graph& g) {
     vector<bool> path(256, false);
     vector<bool> visited(256, false);
     string topo;
     for (auto adj : g) {
         if (!acyclic(g, path, visited, topo, adj.first)) {
             return "";
         }
     }
     reverse(topo.begin(), topo.end());
     return topo;
 }
Exemplo n.º 2
0
Arquivo: rank.c Projeto: aosm/graphviz
void dot_rank(graph_t* g)
{
	edgelabel_ranks(g);
	collapse_sets(g);
	/*collapse_leaves(g);*/
	class1(g);
	minmax_edges(g);
	decompose(g,0);
	acyclic(g);
	rank1(g);
	expand_ranksets(g);
	cleanup1(g);
}
Exemplo n.º 3
0
 bool acyclic(graph& g, vector<bool>& path, vector<bool>& visited, string& topo, char node) {
     if (path[node]) return false;
     if (visited[node]) return true;
     path[node] = true;
     visited[node] = true;
     for (auto neigh : g[node]) {
         if (!acyclic(g, path, visited, topo, neigh)) {
             return false;
         }
     }
     path[node] = false;
     topo += node;
     return true;
 }
Exemplo n.º 4
0
/* dot1_rank:
 * asp != NULL => g is root
 */
static void dot1_rank(graph_t * g, aspect_t* asp)
{
    point p;
#ifdef ALLOW_LEVELS
    attrsym_t* N_level;
#endif
    edgelabel_ranks(g);

    if (asp) {
	init_UF_size(g);
	initEdgeTypes(g);
    }

    collapse_sets(g,g);
    /*collapse_leaves(g); */
    class1(g);
    p = minmax_edges(g);
    decompose(g, 0);
    if (asp && ((GD_comp(g).size > 1)||(GD_n_cluster(g) > 0))) {
	asp->badGraph = 1;
	asp = NULL;
    }
    acyclic(g);
    if (minmax_edges2(g, p))
	decompose(g, 0);
#ifdef ALLOW_LEVELS
    if ((N_level = agattr(g,AGNODE,"level",NULL)))
	setRanks(g, N_level);
    else
#endif

    if (asp)
	rank3(g, asp);
    else
	rank1(g);

    expand_ranksets(g, asp);
    cleanup1(g);
}