[1] | 1 | package agents.anac.y2015.AgentX;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.HashMap;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
| 7 | import genius.core.Bid;
|
---|
| 8 | import genius.core.issue.Issue;
|
---|
| 9 | import genius.core.issue.IssueDiscrete;
|
---|
| 10 | import genius.core.issue.IssueInteger;
|
---|
| 11 | import genius.core.issue.Value;
|
---|
| 12 | import genius.core.issue.ValueDiscrete;
|
---|
| 13 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 14 |
|
---|
| 15 | public class negotiatingInfo {
|
---|
| 16 | private AdditiveUtilitySpace utilitySpace; // 効用空間
|
---|
| 17 | private List<Issue> issues; // 論点
|
---|
| 18 | private ArrayList<Object> opponents; // 自身以外の交渉参加者のsender
|
---|
| 19 | private ArrayList<Bid> MyBidHistory = null; // 提案履歴
|
---|
| 20 | private HashMap<Object, ArrayList<Bid>> opponentsBidHistory = null; // 提案履歴
|
---|
| 21 | private HashMap<Object, Double> opponentsAverage; // 平均
|
---|
| 22 | private HashMap<Object, Double> opponentsVariance; // 分散
|
---|
| 23 | private HashMap<Object, Double> opponentsSum; // 和
|
---|
| 24 | private HashMap<Object, Double> opponentsPowSum; // 二乗和
|
---|
| 25 | private HashMap<Object, Double> opponentsStandardDeviation; // 標準偏差
|
---|
| 26 | private HashMap<Issue, HashMap<Value, Double>> valueRelativeUtility = null; // 自身の効用空間における各論点値の相対効用値行列(線形効用空間用)
|
---|
| 27 | private int round = 0; // 自分の手番数
|
---|
| 28 | private int negotiatorNum = 3; // 交渉者数(不具合が生じた場合に備えて3人で初期化)
|
---|
| 29 | private boolean isLinerUtilitySpace = true; // 線形効用空間であるかどうか
|
---|
| 30 |
|
---|
| 31 | public negotiatingInfo(AdditiveUtilitySpace utilitySpace) {
|
---|
| 32 | // 初期化
|
---|
| 33 | this.utilitySpace = utilitySpace;
|
---|
| 34 | issues = utilitySpace.getDomain().getIssues();
|
---|
| 35 | opponents = new ArrayList<Object>();
|
---|
| 36 | MyBidHistory = new ArrayList<Bid>();
|
---|
| 37 | opponentsBidHistory = new HashMap<Object, ArrayList<Bid>>();
|
---|
| 38 | opponentsAverage = new HashMap<Object, Double>();
|
---|
| 39 | opponentsVariance = new HashMap<Object, Double>();
|
---|
| 40 | opponentsSum = new HashMap<Object, Double>();
|
---|
| 41 | opponentsPowSum = new HashMap<Object, Double>();
|
---|
| 42 | opponentsStandardDeviation = new HashMap<Object, Double>();
|
---|
| 43 | valueRelativeUtility = new HashMap<Issue, HashMap<Value, Double>>();
|
---|
| 44 |
|
---|
| 45 | try {
|
---|
| 46 | initValueRelativeUtility();
|
---|
| 47 | } catch (Exception e) {
|
---|
| 48 | System.out.println("相対効用行列の初期化に失敗しました");
|
---|
| 49 | e.printStackTrace();
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public void initOpponent(Object sender) {
|
---|
| 54 | initNegotiatingInfo(sender); // 交渉情報を初期化
|
---|
| 55 | opponents.add(sender); // 交渉参加者にsenderを追加
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | public void updateInfo(Object sender, Bid offeredBid) {
|
---|
| 59 | try {
|
---|
| 60 | updateNegotiatingInfo(sender, offeredBid);
|
---|
| 61 | } // 交渉情報の更新
|
---|
| 62 | catch (Exception e1) {
|
---|
| 63 | System.out.println("交渉情報の更新に失敗しました");
|
---|
| 64 | e1.printStackTrace();
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private void initNegotiatingInfo(Object sender) {
|
---|
| 69 | opponentsBidHistory.put(sender, new ArrayList<Bid>());
|
---|
| 70 | opponentsAverage.put(sender, 0.0);
|
---|
| 71 | opponentsVariance.put(sender, 0.0);
|
---|
| 72 | opponentsSum.put(sender, 0.0);
|
---|
| 73 | opponentsPowSum.put(sender, 0.0);
|
---|
| 74 | opponentsStandardDeviation.put(sender, 0.0);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | // 相対効用行列の初期化
|
---|
| 78 | private void initValueRelativeUtility() throws Exception {
|
---|
| 79 | ArrayList<Value> values = null;
|
---|
| 80 | for (Issue issue : issues) {
|
---|
| 81 | valueRelativeUtility.put(issue, new HashMap<Value, Double>()); // 論点行の初期化
|
---|
| 82 | values = getValues(issue);
|
---|
| 83 | for (Value value : values) {
|
---|
| 84 | valueRelativeUtility.get(issue).put(value, 0.0);
|
---|
| 85 | } // 論点行の要素の初期化
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | // 相対効用行列の導出
|
---|
| 90 | public void setValueRelativeUtility(Bid maxBid) throws Exception {
|
---|
| 91 | ArrayList<Value> values = null;
|
---|
| 92 | Bid currentBid = null;
|
---|
| 93 | for (Issue issue : issues) {
|
---|
| 94 | currentBid = new Bid(maxBid);
|
---|
| 95 | values = getValues(issue);
|
---|
| 96 | for (Value value : values) {
|
---|
| 97 | currentBid = currentBid.putValue(issue.getNumber(), value);
|
---|
| 98 | valueRelativeUtility.get(issue).put(
|
---|
| 99 | value,
|
---|
| 100 | utilitySpace.getUtility(currentBid)
|
---|
| 101 | - utilitySpace.getUtility(maxBid));
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | public void updateNegotiatingInfo(Object sender, Bid offeredBid)
|
---|
| 107 | throws Exception {
|
---|
| 108 | opponentsBidHistory.get(sender).add(offeredBid); // 提案履歴
|
---|
| 109 |
|
---|
| 110 | double util = utilitySpace.getUtility(offeredBid);
|
---|
| 111 | opponentsSum.put(sender, opponentsSum.get(sender) + util); // 和
|
---|
| 112 | opponentsPowSum.put(sender,
|
---|
| 113 | opponentsPowSum.get(sender) + Math.pow(util, 2)); // 二乗和
|
---|
| 114 |
|
---|
| 115 | int round_num = opponentsBidHistory.get(sender).size();
|
---|
| 116 | opponentsAverage.put(sender, opponentsSum.get(sender) / round_num); // 平均
|
---|
| 117 | opponentsVariance.put(sender, (opponentsPowSum.get(sender) / round_num)
|
---|
| 118 | - Math.pow(opponentsAverage.get(sender), 2)); // 分散
|
---|
| 119 |
|
---|
| 120 | if (opponentsVariance.get(sender) < 0) {
|
---|
| 121 | opponentsVariance.put(sender, 0.0);
|
---|
| 122 | }
|
---|
| 123 | opponentsStandardDeviation.put(sender,
|
---|
| 124 | Math.sqrt(opponentsVariance.get(sender))); // 標準偏差
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | // 交渉者数を返す
|
---|
| 128 | public void updateOpponentsNum(int num) {
|
---|
| 129 | negotiatorNum = num;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | // 線形効用空間でない場合
|
---|
| 133 | public void utilitySpaceTypeisNonLiner() {
|
---|
| 134 | isLinerUtilitySpace = false;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | // 自身の提案情報の更新
|
---|
| 138 | public void updateMyBidHistory(Bid offerBid) {
|
---|
| 139 | MyBidHistory.add(offerBid);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | // 平均
|
---|
| 143 | public double getAverage(Object sender) {
|
---|
| 144 | return opponentsAverage.get(sender);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | // 分散
|
---|
| 148 | public double getVariancer(Object sender) {
|
---|
| 149 | return opponentsVariance.get(sender);
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | // 標準偏差
|
---|
| 153 | public double getStandardDeviation(Object sender) {
|
---|
| 154 | return opponentsStandardDeviation.get(sender);
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | // 相手の提案履歴の要素数を返す
|
---|
| 158 | public int getPartnerBidNum(Object sender) {
|
---|
| 159 | return opponentsBidHistory.get(sender).size();
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | // 自身のラウンド数を返す
|
---|
| 163 | public int getRound() {
|
---|
| 164 | return round;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | // 交渉者数を返す
|
---|
| 168 | public int getNegotiatorNum() {
|
---|
| 169 | return negotiatorNum;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | // 相対効用行列を返す
|
---|
| 173 | public HashMap<Issue, HashMap<Value, Double>> getValueRelativeUtility() {
|
---|
| 174 | return valueRelativeUtility;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | // 線形効用空間であるかどうかを返す
|
---|
| 178 | public boolean isLinerUtilitySpace() {
|
---|
| 179 | return isLinerUtilitySpace;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | // 論点一覧を返す
|
---|
| 183 | public List<Issue> getIssues() {
|
---|
| 184 | return issues;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | // 論点における取り得る値の一覧を返す
|
---|
| 188 | public ArrayList<Value> getValues(Issue issue) {
|
---|
| 189 | ArrayList<Value> values = new ArrayList<Value>();
|
---|
| 190 | switch (issue.getType()) {
|
---|
| 191 | case DISCRETE:
|
---|
| 192 | List<ValueDiscrete> valuesDis = ((IssueDiscrete) issue).getValues();
|
---|
| 193 | for (Value value : valuesDis) {
|
---|
| 194 | values.add(value);
|
---|
| 195 | }
|
---|
| 196 | break;
|
---|
| 197 | case INTEGER:
|
---|
| 198 | int min_value = ((IssueInteger) issue).getUpperBound();
|
---|
| 199 | int max_value = ((IssueInteger) issue).getUpperBound();
|
---|
| 200 | for (int j = min_value; j <= max_value; j++) {
|
---|
| 201 | Object valueObject = new Integer(j);
|
---|
| 202 | values.add((Value) valueObject);
|
---|
| 203 | }
|
---|
| 204 | break;
|
---|
| 205 | default:
|
---|
| 206 | try {
|
---|
| 207 | throw new Exception("issue type " + issue.getType()
|
---|
| 208 | + " not supported by Atlas3");
|
---|
| 209 | } catch (Exception e) {
|
---|
| 210 | System.out.println("論点の取り得る値の取得に失敗しました");
|
---|
| 211 | e.printStackTrace();
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 | return values;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | // 交渉相手の一覧を返す
|
---|
| 218 | public ArrayList<Object> getOpponents() {
|
---|
| 219 | return opponents;
|
---|
| 220 | }
|
---|
| 221 | }
|
---|