-
Notifications
You must be signed in to change notification settings - Fork 11
/
dijkstra.nl
90 lines (71 loc) · 1.81 KB
/
dijkstra.nl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var min = 0;
var argmin = 0;
var p_out = 0;
var p_out_temp = 0;
var p_in = 1;
var p_in_temp = 1;
var nnodes = 0;
var zero = 0;
var big = 99;
var tmp_node = 0;
var tmp_weight = 0;
var tmp_current = 0;
var tmp = 0;
var didsmth = 0;
p_out = READ(p_out);
p_out_temp = ADD(p_out, zero);
tmp_current = INC(zero);
loop_nnodes:tmp = READ(p_in_temp);
JEZ(tmp, found_nnodes);
WRITE(p_out_temp, big);
p_out_temp = INC(p_out_temp);
WRITE(p_out_temp, tmp_current);
p_out_temp = INC(p_out_temp);
p_in_temp = INC(p_in_temp);
nnodes = INC(nnodes);
JEZ(zero, loop_nnodes);
found_nnodes:WRITE(p_out, zero);
JEZ(zero, find_min);
min_return:p_in_temp = ADD(p_in, argmin);
p_in_temp = READ(p_in_temp);
loop_sons:tmp_node = READ(p_in_temp);
JEZ(tmp_node, find_min);
tmp_node = DEC(tmp_node);
p_in_temp = INC(p_in_temp);
tmp_weight = READ(p_in_temp);
p_in_temp = INC(p_in_temp);
p_out_temp = ADD(p_out, tmp_node);
p_out_temp = ADD(p_out_temp, tmp_node);
tmp_current = READ(p_out_temp);
tmp_weight = ADD(min, tmp_weight);
tmp = MIN(tmp_current, tmp_weight);
tmp = SUB(tmp_current, tmp);
JEZ(tmp, loop_sons);
WRITE(p_out_temp, tmp_weight);
JEZ(zero, loop_sons);
find_min:p_out_temp = DEC(p_out);
tmp_node = DEC(zero);
min = ADD(big, zero);
argmin = DEC(zero);
loop_min:p_out_temp = INC(p_out_temp);
tmp_node = INC(tmp_node);
tmp = SUB(tmp_node, nnodes);
JEZ(tmp, min_found);
tmp_weight = READ(p_out_temp);
p_out_temp = INC(p_out_temp);
tmp = READ(p_out_temp);
JEZ(tmp, loop_min);
tmp = MAX(min, tmp_weight);
tmp = SUB(tmp, tmp_weight);
JEZ(tmp, loop_min);
min = ADD(tmp_weight, zero);
argmin = ADD(tmp_node, zero);
JEZ(zero, loop_min);
min_found:tmp = SUB(min, big);
JEZ(tmp, end_of_prog);
p_out_temp = ADD(p_out, argmin);
p_out_temp = ADD(p_out_temp, argmin);
p_out_temp = INC(p_out_temp);
WRITE(p_out_temp, zero);
JEZ(zero, min_return);
end_of_prog:STOP();