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;
}
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);
}
Aggregations