Exemplo n.º 1
0
  /* =============================================================================
   * initializeManager
   * =============================================================================
   */
  public Manager initializeManager() {
    int i;
    int t;
    System.out.println("Initializing manager... ");

    Random randomPtr = new Random();
    randomPtr.random_alloc();
    Manager managerPtr = new Manager();

    int numRelation = RELATIONS;
    int ids[] = new int[numRelation];
    for (i = 0; i < numRelation; i++) {
      ids[i] = i + 1;
    }

    for (t = 0; t < 4; t++) {

      /* Shuffle ids */
      for (i = 0; i < numRelation; i++) {
        int x = randomPtr.posrandom_generate() % numRelation;
        int y = randomPtr.posrandom_generate() % numRelation;
        int tmp = ids[x];
        ids[x] = ids[y];
        ids[y] = tmp;
      }

      /* Populate table */
      for (i = 0; i < numRelation; i++) {
        boolean status;
        int id = ids[i];
        int num = ((randomPtr.posrandom_generate() % 5) + 1) * 100;
        int price = ((randomPtr.posrandom_generate() % 5) * 10) + 50;
        if (t == 0) {
          status = managerPtr.manager_addCar(id, num, price);
        } else if (t == 1) {
          status = managerPtr.manager_addFlight(id, num, price);
        } else if (t == 2) {
          status = managerPtr.manager_addRoom(id, num, price);
        } else if (t == 3) {
          status = managerPtr.manager_addCustomer(id);
        }
        // assert(status);
      }
    } /* for t */

    System.out.println("done.");
    return managerPtr;
  }
Exemplo n.º 2
0
  /* =============================================================================
   * initializeClients
   * =============================================================================
   */
  public Client[] initializeClients(Manager managerPtr) {
    Random randomPtr;
    Client clients[];
    int i;
    int numClient = CLIENTS;
    int numTransaction = TRANSACTIONS;
    int numTransactionPerClient;
    int numQueryPerTransaction = NUMBER;
    int numRelation = RELATIONS;
    int percentQuery = QUERIES;
    int queryRange;
    int percentUser = USER;

    System.out.println("Initializing clients... ");

    randomPtr = new Random();
    randomPtr.random_alloc();

    clients = new Client[numClient];

    numTransactionPerClient = (int) ((double) numTransaction / (double) numClient + 0.5);
    queryRange = (int) ((double) percentQuery / 100.0 * (double) numRelation + 0.5);

    for (i = 0; i < numClient; i++) {
      clients[i] =
          new Client(
              i,
              managerPtr,
              numTransactionPerClient,
              numQueryPerTransaction,
              queryRange,
              percentUser);
    }

    System.out.println("done.");
    System.out.println("    Transactions        = " + numTransaction);
    System.out.println("    Clients             = " + numClient);
    System.out.println("    Transactions/client = " + numTransactionPerClient);
    System.out.println("    Queries/transaction = " + numQueryPerTransaction);
    System.out.println("    Relations           = " + numRelation);
    System.out.println("    Query percent       = " + percentQuery);
    System.out.println("    Query range         = " + queryRange);
    System.out.println("    Percent user        = " + percentUser);

    return clients;
  }