Пример #1
0
def gen_routes():
    # gen trips
    cmd = SUMOPATH + "/tools/randomTrips.py -b %s -e %s -n %s -p %s -o %s --prefix=%s --trip-attributes=%s --additional-files=%s --min-distance=%s --fringe-factor %s --seed 1 " % (
        bt, et, netf, pt, tripf, pfx, tripa, vtp, mind, frg)
    print(cmd)
    subprocess.call(cmd, shell=True)

    if duarouter != "":
        elist = []
        with open(ef, 'r') as fd:
            for line in fd:
                line = line.strip()
                if line.startswith("<edge id"):
                    eid = line.split('"')[1]
                    elist.append(eid)
        wtime = int(duarouter.split(" ")[1])
        begt = int(bt)
        endt = int(et)
        disturb_edge_num = get_conf_int(cfg, 'disturb_edge_num')
        weight_traveltime_min = get_conf_int(cfg, 'weight_traveltime_min')
        weight_traveltime_max = get_conf_int(cfg, 'weight_traveltime_max')
        #duarouter-extra = --weight-period 1000 --weight-files net.weight.xml
        with open('net.weight.xml', 'w') as fd:
            fd.write(st1)
            cnt = 0
            while begt + wtime <= endt:
                fd.write(st3 % (begt, begt + wtime, cnt))
                cnt += 1
                avoid = []
                for i in range(disturb_edge_num):
                    ind = randint(0, len(elist) - 1)
                    while ind in avoid:
                        ind = randint(0, len(elist) - 1)
                    avoid.append(ind)
                    ee = elist[ind]
                    tt = randint(weight_traveltime_min, weight_traveltime_max)
                    fd.write(st4 % (ee, tt))
                fd.write(st5)
                begt += wtime
            fd.write(st2)

    # gen routes
    cmd = "duarouter -n %s -t %s --additional-files=%s -o %s --routing-algorithm %s %s" % (
        netf, tripf, vtp, rouf, alg, duarouter)
    print(cmd)
    subprocess.call(cmd, shell=True)
Пример #2
0
def gen_routes():
	# gen trips
	cmd= SUMOPATH+"/tools/randomTrips.py -b %s -e %s -n %s -p %s -o %s --prefix=%s --trip-attributes=%s --additional-files=%s --min-distance=%s --fringe-factor %s --seed 1 "%(bt,et,netf,pt,tripf,pfx,tripa,vtp,mind,frg)
	print(cmd)
	subprocess.call(cmd,shell=True)

	if duarouter!="" :
		elist = []
		with open(ef,'r') as fd:
			for line in fd:
				line=line.strip()
				if line.startswith("<edge id"):
					eid = line.split('"')[1]
					elist.append(eid)
		wtime = int(duarouter.split(" ")[1])
		begt = int(bt)
		endt = int(et)
		disturb_edge_num = get_conf_int(cfg,'disturb_edge_num')
		weight_traveltime_min = get_conf_int(cfg,'weight_traveltime_min')
		weight_traveltime_max = get_conf_int(cfg,'weight_traveltime_max')
		#duarouter-extra = --weight-period 1000 --weight-files net.weight.xml
		with open('net.weight.xml','w') as fd:
			fd.write(st1)
			cnt=0
			while begt+wtime<= endt:
				fd.write(st3%(begt,begt+wtime,cnt))
				cnt+=1
				avoid = []
				for i in range(disturb_edge_num):
					ind = randint(0,len(elist)-1)
					while ind in avoid:
						ind = randint(0,len(elist)-1)
					avoid.append(ind)
					ee = elist[ind]
					tt = randint(weight_traveltime_min,weight_traveltime_max)
					fd.write(st4%(ee,tt))
				fd.write(st5)
				begt+=wtime
			fd.write(st2)


	# gen routes
	cmd="duarouter -n %s -t %s --additional-files=%s -o %s --routing-algorithm %s %s"%(netf,tripf,vtp,rouf,alg,duarouter)
	print(cmd)
	subprocess.call(cmd,shell=True)
Пример #3
0
    2: 'bci3d4c',
    3: 'bci3d5',
    4: 'bci4d2a',
}
dataName2ind = {}
for k, v in ind2dataName.items():
    dataName2ind[v] = k

configfile = "conf.txt"
confs = "conf/conf-%s.txt"

My_IP = get_my_ip()
lg = Logger()
lg.lg_list([__file__])

from_conf = get_conf_int(configfile, "from_conf")
from_tasklist = get_conf_int(configfile, "from_tasklist")

use_cache = get_conf_int(configfile, "use_cache")
if use_cache:
    try:
        import memcache  # https://www.sinacloud.com/doc/_static/memcache.html
    except:
        use_cache = 0
if use_cache:
    CACHE_SIZE = 100 * 1024 * 1024 * 1024  # 10G
    CACHE_TIME = 0
    cache_place = get_conf(configfile, "cache_place")
    My_IP = get_my_ip()
    if iprint: print("cache loc " + cache_place)
    if cache_place == 'local':
Пример #4
0
from util import read_lines_as_list, read_lines_as_dic

from multiColSeqSeparate import multiColSeqSeparate

iprint = 1

HomeDir = os.path.expanduser("~")
User = getpass.getuser()

if HomeDir.endswith("shu"):
    WORKDIR = os.path.expanduser("~")
elif HomeDir.endswith("srallap"):
    WORKDIR = os.path.expanduser("~") + "/eeg"

