Search in sources :

Example 76 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint 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 77 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint 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();
}
Also used : BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) SatConstraintBuilder(org.btrplace.btrpsl.constraint.SatConstraintBuilder) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 78 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class ScriptBuilderTest method testMeUsage.

public void testMeUsage() {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    try {
        Script v = b.build("namespace foo; VM[1..5] : tiny;\nVM[6..10] : small;\n lonely($me); ");
        SatConstraint cs = v.getConstraints().iterator().next();
        Assert.assertEquals(cs.getInvolvedVMs().size(), 10);
    } catch (ScriptBuilderException x) {
        Assert.fail(x.getMessage(), x);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Aggregations

SatConstraint (org.btrplace.model.constraint.SatConstraint)78 Test (org.testng.annotations.Test)54 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 ArrayList (java.util.ArrayList)39 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)38 DefaultModel (org.btrplace.model.DefaultModel)33 ShareableResource (org.btrplace.model.view.ShareableResource)30 VM (org.btrplace.model.VM)27 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)27 Node (org.btrplace.model.Node)23 Model (org.btrplace.model.Model)20 HashSet (java.util.HashSet)17 Fence (org.btrplace.model.constraint.Fence)16 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)14 Network (org.btrplace.model.view.network.Network)14 Offline (org.btrplace.model.constraint.Offline)13 Switch (org.btrplace.model.view.network.Switch)13 MigrateVM (org.btrplace.plan.event.MigrateVM)13 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)11 Preserve (org.btrplace.model.constraint.Preserve)9