小编ken*_*e17的帖子

如何在R中找到图上所有可能的有效路径?

我正在 R 中解决一个有趣的问题(可能使用igraph和/或tidygraph库),我需要在图表上找到满足某些条件的所有可能路径。问题可以简化为:

我有16 个不同的节点,可以分为4组,每个节点都有一个特征,称之为颜色。*注意:以下可能不是表示数据的最佳方式,但希望它能传达情况。

nodes_set_1 <- c("red", "blue", "orange")
nodes_set_2 <- c("green", "blue", "red", "yellow", "purple")
nodes_set_3 <- c("blue", "green", "red", "orange", "purple")
nodes_set_4 <- c("orange", "blue", "green")
Run Code Online (Sandbox Code Playgroud)

我现在需要找到这些节点之间满足以下三个条件的所有可能路径: (1) 每条路径必须恰好包含每组中的一个节点。(2) 图形是从nodes_set_1nodes_set_2nodes_set_3nodes_set_4 (3) 单个路径中颜色不能重复。

例如,以下路径是有效的:

path_1 <- c(nodes_set_1[1], nodes_set_2[1], nodes_set_3[1], nodes_set_4[1])

下面的路径将无效,因为颜色“蓝色”重复:

path_2 <- c(nodes_set_1[2], nodes_set_2[2], nodes_set_3[2], nodes_set_4[2])

我希望得到一些关于设置和解决这个问题的建议。找到一种有效确定是否不存在有效解决方案的方法也将令人惊奇。

谢谢你!

performance r combinatorics igraph tidygraph

1
推荐指数
1
解决办法
201
查看次数

标签 统计

combinatorics ×1

igraph ×1

performance ×1

r ×1

tidygraph ×1