configfile = "conf.txt"
from_conf = get_conf_int(configfile, "from_conf")
from_tasklist = get_conf_int(configfile, "from_tasklist")
dataSetsDir = get_conf(configfile, "dataSetsDir" + User)
dataProcDir = get_conf(configfile, "dataProcDir" + User)
rawfolder = get_conf(configfile, "rawfolder")
metafolder = get_conf(configfile, "metafolder")
datafolder = get_conf(configfile, "datafolder")

datasets = get_list_startswith(configfile, "datasets")
datapaths = [dataSetsDir + "/" + tmp + "/" for tmp in datasets]
if iprint: print(datapaths)

for i in range(len(datapaths)):
    confsuffix = datasets[i]
    path = datapaths[i]
    conf = conf = "conf/conf-" + confsuffix + ".txt"
Пример #5
0
#!/usr/bin/env python
# http://www.sumo.dlr.de/wiki/TraCI/Traffic_Lights_Value_Retrieval
import os, sys, traceback
import subprocess
import random, time
import json
import inspect
mypydir =os.path.abspath(os.path.dirname(inspect.getfile(inspect.currentframe())))
sys.path.append(mypydir+'/mytools')
from copy import deepcopy
import logging,glob
from datetime import datetime, timedelta
from readconf import get_conf,get_conf_int
configfile = "conf.txt"
LinkPerLane = 4  # each in-edge has # connection links at tls.
YellowTime = get_conf_int(configfile,"tls.yellow.time")-1 # all dts reduce 1.

iprintinfo = 0

class Tls:
    traci=None
    itruth = 0  # log the ground truth
    DataSize=10
    tlslogic2phn=[6,4,5,7,-1,2,0,1,3,-1] # tls phase index -> my ph num
    tls2ph2time = None

    def __init__(self,tlsid):
        self.id=tlsid
        #[1:size][0-4], [0][0] store pos, [0][1] last sorted pos
        self.movement=[[0 for col in range(5)] for row in range(Tls.DataSize)]
        self.ofpath=""
Пример #6
0
                if iprint >= 1: print("makedirs " + accountFolder + subdir)
                os.makedirs(accountFolder + subdir)

semaphore = Semaphore(prefix=StatsDir + os.sep + "time2rawTime.txt",
                      count=1)  # not in use.


def write_time2rawTime(tstr, rawt):  # not in use.
    with semaphore:
        with open(StatsDir + os.sep + "time2rawTime.txt", "a") as f:
            f.write(str(tstr) + " " + str(rawt) + "\n")


''' same in 2.py 4*.py 5*.py files: '''
kCutTraceTimeGap = get_conf_int(
    configfile,
    "kCutTraceTimeGap")  # timestamp between two lines > this then cut.
kCutTraceDistGap = min(150, kCutTraceTimeGap *
                       50)  # dist between two lines > this then cut.

accountRawList = glob.glob(DirRaw + os.sep + "*")

for iddir in accountRawList:

    email = iddir.strip(os.sep).split(os.sep)[-1]
    accountFolder = DirData + os.sep + email + os.sep
    ''' note: gps/obd seq is NOT always continuous, have gaps, have break!'''
    gflist = glob.glob(iddir + os.sep + gpsfolder + os.sep + "*" + EXT)

    for gfn in gflist:  # e.g. ~/greendrive/proc/email/gps/utime.gz
Пример #7
0
# http://www.sumo.dlr.de/wiki/TraCI/Traffic_Lights_Value_Retrieval
import os, sys, traceback
import subprocess
import random, time
import json
import inspect
mypydir = os.path.abspath(
    os.path.dirname(inspect.getfile(inspect.currentframe())))
sys.path.append(mypydir + '/mytools')
from copy import deepcopy
import logging, glob
from datetime import datetime, timedelta
from readconf import get_conf, get_conf_int
configfile = "conf.txt"
LinkPerLane = 4  # each in-edge has # connection links at tls.
YellowTime = get_conf_int(configfile,
                          "tls.yellow.time") - 1  # all dts reduce 1.

iprintinfo = 0


class Tls:
    traci = None
    itruth = 0  # log the ground truth
    DataSize = 10
    tlslogic2phn = [6, 4, 5, 7, -1, 2, 0, 1, 3,
                    -1]  # tls phase index -> my ph num
    tls2ph2time = None

    def __init__(self, tlsid):
        self.id = tlsid
        #[1:size][0-4], [0][0] store pos, [0][1] last sorted pos
Пример #8
0
iprint = 1

HomeDir = os.path.expanduser("~")
User = getpass.getuser()

if HomeDir.endswith("shu"):
    WORKDIR = os.path.expanduser("~")
elif HomeDir.endswith("srallap"):
    WORKDIR = os.path.expanduser("~") + "/eeg"

configfile = "conf.txt"

import memcache  # https://www.sinacloud.com/doc/_static/memcache.html
CACHE_TIME = 0  # or unix 1497190272, if larger than 30 days.
CACHE_SIZE = 100 * 1024 * 1024 * 1024  # 100G, no use, use etc/config
use_cache = get_conf_int(configfile, "use_cache")
if not use_cache:
    print(
        __file__.split("/")[-1], "did not plan to use cache, exit, edit conf")
    sys.exit(0)

cache_place = get_conf(configfile, "cache_place")

my_ip = get_my_ip()
print("my_ip", my_ip)

if cache_place == 'local':
    mc = memcache.Client(['127.0.0.1:11211'],
                         server_max_value_length=CACHE_SIZE)

elif cache_place == 'servers':