-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclingon.js
74 lines (58 loc) · 2.05 KB
/
clingon.js
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
/*
* clingon
*
* A module to interface with clingo.js
* Author: Melanie Dickinson
* Based on code by Adam Smith, Kate Compton, and potassco.org
* January 2019
*
* Requires jQuery
*/
var clingon = (function () {
/*
* Load ASP from a given .lp file and send its contents to a given callback function.
* The given callback function must take a parameter for the code (the plaintext) of the loaded file.
*/
function loadASP (filename, callback) {
$.ajax({
url: filename,
success: function (text) {
// If file was successfully retreived, call the callback function with the code
callback (text);
},
error: function() {
// Could not load file
},
});
}
/*
* Takes an Answer Set Program to solve and a callback function to call when it's done
*/
function groundAndSolve (code, callback) {
var numSolutions = 3; // Max number of solutions to find (0 for all)
console.log(code)
var width = 10;
var grounderArgs = [];//["-c", "width=" + width];
var solverArgs = ["3", "--outf=2"];//, "--sign-def=3", "--heu=vsids", "--seed=" + (2 << 30 * Math.random() | 0)];
console.log("grounding...");
Gringo.groundAsync([code, grounderArgs], function(program) {
console.log("solving...");
Clasp.solveAsync([program, solverArgs], function(result) {
// Give the result back to the given callback function to deal with
callback(result);
//console.log("done " + result.Witnesses.length);
/*
if (result.Witnesses) {
console.log(result.Witnesses);
//callback(processedSets);
} else {
console.warn ("no solutions");
}*/
});
});
};
return {
loadASP : loadASP,
groundAndSolve : groundAndSolve
}
})();