Exemplo n.º 1
0
 private void CreateComStructureSmallworld() {
   // TODO Auto-generated method stub
   for (int i = 0; i < Agents.size(); i++) {
     for (int j = 0; j < para_ComStructure; j++) {
       int temp = (i + j + 1) % Agents.size();
       Agents.get(i).ComNeighbours.add(Agents.get(temp));
       Agents.get(temp).ComNeighbours.add(Agents.get(i));
       // System.out.println("i: "+i+" temp: "+temp);
     }
   }
   // System.exit(0);
   for (int i = 0; i < Agents.size(); i++) {
     for (int j = 0; j < Agents.get(i).ComNeighbours.size(); j++) {
       int range = 10;
       if (Functions.getRandom(0, Agents.size() - 1) < range) {
         Agent agent = Agents.get(Functions.getRandom(0, Agents.size() - 1));
         while (Agents.get(i).ComNeighbours.contains(agent) || agent == Agents.get(i)) {
           agent = Agents.get(Functions.getRandom(0, Agents.size() - 1));
         }
         // System.out.println("small world");
         // System.exit(0);
         Agents.get(i).ComNeighbours.get(j).ComNeighbours.remove(Agents.get(i));
         Agents.get(i).ComNeighbours.set(j, agent);
         agent.ComNeighbours.add(Agents.get(i));
       }
     }
   }
 }
Exemplo n.º 2
0
 @SuppressWarnings("unused")
 private void addRandomCooperation() {
   // TODO Auto-generated method stub
   for (int i = 0; i < Agents.size(); i++) {
     boolean newCooperation = false;
     while (!newCooperation) {
       int random = Functions.getRandom(0, Agents.size() - 1);
       if (!Agents.get(i).CoopNeighbours.contains(Agents.get(random))) {
         newCooperation = true;
         Agents.get(i).CoopNeighbours.add(Agents.get(random));
       }
     }
   }
 }
Exemplo n.º 3
0
  private void Initiation_TasksandAgents() {
    // TODO Auto-generated method stub
    for (int i = 0; i < Number_Agent; i++) {
      Agents.add(Factory.createAgent(i));
    }

    // Initial the cooperation structure
    addSelfCooperation();
    createCoopStructure();
    // addRandomCooperation();

    // Initial the communication structure
    if (Allocation.Method != 1) {
      CreateComStructure();
    }

    System.out.println("Communication Structure finished");
    if (!Test.testComStructrue()) {
      System.out.println("Communication structrue is wrong");
      System.exit(0);
    }

    Tasks = new Task[Allocation_Time][];
    for (int i = 0; i < Allocation_Time; i++) {
      Tasks[i] = new Task[Functions.getRandom(Min_TaskRate, Min_TaskRate)];
    }

    // Calculate the average degree of communication and cooperation network
    double tempComdegree = 0;
    double tempCoopdegree = 0;
    for (int i = 0; i < Agents.size(); i++) {
      tempComdegree += Agents.get(i).ComNeighbours.size();
      tempCoopdegree += Agents.get(i).CoopNeighbours.size();
    }
    averageComStructure = tempComdegree / Agents.size();
    averageCoopStructure = tempCoopdegree / Agents.size() - 1;
  }
Exemplo n.º 4
0
  private void CreateComStructure() {
    // TODO Auto-generated method stub
    if (para_ComStructure == 0) {
      copytheCoopStructure();
      return;
    }
    if (probability_ComStructure == 2) {
      CreateComStructureSmallworld();
      return;
    }
    int randomorder[] = Functions.getRandomOrder(0, Number_Agent - 1);
    for (int i = 0; i < para_ComStructure; i++) {
      for (int j = 0; j < para_ComStructure; j++) {
        if (i != j) {
          Agents.get(randomorder[i]).ComNeighbours.add(Agents.get(randomorder[j]));
        }
      }
    }

    for (int i = para_ComStructure; i < Number_Agent; i++) {
      for (int j = 0; j < para_ComStructure; j++) {
        double[] weight = new double[i]; // Store the weights of former i
        // agents
        double weights = 0; // Store the total weight
        for (int k = 0; k < i; k++) { //
          weight[k] =
              (1 - probability_ComStructure) * Agents.get(randomorder[k]).ComNeighbours.size()
                  + probability_ComStructure; // Calculate the weight
          weights = weights + weight[k]; // Calculate the total weight
        }
        boolean newrelation = false; // remark if a new relation is
        // constructed for agent i in the
        // loop
        while (!newrelation) { // The relation is not constructed
          // successful, construct again
          double randomnumber =
              ((double) (Functions.getRandom(1, 10000))) / 10000; // Create a random percent, from
          // 0.0001 to 1
          double weighted = 0;
          loop:
          for (int k = 0; k < i; k++) { // Select the agent to
            // construct relation
            // according to the
            // former random percent
            weighted = weighted + weight[k] / weights;

            if (weighted >= randomnumber) { // Try to construct
              // relations with the
              // agent k
              if (Agents.get(randomorder[i])
                  .ComNeighbours
                  .contains(Agents.get(randomorder[k]))) { // If
                // the
                // relation
                // between
                // i
                // and
                // k
                // exist,
                // try
                // to
                // construct
                // relation
                // between
                // i
                // and
                // a
                // different
                // agent
                break loop;
              }
              Agents.get(randomorder[i]).ComNeighbours.add(Agents.get(randomorder[k]));
              Agents.get(randomorder[k])
                  .ComNeighbours
                  .add(Agents.get(randomorder[i])); // Construct new
              // relations
              newrelation = true;
              break loop;
            }
          }
        }
      }
    }
  }