Пример #1
0
  private int[] getNewList(int size, int min, int max) {
    int[] returnArray = new int[size];
    try {
      URL randomOrg =
          new URL(
              "http://www.random.org/cgi-bin/randnum?"
                  + "num="
                  + size
                  + "&min="
                  + min
                  + "&max="
                  + max
                  + "&col=1");
      HttpURLConnection con = (HttpURLConnection) randomOrg.openConnection();
      con.setRequestMethod("GET");
      con.setDoInput(true);
      InputStream in = con.getInputStream();
      InputStreamReader isr = new InputStreamReader(in);
      BufferedReader br = new BufferedReader(isr);
      String theLine;

      for (int i = 0; i < size; i++) {
        returnArray[i] = Integer.parseInt(br.readLine());
      }

      con.disconnect();
    }
    // if something fails, revert to something a little less random, but still good
    // the hashCode is based on the objects memory address, which is unique for each object
    catch (Exception e) {
      Random r = new Random();
      r.setSeed(r.hashCode());
      for (int i = 0; i < size; i++) returnArray[i] = r.nextInt(max);
    }
    return returnArray;
  }
Пример #2
0
 /**
  * set the seed for the random stream used in BottomUpHierModel to determine how many routers are
  * assigned to a specific AS
  */
 public void setAssignSeed(long seed) {
   AssignSeed = seed;
   AssignRandom.setSeed(seed);
 }
Пример #3
0
 /**
  * set the seed for the random stream used in TopDownHierModel for the Edge Connection method
  * (i.e. connecting ASs)
  */
 public void setEdgeConnSeed(long seed) {
   ECSeed = seed;
   EdgeConnRandom.setSeed(seed);
 }
Пример #4
0
 /**
  * set the seed for the random stream used in BottomUpHierModel to select routers go into a
  * specifc AS
  */
 public void setGroupingSeed(long seed) {
   GroupSeed = seed;
   GroupingRandom.setSeed(seed);
 }
Пример #5
0
 /** set the seed for the random stream used to assign bandwidths to edges */
 public void setBWSeed(long seed) {
   BWSeed = seed;
   BWRandom.setSeed(seed);
 }
Пример #6
0
 /** set the seed for the random stream used to connect nodes */
 public void setConnectNodesSeed(long seed) {
   connectSeed = seed;
   ConnectRandom.setSeed(seed);
 }
Пример #7
0
 /** set the seed for the random stream used to place nodes on the plane */
 public void setPlaceNodesSeed(long seed) {
   placeSeed = seed;
   PlaceRandom.setSeed(seed);
 }
Пример #8
0
  public double runTest(String exec, String seed) {
    try {
      this.exec = exec;
      readFiles();
      Random r;
      try {
        r = SecureRandom.getInstance("SHA1PRNG");
        r.setSeed(Long.parseLong(seed));
      } catch (Exception e) {
        return -1;
      }
      P = r.nextDouble() * 0.04 + 0.01;
      C = r.nextDouble() * 1e-3;
      String[] medkit = getMedkit(availableResources, requiredResources, missions, P, C);
      if (medkit == null) {
        System.err.println("Got null");
        return 0;
      }
      double[] mk = new double[10000];
      for (int i = 0; i < medkit.length; i++) {
        String[] sp = medkit[i].split(" ");
        if (sp.length != 2) {
          System.err.println("Invalid return.  Element not formatted correctly: " + medkit[i]);
          return 0;
        }
        try {
          int rid = Integer.parseInt(sp[0].substring(1));
          double cnt = Double.parseDouble(sp[1]);
          if (cnt < 0 || Double.isNaN(cnt) || Double.isInfinite(cnt)) {
            System.err.println("Your return contained an invalid double");
            return 0;
          }
          mk[rid] += cnt;
        } catch (Exception e) {
          System.err.println("Invalid return.  Element not formatted correctly: " + medkit[i]);
          return 0;
        }
      }
      String[] sample = missions;
      int[] used = new int[100000];
      ArrayList<String[]> al[] = new ArrayList[10000];
      Arrays.fill(used, -1);
      for (int i = 0; i < 10000; i++) {
        al[i] = new ArrayList();
        int j = r.nextInt(used.length);
        while (used[j] != -1) {
          j = r.nextInt(used.length);
        }
        used[j] = i;
      }
      for (int i = 0; i < sample.length; i++) {
        String[] sp = sample[i].split(" ");
        int mid = Integer.parseInt(sp[0]);
        if (used[mid - 1] != -1) {
          al[used[mid - 1]].add(sp);
        }
      }
      int evac = 0;
      for (int i = 0; i < 10000; i++) {
        double[] m = (double[]) mk.clone();
        evac += eval(m, al[i]);
      }
      System.err.println("Total evacuations: " + evac + "\n");
      if (evac <= P * 10000) {
        double score = 0;
        double m = 0, v = 0;
        for (int i = 0; i < mk.length; i++) {
          m += mass[i] * mk[i];
          v += vol[i] * mk[i];
        }
        score = C * v + m;
        System.out.println("Total mass: " + m + "\n");
        System.out.println("Total volume: " + v + "\n");
        return 1000 / score;
      } else {
        System.out.println("Evacutions exceeded allowed rate");
        return 0;
      }

    } catch (Exception e) {
      System.err.println(e.toString() + "\n");
      StackTraceElement[] ste = e.getStackTrace();
      for (int i = 0; i < ste.length; i++) System.err.println(ste[i] + "\n");
      return -1;
    }
  }
 /**
  * When deserializing, initialize the seed because otherwise we could get duplicate evolution
  * results when doing distributed computing!
  *
  * @param a_inputStream the ObjectInputStream provided for deserialzation
  * @throws IOException
  * @throws ClassNotFoundException
  * @author Klaus Meffert
  * @since 3.01
  */
 private void readObject(ObjectInputStream a_inputStream)
     throws IOException, ClassNotFoundException {
   // always perform the default de-serialization first
   a_inputStream.defaultReadObject();
   m_rn.setSeed(System.currentTimeMillis());
 }