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


Python toposort.toposort函数代码示例

本文整理汇总了Python中toposort.toposort函数的典型用法代码示例。如果您正苦于以下问题:Python toposort函数的具体用法?Python toposort怎么用?Python toposort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了toposort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_simple

    def test_simple(self):
        self.assertEqual(list(toposort({2: {11},
                                        9: {11, 8},
                                        10: {11, 3},
                                        11: {7, 5},
                                        8: {7, 3},
                                        })),
                         [{3, 5, 7},
                          {8, 11},
                          {2, 9, 10},
                          ])

        # make sure self dependencies are ignored
        self.assertEqual(list(toposort({2: {2, 11},
                                        9: {11, 8},
                                        10: {10, 11, 3},
                                        11: {7, 5},
                                        8: {7, 3},
                                        })),
                         [{3, 5, 7},
                          {8, 11},
                          {2, 9, 10},
                          ])

        self.assertEqual(list(toposort({1: set()})),
                         [{1}])
        self.assertEqual(list(toposort({1: {1}})),
                         [{1}])
开发者ID:tdrhq,项目名称:bark,代码行数:28,代码来源:test_toposort.py

示例2: test_cycle

    def test_cycle(self):
        # a simple, 2 element cycle
        self.assertRaises(ValueError, list, toposort({1: {2},
                                                      2: {1}
                                                      }))

        # an indirect cycle
        self.assertRaises(ValueError, list, toposort({1: {2},
                                                      2: {3},
                                                      3: {1},
                                                      }))
开发者ID:tdrhq,项目名称:bark,代码行数:11,代码来源:test_toposort.py

示例3: test_no_dependencies

    def test_no_dependencies(self):
        self.assertEqual(list(toposort({1: {2},
                                        3: {4},
                                        5: {6},
                                        })),
                         [{2, 4, 6}, {1, 3, 5}])

        self.assertEqual(list(toposort({1: set(),
                                        3: set(),
                                        5: set(),
                                        })),
                         [{1, 3, 5}])
开发者ID:tdrhq,项目名称:bark,代码行数:12,代码来源:test_toposort.py

示例4: arrangeNodes

def arrangeNodes(dg):
    ts = list(toposort.toposort(dg))
    xc = 0
    ips = {}
    for st in ts:
        yps = [];
        st = list(st)
        for si in st:
            if si in dg.keys():
                ri = list(dg[si])
                yp = np.mean([ips[rr][1] for rr in ri])
            else:
                yp = 0
            
            while yp in yps:
               yp += 1
               
            yps.append(yp)
                
        #ysi = np.argsort(yps) 
        #ys = (np.arange(len(ysi)) - ysi.mean())
        ysi = np.arange(len(yps))
        ys = yps
        for i, yi in zip(ysi, ys):
            ips[st[i]] = (xc, yi)
        
        xc += 1
        
    return ips
开发者ID:RuralCat,项目名称:CLipPYME,代码行数:29,代码来源:depGraph.py

示例5: _sort_tasks

    def _sort_tasks(task_list):
        """
        Take the list of tasks in any order and sort them topologically
        so the resulting list and be executed correctly.
        :param task_list: List of LocalTask objects
        :return: Sorted list of LocalTask objects
        """

        # Create a list of
        tasks_w_deps = {}
        for task in task_list:
            deps = []
            for port_name in task.inputs.portnames:
                port = task.inputs.__getattribute__(port_name)
                if isinstance(port.value, local_task.Directory):
                    if port.value.parent not in task_list:
                        raise LocalWorkflowError('Task %s is missing from workflow' % port.value.parent.type)
                    deps.append(port.value.parent)
            tasks_w_deps[task] = set(deps)

        sorted_list =[]
        for x in toposort(tasks_w_deps):
            sorted_list += list(x)

        return sorted_list
开发者ID:michaelconnor00,项目名称:gbdxtools,代码行数:25,代码来源:local_workflow.py

示例6: split_dags

def split_dags(forest):
  parents = defaultdict(set)
  def find_parents(expr):
    for child in expr.children:
      parents[child].add(expr)
      find_parents(child)

  for expr in forest:
    find_parents(expr)

  def contains(tree, expr):
    if tree == expr:
      return True
    else:
      return any(contains(child, expr) for child in tree.children)

  exprs = forest + [expr for expr in parents if len(parents[expr]) > 1]

  # TODO: This is O(n^3)
  deps = {expr: set() for expr in exprs}
  for i in xrange(len(exprs)):
    for j in xrange(len(exprs)):
      if i == j:
        continue

      if contains(exprs[i], exprs[j]):
        deps[exprs[i]].add(exprs[j])
  return list(toposort(deps))
开发者ID:mysterymath,项目名称:6502kit,代码行数:28,代码来源:prototype.py

示例7: test_toposort

def test_toposort():
  tf.reset_default_graph()
  nodes = util.make_caterpillar_graph(length=2)
  graph = linearize_lib.get_graph()
  initial = list(toposort(graph))[0]
  assert len(initial) == 1
  assert list(initial)[0].name == 'merge2'
