def connect_lv_generators(network, allow_multiple_genos_per_load=True):
    """Connect LV generators to existing grids.

    This function searches for unconnected generators in all LV grids and
    connects them.

    It connects

        * generators of voltage level 6
            * to MV-LV station

        * generators of voltage level 7
            * with a nom. capacity of <=30 kW to LV loads of type residential
            * with a nom. capacity of >30 kW and <=100 kW to LV loads of type
                retail, industrial or agricultural
            * to the MV-LV station if no appropriate load is available
              (fallback)

    Parameters
    ----------
    network : :class:`~.grid.network.Network`
        The eDisGo container object
    allow_multiple_genos_per_load : :obj:`bool`
        If True, more than one generator can be connected to one load

    Notes
    -----
    For the allocation, loads are selected randomly (sector-wise) using a
    predefined seed to ensure reproducibility.

    """

    # get predefined random seed and initialize random generator
    seed = int(network.config['grid_connection']['random_seed'])
    #random.seed(a=seed)
    random.seed(a=1234)
    # ToDo: Switch back to 'seed' as soon as line ids are finished, #58

    # get standard equipment
    std_line_type = network.equipment_data['lv_cables'].loc[
        network.config['grid_expansion_standard_equipment']['lv_line']]
    std_line_kind = 'cable'

    # # TEMP: DEBUG STUFF
    # lv_grid_stats = pd.DataFrame(columns=('lv_grid',
    #                                       'load_count',
    #                                       'geno_count',
    #                                       'more_genos_than_loads')
    #                             )

    # iterate over all LV grids
    for lv_grid in network.mv_grid.lv_grids:

        lv_loads = lv_grid.graph.nodes_by_attribute('load')

        # counter for genos in v_level 7
        log_geno_count_vlevel7 = 0

        # generate random list (without replacement => unique elements)
        # of loads (residential) to connect genos (P <= 30kW) to.
        lv_loads_res = sorted([lv_load for lv_load in lv_loads
                               if 'residential' in list(lv_load.consumption.keys())],
                              key=lambda _: repr(_))

        if len(lv_loads_res) > 0:
            lv_loads_res_rnd = set(random.sample(lv_loads_res,
                                                 len(lv_loads_res)))
        else:
            lv_loads_res_rnd = None

        # generate random list (without replacement => unique elements)
        # of loads (retail, industrial, agricultural) to connect genos
        # (30kW < P <= 100kW) to.
        lv_loads_ria = sorted([lv_load for lv_load in lv_loads
                               if any([_ in list(lv_load.consumption.keys())
                                       for _ in ['retail', 'industrial', 'agricultural']])],
                              key=lambda _: repr(_))

        if len(lv_loads_ria) > 0:
            lv_loads_ria_rnd = set(random.sample(lv_loads_ria,
                                                 len(lv_loads_ria)))
        else:
            lv_loads_ria_rnd = None

        for geno in sorted(lv_grid.graph.nodes_by_attribute('generator'), key=lambda x: repr(x)):
            if nx.is_isolate(lv_grid.graph, geno):

                lv_station = lv_grid.station

                # generator is of v_level 6 -> connect to LV station
                if geno.v_level == 6:

                    line_length = calc_geo_dist_vincenty(network=network,
                                                         node_source=geno,
                                                         node_target=lv_station)

                    line = Line(id=random.randint(10 ** 8, 10 ** 9),
                                length=line_length / 1e3,
                                quantity=1,
                                kind=std_line_kind,
                                type=std_line_type,
                                grid=lv_grid)

                    lv_grid.graph.add_edge(geno,
                                           lv_station,
                                           line=line,
                                           type='line')

                    # add line to equipment changes to track costs
                    _add_cable_to_equipment_changes(network=network,
                                                    line=line)

                # generator is of v_level 7 -> assign geno to load
                elif geno.v_level == 7:
                    # counter for genos in v_level 7
                    log_geno_count_vlevel7 += 1

                    # connect genos with P <= 30kW to residential loads, if available
                    if (geno.nominal_capacity <= 30) and (lv_loads_res_rnd is not None):
                        if len(lv_loads_res_rnd) > 0:
                            lv_load = lv_loads_res_rnd.pop()
                        # if random load list is empty, create new one
                        else:
                            lv_loads_res_rnd = set(random.sample(lv_loads_res,
                                                                 len(lv_loads_res))
                                                   )
                            lv_load = lv_loads_res_rnd.pop()

                        # get cable distributor of building
                        lv_conn_target = lv_grid.graph.neighbors(lv_load)[0]

                        if not allow_multiple_genos_per_load:
                            # check if there's an existing generator connected to the load
                            # if so, select next load. If no load is available, connect to station.
                            while any([isinstance(_, Generator)
                                       for _ in lv_grid.graph.neighbors(
                                    lv_grid.graph.neighbors(lv_load)[0])]):
                                if len(lv_loads_res_rnd) > 0:
                                    lv_load = lv_loads_res_rnd.pop()

                                    # get cable distributor of building
                                    lv_conn_target = lv_grid.graph.neighbors(lv_load)[0]
                                else:
                                    lv_conn_target = lv_grid.station

                                    logger.debug(
                                        'No valid conn. target found for {}. '
                                        'Connected to {}.'.format(
                                            repr(geno),
                                            repr(lv_conn_target)
                                        )
                                    )
                                    break

                    # connect genos with 30kW <= P <= 100kW to residential loads
                    # to retail, industrial, agricultural loads, if available
                    elif (geno.nominal_capacity > 30) and (lv_loads_ria_rnd is not None):
                        if len(lv_loads_ria_rnd) > 0:
                            lv_load = lv_loads_ria_rnd.pop()
                        # if random load list is empty, create new one
                        else:
                            lv_loads_ria_rnd = set(random.sample(lv_loads_ria,
                                                                 len(lv_loads_ria))
                                                   )
                            lv_load = lv_loads_ria_rnd.pop()

                        # get cable distributor of building
                        lv_conn_target = lv_grid.graph.neighbors(lv_load)[0]

                        if not allow_multiple_genos_per_load:
                            # check if there's an existing generator connected to the load
                            # if so, select next load. If no load is available, connect to station.
                            while any([isinstance(_, Generator)
                                       for _ in lv_grid.graph.neighbors(
                                    lv_grid.graph.neighbors(lv_load)[0])]):
                                if len(lv_loads_ria_rnd) > 0:
                                    lv_load = lv_loads_ria_rnd.pop()

                                    # get cable distributor of building
                                    lv_conn_target = lv_grid.graph.neighbors(lv_load)[0]
                                else:
                                    lv_conn_target = lv_grid.station

                                    logger.debug(
                                        'No valid conn. target found for {}. '
                                        'Connected to {}.'.format(
                                            repr(geno),
                                            repr(lv_conn_target)
                                        )
                                    )
                                    break

                    # fallback: connect to station
                    else:
                        lv_conn_target = lv_grid.station

                        logger.debug(
                            'No valid conn. target found for {}. '
                            'Connected to {}.'.format(
                                repr(geno),
                                repr(lv_conn_target)
                            )
                        )

                    line = Line(id=random.randint(10 ** 8, 10 ** 9),
                                length=1e-3,
                                quantity=1,
                                kind=std_line_kind,
                                type=std_line_type,
                                grid=lv_grid)

                    lv_grid.graph.add_edge(geno,
                                           lv_station,
                                           line=line,
                                           type='line')

                    # add line to equipment changes to track costs
                    _add_cable_to_equipment_changes(network=network,
                                                    line=line)

        # warn if there're more genos than loads in LV grid
        if log_geno_count_vlevel7 > len(lv_loads):
            logger.debug('The count of newly connected generators in voltage level 7 ({}) '
                         'exceeds the count of loads ({}) in LV grid {}.'
                         .format(str(log_geno_count_vlevel7),
                                 str(len(lv_loads)),
                                 repr(lv_grid)
                                 )
                         )
Connect LV generators to existing grids.

    This function searches for unconnected generators in all LV grids and
    connects them.

    It connects

        * generators of voltage level 6
            * to MV-LV station

        * generators of voltage level 7
            * with a nom. capacity of <=30 kW to LV loads of type residential
            * with a nom. capacity of >30 kW and <=100 kW to LV loads of type
                retail, industrial or agricultural
            * to the MV-LV station if no appropriate load is available
              (fallback)

    Parameters
    ----------
    network : :class:`~.grid.network.Network`
        The eDisGo container object
    allow_multiple_genos_per_load : :obj:`bool`
        If True, more than one generator can be connected to one load

    Notes
    -----
    For the allocation, loads are selected randomly (sector-wise) using a
    predefined seed to ensure reproducibility.