Esempio n. 1
1
 /*
  * public HashMap getLeafElements() { HashMap map = new HashMap(); Object[]
  * elts = dataElements.values().toArray(); for (int j=0; j<elts.length; j++)
  * { PDMDataElement data = (PDMDataElement) elts[j];
  * map.put(data.getID(),data); } Object[] ops =
  * operations.values().toArray(); for (int i=0; i<ops.length; i++){
  * PDMOperation op = (PDMOperation) ops[i]; if
  * (!(op.getInputElements().isEmpty())){ HashMap outs =
  * op.getOutputElements(); Object[] outArray = outs.values().toArray(); for
  * (int j=0; j<outArray.length; j++) { PDMDataElement d = (PDMDataElement)
  * outArray[j]; map.remove(d.getID()); } } } return map; }
  */
 public HashMap getLeafElements() {
   HashMap result = new HashMap();
   HashSet leafOps = getLeafOperations();
   if (!(leafOps.isEmpty())) {
     Iterator it = leafOps.iterator();
     while (it.hasNext()) {
       PDMOperation op = (PDMOperation) it.next();
       PDMDataElement data = op.getOutputElement();
       result.put(data.getID(), data);
     }
   } else {
     Object[] elts = dataElements.values().toArray();
     for (int j = 0; j < elts.length; j++) {
       PDMDataElement data = (PDMDataElement) elts[j];
       result.put(data.getID(), data);
     }
     Object[] ops = operations.values().toArray();
     for (int i = 0; i < ops.length; i++) {
       PDMOperation op = (PDMOperation) ops[i];
       HashMap outs = op.getOutputElements();
       Object[] outArray = outs.values().toArray();
       for (int j = 0; j < outArray.length; j++) {
         PDMDataElement d = (PDMDataElement) outArray[j];
         result.remove(d.getID());
       }
     }
   }
   return result;
 }
Esempio n. 2
0
 public HashSet getLeafOperations() {
   HashSet result = new HashSet();
   Object[] ops = operations.values().toArray();
   for (int i = 0; i < ops.length; i++) {
     PDMOperation op = (PDMOperation) ops[i];
     if ((op.getInputElements().isEmpty())) {
       result.add(op);
     }
   }
   return result;
 }
Esempio n. 3
0
 /**
  * Returns a HashSet with the operations that have data element 'data' as output element.
  *
  * @param data PDMDataElement
  * @return HashSet
  */
 public HashSet getOperationsWithOutputElement(PDMDataElement data) {
   HashSet opso = new HashSet();
   Object[] ops = operations.values().toArray();
   for (int i = 0; i < ops.length; i++) {
     PDMOperation op = (PDMOperation) ops[i];
     HashMap outputs = op.getOutputElements();
     if (outputs.containsValue(data)) {
       opso.add(op);
     }
   }
   return opso;
 }
Esempio n. 4
0
  /**
   * Writes the model to DOT.
   *
   * @param bw The writer
   * @throws IOException If writing fails
   */
  public void writeToDot(Writer bw) throws IOException {
    // super.writeToDot(bw);

    // Preamble of dot file
    bw.write(
        "digraph G {ranksep=\".3\"; fontsize=\"8\"; remincross=true; margin=\"0.0,0.0\"; rankdir=TB; ");
    bw.write("fontname=\"Arial\"; \n");
    bw.write("edge [arrowsize=\"0.5\"];\n");
    bw.write("node [fontname=\"Arial\",fontsize=\"8\"];\n");

    // Add the Data Element nodes
    Iterator it = getVerticeList().iterator();
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof PDMDataElement) {
        ((PDMDataElement) object).writeToDot(bw, this);
      }
    }

    // Add all edges
    it = operations.values().iterator();
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof PDMOperation) {
        ((PDMOperation) object).writeToDot(bw, this);
      }
    }

    bw.write("\n}\n");
  }
Esempio n. 5
0
 /**
  * Returns a HashMap with the preceeding data elements of data element 'data'
  *
  * @param data PDMDataElement
  * @return HashMap
  */
 public HashMap getPrecedingElements(PDMDataElement data) {
   HashMap precs = new HashMap();
   Object[] ops = operations.values().toArray();
   for (int i = 0; i < ops.length; i++) {
     PDMOperation op = (PDMOperation) ops[i];
     if (op.getOutputElements().containsValue(data)) {
       HashMap ins = op.getInputElements();
       Object[] inputs = ins.values().toArray();
       for (int j = 0; j < inputs.length; j++) {
         PDMDataElement el = (PDMDataElement) inputs[j];
         precs.put(el.getID(), el);
       }
     }
   }
   return precs;
 }
