1 | package agents.anac.y2014.Aster;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Iterator;
|
---|
5 | import java.util.Random;
|
---|
6 |
|
---|
7 | import genius.core.Bid;
|
---|
8 | import genius.core.utility.AbstractUtilitySpace;
|
---|
9 |
|
---|
10 | public class ChooseAction {
|
---|
11 | private AbstractUtilitySpace utilitySpace;
|
---|
12 | private Random rnd;
|
---|
13 | private static final int NUMBER_ITERATIONS = 1000; // 繰り返�回数
|
---|
14 | private static final double EPSILON = 0.3D;
|
---|
15 |
|
---|
16 | public ChooseAction(AbstractUtilitySpace utilitySpace) {
|
---|
17 | this.utilitySpace = utilitySpace;
|
---|
18 | this.rnd = new Random();
|
---|
19 | }
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Select Next Bid (for MultiList)
|
---|
23 | *
|
---|
24 | */
|
---|
25 | public Bid nextOfferingBid(double bidTarget,
|
---|
26 | ArrayList<Bid> selectMyBidList, ArrayList<Bid> opponentBidList)
|
---|
27 | throws Exception {
|
---|
28 | Bid nextBid = null;
|
---|
29 | double nextBidUtil = 0.0;
|
---|
30 | int iteration = 0;
|
---|
31 |
|
---|
32 | do {
|
---|
33 | if (Math.random() > EPSILON) {
|
---|
34 | nextBid = selectWeightedBid(opponentBidList);
|
---|
35 | } else {
|
---|
36 | nextBid = selectRandomBid(selectMyBidList,
|
---|
37 | selectMyBidList.size());
|
---|
38 | }
|
---|
39 | nextBidUtil = utilitySpace.getUtility(nextBid);
|
---|
40 | } while ((nextBidUtil < bidTarget) && (++iteration < NUMBER_ITERATIONS));
|
---|
41 |
|
---|
42 | return nextBid;
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * SelectionNextBid
|
---|
47 | *
|
---|
48 | */
|
---|
49 | public Bid nextOfferingBid(double bidTarget, ArrayList<Bid> bidList,
|
---|
50 | boolean select_flag) throws Exception {
|
---|
51 | Bid nextBid = null;
|
---|
52 | double nextBidUtil = 0.0;
|
---|
53 | int iteration = 0;
|
---|
54 | int listSize = bidList.size();
|
---|
55 |
|
---|
56 | if (listSize == 1) {
|
---|
57 | return bidList.get(0);
|
---|
58 | }
|
---|
59 |
|
---|
60 | do {
|
---|
61 | if (select_flag) {
|
---|
62 | nextBid = selectRandomBid(bidList, listSize);
|
---|
63 | } else {
|
---|
64 | nextBid = selectWeightedBid(bidList);
|
---|
65 | }
|
---|
66 | nextBidUtil = utilitySpace.getUtility(nextBid);
|
---|
67 | } while ((nextBidUtil < bidTarget) && (++iteration < NUMBER_ITERATIONS));
|
---|
68 |
|
---|
69 | return nextBid;
|
---|
70 | }
|
---|
71 |
|
---|
72 | // SelectNextBid(Weighted)
|
---|
73 | private Bid selectWeightedBid(ArrayList<Bid> bidList) {
|
---|
74 | int totalUtil = 0;
|
---|
75 | int index = 0;
|
---|
76 | int listSize = bidList.size();
|
---|
77 |
|
---|
78 | if (listSize == 1) {
|
---|
79 | return bidList.get(0);
|
---|
80 | }
|
---|
81 |
|
---|
82 | try {
|
---|
83 | for (Iterator<Bid> it = bidList.iterator(); it.hasNext();) {
|
---|
84 | int bidUtility = (int) (utilitySpace.getUtility(it.next()) * 100);
|
---|
85 | totalUtil += bidUtility;
|
---|
86 | }
|
---|
87 |
|
---|
88 | int rndint = rnd.nextInt(totalUtil);
|
---|
89 |
|
---|
90 | for (Iterator<Bid> it = bidList.iterator(); it.hasNext(); index++) {
|
---|
91 | int bidUtility = (int) (utilitySpace.getUtility(it.next()) * 100);
|
---|
92 | if (rndint < bidUtility) {
|
---|
93 | return bidList.get(index);
|
---|
94 | } else {
|
---|
95 | rndint -= bidUtility;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | } catch (Exception e) {
|
---|
99 | e.printStackTrace();
|
---|
100 | }
|
---|
101 |
|
---|
102 | // ifFailure
|
---|
103 | return selectRandomBid(bidList, bidList.size());
|
---|
104 | }
|
---|
105 |
|
---|
106 | // SelectNextBid(Random)
|
---|
107 | private Bid selectRandomBid(ArrayList<Bid> bidList, int listSize) {
|
---|
108 | int rand = rnd.nextInt(listSize);
|
---|
109 | return bidList.get(rand);
|
---|
110 | }
|
---|
111 | } |
---|