source: src/main/java/agents/anac/y2018/ponpokorampage/PonPokoRampage.java@ 345

Last change on this file since 345 was 345, checked in by Tim Baarslag, 4 years ago

Fixed agent 2018 descriptions

File size: 5.9 KB
Line 
1package agents.anac.y2018.ponpokorampage;
2
3import java.util.List;
4
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.Comparator;
8import java.util.HashMap;
9import java.util.HashSet;
10import java.util.Map;
11import java.util.Random;
12import java.util.Set;
13
14import genius.core.AgentID;
15import genius.core.Bid;
16import genius.core.Domain;
17import genius.core.actions.Accept;
18import genius.core.actions.Action;
19import genius.core.actions.EndNegotiation;
20import genius.core.actions.Offer;
21import genius.core.parties.AbstractNegotiationParty;
22import genius.core.parties.NegotiationInfo;
23import genius.core.utility.UtilitySpace;
24
25
26public class PonPokoRampage extends AbstractNegotiationParty {
27
28 private Bid lastReceivedBid = null;
29 private Domain domain = null;
30
31 private Map<String, List<Bid>> hoge;
32 private Map<String, Boolean> hardliner;
33
34 private List<BidInfo> lBids;
35
36 private double threshold_low = 0.99;
37 private double threshold_high = 1.0;
38
39 private final int PATTERN_SIZE = 5;
40 private int pattern = 0;
41// PrintStream out;
42 private int count = 0;
43
44 @Override
45 public void init(NegotiationInfo info) {
46
47// try {
48// out = new PrintStream("C:\\debug.log");
49// }catch (Exception e){
50//
51// }
52
53 super.init(info);
54 this.domain = info.getUtilitySpace().getDomain();
55
56// long a = System.currentTimeMillis();
57 lBids = new ArrayList<>(AgentTool.generateRandomBids(this.domain, 30000, this.rand, this.utilitySpace ) );
58 Collections.sort(lBids, new BidInfoComp().reversed() );
59// out.println(System.currentTimeMillis() -a);
60 hoge = new HashMap<>();
61 hardliner = new HashMap<>();
62
63
64 pattern = rand.nextInt(PATTERN_SIZE);
65 }
66
67 @Override
68 public Action chooseAction(List<Class<? extends Action>> validActions) {
69 count++;
70 long a = System.currentTimeMillis();
71
72 if (utilitySpace.getReservationValue() >= 0.9){
73 return new EndNegotiation(getPartyId());
74 }
75
76 if (count % 200 == 199){
77 hoge.forEach( (k ,v) -> {
78 //out.println((new HashSet<>(v)).size());
79 if( (new HashSet<>(v)).size() < 20 * getTimeLine().getTime()){
80 hardliner.put(k,Boolean.TRUE);
81 }
82 else {
83 hardliner.put(k, Boolean.FALSE);
84 }
85 });
86 }
87
88 //譲歩度合いの設定
89 if (pattern == 0) {
90 threshold_high = 1 - 0.1 * timeline.getTime();
91 threshold_low = 1 - 0.2 * timeline.getTime() - 0.1 * Math.abs(Math.sin(this.timeline.getTime() * 16));
92 }
93 else if (pattern == 1){
94 threshold_high = 1;
95 threshold_low = 1 - 0.22 * timeline.getTime();
96 }
97 else if (pattern == 2){
98 threshold_high = 1 - 0.1 * timeline.getTime();
99 threshold_low = 1 - 0.1 * timeline.getTime() - 0.15 * Math.abs(Math.sin(this.timeline.getTime() * 32));
100 }
101 else if (pattern == 3){
102 threshold_high = 1 - 0.05 * timeline.getTime();
103 threshold_low = 1 - 0.2 * timeline.getTime();
104 if (timeline.getTime() > 0.98){
105 threshold_low = 1 - 0.3 * timeline.getTime();
106 }
107 }else if (pattern == 4){
108 threshold_high = 1 - 0.15 * this.timeline.getTime() * Math.abs(Math.sin(this.timeline.getTime() * 32));
109 threshold_low = 1 - 0.25 * this.timeline.getTime() * Math.abs(Math.sin(this.timeline.getTime() * 32));
110 }
111 else {
112 System.out.println("pattern error");
113 threshold_high = 1 - 0.1 * timeline.getTime();
114 threshold_low = 1 - 0.2 * Math.abs(Math.sin(this.timeline.getTime() * 64));
115 }
116
117 if (hardliner.containsValue(Boolean.TRUE)){
118 threshold_low += 0.05;
119 }
120
121 //Accept判定
122 if ( lastReceivedBid != null) {
123 if (getUtility(lastReceivedBid) > threshold_low ){
124 return new Accept(getPartyId(), lastReceivedBid);
125 }
126 }
127
128 //Offerするbidの選択
129 Bid bid = null;
130 while (bid == null){
131 bid = AgentTool.selectBidfromList(this.lBids, this.threshold_high, this.threshold_low);
132 if (bid == null) {
133 threshold_low -= 0.001;
134 }
135 }
136 return new Offer(getPartyId(), bid);
137 }
138
139 @Override
140 public void receiveMessage(AgentID sender, Action action) {
141 super.receiveMessage(sender, action);
142 if (action instanceof Offer) {
143 lastReceivedBid = ((Offer) action).getBid();
144 if (hoge.containsKey(sender.getName())){
145 hoge.get(sender.getName()).add(((Offer) action).getBid());
146 }else {
147 hoge.put(sender.getName(), new ArrayList<>());
148 hoge.get(sender.getName()).add( ((Offer) action).getBid());
149 }
150 }
151 }
152
153 @Override
154 public String getDescription() {
155 return "ANAC2018";
156 }
157
158}
159
160class AgentTool{
161
162 private static Random random = new Random();
163
164 public static Bid selectBidfromList( List<BidInfo> bidInfoList, double higerutil, double lowwerutil){
165 List<BidInfo> bidInfos = new ArrayList<>();
166 bidInfoList.forEach(bidInfo -> {
167 if (bidInfo.getutil() <= higerutil && bidInfo.getutil() >= lowwerutil){
168 bidInfos.add(bidInfo);
169 }
170 });
171 if (bidInfos.size() == 0){
172 return null;
173 }
174 else {
175 return bidInfos.get(random.nextInt(bidInfos.size())).getBid();
176 }
177 }
178
179 public static Set<BidInfo> generateRandomBids(Domain d, int numberOfBids, Random random, UtilitySpace utilitySpace){
180 Set<BidInfo> randombids = new HashSet<>();
181 for (int i = 0; i < numberOfBids; i++){
182 Bid b = d.getRandomBid(random);
183 randombids.add(new BidInfo(b, utilitySpace.getUtility(b)));
184 }
185 return randombids;
186 }
187
188}
189
190
191//bidとその効用を保存するクラス
192class BidInfo{
193 Bid bid;
194 double util;
195 public BidInfo( Bid b ){
196 this.bid = b;
197 util = 0.0;
198 }
199 public BidInfo( Bid b , double u){
200 this.bid = b;
201 util = u;
202 }
203
204 public void setutil(double u){
205 util = u;
206 }
207
208 public Bid getBid(){
209 return bid;
210 }
211
212 public double getutil(){
213 return util;
214 }
215
216
217 @Override
218 public int hashCode() {
219 return bid.hashCode();
220 }
221
222 public boolean equals(BidInfo bidInfo) {
223 return bid.equals(bidInfo.getBid());
224 }
225
226 @Override
227 public boolean equals(Object obj){
228 if ( obj == null){
229 return false;
230 }
231 if ( obj instanceof BidInfo){
232 return ((BidInfo)obj).getBid().equals(bid);
233 }else {
234 return false;
235 }
236 }
237
238}
239
240final class BidInfoComp implements Comparator<BidInfo> {
241 BidInfoComp(){
242 super();
243 }
244 @Override
245 public int compare(BidInfo o1, BidInfo o2) {
246 return Double.compare(o1.getutil(), o2.getutil());
247 }
248}
Note: See TracBrowser for help on using the repository browser.