示例#1
0
  public void setup(Scenario scenario, SimTime time) {
    float px;
    float py;

    for (int i = 0; i < numNodes; i++) {
      // float p=2+i*1.5f;
      // float p=5+i;
      px = (float) (Math.random() * scenario.getWidth());
      py = (float) (Math.random() * scenario.getHeight());

      Node newNode =
          new EcraNode(new Point2d(px, py), nodeRadius, scenario, vMin, vMax, targetAttr);
      newNode.setAntennaRadius(antennaRadius);
      nodes.add(newNode);
    }

    // Salvo un rierimento allo scenario
    this.scenario = scenario;

    // Crea i reference point
    createRefPoints();

    // Assegna i ref point di default
    setDefaultRefPoint((int) (numRefPoint / 2));

    // Seleziona i ref point
    if (estractRefPoint) estractRefPoints();

    // Imposto per la prima volta i ruoli
    roleAssignament();
  } // Fine generateNodes
示例#2
0
  private void createRefPoints() {
    if ((numRefPoint % 2) != 0) numRefPoint++;

    int n = (int) (numRefPoint / 2);

    refPoints = new Point2d[n][n];

    float startW = (int) (scenario.getWidth() / numRefPoint);
    float startH = (int) (scenario.getHeight() / numRefPoint);
    float stepW = startW * 2;
    float stepH = startH * 2;

    Point2d newRefPoint = null;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        newRefPoint = new Point2d(startW + (i) * stepW, startH + (j) * stepH);
        refPoints[j][i] = newRefPoint;
      }
    }

    /*for(int i=0;i<n;i++)
      {
    for(int j=0;j<n;j++)
     {
      System.out.print(refPoints[i][j]);
     }
    System.out.print("\n");
      }*/
  } // Fine createRefPoints