def initial_network(config, locator):
    """
    Initiate data of main problem (not all the dict_length is included in this case)

    :returns:
        - **points_on_line** : information about every node in study case
        - **tranches** : tranches
        - **dict_length** : dictionary containing lengths
        - **dict_path** : dictionary containing paths
    :rtype: geodf, geodf, dict, dict

    """

    # localfiles
    input_buildings_shp = locator.get_electric_substation_input_location()
    output_substations_shp = locator.get_electric_substation_output_location()
    input_streets_shp = locator.get_street_network()

    # calcualte and save file with location
    building_points, _ = calc_substation_location(input_buildings_shp,
                                                  output_substations_shp, [])
    points_on_line, tranches = gia.connect_building_to_grid(
        building_points, input_streets_shp)
    points_on_line_processed = gia.process_network(points_on_line, config,
                                                   locator)
    dict_length, dict_path = gia.create_length_dict(points_on_line_processed,
                                                    tranches)

    return points_on_line_processed, tranches, dict_length, dict_path
Example #2
0
def initial_network(config, locator):
    """
    Initiate data of main problem

    :param config:
    :param locator:
    :returns:
        - **points_on_line** : information about every node in study case
        - **tranches** : tranches
        - **dict_length** : dictionary containing lengths
        - **dict_path** : dictionary containing paths
    :rtype: geodf, geodf, dict, dict

    """

    input_buildings_shp = locator.get_electric_substation_input_location()
    output_substations_shp = locator.get_electric_substation_output_location()
    input_streets_shp = locator.get_street_network()

    building_points, _ = calc_substation_location(input_buildings_shp,
                                                  output_substations_shp, [])
    # connect building nodes to street
    points_on_line, tranches = gia.connect_building_to_grid(
        building_points, input_streets_shp)
    # write node types (consumer/plant) in the attribute table
    points_on_line_processed = gia.process_network(points_on_line, config,
                                                   locator)
    # get lengths of all edges
    dict_length, dict_path = gia.create_length_complete_dict(
        points_on_line_processed, tranches)

    return points_on_line_processed, tranches, dict_length, dict_path
def layout_network(network_layout, locator, plant_building_names=[], input_path_name='streets', output_name_network="",
                   optimization_flag=False):
    # Local variables
    weight_field = 'Shape_Leng'
    total_demand_location = locator.get_total_demand()
    path_potential_network = locator.get_temporary_file("potential_network.shp")  # shapefile, location of output.

    type_mat_default = network_layout.type_mat
    pipe_diameter_default = network_layout.pipe_diameter
    type_network = network_layout.network_type
    create_plant = network_layout.create_plant
    connected_buildings = network_layout.connected_buildings
    consider_only_buildings_with_demand = network_layout.consider_only_buildings_with_demand
    allow_looped_networks = network_layout.allow_looped_networks

    if input_path_name == 'streets':  # point to default location of streets file
        path_streets_shp = locator.get_street_network()  # shapefile with the stations
        input_buildings_shp = locator.get_zone_geometry()
        output_substations_shp = locator.get_temporary_file("nodes_buildings.shp")
        # Calculate points where the substations will be located
        calc_substation_location(input_buildings_shp, output_substations_shp, connected_buildings,
                                 consider_only_buildings_with_demand, type_network, total_demand_location)
    elif input_path_name == 'electrical_grid':  # point to location of electrical grid
        path_streets_shp = locator.get_electric_network_output_location(input_path_name)
        output_substations_shp = locator.get_electric_substation_output_location()
    else:
        raise Exception("the value of the variable input_path_name is not valid")

    # Calculate potential network
    crs_projected = calc_connectivity_network(path_streets_shp, output_substations_shp,
                                              path_potential_network)

    # calc minimum spanning tree and save results to disk
    output_edges = locator.get_network_layout_edges_shapefile(type_network, output_name_network)
    output_nodes = locator.get_network_layout_nodes_shapefile(type_network, output_name_network)
    output_network_folder = locator.get_input_network_folder(type_network, output_name_network)

    if connected_buildings != []:
        building_names = locator.get_zone_building_names()
        disconnected_building_names = [x for x in connected_buildings if x not in building_names]
    else:
        # if connected_buildings is left blank, we assume all buildings are connected (no disconnected buildings)
        disconnected_building_names = []
    calc_steiner_spanning_tree(crs_projected, path_potential_network, output_network_folder, output_substations_shp,
                               output_edges, output_nodes, weight_field, type_mat_default, pipe_diameter_default,
                               type_network, total_demand_location, create_plant,
                               allow_looped_networks, optimization_flag, plant_building_names, disconnected_building_names)
