|
17 | 17 | { |
18 | 18 | "metadata": { |
19 | 19 | "ExecuteTime": { |
20 | | - "end_time": "2025-06-19T15:50:24.279065300Z", |
21 | | - "start_time": "2025-06-19T15:50:24.119250200Z" |
| 20 | + "end_time": "2025-06-19T17:22:44.247196600Z", |
| 21 | + "start_time": "2025-06-19T17:22:44.089978900Z" |
22 | 22 | } |
23 | 23 | }, |
24 | 24 | "cell_type": "code", |
|
42 | 42 | { |
43 | 43 | "metadata": { |
44 | 44 | "ExecuteTime": { |
45 | | - "end_time": "2025-06-19T15:50:25.272229100Z", |
46 | | - "start_time": "2025-06-19T15:50:24.295155300Z" |
| 45 | + "end_time": "2025-06-19T17:22:45.214580900Z", |
| 46 | + "start_time": "2025-06-19T17:22:44.256858700Z" |
47 | 47 | } |
48 | 48 | }, |
49 | 49 | "cell_type": "code", |
|
53 | 53 | "\n", |
54 | 54 | "val gatesWithId = gates.mapIndexed { i, g -> GateWithId(\"$i\", g.in1, g.in2, g.operation.toString(), g.out) }\n", |
55 | 55 | "val wiresWithId = wires.mapIndexed { i, w -> WireWithId(\"${i + gates.size}\", w.name) }\n", |
| 56 | + "val gatesById = gatesWithId.associateBy { it.id }\n", |
| 57 | + "val wiresById = wiresWithId.associateBy { it.id }\n", |
56 | 58 | "val gatesOutLookup = gatesWithId.associateBy { it.out }\n", |
57 | 59 | "val gatesInLookup = gatesWithId.fold(emptyMap<String, GateWithId>()) { acc, gate ->\n", |
58 | 60 | " (acc + (gate.in1 to gate)) + (gate.in2 to gate)\n", |
|
74 | 76 | { |
75 | 77 | "metadata": { |
76 | 78 | "ExecuteTime": { |
77 | | - "end_time": "2025-06-19T15:50:25.779627800Z", |
78 | | - "start_time": "2025-06-19T15:50:25.282871300Z" |
| 79 | + "end_time": "2025-06-19T17:22:45.565090Z", |
| 80 | + "start_time": "2025-06-19T17:22:45.223580300Z" |
79 | 81 | } |
80 | 82 | }, |
81 | 83 | "cell_type": "code", |
|
126 | 128 | { |
127 | 129 | "metadata": { |
128 | 130 | "ExecuteTime": { |
129 | | - "end_time": "2025-06-19T15:50:26.593631900Z", |
130 | | - "start_time": "2025-06-19T15:50:25.793419900Z" |
| 131 | + "end_time": "2025-06-19T17:22:46.433761400Z", |
| 132 | + "start_time": "2025-06-19T17:22:45.580090500Z" |
131 | 133 | } |
132 | 134 | }, |
133 | 135 | "cell_type": "code", |
|
136 | 138 | "\n", |
137 | 139 | "File(\"wiredGates.dot\").printWriter().use { out ->\n", |
138 | 140 | " out.println(\"digraph {\")\n", |
139 | | - " out.println(\" edge [arrowhead=vee arrowsize=0.6]\")\n", |
| 141 | + " out.println(\" edge [fontname=Arial fontsize=9 arrowhead=vee arrowsize=0.6]\")\n", |
140 | 142 | " out.println(\" node [fontname=Arial shape=plain]\")\n", |
141 | 143 | " val gatesCount = gatesWithId.size\n", |
142 | 144 | " val outWires = gatesWithId.filter { gatesInLookup[it.out] == null }.map { it.out }\n", |
|
162 | 164 | "\n", |
163 | 165 | " wiredGateIds.first.forEachIndexed { i, fromId ->\n", |
164 | 166 | " val toId = wiredGateIds.second[i]\n", |
165 | | - " out.println(\" $fromId -> $toId\")\n", |
| 167 | + " val fromGate = gatesById[fromId]\n", |
| 168 | + " val attributes = if (fromGate != null) {\n", |
| 169 | + " if (fromGate.out.startsWith(\"z\")) {\n", |
| 170 | + " \" [color=$outZColor]\"\n", |
| 171 | + " } else {\n", |
| 172 | + " // the \"from\" and \"to\" nodes are gates -> label their connection\n", |
| 173 | + " \" [label=${fromGate.out}]\"\n", |
| 174 | + " }\n", |
| 175 | + " } else {\n", |
| 176 | + " // the \"from\" node is an input\n", |
| 177 | + " if (wiresById.getValue(fromId).name.startsWith(\"x\")) {\n", |
| 178 | + " \" [color=$inXColor]\"\n", |
| 179 | + " } else {\n", |
| 180 | + " \" [color=$inYColor]\"\n", |
| 181 | + " }\n", |
| 182 | + " }\n", |
| 183 | + " out.println(\" $fromId -> $toId$attributes\")\n", |
166 | 184 | " }\n", |
167 | 185 | "\n", |
168 | 186 | " out.println(\"}\")\n", |
|
175 | 193 | "metadata": {}, |
176 | 194 | "cell_type": "markdown", |
177 | 195 | "source": [ |
178 | | - "The resulting graph looks like this:\n", |
| 196 | + "The graph can be generated by calling\n", |
| 197 | + "\n", |
| 198 | + "```bash\n", |
| 199 | + "dot wiredGates.dot -Tsvg -o wiredGates.svg\n", |
| 200 | + "```\n", |
| 201 | + "\n", |
| 202 | + "It looks like this:\n", |
179 | 203 | "\n", |
180 | 204 | "" |
181 | 205 | ] |
|
0 commit comments