digital levelization

hello everyone,
i'm self-taught c++ programmer,and i have one problem that is for given digital circuit after implementing it i should levelize it with following
pseudo code but i dont know how to start(how to translate this code to c++ )
i know we should represent the circuits like directed graph(algorithm)
i just dont know how to begin,,,(i have implemented the circuit by the way i.e connect the gates to each other)
just wanna levelize it or transact with it like graph...your guides will greatly appreciated,,,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Levelize(MyCircuit)
		//{
		//SET ReadyGates,ReadyNets;
		//GATE g;
		//NET n;
		//ReadyGates = TheEmptySet;
		//ReadyNets = TheEmptySet;
		//For all primary inputs n of MyCircuit do
		//n.level = 0;
		//For all gates g in the fanout of n do
		//If all inputs of g have level numbers Then
		//Add g to ReadyGates;
		//}EndIf
		//}EndFor
		//}EndFor
		//Repeat for constant one, constant zero signals;
		//While ReadyGates is not Empty or ReadyNets is not Empty do
		//If ReadyGates is not Empty Then
		//Select gate g and remove it from ReadyGates;
		//int MaxLevel = 0;
		//For each net n which is an input to g do
		//If n.Level > MaxLevel Then MaxLevel = n.Level;
		//}EndFor
		//g.Level = MaxLevel + 1;
		//For each output n of g do
		//If all driving gates of n have level numbers Then
		//Add n to ReadyNets
		//}EndIf
		//}EndFor
		//}EndIf
		//If ReadyNets is not Empty Then
		//Select Net n and remove it from ReadyNets;
		//MaxLevel = 0;
		//For each driving gate g of n do
		//If g.Level > MaxLevel Then MaxLevel = g.Level;
                //Design Automation: Logic Simulation4
		//}EndFor
		//n.Level = MaxLevel;
		//For gate g in the fanout of n do
		//If all inputs of g have level numbers Then
		//Add g to ReadyGates
		//}EndIf
		//}EndFor
		//}EndIf
		//}EndWhile
		//} 

thanks a million.
You need to figure out what set, gate, and net objects are. The rest of the algorithm looks simple, just loops, possibly manipulation of a container of some sort, but the trick is going to have representation of those objects.

If you have those objects already (I think you have at least Gates and one of the other 2 wrapping gates up in a container?) you need to figure out how to apply this algorithm to your objects.

I don't know what the "set" is (I know what that is in math, but there seems to be no sensible use for it here).
Last edited on
my circuit contains 6 nand gates (benchmark c17) i have implemented them and connect them
but my problem is what you said" how to apply this algorithm to my circuit?"
i think set is set of input vector that we should apply to the circuit and propagate them as we go throw along the circuit(meet the next level of circuit) i'm not very good in programming and have no idea with this code...so...
thank you for your time
ok so you need to be sure about that, and if you don't have such a thing, you need a container to represent the "set" in the algorithm. That could be a simple thing like vector or array, or it could be you need a class. It might help you figure out what you need if you look forward at any additional upcoming code/algorithms you will need next to see if set comes up again, and if so, how it is being used...

we can't write code using containers until we have those containers and understand how they are to be used, this step is critical. It is basically understanding the problem before trying to solve it ....

Topic archived. No new replies allowed.