Search in sources :

Example 6 with UserVar

use of org.btrplace.safeplace.spec.term.UserVar in project scheduler by btrplace.

the class MyCstrSpecVisitor method visitSetInComprehension.

@Override
public SetBuilder<?> visitSetInComprehension(@NotNull CstrSpecParser.SetInComprehensionContext ctx) {
    // Get the binder
    List<UserVar<?>> v = visitTypedef(ctx.typedef());
    Proposition p = Proposition.True;
    if (ctx.COMMA() != null) {
        p = (Proposition) visit(ctx.formula());
    }
    Term<?> t = (Term<?>) visit(ctx.term());
    return new SetBuilder<>(t, v.get(0), p);
}
Also used : Term(org.btrplace.safeplace.spec.term.Term) ProtectedTerm(org.btrplace.safeplace.spec.term.ProtectedTerm) Proposition(org.btrplace.safeplace.spec.prop.Proposition) ProtectedProposition(org.btrplace.safeplace.spec.prop.ProtectedProposition) SetBuilder(org.btrplace.safeplace.spec.term.SetBuilder) UserVar(org.btrplace.safeplace.spec.term.UserVar)

Example 7 with UserVar

use of org.btrplace.safeplace.spec.term.UserVar in project scheduler by btrplace.

the class SpecScanner method makeArgs.

/**
 * @throws SpecException
 */
private List<UserVar<?>> makeArgs(String cl, String[] strings) throws IOException {
    List<UserVar<?>> args = new ArrayList<>();
    for (String arg : strings) {
        CstrSpecParser parser = new CstrSpecParser(getTokens(arg));
        ParseTree tree = parser.typedef();
        MyCstrSpecVisitor v = new MyCstrSpecVisitor().library(functions);
        args.add(v.getUserVar(cl, tree));
    }
    return args;
}
Also used : CstrSpecParser(org.btrplace.safeplace.spec.antlr.CstrSpecParser) ArrayList(java.util.ArrayList) ParseTree(org.antlr.v4.runtime.tree.ParseTree) UserVar(org.btrplace.safeplace.spec.term.UserVar)

Example 8 with UserVar

use of org.btrplace.safeplace.spec.term.UserVar in project scheduler by btrplace.

the class SpecScanner method parseSide.

/**
 * @throws SpecException
 */
private 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 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)

Example 9 with UserVar

use of org.btrplace.safeplace.spec.term.UserVar in project scheduler by btrplace.

the class Constraint method eval.

@Override
public Boolean eval(Context mo, Object... values) {
    for (int i = 0; i < this.args.size(); i++) {
        UserVar v = this.args.get(i);
        mo.setValue(v.label(), values[i]);
    }
    return proposition().eval(mo);
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) UserVar(org.btrplace.safeplace.spec.term.UserVar)

Aggregations

UserVar (org.btrplace.safeplace.spec.term.UserVar)9 Proposition (org.btrplace.safeplace.spec.prop.Proposition)5 ProtectedProposition (org.btrplace.safeplace.spec.prop.ProtectedProposition)4 ProtectedTerm (org.btrplace.safeplace.spec.term.ProtectedTerm)3 Term (org.btrplace.safeplace.spec.term.Term)3 ArrayList (java.util.ArrayList)2 ParseTree (org.antlr.v4.runtime.tree.ParseTree)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 CstrSpecParser (org.btrplace.safeplace.spec.antlr.CstrSpecParser)2 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)1 SideConstraint (org.btrplace.model.constraint.SideConstraint)1 Exists (org.btrplace.safeplace.spec.prop.Exists)1 ForAll (org.btrplace.safeplace.spec.prop.ForAll)1 ListBuilder (org.btrplace.safeplace.spec.term.ListBuilder)1 SetBuilder (org.btrplace.safeplace.spec.term.SetBuilder)1 Var (org.btrplace.safeplace.spec.term.Var)1 Atomic (org.btrplace.safeplace.spec.type.Atomic)1 CoreConstraint (org.btrplace.scheduler.CoreConstraint)1