-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
144 lines (118 loc) · 6.21 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/python3
# The main code of the Simulator
import networkx
from AutoFeasRest.Model.Algorithm.ArisILP import ArisILP
from AutoFeasRest.Model.Algorithm.BinpackHeur import BinpackHeur
from AutoFeasRest.Model.Algorithm.RamyILP import RamyILP
from AutoFeasRest.Model.Graph.Network import PhysicalNetwork
from AutoFeasRest.InfeasAnalysis.InfeasAnalysis import InfeasAnalyzer
from AutoFeasRest.Parsing.InputParser import InputParser
from AutoFeasRest.Parsing.OutputParser import OutputParser
from AutoFeasRest.Visualization.Visualizer import NetworkVisualizer
# TODO: Improve Network Visualization
def main():
# Input Parameters
make_random_new_requests = False
algorithm_name = "RamyILP"
network_topology = "Reduced" # "Reduced" or "Regional"
# Feasibility Restoration Parameters
enable_infeas_repair = True
grouping_method = "Resource_Location" # "Resource_Location" or "Resource_Location"
compute_resource_factor = 500
bw_factor = 40
e2e_delay_factor = 5
propg_delay_factor = 10
# Create the network
net, input_parser = create_network("Net1", network_topology)
# Draw the network topology
net_visual = NetworkVisualizer(net)
net_visual.plot()
# Create the requests
hosted_requests, new_requests = create_requests(input_parser, make_random_new_requests)
# Apply the placement of the hosted requests (if any)
input_parser.assign_hosted_requests()
# VNF Placement
# TODO: fix differences between objective functions of RamyILP and BinpackHeur
algo = get_algorithm(net, new_requests, hosted_requests, algorithm_name)
# Solve the formulated problem
algo.solve(display_result=True, print_decision_variables=False)
# Check Feasibility
if algo.isFeasible:
algo.apply_result()
out_parser = OutputParser(net, hosted_requests, new_requests)
out_parser.parse_request_assignments()
elif enable_infeas_repair:
feasibility_restoration(algorithm_instance=algo, grouping_method=grouping_method, algorithm_name=algorithm_name,
net=net, hosted_requests=hosted_requests, new_requests=new_requests,
compute_resource_factor=compute_resource_factor,bw_factor=bw_factor,
e2e_delay_factor=e2e_delay_factor,propg_delay_factor=propg_delay_factor)
else:
print("Model is Infeasible")
net_visual.interactive_visual()
print("Done")
def create_network(network_name, network_topology):
net = PhysicalNetwork(name=network_name)
if network_topology == "Reduced":
network_nodes_file = "input/ReducedTopo/01-NetworkNodes.csv"
network_connections_file = "input/ReducedTopo/02-NetworkConnections.csv"
elif network_topology == "Regional":
network_nodes_file = "input/RegionalTopo/01-NetworkNodes.csv"
network_connections_file = "input/RegionalTopo/02-NetworkConnections.csv"
input_parser = InputParser(net, network_nodes_file=network_nodes_file,
network_connections_file=network_connections_file)
return net, input_parser
def create_requests(input_parser, make_random_new_requests):
# Todo: Generalize make_random_new_requests
hosted_requests = input_parser.get_all_hosted_requests()
if make_random_new_requests:
new_requests, req_dist = input_parser.get_random_new_requests_from_gateway("w3",
seed_number=0) # This bypass requests dist. file
else:
new_requests = input_parser.get_all_new_requests()
return hosted_requests, new_requests
def get_algorithm(net, new_requests, hosted_requests, algorithm_name):
"""
Returns algorithm instance of type selected based on algorithm_name.
:param net: Network to be used
:param new_requests: New requests to be assigned
:param hosted_requests: Hosted requests in the network
:param algorithm_name: The name of the algorithm. Supported algorithms: RamyILP, ArisILP, BinpackHeur
:return: Return the algorithm selected based on algorithm_name
"""
algo = None
if algorithm_name == "RamyILP":
algo = RamyILP(net, new_requests=new_requests, hosted_requests=hosted_requests, model_name="DemoModel")
elif algorithm_name == "ArisILP":
algo = ArisILP(net, new_requests=new_requests, hosted_requests=hosted_requests)
elif algorithm_name == "BinpackHeur":
algo = BinpackHeur(net, new_requests=new_requests, hosted_requests=hosted_requests)
return algo
def feasibility_restoration(algorithm_instance, grouping_method, algorithm_name, net, hosted_requests, new_requests,
compute_resource_factor, bw_factor, e2e_delay_factor, propg_delay_factor):
# Repair Infeas
algo = algorithm_instance
inf_analyzer = InfeasAnalyzer(algo.model, compute_resource_factor=compute_resource_factor,
bw_factor=bw_factor, e2e_delay_factor=e2e_delay_factor,
propg_delay_factor=propg_delay_factor)
recommended_constraints = None
if grouping_method == "Resource_Location":
recommended_constraints = "[L1, L2, L3, L4, L5]"
elif grouping_method == "Constraint_Type":
recommended_constraints = "[C1, C2, C3, C4]"
# TODO: get recommended_constraints from the agent
inf_analyzer.repair_infeas(all_constrs_are_modif=False, constraints_grouping_method=grouping_method,
recommeded_consts_groups_to_relax=recommended_constraints)
repair_result = inf_analyzer.result
repair_result.print_result()
# Apply repair and resolve
if repair_result.is_repaired:
inf_analyzer.apply_infeas_repair(net, hosted_requests, new_requests)
new_algo = get_algorithm(net, new_requests, hosted_requests, algorithm_name)
new_algo.solve(display_result=True, print_decision_variables=False)
# Todo: when number of requests of type 2 exceeds 9:repair_result.is_repaired is true but new_algo.isFeasible is false
if new_algo.isFeasible:
algo.apply_result()
out_parser = OutputParser(net, hosted_requests, new_requests)
out_parser.parse_request_assignments()
if __name__ == '__main__':
main()