Example #1
0
def generate(n, l, nlanes):
    aux.check('simulations/netDef/')
    aux.check('simulations/netDef/csv/')
    aux.check('simulations/netDef/xml/')
    aux.check('simulations/input/')

    #generates the network
    networkgenerator.networkgenerator(l, n, nlanes)
    #generates the necessary files (C.dat, J.dat, E.dat ...)
    aux.check('simulations/postprocess/data/')
    files.dat()
Example #2
0
def test(tsim, seed, maxDur, frequency, ncases):
    #it differs from the train function because in this case there is only one maxDur
    #and then the files containing the times are not required
    start_time = time.time()

    cases = range(0, ncases)

    aux.check('output/')

    aux.check('output/test/')
    aux.check('output/test/detectors/')
    aux.check('output/test/tripinfo/')

    aux.check('output/xml/')

    #generates de configuration file
    files.configuration(tsim)

    for case in cases:
        start_traffic = time.time()
        print '-------- Generating traffic files --------'
        #generates the traffic for the simulation
        tripsGenerator.writeTrips(0, tsim, 'case' + str(case), seed)
        subprocess.call([
            "duarouter", "-n", "simulations/input/mapa.net.xml", "-t",
            "simulations/input/trips.trips.xml", "-o",
            "simulations/input/rutes.rou.xml", "--unsorted-input", "true",
            "--ignore-errors", "true", "--departspeed", "10", "--departlane",
            "free"
        ])

        print 'Traffic generation time: {} seconds'.format(
            str(time.time() - start_traffic))
        print ''

        print '-------- Simulating case {case} with  maxDur of reference {maxDur} seconds --------'.format(
            case=case, maxDur=maxDur)
        #generate additional file for the simulation
        files.additional(maxDur, frequency)

        start_simulation = time.time()
        #runs the simulation
        subprocess.call([
            "sumo", "-c", "configuration.sumocfg", "--xml-validation", "never",
            "--time-to-teleport", "-1", "--seed",
            str(seed)
        ])
        print ''
        os.system(
            "$SUMO_HOME/tools/xml/xml2csv.py output/xml/tripinfo.xml -o output/test/tripinfo/tripinfo{case}m{maxDur}s{seed}.csv"
            .format(case=case, maxDur=maxDur, seed=seed))
Example #3
0
import subprocess
from simulations.pythons import auxiliary as aux
ncases = 8
maxDur = 25
seed_train = 10
#seed_test = 20
#seed_NS = seed_test

#put all the generated data for every case in one file (for each case)
#train
#subprocess.call(['Rscript', 'analysis/preprocess/getDataFiles.R', 'train', str(maxDur), str(seed_train), str(ncases)])
#subprocess.call(['Rscript', 'analysis/preprocess/getDataFiles3.R', 'train', str(maxDur), str(seed_train), str(ncases)])

#test
#subprocess.call(['Rscript', 'analysis/preprocess/getDataFiles.R', 'test', str(maxDur), str(seed_test), str(ncases)])
#subprocess.call(['Rscript', 'analysis/preprocess/getDataFiles3.R', 'test', str(maxDur), str(seed_train), str(ncases)])

#non stationary
for seed in range(20, 111, 10):
    subprocess.call([
        'Rscript', 'analysis/preprocess/getDataFiles.R', 'NS',
        str(maxDur),
        str(seed),
        str(ncases)
    ])
    #subprocess.call(['Rscript', 'analysis/preprocess/getDataFiles3.R', 'NS', str(maxDur), str(seed_test), str(ncases)])

