Example #1
0
class Simulation(object):
    """Just a Container for object lists and other global stuff"""
    def __init__(self):

        ''' 
        input the scenario here. make sure the configuration files 
        are in the correct folder! 
        '''
        self.scenario = "default"

        ''' time management '''
        self.start_time = 3600 * 5
        self.current_time = self.start_time + 0
        self.speed = 5
        self.timestring = str(datetime.timedelta(seconds=math.floor(self.current_time)))

        self.debugbatch = pyglet.graphics.Batch()
        
        ''' setup, check and clear resources '''
        self.resources = ResourceSetup(self.scenario)
        self.spatial_db = self.resources.mongo_connection['spatial_db']
        
        ''' 
        import static geodata directly (every other import is done 
        via the appropriate manager classes
        '''
        self.importer = Importer("thesis_db", "thesis", "thesis")
        self.extent = self.importer.set_global_extent("street_network")
        self.roads = self.importer.read_line_layer("street_network")
        self.buildings_footprint = self.importer.read_line_layer("buildings_line")

        ''' create building centroids '''
        self.building_manager = BuildingManager(self, 
            self.importer.read_point_layer(
            "buildings_centroid", attributes=["building_id"]), 
            "config/"+self.scenario+"/building_attributes.json")

        ''' create actor manager '''
        self.actor_manager = ActorManager(self)

        ''' create routable network (coarse routing and between vectors as edge attributes) '''
        self.router = Router(self)
        self.router.create_routable_network_from_line_data(self.roads)
        self.router.create_lane_collsion_data()

        ''' create parking lots via the lot manager. initial config is provided via config json '''
        self.lots = self.importer.read_line_layer("parking_lots", attributes=["lot_permis", "lot_type", "lot_tech"])
        self.lot_manager = LotManager(self, self.lots, 
            "config/"+self.scenario+"/lot_init_fill.json", 
            "config/"+self.scenario+"/actor_attributes.json")

        ''' create spawners from config json file. See config for details'''
        self.spawner = Spawner(self, "config/"+self.scenario+"/actor_spawn.json", 
            "config/"+self.scenario+"/actor_attributes.json", 
            "config/"+self.scenario+"/exit_nodes.json")

        ''' display objects '''
        self.window = pyglet.window.Window(width=1000, height=600)
        self.window.set_location(10, 10)
        self.camera = Camera((200, 500), 50, 0, 1000)
        self.graphics = Graphics()
        self.fps_display = pyglet.clock.ClockDisplay()

        ''' create displayable batches '''
        self.buildings_footprint_batch = self.graphics.create_pyglet_line_batch(
            self.buildings_footprint, (200, 200, 200))
        self.router.create_pyglet_batch_from_network()

        ''' debug options '''
        self.debug_layer = None
        self.click_debug = None
        self.stop = False

        ''' GUI '''
        #self.gui = Frame(Theme('/Users/anresources/gui/'), w=1000, h=600)
        #self.window.push_handlers(self.gui)
        self.current_actor = None

        ''' mouse management '''
        self.mouse = []
 
    def change_speed(self, speed_change):
        if self.speed + speed_change != 0:
            self.speed += speed_change

    def trigger_stop(self):
        self.stop = (not self.stop)