예제 #1
0
파일: power.py 프로젝트: sdy99/PowerAI
 def generate_island_info(self):
     """
     生成分岛信息。
     """
     graph = PowerGraph(self, graph_type='multi', node_type='bus')
     islands = graph.get_islands(10)
     self.data['bus']['island'] = islands
예제 #2
0
파일: action.py 프로젝트: sdy99/PowerAI
def random_open_acline(power, num, keep_link=True):
    """ 随机开断一定数量的交流线。

    :param power: Power. Power实例,需要检查连通性。
    :param num: int. 开断数量。
    :param keep_link: bool. 是否保持连接状态,即不增加分岛。
    :return list[index]. 开断线路的索引列表。
    """
    ret = []
    aclines = power.data['acline']
    indices = aclines[(aclines['mark'] == 1) & (aclines['ibus'] != aclines['jbus'])].index
    if keep_link:
        graph = PowerGraph(power, graph_type='multi', node_type='bus', on_only=True)
    while num > 0:
        if len(indices) < num:
            raise ValueError('Not plenty of aclines to be off.')
        idx = indices[random.sample(range(len(indices)), 1)[0]]
        indices = indices.drop(idx)
        if keep_link:
            edge = (aclines.loc[idx, 'ibus'], aclines.loc[idx, 'jbus'], idx)
            if graph.is_connected(edge[0], edge[1], [edge]):
                continue
            graph.G.remove_edge(*edge)
        aclines.loc[idx, 'mark'] = 0
        ret.append(idx)
        num = num - 1
    return ret
예제 #3
0
파일: test_topo.py 프로젝트: sdy99/PowerAI
def test_topo():
    path = '../dataset/wepri36'
    fmt = 'off'
    power = Power(fmt)
    power.load_power(path, fmt=fmt, lp=False, st=False, station=True)
    graph1 = PowerGraph(power,
                        graph_type='single',
                        node_type='station',
                        on_only=True)
    islands1 = graph1.get_islands(min_num=5)
    print(islands1)
    graph2 = PowerGraph(power,
                        graph_type='multi',
                        node_type='bus',
                        on_only=False,
                        edge_columns=['x'])
    islands2 = graph2.get_islands(min_num=10)
    print(islands2)