1 /* =============================================================================
5 * =============================================================================
7 * Copyright (C) Stanford University, 2006. All Rights Reserved.
10 * =============================================================================
12 * For the license of bayes/sort.h and bayes/sort.c, please see the header
15 * ------------------------------------------------------------------------
17 * For the license of kmeans, please see kmeans/LICENSE.kmeans
19 * ------------------------------------------------------------------------
21 * For the license of ssca2, please see ssca2/COPYRIGHT
23 * ------------------------------------------------------------------------
25 * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the
26 * header of the files.
28 * ------------------------------------------------------------------------
30 * For the license of lib/rbtree.h and lib/rbtree.c, please see
31 * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree
33 * ------------------------------------------------------------------------
35 * Unless otherwise noted, the following license applies to STAMP files:
37 * Copyright (c) 2007, Stanford University
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions are
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
47 * * Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
52 * * Neither the name of Stanford University nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY
57 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
59 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
61 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
62 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
63 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
64 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
66 * THE POSSIBILITY OF SUCH DAMAGE.
68 * =============================================================================
74 public class Vacation {
75 /* =============================================================================
77 * =============================================================================
82 public static void displayUsage (String appName) {
83 System.out.println("Usage: %s [options]\n"+ appName);
84 System.out.println("\nOptions: (defaults)\n");
85 System.out.println(" c <UINT> Number of [c]lients (%i)\n"+
86 PARAM_DEFAULT_CLIENTS);
87 System.out.println(" n <UINT> [n]umber of user queries/transaction (%i)\n"+
88 PARAM_DEFAULT_NUMBER);
89 System.out.println(" q <UINT> Percentage of relations [q]ueried (%i)\n"+
90 PARAM_DEFAULT_QUERIES);
91 System.out.println(" r <UINT> Number of possible [r]elations (%i)\n"+
92 PARAM_DEFAULT_RELATIONS);
93 System.out.println(" t <UINT> Number of [t]ransactions (%i)\n"+
94 PARAM_DEFAULT_TRANSACTIONS);
95 System.out.println(" u <UINT> Percentage of [u]ser transactions (%i)\n"+
101 /* =============================================================================
103 * =============================================================================
113 public void setDefaultParams () {
114 CLIENTS = PARAM_DEFAULT_CLIENTS;
115 NUMBER = PARAM_DEFAULT_NUMBER;
116 QUERIES = PARAM_DEFAULT_QUERIES;
117 RELATIONS = PARAM_DEFAULT_RELATIONS;
118 TRANSACTIONS = PARAM_DEFAULT_TRANSACTIONS;
119 USER = PARAM_DEFAULT_USER;
123 /* =============================================================================
125 * =============================================================================
127 public void parseArgs (String argv[]) {
131 for(int i=0;i<argv.length;i++) {
133 if (arg.equals("-c"))
134 CLIENTS=Integer.parseInt(argv[++i]);
135 else if (arg.equals("-n"))
136 NUMBER=Integer.parseInt(argv[++i]);
137 else if (arg.equals("-q"))
138 QUERIES=Integer.parseInt(argv[++i]);
139 else if (arg.equals("-r"))
140 RELATIONS=Integer.parseInt(argv[++i]);
141 else if (arg.equals("-t"))
142 TRANSACTIONS=Integer.parseInt(argv[++i]);
143 else if (arg.equals("-u"))
144 USER=Integer.parseInt(argv[++i]);
150 displayUsage(argv[0]);
155 /* =============================================================================
157 * -- Wrapper function
158 * =============================================================================
160 public static boolean addCustomer (Manager managerPtr, int id, int num, int price) {
161 return managerPtr.manager_addCustomer(id);
165 /* =============================================================================
167 * =============================================================================
169 public Manager initializeManager () {
172 System.out.println("Initializing manager... ");
174 Random randomPtr = new Random();
175 randomPtr.random_alloc();
176 Manager managerPtr = new Manager();
178 int numRelation = RELATIONS;
179 int ids[] = new int[numRelation];
180 for (i = 0; i < numRelation; i++) {
184 for (t = 0; t < 4; t++) {
187 for (i = 0; i < numRelation; i++) {
188 int x = randomPtr.posrandom_generate() % numRelation;
189 int y = randomPtr.posrandom_generate() % numRelation;
196 for (i = 0; i < numRelation; i++) {
199 int num = ((randomPtr.posrandom_generate() % 5) + 1) * 100;
200 int price = ((randomPtr.posrandom_generate() % 5) * 10) + 50;
202 status=managerPtr.manager_addCar(id, num, price);
204 status=managerPtr.manager_addFlight(id, num, price);
206 status=managerPtr.manager_addRoom(id, num, price);
208 status=managerPtr.manager_addCustomer(id);
215 System.out.println("done.");
220 /* =============================================================================
222 * =============================================================================
224 public Client[] initializeClients (Manager managerPtr) {
228 int numClient = CLIENTS;
229 int numTransaction = TRANSACTIONS;
230 int numTransactionPerClient;
231 int numQueryPerTransaction = NUMBER;
232 int numRelation = RELATIONS;
233 int percentQuery = QUERIES;
235 int percentUser = USER;
237 System.out.println("Initializing clients... ");
239 randomPtr = new Random();
240 randomPtr.random_alloc();
242 clients = new Client[numClient];
244 numTransactionPerClient = (int)((double)numTransaction / (double)numClient + 0.5);
245 queryRange = (int)((double)percentQuery / 100.0 * (double)numRelation + 0.5);
247 for (i = 0; i < numClient; i++) {
248 clients[i] = new Client(i,
250 numTransactionPerClient,
251 numQueryPerTransaction,
256 System.out.println("done.");
257 System.out.println(" Transactions = "+ numTransaction);
258 System.out.println(" Clients = "+ numClient);
259 System.out.println(" Transactions/client = "+ numTransactionPerClient);
260 System.out.println(" Queries/transaction = "+ numQueryPerTransaction);
261 System.out.println(" Relations = "+ numRelation);
262 System.out.println(" Query percent = "+ percentQuery);
263 System.out.println(" Query range = "+ queryRange);
264 System.out.println(" Percent user = "+ percentUser);
271 /* =============================================================================
273 * =============================================================================
275 public static void main(String argv[]) {
282 Vacation vac=new Vacation();
284 managerPtr = vac.initializeManager();
285 clients = vac.initializeClients(managerPtr);
286 int numThread = vac.CLIENTS;
288 /* Run transactions */
289 System.out.println("Running clients... ");
291 Barrier.setBarrier(numThread);
293 for(int i=1;i<numThread;i++) {
297 start=System.currentTimeMillis();
299 stop=System.currentTimeMillis();
301 System.out.print("done.");
302 long diff=stop-start;
303 System.out.println("TIME="+diff);
304 vac.checkTables(managerPtr);
307 System.out.println("Deallocating memory... ");
309 * TODO: The contents of the manager's table need to be deallocated.
311 System.out.println("done.");
314 void checkTables (Manager managerPtr) {
316 int numRelation = RELATIONS;
317 RBTree customerTablePtr = managerPtr.customerTablePtr;
318 RBTree tables[]=new RBTree[3];
319 tables[0]=managerPtr.carTablePtr;
320 tables[1]=managerPtr.flightTablePtr;
321 tables[2]=managerPtr.roomTablePtr;
326 System.out.println("Checking tables... ");
328 /* Check for unique customer IDs */
329 int percentQuery = QUERIES;
330 int queryRange = (int)((double)percentQuery / 100.0 * (double)numRelation + 0.5);
331 int maxCustomerId = queryRange + 1;
332 for (i = 1; i <= maxCustomerId; i++) {
333 if (customerTablePtr.find(i)!=null) {
334 if (customerTablePtr.remove(i)) {
335 if (customerTablePtr.find(i)!=null) {
336 System.out.println("ERROR");
343 /* Check reservation tables for consistency and unique ids */
344 for (t = 0; t < numTable; t++) {
345 RBTree tablePtr = tables[t];
346 for (i = 1; i <= numRelation; i++) {
347 if (tablePtr.find(i)!=null) {
349 if (!managerPtr.manager_addCar(i,0,0)) {
350 System.out.println("ERROR3");
354 if (!managerPtr.manager_addFlight(i, 0, 0)) {
355 System.out.println("ERROR3");
359 if (!managerPtr.manager_addRoom(i,0,0)) {
360 System.out.println("ERROR3");
365 if (tablePtr.remove(i)) {
366 if (tablePtr.remove(i)) {
367 System.out.println("ERROR2");
375 System.out.println("done.");
381 /* =============================================================================
385 * =============================================================================