use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class RunningCapacityBuilder method buildConstraint.
@Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (!checkConformance(t, args)) {
return Collections.emptyList();
}
@SuppressWarnings("unchecked") List<Node> ns = (List<Node>) params[0].transform(this, t, args.get(0));
BtrpNumber n = (BtrpNumber) args.get(1);
if (!n.isInteger()) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects an integer");
return Collections.emptyList();
}
int v = n.getIntValue();
if (v < 0) {
t.ignoreError("Parameter '" + params[1].getName() + "' expects a positive integer (" + v + " given)");
return Collections.emptyList();
}
return ns != null ? Collections.singletonList(new RunningCapacity(new HashSet<>(ns), v)) : Collections.emptyList();
}
use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class BooleanBinaryOperation method go.
@Override
public BtrpOperand go(BtrPlaceTree parent) {
BtrpOperand l = getChild(0).go(this);
BtrpOperand r = getChild(1).go(this);
if (l == IgnorableOperand.getInstance() || r == IgnorableOperand.getInstance()) {
return IgnorableOperand.getInstance();
}
if (!(l instanceof BtrpNumber)) {
return ignoreError("Expression expected, but was '" + l + "'");
}
if (!(r instanceof BtrpNumber)) {
return ignoreError("Expression expected, but was '" + r + "'");
}
boolean b1 = BtrpNumber.TRUE.equals(l);
boolean b2 = BtrpNumber.TRUE.equals(r);
return eval(b1, b2);
}
use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class ScriptBuilderTest method testLogical.
public void testLogical() {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
try {
Script v = b.build(new File(RC_ROOT + "logical.btrp"));
BtrpNumber and1 = (BtrpNumber) v.getImportable("$and1");
BtrpNumber and2 = (BtrpNumber) v.getImportable("$and2");
BtrpNumber and3 = (BtrpNumber) v.getImportable("$and3");
BtrpNumber and4 = (BtrpNumber) v.getImportable("$and4");
BtrpNumber or1 = (BtrpNumber) v.getImportable("$or1");
BtrpNumber or2 = (BtrpNumber) v.getImportable("$or2");
BtrpNumber or3 = (BtrpNumber) v.getImportable("$or3");
BtrpNumber or4 = (BtrpNumber) v.getImportable("$or4");
Assert.assertEquals(and1, BtrpNumber.FALSE);
Assert.assertEquals(and2, BtrpNumber.FALSE);
Assert.assertEquals(and3, BtrpNumber.FALSE);
Assert.assertEquals(and4, BtrpNumber.TRUE);
Assert.assertEquals(or1, BtrpNumber.TRUE);
Assert.assertEquals(or2, BtrpNumber.TRUE);
Assert.assertEquals(or3, BtrpNumber.TRUE);
Assert.assertEquals(or4, BtrpNumber.FALSE);
BtrpNumber h1 = (BtrpNumber) v.getImportable("$h1");
BtrpNumber h2 = (BtrpNumber) v.getImportable("$h2");
Assert.assertEquals(h1, BtrpNumber.TRUE);
Assert.assertEquals(h2, BtrpNumber.TRUE);
} catch (ScriptBuilderException x) {
Assert.fail(x.getMessage(), x);
}
}
Aggregations