use of org.btrplace.btrpsl.constraint.SatConstraintBuilder in project scheduler by btrplace.
the class ConstraintStatement method go.
/**
* Build the constraint.
* The constraint is built if it exists in the catalog and if the parameters
* are compatible with the constraint signature.
*
* @param parent the parent of the root
* @return {@code Content.empty} if the constraint is successfully built.
* {@code Content.ignore} if an error occurred (the error is already reported)
*/
@Override
public BtrpOperand go(BtrPlaceTree parent) {
String cname = getText();
if (catalog == null) {
return ignoreError("No constraints available");
}
SatConstraintBuilder b = catalog.getConstraint(cname);
if (b == null) {
ignoreError("Unknown constraint '" + cname + "'");
}
// Get the params
int i = 0;
boolean discrete = false;
if (">>".equals(getChild(0).getText())) {
i = 1;
discrete = true;
}
List<BtrpOperand> params = new ArrayList<>();
for (; i < getChildCount(); i++) {
params.add(getChild(i).go(this));
}
if (b != null) {
List<? extends SatConstraint> constraints = b.buildConstraint(this, params);
for (SatConstraint c : constraints) {
if (c != null) {
if (discrete) {
if (!c.setContinuous(false)) {
return ignoreError("Discrete restriction is not supported by constraint '" + cname + "'");
}
} else {
// force the continuous mode, if available
c.setContinuous(true);
}
script.addConstraint(c);
}
}
}
return IgnorableOperand.getInstance();
}
Aggregations