/** store the data in the data center's nodes just by first fit first service */
 public void bindReplicasToStorageNodesSimple_Net() {
   int replicaNum = replicaList.size();
   nodeList = this.getNodeList();
   int nodeNum = nodeList.size();
   int idx = 0;
   for (int i = 0; i < replicaNum; i++) {
     StorageNode node = nodeList.get(idx);
     // BlockReplica replica = replicaList.remove(i);
     BlockReplica replica = replicaList.get(i);
     double replicaSize = replica.getSize();
     if (node.getAvailableSpace() - replicaSize >= 0.000000000000000000000001
         && !node.contains(replica.getName())) {
       double time = node.addFile(replica);
       double accrossLatency = NetworkTopology.getDelay(getId(), node.getDatacenter().getId());
       time += accrossLatency;
       Log.printLine(
           "it take "
               + time
               + " seconds to write the replica #"
               + replica.getId()
               + " to be stored in datacenter "
               + node.getDatacenter().getName()
               + " node #"
               + node.getId());
       // node.setCapacity(node.getCapacity()-replicaSize);
       idx = (idx + 1) % nodeNum;
     } else {
       idx = (idx + 1) % nodeNum;
       i--; // 该副本还未分配到node上,故重新再看接下来的node能否有空间存副本
     }
   }
 }
 /** Store data to StorageNode with the Node is selected randomly */
 public void bindReplicasToStorageNodeRand_Net() {
   int replicaNum = replicaList.size();
   int nodeSize = nodeList.size();
   for (int i = 0; i < replicaNum; i++) {
     BlockReplica replica = replicaList.get(i);
     StorageNode node =
         nodeList.get(java.util.concurrent.ThreadLocalRandom.current().nextInt(nodeSize));
     double replicaSize = replica.getSize();
     if (node.getAvailableSpace() - replicaSize >= 0.000000000000000000000001
         && !node.contains(replica.getName())) {
       double time = node.addFile(replica);
       double accrossLatency = NetworkTopology.getDelay(getId(), node.getDatacenter().getId());
       time += accrossLatency;
       /*Log.printLine("it take " + time
       + " seconds to write the replica #" + replica.getId()
       + " to be stored in datacenter "
       + node.getDatacenter().getName() + " node #"
       + node.getId());*/
       Log.printLine(
           "replica #"
               + replica.getId()
               + "    			"
               + node.getDatacenter().getName()
               + " node #"
               + node.getId()
               + " 			"
               + time);
     } else {
       i--;
     }
   }
 }
 /**
  * store data in the data center's nodes according the TOPSIS( Technique for Order Preference by
  * Similarity to Ideal Solution)
  *
  * @param none
  */
 @SuppressWarnings("unchecked")
 public void bindReplicasToStorageNodesTOPSIS() {
   // TODO Auto-generated method stub
   int replicaNum = replicaList.size();
   int nodeSize = nodeList.size();
   int idx = 0;
   for (int i = 0; i < replicaNum; i++) {
     //			TOPSIS();
     TOPSIS.buildTOPSIS(datacenterList, (List<StorageNode>) nodeList);
     BlockReplica rep = replicaList.get(i);
     double replicaSize = rep.getSize();
     //			StorageNode node = nodeList.get(this.rankedTOPSISnodeIndex[idx]);//
     // rankedTOPSISnodeIndex中对于小数据不行呢
     StorageNode node = nodeList.get(TOPSIS.rankedTOPSISnodeIndex[idx]);
     if (node.getAvailableSpace() - replicaSize > 0.000000000000000001
         && !node.contains(rep.getName())) {
       double time = node.addFile(rep); // if the node has already added
       // this file,the time just
       // include networkLatency and
       // transport time
       Log.printLine(
           "it take "
               + time
               + " seconds to write the replica #"
               + rep.getId()
               + "to be stored in datacenter "
               + node.getDatacenter().getName()
               + " node #"
               + node.getId());
     } else { // rep没有加进去
       i--;
     }
     idx = (idx + 1) % nodeSize;
   }
 }
 /**
  * Read the given data from the storage node and log the time it cost
  *
  * @param replica the data that wants to read
  */
 public void readData(BlockReplica replica) {
   double time = 0.0;
   int nodeNum = nodeList.size();
   for (int i = 0; i < nodeNum; i++) {
     StorageNode node = nodeList.get(i);
     if (node.contains(replica)) {
       time += replica.getSize() / node.getMaxTransferRate();
       break;
     }
   }
   Log.printLine("read replica #" + replica.getId() + " cost: " + time + " secnods");
 }
  /**
   * Store data to StorageNode with the Node is selected based on backward-cloud generator and AHP
   */
  public void bindReplicasToStorageNode_DcSelectAHP_Net() {
    int replicaNum = replicaList.size();
    //		int numDc = datacenterList.size();
    // 这里等于先赋值为0的话,对后面选择数据中心索引有误导
    /*rankedDCindex = new int[numDc];
    for(int i=0;i<numDc;i++){
    	rankedDCindex[i] = 0;
    }*/

    int dcIndex = 0, nodeId = 0;
    for (int i = 0; i < replicaNum; i++) {
      BlockReplica replica = replicaList.get(i);

      // 采用AHP-逆向云算法生成排序好了的数据中心索引
      AHP_BackwardCloud.AHP_BackwardCloud_Init(datacenterList);
      dcIndex = dcIndex % AHP_BackwardCloud.rankedDCindex.length;
      //			int localNodeId
      // =TOPSIS_Local(datacenterList.get(AHP_BackwardCloud.rankedDCindex[dcIndex]));
      TOPSIS_Local(datacenterList.get(AHP_BackwardCloud.rankedDCindex[dcIndex]));
      nodeId = nodeId % TOPSIS.rankedTOPSISnodeIndex.length;
      int localNodeId = TOPSIS.rankedTOPSISnodeIndex[nodeId];
      double replicaSize = replica.getSize();
      StorageDatacenter dc = datacenterList.get(AHP_BackwardCloud.rankedDCindex[dcIndex]);
      List<StorageNode> localNodeLst = (List<StorageNode>) dc.nodeList;
      StorageNode node = dc.NodeList.getById(localNodeLst, localNodeId);
      if (node.getAvailableSpace() - replicaSize >= 0.000000000000000000000001
          && !node.contains(replica.getName())) {
        double time = node.addFile(replica);
        double accrossLatency = NetworkTopology.getDelay(getId(), node.getDatacenter().getId());
        time += accrossLatency;
        /*Log.printLine("it take " + time
        + " seconds to write the replica #" + replica.getId()
        + " to be stored in datacenter "
        + node.getDatacenter().getName() + " node #"
        + node.getId());*/
        Log.printLine(
            "replica #"
                + replica.getId()
                + "    			"
                + node.getDatacenter().getName()
                + " node #"
                + node.getId()
                + " 			"
                + time);
      } else {
        i--;
      }
      dcIndex++;
      nodeId++;
    }
  }