Skip to content

Commit

Permalink
NetRenderer -- improve representation of graph
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 29, 2023
1 parent 8e71a65 commit 079ca49
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 106 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ no `defru` just `defrule` -- add feature when very very needed

change the `render` command to simple `run` command

`NetRenderer` show free port names
`NetRenderer` show port name

# value

Expand Down
16 changes: 8 additions & 8 deletions docs/tests/DiffList.inet.one_two_soles.finial.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cons#2 -- sole#1 [label="0-0"]
cons#6 -- sole#5 [label="0-0"]
cons#8 -- sole#7 [label="0-0"]
cons#8 -- cons#6 [label="1-2"]
diff#13 -- cons#6 [label="0-1"]
cons#8 -- cons#2 [label="2-2"]
diff#13 -- cons#2 [label="1-1"]
diff#13(2) -- diff#13
(sole#1)-[0] [0]-(cons#2)
(sole#5)-[0] [0]-(cons#6)
(sole#7)-[0] [0]-(cons#8)
(cons#6)-[2] [1]-(cons#8)
(cons#6)-[1] [0]-(diff#13)
(cons#2)-[2] [2]-(cons#8)
(cons#2)-[1] [1]-(diff#13)
(diff#13)-[2]
22 changes: 11 additions & 11 deletions docs/tests/DiffList.inet.one_two_soles.initial.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cons#2 -- sole#1 [label="0-0"]
diff#3 -- cons#2 [label="0-2"]
cons#6 -- sole#5 [label="0-0"]
cons#8 -- sole#7 [label="0-0"]
cons#8 -- cons#6 [label="1-2"]
diff#9 -- cons#8 [label="0-2"]
diff_append#10 -- diff#3 [label="1-2"]
cons#2 -- diff#3 [label="1-1"]
cons#6 -- diff#9 [label="1-1"]
diff_append#10 -- diff#9 [label="0-2" color=red]
diff_append#10(2) -- diff_append#10
(diff#9)-[2]![0]-(diff_append#10)
(sole#1)-[0] [0]-(cons#2)
(cons#2)-[2] [0]-(diff#3)
(sole#5)-[0] [0]-(cons#6)
(sole#7)-[0] [0]-(cons#8)
(cons#6)-[2] [1]-(cons#8)
(cons#8)-[2] [0]-(diff#9)
(diff#3)-[2] [1]-(diff_append#10)
(diff#3)-[1] [1]-(cons#2)
(diff#9)-[1] [1]-(cons#6)
(diff_append#10)-[2]
20 changes: 10 additions & 10 deletions docs/tests/DiffList.inet.two_two_soles.finial.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cons#16 -- sole#15 [label="0-0"]
cons#18 -- sole#17 [label="0-0"]
cons#18 -- cons#16 [label="1-2"]
cons#22 -- sole#21 [label="0-0"]
cons#24 -- sole#23 [label="0-0"]
cons#24 -- cons#22 [label="1-2"]
diff#29 -- cons#22 [label="0-1"]
cons#24 -- cons#18 [label="2-2"]
diff#29 -- cons#16 [label="1-1"]
diff#29(2) -- diff#29
(sole#15)-[0] [0]-(cons#16)
(sole#17)-[0] [0]-(cons#18)
(cons#16)-[2] [1]-(cons#18)
(sole#21)-[0] [0]-(cons#22)
(sole#23)-[0] [0]-(cons#24)
(cons#22)-[2] [1]-(cons#24)
(cons#22)-[1] [0]-(diff#29)
(cons#18)-[2] [2]-(cons#24)
(cons#16)-[1] [1]-(diff#29)
(diff#29)-[2]
26 changes: 13 additions & 13 deletions docs/tests/DiffList.inet.two_two_soles.initial.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cons#16 -- sole#15 [label="0-0"]
cons#18 -- sole#17 [label="0-0"]
cons#18 -- cons#16 [label="1-2"]
diff#19 -- cons#18 [label="0-2"]
cons#22 -- sole#21 [label="0-0"]
cons#24 -- sole#23 [label="0-0"]
cons#24 -- cons#22 [label="1-2"]
diff#25 -- cons#24 [label="0-2"]
diff_append#26 -- diff#19 [label="1-2"]
cons#16 -- diff#19 [label="1-1"]
cons#22 -- diff#25 [label="1-1"]
diff_append#26 -- diff#25 [label="0-2" color=red]
diff_append#26(2) -- diff_append#26
(diff#25)-[2]![0]-(diff_append#26)
(sole#15)-[0] [0]-(cons#16)
(sole#17)-[0] [0]-(cons#18)
(cons#16)-[2] [1]-(cons#18)
(cons#18)-[2] [0]-(diff#19)
(sole#21)-[0] [0]-(cons#22)
(sole#23)-[0] [0]-(cons#24)
(cons#22)-[2] [1]-(cons#24)
(cons#24)-[2] [0]-(diff#25)
(diff#19)-[2] [1]-(diff_append#26)
(diff#19)-[1] [1]-(cons#16)
(diff#25)-[1] [1]-(cons#22)
(diff_append#26)-[2]
30 changes: 15 additions & 15 deletions docs/tests/List.inet.six_soles.finial.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
cons#2 -- sole#1 [label="0-0"]
cons#2 -- null#0 [label="1-0"]
cons#4 -- sole#3 [label="0-0"]
cons#4 -- cons#2 [label="1-2"]
cons#6 -- sole#5 [label="0-0"]
cons#6 -- cons#4 [label="1-2"]
cons#9 -- sole#8 [label="0-0"]
cons#9 -- null#7 [label="1-0"]
cons#11 -- sole#10 [label="0-0"]
cons#11 -- cons#9 [label="1-2"]
append#16 -- sole#12 [label="0-0"]
append#16 -- cons#6 [label="1-2"]
cons#17 -- cons#11 [label="0-2"]
cons#17 -- append#16 [label="1-2"]
cons#17(2) -- cons#17
(sole#1)-[0] [0]-(cons#2)
(null#0)-[0] [1]-(cons#2)
(sole#3)-[0] [0]-(cons#4)
(cons#2)-[2] [1]-(cons#4)
(sole#5)-[0] [0]-(cons#6)
(cons#4)-[2] [1]-(cons#6)
(sole#8)-[0] [0]-(cons#9)
(null#7)-[0] [1]-(cons#9)
(sole#10)-[0] [0]-(cons#11)
(cons#9)-[2] [1]-(cons#11)
(sole#12)-[0] [0]-(append#16)
(cons#6)-[2] [1]-(append#16)
(cons#11)-[2] [0]-(cons#17)
(append#16)-[2] [1]-(cons#17)
(cons#17)-[2]
30 changes: 15 additions & 15 deletions docs/tests/List.inet.six_soles.initial.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
cons#2 -- sole#1 [label="0-0"]
cons#2 -- null#0 [label="1-0"]
cons#4 -- sole#3 [label="0-0"]
cons#4 -- cons#2 [label="1-2"]
cons#6 -- sole#5 [label="0-0"]
cons#6 -- cons#4 [label="1-2"]
cons#9 -- sole#8 [label="0-0"]
cons#9 -- null#7 [label="1-0"]
cons#11 -- sole#10 [label="0-0"]
cons#11 -- cons#9 [label="1-2"]
cons#13 -- sole#12 [label="0-0"]
cons#13 -- cons#11 [label="1-2"]
append#14 -- cons#6 [label="1-2"]
append#14 -- cons#13 [label="0-2" color=red]
append#14(2) -- append#14
(cons#13)-[2]![0]-(append#14)
(sole#1)-[0] [0]-(cons#2)
(null#0)-[0] [1]-(cons#2)
(sole#3)-[0] [0]-(cons#4)
(cons#2)-[2] [1]-(cons#4)
(sole#5)-[0] [0]-(cons#6)
(cons#4)-[2] [1]-(cons#6)
(sole#8)-[0] [0]-(cons#9)
(null#7)-[0] [1]-(cons#9)
(sole#10)-[0] [0]-(cons#11)
(cons#9)-[2] [1]-(cons#11)
(sole#12)-[0] [0]-(cons#13)
(cons#11)-[2] [1]-(cons#13)
(cons#6)-[2] [1]-(append#14)
(append#14)-[2]
10 changes: 5 additions & 5 deletions docs/tests/Nat.inet.four.finial.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add1#9 -- zero#8 [label="0-0"]
add1#23 -- add1#25 [label="0-1"]
add1#25 -- add1#27 [label="0-1"]
add1#27 -- add1#9 [label="0-1"]
add1#23(1) -- add1#23
(zero#8)-[0] [0]-(add1#9)
(add1#25)-[1] [0]-(add1#23)
(add1#27)-[1] [0]-(add1#25)
(add1#9)-[1] [0]-(add1#27)
(add1#23)-[1]
22 changes: 11 additions & 11 deletions docs/tests/Nat.inet.four.initial.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
add1#9 -- zero#8 [label="0-0"]
add1#11 -- zero#10 [label="0-0"]
add#12 -- add1#9 [label="1-1"]
add1#14 -- zero#13 [label="0-0"]
add1#16 -- zero#15 [label="0-0"]
add#17 -- add1#14 [label="1-1"]
add#18 -- add#17 [label="0-2"]
add#18 -- add#12 [label="1-2"]
add#12 -- add1#11 [label="0-1" color=red]
add#17 -- add1#16 [label="0-1" color=red]
add#18(2) -- add#18
(add1#11)-[1]![0]-(add#12)
(add1#16)-[1]![0]-(add#17)
(zero#8)-[0] [0]-(add1#9)
(zero#10)-[0] [0]-(add1#11)
(add1#9)-[1] [1]-(add#12)
(zero#13)-[0] [0]-(add1#14)
(zero#15)-[0] [0]-(add1#16)
(add1#14)-[1] [1]-(add#17)
(add#17)-[2] [0]-(add#18)
(add#12)-[2] [1]-(add#18)
(add#18)-[2]
6 changes: 3 additions & 3 deletions docs/tests/Nat.inet.two.finial.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add1#1 -- zero#0 [label="0-0"]
add1#7 -- add1#1 [label="0-1"]
add1#7(1) -- add1#7
(zero#0)-[0] [0]-(add1#1)
(add1#1)-[1] [0]-(add1#7)
(add1#7)-[1]
10 changes: 5 additions & 5 deletions docs/tests/Nat.inet.two.initial.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add1#1 -- zero#0 [label="0-0"]
add1#3 -- zero#2 [label="0-0"]
add#4 -- add1#1 [label="1-1"]
add#4 -- add1#3 [label="0-1" color=red]
add#4(2) -- add#4
(add1#3)-[1]![0]-(add#4)
(zero#0)-[0] [0]-(add1#1)
(zero#2)-[0] [0]-(add1#3)
(add1#1)-[1] [1]-(add#4)
(add#4)-[2]
18 changes: 9 additions & 9 deletions src/renderers/NetRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ export class NetRenderer {
renderToDot(net: Net): string {
const lines: Array<string> = []

for (const edge of net.edges) {
for (const edge of net.activeEdges) {
const start = formatNode(edge.start.node)
const end = formatNode(edge.end.node)
const indexes = `${edge.end.index}-${edge.start.index}`
lines.push(`${end} -- ${start} [label="${indexes}"]`)
lines.push(
`(${start})-[${edge.start.index}]![${edge.end.index}]-(${end})`,
)
}

for (const edge of net.activeEdges) {
for (const edge of net.edges) {
const start = formatNode(edge.start.node)
const end = formatNode(edge.end.node)
const indexes = `${edge.end.index}-${edge.start.index}`
lines.push(`${end} -- ${start} [label="${indexes}" color=red]`)
lines.push(
`(${start})-[${edge.start.index}] [${edge.end.index}]-(${end})`,
)
}

for (const port of net.portStack) {
const start = formatNode(port.node)
const end = `${formatNode(port.node)}(${port.index})`
lines.push(`${end} -- ${start}`)
lines.push(`(${formatNode(port.node)})-[${port.index}]`)
}

return lines.join("\n")
Expand Down

0 comments on commit 079ca49

Please sign in to comment.