当前位置: 首页>>代码示例>>Python>>正文


Python DiGraph.node[nd]['mode']方法代码示例

本文整理汇总了Python中networkx.DiGraph.node[nd]['mode']方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.node[nd]['mode']方法的具体用法?Python DiGraph.node[nd]['mode']怎么用?Python DiGraph.node[nd]['mode']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx.DiGraph的用法示例。


在下文中一共展示了DiGraph.node[nd]['mode']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: synthesize

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import node[nd]['mode'] [as 别名]
def synthesize(tsys, exprtab, init_flags='ALL_ENV_EXIST_SYS_INIT'):
    assert init_flags.upper() == 'ALL_ENV_EXIST_SYS_INIT', 'Only the initial condition interpretation ALL_ENV_EXIST_SYS_INIT is supported.'

    W, Y_list, X_list = get_winning_set(tsys, return_intermediates=True)
    initial_states = get_initial_states(W, tsys, exprtab, init_flags)
    if initial_states is None:
        return None

    goalnames = ['SYSGOAL'+str(i) for i in range(tsys.num_sgoals)]

    for goalmode in range(tsys.num_sgoals):
        Y_list[goalmode][0] = set([s for s in W if goalnames[goalmode] in tsys.G.node[s]['sat']])

    strategy = DiGraph()
    next_id = len(initial_states)
    workset = list(range(next_id))
    strategy.add_nodes_from([(i, {'state': s, 'mode': 0, 'initial': True})
                             for (i,s) in enumerate(initial_states)])
    while len(workset) > 0:
        nd = workset.pop()

        j = 0
        while j < len(Y_list[strategy.node[nd]['mode']]):
            if strategy.node[nd]['state'] in Y_list[strategy.node[nd]['mode']][j]:
                break
            j += 1
        if j == 0:
            assert goalnames[strategy.node[nd]['mode']] in tsys.G.node[strategy.node[nd]['state']]['sat']
            original_mode = strategy.node[nd]['mode']
            while goalnames[strategy.node[nd]['mode']] in tsys.G.node[strategy.node[nd]['state']]['sat']:
                strategy.node[nd]['mode'] = (strategy.node[nd]['mode'] + 1) % tsys.num_sgoals
                if strategy.node[nd]['mode'] == original_mode:
                    break
            if strategy.node[nd]['mode'] != original_mode:
                repeat_found = False
                for possible_repeat, attr in strategy.nodes_iter(data=True):
                    if (possible_repeat != nd
                        and attr['mode'] == strategy.node[nd]['mode']
                        and attr['state'] == strategy.node[nd]['state']):
                        repeat_found = True
                        for (u,v) in strategy.in_edges_iter(nd):
                            strategy.add_edge(u, possible_repeat)
                        strategy.remove_edges_from(strategy.in_edges(nd))
                        strategy.remove_node(nd)
                        break
                if repeat_found:
                    continue

            j = 0
            while j < len(Y_list[strategy.node[nd]['mode']]):
                if strategy.node[nd]['state'] in Y_list[strategy.node[nd]['mode']][j]:
                    break
                j += 1
            if j == 0:
                assert goalnames[strategy.node[nd]['mode']] in tsys.G.node[strategy.node[nd]['state']]['sat']

        for envpost in tsys.envtrans[strategy.node[nd]['state']]:
            next_state = None
            for succ_nd in tsys.G.successors(strategy.node[nd]['state']):
                if (tuple([succ_nd[i] for i in tsys.ind_uncontrolled]) == envpost
                    and ((j > 0 and succ_nd in Y_list[strategy.node[nd]['mode']][j-1])
                         or (j == 0 and succ_nd in W))):
                    next_state = succ_nd
                    break

            if next_state is None:
                assert j > 0
                if j == 0:
                    import pdb; pdb.set_trace()
                blocking_index = None
                blocking_sets = X_list[strategy.node[nd]['mode']][j-1]
                for k in range(len(blocking_sets)):
                    if strategy.node[nd]['state'] in blocking_sets[k]:
                        blocking_index = k
                        break
                assert blocking_index is not None
                for succ_nd in tsys.G.successors(strategy.node[nd]['state']):
                    if (tuple([succ_nd[i] for i in tsys.ind_uncontrolled]) == envpost
                        and succ_nd in blocking_sets[blocking_index]):
                        next_state = succ_nd
                        break
                assert next_state is not None

            foundmatch = False
            for candidate, cattr in strategy.nodes_iter(data=True):
                if cattr['state'] == next_state and cattr['mode'] == strategy.node[nd]['mode']:
                    strategy.add_edge(nd, candidate)
                    foundmatch = True
                    break
            if not foundmatch:
                if j == 0:
                    new_mode = (strategy.node[nd]['mode'] + 1) % tsys.num_sgoals
                else:
                    new_mode = strategy.node[nd]['mode']

                workset.append(next_id)
                strategy.add_node(next_id, {'state': next_state,
                                            'mode': new_mode,
                                            'initial': False})
                strategy.add_edge(nd, next_id)
#.........这里部分代码省略.........
开发者ID:slivingston,项目名称:gr1py,代码行数:103,代码来源:solve.py


注:本文中的networkx.DiGraph.node[nd]['mode']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。