示例#1
0
def get_optimal_chains(digraph, ndds, edge_success_prob=1):
    # Chain edges
    chain_next_vv = {
        e.src.id: e.tgt.id
        for e in digraph.es for var in e.grb_vars if var.x > 0.1
    }

    optimal_chains = []
    for i, ndd in enumerate(ndds):
        chain_edges = []
        for e in ndd.edges:
            if e.edge_var.x > 0.1:
                assert len(chain_edges) == 0
                chain_edges.append(e)
                vtx_indices = find_selected_path(e.tgt.id, chain_next_vv)
                # Get weight of edge from NDD
                weight = e.weight * edge_success_prob
                # Add weights of edges between vertices
                for j in range(len(vtx_indices) - 1):
                    weight += digraph.adj_mat[vtx_indices[j]][vtx_indices[
                        j + 1]].weight * edge_success_prob**(j + 2)
                    chain_edges.append(
                        digraph.adj_mat[vtx_indices[j]][vtx_indices[j + 1]])
                optimal_chains.append(kidney_ndds.Chain(
                    i, vtx_indices, weight))

    return optimal_chains
示例#2
0
def get_optimal_chains(digraph, ndds, edge_success_prob=1):
    # Chain edges
    chain_next_vv = {e.src.id: e.tgt.id
                        for e in digraph.es
                        for var in e.grb_vars
                        if var.x > 0.1}
        
    optimal_chains = []
    for i, ndd in enumerate(ndds):
        for e in ndd.edges:
            if e.edge_var.x > 0.1:
                vtx_indices = find_selected_path(e.target_v.id, chain_next_vv)
                # Get score of edge from NDD
                score = e.score * edge_success_prob
                # Add scores of edges between vertices
                for j in range(len(vtx_indices) - 1):
                    score += digraph.adj_mat[vtx_indices[j]][vtx_indices[j+1]].score * edge_success_prob**(j+2)
                optimal_chains.append(kidney_ndds.Chain(i, vtx_indices, score))
    
    return optimal_chains