use of org.btrplace.safeplace.spec.prop.Proposition in project scheduler by btrplace.
the class SpecVerifier method verify.
@Override
public VerifierResult verify(TestCase tc) {
Proposition good = tc.constraint().proposition();
if (tc.continuous()) {
Context mo = new Context(tc.instance().getModel());
mo.setRootContext(new Context(tc.instance().getModel().copy()));
fillArguments(mo, tc);
Boolean res = good.eval(mo);
if (!Boolean.TRUE.equals(res)) {
return VerifierResult.newKo("Failure at the initial stage");
}
ReconfigurationSimulator sim = new ReconfigurationSimulator(mo, tc.plan());
int x = sim.start(good);
if (x >= 0) {
return VerifierResult.newKo("Failure at time '" + x + "'");
}
return VerifierResult.newOk();
}
// DISCRETE
Model res = tc.plan().getResult();
if (res == null) {
throw new IllegalStateException("no destination model");
}
Context mo = new Context(res);
mo.setRootContext(new Context(tc.instance().getModel().copy()));
fillArguments(mo, tc);
Boolean bOk = good.eval(mo);
if (bOk == null) {
return VerifierResult.newError(new Exception("Runtime error in the spec"));
}
if (bOk) {
return VerifierResult.newOk();
}
return VerifierResult.newKo("Unconsistent destination model");
}
use of org.btrplace.safeplace.spec.prop.Proposition in project scheduler by btrplace.
the class SpecScanner method parseCore2.
/**
* @throws SpecException
*/
private Constraint parseCore2(CoreConstraint core) throws IOException {
CommonTokenStream tokens = getTokens(core.inv());
CstrSpecParser parser = new CstrSpecParser(tokens);
ParseTree tree = parser.formula();
MyCstrSpecVisitor v = new MyCstrSpecVisitor().library(functions);
Proposition p = v.getProposition(core.name(), tree);
return new Constraint(core.name(), p);
}
use of org.btrplace.safeplace.spec.prop.Proposition in project scheduler by btrplace.
the class ReconfigurationSimulator method start.
/**
* Evaluate the proposition over a reconfiguration, at any timestamp.
* @param prop the proposition to evaluate
* @return the moment the proposition is not valid. {@code -1} if the proposition is correct
*/
public int start(Proposition prop) {
// sort actions by timestamp
Set<Integer> s = new TreeSet<>(Comparator.comparingInt(a -> a));
for (Action a : p.getActions()) {
s.add(a.getStart());
s.add(a.getEnd());
if (!starts.containsKey(a.getStart())) {
starts.put(a.getStart(), new ArrayList<>());
}
if (!ends.containsKey(a.getEnd())) {
ends.put(a.getEnd(), new ArrayList<>());
}
starts.get(a.getStart()).add(a);
ends.get(a.getEnd()).add(a);
}
timeStamps = s.stream().collect(Collectors.toList());
for (Integer i : timeStamps) {
List<Action> st = starts.get(i);
if (st == null) {
st = new ArrayList<>();
}
List<Action> ed = ends.get(i);
if (ed == null) {
ed = new ArrayList<>();
}
at(st, ed);
Boolean res = prop.eval(co);
if (!Boolean.TRUE.equals(res)) {
return i;
}
}
return -1;
}
use of org.btrplace.safeplace.spec.prop.Proposition in project scheduler by btrplace.
the class SpecScanner method parseSide.
/**
* @throws SpecException
*/
private org.btrplace.safeplace.spec.Constraint parseSide(Side s, List<Constraint> known) throws IOException {
List<UserVar<?>> args = makeArgs(s.impl.getSimpleName(), s.s.args());
CstrSpecParser parser = new CstrSpecParser(getTokens(s.s.inv()));
ParseTree tree = parser.formula();
MyCstrSpecVisitor v = new MyCstrSpecVisitor().library(functions).args(args).constraints(known);
Proposition p = v.getProposition(s.impl.getSimpleName(), tree);
return new org.btrplace.safeplace.spec.Constraint(s.impl.getSimpleName(), p).args(args).impl(s.impl);
}
Aggregations