public boolean hashSetContainsSameOperations(HashSet set1, HashSet set2) { boolean result = false; HashSet s1 = (HashSet) set1.clone(); HashSet s2 = (HashSet) set2.clone(); // first part, are all elements of s1 also in s2? boolean one = false; Iterator it = set1.iterator(); while (it.hasNext()) { PDMOperation d = (PDMOperation) it.next(); if (s2.contains(d)) { s1.remove(d); } } if (s1.isEmpty()) { one = true; } // second part, are all elements of s21 also in s1? boolean two = false; HashSet s3 = (HashSet) set1.clone(); HashSet s4 = (HashSet) set2.clone(); Iterator it2 = set2.iterator(); while (it2.hasNext()) { PDMOperation d = (PDMOperation) it2.next(); if (s3.contains(d)) { s4.remove(d); } } if (s4.isEmpty()) { two = true; } // administrative stuff s1.clear(); s2.clear(); s3.clear(); s4.clear(); result = one && two; return result; }
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; }
public HashSet calculateExecutableOperations( HashSet dataElts, HashSet executed, HashSet failed, boolean root) { HashSet result = new HashSet(); HashSet enabledOperations = new HashSet(); if (root) { // Calculate the enabled operations (i.e. those operation of which // all input elements are in the set of available elements) Object[] ops = operations.values().toArray(); for (int i = 0; i < ops.length; i++) { PDMOperation op = (PDMOperation) ops[i]; HashMap inputs = op.getInputElements(); Object[] ins = inputs.values().toArray(); boolean enabled = true; int k = 0; while (enabled && k < ins.length) { PDMDataElement d = (PDMDataElement) ins[k]; if (!(dataElts.contains(d))) { enabled = false; } k++; } if (enabled) { enabledOperations.add(op); // System.out.println("Enabled operation: "+ op.getID()); } } } else if (!(dataElts.contains(this.getRootElement()))) { // Calculate the enabled operations (i.e. those operation of which // all input elements are in the set of available elements) Object[] ops = operations.values().toArray(); for (int i = 0; i < ops.length; i++) { PDMOperation op = (PDMOperation) ops[i]; HashMap inputs = op.getInputElements(); Object[] ins = inputs.values().toArray(); boolean enabled = true; int k = 0; while (enabled && k < ins.length) { PDMDataElement d = (PDMDataElement) ins[k]; if (!(dataElts.contains(d))) { enabled = false; } k++; } if (enabled) { enabledOperations.add(op); } } } // remove already executed operations Iterator exIt = executed.iterator(); while (exIt.hasNext()) { PDMOperation op = (PDMOperation) exIt.next(); enabledOperations.remove(op); } // remove already failed operations Iterator fIt = failed.iterator(); while (fIt.hasNext()) { PDMOperation op = (PDMOperation) fIt.next(); enabledOperations.remove(op); } result = enabledOperations; return result; }