示例#1
0
  public HashSet calculateNextStates(
      PDMState state,
      PDMStateSpace statespace,
      boolean root,
      boolean failure,
      int numStates,
      int breadth) {
    HashSet result = new HashSet();
    HashSet data = state.dataElements;
    HashSet exec1 = state.executedOperations;
    HashSet failed = state.failedOperations;

    HashSet execOps = calculateExecutableOperations(data, exec1, failed, root);
    Iterator it = execOps.iterator();
    int b = 0;
    int bLimit = 0;
    if (!failure) {
      bLimit = breadth;
    } else {
      bLimit = breadth / 2;
    }
    // for each executable operation a new state is created
    while (it.hasNext() && i < numStates && b < bLimit) {
      if (!failure) {
        PDMOperation op = (PDMOperation) it.next();
        PDMDataElement d = op.getOutputElement();
        // First, add the state with the operation 'op' succesfully
        // executed
        HashSet ins2 = (HashSet) data.clone(); // NB: is it necessary to
        // clear this clone
        // again?
        ins2.add(d);
        HashSet exec2 = (HashSet) exec1.clone();
        exec2.add(op);
        PDMState s = checkIfStateExists(statespace, ins2, exec2, failed);
        // Check whether the new state already exists
        // If so, then another link to this state is made
        if (!(s == null)) {
          PDMState st = s;
          PDMStateEdge edge = new PDMStateEdge(state, st, op.getID(), 1.0);
          statespace.addEdge(edge);
        }
        // If not, a new state is created and linked to the current
        // state
        else {
          String name = "state" + i;
          // int num = checkStatusOfState(statespace, )
          PDMState st = new PDMState(statespace, name, ins2, exec2, failed);
          statespace.addState(st);
          result.add(st);
          PDMStateEdge edge = new PDMStateEdge(state, st, op.getID(), 1.0);
          statespace.addEdge(edge);
          i++;
          b++;
        }
      }

      // Then, if failure of operations is considered, add the state with
      // the failed operations 'op'.
      if (failure) {
        PDMOperation op = (PDMOperation) it.next();
        PDMDataElement d = op.getOutputElement();
        // First, add the state with the operation 'op' succesfully
        // executed
        HashSet ins2 = (HashSet) data.clone(); // NB: is it necessary to
        // clear this clone
        // again?
        ins2.add(d);
        HashSet exec2 = (HashSet) exec1.clone();
        exec2.add(op);
        PDMState s = checkIfStateExists(statespace, ins2, exec2, failed);
        // Check whether the new state already exists
        // If so, then another link to this state is made
        if (!(s == null)) {
          PDMState st = s;
          double prob = 1.0 - (op.getFailureProbability());
          PDMStateEdge edge = new PDMStateEdge(state, st, op.getID(), prob);
          statespace.addEdge(edge);
        }
        // If not, a new state is created and linked to the current
        // state
        else {
          String name = "state" + i;
          // int num = checkStatusOfState(statespace, )
          PDMState st = new PDMState(statespace, name, ins2, exec2, failed);
          statespace.addState(st);
          result.add(st);
          double prob = 1.0 - (op.getFailureProbability());
          PDMStateEdge edge = new PDMStateEdge(state, st, op.getID(), prob);
          statespace.addEdge(edge);
          i++;
          b++;
        }
        HashSet failed2 = (HashSet) failed.clone();
        failed2.add(op);
        PDMState s2 = checkIfStateExists(statespace, data, exec1, failed2);
        if (!(s2 == null)) {
          PDMState st = s2;
          PDMStateEdge edge = new PDMStateEdge(state, st, op.getID(), op.getFailureProbability());
          statespace.addEdge(edge);
        }
        // If not, a new state is created and linked to the current
        // state
        else {
          String name = "state" + i;
          PDMState st = new PDMState(statespace, name, data, exec1, failed2);
          statespace.addState(st);
          result.add(st);
          PDMStateEdge edge = new PDMStateEdge(state, st, op.getID(), op.getFailureProbability());
          statespace.addEdge(edge);
          i++;
          b++;
        }
        // failed2.clear();
      }
    }
    return result;
  }
示例#2
0
  public PDMStateSpace calculateSimpleStateSpace(
      boolean root, boolean failure, boolean input, boolean colored, int numStates, int breadth) {
    PDMStateSpace result = new PDMStateSpace(this, colored);
    HashSet states = new HashSet();
    int j = (operations.size() + 1);

    if (!input) {
      HashSet empty = new HashSet();
      PDMState st = new PDMState(result, "state" + i, empty, empty, empty);
      result.addState(st);
      states.add(st);
      i++;
    } else {
      // Start with the complete set of input data elements available
      HashSet empty = new HashSet();
      String name = new String("state" + i);
      HashSet ins = new HashSet(); // this hashSet contains the input
      // elements to the process (input
      // elements of PDM)
      HashSet execOps = new HashSet();
      // Fill the hashSet with the leaf elements
      HashMap leafs = getLeafElements();
      Object[] leafElts = leafs.values().toArray();
      for (int i = 0; i < leafElts.length; i++) {
        PDMDataElement d = (PDMDataElement) leafElts[i];
        ins.add(d);
      }
      HashSet leafOps = getLeafOperations();
      Iterator it = leafOps.iterator();
      while (it.hasNext()) {
        PDMOperation op = (PDMOperation) it.next();
        execOps.add(op);
      }

      PDMState start = new PDMState(result, name, ins, execOps, empty); // start
      // state
      // of
      // the
      // statespace
      result.addState(start);
      i++;
      states.add(start);
    }
    while (!states.isEmpty()) {
      HashSet states2 = (HashSet) states.clone();
      Iterator it = states2.iterator();
      while (it.hasNext()) {
        PDMState state = (PDMState) it.next();
        HashSet nextStates = calculateNextStates(state, result, root, failure, numStates, breadth);
        Iterator it2 = nextStates.iterator();
        // Add the new states to iterator
        while (it2.hasNext()) {
          PDMState st = (PDMState) it2.next();
          states.add(st);
        }
        states.remove(state);
      }
    }
    i = 0;
    j = 0;
    Message.add("<PDMMDPStateSpace>", Message.TEST);
    Message.add("<NumberOfStates = " + result.getNumberOfStates() + " >", Message.TEST);
    Message.add("</PDMMDPStateSpace>", Message.TEST);
    return result;
  }