Beispiel #1
0
def NodesOut_init(model, node, route_no):
    out = []

    if node == 'source':
        start_node = write_data.roadSeg_to_node(model.Routes[route_no][0],
                                                model.nLayers.value)
        for i in range(model.nLayers.value):
            out.append(start_node + i)

    elif node == 'destination':
        return out

    else:

        roadSeg = write_data.node_to_roadSeg(node, model.nLayers.value)
        if roadSeg not in model.Routes[route_no]:
            return out
        soc = write_data.node_to_soc(node, model.nLayers.value)
        if soc < 1.0e-10 and roadSeg != model.Routes[route_no][0]:
            out.append('destination')
            return out

        if roadSeg == model.Routes[route_no][-1]:
            out.append('destination')
        elif roadSeg == model.Routes[route_no][0]:
            next_roadSeg = model.Routes[route_no][1]
            next_start_node = write_data.roadSeg_to_node(
                next_roadSeg, model.nLayers.value)
            if node == write_data.roadSeg_to_node(roadSeg,
                                                  model.nLayers.value):
                out.append(next_start_node)
                out.append(next_start_node + 1)
        else:
            roadSeg_indx = model.Routes[route_no].index(roadSeg)
            next_roadSeg = model.Routes[route_no][roadSeg_indx + 1]
            next_start_node = write_data.roadSeg_to_node(
                next_roadSeg, model.nLayers.value)
            current_soc = write_data.node_to_soc(node, model.nLayers.value)
            if current_soc > 1.0e-10:
                #INSTALL = True
                INSTALL = True
                next_soc = write_data.nextSOC(current_soc, INSTALL,
                                              model.nLayers.value)
                next_node_posn = write_data.position_in_layer(
                    next_soc, model.nLayers.value)
                next_node = next_start_node + next_node_posn
                out.append(next_node)

                #INSTALL = False
                INSTALL = False
                next_soc = write_data.nextSOC(current_soc, INSTALL,
                                              model.nLayers.value)
                next_node_posn = write_data.position_in_layer(
                    next_soc, model.nLayers.value)
                next_node = next_start_node + next_node_posn
                if next_node != out[-1]:
                    out.append(next_node)

    return out
Beispiel #2
0
def NodesIn_init(model, node, route_no):
    out = []

    if node == 'source':
        return out

    elif node == 'destination':
        start_node = write_data.roadSeg_to_node(model.Routes[route_no][-1],
                                                model.nLayers.value)
        for i in range(model.nLayers.value):
            out.append(start_node + i)
        for roadSeg in model.Routes[route_no][1:-1]:
            start_node = write_data.roadSeg_to_node(roadSeg,
                                                    model.nLayers.value)
            out.append(start_node + model.nLayers.value - 1)

    else:
        roadSeg = write_data.node_to_roadSeg(node, model.nLayers.value)
        if roadSeg not in model.Routes[route_no]:
            return out
        if roadSeg == model.Routes[route_no][0]:
            out.append('source')
        else:
            roadSeg_indx = model.Routes[route_no].index(roadSeg)
            prev_roadSeg = model.Routes[route_no][roadSeg_indx - 1]
            prev_start_node = write_data.roadSeg_to_node(
                prev_roadSeg, model.nLayers.value)
            current_soc = write_data.node_to_soc(node, model.nLayers.value)
            prev_soc = write_data.prevSOC(current_soc, model.nLayers.value)
            posn = [
                write_data.position_in_layer(soc, model.nLayers.value)
                for soc in prev_soc
            ]
            if roadSeg == model.Routes[route_no][1]:
                if 0 in posn:
                    out.append(prev_start_node)
            else:
                out = [prev_start_node + i for i in posn]

    return out
