Exemple #1
0
 def init_sumo(self):
     print("3、初始化sumo仿真对象")
     SUMO.junctions = dict()
     for jid in config.junctions:
         SUMO.junctions[jid] = Junction(jid)
         print("        3.1、初始化SUMO.junctions成员变量:", Junction(jid))
     self.sumo = SUMO(config.sumocfg)  #sumoconfig中应传入将要打开的.sumocfg文件的路径
     self.sumo.subInductionloop(config.cinductionloopid, config.clane,
                                config.radius)
Exemple #2
0
    def addToJunction(self, pos):
        x = pos[0]
        y = pos[1]
        junctionID = self.array_Junction[x][
            y]  # get the junction-ID of that point

        # if no junction-ID is alloted up till now
        if not junctionID:
            junctionID = len(self.list_Junction)  # get a new junction ID
            junction = Junction(
                pos,
                junctionID)  # create a new Junction type variable with that ID
            self.list_Junction.append(
                junction
            )  # append this Junction variable to the list - list_Junction

        # find the neighbours of that junction point in some given area
        for i in range(-2, 3):
            for j in range(-2, 3):
                if (x + i < 0) or (y + j < 0) or (x + i > self.row) or (
                        y + j > self.col):
                    continue
                if self.isSkeleton(
                        x + i,
                        y + j):  # if the neighbour is part of the skeleton
                    self.array_Junction[x + i][
                        y + j] = junctionID  # give it the same junction-ID
                    self.list_Junction[junctionID].addJunctionNeighbourhood([
                        x + i, y + j
                    ])  # append its position to the list - list_junctionArea
                    self.array_done[x + i][
                        y + j] = 1  # mark that neighbourhood point as done
        return
Exemple #3
0
    def process_detqueue(self):
        """
            封装检测器数据消息并发送到对应设备
            暂设所有检测器均无故障
        """
        while True:
            if not A_queuedata.det_queue.empty():
                detdata = A_queuedata.det_queue.get()
                for junctionid in config.junctions:
                    J = Junction(junctionid)
                    # detdata = {'J1_1': {16: 1}, 'J1_10': {16: 0}, 'J1_11': {16: 0}, 'J1_12': {16: 0}, 'J1_2': {16: 0},
                    #  'J1_3': {16: 0}, 'J1_4': {16: 0}, 'J1_5': {16: 0}, 'J1_6': {16: 0}, 'J1_7': {16: 0},
                    #  'J1_8': {16: 0}, 'J1_9': {16: 0}}
                    detstatus = ''.join(
                        ['1' if detdata[d][16] else '0' for d in J.detectors])
                    if len(detstatus) < 17:  #暂设检测器都没有故障,故障位全为0
                        tmp = detstatus + '0' * (64 - len(detstatus))
                    else:
                        tmp = detstatus[:16] + '0' * 16 + detstatus[
                            16:] + '0' * (48 - len(detstatus))
                    print(tmp)
                    try:
                        bindet = struct.pack('>Q', int(tmp, 2))

                    except Exception as e:
                        print("========================")
                        print(e)
                    udpcli = UDP_Client(J.addr, 0)
                    udpcli.send(bindet)
Exemple #4
0
def create_connection_function(data):
    connection_function = None
    con_type = data[2]
    if con_type == "terminator":
        connection_function = Terminator(data)
    elif con_type == "junction":
        connection_function = Junction(data)
    elif con_type == "connection":
        connection_function = Connection(data)
    return connection_function
