Search in sources :

Example 1 with Proposition

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");
}
Also used : Model(org.btrplace.model.Model) Proposition(org.btrplace.safeplace.spec.prop.Proposition) Constraint(org.btrplace.safeplace.spec.Constraint)

Example 2 with Proposition

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);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CoreConstraint(org.btrplace.scheduler.CoreConstraint) SideConstraint(org.btrplace.model.constraint.SideConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) CstrSpecParser(org.btrplace.safeplace.spec.antlr.CstrSpecParser) Proposition(org.btrplace.safeplace.spec.prop.Proposition) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 3 with Proposition

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;
}
Also used : Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) BootVM(org.btrplace.plan.event.BootVM) ArrayList(java.util.ArrayList) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) ShutdownVM(org.btrplace.plan.event.ShutdownVM) NodeStateType(org.btrplace.safeplace.spec.type.NodeStateType) Map(java.util.Map) SuspendVM(org.btrplace.plan.event.SuspendVM) ActionVisitor(org.btrplace.plan.event.ActionVisitor) ResumeVM(org.btrplace.plan.event.ResumeVM) Set(java.util.Set) Collectors(java.util.stream.Collectors) BootNode(org.btrplace.plan.event.BootNode) AllocateEvent(org.btrplace.plan.event.AllocateEvent) List(java.util.List) Proposition(org.btrplace.safeplace.spec.prop.Proposition) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Allocate(org.btrplace.plan.event.Allocate) VMStateType(org.btrplace.safeplace.spec.type.VMStateType) Action(org.btrplace.plan.event.Action) ForgeVM(org.btrplace.plan.event.ForgeVM) Comparator(java.util.Comparator) KillVM(org.btrplace.plan.event.KillVM) Action(org.btrplace.plan.event.Action) TreeSet(java.util.TreeSet)

Example 4 with Proposition

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);
}
Also used : CoreConstraint(org.btrplace.scheduler.CoreConstraint) SideConstraint(org.btrplace.model.constraint.SideConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) CstrSpecParser(org.btrplace.safeplace.spec.antlr.CstrSpecParser) Proposition(org.btrplace.safeplace.spec.prop.Proposition) ParseTree(org.antlr.v4.runtime.tree.ParseTree) UserVar(org.btrplace.safeplace.spec.term.UserVar)

Aggregations

Proposition (org.btrplace.safeplace.spec.prop.Proposition)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 SideConstraint (org.btrplace.model.constraint.SideConstraint)2 CstrSpecParser (org.btrplace.safeplace.spec.antlr.CstrSpecParser)2 CoreConstraint (org.btrplace.scheduler.CoreConstraint)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Collectors (java.util.stream.Collectors)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 Model (org.btrplace.model.Model)1 Node (org.btrplace.model.Node)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1 Action (org.btrplace.plan.event.Action)1 ActionVisitor (org.btrplace.plan.event.ActionVisitor)1