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

Method addConnector

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

Add a connector between wire1 and wire2 in the network.

(self, wire1, wire2)

Source from the content-addressed store, hash-verified

41 self.addConnector(wire1, wire2)
42
43 def addConnector(self, wire1, wire2):
44 """Add a connector between wire1 and wire2 in the network."""
45 if wire1 == wire2:
46 return
47
48 if wire1 > wire2:
49 wire1, wire2 = wire2, wire1
50
51 try:
52 last_level = self[-1]
53 except IndexError:
54 # Empty network, create new level and connector
55 self.append({wire1: wire2})
56 return
57
58 for wires in last_level.items():
59 if wires[1] >= wire1 and wires[0] <= wire2:
60 self.append({wire1: wire2})
61 return
62
63 last_level[wire1] = wire2
64
65 def sort(self, values):
66 """Sort the values in-place based on the connectors in the network."""

Callers 1

__init__Method · 0.95

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected