source: src/main/java/negotiator/onetomany/domain/oldAggregations.java@ 244

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

Bug in classes Chip, Stack and operations, Bundle and operations fixed; they work well. Old versions of aggregation operators and tests copied into an old file.

File size: 16.4 KB
Line 
1//import java.util.Arrays;
2//
3// public Bundle aggregateWith333(Bundle b)
4// {
5// if (b!=null && this!=null)
6// {
7// Bundle l=new Bundle();
8//
9// for (Stack s : b.getBundle())
10// {
11// l=this.aggregateWith(s);
12// }
13// return l;
14// }
15// return this;
16// }
17//
18//public Bundle aggregateWith(Bundle b)
19// {
20// if (b!=null && this!=null)
21// {
22// Bundle l=new Bundle();
23//
24// for (Stack s : b.getBundle())
25// {
26// l=this.aggregateWith(s); // due to parallel actions on all stacks in a nested manner, sometimes some strange results, when the second bundle has multiple stacks (doesn't matter if any shared colors or not!!
27//// Boolean f=false;
28//// for (int i=1; i<this.size();i++)
29//// {
30//// Stack t= this.getBundle().get(i);
31//// t.aggregateWith(s);
32////
33////
34//// for (Stack t : this.getBundle())
35//// {
36//// if (t.getChip().getColor()==s.getChip().getColor())
37//// {
38//// l.addStack(t.aggregateWith(s));
39//// f=true;
40//// }
41//// else
42//// l.addStack(t);
43//// }
44//// if (!f)
45//// l.addStack(s);
46// }
47// return l;
48// }
49// return this;
50// }
51//
52//
53// public int findStack(Stack s)
54// {
55// int i=-1; //not found
56// if (s!=null)
57// for (int j=0;j<this.size();j++)
58// {
59// if (s.getChip().getColor()==this.getStack(j).getChip().getColor())
60// {
61// i=j;
62// break;
63// }
64// }
65// return i;
66// }
67//
68//
69// public Bundle aggregateWith2(Stack s)
70// {
71// if (s!=null && this!=null && findStack(s)>=0)
72// {
73// Bundle b=new Bundle();
74// Boolean f=false;
75//
76// for (int i=0; i<this.size();i++)
77// {
78// Stack t=this.getStack(i);
79// if (t.getChip().getColor()==s.getChip().getColor())
80// {
81// b.addStack(t.aggregateWith(s));
82// f=true;
83// }
84// else
85// b.addStack(t);
86// }
87// if (!f) //s not aggregated with any stack in `this' bundle
88// b.addStack(s);
89// return b;
90// }
91// return this;
92// }
93//
94//
95// public Bundle aggregateWith2(Bundle b)
96// {
97// if (b!=null && this!=null)
98// {
99// Bundle l=new Bundle();
100//
101// for (Stack s : b.getBundle())
102// {
103// l=this.aggregateWith2(s);
104// }
105// return l;
106// }
107// return this;
108// }
109//
110// public Bundle aggregateWith3(Bundle b)
111// {
112// if (b!=null && this!=null)
113// {
114// Bundle l=new Bundle();
115// //Boolean[] f1= {}; //flag for b bundle stack added
116// //Boolean[] f2= {}; //flag for `this' bundle stack added
117// Boolean[] f2 = new Boolean[this.size()]; //flag for `this' bundle stack added
118// Arrays.fill(f2, Boolean.FALSE);
119//
120// for (int j=0;j<b.size();j++) //loop over bundle b stacks
121// {
122// Stack s=b.getStack(j);
123//
124// for (int i=0; i<this.size();i++) //loop over `this' bundle stacks
125// {
126// int k=findStack(s);
127// if (k>=0)
128// {
129// Stack t= this.getStack(k);
130// l.addStack(t.aggregateWith(s));
131// //f1[j]=true; // this stack of b bundle considered into the new bundle
132// f2[k]=true; // this stack of `this' bundle considered into the new bundle
133// }
134// else
135// {
136// l.addStack(s);
137// //f1[j]=true; // this stack of b bundle directly added into the new bundle
138// }
139// }
140// }
141// for (int i=1;i<this.size();i++)
142// if (f2[i]!=true)
143// l.addStack(this.getStack(i));
144//
145// //and no need to check for f1, because in if or else above have been considered
146//
147// return l;
148// }
149// return this;
150// }
151//
152//
153// public Bundle aggregateWith333(Bundle b)
154// {
155// if (b!=null && this!=null)
156// {
157// Bundle l=new Bundle();
158//
159// for (Stack s : b.getBundle())
160// {
161// l=this.aggregateWith3(s);
162// }
163// return l;
164// }
165// return this;
166// }
167//
168//
169// public Bundle aggregateWith4(Bundle b)
170// {
171// if (b!=null && this!=null)
172// {
173// Bundle l=new Bundle();
174// int i;
175// for (i=1;i<this.size();i++)
176// l.addStack(this.getStack(i));
177//
178// for (int j=0;j<b.size();j++) //loop over bundle b stacks
179// {
180// Stack s=b.getStack(j);
181// i=findStack(s);
182// if (i>=0) // the color of j-th stack of bundle b found in i-th stack of `this' bundle
183// {
184// l.aggregateWith2(this.getStack(i)); //aggregate these two stacks into the new bundle l <-- aggregateWith2 stack (difference with aggregateWith5 bundle)
185// }
186// else
187// l.addStack(s); // so put j-th stack of bundle b directly into the new bundle
188// // and other stacks of `this' bundle have already been in the new bundle!
189// }
190// return l;
191// }
192// return this;
193// }
194//
195//
196// public Bundle aggregateWith5(Bundle b)
197// {
198// if (b!=null && this!=null)
199// {
200// Bundle l=new Bundle();
201// int i;
202// for (i=1;i<this.size();i++)
203// l.addStack(this.getStack(i));
204//
205// for (int j=0;j<b.size();j++) //loop over bundle b stacks
206// {
207// Stack s=b.getStack(j);
208// i=findStack(s);
209// if (i>=0) // the color of j-th stack of bundle b found in i-th stack of `this' bundle
210// {
211// l.aggregateWith(this.getStack(i)); //aggregate these two stacks into the new bundle l <-- aggregateWith stack (difference with aggregateWith4 bundle)
212// }
213// else
214// l.addStack(s); // so put j-th stack of bundle b directly into the new bundle
215// // and other stacks of `this' bundle have already been in the new bundle!
216// }
217// return l;
218// }
219// return this;
220// }
221//
222//
223//
224//
225//
226
227
228//OTHER TESTS
229//
230//
231//
232//
233// System.out.println("\nTEST12::: index of stack1 in Bundle1: "+bundle1.findStack(stack1));
234//
235// System.out.println("\nTEST13::: index of stack2 in Bundle1: "+bundle1.findStack(stack2));
236//
237// System.out.println("\nTEST14::: index of null in Bundle1: "+bundle1.findStack(null));
238//
239// s=new Stack(new Chip("Yellow", 8),40);
240//
241// System.out.println("\nTEST15::: index of stack "+s+" in Bundle1: "+bundle1.findStack(s));
242
243//
244//
245//System.out.println("\n*TEST6-02:::Bundle1: "+bundle1+" is aggregated with Stack "+ss+" as follows:\n"+bundle1.aggregateWith2(ss));
246//System.out.println("\n*TEST6:::Bundle1: "+bundle1+" is aggregated with Stack: 40 x Chip(Yellow, 8$) as follows:\n"+bundle1.aggregateWith2(new Stack(new Chip("Yellow", 8),40)));
247//System.out.println("\n*TEST6-03:::Bundle1: "+bundle1+" is aggregated with Stack "+sss+" as follows:\n"+bundle1.aggregateWith2(sss));
248//
249//
250//
251//System.out.println("\n*TEST7:::Bundle1: "+bundle1+" is aggregated with ``null Stack'' as follows:\n"+bundle1.aggregateWith2(ssss));
252//
253//
254//System.out.println("\n-----aggregateWith-----");
255//
256//
257//
258//
259//System.out.println("\n*TEST9-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated with ``null'' bundle5 as follows:\n"+ b2.aggregateWith(bundle5));
260//
261//
262//System.out.println("\n*TEST9-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated with ``null'' bundle5 as follows:\n"+ b1.aggregateWith(bundle5));
263//
264//
265//System.out.println("\n*TEST9-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith(b5));
266//
267//System.out.println("\n*TEST9-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith(b3));
268//
269//System.out.println("\n*TEST9-05::: With shared colors ::: single stack B2: "+b2+" is aggregated with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith(b6));
270//
271//System.out.println("\n*TEST9-06::: With shared colors ::: single stack B2: "+b2+" is aggregated with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith(b1));
272//
273//
274//System.out.println("\n*TEST9-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith(b3));
275//
276//
277//System.out.println("\n*TEST9-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith(b2));
278//
279//System.out.println("\n*TEST9-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith(b4));
280//
281//
282//System.out.println("\n-----aggregateWith2-----");
283//
284//
285//System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith2(bundle5));
286//
287//
288//System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith2(bundle5));
289//
290//
291//System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith2(b5));
292//
293//System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith2(b3));
294//
295//System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith2(b6));
296//
297//System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith2(b1));
298//
299//
300//System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith2(b3));
301//
302//
303//System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith2(b2));
304//
305//System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith2(b4));
306//
307//
308//System.out.println("\n-----BUNDLEaggregateWith4Bundle (& BUNDLEaggregateWith2Stack)-----");
309//
310//
311//System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith4(bundle5));
312//
313//
314//System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith4(bundle5));
315//
316//
317//System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith4(b5));
318//
319//System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith4(b3));
320//
321//System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith4(b6));
322//
323//System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith4(b1));
324//
325//
326//System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith4(b3));
327//
328//
329//System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith4(b2));
330//
331//System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith4(b4));
332//
333//System.out.println("\n-----BUNDLEaggregateWith5Bundle (& BUNDLEaggregateWithStack)-----");
334//
335//
336//System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith5(bundle5));
337//
338//
339//System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith5(bundle5));
340//
341//
342//System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith5(b5));
343//
344//System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith5(b3));
345//
346//System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith5(b6));
347//
348//System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith5(b1));
349//
350//
351//System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith5(b3));
352//
353//
354//System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith5(b2));
355//
356//System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith5(b4));
357//
358//
359//System.out.println("\n-----BUNDLEaggregateWith33Bundle (& BUNDLEaggregateWithStack)-----");
360//
361//
362//System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith33(bundle5));
363//
364//
365//System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith33(bundle5));
366//
367//
368//System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith33(b5));
369//
370//System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith33(b3));
371//
372//System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith33(b6));
373//
374//System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith33(b1));
375//
376//
377//System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith33(b3));
378//
379//
380//System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith33(b2));
381//
382//System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith33(b4));
383//
384//System.out.println("\n-----BUNDLEaggregateWith333Bundle-----");
385//
386//
387//System.out.println("\n*TEST10-01::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b2.aggregateWith333(bundle5));
388//
389//
390//System.out.println("\n*TEST10-02::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with ``null'' bundle5 as follows:\n"+ b1.aggregateWith333(bundle5));
391//
392//
393//System.out.println("\n*TEST10-03::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b5+" as follows:\n"+ b2.aggregateWith333(b5));
394//
395//System.out.println("\n*TEST10-04::: Without shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b2.aggregateWith333(b3));
396//
397//System.out.println("\n*TEST10-05::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with single stack B5: "+b6+" as follows:\n"+ b2.aggregateWith333(b6));
398//
399//System.out.println("\n*TEST10-06::: With shared colors ::: single stack B2: "+b2+" is aggregated2 with multi stack B3: "+b1+" as follows:\n"+ b2.aggregateWith333(b1));
400//
401//
402//System.out.println("\n*TEST10-07::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B3: "+b3+" as follows:\n"+ b1.aggregateWith333(b3));
403//
404//
405//System.out.println("\n*TEST10-08::: With shared colors ::: multi stack B1: "+b1+" is aggregated2 with single stack B2: "+b2+" as follows:\n"+ b1.aggregateWith333(b2));
406//
407//System.out.println("\n*TEST10-09::: Without shared colors ::: multi stack B1: "+b1+" is aggregated2 with multi stack B2: "+b4+" as follows:\n"+ b1.aggregateWith333(b4));
408//
409//
Note: See TracBrowser for help on using the repository browser.