示例#1
0
 @SuppressWarnings("unchecked")
 public static Map<VirtualNetwork, Boolean> calculateMappedVnr(NetworkStack stack) {
   VirtualNetwork tempVnr;
   Network tmpN;
   boolean isMapped;
   Map<VirtualNetwork, Boolean> isMappedVnr = new LinkedHashMap<VirtualNetwork, Boolean>();
   for (Iterator<Network<?, ?, ?>> net = stack.iterator(); net.hasNext(); ) {
     tmpN = net.next();
     if (tmpN.getLayer() != 0) {
       tempVnr = (VirtualNetwork) tmpN;
       isMapped = true;
       for (VirtualNode tmpVNode : tempVnr.getVertices()) {
         for (AbstractDemand dem : tmpVNode) {
           if (dem instanceof CpuDemand) {
             if (dem.getMappings().isEmpty()) {
               isMapped = false;
             }
             break;
           }
         }
       }
       isMappedVnr.put(tempVnr, isMapped);
     }
   }
   return isMappedVnr;
 }
示例#2
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));
  }