我需要一个建议,如何用一个程序(以编程方式)计算从开始节点到结束节点的所有可能路径,我可以使用C#、Python或Matlab,但我不知道哪一个更容易、更快速地编码,也不知道从何处开始,我还需要自动绘制节点之间的边,并在以后计算更多公式。 我有以下数据
Node Date Data
A 2020-01-01 2.09
B 2020-01-05 0.89
C 2020-01-08 3.17
D 2020-01-08 1.15
E 2020-01-15 3.65
我想做以下工作:
创建从任何节点到另一个节点的路径(单向,仅从较低日期到较高日期),并且必须在路径中的日期之间通过所有节点,例如:
1.1由(A)至(E) 应提取以下路径:
因为C和D在同一天,所以我们有两条不同的路径
列表项
使用Python groupby和Pythonitertools module中的产品
代码
用法
示例1:字符串中的数据
示例2:文件Data.txt中的数据
输出(两种情况下):
这将为每个路径生成节点链列表。它使用python列表和字典进行散列-因此,如果处理大型数据集,速度会非常慢。如果是这种情况,请查看熊猫库(groupby)。同样的逻辑也会起作用,但在nodes_by_date函数中肯定会节省时间。该库中还可能有其他工具来生成所需的路径
相关问题 更多 >
编程相关推荐