ribolands/pathfinder.py
def neighborhood_flooding(fp, ndata, gedges, tedges = None, minh = None):
    """ Calculate flooded paths for all edges.

    Note: Modifies arguments ndata and tedges.

    Starting with ndata and tedges (which may be None), 
    we add all the guide-edges to the graph.

    Args:
        ndata:
        gedges:
        tedges: 
    """
    if tedges is None:
        tedges = dict()

    guide_nbrs = {k: set() for k in ndata}
    for (p, q) in gedges: 
        assert p != q
        if (p, q) not in tedges:
            guide_nbrs[p].add(q)

    tstep_nbrs = {k: set() for k in ndata}
    for (p, q) in tedges: 
        assert p != q
        assert tedges[(p, q)]['saddle_energy'] is not None
        tstep_nbrs[p].add(q)

    while not all(len(v) == 0 for v in guide_nbrs.values()):
        seen = set()
        new_gedges = []
        for s2 in sorted(ndata, key = lambda x: (ndata[x]['energy'], x), 
                         reverse = True):
            for s1 in sorted(guide_nbrs[s2], key = lambda x: (ndata[x]['energy'], x), 
                             reverse = True):
                assert s1 != s2
                if (s1, s2) in seen:
                    continue

                assert ndata[s1]['energy'] <= ndata[s2]['energy']
                e2 = ndata[s2]['energy']
                e1 = ndata[s1]['energy']
                
                for (ss2, en2, ssB, enB, ss1, en1) in edge_flooding(fp, s2, s1, 
                                                                    e2, e1, minh):
                    assert ss1 != ss2
                    if ss2 == s2 and ss1 == s1: 
                        # adding the direct connection.
                        assert ndata[ss2]['energy'] == en2
                        assert ndata[ss1]['energy'] == en1
                        tedges[(ss2, ss1)] = {'saddle_energy': enB}
                        tedges[(ss1, ss2)] = {'saddle_energy': enB}
                        tstep_nbrs[ss2].add(ss1)
                        tstep_nbrs[ss1].add(ss2)
                        guide_nbrs[ss2].remove(ss1)
                        guide_nbrs[ss1].remove(ss2)
                    elif ss2 in tstep_nbrs.get(ss1, set()): 
                        # we might have found a better transition energy.
                        assert ss1 in tstep_nbrs[ss2]
                        # TODO: is this ncecessary?
                        #assert ss2 not in guide_nbrs[ss1]
                        #assert ss1 not in guide_nbrs[ss2]
                        assert ndata[ss2]['energy'] == en2
                        assert ndata[ss1]['energy'] == en1
                        if tedges[(ss2, ss1)]['saddle_energy'] is not None:
                            enB = min(enB, tedges[(ss2, ss1)]['saddle_energy'])
                        tedges[(ss2, ss1)] = {'saddle_energy': enB}
                        tedges[(ss1, ss2)] = {'saddle_energy': enB}
                    else: 
                        # postpone evaluation for next time.
                        assert ss2 not in ndata or ndata[ss2]['energy'] == en2
                        assert ss1 not in ndata or ndata[ss1]['energy'] == en1
                        ndata[ss2] = ndata.get(ss2, {'energy': en2})
                        ndata[ss1] = ndata.get(ss1, {'energy': en1})
                        guide_nbrs[ss2] = guide_nbrs.get(ss2, set())
                        guide_nbrs[ss1] = guide_nbrs.get(ss1, set())
                        tstep_nbrs[ss2] = tstep_nbrs.get(ss2, set())
                        tstep_nbrs[ss1] = tstep_nbrs.get(ss1, set())
                        new_gedges.append((ss2, ss1))
                if s2 not in tstep_nbrs[s1]: 
                    assert s1 != s2
                    assert s1 not in tstep_nbrs[s2] 
                    guide_nbrs[s2].remove(s1)
                    guide_nbrs[s1].remove(s2)
                    tedges[(s1, s2)] = {'saddle_energy': None}
                    tedges[(s2, s1)] = {'saddle_energy': None}
                seen.add((s2, s1))
        for (p, q) in new_gedges:
            assert p != q
            guide_nbrs[p].add(q)
            guide_nbrs[q].add(p)
    return ndata, tedges
 Calculate flooded paths for all edges.

    Note: Modifies arguments ndata and tedges.

    Starting with ndata and tedges (which may be None), 
    we add all the guide-edges to the graph.

    Args:
        ndata:
        gedges:
        tedges: 
    
