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

Method draw

examples/ga/sortingnetwork.py:82–110  ·  view source on GitHub ↗

Return an ASCII representation of the network.

(self)

Source from the content-addressed store, hash-verified

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

Callers 2

mainFunction · 0.95
mainFunction · 0.95

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected