Example #1
0
def main():
    """Defines the simulation, map, monitors, persons. Cafe locations are set up at cafe POI on road network."""
    s = Simulation(geo=osm.OSMModel('../data/minimap0.osm'), rel_speed=50, seed=6)
    #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(PoiActWiggler, 1, monitor=m, args={"infected":True, "speed":1.7})
    s.add_persons(PoiActWiggler, 1, monitor=m)
    for p in [node for node in s.geo.way_nodes if "amenity" in node.tags and node.tags["amenity"] == "cafe"]:
        c = Cafe(p.tags['name'], s)
        p.worldobject = c
        s.activate(c, c.serve(), 0)
    s.run(until=50000, real_time=True, monitor=True)
Example #2
0
def main():
    """Defines the simulation, map, monitors, persons. Sets up the reactivation alarm."""
    s = Simulation(geo=osm.OSMModel('../data/minimap0.osm'), rel_speed=50)
    #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    sys.stderr.write('Number of cafe nodes: %s \n' % len([node for node in s.geo.way_nodes if "amenity" in node.tags and node.tags["amenity"] == "cafe"]))
    s.add_persons(PassivateWiggler, 4, monitor=m)
    s.a = Alarm('alarm', s)
    s.activate(s.a, s.a.go(), 0)
    s.run(until=500000, real_time=True, monitor=True)
Example #3
0
def main():
    """What to profile is defined here."""
    ticks = 100
    zombies = 1000
    osm_file = '../data/chicago1.osm'

    print 'Loading geo & routing ... '
    s = Simulation(geo=osm.OSMModel(osm_file, grid_size=50), rel_speed=20)
    s.add_persons(ZombieWiggler, zombies, args={"infected":True, "speed":0.7})
    t = time.time()
    print 'Go! '
    s.run(until=ticks, real_time=False, monitor=False)
    print 'Done %s with %s zombies on map %s' % (ticks, zombies, osm_file)
    print 'Duration: ', time.time() - t
Example #4
0
def main():
    """Defines the simulation, map, monitors, persons."""
    s = Simulation(geo=osm.OSMModel('../data/hannover2.osm', grid_size=50), rel_speed=120, seed=6001)
    #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(StopActionsWiggler, 1, monitor=m, args={"infected":True, "speed":2.4})
    s.add_persons(StopActionsWiggler, 49, monitor=m)
    s.run(until=4000, real_time=True, monitor=True)
Example #5
0
def main():
    """Defines the zombie infection simulation with random movement.
    
    map: hannover1.osm, output to socketPlayer or champlain child process player, 
    49 healthy people, 1 zombie, infection using action decorator."""
    s = Simulation(geo=osm.OSMModel("../data/hannover0.osm"), rel_speed=60)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(ZombieWiggler, 49, monitor=m)
    s.add_persons(ZombieWiggler, 1, monitor=m, args={"infected": True, "speed": 0.7})
    s.run(until=10000, real_time=True, monitor=True)
Example #6
0
def main():
    """Defines the BT infection simulation with random movement.
    
    map: hannover2.osm, output to socketPlayer or champlain child process player, 
    89 healthy people, 1 infected, infection using action decorator."""
    s = Simulation(geo=osm.OSMModel('../data/hannover2.osm'), rel_speed=120)
    #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 10)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(BTVirusWiggler, 1, monitor=m, args={"infected":True, "infectionTime":-301})
    s.add_persons(BTVirusWiggler, 89, monitor=m)
    s.run(until=28800, real_time=True, monitor=True)
Example #7
0
def main():
    """Defines the simulation, map, monitors, persons and exits at border nodes."""
    s = Simulation(geo=osm.OSMModel('../data/hannover2.osm'), rel_speed=60)
    #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(ExitWiggler, 20, monitor=m)
    exits = [node for node in s.geo.way_nodes if "border" in node.tags]
    exit = WigglerExit('theExit', s)
    s.activate(exit, exit.serve(), 0)
    for e in exits:
        e.worldobject = exit   
    s.run(until=10000, real_time=True, monitor=True)
Example #8
0
def main():
    """Defines the simulation, map, monitors, persons. Connects POI with road network."""
    s = Simulation(geo=osm.OSMModel('../data/hannover2.osm'), rel_speed=30)
    # cafes are buildings and located in non_way_nodes --> filter that by tags
    cafes = [node for node in s.geo.non_way_nodes if "amenity" in node.tags and node.tags["amenity"] in ("bar","cafe","pub")]
    for cafe in cafes:
        # find nearest node to cafe
        dist = float('inf')
        nearest = None
        if not cafe.neighbors:
            for node in s.geo.way_nodes:
                d = utils.distance(cafe, node)
                if d < dist and node.neighbors:
                    dist = d
                    nearest = node
            # update neighbors
            cafe.neighbors[nearest] = int(dist)
            nearest.neighbors[cafe] = int(dist)
            cafe.n = [nearest]
            # update ways
            way = osm.WaySegment(cafe, nearest)
            cafe.ways[nearest] = way
            nearest.ways[cafe] = way
            s.geo.add(way)
            # add exit to cafe
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(PoiWiggler, 2, monitor=m, args={"cafes": cafes})
    s.run(until=10000, real_time=True, monitor=True)
