Changes between Version 162 and Version 163 of WikiStart


Ignore:
Timestamp:
03/26/19 15:35:00 (6 years ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart

    v162 v163  
    127127                        action = new Offer(me, bidspace.get(BigInteger.valueOf(i)));
    128128                }
    129                 try {
    130                         getConnection().send(action);
    131                 } catch (IOException e) {
    132                         e.printStackTrace();
    133                 }
    134 
     129                getConnection().send(action);
    135130        }
    136131
     
    161156We recommend to do initialization of the party only in the init() and not in the constructor or static code.
    162157This because instances of your class can be made both for extracting general info as getDescription(), or to really run your class.
     158
     159
     160= Writing a party in Python
     161We 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{{{
     163class 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
     197You 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
    163199
    164200= JSON layout