Exemple #5
0
def System_Object_Creation(T,
                           Input_Data_File,
                           element_stochastic_components,
                           SystemObjects,
                           Element_Dict,
                           Flushing_Group_Dict,
                           stochastic_flow_list,
                           op_policy_params=None):

    # Purpose: To create all reservoir/reach/junction/diversion objects (instances of classes, e.g., Reservoir)

    # Inputs:
    # (1) All inputs created automatically within SedSim_v2.py using various functions called there.

    # Create all system objects (reservoirs, channels, diversions, junctions), already loaded in their correct simulation order.
    for i in SystemObjects["Ordered Simulation List"]:
        if Element_Dict[i]["Type"] == "Reservoir":
            SystemObjects[i] = Reservoir(
                i,
                T,
                Input_Data_File,
                Element_Dict[i],
                stochastic_components=element_stochastic_components[i],
                op_policy_params=op_policy_params)
            # If the simulated system will have reservoirs with flushing performed, need to create a dictionary storing flushing group ID
            #  and non_drawdown group ID, to be fed back to each reservoir and stored there.
            if SystemObjects[i].Flushing_Group_ID is not None:
                # If reservoir has a flushing group ID, create such a key in the Flushing ID dictionary.
                if SystemObjects[
                        i].Flushing_Group_ID not in Flushing_Group_Dict[
                            "Flushing Group ID"]:
                    # Store reservoir names with this ID in a list.
                    Flushing_Group_Dict["Flushing Group ID"][
                        SystemObjects[i].Flushing_Group_ID] = []
                    Flushing_Group_Dict["Flushing Group ID"][
                        SystemObjects[i].Flushing_Group_ID].append(
                            SystemObjects[i].name)
                else:
                    # Key ID already exists. Add Reservoir name to list.
                    Flushing_Group_Dict["Flushing Group ID"][
                        SystemObjects[i].Flushing_Group_ID].append(
                            SystemObjects[i].name)
            if SystemObjects[i].Non_Flushing_Group_ID is not None:
                # If reservoir has a flushing group NON-DRAWDOWN ID, create such a key in the Non-drawdown Flushing ID dictionary.
                if SystemObjects[
                        i].Non_Flushing_Group_ID not in Flushing_Group_Dict[
                            "Non Drawdown Flushing Group ID"]:
                    # Store reservoir names with this ID in a list.
                    Flushing_Group_Dict["Non Drawdown Flushing Group ID"][
                        SystemObjects[i].Non_Flushing_Group_ID] = []
                    Flushing_Group_Dict["Non Drawdown Flushing Group ID"][
                        SystemObjects[i].Non_Flushing_Group_ID].append(
                            SystemObjects[i].name)
                else:
                    # Key ID already exists. Add Reservoir name to list.
                    Flushing_Group_Dict["Non Drawdown Flushing Group ID"][
                        SystemObjects[i].Non_Flushing_Group_ID].append(
                            SystemObjects[i].name)
        elif Element_Dict[i]["Type"] == "Reach":
            SystemObjects[i] = Channel(i, T, Input_Data_File, Element_Dict[i],
                                       element_stochastic_components[i])
        elif Element_Dict[i]["Type"] == "Junction":
            SystemObjects[i] = Junction(i, T, Input_Data_File, Element_Dict[i],
                                        element_stochastic_components[i],
                                        stochastic_flow_list)
        elif Element_Dict[i]["Type"] == "Diversion":
            SystemObjects[i] = Diversion_Channel(
                i, T, Input_Data_File, Element_Dict[i],
                element_stochastic_components[i])
        elif Element_Dict[i]["Type"] == "Bypass Structure":
            SystemObjects[i] = Bypass_Structure(i, T, Input_Data_File,
                                                Element_Dict[i])

    # Store the Flushing Group Dictionary as part of each reservoir's attributes
    for i in SystemObjects["Ordered Simulation List"]:
        if Element_Dict[i]["Type"] == "Reservoir":
            SystemObjects[i].Flushing_Dictionary = Flushing_Group_Dict

    return SystemObjects, Flushing_Group_Dict, element_stochastic_components
Exemple #6
0
        "please declare environment variable 'SUMO_HOME' as the root directory of \
        your sumo installation (it should contain folders 'bin', 'tools' and 'docs')")

import traci
from junction import Junction
from device import Device
from phaseConfig import setJunctionPhase

#===============================Generate Route File====================================

#put code to generate route file here, or better make it in some other python file, import and then run here!

#====================================Make Junctions====================================
junction_U = Junction(_id = 'U',
	dev_a_dets = ['0', '1', '2', '3', '4', '5'], 
	dev_b_dets = ['6', '7', '8', '9', '10', '11'], 
	dev_c_dets = ['54', '55', '56', '57', '58', '59'], 
	dev_d_dets = ['60', '61', '62', '63', '64', '65'],
	phaseMap = {1:1, 2:2, 3:4, 4:3})

junction_L = Junction(_id = 'L', 
	dev_a_dets = ['18', '19', '20', '21', '22', '23'], 
	dev_b_dets = ['12', '13', '14', '15', '16', '17'], 
	dev_c_dets = ['66', '67', '68', '69', '70', '71'], 
	dev_d_dets = ['24', '25', '26', '27', '28', '29'],
	phaseMap = {1:1, 2:2, 3:4, 4:3})

junction_R = Junction(_id = 'R', 
	dev_a_dets = ['30', '31', '32', '33', '34', '35'], 
	dev_b_dets = ['48', '49', '50', '51', '52', '53'], 
	dev_c_dets = ['36', '37', '38', '39', '40', '41'], 
	dev_d_dets = ['42', '43', '44', '45', '46', '47'],
Exemple #7
0
 def add_junktion(self, angle, radius):
     junc = Junction(self.pos + [radius * cos(angle), radius * sin(angle)])
     self.junctions[angle] = junc
Exemple #8
0
def build_junctions():
    j_ids = global_hparams.junctions
    backend = sumo_backend.get_backend()
    junctions = [Junction(j_id, j_id, backend)
                 for j_id in j_ids]  # TODO: compute junction neighbors
    return junctions