source: src/main/java/parties/in4010/q12015/group1/Group1.java@ 1

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

Initial import : Genius 9.0.0

File size: 6.0 KB
Line 
1package parties.in4010.q12015.group1;
2
3import java.util.HashMap;
4import java.util.List;
5import java.util.Random;
6
7import genius.core.AgentID;
8import genius.core.Bid;
9import genius.core.BidHistory;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.DefaultAction;
13import genius.core.actions.Offer;
14import genius.core.bidding.BidDetails;
15import genius.core.boaframework.SortedOutcomeSpace;
16import genius.core.issue.Issue;
17import genius.core.issue.IssueDiscrete;
18import genius.core.issue.IssueInteger;
19import genius.core.issue.IssueReal;
20import genius.core.issue.Value;
21import genius.core.issue.ValueInteger;
22import genius.core.issue.ValueReal;
23import genius.core.misc.Range;
24import genius.core.parties.AbstractNegotiationParty;
25
26public class Group1 extends AbstractNegotiationParty {
27 private double MINIMUM_BID_UTILITY;
28 private Bid opponentLastBid;
29 public Action action = null;
30 Bid bid = null;
31 BidHistory bidHistory;
32 SortedOutcomeSpace sortedOutcomeSpace;
33 List<BidDetails> bidDetailsList;
34 HashMap<Integer, Value> values = new HashMap<Integer, Value>();
35 int counter = 0;
36
37 public void OpponentAction(Action opponentAction) {
38 bidHistory = new BidHistory();
39 opponentLastBid = DefaultAction.getBidFromAction(opponentAction); // Extracting
40 // Bid from
41 // opponent
42 // Action
43 System.out.println(opponentAction.toString());
44 if (getUtility(opponentLastBid) != 0) {
45 BidDetails bd = new BidDetails(opponentLastBid,
46 getUtility(opponentLastBid)); // Extracting Bid details of
47 // each Bid
48 System.out.println("He " + bd.toString());
49 bidHistory.add(bd);
50 bidHistory.sortToUtility(); // Sorting Bid History by Utility values
51 }
52 System.out.println("Opponent's bid history is :"
53 + bidHistory.toString());
54 }
55
56 public void init() // Setting minimum Bid Utility value as per time
57 // variation
58 {
59 if (timeline.getTime() < 0.9)
60 MINIMUM_BID_UTILITY = 0.8;
61 else if (timeline.getTime() < 0.96 && timeline.getTime() > 0.9)
62 MINIMUM_BID_UTILITY = 0.7;
63 else
64 MINIMUM_BID_UTILITY = 0.3;
65 System.out.println("Minium bid utility is :" + MINIMUM_BID_UTILITY);
66 }
67
68 @Override
69 public Action chooseAction(List<Class<? extends Action>> validActions) {
70 init();
71 if (!validActions.contains(Accept.class)) // Checking for first Bid
72 {
73 try {
74 return new Offer(getPartyId(), generateNewBid());
75 } catch (Exception e) {
76 e.printStackTrace();
77 return null;
78 }
79 } else {
80 if (opponentLastBid != null
81 && getUtility(opponentLastBid) >= MINIMUM_BID_UTILITY) // point
82 // of
83 // acceptance
84 return new Accept(getPartyId(), opponentLastBid);
85 else {
86 try {
87 return new Offer(getPartyId(), generateNewBid());
88 } catch (Exception e) {
89 e.printStackTrace();
90 return null;
91 }
92 }
93 }
94 }
95
96 private Bid generateNewBid() throws Exception // generating a new Bid in
97 // Cyclic manner
98 {
99 System.out.println(counter);
100 int size = bidDetailsList.size();
101 BidDetails p = bidDetailsList.get(counter);
102 bid = p.getBid();
103 if (counter + 1 == size)
104 counter = 0;
105 else
106 counter++;
107 return bid;
108 }
109
110 private Bid generateNewBidContinous() throws Exception // Placing bids for
111 // continuous domain
112 {
113 List<Issue> issues = utilitySpace.getDomain().getIssues();
114 Random randomnr = new Random();
115 do {
116 for (Issue lIssue : issues) {
117 switch (lIssue.getType()) {
118 case DISCRETE:
119 IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
120 int optionIndex = randomnr.nextInt(lIssueDiscrete
121 .getNumberOfValues());
122 values.put(lIssue.getNumber(),
123 lIssueDiscrete.getValue(optionIndex));
124 break;
125 case REAL:
126 IssueReal lIssueReal = (IssueReal) lIssue;
127 int optionInd = randomnr.nextInt(lIssueReal
128 .getNumberOfDiscretizationSteps() - 1);
129 values.put(
130 lIssueReal.getNumber(),
131 new ValueReal(lIssueReal.getLowerBound()
132 + (lIssueReal.getUpperBound() - lIssueReal
133 .getLowerBound())
134 * (double) (optionInd)
135 / (double) (lIssueReal
136 .getNumberOfDiscretizationSteps())));
137 break;
138 case INTEGER:
139 IssueInteger lIssueInteger = (IssueInteger) lIssue;
140 int optionIndex2 = lIssueInteger.getLowerBound()
141 + randomnr.nextInt(lIssueInteger.getUpperBound()
142 - lIssueInteger.getLowerBound());
143 values.put(lIssueInteger.getNumber(), new ValueInteger(
144 optionIndex2));
145 break;
146 default:
147 System.out.println("not in any type");
148 }
149 }
150 bid = new Bid(utilitySpace.getDomain(), values);
151 } while (getUtility(bid) < MINIMUM_BID_UTILITY);
152 for (Integer name : values.keySet()) {
153 String key = name.toString();
154 String value = values.get(name).toString();
155 System.out.println(key + " " + value);
156 }
157 return bid;
158 }
159
160 @Override
161 public void receiveMessage(AgentID sender, Action action) {
162 OpponentAction(action);
163 if (timeline.getTime() < 0.9) {
164 Range r = new Range(0.8, 1); // extracting bids in utility range of
165 // 1 and 0.8
166 sortedOutcomeSpace = new SortedOutcomeSpace(this.getUtilitySpace());
167 bidDetailsList = sortedOutcomeSpace.getBidsinRange(r);
168 ;
169 } else if (timeline.getTime() > 0.9 && timeline.getTime() < 0.96) {
170 Range r = new Range(0.7, 1); // extracting bids from opponents bids
171 // which has utility range from 1
172 // to0.7 for us
173 sortedOutcomeSpace = new SortedOutcomeSpace(this.getUtilitySpace());
174 bidDetailsList = sortedOutcomeSpace.getBidsinRange(r);
175 bidDetailsList.addAll(bidHistory.getHistory());
176 } else {
177 Range r = new Range(0.5, 0.7); // extracting bids in utility range
178 // of 0.7 and 0.5
179 sortedOutcomeSpace = new SortedOutcomeSpace(this.getUtilitySpace());
180 bidDetailsList = sortedOutcomeSpace.getBidsinRange(r);
181 }
182 }
183
184 @Override
185 public String getDescription() {
186 return "Negotiation Agent Group 1";
187 }
188}
Note: See TracBrowser for help on using the repository browser.