[127] | 1 | package agents.anac.y2015.JonnyBlack;
|
---|
| 2 |
|
---|
| 3 | import java.util.Collections;
|
---|
| 4 | import java.util.Vector;
|
---|
| 5 |
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.issue.IssueDiscrete;
|
---|
| 8 | import genius.core.issue.ValueDiscrete;
|
---|
| 9 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 10 |
|
---|
| 11 | import java.util.HashMap;
|
---|
| 12 |
|
---|
| 13 | public class Party {
|
---|
| 14 | String ID;
|
---|
| 15 | int counts[][];
|
---|
| 16 | double weights[];
|
---|
| 17 | public Vector<BidHolder> orderedBids;
|
---|
| 18 | Party(String id,int[][] issueVals)
|
---|
| 19 | {
|
---|
| 20 | this.ID =id;
|
---|
| 21 | counts = new int[issueVals.length][];
|
---|
| 22 | for(int i=0;i<issueVals.length;i++)
|
---|
| 23 | {
|
---|
| 24 | counts[i] = new int[issueVals[i].length];
|
---|
| 25 | }
|
---|
| 26 | weights = new double[issueVals.length];
|
---|
| 27 | this.orderedBids=new Vector<BidHolder>();
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public double getPredictedUtility(Bid b,AdditiveUtilitySpace us)
|
---|
| 31 | {
|
---|
| 32 | double total = 0;
|
---|
| 33 | for(int i=0;i<this.counts.length;i++)
|
---|
| 34 | {
|
---|
| 35 | total += getValueForIssue(b, us, i);
|
---|
| 36 | }
|
---|
| 37 | return total;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public double getValueForIssue(Bid b, AdditiveUtilitySpace us,int i)
|
---|
| 41 | {
|
---|
| 42 | double eval =0;
|
---|
| 43 | try {
|
---|
| 44 | IssueDiscrete id = (IssueDiscrete)us.getIssue(i);
|
---|
| 45 | int choice = id.getValueIndex((ValueDiscrete)b.getValue(i+1));
|
---|
| 46 | eval = weights[i]*getVal(i, choice);
|
---|
| 47 |
|
---|
| 48 | } catch (Exception e) {
|
---|
| 49 | // TODO Auto-generated catch block
|
---|
| 50 | e.printStackTrace();
|
---|
| 51 | }
|
---|
| 52 | return eval;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public double getVal(int i,int j)
|
---|
| 56 | {
|
---|
| 57 | int ord=0;
|
---|
| 58 | for(int k =0;k<counts[i].length;k++)
|
---|
| 59 | {
|
---|
| 60 | if(counts[i][k]<=counts[i][j])
|
---|
| 61 | ord++;
|
---|
| 62 | }
|
---|
| 63 | double part = 1.0/counts[i].length;
|
---|
| 64 | return ord*part;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | public void calcWeights()
|
---|
| 68 | {
|
---|
| 69 | calcWeightsWithGini();
|
---|
| 70 | //calcWeightsWithEntropy();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public void calcWeightsWithGini()
|
---|
| 74 | {
|
---|
| 75 | double sumweight =0;
|
---|
| 76 | for(int i =0;i<weights.length;i++)
|
---|
| 77 | {
|
---|
| 78 | this.weights[i] = weigthWithGini(i);
|
---|
| 79 | sumweight+=this.weights[i];
|
---|
| 80 | }
|
---|
| 81 | for(int i =0;i<weights.length;i++)
|
---|
| 82 | {
|
---|
| 83 | this.weights[i] /= sumweight;
|
---|
| 84 |
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | public void calcWeightsWithEntropy()
|
---|
| 90 | {
|
---|
| 91 | double sumweight =0;
|
---|
| 92 | double maxent = 0;
|
---|
| 93 | for(int i =0;i<weights.length;i++)
|
---|
| 94 | {
|
---|
| 95 | this.weights[i] = weigthWithEntropy(i);
|
---|
| 96 | if(this.weights[i]>maxent)
|
---|
| 97 | maxent=this.weights[i];
|
---|
| 98 | }
|
---|
| 99 | for(int i =0;i<weights.length;i++)
|
---|
| 100 | {
|
---|
| 101 | if(maxent==0)
|
---|
| 102 | this.weights[i]=1;
|
---|
| 103 | else
|
---|
| 104 | this.weights[i]=maxent/this.weights[i];
|
---|
| 105 | sumweight+=this.weights[i];
|
---|
| 106 | }
|
---|
| 107 | for(int i =0;i<weights.length;i++)
|
---|
| 108 | {
|
---|
| 109 | this.weights[i] /= sumweight;
|
---|
| 110 |
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | public double getWeight(int ind)
|
---|
| 115 | {
|
---|
| 116 | return this.weigthWithGini(ind);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | private double weigthWithGini(int ind)
|
---|
| 120 | {
|
---|
| 121 | double w = 0;
|
---|
| 122 | int sum =0;
|
---|
| 123 | for(int i =0;i<this.counts[ind].length;i++)
|
---|
| 124 | {
|
---|
| 125 | sum+=this.counts[ind][i];
|
---|
| 126 | double r = 1.0*this.counts[ind][i]*this.counts[ind][i];
|
---|
| 127 | w+=r;
|
---|
| 128 | }
|
---|
| 129 | return w/(sum*sum);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | private double weigthWithEntropy(int ind)
|
---|
| 133 | {
|
---|
| 134 | double w = 0;
|
---|
| 135 | int sum =0;
|
---|
| 136 | for(int i =0;i<this.counts[ind].length;i++)
|
---|
| 137 | {
|
---|
| 138 | sum+=this.counts[ind][i];
|
---|
| 139 | }
|
---|
| 140 | for(int i =0;i<this.counts[ind].length;i++)
|
---|
| 141 | {
|
---|
| 142 | if(this.counts[ind][i]==0)
|
---|
| 143 | continue;
|
---|
| 144 | double p = 1.0*this.counts[ind][i]/sum;
|
---|
| 145 | w+= - p*Math.log(p);
|
---|
| 146 | }
|
---|
| 147 | return w/(sum*sum);
|
---|
| 148 | }
|
---|
| 149 | @Override
|
---|
| 150 | public boolean equals(Object obj) {
|
---|
| 151 | return this.ID.equals(((Party) obj).ID);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | public void show()
|
---|
| 155 | {
|
---|
| 156 | for(int i =0;i<this.counts.length;i++)
|
---|
| 157 | {
|
---|
| 158 | System.out.print(this.weights[i]+" ");
|
---|
| 159 | for(int j =0;j<this.counts[i].length;j++)
|
---|
| 160 | {
|
---|
| 161 | System.out.print(this.counts[i][j]+" ");
|
---|
| 162 | }
|
---|
| 163 | System.out.println();
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | }
|
---|
| 167 | public void orderBids(AdditiveUtilitySpace us)
|
---|
| 168 | {
|
---|
| 169 | for(BidHolder b : orderedBids)
|
---|
| 170 | {
|
---|
| 171 | b.v = this.getPredictedUtility(b.b, us);
|
---|
| 172 | }
|
---|
| 173 | Collections.sort(orderedBids);
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | public void setOrderedBids(Vector<BidHolder> acceptableBids,AdditiveUtilitySpace us) {
|
---|
| 177 | for(BidHolder bh :acceptableBids)
|
---|
| 178 | {
|
---|
| 179 | BidHolder bh1 = new BidHolder();
|
---|
| 180 | bh1.b=bh.b;
|
---|
| 181 | bh1.v = this.getPredictedUtility(bh.b, us);
|
---|
| 182 | this.orderedBids.add(bh1);
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 | }
|
---|