-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile.cpp
More file actions
116 lines (100 loc) · 2.47 KB
/
file.cpp
File metadata and controls
116 lines (100 loc) · 2.47 KB
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
#include<iostream>
#include<ctime>
#include"router.h"
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define ps(x,y) cout<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define pw(b,p) pow(b,p) + 0.1
#define endl "\n"
void fastIO()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
void solve()
{
int n,m;
cin>>n>>m;
router network[1000];
for(int i=0;i<n;i++) network[i]= (router(n,i,network));
for(int i=0;i<m;i++)
{
int a,b;
double c;
cin>>a>>b>>c;
a--;b--;
network[a].addEdge(b,c);
network[b].addEdge(a,c);
}
int q;
cin>>q;
for(int i=0;i<q;i++)
{
int src,dest,dur,strt;
cin>>src>>dest>>dur>>strt;
src--;dest--;
while(dur--) network[src].recieve(packet(src,dest),strt);
}
double rc=0;
map<int,int> ctbyrcd_2;
for(int i=0;;i++)
{
if(i%update_time==0) for(int j=0;j<n;j++) network[j].sendupdate();
bool rem = false;
int val = 0;
for(int j=0;j<n;j++)
{
rem |= network[j].iterate(i,val);
ctbyrcd_2[i]=max(ctbyrcd_2[i],val);
}
rc=i;
if(!rem) break;
if(!detail)
{
cout<<"ITERATION at: "<<i<<" complete\n";
}
}
cout<<"\n\n\n\n#######################################\n\n\n";
double load=0;
double ct=0;
map<int,double> qs;
map<int,int> ctbyrcd;
map<int,vector<int>> ctbyevnt;
map<int,double> load_size;
for(int i=0;i<n;i++)
{
network[i].info(load,qs,ct,ctbyrcd,ctbyevnt,load_size);
}
cout<<"SIMULATION END\nRESULTS:\n";
cout<<"CONVERGENCE TIME: "<<ct;
cout<<"\nLOAD: "<<load/(n*rc/100)<<"%\n";
cout<<"QUEUE SIZE/TIME: ";
for(auto j:qs)
{
cout<<j.ss<<",";
}
cout<<endl;
}
int32_t main()
{
srand(time(0));
fastIO();
w(t)
{
solve();
cout<<endl;
}
return 0;
}