开发者ID:BhaskarNallani,项目名称:gradient-checkpointing,代码行数:7,代码来源:linearize_test.py

示例8: main

def main():
    args = parse_args()
    logging.basicConfig(level=args.loglevel)

    if has_path is False or has_toposort is False:
        LOG.error('Your python environment is missing required modules')
        sys.exit(1)

    dirs = {}

    for item in (Path(dir) for dir in args.dirs):
        if item.name.startswith('.'):
            continue

        if not item.is_dir():
            LOG.warn('skipping %s (not a directory)', item)
            continue

        dirs[item] = {
            'requires': [],
            'required_by': [],
            'provides': [],
        }

        this = dirs[item]

        for reqtype in this.keys():
            LOG.debug('check %s %s', item.name, reqtype)
            try:
                with (item / '.deps' / reqtype).open() as fd:
                    LOG.debug('reading %s deps for %s', reqtype, item.name)
                    this[reqtype] = fd.read().splitlines()
            except IOError:
                continue

    # generated provided_by dictionary
    provided_by = {}
    for k, v in dirs.items():
        provided_by[k.name] = k
        for provide in v['provides']:
            provided_by[provide] = k

    order = {}
    for k, v in dirs.items():
        order.setdefault(k, set())
        for req in v['requires']:
            LOG.debug('%s requires %s (provided by %s)',
                      k, req, provided_by[req])
            order[k].add(provided_by[req])

        for req in v['required_by']:
            LOG.debug('%s is required by %s (via %s)',
                      k, provided_by[req], req)
            order.setdefault(provided_by[req], set()).add(k)

    order = [item for stage in toposort.toposort(order)
             for item in stage]

    print ' '.join(str(x) for x in order)
开发者ID:larsks,项目名称:extro.py,代码行数:59,代码来源:extro.py

示例9: test_input_not_modified_when_cycle_error

 def test_input_not_modified_when_cycle_error(self):
     data = {1: {2},
             2: {1},
             3: {4},
             }
     orig = data.copy()
     self.assertRaises(ValueError, list, toposort(data))
     self.assertEqual(data, orig)
开发者ID:tdrhq,项目名称:bark,代码行数:8,代码来源:test_toposort.py

示例10: number_of_strongly_connected_components

def number_of_strongly_connected_components(adj, rev_adj):
    visited = set()
    cc = 0
    order = toposort(rev_adj)
    for v in order:
        if v not in visited:
            explore(v, adj, visited, cc)
            cc += 1
    return cc
开发者ID:weilu,项目名称:graphs,代码行数:9,代码来源:strongly_connected.py

示例11: test_input_not_modified

 def test_input_not_modified(self):
     data = {2: {11},
             9: {11, 8},
             10: {11, 3},
             11: {7, 5},
             8: {7, 3, 8},  # includes something self-referential
             }
     orig = data.copy()
     results = list(toposort(data))
     self.assertEqual(data, orig)
开发者ID:tdrhq,项目名称:bark,代码行数:10,代码来源:test_toposort.py

示例12: calculate_dependencies

 def calculate_dependencies():
     """Calculate test dependencies
     First do a topological sorting based on the dependencies.
     Then sort the different dependency groups based on priorities.
     """
     order = []
     for g in toposort(merge_dicts(dependencies, soft_dependencies)):
         for t in sorted(g, key=lambda x: (priorities[x], x)):
             order.append(t)
     return order
开发者ID:Zitrax,项目名称:nose-dep,代码行数:10,代码来源:nosedep.py

示例13: test_strings

 def test_strings(self):
     self.assertEqual(list(toposort({'2': {'11'},
                                     '9': {'11', '8'},
                                     '10': {'11', '3'},
                                     '11': {'7', '5'},
                                     '8': {'7', '3'},
                                     })),
                      [{'3', '5', '7'},
                       {'8', '11'},
                       {'2', '9', '10'},
                       ])
开发者ID:tdrhq,项目名称:bark,代码行数:11,代码来源:test_toposort.py

示例14: calculate_dependencies

    def calculate_dependencies():
        """Calculate test dependencies
        First do a topological sorting based on the dependencies.
        Then sort the different dependency groups based on priorities.
        """
        order = []
        for group in toposort(dependencies):
            priority_sorted_group = sorted(group, key=lambda x: (priorities[x], x))
            order.extend(priority_sorted_group)

        return order
开发者ID:rkday,项目名称:nose2dep,代码行数:11,代码来源:core.py

示例15: ops_in_toposorted_order

def ops_in_toposorted_order(ops):
  """Produces ops in deterministic order such that children are executed
  after parents"""

  graph_dict = tf_ops_to_graph(ops)
  toposorted = toposort.toposort(graph_dict)
  ops = []
  # toposort assumes children are dependencies, reverse order
  for op_set in reversed(list(toposorted)):
    ops.extend(sorted(op_set, key=lambda op: op.name))
  return ops
开发者ID:yaroslavvb,项目名称:stuff,代码行数:11,代码来源:graph_template.py


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