Beispiel #3
0
def NodesOut_init(model, node, route_no):

    out = []

    if route_no not in model.nodes_in_dic:
        #print 'cccc'
        model.nodes_in_dic[route_no] = {}
        model.nodes_in_dic[route_no][node] = []
    elif node not in model.nodes_in_dic[route_no]:
        #print 'route_no: ', route_no, model.nodes_in_dic[route_no]
        #print 'dddd', node

        model.nodes_in_dic[route_no][node] = []

    #print model.nodes_in_dic[route_no]
    if node == 'source':
        start_node = write_data.roadSeg_to_node(model.Routes[route_no][0],
                                                model.nLayers.value)
        for i in range(model.nLayers.value):
            out.append(start_node + i)
            if start_node + i not in model.nodes_in_dic[route_no]:
                model.nodes_in_dic[route_no][start_node + i] = [node]
            else:
                model.nodes_in_dic[route_no][start_node + i].append(node)

    elif node == 'destination':

        return out

    else:
        roadSeg = write_data.node_to_roadSeg(node, model.nLayers.value)
        if roadSeg not in model.Routes[route_no]:
            return out
        standard_soc = write_data.node_to_soc(node, model.nLayers.value)

        if standard_soc < 1.0e-10 and roadSeg != model.Routes[route_no][0]:
            out.append('destination')
            if 'destination' not in model.nodes_in_dic[route_no]:
                model.nodes_in_dic[route_no]['destination'] = [node]
            else:
                model.nodes_in_dic[route_no]['destination'].append(node)
            return out

        if roadSeg == model.Routes[route_no][-1]:
            out.append('destination')
            if 'destination' not in model.nodes_in_dic[route_no]:
                model.nodes_in_dic[route_no]['destination'] = [node]
            else:
                model.nodes_in_dic[route_no]['destination'].append(node)
        elif roadSeg == model.Routes[route_no][0]:
            next_roadSeg = model.Routes[route_no][1]
            next_start_node = write_data.roadSeg_to_node(
                next_roadSeg, model.nLayers.value)
            if node == write_data.roadSeg_to_node(roadSeg,
                                                  model.nLayers.value):
                current_standard_soc = write_data.node_to_soc(
                    node, model.nLayers.value)
                current_range_soc = standard_soc_to_range_soc(
                    model, current_standard_soc)
                velocity = model.graph.node[str(roadSeg -
                                                2)]['speed_urban'] * 0.01
                distance = model.graph.node[str(roadSeg -
                                                2)]['length'] * 0.00621371
                INSTALL = True
                next_range_soc = write_data.nextSOC_real_data(
                    current_range_soc, distance, 1, velocity, INSTALL)
                next_standard_soc = range_soc_to_standard_soc(
                    model, next_range_soc)
                next_node_posn = write_data.position_in_layer(
                    next_standard_soc, model.nLayers.value)
                next_node = next_start_node + next_node_posn
                out.append(next_node)
                if next_node not in model.nodes_in_dic[route_no]:
                    model.nodes_in_dic[route_no][next_node] = [node]
                else:
                    model.nodes_in_dic[route_no][next_node].append(node)

                INSTALL = False
                next_range_soc = write_data.nextSOC_real_data(
                    current_range_soc, distance, 1, velocity, INSTALL)
                next_standard_soc = range_soc_to_standard_soc(
                    model, next_range_soc)
                next_node_posn = write_data.position_in_layer(
                    next_standard_soc, model.nLayers.value)
                next_node = next_start_node + next_node_posn
                out.append(next_node)

                #out.append(next_start_node)
                #out.append(next_start_node + 1)
                if next_node not in model.nodes_in_dic[route_no]:
                    model.nodes_in_dic[route_no][next_node] = [node]
                else:
                    model.nodes_in_dic[route_no][next_node].append(node)
                #print out
            '''     
      elif roadSeg == model.Routes[route_no][-2]:
        next_roadSeg = model.Routes[route_no][-1]
        next_start_node = write_data.roadSeg_to_node(next_roadSeg, model.nLayers.value)
        current_standard_soc = write_data.node_to_soc(node, model.nLayers.value)
        node_posn = write_data.position_in_layer(current_standard_soc, model.nLayers.value)
        out.append(next_start_node + node_posn)
        if next_start_node + node_posn not in model.nodes_in_dic[route_no]:
          model.nodes_in_dic[route_no][next_start_node + node_posn] = [node]
        else:
          model.nodes_in_dic[route_no][next_start_node + node_posn].append(node)
      '''
        else:

            roadSeg_indx = model.Routes[route_no].index(roadSeg)
            next_roadSeg = model.Routes[route_no][roadSeg_indx + 1]
            next_start_node = write_data.roadSeg_to_node(
                next_roadSeg, model.nLayers.value)
            current_standard_soc = write_data.node_to_soc(
                node, model.nLayers.value)

            if current_standard_soc > 1.0e-10:
                #INSTALL = True

                INSTALL = True
                velocity = model.graph.node[str(roadSeg -
                                                2)]['speed_urban'] * 0.01
                distance = model.graph.node[str(roadSeg -
                                                2)]['length'] * 0.00621371
                current_range_soc = standard_soc_to_range_soc(
                    model, current_standard_soc)
                next_range_soc = write_data.nextSOC_real_data(
                    current_range_soc, distance, 1, velocity, INSTALL)
                next_standard_soc = range_soc_to_standard_soc(
                    model, next_range_soc)
                next_node_posn = write_data.position_in_layer(
                    next_standard_soc, model.nLayers.value)
                next_node = next_start_node + next_node_posn
                #print next_soc
                if node == 506112:
                    print "\n \t", velocity, distance
                out.append(next_node)
                if next_node not in model.nodes_in_dic[route_no]:
                    model.nodes_in_dic[route_no][next_node] = [node]
                else:
                    model.nodes_in_dic[route_no][next_node].append(node)

                #INSTALL = False
                INSTALL = False
                velocity = model.graph.node[str(roadSeg -
                                                2)]['speed_urban'] * 0.01
                distance = model.graph.node[str(roadSeg -
                                                2)]['length'] * 0.00621371
                current_range_soc = standard_soc_to_range_soc(
                    model, current_standard_soc)
                next_range_soc = write_data.nextSOC_real_data(
                    current_range_soc, distance, 1, velocity, INSTALL)
                next_standard_soc = range_soc_to_standard_soc(
                    model, next_range_soc)
                next_node_posn = write_data.position_in_layer(
                    next_standard_soc, model.nLayers.value)
                next_node = next_start_node + next_node_posn
                #print next_soc
                if next_node != out[-1]:
                    out.append(next_node)
                    if next_node not in model.nodes_in_dic[route_no]:
                        model.nodes_in_dic[route_no][next_node] = [node]
                    else:
                        model.nodes_in_dic[route_no][next_node].append(node)
                    #model.nodes_in_dic[route_no][next_node].append(node)
    #print out

    return out