-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
265 lines (230 loc) · 6.84 KB
/
demo.html
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>N Queens SAT</title>
<link rel="stylesheet" href="minisat/styles.css">
</head>
<body>
<script src="js/solver.js"></script>
<div id="outer">
<div class="mynav bg-dark minirow">
<ul class="myul">
<li><a class="nav-link myelem" href="#">CryptoMiniSat</a></li>
<li><button type="button" id="save" class="btn btn-primary btn-md myelem" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Copied to clipboard" aria-label="Copy to Clipboard" disabled>
<i class="fas fa-paste" aria-hidden="true"></i>
</button></li>
<li style="float:right;">
<span style="width:10px;"></span>
<button type="button" id="runbutton" class="btn btn-primary myelem" disabled>
<i id="playbut" class="fas fa-play" aria-hidden="true"></i>
</button>
</li>
<li style="float:right;">
<div class="myelem" id="result">Loading</div>
</li>
</ul>
</div>
<div id="inner"><div id="wrapper">
<div id="outputdiv" class="row"><textarea id="editor" spellcheck="false"></textarea></div>
<div id="outputdiv" class="row"><textarea id="output" readOnly="true" spellcheck="false">CryptoMiniSat Output
---------------
</textarea></div>
</div></div>
</div>
<!-- Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- FontAwesome -->
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<!-- Default Statcounter code for cyrptominisat_web
http://msoos.github.io/cryptominisat_web/ -->
<script type="text/javascript">
var sc_project=11721099;
var sc_invisible=1;
var sc_security="7e859659";
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js"
async></script>
<noscript><div class="statcounter"><a title="Web Analytics"
href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="//c.statcounter.com/11721099/0/7e859659/1/" alt="Web
Analytics"></a></div></noscript>
<!-- End of Statcounter Code -->
<script>
function base64dec(x) {
try {
if (x.length % 4 != 0) {
x = x.padEnd(x.length + (4 - (x.length % 4)), '=')
}
return atob(x.replace(/-/g, '+').replace(/_/g, '/'))
} catch (err) {
return ''
}
}
function base64enc(x) {
return btoa(x).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g,'')
}
function copyToClipboard(x) {
// Create an invisible text area
var target = $('<textarea>')
.css('position', 'absolute')
.css('left', '-9999px')
.css('top', '0px')
.val(x)
$('body').append(target);
// Copy the contents
target.focus()
target[0].setSelectionRange(0, x.length)
document.execCommand('copy')
// Remove it from the page
target.remove()
}
$().ready(function () {
// Load text from the URL hash if it's there
if (window.location.hash) {
var hash = window.location.hash.substring(1);
$('#editor').val(base64dec(hash));
$('#save').removeAttr('disabled');
} else {
$.ajax({
url : "minisat/test.cnf",
dataType: "text",
success : function (data) {
$('#editor').val(sat(5));
$('#save').removeAttr('disabled');
}
});
}
// Clear the hash whenever the code is updated
editor.session.on('change', function () {
window.location.hash = '';
})
// Save button implementation
$('#save').click(function () {
// Push a new history item and change the URL
window.location.hash = '';
history.pushState(
{ 'source': editor.getValue() },
'', // title
window.location.href.replace(/#$/, '') + '#' + base64enc(editor.getValue())
)
// Copy the URL to the clipboard
copyToClipboard(window.location.href);
// Show and hide the popover as a visual indication
var x = this;
$(this).popover('show');
setTimeout(function() {
$(x).popover('hide');
}, 700);
})
})
</script>
<script src="minisat/cryptominisat5_simple.js" type="text/javascript" charset="utf-8"></script>
<script>
function scroll() {
document.getElementById("output").scrollTop = document.getElementById("output").scrollHeight;
}
function at_bottom() {
var height = document.getElementById("output").offsetHeight;
return (document.getElementById("output").scrollTop+height) >= document.getElementById("output").scrollHeight;
}
Module['onRuntimeInitialized'] = function () {
$().ready(function () {
$('#runbutton').removeAttr("disabled")
$('#result').text('Ready');
})
}
Module['print'] = function(text) {
var bottom = at_bottom();
$('#output').append(text+"\n")
if (bottom) {
scroll();
}
};
Module['printErr'] = function(text) {
$('#output').append("--error-- " + text+"\n")
scroll();
};
must_stop = false;
running = false;
function check_result(result) {
if (must_stop) {
$('#output').append("Stopped.\n")
$('#result').text('Ready');
$('#playbut').removeClass("fa-stop");
$('#playbut').addClass("fa-play");
scroll();
must_stop = false;
running = false;
return;
}
var nconfl = num_conflicts();
$('#result').text(nconfl + " confl");
if (result == 0) {
$('#result').text('SAT');
running = false;
} else if (result == 1) {
$('#result').text('UNSAT');
running = false;
} else if (result == 2) {
window.setTimeout(function(){
var result = cont_query();
check_result(result);
}, 50);
}
if (!running) {
$('#playbut').removeClass("fa-stop");
$('#playbut').addClass("fa-play");
}
}
$().ready(function () {
$('#runbutton').click(function () {
if (running) {
must_stop = true;
$('#output').append("Stopping...\n")
scroll();
return;
}
running = true;
$('#playbut').removeClass("fa-play");
$('#playbut').addClass("fa-stop");
$('#result').text('Running');
var source = $('#editor').val();
try {
var result = cms_query(source)
check_result(result);
} catch (err) {
console.log(result);
console.log(err);
running = false;
must_stop =false;
$('#result').text('Error');
}
})
})
</script>
<script>
function cms_query(source) {
$('#output').html("");
scroll();
var solve_function = Module.cwrap('cstart_solve', 'number', ['string']);
ret = solve_function(source);
return ret;
}
function cont_query() {
var cont_function = Module.cwrap('ccontinue_solve', 'number');
ret = cont_function();
return ret;
}
function num_conflicts() {
var num_conflicts_function = Module.cwrap('cget_num_conflicts', 'number');
ret = num_conflicts_function();
return ret;
}
</script>
</body>
</html>