Calculate flooded paths for all edges.
Note: Modifies arguments ndata and tedges.

Starting with ndata and tedges (which may be None),
we add all the guide-edges to the graph.
Calculate flooded paths for all edges . Note : Modifies arguments ndata and tedges . Starting with ndata and tedges ( which may be None ) we add all the guide - edges to the graph .
def neighborhood_flooding(fp, ndata, gedges, tedges = None, minh = None):
    if tedges is None:
        tedges = dict()
    guide_nbrs = {k: set() for k in ndata}
    for (p, q) in gedges: 
        assert p != q
        if (p, q) not in tedges:
            guide_nbrs[p].add(q)
    tstep_nbrs = {k: set() for k in ndata}
    for (p, q) in tedges: 
        assert p != q
        assert tedges[(p, q)]['saddle_energy'] is not None
        tstep_nbrs[p].add(q)
    while not all(len(v) == 0 for v in guide_nbrs.values()):
        seen = set()
        new_gedges = []
        for s2 in sorted(ndata, key = lambda x: (ndata[x]['energy'], x), 
                         reverse = True):
            for s1 in sorted(guide_nbrs[s2], key = lambda x: (ndata[x]['energy'], x), 
                             reverse = True):
                assert s1 != s2
                if (s1, s2) in seen:
                    continue
                assert ndata[s1]['energy'] <= ndata[s2]['energy']
                e2 = ndata[s2]['energy']
                e1 = ndata[s1]['energy']
                for (ss2, en2, ssB, enB, ss1, en1) in edge_flooding(fp, s2, s1, 
                                                                    e2, e1, minh):
                    assert ss1 != ss2
                    if ss2 == s2 and ss1 == s1: 
                        assert ndata[ss2]['energy'] == en2
                        assert ndata[ss1]['energy'] == en1
                        tedges[(ss2, ss1)] = {'saddle_energy': enB}
                        tedges[(ss1, ss2)] = {'saddle_energy': enB}
                        tstep_nbrs[ss2].add(ss1)
                        tstep_nbrs[ss1].add(ss2)
                        guide_nbrs[ss2].remove(ss1)
                        guide_nbrs[ss1].remove(ss2)
                    elif ss2 in tstep_nbrs.get(ss1, set()): 
                        assert ss1 in tstep_nbrs[ss2]
                        assert ndata[ss2]['energy'] == en2
                        assert ndata[ss1]['energy'] == en1
                        if tedges[(ss2, ss1)]['saddle_energy'] is not None:
                            enB = min(enB, tedges[(ss2, ss1)]['saddle_energy'])
                        tedges[(ss2, ss1)] = {'saddle_energy': enB}
                        tedges[(ss1, ss2)] = {'saddle_energy': enB}
                    else: 
                        assert ss2 not in ndata or ndata[ss2]['energy'] == en2
                        assert ss1 not in ndata or ndata[ss1]['energy'] == en1
                        ndata[ss2] = ndata.get(ss2, {'energy': en2})
                        ndata[ss1] = ndata.get(ss1, {'energy': en1})
                        guide_nbrs[ss2] = guide_nbrs.get(ss2, set())
                        guide_nbrs[ss1] = guide_nbrs.get(ss1, set())
                        tstep_nbrs[ss2] = tstep_nbrs.get(ss2, set())
                        tstep_nbrs[ss1] = tstep_nbrs.get(ss1, set())
                        new_gedges.append((ss2, ss1))
                if s2 not in tstep_nbrs[s1]: 
                    assert s1 != s2
                    assert s1 not in tstep_nbrs[s2] 
                    guide_nbrs[s2].remove(s1)
                    guide_nbrs[s1].remove(s2)
                    tedges[(s1, s2)] = {'saddle_energy': None}
                    tedges[(s2, s1)] = {'saddle_energy': None}
                seen.add((s2, s1))
        for (p, q) in new_gedges:
            assert p != q
            guide_nbrs[p].add(q)
            guide_nbrs[q].add(p)
    return ndata, tedges
