MCPcopy Create free account
hub / github.com/DEAP/deap / draw

Method draw

doc/code/tutorials/part_4/sortingnetwork.py:88–116  ·  view source on GitHub ↗

Return an ASCII representation of the network.

(self)

Source from the content-addressed store, hash-verified

86 return misses
87
88 def draw(self):
89 """Return an ASCII representation of the network."""
90 str_wires = [["-"]*7 * self.depth]
91 str_wires[0][0] = "0"
92 str_wires[0][1] = " o"
93 str_spaces = []
94
95 for i in range(1, self.dimension):
96 str_wires.append(["-"]*7 * self.depth)
97 str_spaces.append([" "]*7 * self.depth)
98 str_wires[i][0] = str(i)
99 str_wires[i][1] = " o"
100
101 for index, level in enumerate(self):
102 for wire1, wire2 in level.items():
103 str_wires[wire1][(index+1)*6] = "x"
104 str_wires[wire2][(index+1)*6] = "x"
105 for i in range(wire1, wire2):
106 str_spaces[i][(index+1)*6+1] = "|"
107 for i in range(wire1+1, wire2):
108 str_wires[i][(index+1)*6] = "|"
109
110 network_draw = "".join(str_wires[0])
111 for line, space in zip(str_wires[1:], str_spaces):
112 network_draw += "\n"
113 network_draw += "".join(space)
114 network_draw += "\n"
115 network_draw += "".join(line)
116 return network_draw
117
118 @property
119 def depth(self):

Callers 2

mainFunction · 0.95
mainFunction · 0.95

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected