use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class MaxOnlineBuilder method buildConstraint.
/**
* Build an online constraint.
*
* @param args must be 1 set of nodes. The set must not be empty
* @return a constraint
*/
@Override
public List<MaxOnline> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (checkConformance(t, args)) {
@SuppressWarnings("unchecked") List<Node> ns = (List<Node>) params[0].transform(this, t, args.get(0));
if (ns == null) {
return Collections.emptyList();
}
Set<Node> s = new HashSet<>(ns);
if (s.size() != ns.size()) {
// Prevent duplicates
return Collections.emptyList();
}
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 Collections.singletonList(new MaxOnline(new HashSet<>(ns), v, true));
}
return Collections.emptyList();
}
use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class PreserveBuilder method buildConstraint.
@Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
if (!checkConformance(t, args)) {
return Collections.emptyList();
}
@SuppressWarnings("unchecked") List<VM> s = (List<VM>) params[0].transform(this, t, args.get(0));
String rcId = (String) params[1].transform(this, t, args.get(1));
BtrpNumber n = (BtrpNumber) args.get(2);
if (!n.isInteger()) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects an integer");
return Collections.emptyList();
}
int v = n.getIntValue();
if (v < 0) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects a positive integer (" + v + " given)");
return Collections.emptyList();
}
return s != null && rcId != null ? Preserve.newPreserve(s, rcId, v) : Collections.emptyList();
}
use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class ResourceCapacityBuilder 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));
String rcId = (String) params[1].transform(this, t, args.get(1));
BtrpNumber n = (BtrpNumber) args.get(2);
if (!n.isInteger()) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects an integer");
return Collections.emptyList();
}
int v = n.getIntValue();
if (v < 0) {
t.ignoreError("Parameter '" + params[2].getName() + "' expects a positive integer (" + v + " given)");
return Collections.emptyList();
}
return ns != null ? Collections.singletonList(new ResourceCapacity(new HashSet<>(ns), rcId, v)) : Collections.emptyList();
}
use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class ScriptBuilderTest method testSetManipulation.
public void testSetManipulation() throws ScriptBuilderException {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Script v = b.build(new File(RC_ROOT + "setManip.btrp"));
BtrpSet t1 = (BtrpSet) v.getImportable("$T1");
BtrpSet t2 = (BtrpSet) v.getImportable("$T2");
BtrpSet t3 = (BtrpSet) v.getImportable("$T3");
BtrpNumber x = (BtrpNumber) v.getImportable("$x");
BtrpNumber res = (BtrpNumber) v.getImportable("$res");
BtrpNumber res2 = (BtrpNumber) v.getImportable("$res2");
BtrpNumber res3 = (BtrpNumber) v.getImportable("$res3");
BtrpNumber y = (BtrpNumber) v.getImportable("$y");
Assert.assertEquals(t1.size() + t2.size() + t3.size(), 100);
Assert.assertEquals(x.getIntValue(), 12);
Assert.assertEquals(y.getIntValue(), 3);
BtrpSet C = (BtrpSet) v.getImportable("$C");
Assert.assertEquals(C.size(), 90);
BtrpSet a = (BtrpSet) v.getImportable("$a");
Assert.assertEquals(res, BtrpNumber.TRUE);
Assert.assertEquals(res2, BtrpNumber.TRUE);
Assert.assertEquals(res3, BtrpNumber.TRUE);
Assert.assertEquals(a.degree(), 2);
Assert.assertEquals(a.size(), 4);
}
use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.
the class ScriptBuilderTest method testIfStatement.
public void testIfStatement() {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
try {
Script v = b.build(new File(RC_ROOT + "ifStatement.btrp"));
BtrpNumber first = (BtrpNumber) v.getImportable("$first");
BtrpNumber second = (BtrpNumber) v.getImportable("$second");
BtrpNumber third = (BtrpNumber) v.getImportable("$third");
Assert.assertNotNull(first);
Assert.assertNotNull(second);
Assert.assertEquals(first, BtrpNumber.TRUE);
Assert.assertEquals(second, BtrpNumber.TRUE);
Assert.assertEquals(third.getIntValue(), 5);
} catch (ScriptBuilderException x) {
Assert.fail(x.getMessage(), x);
}
}
Aggregations