Exemplo n.º 1
0
  public PDMState checkIfStateExists(
      PDMStateSpace statespace, HashSet data, HashSet exec, HashSet failed) {
    PDMState result = null;
    boolean bool = false;
    HashSet states = statespace.getStates();
    Iterator it = states.iterator();
    while (it.hasNext() && !bool) {
      PDMState state2 = (PDMState) it.next();
      boolean one = false;
      boolean two = false;
      boolean three = false;
      HashSet data2 = state2.dataElements;
      HashSet exec2 = state2.executedOperations;
      HashSet failed2 = state2.failedOperations;
      one = hashSetContainsSameDataElements(data, data2);
      two = hashSetContainsSameOperations(exec, exec2);
      three = hashSetContainsSameOperations(failed, failed2);

      if (one && two && three) {
        bool = true;
        result = state2;
      }
    }
    return result;
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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;
  }