from multiprocessing import Pool
from CarController import CarController
from Map import Map

def runSim(paths):
    m = Map()
    cc = CarController(m)
    m.fromPath(paths[0])
    cc.fromPath(paths[1])
    cc.prepareRoute()
    while cc.t < 3600:
        cc.update()
    newline = '\n'
    return f"{paths[0]}/{paths[1]} : \ntemps d'arrêt moyen : {cc.totalStopped / cc.carsDestroyed:.2f}s/voitures \n<vitesse/vitesse max>T : {cc.speedPercentageTotal / cc.carsDestroyed:.2f} \nbacklog total : {cc.getFlowBacklog():.2f} \n {newline.join(f'{f.id} : {f.backlog(cc.t):.2f}' for f in cc.flows)}"

nbThreads = 7
poly = "rdpt_polytech_fixed.net.xml"
paths = [
            [poly, "rdpt_polytech_burst_moy.rou.xml"],
            [poly, "rdpt_polytech_burst_moy_dynSpeed.rou.xml"],
            [poly, "rdpt_polytech_burst_moy_div2.rou.xml"],
            [poly, "rdpt_polytech_burst_moy_IA.rou.xml"],
            ["rdpt_polytech_shortcut_3.net.xml", "rdpt_polytech_burst_moy_shortcut_3.rou.xml"],
            ["comp_inter.net.xml", "comp_inter.rou.xml"],
            ["comp_rdp.net.xml", "comp_rdp.rou.xml"]
        ]
with Pool(nbThreads) as p:
    for l in p.map(runSim,paths):
        print(l)
