Example #1
0
    def updater__check_reinitialization(self, identifier):
        #
        # VARIABLES
        #
        from environment import Environment
        from updater import Updater

        #
        # CODE
        #

        # we need the environment
        environment_directory = 'environments/'
        environment = Environment(identifier)
        environment.read_environment_file("./" + environment_directory +
                                          identifier + ".xml")
        environment.initialize()

        # and we need to create an exogenous network
        environment.network.create_exogenous_network(
            environment.parameter.network_density)

        updater = Updater(identifier, environment)
        print "<<< BEFORE UPDATE"
        print updater

        print "<<< UPDATING "
        updater.do_update()
        print updater

        updater.reinitialize(identifier, environment)
        print "<<< AFTER REINITIALIZATION"
        print updater
 def do_run(self):
     debug = False # debug
     
     updater = Updater(self.identifier,  self.environment)
     
     for simulation in range(0, self.environment.parameter.num_simulations):
         
         if (debug): # debug
             print "<< SIMULATION #: " + str(simulation) + " >>"
             
         # reinitialize the network and the agents before every run
         updater.reinitialize(self.identifier, self.environment)
         
         #
         # do the sweeps                
         #
         for sweep in range(0, self.environment.parameter.num_sweeps):
             
             # see if we have a new state of the world (call with -1 for random new state based on parameters)
             self.get_new_state_of_world(self.environment.parameter.theta) # this implies that the state never changes
             
             if (debug): # debug
                 print "<<<< Sweep: " + str(sweep) + " State: " + str(self.environment.parameter.theta) + " >>>>"
                             
             # do the update step
             updater.do_update()
             
             if (debug): # debug
                 print self.environment.network
             
         # end for sweep
         self.measurement.measure_average_actions(self.environment.network.network, sweep) # average_actions is measured differently
         self.measurement.measure_network_density(self.environment.network.network, sweep) # density of network
         self.measurement.measure_path_length(self.environment.network.network, sweep) # average shortest path length
         self.measurement.measure_clustering(self.environment.network.network, sweep) # average clustering
         # utility is measured slightly different and the network instance is passed instead of the networkx graph
         self.measurement.measure_utility(self.environment.network, updater, sweep) 
         self.measurement.measure_individual_utility(self.environment.network, updater, sweep) 
         self.measurement.measure_pairwise_utility(self.environment.network, updater, sweep) 
         
     # end for simulation
     self.measurement.histo_average_actions.append(self.measurement.average_actions[:])
     self.measurement.histo_network_density.append(self.measurement.network_density[:])
     self.measurement.histo_path_length.append(self.measurement.path_length[:])
     self.measurement.histo_clustering.append(self.measurement.clustering[:])
     self.measurement.histo_utility.append(self.measurement.utility[:])        
     self.measurement.histo_individual_utility.append(self.measurement.individual_utility[:])
     self.measurement.histo_pairwise_utility.append(self.measurement.pairwise_utility[:])
Example #3
0
class Runner(object):
#	from environment import Environment
	
	#
	# VARIABLES
	#

	# 
	# METHODS
	#
	#-------------------------------------------------------------------------
	# __init__
	#-------------------------------------------------------------------------
	def __init__(self):
		pass
	#-------------------------------------------------------------------------


	#-------------------------------------------------------------------------
	# initialize()
	#-------------------------------------------------------------------------
	def initialize(self,  environment):
		self.environment = environment
		self.updater = Updater(self.environment)
		self.shocker = Shock()
	#-------------------------------------------------------------------------


	#-------------------------------------------------------------------------
	# do_run
	#-------------------------------------------------------------------------
	def do_run(self, measurement,  debug):
		# loop over all time steps and do the updating
		for i in range(self.environment.parameters.numSweeps):
			# the update step
			self.updater.do_update(self.environment, i, debug)
			
			# check if there is a shock at the current time step
			if (int(self.environment.get_state(i).shockType) != 0):
				self.shocker.do_shock(self.environment, int(i))
				self.environment.get_state(i).shockType = 0
			
			# do the measurement
			measurement.do_measurement(self.environment.banks)
Example #4
0
    def updater__updater2(self, args):
        from environment import Environment
        from updater import Updater

        #
        # INITIALIZATION
        #
        environment_directory = str(args[1])
        identifier = str(args[2])
        log_directory = str(args[3])

        # Configure logging parameters so we get output while the program runs
        logging.basicConfig(
            format="%(asctime)s %(message)s",
            datefmt="%m/%d/%Y %H:%M:%S",
            filename=log_directory + identifier + ".log",
            level=logging.INFO,
        )
        logging.info("START logging for test updater__updater2 in run: %s", environment_directory + identifier + ".xml")

        #
        # TEST CODE
        #
        environment = Environment(environment_directory, identifier)
        # create a test environment with standardised banks
        environment.banks[0].change_deposits(1.0)
        environment.banks[1].change_deposits(-1.0)

        updater = Updater(environment)

        #
        # execute the update code
        #
        updater.do_update(
            environment.get_state(0), environment.network, environment.network.contracts.nodes(), 0, "info"
        )

        #
        # MEASUREMENT AND LOGGING
        #
        logging.info(
            "FINISHED logging for test updater__updater2 in run: %s \n", environment_directory + identifier + ".xml"
        )
Example #5
0
    def updater__updater2(self, args):
        from environment import Environment
        from updater import Updater

        #
        # INITIALIZATION
        #
        environment_directory = str(args[1])
        identifier = str(args[2])
        log_directory = str(args[3])

        # Configure logging parameters so we get output while the program runs
        logging.basicConfig(format='%(asctime)s %(message)s',
                            datefmt='%m/%d/%Y %H:%M:%S',
                            filename=log_directory + identifier + ".log",
                            level=logging.INFO)
        logging.info('START logging for test updater__updater2 in run: %s',
                     environment_directory + identifier + ".xml")

        #
        # TEST CODE
        #
        environment = Environment(environment_directory, identifier)
        # create a test environment with standardised banks
        environment.banks[0].change_deposits(1.0)
        environment.banks[1].change_deposits(-1.0)

        updater = Updater(environment)

        #
        # execute the update code
        #
        updater.do_update(environment.get_state(0), environment.network,
                          environment.network.contracts.nodes(), 0, "info")

        #
        # MEASUREMENT AND LOGGING
        #
        logging.info(
            'FINISHED logging for test updater__updater2 in run: %s \n',
            environment_directory + identifier + ".xml")
    def do_run(self):
        updater = Updater(self.identifier, self.environment)

        for i in range(0, self.environment.parameter.num_sweeps):
            updater.do_update()