<s> """<STR_LIT>""" <EOL> import random <EOL> import logging <EOL> from fms . engines import Engine <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> class AsynchronousRandWReplace ( Engine ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parameters = None , offset = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> Engine . __init__ ( self , parameters , offset ) <EOL> self . params = parameters <EOL> self . rank = offset <EOL> if parameters : <EOL> random . seed ( parameters [ '<STR_LIT>' ] ) <EOL> def run ( self , world , agents , market ) : <EOL> """<STR_LIT>""" <EOL> market . sellbook = world . state ( ) [ '<STR_LIT>' ] <EOL> logger . debug ( "<STR_LIT>" % market . sellbook ) <EOL> market . buybook = world . state ( ) [ '<STR_LIT>' ] <EOL> logger . debug ( "<STR_LIT>" % market . buybook ) <EOL> for day in range ( self . days ) : <EOL> for time in range ( self . daylength ) : <EOL> agt = random . randint ( <NUM_LIT:0> , len ( agents ) - <NUM_LIT:1> ) <EOL> order = market . sanitize_order ( agents [ agt ] . speak ( ) ) <EOL> if market . is_valid ( agents [ agt ] , order ) : <EOL> if self . params . orderslogfile : <EOL> self . output_order ( order ) <EOL> market . record_order ( order , world . tick , <EOL> self . unique_by_agent ) <EOL> if self . showbooks : <EOL> market . output_books ( world . tick ) <EOL> market . do_clearing ( world . tick ) <EOL> world . lastmarketinfo . update ( <EOL> { '<STR_LIT>' : market . sellbook , '<STR_LIT>' : market . buybook } ) <EOL> world . tick += <NUM_LIT:1> <EOL> if self . params [ '<STR_LIT>' ] : <EOL> world . show_time ( day , time , self . days * self . daylength ) <EOL> if self . clearbooksateod : <EOL> market . clear_books ( ) <EOL> wealthname = market . outputfile . name . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> fwealth = file ( wealthname , '<STR_LIT:w>' ) <EOL> mask = '<STR_LIT:;>' . join ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:%s>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> for agent in agents : <EOL> print >> fwealth , mask % ( time , <EOL> id ( agent ) , <EOL> agent . __class__ . __name__ , <EOL> agent . money , <EOL> agent . stocks ) <EOL> fwealth . close ( ) <EOL> logger . debug ( "<STR_LIT>" % market . sellbook ) <EOL> logger . debug ( "<STR_LIT>" % market . buybook ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print AsynchronousRandWReplace ( ) </s>
