コード例 #1
0
ファイル: runsim.py プロジェクト: bbengfort/swarm-simulator
 def run():
     world = World(ally_conf_path=args.conf_path)
     while world.time < args.iterations:
         try:
             world.update()
         except KeyboardInterrupt:
             break
コード例 #2
0
ファイル: runsim.py プロジェクト: bbengfort/swarm-simulator
def head2head(args):
    """
    Run a head to head simulation, outputing the magnitude of the stash of
    each team in the simulation at every time step.
    """
    start = time.time()
    world = World(ally_conf_path=args.conf_path, maximum_time=args.iterations)

    print "Starting headless simulation, use CTRL+C to quit."
    writer = csv.writer(args.stream, delimiter='\t')
    writer.writerow(('black', 'red'))
    while world.time < world.iterations:
        try:
            world.update()
            writer.writerow((str(world.ally_home.stash), str(world.enemy_home.stash)))
            if world.time % 1000 == 0:
                print "%ik iterations completed" % (world.time / 1000)
        except KeyboardInterrupt:
            print "Quitting Early!"
            break

    finit = time.time()
    delta = finit - start

    output = []
    output.append("Ran %i time steps in %0.3f seconds" % (world.time, delta))
    output.append("Agents successfully collected %i resources" % world.ally_home.stash)
    return "\n".join(output)
コード例 #3
0
 def run():
     world = World(ally_conf_path=args.conf_path)
     while world.time < args.iterations:
         try:
             world.update()
         except KeyboardInterrupt:
             break
コード例 #4
0
ファイル: tasks.py プロジェクト: dtbinh/swarm-simulator
def head2head(configuration, outpath, iterations=10000):
    """
    Run a head to head simulation using the configuration for the black
    team against the red team. Write detailed stats out to the outpath.
    Can also specificy the number of iterations to run the simulation for.
    """
    start = time.time()
    world = World(ally_conf_path=configuration, maximum_time=iterations)

    with open(outpath, 'w') as outfile:
        writer = csv.writer(outfile)
        header = (
            'black',
            'red',
        ) + ('deposit', ) * world.deposits
        writer.writerow(header)
        writer.writerow(world.status())

        for step in xrange(world.iterations):
            try:
                world.update()
                writer.writerow(world.status())
            except Exception as e:
                break

    finit = time.time()
    delta = finit - start

    return {
        'fitness': world.ally_home.stash,
        'run_time': delta,
        'iterations': world.time,
        'home_stash': world.ally_home.stash,
        'enemy_stash': world.enemy_home.stash,
    }
コード例 #5
0
def simulate(args):
    """
    Run a headless simulation with configuration file
    """
    start = time.time()
    world = World(ally_conf_path=args.conf_path)

    print "Starting headless simulation, use CTRL+C to quit."
    while world.time < world.iterations:
        try:
            world.update()
            if world.time % 1000 == 0:
                print "%ik iterations completed" % (world.time / 1000)
        except KeyboardInterrupt:
            print "Quitting Early!"
            break

    finit = time.time()
    delta = finit - start

    output = []
    output.append("Ran %i time steps in %0.3f seconds" % (world.time, delta))
    output.append("Agents successfully collected %i resources" %
                  world.ally_home.stash)
    return "\n".join(output)
コード例 #6
0
def head2head(args):
    """
    Run a head to head simulation, outputing the magnitude of the stash of
    each team in the simulation at every time step.
    """
    start = time.time()
    world = World(ally_conf_path=args.conf_path, maximum_time=args.iterations)

    print "Starting headless simulation, use CTRL+C to quit."
    writer = csv.writer(args.stream, delimiter='\t')
    writer.writerow(('black', 'red'))
    while world.time < world.iterations:
        try:
            world.update()
            writer.writerow(
                (str(world.ally_home.stash), str(world.enemy_home.stash)))
            if world.time % 1000 == 0:
                print "%ik iterations completed" % (world.time / 1000)
        except KeyboardInterrupt:
            print "Quitting Early!"
            break

    finit = time.time()
    delta = finit - start

    output = []
    output.append("Ran %i time steps in %0.3f seconds" % (world.time, delta))
    output.append("Agents successfully collected %i resources" %
                  world.ally_home.stash)
    return "\n".join(output)
コード例 #7
0
ファイル: tasks.py プロジェクト: bbengfort/swarm-simulator
def head2head(configuration, outpath, iterations=10000):
    """
    Run a head to head simulation using the configuration for the black
    team against the red team. Write detailed stats out to the outpath.
    Can also specificy the number of iterations to run the simulation for.
    """
    start = time.time()
    world = World(ally_conf_path=configuration, maximum_time=iterations)

    with open(outpath, 'w') as outfile:
        writer = csv.writer(outfile)
        header = ('black', 'red',) + ('deposit',) * world.deposits
        writer.writerow(header)
        writer.writerow(world.status())

        for step in xrange(world.iterations):
            try:
                world.update()
                writer.writerow(world.status())
            except Exception as e:
                break

    finit = time.time()
    delta = finit - start

    return {
        'fitness':     world.ally_home.stash,
        'run_time':    delta,
        'iterations':  world.time,
        'home_stash':  world.ally_home.stash,
        'enemy_stash': world.enemy_home.stash,
    }
コード例 #8
0
ファイル: tasks.py プロジェクト: dtbinh/swarm-simulator
def runsim(configuration):
    """
    Run a simulation for the given number of timesteps and return fitness.
    """
    start = time.time()
    world = World(ally_conf_path=configuration)

    for step in xrange(world.iterations):
        try:
            world.update()
        except Exception as e:
            break

    finit = time.time()
    delta = finit - start

    return {
        'fitness': world.ally_home.stash,
        'run_time': delta,
        'iterations': world.time,
        'home_stash': world.ally_home.stash,
        'enemy_stash': world.enemy_home.stash,
    }
コード例 #9
0
ファイル: tasks.py プロジェクト: bbengfort/swarm-simulator
def runsim(configuration):
    """
    Run a simulation for the given number of timesteps and return fitness.
    """
    start = time.time()
    world = World(ally_conf_path=configuration)

    for step in xrange(world.iterations):
        try:
            world.update()
        except Exception as e:
            break

    finit = time.time()
    delta = finit - start

    return {
        'fitness':     world.ally_home.stash,
        'run_time':    delta,
        'iterations':  world.time,
        'home_stash':  world.ally_home.stash,
        'enemy_stash': world.enemy_home.stash,
    }
コード例 #10
0
ファイル: runsim.py プロジェクト: bbengfort/swarm-simulator
def simulate(args):
    """
    Run a headless simulation with configuration file
    """
    start = time.time()
    world = World(ally_conf_path=args.conf_path)

    print "Starting headless simulation, use CTRL+C to quit."
    while world.time < world.iterations:
        try:
            world.update()
            if world.time % 1000 == 0:
                print "%ik iterations completed" % (world.time / 1000)
        except KeyboardInterrupt:
            print "Quitting Early!"
            break

    finit = time.time()
    delta = finit - start

    output = []
    output.append("Ran %i time steps in %0.3f seconds" % (world.time, delta))
    output.append("Agents successfully collected %i resources" % world.ally_home.stash)
    return "\n".join(output)