Example #1
0
  @Override
  public double calculate() {
    HashMap<VirtualLink, Integer> lengths = new HashMap<VirtualLink, Integer>();

    SubstrateNetwork sNetwork = stack.getSubstrate();
    for (SubstrateLink sl : sNetwork.getEdges()) {
      LinkedList<VirtualLink> visited = new LinkedList<VirtualLink>();

      for (AbstractResource r : sl.get()) {
        for (Mapping m : r.getMappings()) {
          AbstractDemand d = m.getDemand();
          NetworkEntity<? extends AbstractConstraint> e = d.getOwner();
          if (e instanceof VirtualLink) {
            VirtualLink vl = (VirtualLink) e;

            if (!visited.contains(vl)) {
              visited.add(vl);

              Integer i = lengths.get(vl);
              if (i == null) {
                i = 1;
              } else {
                i++;
              }
              lengths.put(vl, i);
            }
          }
        }
      }
    }

    int sum = 0;
    for (Integer i : lengths.values()) {
      sum += i;
    }

    int counter = 0;
    for (@SuppressWarnings("rawtypes") Network net : stack) {
      if (net instanceof VirtualNetwork) {
        VirtualNetwork vNet = (VirtualNetwork) net;
        counter += vNet.getEdgeCount();
      }
    }

    return (counter == 0 ? 0.0 : (sum / (double) counter));
  }
Example #2
0
 public static int getStressLevel(SubstrateNode n) {
   int max = 0;
   int stress;
   for (AbstractResource r : n.get()) {
     stress = 0;
     if (r instanceof CpuResource) {
       for (Mapping f : r.getMappings()) {
         if (f.getDemand().getOwner() instanceof VirtualNode) stress++;
       }
     } else {
       stress = r.getMappings().size();
     }
     if (stress > max) {
       max = stress;
     }
   }
   return max;
 }