Example #9
0
def main():
    """Defines the simulation, map, monitors, persons."""
    s = Simulation(geo=osm.OSMModel("../data/minimap1.osm"), rel_speed=20)
    # m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(PauseWiggler, 1, monitor=m)
    s.run(until=500000, real_time=True, monitor=True)
Example #10
0
def main():
    """Defines the simulation, map, monitors, persons."""
    t = time.time()
    s = Simulation(geo=osm.OSMModel('../data/hannover2.osm'), rel_speed=40)
    print time.time() - t
    #m = s.add_monitor(EmptyMonitor, 2)
    #m = s.add_monitor(PipePlayerMonitor, 2)
    #m = s.add_monitor(RecordFilePlayerMonitor, 2)
    #m = s.add_monitor(RecordFilePlayerMonitor, 2, filename='exampleoutput_RecordFilePlayerMonitor')
    #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 2)

    s.add_persons(RandomWiggler, 1000, monitor=m)
    s.run(until=1000, real_time=True, monitor=True)
Example #11
0
def main():
    """Shows the different osm.ROADTYPE implementations.
    
    Different road width types can be tested here. Use minimap3 to show the
    walking side by side and RoadWidthTest map for osm data with width values."""
    
    #osm.ROADTYPE = osm.ROADTYPE_NODIMENSION            # road width = 0
    osm.ROADTYPE = osm.ROADTYPE_ONEWAY_NOSIDEWALK       # road width = width from the middle of road to the right in walking direction (as int)
    #osm.ROADTYPE = osm.ROADTYPE_TWOWAY_NOSIDEWALK      # road width = 2xwidth from the left of the road to the right both directions lanes (as int) 
    #osm.ROADTYPE = osm.ROADTYPE_ONEWAY_ONSIDEWALK      # no movement on street, but only on sidewalk (as list [road width per direction, sidewalk width+road width per direction]
    
    osm.ROADWIDTH_DEFAULTS = osm.ROADWIDTH_DEFAULTS     # stores width default of different highway types, used if tag (approx_)width is not set
    #osm.ROADWIDTH_DEFAULTS['footway'] = [3,5]          # set default width of highway=footway, must correspond to above ROADTYPE (here: list) - example for *ONSIDEWALK
    osm.ROADWIDTH_DEFAULTS['footway'] = 3               # set default width of highway=footway, must correspond to above ROADTYPE (here: int) - example for all the others
    
    # demo map with different road widths in osm data
    #s = Simulation(geo=osm.OSMModel('../data/RoadWidthTest.osm'), rel_speed=40)
    # simple demo map to see walking side by side
    s = Simulation(geo=osm.OSMModel('../data/minimap3.osm'), rel_speed=20)
    #m = s.add_monitor(ChildprocessPlayerChamplainMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(RandomWiggler, 2, monitor=m)
    [p for p in s.persons][0].set_speed(1.8)            # if people move in same direction, one should be faster to see them passing each other
    s.run(until=10000, real_time=True, monitor=True)
Example #12
0
def main():
    """Defines the simulation, map, monitor, different people.
    
    Combines 20 WorkWigglers, 20 DrunkWigglers and 5 RandomWigglers."""
    s = Simulation(geo=osm.OSMModel('../data/kl0.osm'), rel_speed=300)
    m = s.add_monitor(SocketPlayerMonitor, 30)
    s.add_persons(WorkWiggler, 20, monitor=m)
    s.add_persons(DrunkWiggler, 20, monitor=m)
    s.add_persons(RandomWiggler, 1, monitor=m, args={'speed':0.5})
    clock = SocketPlayerClock('clock', s, 300, m) #: a clock drawer for SocketPlayerMonitor
    s.activate(clock, clock.run(), 0)
    s.run(until=48000, real_time=True, monitor=True)
Example #13
0
def main():
    """Defines the simulation, map, monitors, persons."""
    s = Simulation(geo=osm.OSMModel("../data/hannover1.osm"), rel_speed=40)
    m = s.add_monitor(SocketPlayerMonitor, 2)
    s.add_persons(RoutingShowcaseWiggler, 2, monitor=m)
    s.run(until=10000, real_time=True)
