Search in sources :

Example 11 with BtrpNumber

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();
}
Also used : RunningCapacity(org.btrplace.model.constraint.RunningCapacity) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) Node(org.btrplace.model.Node) List(java.util.List) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 12 with BtrpNumber

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);
}
Also used : BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber)

Example 13 with BtrpNumber

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);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) File(java.io.File)

Aggregations

BtrpNumber (org.btrplace.btrpsl.element.BtrpNumber)13 File (java.io.File)4 List (java.util.List)4 DefaultModel (org.btrplace.model.DefaultModel)4 Node (org.btrplace.model.Node)3 SatConstraint (org.btrplace.model.constraint.SatConstraint)3 HashSet (java.util.HashSet)1 BtrpOperand (org.btrplace.btrpsl.element.BtrpOperand)1 BtrpSet (org.btrplace.btrpsl.element.BtrpSet)1 VM (org.btrplace.model.VM)1 MaxOnline (org.btrplace.model.constraint.MaxOnline)1 ResourceCapacity (org.btrplace.model.constraint.ResourceCapacity)1 RunningCapacity (org.btrplace.model.constraint.RunningCapacity)1