Esempio n. 6
0
 /**
  * Export to PDM file.
  *
  * @param bw Writer
  * @throws IOException If writing fails
  */
 public void writeToPDM(Writer bw) throws IOException {
   bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
   bw.write("<PDM\n");
   bw.write("\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
   bw.write(
       "\txsi:noNamespaceSchemaLocation=\"C:/Documents and Settings/ivdfeest/My Documents/Implementatie/PDM.xsd\"\n");
   bw.write(">\n");
   Iterator it = dataElements.values().iterator();
   while (it.hasNext()) {
     PDMDataElement dataElement = (PDMDataElement) it.next();
     dataElement.writeToPDM(bw);
   }
   Iterator it2 = resources.values().iterator();
   while (it2.hasNext()) {
     PDMResource resource = (PDMResource) it.next();
     resource.writeToPDM(bw);
   }
   Iterator it3 = operations.values().iterator();
   while (it3.hasNext()) {
     PDMOperation operation = (PDMOperation) it.next();
     operation.writeToPDM(bw);
   }
   bw.write("</PDM>\n");
 }
Esempio n. 7
0
 /**
  * Removes an Operation to the set of Operations of the Product Data Model added by Johfra
  *
  * @param operation PDMOperation
  */
 public void remOperation(PDMOperation operation) {
   operations.remove(operation.getID());
 }
Esempio n. 8
0
 /**
  * Adds an Operation to the set of Operations of the Product Data Model
  *
  * @param operation PDMOperation
  */
 public void addOperation(PDMOperation operation) {
   operations.put(operation.getID(), operation);
 }
Esempio n. 9
0
  /**
   * Export PDM model to Declare process model.
   *
   * @param bw Writer
   * @throws IOException If writing fails
   */
  public void writePDMToDeclare(Writer bw) throws IOException {
    // write the preamble of the XML file
    bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
    bw.write("<model>\n");
    bw.write("<assignment language=\"ConDec\" name=\"" + name + "\">\n");

    // write the activity definitions, i.e. each operation in the PDM is an
    // activity definition in Declare
    bw.write("<activitydefinitions>\n");
    // start with an initial activity that puts the values for the leaf
    // elements of the PDM
    bw.write("<activity id=\"Initial\" name=\"Initial\">\n");
    bw.write("<authorization/>\n");
    bw.write("<datamodel>\n");
    // all leaf elements
    HashMap leafs = getLeafElements();
    Object[] leafElts = leafs.values().toArray();
    for (int i = 0; i < leafElts.length; i++) {
      PDMDataElement data = (PDMDataElement) leafElts[i];
      data.writePDMToDeclare(bw, "output");
    }
    bw.write("</datamodel>\n");
    bw.write("<attributes/>\n");
    bw.write("</activity>\n");

    // first remove input operations from the set of operations and then
    // write all real operations
    HashMap realOps = (HashMap) operations.clone();
    HashSet inputOps = getLeafOperations();
    Iterator it7 = inputOps.iterator();
    while (it7.hasNext()) {
      PDMOperation op = (PDMOperation) it7.next();
      realOps.remove(op.getID());
    }
    Iterator it4 = realOps.values().iterator();
    while (it4.hasNext()) {
      PDMOperation operation = (PDMOperation) it4.next();
      operation.writePDMToDeclare(bw);
    }
    bw.write("\n");
    // write all input operations (i.e. producing input data elements)
    Iterator it8 = inputOps.iterator();
    while (it8.hasNext()) {
      PDMOperation op = (PDMOperation) it8.next();
      op.writePDMToDeclare(bw);
    }

    bw.write("</activitydefinitions>\n");

    // write the constraint definition, for now we do not have any
    // constraints in the PDM that are translated to Declare
    bw.write("<constraintdefinitions>\n");
    bw.write("</constraintdefinitions>\n");

    // write all dataelements
    bw.write("<data>\n");
    Iterator it5 = dataElements.values().iterator();
    while (it5.hasNext()) {
      PDMDataElement dataElement = (PDMDataElement) it5.next();
      dataElement.writePDMToDeclare(bw);
    }
    bw.write("</data>\n");

    // write the organizational information
    bw.write("<team/>\n");

    // TODO: improve graphical positioning of activities. Now they are
    // presented in one long line.
    // write the graphical positioning information of the Declare model,
    // first the initial operation, then the real operations and then the
    // input operations.
    bw.write("<graphical>\n");
    bw.write("<cells>\n");
    Iterator it6 = realOps.values().iterator();
    Double pos = 10.0;
    while (it6.hasNext()) {
      PDMOperation operation = (PDMOperation) it6.next();
      bw.write(
          "<cell activitydefinition=\""
              + operation.getOperationNR()
              + "\" height=\"40.0\" width=\"80.0\" x=\""
              + pos
              + "\" y=\"90.0\" />\n");
      pos = pos + 85.0;
    }
    Iterator it9 = inputOps.iterator();
    pos = 10.0;
    while (it9.hasNext()) {
      PDMOperation operation = (PDMOperation) it9.next();
      bw.write(
          "<cell activitydefinition=\""
              + operation.getOperationNR()
              + "\" height=\"40.0\" width=\"80.0\" x=\""
              + pos
              + "\" y=\"180.0\" />\n");
      pos = pos + 85.0;
    }

    bw.write("</cells>\n");

    // write the connectors
    bw.write("<connectors/>\n");
    // close the XML file in the right way
    bw.write("</graphical>\n");
    bw.write("</assignment>\n");
    bw.write("</model>\n");
  }
Esempio n. 10
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;
  }
Esempio n. 11
0
  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;
  }