Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
15
Task/Graph-colouring/J/graph-colouring-1.j
Normal file
15
Task/Graph-colouring/J/graph-colouring-1.j
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
parse=: {{
|
||||
ref=: 2$L:1(;:each cut y) -.L:1 ;:'-'
|
||||
labels=: /:~~.;ref
|
||||
sparse=. (*:#labels) > 20*#ref
|
||||
graph=: (+.|:) 1 (labels i.L:1 ref)} $.^:sparse 0$~2##labels
|
||||
}}
|
||||
|
||||
greedy=: {{
|
||||
colors=. (#y)#a:
|
||||
for_node.y do.
|
||||
color=. <{.(-.~ [:i.1+#) ~.;node#colors
|
||||
colors=. color node_index} colors
|
||||
end.
|
||||
;colors
|
||||
}}
|
||||
32
Task/Graph-colouring/J/graph-colouring-2.j
Normal file
32
Task/Graph-colouring/J/graph-colouring-2.j
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
ex1=:'0-1 1-2 2-0 3'
|
||||
ex2=:'1-6 1-7 1-8 2-5 2-7 2-8 3-5 3-6 3-8 4-5 4-6 4-7'
|
||||
ex3=:'1-4 1-6 1-8 3-2 3-6 3-8 5-2 5-4 5-8 7-2 7-4 7-6'
|
||||
ex4=:'1-6 7-1 8-1 5-2 2-7 2-8 3-5 6-3 3-8 4-5 4-6 4-7'
|
||||
require'format/printf'
|
||||
require'format/printf'
|
||||
task=: {{
|
||||
colors=. greedy parse y
|
||||
echo'nodes: %d, edges: %d, colours: %d' sprintf #each graph;ref;~.colors
|
||||
edgecolors=. <@(,&":':',&":])/"1(>labels i.L:1 ref){colors
|
||||
,./>' ',.~each^:2(cut y),:each edgecolors
|
||||
}}
|
||||
|
||||
task ex1
|
||||
nodes: 4, edges: 4, colours: 3
|
||||
0-1 1-2 2-0 3
|
||||
0:1 1:2 2:0 0:0
|
||||
|
||||
task ex2
|
||||
nodes: 8, edges: 12, colours: 2
|
||||
1-6 1-7 1-8 2-5 2-7 2-8 3-5 3-6 3-8 4-5 4-6 4-7
|
||||
0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1
|
||||
|
||||
task ex3
|
||||
nodes: 8, edges: 12, colours: 4
|
||||
1-4 1-6 1-8 3-2 3-6 3-8 5-2 5-4 5-8 7-2 7-4 7-6
|
||||
0:1 0:2 0:3 1:0 1:2 1:3 2:0 2:1 2:3 3:0 3:1 3:2
|
||||
|
||||
task ex4
|
||||
nodes: 8, edges: 12, colours: 2
|
||||
1-6 7-1 8-1 5-2 2-7 2-8 3-5 6-3 3-8 4-5 4-6 4-7
|
||||
0:1 1:0 1:0 1:0 0:1 0:1 0:1 1:0 0:1 0:1 0:1 0:1
|
||||
37
Task/Graph-colouring/J/graph-colouring-3.j
Normal file
37
Task/Graph-colouring/J/graph-colouring-3.j
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
anneal=: {{
|
||||
best=. i.#y [ cost=. #~.greedy y
|
||||
for.i.#y do.
|
||||
o=. ?~#y
|
||||
c=.#~.greedy o ([ { {"1) y
|
||||
if. cost > c do.
|
||||
best=. o [ cost=. c
|
||||
end.
|
||||
end.
|
||||
(/:best) { greedy best ([ { {"1) y
|
||||
}}
|
||||
task=: {{
|
||||
colors=. anneal parse y
|
||||
echo'nodes: %d, edges: %d, colours: %d' sprintf #each graph;ref;~.colors
|
||||
edgecolors=. <@(,&":':',&":])/"1(>labels i.L:1 ref){colors
|
||||
,./>' ',.~each^:2(cut y),:each edgecolors
|
||||
}}
|
||||
|
||||
task ex1
|
||||
nodes: 4, edges: 4, colours: 3
|
||||
0-1 1-2 2-0 3
|
||||
0:1 1:2 2:0 0:0
|
||||
|
||||
task ex2
|
||||
nodes: 8, edges: 12, colours: 2
|
||||
1-6 1-7 1-8 2-5 2-7 2-8 3-5 3-6 3-8 4-5 4-6 4-7
|
||||
0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1
|
||||
|
||||
task ex3
|
||||
nodes: 8, edges: 12, colours: 2
|
||||
1-4 1-6 1-8 3-2 3-6 3-8 5-2 5-4 5-8 7-2 7-4 7-6
|
||||
0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1 0:1
|
||||
|
||||
task ex4
|
||||
nodes: 8, edges: 12, colours: 2
|
||||
1-6 7-1 8-1 5-2 2-7 2-8 3-5 6-3 3-8 4-5 4-6 4-7
|
||||
0:1 1:0 1:0 1:0 0:1 0:1 0:1 1:0 0:1 0:1 0:1 0:1
|
||||
Loading…
Add table
Add a link
Reference in a new issue