#predicts the time for several cases
aux.check('analysis/models/')
Example #4
0
def train(tsim, seed, values, frequency, ncases):
    start_time = time.time()

    cases = range(0, ncases)

    aux.check('output/train/')
    aux.check('output/train/times/')
    aux.check('output/train/times/travelTime/')
    aux.check('output/train/times/timeLoss/')
    aux.check('output/train/csv/')
    aux.check('output/train/csv/detectors/')
    aux.check('output/train/csv/tripinfo/')

    aux.check('output/xml/')

    #generates de configuration file
    files.configuration(tsim)
    start_train = time.time()
    for case in cases:
        start_traffic = time.time()
        print '-------- Generating traffic files --------'
        timesDoc = open(
            "output/train/times/travelTime/" + 'case' + str(case) + ".csv",
            'w')
        timesDoc.write('maxDur;meanTime;maxTime\n')
        timesLoss = open(
            "output/train/times/timeLoss/" + 'case' + str(case) + "Loss.csv",
            'w')
        timesLoss.write('maxDur;meanLoss;maxLoss\n')

        #generates the traffic for the simulation
        tripsGenerator.writeTrips(0, tsim, 'case' + str(case), seed)
        subprocess.call([
            "duarouter", "-n", "simulations/input/mapa.net.xml", "-t",
            "simulations/input/trips.trips.xml", "-o",
            "simulations/input/rutes.rou.xml", "--unsorted-input", "true",
            "--ignore-errors", "true", "--departspeed", "10", "--departlane",
            "free"
        ])

        print 'Traffic generation time: {} seconds'.format(
            str(time.time() - start_traffic))
        print ''

        for i in range(len(values)):
            maxDur = values[i]
            print '-------- Simulating case {case} with  maxDur {maxDur} seconds --------'.format(
                case=case, maxDur=maxDur)
            #generate additional file for the simulation
            files.additional(maxDur, frequency)

            #runs the simulation
            start_simulation = time.time()
            subprocess.call([
                "sumo", "-c", "configuration.sumocfg", "--xml-validation",
                "never", "--time-to-teleport", "-1", "--seed",
                str(seed)
            ])
            print ''
            os.system(
                "$SUMO_HOME/tools/xml/xml2csv.py output/xml/tripinfo.xml -o output/train/csv/tripinfo/tripinfo{case}m{maxDur}s{seed}.csv"
                .format(case=case, maxDur=maxDur, seed=seed))
            os.system(
                "$SUMO_HOME/tools/xml/xml2csv.py output/xml/detectors.xml -o output/train/csv/detectors/detectors{case}m{maxDur}s{seed}.csv"
                .format(case=case, maxDur=maxDur, seed=seed))
Example #5
0
def run_states(t_change, t_sim, seed, maxDur1, maxDur2, frequency, case):
    aux.check('output/')
    aux.check('output/testTLS/')
    aux.check('output/testTLS/states/')
    aux.check('output/testTLS/detectors/')
    aux.check('output/testTLS/detectors/original/')
    aux.check('output/testTLS/tripinfo/')

    aux.check('output/xml/')

    #generates the traffic for the simulation
    tripsGenerator.writeTrips(0, t_sim, 'case' + str(case) + 'NS', seed)
    subprocess.call([
        "duarouter", "-n", "simulations/input/mapa.net.xml", "-t",
        "simulations/input/trips.trips.xml", "-o",
        "simulations/input/rutes.rou.xml", "--unsorted-input", "true",
        "--ignore-errors", "true", "--departspeed", "10", "--departlane",
        "free"
    ])
    #runs the simulation
    files.additional(maxDur1, frequency)
    files.configuration2(0, t_change)
    subprocess.call([
        "sumo", "-c", "configuration.sumocfg", "--xml-validation", "never",
        "--time-to-teleport", "-1", "--seed",
        str(seed), "--save-state.times",
        str(t_change), "--save-state.files", "state.sbx"
    ])
    os.system(
        "$SUMO_HOME/tools/xml/xml2csv.py output/xml/tripinfo.xml -o output/tripinfo1.csv"
    )
    os.system(
        "$SUMO_HOME/tools/xml/xml2csv.py output/xml/detectors.xml -o output/detectors1.csv"
    )
    #reconfigure the tls
    files.configuration2(t_change, t_sim)
    files.additional(maxDur2, frequency)
    #continue the simulation with the new configuration
    subprocess.call([
        "sumo", "-c", "configuration.sumocfg", "--xml-validation", "never",
        "--time-to-teleport", "-1", "--seed",
        str(seed), "--load-state", "state.sbx"
    ])

    os.system(
        "$SUMO_HOME/tools/xml/xml2csv.py output/xml/tripinfo.xml -o output/tripinfo2.csv"
    )
    os.system(
        "$SUMO_HOME/tools/xml/xml2csv.py output/xml/detectors.xml -o output/detectors2.csv"
    )

    #merge the files into one
    os.system(
        "mv output/tripinfo1.csv output/testTLS/tripinfo/tripinfo{case}s{seed}t{time}.csv"
        .format(case=case, seed=seed, time=str(t_change)))
