| 158 | |
| 159 | |
| 160 | = Writing a party in Python |
| 161 | We provide a python-to-java adapter so that you can easily write your agent in python instead of Java. You can check the example code [https://tracinsy.ewi.tudelft.nl/trac/Genius2/browser/exampleparties/randompartypy here]. A python-based agent looks like this: |
| 162 | {{{ |
| 163 | class RandomParty (DefaultParty): |
| 164 | def notifyChange(self, info): |
| 165 | if isinstance(info, Settings) : |
| 166 | self._fetchProfile(info.getProfile()) |
| 167 | self.me = info.getID() |
| 168 | elif isinstance(info , ActionDone): |
| 169 | self.lastActor = info.getAction().getActor() |
| 170 | otheract = info.getAction() |
| 171 | if isinstance(otheract, Offer): |
| 172 | self.lastReceivedBid = otheract.getBid() |
| 173 | elif isinstance(info , YourTurn): |
| 174 | self._myTurn() |
| 175 | |
| 176 | def getCapabilities(self): # -> Capabilities |
| 177 | return Capabilities(HashSet([ ProtocolRef(URI("SAOP"))])) |
| 178 | |
| 179 | def getDescription(self): |
| 180 | return "places random bids until it can accept an offer with utility >0.6. Python version" |
| 181 | |
| 182 | def terminate(self): |
| 183 | self.profile.disconnect() |
| 184 | |
| 185 | def _myTurn(self): |
| 186 | if self.lastReceivedBid != None and self.profile.getProfile().getUtility(self.lastReceivedBid).doubleValue() > 0.6: |
| 187 | action = Accept(self.me, self.lastReceivedBid) |
| 188 | else: |
| 189 | bidspace = AllBidsList(self._getProfile().getDomain()) |
| 190 | i = self.random.nextInt(bidspace.size()) # warning: jython implicitly converts BigInteger to long. |
| 191 | action = Offer(self.me, bidspace.get(BigInteger.valueOf(i))) |
| 192 | self.getConnection().send(action) |
| 193 | |
| 194 | ... |
| 195 | }}} |
| 196 | |
| 197 | You need to wrap your python agent into a jar wrapper to get it accepted by the parties server. To do this, check the javadoc with the [https://tracinsy.ewi.tudelft.nl/trac/Genius2/browser/pythonadapter/src/main/java/genius2/pythonadapter/PythonPartyAdapter.java PythonPartyAdapter]. |
| 198 | |