Exemple #1
0
    def solve(self):
        nodes, edges = self.get_map()

        world = World(nodes, self.cost, edges=edges)

        ants = 20
        solver = Solver(ant_count=ants)
        solution = solver.solve(world)

        print("Nodes: ", len(nodes))
        print("Number of ants: ", ants)
        print("Best distance: ", solution.distance)

        print("Path: ")
        path = solution.tour
        for i in range(len(path)):
            print("\t" + str(i + 1) + ": ", path[i][3])
Exemple #2
0
def start(window):
    global world, commands, scenes, current_scene

    # window & corner-case setup
    signal.signal(signal.SIGINT, lambda sig, frame: end(window))

    # game setup
    world = World()
    commands = {
        "help": cmd_help,
        "exit": cmd_exit,
        "view": world.display_map,
        "scan": world.display_scanned_map,
        "stats": world.player.display_stats,
        "control mode": lambda: change_scene_to("control_mode"),
        "move north": partial(world.move_player, Direction.North),
        "move east": partial(world.move_player, Direction.East),
        "move south": partial(world.move_player, Direction.South),
        "move west": partial(world.move_player, Direction.West),
        "yell": cmd_yell
    }

    init_scenes("terminal_mode", window,
                world)  # TODO: should start with "active_mode" or "menu"
Exemple #3
0
import tkinter as tk
from system.operation import Operation
from model.world import World
import settings

root = tk.Tk()
img = tk.PhotoImage(file='png/sports-car.png')
root.tk.call('wm', 'iconphoto', root._w, img)
menu = tk.Menu(root)

root.config(menu=menu)
root.protocol("WM_DELETE_WINDOW", lambda: op.terminate(root))
toolbar = tk.Frame(root)
function = tk.Frame(toolbar)
info = tk.Frame(toolbar)
world = World()
world.load()

buttonGroup = tk.Frame(function)
sliderGroup = tk.Frame(function)

play = tk.Button(buttonGroup, text="Action")
playPNG = tk.PhotoImage(file="png/play-button.png")
pausePNG = tk.PhotoImage(file="png/pause.png")
play.config(compound=tk.LEFT,
            image=playPNG,
            width="70",
            height="24",
            bg="#FFFFFF",
            command=lambda: op.runModel())
play.pack(side=tk.LEFT, padx=2, pady=2)
Exemple #4
0
path = os.path.join(os.getcwd(), "data")
START_DENSITY = 0.005
TERMINATE_DENSITY = 0.9
STEP = 0.005
ITERATION = 10
CAR_NUM = 15
START_COLLECT = 10000
checkLockTime = 10000
zero = [0 for i in range(10)]
for car in range(15, 220, 5):
    print('Car number is {}'.format(car))
    i = 0
    while i < ITERATION:
        print('exp{}'.format(i + 1))
        world = World(exp=True)
        world.load()
        world.carsNumber = car
        expList = []
        time = 0
        zeroList = []
        while time < setDict["collecting_time"] + 1:
            world.onTick(0.2)
            if len(world.cars) == 0:
                print()
                break
            avgSpeed, avgDensity, flow = world.systemInfo()
            zeroList.append(0 if avgSpeed == 0.0 else 1)
            if time > 100 and zeroList[-10:] == zero:
                print()
                break
Exemple #5
0
 def sync(cls):
     now = datetime.now().strftime('%Y-%m-%d_%H')
     log.info(f'begin sync {now}')
     file_name = f"./data/{now}.json"
     if not os.path.exists(file_name):
         CrawlerService.crawler()
     raw_data = json.load(open(file_name, 'r'))
     data = raw_data['nCoV2019']
     date = datetime.now().strftime('%Y%m%d')
     world = World(date=date,
                   name='中国',
                   confirmed=data['totalConNum'],
                   suspected=data['totalSusNum'],
                   cured=data['totalCureNum'],
                   dead=data['totalDeathNum'],
                   add_confirmed=data['addCon'],
                   add_cured=data['addCure'],
                   add_dead=data['addDeath'],
                   add_suspected=data['addSus'])
     history_list = data['historyList']
     histories = []
     for history in history_list:
         histories.append(
             History(date=history['date'],
                     confirmed=history['conNum'],
                     cured=history['cureNum'],
                     dead=history['deathNum'],
                     suspected=history['susNum']))
     overseas_list = data['overseasList']
     worlds = []
     for overseas in overseas_list:
         worlds.append(
             World(date=date,
                   confirmed=overseas['conNum'],
                   cured=overseas['cureNum'],
                   suspected=overseas['susNum'],
                   dead=overseas['deathNum'],
                   name=overseas['name']))
     domestic_list = data['domesticList']
     provinces = []
     cities = []
     for domestic in domestic_list:
         provinces.append(
             Province(date=date,
                      province_name=domestic['name'],
                      short_name=domestic['name'],
                      confirmed=domestic['conNum'],
                      dead=domestic['deathNum'],
                      suspected=domestic['susNum'],
                      cured=domestic['cureNum']))
         city_list = domestic['cities']
         for city in city_list:
             cities.append(
                 City(date=date,
                      province_name=domestic['name'],
                      city_name=city['name'],
                      confirmed=city['conNum'],
                      suspected=city['susNum'],
                      cured=city['cureNum'],
                      dead=city['deathNum']))
     History.select().delete()
     History.bulk_insert(histories)
     World.select().filter(World.date == date).delete()
     world.insert()
     World.bulk_insert(worlds)
     Province.select().filter(Province.date == date).delete()
     Province.bulk_insert(provinces)
     City.select().filter(City.date == date).delete()
     City.bulk_insert(cities)
     log.info(f'sync {now} done')