def plot_complete(m, config, locator, network_number, generation):

    points_on_line, tranches, dict_length, dict_path = initial_network(config, locator)
    var_x = m.var_x.values()

    # Plotting Graph
    fig, (ax1, ax2) = plt.subplots(1, 2, gridspec_kw={'width_ratios': [3, 1]})

    ax1.axis('auto')
    ax1.set_aspect('equal')
    ax1.set_axis_off()
    ax2.set_axis_off()

    # Plotting Buildings
    input_buildings_shp = locator.get_electric_substation_input_location()
    output_substations_shp = locator.get_electric_substation_output_location()
    building_points, building_poly = calc_substation_location(input_buildings_shp,output_substations_shp, [])
    building_poly.plot(ax=ax1, color='white', edgecolor='grey')

    for x in var_x:
        node_int = re.findall(r'\d+', x.local_name)

        start_node = int(node_int[0])
        end_node = int(node_int[1])
        type = int(node_int[1])

        list_path = dict_path[start_node][end_node]

        for idx_path, path in enumerate(list_path[:-1]):
            int_node1 = list_path[idx_path]
            int_node2 = list_path[idx_path + 1]

            geo_node1 = points_on_line.loc[int_node1].geometry.xy
            geo_node2 = points_on_line.loc[int_node2].geometry.xy

            ax1.plot((geo_node1[0][0],
                      geo_node2[0][0]),
                     (geo_node1[1][0],
                      geo_node2[1][0]),
                     color='grey')

        print start_node, end_node, type

    for idx, point in points_on_line.iterrows():
        name = str(point['Name'][4::])

        if point['Type'] == 'PLANT':
            ax1.plot(point.geometry.xy[0], point.geometry.xy[1], marker='o', color='red', markersize=5)
        elif point['Type'] == 'CONSUMER':
            ax1.plot(point.geometry.xy[0], point.geometry.xy[1], marker='o', color='green', markersize=5)
        else:  # intersection
            ax1.plot(point.geometry.xy[0], point.geometry.xy[1], marker='o', color='blue', markersize=5)

        ax1.text(point.geometry.xy[0][0], point.geometry.xy[1][0], name, fontsize=8)

    plt.savefig(locator.get_concept_network_plot_complete(network_number, generation))
Example #5
0
def connect_building_to_street(m, points_on_line, list_geo_thermal_network,
                               config, locator, dict_connected):
    """
    Connect centroid of every THERMAL consumer building to thermal network

    :param m: complete pyomo model
    :type m: pyomo model
    :param points_on_line: information about every node in study case
    :type points_on_line: GeoDataFrame
    :param list_geo_thermal_network: tuples with geo data of startnode and endnode
    :type list_geo_thermal_network: list(float, float)
    :param config:
    :param locator:
    :param dict_connected:
    :return: list_geo_thermal_network
    :rtype: list(float, float)

    """

    input_buildings_shp = locator.get_electric_substation_input_location()
    output_substations_shp = locator.get_electric_substation_output_location()
    building_centroids, poly = calc_substation_location(
        input_buildings_shp, output_substations_shp, [])

    list_connected = []
    for idx_connected, connected in enumerate(dict_connected):
        list_connected.append((idx_connected, int(connected)))

    for connected in list_connected:
        if connected[1]:
            int_node = connected[0]

            geo1 = points_on_line.iloc[int_node]['geometry'].xy
            geo2 = building_centroids.iloc[int_node]['geometry'].xy

            str_geo1 = str('[') + str(geo1[0][0]) + str(',') + str(
                geo1[1][0]) + str(']')
            str_geo2 = str('[') + str(geo2[0][0]) + str(',') + str(
                geo2[1][0]) + str(']')

            str_geo = str('[') + str_geo1 + str(',') + str_geo2 + str(']')
            list_geo_thermal_network.append(str_geo)

    return list_geo_thermal_network