c - 需要关于如何实现这个的帮助..选择一个最好的数据结构

标签 c algorithm data-structures graph directed-graph

我想分析一个组合数字电路。 ASCII 文件包含电路的描述,格式如下:

<name> <logic gate> <inputs> <outputs> <input 1>…<last input> <output> <delay>

地点: <name>是一个不超过 20 个字符的字符串,带有逻辑门的名称。 <logic gate>是一个不超过 20 个字符的字符串,用于标识逻辑门的类型。可以是INPUT , OUTPUT , AND , OR , NOT . <inputs>是一个整数,对于 INPUT 等于 0,对于 NOT 或 OUTPUT 等于 1,对于 AND 和 OR 等于 2。 <outputs>对于 OUTPUT 是等于 0 的整数,否则大于 0。 <input 1> , <last input>, <output > 是每个不超过 20 个字符的字符串,用于标识逻辑门的输入/输出网络的名称。 <delay>是一个整数,标识逻辑门计算其功能所花费的时间。

程序在读取包含电路描述的文件后,必须计算电路的关键路径,它可以定义为连接输入类型门和输出类型之一的路径,其延迟总和路径中门的数量是电路中所有可能路径中最高的。

Can anyone please tell me the data structures that are best suited for storing the information the program has to elaborate.
How could i load the the data structure into the memory?

例子

A INPUT 0 1 net1 1
B INPUT 0 1 net2 1
C INPUT 0 1 net3 1
G1 NOT 1 1 net1 net4 1
G2 OR 2 1 met3 net4 net5 1
G3 AND 2 1 net4 net2 net6 2
G4 AND 2 1 net6 net5 net7 2
D OUTPUT 1 0 net6 1
E OUTPUT 1 0 E 1 



In this example the critical path is A/G1/G2/G4/E with a delay of 7.

我该如何实现呢?

最佳答案

如果我对您的问题的理解正确,那么您真的很想知道应该使用哪种算法来计算关键路径。这似乎类似于“什么是最短路径?”类型的问题。我推荐 Dijkstra's Algorithm对于这个问题。

关于c - 需要关于如何实现这个的帮助..选择一个最好的数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4530161/

相关文章:

algorithm - 什么数据结构或算法用于自动完成?

javascript - 如何从 JSON 兼容的嵌套对象/数据结构递归生成类似标记的字符串?

java - 生成与集合中给定的任何一个不同的随机索引

c - GCC - 编译时出错

c++ - 为什么我不能在 memcpy 中使用 const 参数?

C - 通过调用 printf?y 修复了 SDL 不一致的帧速率和屏幕垃圾

c++ - 对每个簇大小具有上限要求的聚类算法

algorithm - bellman-ford 是否可以在一次迭代中完成?

c++ - 优先级队列的重载运算符

c - 使用组播 UDP 的 C 网络记录器?