forked from gsdlab/chocosolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidate.java
62 lines (52 loc) · 2.41 KB
/
Validate.java
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
package org.clafer.cli;
import java.io.File;
import java.io.PrintStream;
import joptsimple.OptionSet;
import org.clafer.assertion.Assertion;
import org.clafer.compiler.ClaferAsserter;
import org.clafer.compiler.ClaferCompiler;
import org.clafer.compiler.ClaferOption;
import org.clafer.compiler.ClaferSearchStrategy;
import org.clafer.instance.InstanceClafer;
import org.clafer.instance.InstanceModel;
import org.clafer.javascript.JavascriptFile;
import org.clafer.scope.Scope;
public class Validate {
public static void runValidate(File inputFile, JavascriptFile javascriptFile, OptionSet options, PrintStream outStream) throws Exception {
//----------------------------------------
// Running the model itself(instantiating)
//----------------------------------------
Assertion[] assertions = javascriptFile.getAssertions();
// no assertions means the model is valid
if (assertions.length == 0)
return;
// handle scopes
Scope scope = Utils.resolveScopes(javascriptFile, options);
// handle search strategy
ClaferOption compilerOption = ClaferOption.Default;
if (options.has("search")) {
compilerOption = compilerOption.setStrategy((ClaferSearchStrategy) options.valueOf("search"));
}
ClaferAsserter solver = ClaferCompiler.compile(javascriptFile.getModel(), scope, assertions, javascriptFile.getOption());
int index = 0; // optimal instance id
boolean prettify = options.has("prettify");
while (solver.find()) {
System.out.println("Failed assertion(s):");
for (Assertion failedAssertion : solver.failedAssertions())
System.out.println(" " + failedAssertion);
outStream.println("\n=== Counterexample " + (++index) + " Begin ===\n");
InstanceModel instance = solver.instance();
if (prettify)
instance.print(outStream);
else {
for (InstanceClafer c : instance.getTopClafers())
Utils.printClafer(c, outStream);
}
outStream.println("\n--- Counterexample " + (index) + " End ---\n");
}
if (index == 0)
System.out.println("No counterexamples found within the scope. All assertions may hold.");
else
System.out.println("Generated all " + index + " counterexample(s) within the scope\n");
}
}