예제 #1
0
  private boolean constrained(
      Assignment assignment1,
      Assignment assignment2) { // checks if assignment1 is constrained with assignment2

    if (assignment1 == null || assignment2 == null) {
      return false;
    }

    int id1 = assignment1.getID();

    int id2 = assignment2.getID();

    int value1 = assignment1.getValue();
    int value2 = assignment2.getValue();
    if (constrained_agents(id1, id2)) {
      int[][] values = constraints[id1][id2]; // the values are constrained
      if (values[value1][value2] == 1) {
        return true;
      }
    }
    return false;
  }
예제 #2
0
 private void setDomain(CPA cpa) {
   for (int i = 0; i < cpa.length(); i++) {
     Assignment ass = cpa.getAssignment(i);
     if (ass != null) {
       int agentID = ass.getID();
       int assValue = ass.getValue();
       if (constrained_agents(agentID, this.ID)) {
         int[][] values = constraints[agentID][this.ID];
         System.out.println("#### the value is    " + values[4][4]);
         for (int j = 0; j < Domain.length; j++) {
           if (values[j][assValue] == 1) { // values are constrained
             Domain[j] = 0;
           }
         }
       }
     } else {
       break;
     }
   }
 }
    public boolean visit(Expression e) throws Exception {
      if (typeDeclaration.sourceStart() < e.sourceStart()
          && typeDeclaration.sourceEnd() > e.sourceEnd()) {
        if (e instanceof Assignment) {
          if (e.sourceStart() == offset && e.sourceEnd() - e.sourceStart() == length) {
            result = ((Assignment) e).getValue();
            context = contextStack.peek();
          } else if (variableName != null) {
            Assignment assignment = (Assignment) e;
            Expression left = assignment.getVariable();
            Expression right = assignment.getValue();

            if (left instanceof StaticFieldAccess) {
              StaticFieldAccess fieldAccess = (StaticFieldAccess) left;
              Expression dispatcher = fieldAccess.getDispatcher();
              if (dispatcher instanceof TypeReference
                  && "self".equals(((TypeReference) dispatcher).getName())) { // $NON-NLS-1$
                Expression field = fieldAccess.getField();
                if (field instanceof VariableReference
                    && variableName.equals(((VariableReference) field).getName())) {
                  staticDeclarations.put(right, contextStack.peek());
                }
              }
            } else if (left instanceof FieldAccess) {
              FieldAccess fieldAccess = (FieldAccess) left;
              Expression dispatcher = fieldAccess.getDispatcher();
              if (dispatcher instanceof VariableReference
                  && "$this".equals(((VariableReference) dispatcher).getName())) { // $NON-NLS-1$
                Expression field = fieldAccess.getField();
                if (field instanceof SimpleReference
                    && variableName.equals('$' + ((SimpleReference) field).getName())) {
                  staticDeclarations.put(right, contextStack.peek());
                }
              }
            }
          }
        }
      }
      return visitGeneral(e);
    }
예제 #4
0
 /** Returns assignment that corresponds to the given value (if it is present in the set) */
 public Assignment<T> getAssignment(T value) {
   for (Assignment<T> a : iSet) if (a.getValue().getId() == value.getId()) return a;
   return null;
 }
 public boolean isSatisfied() {
   Solution current = csp.getCurrentSolution();
   Assignment lastAssignment = csp.getCurrentSolution().getLastAssignment();
   for (Iterator ite = current.getAssignments().iterator(); ite.hasNext(); ) {
     Assignment previousAssignment = (Assignment) ite.next();
     if (!lastAssignment.getVariable().equals(previousAssignment.getVariable())) {
       if (lastAssignment.getValue().equals(previousAssignment.getValue())) {
         return false;
       }
     }
   }
   return true;
 }