示例#1
0
def test_str():
    adjacency_dict = {2: {'weight': 3, 'status': True},
                      3: {'weight': 1, 'status': True},
                      4: {'weight': 4, 'status': True},
                      5: {'weight': 2, 'status': True}}

    node_1 = Node(1, 'A', adjacency_dict)
    string = node_1.__str__()

    for key in node_1.get_adjacents():
        assert 'Node     #' + str(key) in string
示例#2
0
def test_is_adjacent():
    """
    arrange phase: setting up the instances (creating adjacency)
    act phase: performing an action
    assert phase:
    :return:
    """
    node1 = Node(1, 'A', {2: {'weight': 3, 'status': True}})

    assert node1.is_adjacent(2)
    assert not node1.is_adjacent(3)
    assert not node1.is_adjacent(node1.node_id)
示例#3
0
def test_get_adjacents():
    adjacency_dict = {2: {'weight': 3, 'status': True},
                      3: {'weight': 1, 'status': True},
                      4: {'weight': 4, 'status': True},
                      5: {'weight': 2, 'status': True}}

    node_1 = Node(1, 'A', adjacency_dict)

    adjacents = node_1.get_adjacents()
    assert len(adjacents) is len(adjacency_dict)

    for key in adjacency_dict:
        assert key in adjacents
    def graph_builder(n: int,
                      max_weight: int = None,
                      seed: int = None) -> Network:
        """
        Returns randomly generated network with n nodes.

        :param int n: number of nodes generated graph will contain
        :param int max_weight: optional param that sets a maximum weight for edges
        :param int seed: optional parameter to control pseudorandom generator

        :return: randomly generated network with N nodes
        :rtype: Network
        """

        network_dict = {}
        if not max_weight:
            max_weight = 50

        for x in range(1, n + 1):
            adjacency_dict = GraphBuilder.generate_random_adjacency_dict(
                x, n, max_weight)
            node = Node(x, 'Node #' + str(x), adjacency_dict)
            network_dict[x] = node
        network = Network(network_dict)
        return network
def import_nodes(worksheet):
    """
    Imports node from each row and adds it to the network. These nodes
    only contain the following fields: node_id, hospital_name, region,
    city, and state. (adjacency_dict is handled in generate_distance_vector()
    and status is assumed to be True)

    :param Worksheet worksheet: worksheet to read data from
    :return: Network
    """
    network = Network()
    for x in range(2, worksheet.max_row + 1):
        network.add_node(
                node=Node(node_id=int(worksheet[f'{column_indices["unique id"]}{x}'].value),
                          hospital_name=worksheet[f'{column_indices["hospital name"]}{x}'].value,
                          region=int(worksheet[f'{column_indices["region"]}{x}'].value),
                          city=worksheet[f'{column_indices["city"]}{x}'].value,
                          state=worksheet[f'{column_indices["state"]}{x}'].value),
                feedback=False)

    generate_distance_vector(network=network)
    return network
示例#6
0
ANSI_CYAN = "\033[36m"
ANSI_YELLOW = '\033[33;1m'
ANSI_RED = '\033[31;1m'
ANSI_RESET = "\033[0m"

# builds hospitals (represented as nodes)
hospital_a = Node(
    1, 'A', {
        2: {
            'weight': 3,
            'status': True
        },
        3: {
            'weight': 1,
            'status': True
        },
        5: {
            'weight': 4,
            'status': True
        },
        9: {
            'weight': 2,
            'status': True
        }
    })
hospital_b = Node(
    2, 'B', {
        1: {
            'weight': 3,
            'status': True
        },
Everything below is just to briefly demonstrate/test
the basic functions of our graph/network
"""

# creates 10 individual nodes (hard coded adjacency lists to match)
node_1 = Node(
    1, 'A', {
        2: {
            'weight': 3,
            'status': True
        },
        3: {
            'weight': 1,
            'status': True
        },
        5: {
            'weight': 4,
            'status': True
        },
        9: {
            'weight': 2,
            'status': True
        }
    })
node_2 = Node(
    2, 'B', {
        1: {
            'weight': 3,
            'status': True
        },
def build_network(nodes, data):
    network = Network()
    for node in nodes:
        network.add_node(node=Node(node), feedback=False)

    return add_edges(network=network, data=data)