Example #14
0
def main():
    """Defines the simulation, map, monitors, persons."""
    # setup works just like every other Simulation
    s = Simulation(geo=osm.OSMModel("../data/minimap4.osm"), rel_speed=40)
    # add a SocketPlayerMonitor...after this the monitor will wait until an connection was established
    m = s.add_monitor(SocketPlayerMonitor, 2)

    # the player will draw a bounding box (as specified by the map)
    # it is basically a simple rectangle with the id 0
    # to prevent this from happening set before the simulation starts
    # m.draw_bb = False

    # persons in a simulation will be send to the player automatically by the monitor
    s.add_persons(SocketPlayerDemoWiggler, 10, monitor=m)

    # the player automatically centers on the middle of the bounding box
    # should you not want this, you can center it on other coordinates using
    m.center_on_lat_lon(s.geo.bounds["minlat"], s.geo.bounds["minlon"])
    # please note that in the current version there is a slight inaccuracy in the way the map is drawn
    # this means that the player will not center exactly on the specified coordinates

    # when the player is running, geometric objects can be drawn using the monitors draw methods
    #
    # in this example a circle will be drawn, other objects might need different arguments but work just the same
    # these arguments are necessary for almost all drawings:
    #   id is a unique identifier. When trying to draw two objects with the same id, the older one will be replaced.
    #      This mechanism can be used to update an object.
    #      Note: IDs also determines the order in which objects are drawn. This might be important when objects are overlapping.
    #   color is allways a 4-tuple of values in the range [0,1] representing RGBA-color, or a string with the name of a color
    #   ttl is available with most drawable objects. It represents a time in seconds, after which the object will be removed from the player.
    #      This might for example be used to signal an event to the viewer
    #      A ttl of 0 means this object will exist until simulation ends or it is deleted otherwise (default)
    m.draw_circle(
        id=0,
        center_lat=s.geo.bounds["minlat"],
        center_lon=s.geo.bounds["minlon"],
        radius=50,
        filled=True,
        color=(1.0, 0.6, 0.4, 1.0),
        ttl=10,
    )
    m.draw_circle(
        id=1,
        center_lat=s.geo.bounds["minlat"],
        center_lon=s.geo.bounds["minlon"],
        radius=25,
        filled=True,
        color="spring-spring-yellow",
        ttl=10,
    )

    # after every object drawn this way, the player will be told to redraw everything
    # this is not very fast when sending many objects at once
    # to send many objects at once you should use the monitors socket directly
    (r, g, b, a) = (1.0, 1.0, 0.5, 0.5)
    data = struct.pack(
        m.FORMATS["point"], 0, s.geo.bounds["minlat"], s.geo.bounds["minlon"], 3, r, g, b, a, 0  # id  # radius
    )
    m.conn.send(m.MESSAGES["point"] + data)
    data = struct.pack(
        m.FORMATS["point"], 1, s.geo.bounds["maxlat"], s.geo.bounds["minlon"], 6, r, g, b, a, 0  # id  # radius
    )
    m.conn.send(m.MESSAGES["point"] + data)
    data = struct.pack(
        m.FORMATS["point"], 2, s.geo.bounds["maxlat"], s.geo.bounds["maxlon"], 10, r, g, b, a, 0  # id  # radius
    )
    m.conn.send(m.MESSAGES["point"] + data)
    # finish by telling the player to draw. This is not necessary but ensures that changes will be drawn instantly
    m.conn.send(m.MESSAGES["draw"])

    # objects that do not have ttl > 0 will remain in the player until they are removed, replaced or until the simulation ends
    # deleting an object can be done by calling SocketPlayerMonitor.remove_object()
    m.draw_circle(2, s.geo.bounds["maxlat"], s.geo.bounds["minlon"], 50, True, (1.0, 1.0, 1.0, 1.0))
    m.remove_object(type="circle", id=2)
    # since we removed the circle before the simulation even starts, it will not appear at all

    # the player can create a heatmap while a simulation is running
    # this is achieved by drawing points in a more performant manner
    # as a trade-off these 'blips' can not be removed
    m.add_heatmap_blip(s.geo.bounds["minlat"], s.geo.bounds["maxlon"], 10, (1.0, 0.0, 0.0, 0.2))

    # using real_time=True is highly recommended...
    s.run(until=500, real_time=True, monitor=True)
Example #15
0
def main():
    """Defines the simulation, map, monitors, persons."""
    # initialize simulation as usual
    map_path = '../data/hannover0.osm'
    s = Simulation(geo=osm.OSMModel(map_path), rel_speed=1)

    # create an instance of ExternalDataManager and add it to the simulation as a SimPy process (do NOT use add_persons).
    #ext_manager = ExternalDataManager(sim=s, address='0.0.0.0', port=8080, map_path='../data/home.osm', free_move_only=True)
    ext_manager = ExternalDataManager(sim=s, address='0.0.0.0', port=8080, map_path=map_path, free_move_only=False)
    s.activate(ext_manager, ext_manager.run(), 0)

    # continue initialization as usual
    #m = s.add_monitor(EmptyMonitor, 2)
    m = s.add_monitor(SocketPlayerMonitor, 1)
    s.add_persons(ExternalZombieWiggler, 1, monitor=m)
    s.add_persons(ZombieWiggler, 48, monitor=m)
    s.add_persons(ZombieWiggler, 1, monitor=m, args={"infected":True, "speed":0.7})
    s.run(until=1000000, real_time=True, monitor=True)
    ext_manager.shutdown() # call this to reliably shut down the webserver