简体   繁体   English

如何找到用c ++实现的有向图的所有路径作为邻接表?

[英]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: 我在C ++中将图形实现为顶点,如下所示:

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. 在邻接列表中,除了VERTEX之外,您还拥有EDGE。 in each EDGE you specify the FROM and TO, this will represent the vertices on both ends of the EDGE. 在每个EDGE中,您指定FROM和TO,这将代表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. 为了找到给定VERTEX的所有路径,您只需循环邻接表并找到所有FROMS等于要查找其所有子级的VERTEX的EDGES。

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. 例如:如果要查找来自顶点A的所有路径,然后搜索邻接列表并过滤所有FROM(或源节点)等于A的边,则结果是来自顶点A的可能路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C ++中为有向图创建邻接列表 - Making an adjacency list in C++ for a directed graph 将边添加到使用C ++中的链接列表实现的有向图(邻接列表)中 - Add edge to a directed graph (Adjacency list) implemented using Linked List in C++ 图 - 邻接表 C++ - 从源到目标的所有路径 - Graph - Adjacency List C++ - All Paths from source to destination 在 C++ 中将邻接列表转换为有向无环图的邻接矩阵 - Converting an Adjacency List to a an Adjacency Matrix for a Directed Acyclic Graph in C++ 如何对 C++ 中使用邻接表实现的图进行排序? - How can I sort a graph implemented with adjacency list in C++? 使用C ++向量的有向图的邻接表表示 - Adjacency list representation of a directed graph using c++ vector 如何在C ++中找到图的邻接表的大小? - How to find the size of the adjacency list of the graph in c++? 考虑到遍历的路径每次都是相同的,如何在C ++中实现有向图而不使用邻接表? - How do I implement a directed graph in C++ without using an adjacency list, given that the path of traversal will be the same every time? 找到有向图C ++的最短路径 - Finding the shortest paths of a directed graph C++ 使用邻接矩阵在C ++上的有向图中查找所有循环的算法 - Algorithm for finding all cycles in a directed graph on C++ using Adjacency matrix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM