-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.py
30 lines (23 loc) · 971 Bytes
/
classes.py
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
from collections import defaultdict
#***************************************************************#
# A class to package all the information of one gate of the circuit
class Gate:
def __init__(self, name, inputs, output):
self.name = name
self.inputs = inputs # list of inputs
self.output = output # only one output(primitive gates)
#***************************************************************#
# A class to represent a graph using adjancency list
class Graph:
def __init__(self):
self.adj = defaultdict(list) # Adjacency list
# Adds a directed edge from a to b (a---->b)
def add_edge(self, a, b):
self.adj[a].append(b)
# prints the graph
def print_graph(self, name):
print(f"The {name} graph:\n----------------------------")
for vertex in self.adj:
print(vertex, "--->", self.adj[vertex])
print("-----------------------------------\n");
#***************************************************************#