-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
235 lines (192 loc) · 7.43 KB
/
index.html
File metadata and controls
235 lines (192 loc) · 7.43 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width=device-width, initial-scale=1.0">
<title>Zerofy's Prime Path Coverage Tool</title>
<script src = "https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.js"></script>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
}
textarea {
width: 100%;
height: 300px;
padding: 10px;
font-family: monospace;
font-size: 14px;
margin: 10px 0;
box-sizing: border-box;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
.compute-btn {
background-color: #52b1f9;
}
.compute-btn:hover {
background-color: #0290fc;
}
.inactive-btn {
background-color: #f96652;
}
.inactive-btn:hover {
background-color: #fc0202;
}
#output {
margin-top: 20px;
white-space: pre-wrap;
font-family: monospace;
background: #f5f5f5;
padding: 15px;
border-radius: 4px;
display: none;
}
#feedback {
margin: 20px 0;
color: #666;
}
code {
background-color: #f5f5f5;
color: #fc0f02;
padding: 0.2em 0.4em;
border-radius: 4px;
font-size: 0.95em;
}
</style>
</head>
<body>
<h1>Zerofy's Graph Coverage Tool</h1>
<p>
Enter graph information in the box below using one of the following formats:<br>
<b>1.</b> Each line represents a directed edge between two nodes separated with a space ( <code>node1 node2</code> ).<br>
<b>2.</b> Each line represents a node and all of its neighbors separated with spaces ( <code>node1 nb1 nb2 ...</code> ).<br>
Lines starting with <code>#</code> are ignored.
</p>
<span><u><b>The algorithm assumes the input is a directed graph.</b></u></span>
<textarea id = "graph_input" placeholder = "Example Input 1:
1 2
2 3
2 4
3 2
Example Input 2:
1 2
2 3 4
3 2
4
Both examples represent the same graph with:
* 4 nodes (1, 2, 3, 4)
* 4 directed edges (1->2, 2->3, 2->4, 3->2)"></textarea>
<button class = "compute-btn" onclick = "compute_prime_paths()">Compute Prime Paths</button>
<button class = "compute-btn" onclick = "compute_edge_pairs()">Compute Edge Pairs</button>
<button class = "inactive-btn" onclick = "generate_tests()">Generate Tests</button>
<p></p>
<div id = "feedback"></div>
<div id = "output"></div>
<script>
let pyodide = null;
const output = document.getElementById('output');
const feedback = document.getElementById('feedback');
async function load_python_script() {
if (!pyodide) {
feedback.textContent = '🐍 Loading Python environment...';
pyodide = await loadPyodide();
const response = await fetch('graph_coverage.py');
const ppc_code = await response.text();
await pyodide.runPythonAsync(ppc_code);
}
}
async function parse_input() {
output.style.display = 'none';
let input = document.getElementById('graph_input').value;
if (!input.trim()) {
alert('Please enter a graph.');
return;
}
feedback.textContent = '🔍 Parsing input...';
pyodide.globals.set('graph_input', input);
const graph = await pyodide.runPythonAsync(`
parse_graph(graph_input)
`);
return graph;
}
async function compute_prime_paths() {
try {
await load_python_script();
let graph = await parse_input();
feedback.textContent = '🤔 Computing prime paths...';
pyodide.globals.set('graph', graph)
let state = await pyodide.runPythonAsync(`
init_computation_state(graph)
`)
while (true) {
pyodide.globals.set('state', state);
state = await pyodide.runPythonAsync(`
_step_prime_paths(state, 10000)
`)
const progress = state.get('progress');
if (progress === 'computed') {
break;
}
feedback.textContent = '🤔 ' + progress;
}
feedback.textContent = '🧹 Removing sub-paths from ' + state.get('paths').length + ' potential prime paths...';
pyodide.globals.set('state', state);
state = await pyodide.runPythonAsync(`
_cleanup_prime_paths(state)
`);
const output_paths = state.get('paths');
pyodide.globals.set('output_paths', output_paths);
output.textContent = await pyodide.runPythonAsync(`format_output(output_paths)`);
output.style.display = 'block';
feedback.textContent = '✅ Found a total of ' + state.get('paths').length + ' prime paths in ' + state.get('iteration') + ' iterations.';
} catch (error) {
output.textContent = 'Error: ' + error.message;
feedback.textContent = '❌ An error occurred while computing prime paths.';
} finally {
output.style.display = 'block';
}
}
async function compute_edge_pairs() {
try {
await load_python_script();
let graph = await parse_input();
feedback.textContent = '🤔 Computing edge pairs...';
pyodide.globals.set('graph', graph)
let state = await pyodide.runPythonAsync(`
init_computation_state(graph)
`)
while (true) {
pyodide.globals.set('state', state);
state = await pyodide.runPythonAsync(`
_step_edge_pairs(state, 10000)
`)
const progress = state.get('progress');
if (progress === 'computed') {
break;
}
feedback.textContent = '🤔 ' + progress;
}
const output_paths = state.get('paths');
pyodide.globals.set('output_paths', output_paths);
output.textContent = await pyodide.runPythonAsync(`format_output(output_paths)`);
output.style.display = 'block';
feedback.textContent = '✅ Found a total of ' + state.get('paths').length + ' edge pairs in ' + state.get('iteration') + ' iterations.';
} catch (error) {
output.textContent = 'Error: ' + error.message;
feedback.textContent = '❌ An error occurred while computing prime paths.';
} finally {
output.style.display = 'block';
}
}
async function generate_tests() {
alert('Tests generation coming soon.');
}
</script>
</body>
</html>