Search in sources :

Example 1 with CoreConstraint

use of org.btrplace.scheduler.CoreConstraint in project scheduler by btrplace.

the class SpecScanner method scan.

/**
 * @throws SpecException
 */
public List<org.btrplace.safeplace.spec.Constraint> scan() throws IllegalAccessException, InstantiationException, IOException {
    List<CoreConstraint> coreAnnots = Collections.synchronizedList(new ArrayList<>());
    List<Class<? extends Function>> funcs = Collections.synchronizedList(new ArrayList<>());
    scanner.matchClassesImplementing(Function.class, funcs::add);
    scanner.matchClassesWithAnnotation(CoreConstraint.class, c -> coreAnnots.add(c.getAnnotation(CoreConstraint.class)));
    scanner.matchClassesWithAnnotation(CoreConstraints.class, c -> {
        CoreConstraint[] x = c.getAnnotationsByType(CoreConstraint.class);
        coreAnnots.addAll(Arrays.asList(x));
    });
    scanner.matchClassesWithAnnotation(SideConstraint.class, c -> sides.add(new Side(c.getAnnotation(SideConstraint.class), (Class<? extends SatConstraint>) c)));
    scanner.scan(Runtime.getRuntime().availableProcessors() - 1);
    for (Class<? extends Function> f : funcs) {
        if (!f.equals(Constraint.class)) {
            functions.add(f.newInstance());
        }
    }
    scanner.matchClassesImplementing(Function.class, c -> {
        try {
            functions.add(c.newInstance());
        } catch (InstantiationException | IllegalAccessException e) {
            throw new IllegalArgumentException(e);
        }
    });
    List<org.btrplace.safeplace.spec.Constraint> cstrs = new ArrayList<>();
    for (CoreConstraint c : coreAnnots) {
        cstrs.add(parseCore2(c));
    }
    List<org.btrplace.safeplace.spec.Constraint> l = new ArrayList<>();
    for (Side s : resolveDependencies(sides)) {
        org.btrplace.safeplace.spec.Constraint c = parseSide(s, l);
        l.add(c);
    }
    cstrs.addAll(l);
    return cstrs;
}
Also used : CoreConstraint(org.btrplace.scheduler.CoreConstraint) SideConstraint(org.btrplace.model.constraint.SideConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) SideConstraint(org.btrplace.model.constraint.SideConstraint) Function(org.btrplace.safeplace.spec.term.func.Function) CoreConstraint(org.btrplace.scheduler.CoreConstraint)

Example 2 with CoreConstraint

use of org.btrplace.scheduler.CoreConstraint 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)

Aggregations

SatConstraint (org.btrplace.model.constraint.SatConstraint)2 SideConstraint (org.btrplace.model.constraint.SideConstraint)2 CoreConstraint (org.btrplace.scheduler.CoreConstraint)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 CstrSpecParser (org.btrplace.safeplace.spec.antlr.CstrSpecParser)1 Proposition (org.btrplace.safeplace.spec.prop.Proposition)1 Function (org.btrplace.safeplace.spec.term.func.Function)1