Example #1
0
 public void makeRelationsButtonActionPerformed(ActionEvent evt) {
   System.out.println("In make relationships");
   int k = stakeholders.size();
   for (Iterator<Stakeholder> s = stakeholders.iterator(); s.hasNext(); ) {
     Stakeholder stakeholder = s.next();
     int place = (int) Math.pow(2.0, (double) k);
     int random = (int) (Math.random() * place);
     place /= 2;
     System.out.println(random);
     for (int i = k - 1; i >= 0; i--) {
       System.out.printf("if(%d >= %d)\n", random, place);
       if (random >= place) {
         System.out.printf("%s.addI(%s)%n", stakeholder.getName(), stakeholders.get(i).getName());
         stakeholder.addInfluence(stakeholders.get(i).getName(), (int) (Math.random() * 4));
         random -= place;
       }
       place /= 2;
     }
   }
 }
Example #2
0
  public void updateShVertexList(ArrayList<Stakeholder> SHList) {
    // remove all vertices and edges currently graphed
    panGraph.removeCells(panGraph.getChildVertices(panGraph.getDefaultParent()), true);

    // add all stakeholders to the graph first, no edges
    for (Iterator<Stakeholder> iter = SHList.iterator(); iter.hasNext(); ) {
      Stakeholder s = iter.next();
      Object v = new Object();
      if (s.getPlacementRank() > Stakeholder.UNDEFINED) {
        panGraph.getModel().beginUpdate();
        try {
          v =
              panGraph.insertVertex(
                  graphParent,
                  null,
                  s.getName(),
                  100,
                  100,
                  s.getDiameter(),
                  s.getDiameter(),
                  s.getStyle());
        } finally {
          panGraph.getModel().endUpdate();
        }
        s.setGraphNode(v);
      }
      // What to do if a stakeholder is a "non-stakeholder", currently adds nothing to graph
      else {
        //                v = panGraph.insertVertex(graphParent, null, null, 100, 100,
        // s.getDiameter(), s.getDiameter(), s.getStyle());
        //                s.setGraphNode(v);
      }
    }
    // now add all edges
    for (Iterator<Stakeholder> mainShIter = SHList.iterator(); mainShIter.hasNext(); ) {
      Stakeholder main = mainShIter.next();
      for (Iterator<Relationship> it = main.getInfluences().iterator(); it.hasNext(); ) {
        Relationship r = it.next();
        // If the relationship magnitude is zero, don't graph it.
        if (r.getMagnitude() != 0) {
          for (Iterator<Stakeholder> secondaryShIter = SHList.iterator();
              secondaryShIter.hasNext(); ) {
            Stakeholder secondary = secondaryShIter.next();
            if (secondary.getName().equals(r.getName())) {
              //                            System.out.printf("insertEdge(%s,%s,%s)\n",
              // main.getName(), secondary.getName(), r.getLineStyle());
              panGraph.getModel().beginUpdate();
              try {
                panGraph.insertEdge(
                    graphParent,
                    null,
                    null,
                    main.getGraphNode(),
                    secondary.getGraphNode(),
                    r.getLineStyle());
              } finally {
                panGraph.getModel().endUpdate();
              }
            }
          }
        }
      }
    }
    graph();
  }