简体   繁体   中英

How to find all paths for a directed graph implemented in c++ as adjacency list?

I implement my graph in C++ as vertex as follows:

struct vertex {
    string node_id;
    string node_name;
    int no_servers;
    float mu;
    int node_type; // 1-7
    float lambda;
    float time;
    bool CD; // 0 if converges join----- and 1 if div  split
    vector<int> adj; // children :adjacency list -vector- of
                     // edges contains the indexes to vertex
}; 

struct fill_data {
    vertex node_data;
    int ORDER; // for edges --- father
    fill_data* next;
};

I need all possible paths for my graph. In each node I will reach there will be some computations using some of its father information.

I couldn't find a structure or away since the number of children for each node differs from one node to another.

In the adjacency list, you also have an EDGE aside from the VERTEX. in each EDGE you specify the FROM and TO, this will represent the vertices on both ends of the EDGE.

In order to find all the paths from a given VERTEX, you simply loop the adjacency list and find all EDGES with a FROM equals the VERTEX that you want to find all its children.

example: if you want to find all paths from vertex A, then search the adjacency list and filter all edges that have a FROM (or source node) equals A, the result is the possible paths from vertex A.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM