source: src/main/java/negotiator/onetomany/domain/test.java@ 243

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

Agent class. Utility_Function interface defined. 8 sample utility functions created and all tested. Now, Bundle has getPrice() and Stack has getColor(). Still, aggregation in Bundle class is without iterators (iterators could not work out yet).

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