Example #6
0
def save_states(t_sim, seed, maxDur, frequency, case):
    aux.check('output/')
    aux.check('output/testTLS/')
    aux.check('output/testTLS/states/')
    aux.check('output/testTLS/detectors/')
    aux.check('output/testTLS/detectors/original/')
    aux.check('output/testTLS/tripinfo/')

    aux.check('output/xml/')

    #generates the traffic for the simulation
    tripsGenerator.writeTrips(0, t_sim, 'case' + str(case) + 'NS', seed)
    subprocess.call([
        "duarouter", "-n", "simulations/input/mapa.net.xml", "-t",
        "simulations/input/trips.trips.xml", "-o",
        "simulations/input/rutes.rou.xml", "--unsorted-input", "true",
        "--ignore-errors", "true", "--departspeed", "10", "--departlane",
        "free"
    ])
    break_times = range(115 * 60, 156 * 60,
                        60)  #every minute (40 states saved)
    times = build_string(break_times)

    #runs the simulations to save all the states
    files.additional(maxDur, frequency)
    files.configuration2(0, t_sim)
    subprocess.call([
        'sumo', '-c', 'configuration.sumocfg', '--xml-validation', 'never',
        '--time-to-teleport', '-1', '--seed',
        str(seed), '--save-state.times', times, '--save-state.prefix',
        'output/testTLS/states/state'
    ])
    os.system(
        "$SUMO_HOME/tools/xml/xml2csv.py output/xml/tripinfo.xml -o output/testTLS/tripinfo.csv"
    )
    os.system(
        "$SUMO_HOME/tools/xml/xml2csv.py output/xml/detectors.xml -o output/testTLS/detectors.csv"
    )
Example #7
0
            .format(case=case, maxDur=maxDur, seed=seed))
        os.system(
            "$SUMO_HOME/tools/xml/xml2csv.py output/xml/detectors.xml -o output/NS/detectors/original/detectors{case}m{maxDur}s{seed}.csv"
            .format(case=case, maxDur=maxDur, seed=seed))
        print 'Simulation and conversion time {} seconds'.format(
            str(time.time() - start_simulation))

    print '\nTotal time of running non-stationary simulations: {} seconds'.format(
        str(time.time() - start_time))
    print '_______________________________________________________________\n'


def changeTLS(t_change, t_sim, seed, maxDur1, maxDur2, frequency, case,
              algorithm):

    aux.check('output/')
    aux.check('output/changeTLS/')
    aux.check('output/changeTLS/detectors/')
    aux.check('output/changeTLS/detectors/' + algorithm + '/')
    aux.check('output/changeTLS/tripinfo/')
    aux.check('output/changeTLS/tripinfo/' + algorithm + '/')

    aux.check('output/xml/')

    #generates the traffic for the simulation
    tripsGenerator.writeTrips(0, t_sim, 'case' + str(case) + 'NS', seed)
    subprocess.call([
        "duarouter", "-n", "simulations/input/mapa.net.xml", "-t",
        "simulations/input/trips.trips.xml", "-o",
        "simulations/input/rutes.rou.xml", "--unsorted-input", "true",
        "--ignore-errors", "true", "--departspeed", "10", "--departlane",