def neighborhood_flooding ( fp , ndata , gedges , tedges = None , minh = None ) : if tedges is None : tedges = dict ( ) guide_nbrs = { k : set ( ) for k in ndata } for ( p , q ) in gedges : assert p != q if ( p , q ) not in tedges : guide_nbrs [ p ] . add ( q ) tstep_nbrs = { k : set ( ) for k in ndata } for ( p , q ) in tedges : assert p != q assert tedges [ ( p , q ) ] [ 'saddle_energy' ] is not None tstep_nbrs [ p ] . add ( q ) while not all ( len ( v ) == 0 for v in guide_nbrs . values ( ) ) : seen = set ( ) new_gedges = [ ] for s2 in sorted ( ndata , key = lambda x : ( ndata [ x ] [ 'energy' ] , x ) , reverse = True ) : for s1 in sorted ( guide_nbrs [ s2 ] , key = lambda x : ( ndata [ x ] [ 'energy' ] , x ) , reverse = True ) : assert s1 != s2 if ( s1 , s2 ) in seen : continue assert ndata [ s1 ] [ 'energy' ] <= ndata [ s2 ] [ 'energy' ] e2 = ndata [ s2 ] [ 'energy' ] e1 = ndata [ s1 ] [ 'energy' ] for ( ss2 , en2 , ssB , enB , ss1 , en1 ) in edge_flooding ( fp , s2 , s1 , e2 , e1 , minh ) : assert ss1 != ss2 if ss2 == s2 and ss1 == s1 : assert ndata [ ss2 ] [ 'energy' ] == en2 assert ndata [ ss1 ] [ 'energy' ] == en1 tedges [ ( ss2 , ss1 ) ] = { 'saddle_energy' : enB } tedges [ ( ss1 , ss2 ) ] = { 'saddle_energy' : enB } tstep_nbrs [ ss2 ] . add ( ss1 ) tstep_nbrs [ ss1 ] . add ( ss2 ) guide_nbrs [ ss2 ] . remove ( ss1 ) guide_nbrs [ ss1 ] . remove ( ss2 ) elif ss2 in tstep_nbrs . get ( ss1 , set ( ) ) : assert ss1 in tstep_nbrs [ ss2 ] assert ndata [ ss2 ] [ 'energy' ] == en2 assert ndata [ ss1 ] [ 'energy' ] == en1 if tedges [ ( ss2 , ss1 ) ] [ 'saddle_energy' ] is not None : enB = min ( enB , tedges [ ( ss2 , ss1 ) ] [ 'saddle_energy' ] ) tedges [ ( ss2 , ss1 ) ] = { 'saddle_energy' : enB } tedges [ ( ss1 , ss2 ) ] = { 'saddle_energy' : enB } else : assert ss2 not in ndata or ndata [ ss2 ] [ 'energy' ] == en2 assert ss1 not in ndata or ndata [ ss1 ] [ 'energy' ] == en1 ndata [ ss2 ] = ndata . get ( ss2 , { 'energy' : en2 } ) ndata [ ss1 ] = ndata . get ( ss1 , { 'energy' : en1 } ) guide_nbrs [ ss2 ] = guide_nbrs . get ( ss2 , set ( ) ) guide_nbrs [ ss1 ] = guide_nbrs . get ( ss1 , set ( ) ) tstep_nbrs [ ss2 ] = tstep_nbrs . get ( ss2 , set ( ) ) tstep_nbrs [ ss1 ] = tstep_nbrs . get ( ss1 , set ( ) ) new_gedges . append ( ( ss2 , ss1 ) ) if s2 not in tstep_nbrs [ s1 ] : assert s1 != s2 assert s1 not in tstep_nbrs [ s2 ] guide_nbrs [ s2 ] . remove ( s1 ) guide_nbrs [ s1 ] . remove ( s2 ) tedges [ ( s1 , s2 ) ] = { 'saddle_energy' : None } tedges [ ( s2 , s1 ) ] = { 'saddle_energy' : None } seen . add ( ( s2 , s1 ) ) for ( p , q ) in new_gedges : assert p != q guide_nbrs [ p ] . add ( q ) guide_nbrs [ q ] . add ( p ) return ndata , tedges
Calculate flooded paths for all edges.
Calculate flooded paths for all edges .
""" Calculate flooded paths for all edges.

    Note: Modifies arguments ndata and tedges.

    Starting with ndata and tedges (which may be None), 
    we add all the guide-edges to the graph.

    Args:
        ndata:
        gedges:
        tedges: 
    """ # adding the direct connection. # we might have found a better transition energy. # TODO: is this ncecessary? #assert ss2 not in guide_nbrs[ss1] #assert ss1 not in guide_nbrs[ss2] # postpone evaluation for next time.
fp
ndata
None
gedges
None
tedges
None
minh