1 | package agents.anac.y2014.KGAgent;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 | import java.util.Random;
|
---|
5 |
|
---|
6 | import agents.anac.y2014.kGA_gent.library_genetic.Gene;
|
---|
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.ValueInteger;
|
---|
12 |
|
---|
13 | public class MyBidGene implements Gene {
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * @param args
|
---|
17 | */
|
---|
18 | double mut = 0.1;// �然変異確立
|
---|
19 |
|
---|
20 | static KGAgent agent = null;
|
---|
21 |
|
---|
22 | static int type = 0;
|
---|
23 |
|
---|
24 | double util = 0.0;
|
---|
25 | double enemyutil = 0.0;
|
---|
26 |
|
---|
27 | boolean utilflag = false;
|
---|
28 |
|
---|
29 | Bid bid;
|
---|
30 |
|
---|
31 | static Random randomnr = null;
|
---|
32 |
|
---|
33 | static boolean agentflag = false;
|
---|
34 |
|
---|
35 | MyBidGene(Bid b) {
|
---|
36 |
|
---|
37 | bid = new Bid(b);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public MyBidGene(MyBidGene mybid) {
|
---|
41 |
|
---|
42 | bid = new Bid(mybid.bid);
|
---|
43 | // util = mybid.util;
|
---|
44 | // enemyutil = mybid.enemyutil;
|
---|
45 |
|
---|
46 | utilflag = false;
|
---|
47 |
|
---|
48 | // TODO 自動ç�?Ÿæˆ�ã�•ã‚Œã�Ÿã‚³ãƒ³ã‚¹ãƒˆãƒ©ã‚¯ã‚¿ãƒ¼ãƒ»ã‚¹ã‚¿ãƒ–
|
---|
49 | }
|
---|
50 |
|
---|
51 | public MyBidGene(KGAgent agent) {
|
---|
52 | this.agent = agent;
|
---|
53 | randomnr = new Random();
|
---|
54 | agentflag = true;
|
---|
55 | type = agent.type;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public MyBidGene() {
|
---|
59 | if (agentflag == false) {
|
---|
60 | System.out.println("AgentSetErrer in MyBidGene");
|
---|
61 | }
|
---|
62 | // System.out.println("Call MyBidGene Instance");
|
---|
63 | bid = agent.GetRandomBid();
|
---|
64 | // System.out.println("End MyBidGene Instance");
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | public boolean equals(Object obj) {
|
---|
69 | if (this == obj) {
|
---|
70 | return true;
|
---|
71 |
|
---|
72 | }
|
---|
73 | if (obj == null) {
|
---|
74 | return false;
|
---|
75 | }
|
---|
76 | return bid.equals((Bid) obj);
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public Gene Cros(Gene g1) {
|
---|
81 | // TODO 自動ç�?Ÿæˆ�ã�•ã‚Œã�Ÿãƒ¡ã‚½ãƒƒãƒ‰ãƒ»ã‚¹ã‚¿ãƒ–
|
---|
82 |
|
---|
83 | List<Issue> issues = bid.getIssues();
|
---|
84 |
|
---|
85 | Bid in1 = ((MyBidGene) g1).bid;
|
---|
86 |
|
---|
87 | Bid ret = new Bid(bid);
|
---|
88 |
|
---|
89 | for (int i = 0; i < issues.size(); i++) {
|
---|
90 |
|
---|
91 | if (randomnr.nextDouble() < 0.5) {
|
---|
92 |
|
---|
93 | try {
|
---|
94 | if (type == 0) {
|
---|
95 | IssueInteger lIssueInteger = (IssueInteger) issues
|
---|
96 | .get(i);
|
---|
97 | ret = ret.putValue(lIssueInteger.getNumber(),
|
---|
98 | in1.getValue(lIssueInteger.getNumber()));
|
---|
99 | } else {
|
---|
100 | IssueDiscrete ID = (IssueDiscrete) issues.get(i);
|
---|
101 | ret = ret.putValue(ID.getNumber(),
|
---|
102 | in1.getValue(ID.getNumber()));
|
---|
103 |
|
---|
104 | }
|
---|
105 |
|
---|
106 | } catch (Exception e) {
|
---|
107 | // TODO 自動ç�?Ÿæˆ�ã�•ã‚Œã�Ÿ catch ブãƒãƒƒã‚¯
|
---|
108 | e.printStackTrace();
|
---|
109 | System.out
|
---|
110 | .println("GeneCrossErrer Number Out? in MyBidGene Line80");
|
---|
111 | }
|
---|
112 |
|
---|
113 | }
|
---|
114 | }
|
---|
115 | return new MyBidGene(ret);
|
---|
116 | }
|
---|
117 |
|
---|
118 | public void Mutate() {
|
---|
119 |
|
---|
120 | List<Issue> issues = bid.getIssues();
|
---|
121 |
|
---|
122 | /*
|
---|
123 | * �然変異
|
---|
124 | */
|
---|
125 | for (int i = 0; i < issues.size(); i++) {
|
---|
126 |
|
---|
127 | if (randomnr.nextDouble() < mut) {
|
---|
128 |
|
---|
129 | if (type == 0) {
|
---|
130 | IssueInteger lIssueInteger = (IssueInteger) issues.get(i);
|
---|
131 | int rndint = randomnr.nextInt(lIssueInteger.getUpperBound()
|
---|
132 | - lIssueInteger.getLowerBound());
|
---|
133 | bid = bid.putValue(lIssueInteger.getNumber(),
|
---|
134 | new ValueInteger(lIssueInteger.getLowerBound()
|
---|
135 | + rndint));
|
---|
136 | } else {
|
---|
137 | IssueDiscrete ID = (IssueDiscrete) issues.get(i);
|
---|
138 | int number = randomnr.nextInt(ID.getNumberOfValues());
|
---|
139 | bid = bid.putValue(ID.getNumber(), ID.getValue(number));
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 | utilflag = false;
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 | /*
|
---|
148 | * state -1 enemy 0 all 1 my
|
---|
149 | */
|
---|
150 | public double GetValue(int state) {
|
---|
151 |
|
---|
152 | if (agent == null) {
|
---|
153 | System.out.println("AgentSetErrer in GetValue in MyBidGene");
|
---|
154 | }
|
---|
155 |
|
---|
156 | if (utilflag == false) {
|
---|
157 |
|
---|
158 | util = agent.GetGeneUtility(this);
|
---|
159 | enemyutil = agent.GetGeneEnemyUtility(this);
|
---|
160 | utilflag = true;
|
---|
161 |
|
---|
162 | }
|
---|
163 | switch (state) {
|
---|
164 | case -1:
|
---|
165 | return enemyutil;
|
---|
166 | case 0:
|
---|
167 | return agent.EnemyPressAll(enemyutil) + util;
|
---|
168 | case 1:
|
---|
169 | return util;
|
---|
170 | default:
|
---|
171 | return 0;
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | @Override
|
---|
176 | public double GetValue() {
|
---|
177 | // TODO 自動ç�?Ÿæˆ�ã�•ã‚Œã�Ÿãƒ¡ã‚½ãƒƒãƒ‰ãƒ»ã‚¹ã‚¿ãƒ–
|
---|
178 |
|
---|
179 | if (utilflag == false) {
|
---|
180 |
|
---|
181 | util = agent.GetGeneUtility(this);
|
---|
182 | enemyutil = agent.GetGeneEnemyUtility(this);
|
---|
183 | utilflag = true;
|
---|
184 |
|
---|
185 | }
|
---|
186 | return agent.getUtility(bid);
|
---|
187 | }
|
---|
188 |
|
---|
189 | public void SetAgent(KGAgent a) {
|
---|
190 | agent = a;
|
---|
191 | }
|
---|
192 |
|
---|
193 | }
|
---|