コード例 #1
0
def model():
    '''
    The main method, where all simulations begin.

    TODO: Use config switch 'useGUI' to decide whether to use
    SimPlot/plotHistogram, or just printHistogram.  There is no
    reason to leave that important data out, even though I don't
    always want to incur the cost/hassle of producing a GUI.
    [Note: The plot code is in method oooh_shiny().  The name of
    the method is a strong hint that it's intended to be developed
    further.]
    '''
    initialize()
    random.seed(SEED)

#    # Create Fares prior to starting the simulation.  Now a TK.
#    for j in range(1,NUM_FARES):
#        # TODO Put this in place later.  grep for "Fare Fare" to see what it's
#        # doing.  It may in fact point to other problems with my strategy.
#        #f=Fare(name='Fare-' + `j`)
##        fname = 'Fare-%s' % j
##        f=Fare(fname)
#        f=Fare(name="Fare-"+str(j))
#        activate(f, f.run())

    # Team 1 - Yellow Cab
    for i in range(NUM_TAXIS):
        tx = Taxi('Taxi-%s' % i, NP)
        if SIMTYPE == 'cooperate':
            activate(tx, tx.cooperate())
        elif SIMTYPE == 'compete':
            activate(tx, tx.compete())
        else:
            print("Error: can't set the simulation type")
            import sys; sys.exit()
    #
    # Team 2 - Checker Cab
    #for i in range(4):
    #    tx=Taxi('Checker-%s' % i)
    #    tx=Taxi('Checker-%s' % i, 'closestfare')
    #    tx=Taxi('Checker-%s' % i, 'mixedmode')
    #    activate(tx, tx.cooperate())
    #    activate(tx, tx.compete())

    ff = FareFactory()
    activate(ff, ff.generate())
#    fare = ff.generate()
#    activate(ff, fare)
#    activate(ff, ff.generate(), datacollector=)
    simulate(until=SIMTIME)
    print('waitingFares', [x.name for x in Agent.waitingFares.theBuffer])
コード例 #2
0
def model_compete_closestfare():
    initialize()
    random.seed(333777)
    NP = 'closestfare'

    for j in range(1, 5):
        f = Fare(name="-" + str(j))
        activate(f, f.run())

    for i in range(5):
        tx = Taxi('Yellow-%s' % i, NP)
        activate(tx, tx.compete())

    ff = FareFactory()
    activate(ff, ff.generate())
    simulate(until=SIMTIME)
    print('waitingFares', [x.name for x in Agent.waitingFares.theBuffer])