def run(self, world, agents, market):
        """
        Sample agents (with replacement) and let them speak on market.   
        As market is asynchronous, as soon as an agent speaks, do_clearing
        is called to execute any possible transaction immediately.
        """
        market.sellbook = world.state()['sellbook']
        logger.debug("Starting with sellbook %s" % market.sellbook)
        market.buybook = world.state()['buybook']
        logger.debug("Starting with buybook %s" % market.buybook)
        for day in range(self.days):
            for time in range(self.daylength):
                #gap length for wealth tracking
                #gaplength = 50
                #if (day % gaplength == 0 and day != 0) or day == self.days - 1:
                #if day == self.days - 1:
		#    fwealth = file('wealthoutput.csv', 'a')
                #    mask = ';'.join(('%d','%d','%s','%d','%d'))
                #    for agent in agents:
                #        print >> fwealth, mask % (time,
                #                             id(agent),
                #                             agent.__class__.__name__,
                #                             agent.money,
		#			     agent.stocks)
                agt = random.randint(0, len(agents)-1)
                order = market.sanitize_order(agents[agt].speak())
                if market.is_valid(agents[agt], order):
                    if self.params.orderslogfile:
                        self.output_order(order)
                    market.record_order(order, world.tick,
                            self.unique_by_agent)
                    if self.showbooks:
                        market.output_books(world.tick)
                    market.do_clearing(world.tick)
                    world.lastmarketinfo.update(
                            {'sellbook':market.sellbook, 'buybook':market.buybook})
                world.tick +=1
                if self.params['timer']:
                    world.show_time(day, time, self.days*self.daylength)
            if self.clearbooksateod:
                market.clear_books()
	wealthname = market.outputfile.name.split('.')[0] + 'wealth.csv'
	fwealth = file(wealthname, 'w')
        mask = ';'.join(('%d','%d','%s','%d','%d'))
        for agent in agents:
            print >> fwealth, mask % (time,
       		                   id(agent),
                                   agent.__class__.__name__,
                                   agent.money,
                                   agent.stocks)
	fwealth.close()

        logger.debug("Ending with sellbook %s" % market.sellbook)
        logger.debug("Ending with buybook %s" % market.buybook)
dataset/ETHPy150Open jcbagneris/fms/fms/contrib/coleman/engines/asynchronousrandwreplace.py/AsynchronousRandWReplace.run/original