source: src/main/java/agents/anac/y2011/HardHeaded/BidSelector.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.7 KB
Line 
1package agents.anac.y2011.HardHeaded;
2
3import java.util.HashMap;
4import java.util.List;
5import java.util.TreeMap;
6
7import genius.core.Bid;
8import genius.core.issue.Issue;
9import genius.core.issue.IssueDiscrete;
10import genius.core.issue.Value;
11import genius.core.utility.AdditiveUtilitySpace;
12import genius.core.utility.UtilitySpace;
13
14/**
15 * This class generates all possible bids that can be offered according to a
16 * given domain. The bids are stored in a treeMap structure sorted by the order
17 * of their utility for the agent.
18 *
19 */
20public class BidSelector {
21 protected UtilitySpace utilitySpace;
22 TreeMap<Double, Bid> BidList;
23
24 /**
25 * BidSelector constructor
26 *
27 * @param pUtilitySpace
28 * a passed {@link AdditiveUtilitySpace} that is used to generate
29 * all possible bid of its domain
30 */
31 public BidSelector(UtilitySpace pUtilitySpace) {
32
33 this.utilitySpace = pUtilitySpace;
34 BidList = new TreeMap<Double, Bid>();
35
36 List<Issue> issues = utilitySpace.getDomain().getIssues();
37
38 HashMap<Integer, Value> InitialBid = new HashMap<Integer, Value>();
39 for (Issue lIssue : issues) {
40 Value v = ((IssueDiscrete) lIssue).getValue(0);
41 InitialBid.put(lIssue.getNumber(), v);
42 }
43 try {
44 Bid b = new Bid(utilitySpace.getDomain(), InitialBid);
45 BidList.put(utilitySpace.getUtility(b), b);
46 }
47
48 catch (Exception e) {
49 e.printStackTrace();
50 }
51
52 for (Issue lIssue : issues) {
53
54 TreeMap<Double, Bid> TempBids = new TreeMap<Double, Bid>();
55
56 IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
57 int optionIndex = lIssueDiscrete.getNumberOfValues();
58
59 // a small value is added to bid utilities, so that their ordering
60 // inside the
61 // TreeMap would be attained
62 double d = -0.00000001;
63 for (Bid TBid : BidList.values()) {
64 for (int i = 0; i < optionIndex; i++) {
65 HashMap<Integer, Value> NewBidV = Bidconfig(TBid);
66 NewBidV.put(lIssue.getNumber(),
67 ((IssueDiscrete) lIssue).getValue(i));
68 try {
69 Bid webid = new Bid(utilitySpace.getDomain(), NewBidV);
70 TempBids.put(utilitySpace.getUtility(webid) + d, webid);
71 d = d - 0.00000001;
72 } catch (Exception e) {
73 }
74
75 }
76 BidList = TempBids;
77 }
78 }
79 }
80
81 /**
82 * receives a bid an generates all possible configurations of it
83 *
84 * @param pBid
85 * passed bid
86 * @return a {@link HashMap} containing all configurations of a possible
87 * bid.
88 */
89 private HashMap<Integer, Value> Bidconfig(Bid pBid) {
90 HashMap<Integer, Value> lNewBidValues = new HashMap<Integer, Value>();
91
92 for (Issue lIssue : this.utilitySpace.getDomain().getIssues()) {
93 try {
94 lNewBidValues.put(lIssue.getNumber(),
95 pBid.getValue(lIssue.getNumber()));
96 } catch (Exception e) {
97 }
98 }
99 return lNewBidValues;
100 }
101}
Note: See TracBrowser for help on using the repository browser.