from grid_digraph_generator import GridDigraphGenerator
from suitability import SuitableNodeWeightGenerator, SuitabilityGraph

if __name__ == '__main__':

    generator = SuitableNodeWeightGenerator()

    seed = 0
    m = n = 30

    gh = GridDigraphGenerator()

    node_weighted = gh.generate(m,
                                n,
                                edge_weighted=True,
                                node_weighted=True,
                                node_weight_generator=generator,
                                seed=seed)

    suitability_graph = SuitabilityGraph()
    suitability_graph.append_graph(node_weighted)

    weights = {i: generator.weights["VERY_SUITABLE"][0] for i in range(m * n)}
    suitability_graph.update_node_weights(weights)
示例#2
0
    suitability_graph = SuitabilityGraph()
    suitability_graph.append_graph(graph)

    # # Compute shortest distances between every pair of nodes.
    # suitability_graph.compute_dist_paths(compute_paths=False)

    # As our goal is to show how Mustafizur's algorithm works, terminals can meet anywhere, thus original suitable nodes
    # are reset and any node in the graph becomes a suitable node (except terminals and POIs).

    # Reset suitable nodes.
    hotspots = suitability_graph.get_suitable_nodes(generator)
    reset_hotspots_weights = {
        h: generator.weights["WARNING"][0]
        for h in hotspots
    }
    suitability_graph.update_node_weights(reset_hotspots_weights)

    # Choose random terminals.

    # Terminals are chosen from a subset of nodes resulting from padding the original graph.
    where = []
    offset = width - 2 * padding - 1
    a = (width + 1) * padding
    for _ in range(0, offset + 1):
        b = a + offset
        where.extend(range(a, b + 1))
        a = b + 2 * padding + 1

    terminals = np.random.choice(a=where, size=35, replace=False)

    # Choose POIs.