<commit_before># coding=utf-8

"""
Generates some basic topologies. Contains utility methods as well.
"""

import itertools

import networkx as nx
from sol.topology.topologynx import Topology
from six.moves import xrange


def fat_tree(k):
    """ Creates a FatTree topology as a directed graph

    :param k: specify the k-value that controls the size of the topology
    :returns: a ~:py:module:networkx DiGraph
    """
    G = nx.empty_graph()
    # Let's do the pods first
    index = 0
    middle = []
    for pod in xrange(k):
        lower = xrange(index, index + k / 2)
        index += k / 2
        upper = xrange(index, index + k / 2)
        index += k / 2
        # Add upper and lower levels
        G.add_nodes_from(lower, layer='edge', functions='switch')
        G.add_nodes_from(upper, layer='aggregation', functions='switch')
        # connect the levels
        G.add_edges_from(itertools.product(lower, upper), capacitymult=1)
        # keep the upper level for later
        middle.extend(upper)
    # Now, create the core
    core = []
    for coreswitch in xrange((k ** 2) / 4):
        G.add_node(index, layer='core', functions='switch')
        core.append(index)
        index += 1
    G.add_edges_from(itertools.product(core, middle), capacitymult=10)
    G = G.to_directed()
    return Topology('k{}'.format(k), G)


def chain_topology(n, name='chain'):
    """
    Generates a chain topology

    :param n: number of nodes in the chain
    :param name: name of the topology
    :return: the new topology
    :rtype TestTopology
    """
    G = nx.path_graph(n).to_directed()
    t = Topology(name, G)
    return t


def complete_topology(n, name='complete'):
    """
    Generates a complete graph topology

    :param n: number of nodes in the complete graph
    :param name: name of the topology
    :return: the new topology
    :rtype: TestTopology
    """
    G = nx.complete_graph(n).to_directed()
    t = Topology(name, G)
    return t
<commit_msg>Refactored path generation methods<commit_after># coding=utf-8

"""
Implements functions that generate some basic topologies.
"""

import itertools

import networkx as nx
from sol.topology.topologynx import Topology
from six.moves import xrange


def fat_tree(k):
    """
    Creates a FatTree topology with a given '-arity'.

    .. seealso:: The `<ccr.sigcomm.org/online/files/p63-alfares.pdf>`_

    :param k: specify the k-value that controls the size of the topology
    :returns: a ~:py:module:`networkx.DiGraph`
    """
    graph = nx.empty_graph()
    # Let's do the pods first
    index = 0
    middle = []
    for pod in xrange(k):
        lower = xrange(index, index + k / 2)
        index += k / 2
        upper = xrange(index, index + k / 2)
        index += k / 2
        # Add upper and lower levels
        graph.add_nodes_from(lower, layer='edge', functions='switch')
        graph.add_nodes_from(upper, layer='aggregation', functions='switch')
        # connect the levels
        graph.add_edges_from(itertools.product(lower, upper), capacitymult=1)
        # keep the upper level for later
        middle.extend(upper)
    # Now, create the core
    core = []
    for coreswitch in xrange((k ** 2) / 4):
        graph.add_node(index, layer='core', functions='switch')
        core.append(index)
        index += 1
    graph.add_edges_from(itertools.product(core, middle), capacitymult=10)
    graph = graph.to_directed()
    return Topology('k{}'.format(k), graph)


def chain_topology(n, name='chain'):
    """
    Generates a chain topology

    :param n: number of nodes in the chain
    :param name: name of the topology
    :return: the new topology
    :rtype :py:class:`sol.topology.topologynx.Topology`
    """
    G = nx.path_graph(n).to_directed()
    t = Topology(name, G)
    return t


def complete_topology(n, name='complete'):
    """
    Generates a complete graph topology

    :param n: number of nodes in the complete graph
    :param name: name of the topology
    :return: the new topology
    :rtype: :py:class:`sol.topology.topologynx.Topology`
    """
    G = nx.complete_graph(n).to_directed()
    t = Topology(name, G)
    return t

{'fraction_non_alphanumeric': 0.11361998558731684, 'fraction_numerical': 0.006245496036512131, 'mean_word_length': 2.8236914600550964, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2465800', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1306, 'n_words': 403}