1 | package agents.anac.y2018.ponpokorampage;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Collections;
|
---|
7 | import java.util.Comparator;
|
---|
8 | import java.util.HashMap;
|
---|
9 | import java.util.HashSet;
|
---|
10 | import java.util.Map;
|
---|
11 | import java.util.Random;
|
---|
12 | import java.util.Set;
|
---|
13 |
|
---|
14 | import genius.core.AgentID;
|
---|
15 | import genius.core.Bid;
|
---|
16 | import genius.core.Domain;
|
---|
17 | import genius.core.actions.Accept;
|
---|
18 | import genius.core.actions.Action;
|
---|
19 | import genius.core.actions.EndNegotiation;
|
---|
20 | import genius.core.actions.Offer;
|
---|
21 | import genius.core.parties.AbstractNegotiationParty;
|
---|
22 | import genius.core.parties.NegotiationInfo;
|
---|
23 | import genius.core.utility.UtilitySpace;
|
---|
24 |
|
---|
25 |
|
---|
26 | public 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 |
|
---|
154 |
|
---|
155 | @Override
|
---|
156 | public String getDescription() {
|
---|
157 | return "anac2018/ponpokorampage";
|
---|
158 | }
|
---|
159 |
|
---|
160 | }
|
---|
161 |
|
---|
162 | class AgentTool{
|
---|
163 |
|
---|
164 | private static Random random = new Random();
|
---|
165 |
|
---|
166 | public static Bid selectBidfromList( List<BidInfo> bidInfoList, double higerutil, double lowwerutil){
|
---|
167 | List<BidInfo> bidInfos = new ArrayList<>();
|
---|
168 | bidInfoList.forEach(bidInfo -> {
|
---|
169 | if (bidInfo.getutil() <= higerutil && bidInfo.getutil() >= lowwerutil){
|
---|
170 | bidInfos.add(bidInfo);
|
---|
171 | }
|
---|
172 | });
|
---|
173 | if (bidInfos.size() == 0){
|
---|
174 | return null;
|
---|
175 | }
|
---|
176 | else {
|
---|
177 | return bidInfos.get(random.nextInt(bidInfos.size())).getBid();
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | public static Set<BidInfo> generateRandomBids(Domain d, int numberOfBids, Random random, UtilitySpace utilitySpace){
|
---|
182 | Set<BidInfo> randombids = new HashSet<>();
|
---|
183 | for (int i = 0; i < numberOfBids; i++){
|
---|
184 | Bid b = d.getRandomBid(random);
|
---|
185 | randombids.add(new BidInfo(b, utilitySpace.getUtility(b)));
|
---|
186 | }
|
---|
187 | return randombids;
|
---|
188 | }
|
---|
189 |
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | //bidとその効用を保存するクラス
|
---|
194 | class BidInfo{
|
---|
195 | Bid bid;
|
---|
196 | double util;
|
---|
197 | public BidInfo( Bid b ){
|
---|
198 | this.bid = b;
|
---|
199 | util = 0.0;
|
---|
200 | }
|
---|
201 | public BidInfo( Bid b , double u){
|
---|
202 | this.bid = b;
|
---|
203 | util = u;
|
---|
204 | }
|
---|
205 |
|
---|
206 | public void setutil(double u){
|
---|
207 | util = u;
|
---|
208 | }
|
---|
209 |
|
---|
210 | public Bid getBid(){
|
---|
211 | return bid;
|
---|
212 | }
|
---|
213 |
|
---|
214 | public double getutil(){
|
---|
215 | return util;
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | @Override
|
---|
220 | public int hashCode() {
|
---|
221 | return bid.hashCode();
|
---|
222 | }
|
---|
223 |
|
---|
224 | public boolean equals(BidInfo bidInfo) {
|
---|
225 | return bid.equals(bidInfo.getBid());
|
---|
226 | }
|
---|
227 |
|
---|
228 | @Override
|
---|
229 | public boolean equals(Object obj){
|
---|
230 | if ( obj == null){
|
---|
231 | return false;
|
---|
232 | }
|
---|
233 | if ( obj instanceof BidInfo){
|
---|
234 | return ((BidInfo)obj).getBid().equals(bid);
|
---|
235 | }else {
|
---|
236 | return false;
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | }
|
---|
241 |
|
---|
242 | final class BidInfoComp implements Comparator<BidInfo> {
|
---|
243 | BidInfoComp(){
|
---|
244 | super();
|
---|
245 | }
|
---|
246 | @Override
|
---|
247 | public int compare(BidInfo o1, BidInfo o2) {
|
---|
248 | return Double.compare(o1.getutil(), o2.getutil());
|
---|
249 | }
|
---|
250 | }
|
---|