Search in sources :

Example 11 with BtrpOperand

use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.

the class DivideOperator 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()) {
        try {
            return l.div(r);
        } catch (ArithmeticException e) {
            return ignoreError(e);
        }
    }
    return IgnorableOperand.getInstance();
}
Also used : BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand)

Example 12 with BtrpOperand

use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.

the class EnumVar method go.

@Override
public BtrpOperand go(BtrPlaceTree parent) {
    String head = getChild(0).getText().substring(0, getChild(0).getText().length() - 1);
    String tail = getChild(getChildCount() - 1).getText().substring(1);
    BtrpSet res = null;
    for (int i = 1; i < getChildCount() - 1; i++) {
        BtrpOperand op = getChild(i).go(this);
        if (op == IgnorableOperand.getInstance()) {
            return op;
        }
        BtrpSet s = (BtrpSet) op;
        for (BtrpOperand o : s.getValues()) {
            // Compose
            String id = head + o.toString() + tail;
            // lookup
            BtrpOperand var = syms.getSymbol(id);
            if (var == null) {
                return ignoreError(parent.getToken(), "Unknown variable '" + id + "'");
            }
            if (res == null) {
                res = new BtrpSet(2, var.type());
            }
            res.getValues().add(var);
        }
    }
    return res;
}
Also used : BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) BtrpSet(org.btrplace.btrpsl.element.BtrpSet) BtrpString(org.btrplace.btrpsl.element.BtrpString)

Example 13 with BtrpOperand

use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.

the class EnumVar method expand.

/**
 * Expand the enumeration.
 * Variables are not evaluated nor checked
 *
 * @return a set of string or an error
 */
public BtrpOperand expand() {
    String head = getChild(0).getText().substring(0, getChild(0).getText().length() - 1);
    String tail = getChild(getChildCount() - 1).getText().substring(1);
    BtrpSet res = new BtrpSet(1, BtrpOperand.Type.STRING);
    for (int i = 1; i < getChildCount() - 1; i++) {
        BtrpOperand op = getChild(i).go(this);
        if (op == IgnorableOperand.getInstance()) {
            return op;
        }
        BtrpSet s = (BtrpSet) op;
        for (BtrpOperand o : s.getValues()) {
            // Compose
            res.getValues().add(new BtrpString(head + o.toString() + tail));
        }
    }
    return res;
}
Also used : BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) BtrpSet(org.btrplace.btrpsl.element.BtrpSet) BtrpString(org.btrplace.btrpsl.element.BtrpString) BtrpString(org.btrplace.btrpsl.element.BtrpString)

Example 14 with BtrpOperand

use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.

the class EqComparisonOperator method go.

@Override
public BtrpOperand go(BtrPlaceTree parent) {
    BtrpOperand l = getChild(0).go(this);
    BtrpOperand r = getChild(1).go(this);
    if (!opposite) {
        return l.eq(r);
    }
    return l.eq(r).not();
}
Also used : BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand)

Example 15 with BtrpOperand

use of org.btrplace.btrpsl.element.BtrpOperand in project scheduler by btrplace.

the class ExplodedSetTree method go.

@Override
public BtrpOperand go(BtrPlaceTree parent) {
    if (getChildCount() == 0) {
        return ignoreError("Empty sets not allowed");
    }
    BtrpOperand t0 = getChild(0).go(this);
    if (t0 == IgnorableOperand.getInstance()) {
        return t0;
    }
    BtrpSet s = new BtrpSet(t0.degree() + 1, t0.type());
    Set<BtrpOperand> viewed = new HashSet<>();
    for (int i = 0; i < getChildCount(); i++) {
        BtrpOperand tx = getChild(i).go(this);
        // s.getIntValue().add() is not safe at all. So preconditions have to be check
        if (tx == IgnorableOperand.getInstance()) {
            return tx;
        }
        if (tx.degree() != s.degree() - 1) {
            return ignoreError(tx + " has type '" + tx.prettyType() + "'. It should be a '" + DefaultBtrpOperand.prettyType(s.degree() - 1, s.type()) + "' to be insertable into a '" + s.prettyType() + "'");
        }
        if (tx.type() != s.type()) {
            return ignoreError("Unable to add '" + tx.type() + "' elements in a set of '" + s.type() + "' elements");
        }
        if (viewed.add(tx)) {
            s.getValues().add(tx);
        } else {
            return ignoreError(tx + " ignored");
        }
    }
    return s;
}
Also used : DefaultBtrpOperand(org.btrplace.btrpsl.element.DefaultBtrpOperand) BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) BtrpSet(org.btrplace.btrpsl.element.BtrpSet) HashSet(java.util.HashSet)

Aggregations

BtrpOperand (org.btrplace.btrpsl.element.BtrpOperand)22 BtrpSet (org.btrplace.btrpsl.element.BtrpSet)8 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BtrpString (org.btrplace.btrpsl.element.BtrpString)2 DefaultBtrpOperand (org.btrplace.btrpsl.element.DefaultBtrpOperand)2 Script (org.btrplace.btrpsl.Script)1 ScriptBuilderException (org.btrplace.btrpsl.ScriptBuilderException)1 SatConstraintBuilder (org.btrplace.btrpsl.constraint.SatConstraintBuilder)1 BtrpElement (org.btrplace.btrpsl.element.BtrpElement)1 BtrpNumber (org.btrplace.btrpsl.element.BtrpNumber)1 DefaultModel (org.btrplace.model.DefaultModel)1 Model (org.btrplace.model.Model)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1