def test_logical_random():
    """Test the creation of a logical random network topology."""

    from distriopt import VirtualNetwork

    virtual = VirtualNetwork.create_random_nw(
        20, req_cores=2, req_memory=8000, req_rate=200
    )
    assert virtual.number_of_nodes() == 20
    for node in virtual.nodes():
        assert virtual.req_cores(node) == 2
        assert virtual.req_memory(node) == 8000
    for i, j in virtual.edges():
        assert virtual.req_rate(i, j) == 200
Example #2
0
    import networkx as nx

    g = nx.Graph()
    g.add_node("Node_0", cores=3, memory=3000)
    g.add_node("Node_1", cores=3, memory=3000)
    g.add_edge("Node_0", "Node_1", rate=20000)

    virtual_topo = VirtualNetwork(g)

    # unfeasible, not enough rate
    physical_topo = PhysicalNetwork.create_test_nw(cores=4,
                                                   memory=4000,
                                                   rate=10000,
                                                   group_interfaces=False)

    prob = EmbedPartition(virtual_topo, physical_topo)
    time_solution, status = prob.solve()
    print(status)

    exit(1)

    physical_topo = PhysicalNetwork.from_files("grisou",
                                               group_interfaces=False)
    virtual_topo = VirtualNetwork.create_random_nw(n_nodes=66)
    # virtual_topo = VirtualNetwork.create_fat_tree(k=4)

    embed = EmbedPartition(virtual_topo, physical_topo)
    time_solution = embed.solve()
    print(time_solution, embed.status)
    print(embed.solution)
                        res_link_mapping[(u, v)].append((i, device_id, j))

                # build solution from the output
                self.solution = Solution.build_solution(
                    self.virtual, self.physical, res_node_mapping, res_link_mapping
                )
                self.status = Solved
                return Solved

            except (NodeResourceError, NoPathFoundError):
                # unfeasible, increase the number of partitions to be used
                pass
        else:
            self.status = Infeasible
            return Infeasible


if __name__ == "__main__":
    from distriopt.embedding import PhysicalNetwork
    from distriopt import VirtualNetwork

    physical_topo = PhysicalNetwork.from_files("grisou", group_interfaces=True)
    virtual_topo = VirtualNetwork.create_random_nw(n_nodes=120, seed=1)
    # virtual_topo = VirtualNetwork.create_fat_tree(k=4)

    embed = EmbedBalanced(virtual_topo, physical_topo)
    time_solution = embed.solve()
    print(time_solution, embed.status, embed.solution.n_machines_used)
    exit(1)
    print(embed.solution)
Example #4
0
def time_comparison_grid5000(timelimit, net_type="fat-tree"):
    """
    Custom Network  (for the moment fat tree and random are available on virtual.py)
    """
    # create the physical network representation
    physical = PhysicalNetwork.from_files("grisou")

    solvers_ilp = {"cplex"}
    solvers_heu = {
        "GreedyPartition": EmbedGreedy,
        "k-balanced": EmbedBalanced,
        "DivideSwap": EmbedPartition,
    }

    res_experiments = {"x": [], "time": {}, "value": {}}
    for method_name in solvers_ilp | solvers_heu.keys():
        res_experiments["time"][method_name] = {}
        res_experiments["value"][method_name] = {}

    if net_type == "fat-tree":
        min_v = 2
        max_v = 12
        step_size = 2
    elif net_type == "random":
        min_v = 25
        max_v = 175
        step_size = 25
    else:
        raise ValueError("invalid experiment type")

    for v in range(min_v, max_v + 1, step_size):
        res_experiments["x"].append(v)

        if net_type == "fat-tree":
            virtual = VirtualNetwork.create_fat_tree(v)
        else:
            virtual = VirtualNetwork.create_random_nw(v)

        # ILP solver
        prob = EmbedILP(virtual, physical)

        for solver_name in solvers_ilp:

            time_solution, status = prob.solve(solver_name=solver_name,
                                               timelimit=timelimit)

            if SolutionStatus[status] != "Solved":
                res_experiments["time"][solver_name][v] = time_solution
                res_experiments["value"][solver_name][v] = prob.current_val
            else:
                res_experiments["time"][solver_name][v] = time_solution
                res_experiments["value"][solver_name][
                    v] = prob.solution.n_machines_used

        # Heuristic approaches
        for heu in solvers_heu:
            prob = solvers_heu[heu](virtual, physical)
            time_solution, status = prob.solve()

            if SolutionStatus[status] == "Not Solved":
                sys.exit("Failed to solve")
            elif SolutionStatus[status] == "Unfeasible":
                sys.exit("unfeasible Problem")
            else:
                pass

            res_experiments["time"][heu][v] = time_solution
            res_experiments["value"][heu][v] = prob.solution.n_machines_used

        pprint.pprint(res_experiments)

        with open(
                os.path.join("results", f"res_{net_type}_{timelimit}s.pickle"),
                "wb") as res_file:
            pickle.dump(res_experiments,
                        res_file,
                        protocol=pickle.HIGHEST_PROTOCOL)