@Override
 public int calculateGlobalCost(Assignment a) {
   ConstraintCheckResult res = new ConstraintCheckResult();
   int cost = 0;
   for (int i = 0; i < getNumberOfVariables(); i++) {
     calculateCost(i, a, res);
     cost = Agt0DSL.boundedSum(cost, res.getCost());
   }
   return cost;
 }
  /**
   * calculate the cost for the given assignment
   *
   * @param owner
   * @param a
   * @param result
   */
  @Override
  public void calculateCost(int owner, Assignment a, ConstraintCheckResult result) {
    List<KAryConstraint> constraintsToConsider = roots[owner].collectAllSubConstraints(a);

    int cost = 0;
    int cc = 0;
    if (constraintsToConsider != null) {
      for (KAryConstraint constraint : constraintsToConsider) {
        constraint.getCost(a, result);
        cost = Agt0DSL.boundedSum(cost, result.getCost());
        cc += result.getCheckCost();
      }
    }

    result.set(cost, cc);
  }
  @Override
  public void getConstraintCost(int owner, Assignment k, ConstraintCheckResult result) {

    KAryConstraint constraint = roots[owner].getConstraint(k);
    if (constraint == null) {
      result.set(0, 0);
    } else {
      constraint.getCost(k, result);
    }
  }