Exemplo n.º 1
0
int SCC ( int s ) {
    vis[s] = GRAY;
    disc[s] = low[s] = globalCnt++;
    tarjan.push_back(s);
    for ( int i = 0; i < adj[s].size(); i++ ) {
        int t = adj[s][i];
        if ( vis[t] == WHITE ) { ///This is tree edge
            SCC ( t );
          low[s] = min ( low[s], low[t] );
        }
        else if ( vis[t] == GRAY ) { ///This is back edge
            ///Cycle detected
            flagCycle = true;
            low[s] = min ( low[s], low[t] );
        }
    }
    if ( disc[s] == low[s] ) {
        while ( 1 ) {
            int lastNode = tarjan.back();
            cycle[lastNode] = head;
            tarjan.pop_back();
            vis[lastNode] = BLACK;
            if ( lastNode == s ) break;
        }
        head++;
    }
}
// Depth First Search 
void DFS(Graph* mygraph)
{
    // initialize arrays
    // inStack array keeps information about nodes whether they are in stack
    int index[mygraph->MaxSize];
    int lowlink[mygraph->MaxSize];
    int inStack[mygraph->MaxSize];
    stackT stack;
    
    // initialize stack
    StackInit(&stack, mygraph->MaxSize);

    // for each node in the graph
    for (int i = 1; i < mygraph->MaxSize; i++)
    {
       index[i] = -1;
       lowlink[i] = -1;
       inStack[i] = 0; // 0 - false
    }
    
    // for each node if it it not visited yet
    // send note to strongly connected components function
    for (int i = 1; i < mygraph->MaxSize; i++)
    {
        if (index[i] == -1)
        {
            SCC(mygraph, i, index, lowlink, stack, inStack);
        }    
    }        
}
void StronglyConnectedComponents( Graph G, void (*visit)(Vertex V) ) {
    memset(visited, 0, sizeof(visited));
    Graph g = ReverseGraph(G);
    for(int i = 0; i < G->NumOfVertices; i++) {
        if (!visited[i]) {
            DFS(g, i, push);
        }
    }
    SCC(G, visit);
}
Exemplo n.º 4
0
void SCC(int u){
    dfs_num[u] = dfs_num[u] = dfsNumberCounter++;
    visited[u] = 1;
    S.push_back(u);
    for(int j = 0; j < (int)AdjList[u].size(); j++){
        ii v = AdjList[u][j];
        if(dfs_num[v.first] == UNVISITED){
            SCC(v.first);
        }
        if(visited[v.first]) dfs_low[u] = min(dfs_low[u], dfs_low[v.first]);
    }
    if(dfs_low[u] == dfs_num[u]){
                // SCC
                // pop until getting u
    }

}
// strongly connected components
// function takes graph, current node, index array, lowlink array, stack and 
// boolean for nodes in stack
void SCC(Graph* mygraph, int u, int index[], int lowlink[], stackT stack, 
                                                                int inStack[])
{   
    // assign current stack to global stack variable
    stackGl = stack;
    counter = counter + 1;
    index[u] = lowlink[u] = counter;
    
    // add current node to stack
    StackPush(&stackGl, u);
    
    // change current node to true 
    inStack[u] = 1;
    
    // create adjacency list
    // it is outlist of current node
    List* adj = (List*)malloc(sizeof(List));
    adj = mygraph->table[u].outlist;   
    
    // while there is a node outlist of current node
    // update lowlink of current node
    while(adj != NULL)
    {
        // adjacent node of the current node
        int v = adj->index;
        
        // if adjacent node has not discovered yet
        // send node to strongly connected component function
        // update the lowlink of the current node
        if (index[v] == -1)
        {
            SCC(mygraph, v, index, lowlink, stackGl, inStack);        
            lowlink[u] = min(lowlink[u],lowlink[v]);       
        }
        // if adjacent node is already discovered 
        // update lowlink number of the current node anyway
        else if(inStack[v] == 1)
        {
            lowlink[u] = min(lowlink[u], index[v]);
        }

        // pass to next node
        adj = adj->next;
    }
    
    int tmp;
    
    // if lowlink number of current node is equal to the index number of same
    // node, print the node
    if(lowlink[u] == index[u])
    {
        // if current node is in not in the top the stack
        // find the node and print out
        while (stackGl.contents[stackGl.top] != u)
        {
            tmp = stackGl.contents[stackGl.top];
            printf("%d ", tmp);
            inStack[tmp] = 0;
            StackPop(&stackGl);
            
        }
        // print it
        tmp = stackGl.contents[stackGl.top];
        printf(" %d\n ", tmp);
        inStack[tmp] = 0;
        
        // remove nodes from stack
        StackPop(&stackGl);
    }
    
}
Exemplo n.º 6
0
Bool EWMH_CMD_Style(char *token, window_style *ptmpstyle, int on)
{
	int found = False;

	if (StrEquals(token, "EWMHDonateIcon"))
	{
		found = True;
		S_SET_DO_EWMH_DONATE_ICON(SCF(*ptmpstyle), on);
		S_SET_DO_EWMH_DONATE_ICON(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_DONATE_ICON(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHDonateMiniIcon"))
	{
		found = True;
		S_SET_DO_EWMH_DONATE_MINI_ICON(SCF(*ptmpstyle), on);
		S_SET_DO_EWMH_DONATE_MINI_ICON(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_DONATE_MINI_ICON(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHDontDonateIcon"))
	{
		found = True;
		S_SET_DO_EWMH_DONATE_ICON(SCF(*ptmpstyle), !on);
		S_SET_DO_EWMH_DONATE_ICON(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_DONATE_ICON(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHDontDonateMiniIcon"))
	{
		found = True;
		S_SET_DO_EWMH_DONATE_MINI_ICON(SCF(*ptmpstyle), !on);
		S_SET_DO_EWMH_DONATE_MINI_ICON(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_DONATE_MINI_ICON(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHMaximizeIgnoreWorkingArea"))
	{
		found = True;
		S_SET_EWMH_MAXIMIZE_MODE(
			SCF(*ptmpstyle), EWMH_IGNORE_WORKING_AREA);
		S_SET_EWMH_MAXIMIZE_MODE(
			SCM(*ptmpstyle), EWMH_WORKING_AREA_MASK);
		S_SET_EWMH_MAXIMIZE_MODE(
			SCC(*ptmpstyle), EWMH_WORKING_AREA_MASK);
	}
	else if (StrEquals(token, "EWMHMaximizeUseWorkingArea"))
	{
		found = True;
		S_SET_EWMH_MAXIMIZE_MODE(
			SCF(*ptmpstyle), EWMH_USE_WORKING_AREA);
		S_SET_EWMH_MAXIMIZE_MODE(
			SCM(*ptmpstyle), EWMH_WORKING_AREA_MASK);
		S_SET_EWMH_MAXIMIZE_MODE(
			SCC(*ptmpstyle), EWMH_WORKING_AREA_MASK);
	}
	else if (StrEquals(token, "EWMHMaximizeUseDynamicWorkingArea"))
	{
		found = True;
		S_SET_EWMH_MAXIMIZE_MODE(
			SCF(*ptmpstyle), EWMH_USE_DYNAMIC_WORKING_AREA);
		S_SET_EWMH_MAXIMIZE_MODE(
			SCM(*ptmpstyle), EWMH_WORKING_AREA_MASK);
		S_SET_EWMH_MAXIMIZE_MODE(
			SCC(*ptmpstyle), EWMH_WORKING_AREA_MASK);
	}
	else if (StrEquals(token, "EWMHMiniIconOverride"))
	{
		found = True;
		S_SET_DO_EWMH_MINI_ICON_OVERRIDE(SCF(*ptmpstyle), on);
		S_SET_DO_EWMH_MINI_ICON_OVERRIDE(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_MINI_ICON_OVERRIDE(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHNoMiniIconOverride"))
	{
		found = True;
		S_SET_DO_EWMH_MINI_ICON_OVERRIDE(SCF(*ptmpstyle), !on);
		S_SET_DO_EWMH_MINI_ICON_OVERRIDE(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_MINI_ICON_OVERRIDE(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHPlacementIgnoreWorkingArea"))
	{
		found = True;
		ptmpstyle->flags.ewmh_placement_mode =
			EWMH_IGNORE_WORKING_AREA;
		ptmpstyle->flag_mask.ewmh_placement_mode =
			EWMH_WORKING_AREA_MASK;
		ptmpstyle->change_mask.ewmh_placement_mode =
			EWMH_WORKING_AREA_MASK;
	}
	else if (StrEquals(token, "EWMHPlacementUseWorkingArea"))
	{
		found = True;
		ptmpstyle->flags.ewmh_placement_mode = EWMH_USE_WORKING_AREA;
		ptmpstyle->flag_mask.ewmh_placement_mode =
			EWMH_WORKING_AREA_MASK;
		ptmpstyle->change_mask.ewmh_placement_mode =
			EWMH_WORKING_AREA_MASK;
	}
	else if (StrEquals(token, "EWMHPlacementUseDynamicWorkingArea"))
	{
		found = True;
		ptmpstyle->flags.ewmh_placement_mode =
			EWMH_USE_DYNAMIC_WORKING_AREA;
		ptmpstyle->flag_mask.ewmh_placement_mode =
			EWMH_WORKING_AREA_MASK;
		ptmpstyle->change_mask.ewmh_placement_mode =
			EWMH_WORKING_AREA_MASK;
	}
	else if (StrEquals(token, "EWMHUseStackingOrderHints"))
	{
		found = True;
		S_SET_DO_EWMH_USE_STACKING_HINTS(SCF(*ptmpstyle), on);
		S_SET_DO_EWMH_USE_STACKING_HINTS(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_USE_STACKING_HINTS(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHIgnoreStackingOrderHints"))
	{
		found = True;
		S_SET_DO_EWMH_USE_STACKING_HINTS(SCF(*ptmpstyle), !on);
		S_SET_DO_EWMH_USE_STACKING_HINTS(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_USE_STACKING_HINTS(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHUseStateHints"))
	{
		found = True;
		S_SET_DO_EWMH_IGNORE_STATE_HINTS(SCF(*ptmpstyle), !on);
		S_SET_DO_EWMH_IGNORE_STATE_HINTS(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_IGNORE_STATE_HINTS(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHIgnoreStateHints"))
	{
		found = True;
		S_SET_DO_EWMH_IGNORE_STATE_HINTS(SCF(*ptmpstyle), on);
		S_SET_DO_EWMH_IGNORE_STATE_HINTS(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_IGNORE_STATE_HINTS(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHUseStrutHints"))
	{
		found = True;
		S_SET_DO_EWMH_IGNORE_STRUT_HINTS(SCF(*ptmpstyle), !on);
		S_SET_DO_EWMH_IGNORE_STRUT_HINTS(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_IGNORE_STRUT_HINTS(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHIgnoreStrutHints"))
	{
		found = True;
		S_SET_DO_EWMH_IGNORE_STRUT_HINTS(SCF(*ptmpstyle), on);
		S_SET_DO_EWMH_IGNORE_STRUT_HINTS(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_IGNORE_STRUT_HINTS(SCC(*ptmpstyle), 1);
	}
	else if (StrEquals(token, "EWMHIgnoreWindowType"))
	{
		found = True;
		S_SET_DO_EWMH_IGNORE_WINDOW_TYPE(SCF(*ptmpstyle), on);
		S_SET_DO_EWMH_IGNORE_WINDOW_TYPE(SCM(*ptmpstyle), 1);
		S_SET_DO_EWMH_IGNORE_WINDOW_TYPE(SCC(*ptmpstyle), 1);
	}
	return found;
}