forked from netcontract/ncflow
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_traffic_matrices.py
executable file
·74 lines (61 loc) · 1.84 KB
/
generate_traffic_matrices.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
#! /usr/bin/env python
from pathos import multiprocessing
from itertools import product
import numpy as np
import traceback
import os
import sys
sys.path.append("..")
from lib.problems import get_problem
TM_DIR = "../traffic-matrices"
SCALE_FACTORS = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0]
MODELS = ["gravity", "uniform", "poisson-high-intra", "poisson-high-inter", "bimodal"]
NUM_SAMPLES = 5
def generate_traffic_matrix(args):
prob_short_name, model, scale_factor = args
tm_model_dir = os.path.join(TM_DIR, model)
for _ in range(NUM_SAMPLES):
print(prob_short_name, model, scale_factor)
problem = get_problem(
prob_short_name,
model,
scale_factor=scale_factor,
seed=np.random.randint(2 ** 31 - 1),
)
problem.print_stats()
try:
problem.traffic_matrix.serialize(tm_model_dir)
except Exception:
print(
"{}, model {}, scale factor {} failed".format(
problem.name, model, scale_factor
)
)
traceback.printexc()
if __name__ == "__main__":
PROBLEM_SHORT_NAMES = [
"gtsce",
"delta",
"us-carrier",
"tata",
"cogentco",
"dial",
"colt",
"interoute",
"ion",
"uninett",
"kdl",
"erdos-renyi-1260231677",
]
if len(sys.argv) == 2 and sys.argv[1] == "--holdout":
TM_DIR += "/holdout"
if not os.path.exists(TM_DIR):
os.makedirs(TM_DIR)
for model in MODELS:
tm_model_dir = os.path.join(TM_DIR, model)
if not os.path.exists(tm_model_dir):
os.makedirs(tm_model_dir)
pool = multiprocessing.ProcessPool(14)
pool.map(
generate_traffic_matrix, product(PROBLEM_SHORT_NAMES, MODELS, SCALE_FACTORS)
)