source: src/main/java/bargainingchips/ChipIssueValue.java@ 340

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

An extended version of Buyer (BuyerExtended), which can be constructed using one among many utility functions. UF_LessPrice and seven complex utility functions based on price+quantity and two types of weights: UF_LessPriceCloseToQuantity, UF_IntensifiedLessPriceCloseToQuantity, UF_PeakedPricePeakedQuantity, UF_PeakedFlatPricePeakedFlatQuantity, UF_PeakedFlatCurvePriceGaussianQuantity, UF_BezierPriceBezierQuantity, and UF_BezierPriceGaussianQuantity. Two more fundamental helper classes: ChipIssueValue, ChipIssueValueBuilder. Adding a validity check to Stack. An update in Bundle main. Adding getSampleBid function to Bid. An update in k variable in Agent. A UF class and UtilityHelperMethods for individual passing utility functions. Adding some more tests in UF_CloseToQuantity main. An update on BundleTest.

File size: 2.1 KB
Line 
1/**
2 *
3 */
4package bargainingchips;
5
6import java.util.Collections;
7import java.util.HashMap;
8import java.util.Iterator;
9import java.util.Map;
10
11/**
12 * This class contains useful functions in dealing with values related to {@link Chip},
13 * i.e., issue values.
14 * For example, BreakEvenPrices, Deviation of Quantities, etc. are defined of this type.
15 *
16 * @author Faria Nassiri-Mofakham
17 *
18 */
19public class ChipIssueValue<T> implements Iterable<Chip>
20{
21 protected Map<Chip, T> i;
22
23 public ChipIssueValue()
24 {
25 i = new HashMap<Chip, T>();
26 }
27
28 public ChipIssueValue(Map<Chip, T> values)
29 {
30 Map<Chip, T> tmpListOfHolding = new HashMap<Chip,T>();
31 tmpListOfHolding.putAll(values);
32 this.i = Collections.unmodifiableMap(tmpListOfHolding);
33 }
34
35 /**
36 * @return the issue value of Chip, in type T
37 */
38 public T getUnitValue(Chip c)
39 {
40 return i.get(c);
41 }
42
43
44// private String writeT<T[]>()
45// {
46// String s = "";
47// T[] j;
48// for (Chip c: t.keySet())
49// {
50// j= t.get(c);
51// System.out.println("j: "+j);
52// for (int k=0; k<j.length; k++)
53// s += j[k].toString();
54// }
55// return s;
56// }
57
58// private String writeT(ChipIssueValue<T[]> t)
59// {
60// String s = "";
61// T[] j;
62// for (Chip c: t)
63// {
64// j= t.getUnitValue(c);
65// //System.out.println("j: "+j);
66// for (int k=0; k<j.length; k++)
67// s += j[k].toString()+" ";
68// }
69// return s;
70// }
71
72
73 @Override
74 public Iterator<Chip> iterator()
75 {
76 return i.keySet().iterator();
77 }
78
79 @Override
80 public String toString()
81 {
82 return i.toString();
83 }
84
85
86 public static <Int> void main(String[] args)
87 {
88 ChipIssueValue<Double> priceDev = new ChipIssueValueBuilder()
89 .addIssue("Red", 7.0)
90 .addIssue("Green", 3.0)
91 .addIssue("Purple", 2.0)
92 .build();
93
94 ChipIssueValue<Int> qtyDev = new ChipIssueValueBuilder()
95 .addIssue("Red", 3)
96 .addIssue("Yellow", 1)
97 .addIssue("Green", 1)
98 .build();
99
100 System.out.println("`Double' Standard deviation of Chips prices are: "+priceDev);
101 System.out.println("`Int' Standard deviation of Chips quantities are: "+qtyDev);
102 }
103
104
105}
106
107
Note: See TracBrowser for help on using the repository browser.