Beispiel #1
0
def init_merge_impacts(wn,
                       valves,
                       segnet,
                       segment_impact_dict,
                       lid2lname,
                       nid2nname,
                       lname2lid,
                       nname2nid,
                       lid2nids,
                       mode='demand'):
    pnames_list = []
    nnames_list = []
    pids_list = []
    for valve in valves:
        seg_from = segnet.nid2seg[valve.nid]
        seg_to = segnet.pid2seg[valve.pid]
        merged_pnames, merged_nnames = get_merged_properties(
            seg_from, seg_to, lid2lname, nid2nname)

        pnames_list.append(merged_pnames)
        nnames_list.append(merged_nnames)

        pids = seg_from.pids + seg_to.pids
        pids_list.append(pids)

    impacts = bundle_analysis(wn, pnames_list, nnames_list, lname2lid,
                              nname2nid, lid2nids)
    seg_impacts = get_segment_impacts(wn, pids_list, impacts, lid2lname)
    segment_impact_dict = update_impact_dict(segment_impact_dict, pids_list,
                                             seg_impacts)
    return seg_impacts
Beispiel #2
0
def init_remove_impacts(wn,
                        segnet,
                        segment_impact_dict,
                        lid2lname,
                        nid2nname,
                        lname2lid,
                        nname2nid,
                        lid2nids,
                        mode='demand'):
    pnames_list = []
    nnames_list = []
    pids_list = []

    for segment in segnet.valid_pipe_segments:
        pids = segment.pids
        pnames = [lid2lname[pid] for pid in pids]
        pnames_list.append(pnames)
        pids_list.append(pids)

        nids = segment.nids
        nnames = [nid2nname[nid] for nid in nids]
        nnames_list.append(nnames)

    impacts = bundle_analysis(wn, pnames_list, nnames_list, lname2lid,
                              nname2nid, lid2nids)
    seg_impacts = get_segment_impacts(wn, pids_list, impacts, lid2lname)
    segment_impact_dict = update_impact_dict(segment_impact_dict, pids_list,
                                             seg_impacts)
    return seg_impacts
Beispiel #3
0
def update_merging_status(wn, segnet, segment_impact_dict, lid2lname,
                          nid2nname, lname2lid, nname2nid, lid2nids):
    pnames_list, nnames_list, pids_list = find_new_bundles(
        segnet, segment_impact_dict, lid2lname, nid2nname)
    print(f'updating {len(pnames_list)} segments')
    impacts = bundle_analysis(wn, pnames_list, nnames_list, lname2lid,
                              nname2nid, lid2nids)
    seg_impacts = get_segment_impacts(wn, pids_list, impacts, lid2lname)
    segment_impact_dict = update_impact_dict(segment_impact_dict, pids_list,
                                             seg_impacts)
    return segment_impact_dict
def calculate_damage_impact(
    wn,
    lid2lname,
    nid2nname,
    lname2lid,
    nname2nid,
    lid2nids,
    num_valve2fail,
    valid_nidpids,
    src_pids,
    src_nids,
    pid2pcost,
    segment_impact_dict,
    fixed_nidpids=[],
):
    vstate = create_valvestates(lid2nids, valid_nidpids, fixed_nidpids)
    segnet_damage = HydroSegmentNet(vstate, src_pids, pid2pcost)
    #     print (f'valves to break: {num_valve2fail}')
    for i in range(num_valve2fail):
        segnet_damage.valve_fail()

    new_segs = []
    old_impacts = []
    for seg in segnet_damage.valid_pipe_segments:
        if (set(src_nids).intersection(seg.nids)):
            print('isolating the source!')
            return -1  # should not happen
        if len(seg.pids) > 0:
            pid_keys = tuple(sorted(seg.pids))
            if pid_keys not in segment_impact_dict:
                new_segs.append(seg)
            else:
                old_impacts.append(segment_impact_dict[pid_keys])

    updated_pipe_bundles, updated_node_bundles = get_bundles_segments(
        new_segs, lid2lname, nid2nname)
    print(f'number of segment to simulate: {len(updated_pipe_bundles)}')

    impact_updated = bundle_analysis(wn, updated_pipe_bundles,
                                     updated_node_bundles, lname2lid,
                                     nname2nid, lid2nids)
    pids_list = [seg.pids for seg in new_segs]
    damage_seg_impacts = get_segment_impacts(wn, pids_list, impact_updated,
                                             lid2lname)
    segment_impact_dict = update_impact_dict(segment_impact_dict, pids_list,
                                             damage_seg_impacts)

    tot_seg_impacts = damage_seg_impacts + old_impacts
    indirect_loss = calc_indirect_impact(tot_seg_impacts)
    direct_loss = calc_direct_impact(tot_seg_impacts)
    tot_loss = indirect_loss + direct_loss
    return (direct_loss, indirect_loss, tot_loss)
Beispiel #5
0
def calculate_merge_impact(seg1,
                           seg2,
                           wn,
                           segment_impact_dict,
                           lid2lname,
                           nid2nname,
                           lname2lid,
                           nname2nid,
                           lid2nids,
                           mode='demand'):
    merged_pids = seg1.pids + seg2.pids
    merged_pnames = [lid2lname[pid] for pid in merged_pids]

    merged_nids = seg1.nids + seg2.nids
    merged_nnames = [nid2nname[nid] for nid in merged_nids]

    merge_impact = bundle_analysis(wn, [merged_pnames], [merged_nnames],
                                   lname2lid, nname2nid, lid2nids)
    seg_impact = SegImpact(len(merged_pids), get_tot_length(wn), merge_impact)

    segment_impact_dict[tuple(sorted(merged_pids))] = seg_impact
    return seg_impact