source: src/main/java/onetomany/test.java@ 257

Last change on this file since 257 was 257, checked in by Faria Nassiri Mofakham, 5 years ago

1) BilateralNegotiation which extends Thread added to onetomany. According to BCG protocol this creates two threads, one for a buyer and one for a seller (it now generates null agents). 2) An ActionListener added to close button in onetomany.etc.GUI.

File size: 15.4 KB
Line 
1/**
2 * Test class
3 */
4package onetomany;
5
6import java.awt.Color;
7
8import onetomany.bargainingchipsgame.Bundle;
9import onetomany.bargainingchipsgame.Chip;
10import onetomany.bargainingchipsgame.Stack;
11import onetomany.bargainingchipsgame.players.Agent;
12import onetomany.bargainingchipsgame.players.utilityfunction.*;
13
14/**
15 * This class is for creating Chips, Stacks, and Bundles to test the operations
16 *
17 * @author Faria Nassiri-Mofakham
18 *
19 */
20
21public class test
22{
23
24 /**
25 * @param args
26 */
27 public static void main(String[] args)
28 {
29 // TODO
30 Chip chip1=new Chip("Pink", 5);
31 System.out.println("\nChip1: "+chip1);
32 Stack stack1=new Stack(chip1,12);
33 System.out.println("\nTEST1:::Stack1: "+stack1+", its price is "+stack1.getPrice());
34
35 System.out.println("\n-----");
36
37 Chip chip2=new Chip("Orange", 7);
38 System.out.println("\nChip2: "+chip2);
39 Stack stack2=new Stack(chip2,9);
40 System.out.println("\nTEST1:::Stack2: "+stack2+", its price is "+stack2.getPrice());
41
42 System.out.println("\n-----");
43
44 Chip c1=new Chip();
45 c1.setRandomColor();
46 double p1=100; double p2=1000;
47 c1.setRandomPrice(p1,p2);
48 System.out.println("With random defined color, and random price between "+p1+" and "+p2+", the Chip: "+c1);
49
50 System.out.println("\n-----");
51
52 Chip c2=new Chip();
53 c2.setColorRandomRGB();
54 c2.setRandomPrice(p1,p2);
55 System.out.println("With random RGB color, and random price between "+p1+" and "+p2+", the Chip: "+c2);
56
57
58
59 System.out.println("\n-----");
60
61 Bundle bundle1 = new Bundle();
62
63 bundle1.addStack(stack1);
64 bundle1.addStack(stack2);
65
66 System.out.println("\nTEST2:::Bundle1: "+bundle1);
67
68
69 //generating a bundle with stacks in random colors, random unit price, and random quantity
70 Bundle bundle2 = new Bundle();
71 for (int i=1; i<5;i++)
72 {
73 // int r=(int)(Math.random()*266; int g=(int)(Math.random()*266; int b=(int)(Math.random()*266;
74 // Color c=new Color((int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255));
75 bundle2.addStack(new Stack(new Chip(new Color((int)(Math.random()*255+1),(int)(Math.random()*255+1),(int)(Math.random()*255+1)).toString(), (double)(Math.random()*20+1)), (int)(Math.random()*10+1)));
76
77 }
78
79 System.out.println("\nTEST3:::Bundle2: "+bundle2);
80
81
82 Bundle bundle3= new Bundle();
83 bundle3.addStack(new Stack(new Chip("Red", 5), 17));
84 bundle3.addStack(new Stack(new Chip("Green", 7), 15));
85 bundle3.addStack(new Stack(new Chip("Blue", 10), 3));
86 bundle3.addStack(new Stack(new Chip("Pink", 2), 1));
87 bundle3.addStack(new Stack(new Chip("Orange", 1), 4));
88
89 System.out.println("\nTEST4:::Bundle3: "+bundle3);
90
91 Bundle bundle4= new Bundle();
92
93 Bundle bundle5=null;
94
95 System.out.println("\nBundle4: "+bundle4+"\nBundle5: "+bundle5);
96
97 System.out.println("\n-----");
98
99
100 System.out.println("\n*TEST5::: Aggregating stack1: "+stack1+" into stack2: "+stack2+" results in "+stack2.aggregateWith(stack1));
101
102
103 System.out.println("\n-----");
104
105 Stack s=null;
106
107
108
109 System.out.println("\n*TEST6-01:::Stack1: "+stack1+" is aggregated with ``null Stack'' as follows:\n"+stack1.aggregateWith(s));
110
111
112 System.out.println("\n-----");
113
114 Stack ss=new Stack(new Chip("Orange", 8),40);
115 // System.out.println("\n*TEST6-02:::Bundle1: "+bundle1+" is aggregated with Stack "+ss+" as follows:\n"+bundle1.aggregateWith(ss));
116
117
118
119 // System.out.println("\n*TEST6:::Bundle1: "+bundle1+" is aggregated with Stack: 40 x Chip(Yellow, 8$) as follows:\n"+bundle1.aggregateWith(new Stack(new Chip("Yellow", 8),40)));
120
121
122 Stack sss=new Stack(new Chip("Cyan", 5),16);
123
124 // System.out.println("\n*TEST6-03:::Bundle1: "+bundle1+" is aggregated with Stack "+sss+" as follows:\n"+bundle1.aggregateWith(sss));
125
126
127 System.out.println("\n-----");
128
129 Stack ssss=null;
130
131 // System.out.println("\n*TEST7:::Bundle1: "+bundle1+" is aggregated with ``null Stack'' as follows:\n"+bundle1.aggregateWith(ssss));
132
133
134
135 System.out.println("\n-----");
136
137 System.out.println("\n*TEST8:::Bundle1: "+bundle1+" is aggregated with ``null bundle'' as follows:\n"+bundle1.aggregateWith(bundle5));
138
139 System.out.println("\n-----");
140
141 System.out.println("\n*TEST9:::Bundle1: "+bundle1+" is aggregated with Bundle3: "+bundle3+" as follows:\n"+ bundle1.aggregateWith(bundle3));
142
143 System.out.println("\n-----");
144
145 System.out.println("\n-----");
146
147
148
149 Bundle b1=new Bundle();
150 b1.addStack(new Stack(new Chip("Red", 1), 10));
151 b1.addStack(new Stack(new Chip("Blue", 8), 30));
152 b1.addStack(new Stack(new Chip("Orange", 4), 30));
153 b1.addStack(new Stack(new Chip("Pink", 8), 80));
154
155
156
157
158 Bundle b2=new Bundle();
159 b2.addStack(new Stack(new Chip("Red", 3), 20));
160
161 Bundle b3=new Bundle();
162 b3.addStack(new Stack(new Chip("Blue", 4), 30));
163 b3.addStack(new Stack(new Chip("Orange", 6), 20));
164
165 Bundle b4=new Bundle();
166 b4.addStack(new Stack(new Chip("White", 4), 30));
167 b4.addStack(new Stack(new Chip("Yellow", 6), 20));
168
169
170 Bundle b5=new Bundle();
171 b5.addStack(new Stack(new Chip("Cyan", 7), 90));
172
173
174
175 Bundle b6=new Bundle();
176 b6.addStack(new Stack(new Chip("Red", 9), 10));
177
178
179 Bundle bbb=new Bundle();
180 bbb=b3;
181 System.out.println("\n*TEST::: "+bbb);
182
183 System.out.println("\n-----aggregateWith----");
184
185
186
187
188 System.out.println("\n-----BUNDLEaggregateWithBundle-----");
189
190
191 System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith(bundle5));
192
193
194 System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith(bundle5));
195
196
197 System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith(b5));
198
199 System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith(b3));
200
201 System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith(b6));
202
203 System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith(b1));
204
205
206 System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith(b3));
207
208
209 System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith(b2));
210
211 System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith(b4));
212
213 System.out.println("\n-----BUNDLEaggregateWith333Bundle-----");
214
215
216
217 System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated333 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith333(bundle5));
218
219
220 System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated333 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith333(bundle5));
221
222
223 System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated333 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith333(b5));
224
225 System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated333 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith333(b3));
226
227 System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated333 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith333(b6));
228
229 System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated333 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith333(b1));
230
231
232 System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated333 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith333(b3));
233
234
235 System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated333 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith333(b2));
236
237 System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated333 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith333(b4));
238
239
240
241 System.out.println("\n-----TEST11: Agent creations -----");
242
243
244
245 Utility_Function u1=new UF_IWant3Red();
246 Agent belinda = new Agent();//bundle3, u, 10, null);
247 belinda.setName("Belinda");
248 belinda.setWishlist(bundle3);
249 belinda.setUtility(u1);
250 belinda.setDeadline(10);
251
252 System.out.println("\n"+belinda+"\nTEST11-01* utility of aggregated bundle TEST10-09 "+b1.aggregateWith(b4)+"\nfor "+belinda.getName()+" is: "+belinda.getUtility(b1.aggregateWith(b4)));
253
254
255 Utility_Function u2=new UF_Nice();
256 Agent bella = new Agent();//bundle3, u, 10, null);
257 bella.setName("Bella");
258 bella.setWishlist(bundle3);
259 bella.setUtility(u2);
260 bella.setDeadline(100);
261
262 System.out.println("\n"+bella+"\nTEST11-02* utility of aggregated bundle TEST10-09 "+b1.aggregateWith(b4)+"\nfor "+bella.getName()+" is: "+bella.getUtility(b1.aggregateWith(b4)));
263
264
265 Utility_Function u4=new UF_AllOrNothing(bundle3);
266 Agent sam = new Agent();
267 sam.setName("Sam");
268 sam.setWishlist(bundle3);
269 sam.setUtility(u4);
270 sam.setDeadline(1000);
271
272 System.out.println("\n"+sam+"\nTEST11-04* utility of bundle3 "+bundle3+"\nfor "+sam.getName()+" is: "+sam.getUtility(bundle3));
273
274
275 Bundle a=new Bundle();
276 a.addStack(new Stack(new Chip("Blue", 4), 30));
277 a.addStack(new Stack(new Chip("Orange", 6), 20));
278
279 Bundle aa=new Bundle();
280 aa.addStack(new Stack(new Chip("Orange", 6), 20));
281 aa.addStack(new Stack(new Chip("Blue", 4), 30));
282
283
284
285 Agent simon = new Agent("Simon", a, new UF_AllOrNothing(a), 1000, null);
286
287 System.out.println("\n"+simon+"\nTEST11-05* utility of bundle aa "+aa+"\nfor "+simon.getName()+" is: "+simon.getUtility(aa));
288
289
290
291 Bundle aaa=new Bundle();
292 aaa.addStack(new Stack(new Chip("Orange", 6), 20));
293 aaa.addStack(new Stack(new Chip("Blue", 4), 30));
294 aaa.addStack(new Stack(new Chip("White", 4), 30));
295
296
297 Utility_Function u6=new UF_FreeDisposal(aaa);
298 Agent bethy = new Agent();
299 bethy.setName("Bethy");
300 bethy.setWishlist(aaa);
301 bethy.setUtility(u6);
302 bethy.setDeadline(1000);
303
304
305 System.out.println("\n"+bethy+"\nTEST11-06* utility of bundle aa "+aa+"\nfor "+bethy.getName()+" is: "+bethy.getUtility(aa));
306
307 System.out.println("\n"+bethy+"\nTEST11-07* utility of bundle aaa "+aaa+"\nfor "+bethy.getName()+" is: "+bethy.getUtility(aaa));
308
309 Bundle aaaa=new Bundle();
310 aaaa.addStack(new Stack(new Chip("Orange", 6), 20));
311
312 System.out.println("\n"+bethy+"\nTEST11-08* utility of bundle aaaa "+aaaa+"\nfor "+bethy.getName()+" is: "+bethy.getUtility(aaaa));
313
314
315
316
317 Utility_Function u8=new UF_Silly();
318 Agent sterling = new Agent();
319 sterling.setName("Sterling");
320 sterling.setWishlist(a);
321 sterling.setUtility(u8);
322 sterling.setDeadline(10);
323
324 System.out.println("\n"+sterling+"\nTEST11-09* utility of bundle a "+a+"\nfor "+sterling.getName()+" is: "+sterling.getUtility(a));
325
326 System.out.println("\n"+sterling+"\nTEST11-10* utility of bundle aaaa "+aaaa+"\nfor "+sterling.getName()+" is: "+sterling.getUtility(aaaa));
327
328 System.out.println("\n"+sterling+"\nTEST11-11* utility of bundle aaa "+aaa+"\nfor "+sterling.getName()+" is: "+sterling.getUtility(aaa));
329
330
331
332 String c="Blue";
333 int q=30;
334 Bundle w=new Bundle();
335 w.addStack(new Stack(new Chip(c,10),q));
336
337 Utility_Function u9=new UF_IWantColorAndQuantity(c, q);
338 Agent sandra = new Agent();
339 sandra.setName("Sandra");
340 sandra.setWishlist(w); // there should be a better way to bring those parameters for making the wishlist at time of calling the utility function
341 sandra.setUtility(u9);
342 sandra.setDeadline(10);
343
344 System.out.println("\n"+sandra+"\nTEST11-09* utility of bundle a "+a+"\nfor "+sandra.getName()+" is: "+sandra.getUtility(a));
345
346 System.out.println("\n"+sandra+"\nTEST11-10* utility of bundle aaaa "+aaaa+"\nfor "+sandra.getName()+" is: "+sandra.getUtility(aaaa));
347
348 System.out.println("\n"+sandra+"\nTEST11-11* utility of bundle aaa "+aaa+"\nfor "+sandra.getName()+" is: "+sandra.getUtility(aaa));
349
350
351 System.out.println("\n========================IT IS UF_prcntQTYandprcntPrice=========================");
352
353
354 Utility_Function u3=new UF_prcntQTYandprcntPrice(b3,0.5,0.5);
355 Agent bob = new Agent();
356 bob.setName("Bob");
357 bob.setWishlist(b3);
358 bob.setUtility(u3);
359 bob.setDeadline(100);
360
361 System.out.println("\n"+bob+"\nTEST11-03* utility of b1 "+b3+"\nfor "+bob.getName()+" is: "+bob.getUtility(b3)+"\n"+bob.getWishlist().getPrice()+"\n"+b3.getPrice());
362
363 System.out.println("\n"+bob+"\nTEST11-033* utility of b1 "+b1+"\nfor "+bob.getName()+" is: "+bob.getUtility(b1)+"\n"+bob.getWishlist().getPrice()+"\n"+b1.getPrice());
364
365 System.out.println("\n"+bob+"\nTEST11-0333* utility of b1 "+aaa+"\nfor "+bob.getName()+" is: "+bob.getUtility(aaa)+"\n"+bob.getWishlist().getPrice()+"\n"+aaa.getPrice());
366
367
368
369
370
371 Utility_Function u33=new UF_prcntQTYandprcntPrice(b3,0.1,0.1);
372 Agent bob33 = new Agent();
373 bob33.setName("Bob33");
374 bob33.setWishlist(b3);
375 bob33.setUtility(u33);
376 bob33.setDeadline(100);
377
378 System.out.println("\n"+bob33+"\nTEST11-03* utility of b1 "+b3+"\nfor "+bob33.getName()+" is: "+bob33.getUtility(b3)+"\n"+bob33.getWishlist().getPrice()+"\n"+b3.getPrice());
379
380 System.out.println("\n"+bob33+"\nTEST11-033* utility of b1 "+b1+"\nfor "+bob33.getName()+" is: "+bob33.getUtility(b1)+"\n"+bob33.getWishlist().getPrice()+"\n"+b1.getPrice());
381
382 System.out.println("\n"+bob33+"\nTEST11-0333* utility of b1 "+aaa+"\nfor "+bob33.getName()+" is: "+bob33.getUtility(aaa)+"\n"+bob33.getWishlist().getPrice()+"\n"+aaa.getPrice());
383
384
385
386
387
388
389 Utility_Function u333=new UF_prcntQTYandprcntPrice(b3,0.8,0.8);
390 Agent bob333 = new Agent();
391 bob333.setName("Bob333");
392 bob333.setWishlist(b3);
393 bob333.setUtility(u333);
394 bob333.setDeadline(100);
395
396 System.out.println("\n"+bob333+"\nTEST11-03* utility of b1 "+b3+"\nfor "+bob333.getName()+" is: "+bob333.getUtility(b3)+"\n"+bob333.getWishlist().getPrice()+"\n"+b3.getPrice());
397
398 System.out.println("\n"+bob333+"\nTEST11-033* utility of b1 "+b1+"\nfor "+bob333.getName()+" is: "+bob333.getUtility(b1)+"\n"+bob333.getWishlist().getPrice()+"\n"+b1.getPrice());
399
400 System.out.println("\n"+bob333+"\nTEST11-0333* utility of b1 "+aaa+"\nfor "+bob333.getName()+" is: "+bob333.getUtility(aaa)+"\n"+bob333.getWishlist().getPrice()+"\n"+aaa.getPrice());
401
402
403
404 Utility_Function u7=new UF_75pQtyOrNothing(a);
405 Agent barbara = new Agent();
406 barbara.setName("Barbara");
407 barbara.setWishlist(a);
408 barbara.setUtility(u7);
409 barbara.setDeadline(10);
410
411 System.out.println("\n"+barbara+"\nTEST11-09* utility of bundle a "+a+"\nfor "+barbara.getName()+" is: "+barbara.getUtility(a)+" size of wishlist "+barbara.getWishlist().size()+ " "+(double)barbara.getWishlist().size()*0.75);
412
413 System.out.println("\n"+barbara+"\nTEST11-10* utility of bundle aaaa "+aaaa+"\nfor "+barbara.getName()+" is: "+barbara.getUtility(aaaa));
414
415 barbara.printUtility(aaa);
416
417
418
419
420 }
421
422}
Note: See TracBrowser for help on using the repository browser.