-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvne.cpp
More file actions
4318 lines (3868 loc) · 103 KB
/
vne.cpp
File metadata and controls
4318 lines (3868 loc) · 103 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "VNE.h"
#include "VNEGeneral.h"
#include "VNEOrder.h"
#include "VNEAlgorithm.h"
#include "AdmissionControl.h"
#include "VNECandidate.h"
#include "scenario.h"
#include "iostream"
#include "fstream"
//#define MAXVNODENUM 50
using namespace std;
PNet* PN; // physical network
PNet* bufPN;
PNet* tempPN;
PNet* nicePN;
VNet** VNs; // virtual networks
VNet* tempVN;
VNet* niceVN;
VNet* bufVN;
int **Conflict; // Conflict Graph
int ShortestPath[SNODENUM][SNODENUM][MAXPATH]; // shortest path
double distances[SNODENUM][SNODENUM]; // distance between two nodes
bool PBGfail = false; // PBG graph or not
ofstream flog; // log file
ofstream Rresult;
ofstream Tresult;
// Request Queue
class queue{
public :
int* storage; // queue
int Qsize; // queue max size
int size; // queue size, i.e., # items in queue
int top;
int bot;
// Default Constructor
queue(){}
// Constructor
queue(int quesize){
int i;
storage = new int[quesize];
for( i=0;i<quesize;i++) storage[i] = -1;
Qsize = quesize;
top = 0;
bot = 0;
size = 0;
}
void enqueue(int ev){
int i;
if(size!=(top-bot+Qsize)%Qsize) cout<<"error!!!"<<endl;
//TODO:: enqueue
if(size<Qsize-1){
storage[top]=ev;
top=(top+1)%Qsize;
size++;
}
else{
flog<<"Queue is full!"<<endl;
if(EXPANDWINQ == 0){
storage[top] = ev;
top=(top+1)%Qsize;
storage[bot] = -1;
bot=(bot+1)%Qsize;
size = size;
}
else{
int OldQsize = Qsize;
int* ExpandStrg;
Qsize = 2*OldQsize;
ExpandStrg = new int[Qsize];
for(i=0;i<OldQsize;i++)
ExpandStrg[i] = storage[(i+bot)%OldQsize];
delete [] storage;
storage = new int[Qsize];
for(i=0;i<Qsize;i++)
storage[i] = -1;
for(i=0;i<OldQsize;i++)
storage[i] = ExpandStrg[i];
bot = 0;
top = size;
storage[top] = ev;
top=(top+1)%Qsize;
size++;
delete [] ExpandStrg;
ExpandStrg = NULL;
}
}
if(size!=(top-bot+Qsize)%Qsize) cout<<"error!!!"<<endl;
}
int dequeue(){
//TODO:: dequeue
int temp;
if(size!=(top-bot+Qsize)%Qsize) cout<<"error!!!"<<endl;
if(size==0)
return -1;
temp = storage[bot];
storage[bot]=-1;
bot=(bot+1)%Qsize;
size--;
if(size!=(top-bot+Qsize)%Qsize) cout<<"error!!!"<<endl;
return temp;
}
void sort(int key){ //key = 1..6 : choice of key-metric for ordering, key = 0: service order
//sort
if(size!=(top-bot+Qsize)%Qsize) cout<<"error!!!"<<endl;
int i,j;
double k;
int* temp = new int[Qsize];
double* worth = new double[Qsize];
int index;
double biggest;
for(i=0;i<Qsize;i++) temp[i]=storage[i];
for(i=0;i<Qsize;i++){
if(i<size)
storage[i] = temp[(bot+i)%Qsize];
else
storage[i] = -1;
}
bot = 0;
top = size;
for(i=0;i<Qsize;i++)
worth[i] = -1;
if(key==1){
for(i=0;i<size;i++)
worth[i] = 0;
}
// 1 / density
else if(key==2){
for(i=0;i<size;i++)
worth[i] = (double)(VNs[storage[i]]->NumNode)/(double)(VNs[storage[i]]->NumLink);
flog<<"top :"<<top<<"bot: "<<bot<<"size: "<<size<<endl;
for(i=0;i<Qsize;i++){
flog<<"worth["<<i<<"] : "<<worth[i]<<"// storage["<<i<<"] : "<<storage[i]<<endl;
}
for(i=1;i<size;i++){
biggest = worth[i-1];
index = storage[i-1];
for(j=i;j<size;j++){
if(biggest<worth[j]){
worth[i-1] = worth[j];
storage[i-1] = storage[j];
worth[j] = biggest;
storage[j] = index;
biggest = worth[i-1];
index = storage[i-1];
}
}
}
}
// Revenue decreasing order
else if(key==3){
for(i=0;i<size;i++){
worth[i] =0;
for(j=0;j<VNs[storage[i]]->NumNode;j++){
worth[i] += VNs[storage[i]]->Nodes[j]->cpu;
}
for(j=0;j<VNs[storage[i]]->NumLink;j++){
worth[i] += ALPHA*VNs[storage[i]]->Links[j]->capacity;
}
}
flog<<"top :"<<top<<"bot: "<<bot<<"size: "<<size<<endl;
for(i=0;i<Qsize;i++){
flog<<"worth["<<i<<"] : "<<worth[i]<<"// storage["<<i<<"] : "<<storage[i]<<endl;
}
for(i=1;i<size;i++){
biggest = worth[i-1];
index = storage[i-1];
for(j=i;j<size;j++){
if(biggest<worth[j]){
worth[i-1] = worth[j];
storage[i-1] = storage[j];
worth[j] = biggest;
storage[j] = index;
biggest = worth[i-1];
index = storage[i-1];
}
}
}
}
// Revenue * time
else if(key==4){
for(i=0;i<size;i++){
worth[i] =0;
for(j=0;j<VNs[storage[i]]->NumNode;j++){
worth[i] += VNs[storage[i]]->Nodes[j]->cpu;
}
for(j=0;j<VNs[storage[i]]->NumLink;j++){
worth[i] += ALPHA*VNs[storage[i]]->Links[j]->capacity;
}
worth[i] = worth[i] * (double)(VNs[storage[i]]->RqT) /(double)(TWIN);
}
flog<<"top :"<<top<<"bot: "<<bot<<"size: "<<size<<endl;
for(i=0;i<Qsize;i++){
flog<<"worth["<<i<<"] : "<<worth[i]<<"// storage["<<i<<"] : "<<storage[i]<<endl;
}
for(i=1;i<size;i++){
biggest = worth[i-1];
index = storage[i-1];
for(j=i;j<size;j++){
if(biggest<worth[j]){
worth[i-1] = worth[j];
storage[i-1] = storage[j];
worth[j] = biggest;
storage[j] = index;
biggest = worth[i-1];
index = storage[i-1];
}
}
}
}
// Revenue/Density decreasing order
else if(key==5){
for(i=0;i<size;i++){
worth[i] =0;
for(j=0;j<VNs[storage[i]]->NumNode;j++){
worth[i] += VNs[storage[i]]->Nodes[j]->cpu;
}
for(j=0;j<VNs[storage[i]]->NumLink;j++){
worth[i] += ALPHA*VNs[storage[i]]->Links[j]->capacity;
}
worth[i] = worth[i] *(double)(VNs[storage[i]]->NumNode) / (double)(VNs[storage[i]]->NumLink);
}
flog<<"top :"<<top<<"bot: "<<bot<<"size: "<<size<<endl;
for(i=0;i<Qsize;i++){
flog<<"worth["<<i<<"] : "<<worth[i]<<"// storage["<<i<<"] : "<<storage[i]<<endl;
}
for(i=1;i<size;i++){
biggest = worth[i-1];
index = storage[i-1];
for(j=i;j<size;j++){
if(biggest<worth[j]){
worth[i-1] = worth[j];
storage[i-1] = storage[j];
worth[j] = biggest;
storage[j] = index;
biggest = worth[i-1];
index = storage[i-1];
}
}
}
}
// Revenue*time/Density decreasing order
else if(key==6){
for(i=0;i<size;i++){
worth[i] =0;
for(j=0;j<VNs[storage[i]]->NumNode;j++){
worth[i] += VNs[storage[i]]->Nodes[j]->cpu;
}
for(j=0;j<VNs[storage[i]]->NumLink;j++){
worth[i] += ALPHA*VNs[storage[i]]->Links[j]->capacity;
}
worth[i] = worth[i] * (double)(VNs[storage[i]]->RqT) /(double)(TWIN) *(double)(VNs[storage[i]]->NumNode) / (double)(VNs[storage[i]]->NumLink);
}
flog<<"top :"<<top<<"bot: "<<bot<<"size: "<<size<<endl;
for(i=0;i<Qsize;i++){
flog<<"worth["<<i<<"] : "<<worth[i]<<"// storage["<<i<<"] : "<<storage[i]<<endl;
}
for(i=1;i<size;i++){
biggest = worth[i-1];
index = storage[i-1];
for(j=i;j<size;j++){
if(biggest<worth[j]){
worth[i-1] = worth[j];
storage[i-1] = storage[j];
worth[j] = biggest;
storage[j] = index;
biggest = worth[i-1];
index = storage[i-1];
}
}
}
}
else if(key==0){
for(i=0;i<size;i++)
worth[i] = VNs[storage[i]]->endT;
for(i=1;i<size;i++){
biggest = worth[i-1];
index = storage[i-1];
for(j=i;j<size;j++){
if(biggest>worth[j]){
worth[i-1] = worth[j];
storage[i-1] = storage[j];
worth[j] = biggest;
storage[j] = index;
biggest = worth[i-1];
index = storage[i-1];
}
}
}
}
if(key==0)
flog<<"EmbeddedQ Sort Result - "<<size<<" ("<<top<<" "<<bot<<")";
else
flog<<"WindowQ Sort Result - "<<size<<" ("<<top<<" "<<bot<<")";
for(i=0;i<Qsize;i++){
if(storage[i]!=-1){
flog<<" ("<<i<<" | "<<storage[i]<<" | "<<worth[i]<<") ";
}
}
flog<<endl;
delete [] temp;
delete [] worth;
if(size!=(top-bot+Qsize)%Qsize) cout<<"error!!!"<<endl;
}
bool isEmpty(){
//isEmpty 1: empty, 0: not empty
if(size!=(top-bot+Qsize)%Qsize) cout<<"error!!!"<<endl;
if(size==0) return true;
else return false;
}
~queue(){
delete [] storage;
}
};
queue WindowQ(MAXWINQ);
queue EmbeddedQ(MAXEBEDVN);
int TotalVNSet = 0;
// FeasType = 1, SUF
int SUF_O = 0;
int SUF_X = 0;
// FeasType = 2, PBG, SUF
int PBG_O = 0;
int PBG_X = 0;
int PBG_O_SUF_X = 0;
int PBG_O_SUF_O = 0;
// FeasType = 3, PBG, MWIS
// int PBG_O = 0;
// int PBG_X = 0;
int PBG_O_MWIS_X = 0;
int PBG_O_MWIS_O = 0;
// FeasType = 4, PBG, Nec, MWIS
// int PBG_O = 0;
// int PBG_X = 0;
int PBG_O_NEC_X = 0;
int PBG_O_NEC_O = 0;
int PBG_O_NEC_O_MWIS_X = 0;
int PBG_O_NEC_O_MWIS_O = 0;
// FeasType = 5, PBG, SUF, MWIS
// int PBG_O = 0;
// int PBG_X = 0;
// int PBG_O_SUF_X = 0;
// int PBG_O_SUF_O = 0;
int PBG_O_SUF_X_MWIS_X = 0;
int PBG_O_SUF_X_MWIS_O = 0;
// FeasType = 6, PBG, SUF, Nec, MWIS
// int PBG_O = 0;
// int PBG_X = 0;
// int PBG_O_SUF_X = 0;
// int PBG_O_SUF_O = 0;
int PBG_O_SUF_X_NEC_X = 0;
int PBG_O_SUF_X_NEC_O = 0;
int PBG_O_SUF_X_NEC_O_MWIS_X = 0;
int PBG_O_SUF_X_NEC_O_MWIS_O = 0;
int main(int argc, char** argv){
int i,j;
int Time;
int temp;
int mapVnet; //virtual network to be embedded
bool mapped;
int winnum; //index of window
bool feas;
bool nodemapok;
double embmetric;
double EmbMetric[TRY];
int nice =-1;
int sort_index;
int sort_temp;
int windowqsize = 0;
bool while1, while2;
int VOrderArr[MAXVNODENUM];
int SOrderArr[SNODENUM];
int EmdArr[SNODENUM];
// Statics Variables
int TotRevenue = 0;
int CurrentRevenue= 0;
double AvRevenue = 0; // TotRevenue / winnum
int trycount = 0;
int VNcount =0;
int CurrentTry = 0;
int CurrentVNcount =0;
int acceptcount = 0;
int CurrentAccept = 0;
double accptrat = 0; // acceptcount / trycount
double Currentaccptrat = 0; // (CurrentTry !=0) ? (CurrentAccept/CurrentTry) : 0;
int LinkAccept =0;
int CapAccept = 0;
int CurrentLinkAccept = 0;
int CurrentCapAccept = 0;
int NodeAccept =0;
int CpuAccept = 0;
int CurrentNodeAccept = 0;
int CurrentCpuAccept = 0;
double AcceptDensity = 0; // LinkAccept / NodeAccept
double CurrentAcceptDensity = 0; // CurrentLinkAccept / CurrentNodeAccept
double CurrentAvgCpuRatio = 0;
double CurrentAvgCapRatio = 0;
double CurrentSqrCpuRatio = 0;
double CurrentSqrCapRatio = 0;
double CurrentVarCpuRatio = 0;
double CurrentVarCapRatio = 0;
double CurrentAvgCpuRatio_ON = 0;
double CurrentAvgCapRatio_ON = 0;
double CurrentSqrCpuRatio_ON = 0;
double CurrentSqrCapRatio_ON = 0;
double CurrentVarCpuRatio_ON = 0;
double CurrentVarCapRatio_ON = 0;
int CurrentOnLink = 0; // How many phyical links are being used
int CurrentOnNode = 0; // How many phyical nodes are being used
double TotCpuRatio =0; // total busy time of nodes
double TotCapRatio =0; // total busy time of links
double TotSqrCpuRatio = 0;
double TotSqrCapRatio = 0;
int TotOnLink = 0;
int TotOnNode = 0;
double AvgCpuRatio = 0; // TotCpuRatio / (winnum * NumNode)
double AvgCapRatio = 0; // TotCapRatio / (winnum * NumLink)
double AvgVarCpuRatio = 0; // (TotSqrCpuRatio - TotCpuRatio * TotCpuRatio) / (winnum * NumNode)
double AvgVarCapRatio = 0; // (TotSqrCapRatio - TotCapRatio * TotCapRatio) / (winnum * NumNode)
double AvgCpuRatio_ON = 0; // TotCpuRatio / (TotOnNode)
double AvgCapRatio_ON = 0;
double AvgVarCpuRatio_ON = 0; // (TotSqrCpuRatio_ON - TotCpuRatio_ON * TotCpuRatio_ON) / (TotOnNode)
double AvgVarCapRatio_ON = 0;
int AvgOnLink = 0; // TotOnLink / winnum
int AvgOnNode = 0; // TotOnNode / winnum
stringstream st;
string resultfile;
stringstream st1;
string resultfile1;
stringstream st2;
string resultfile2;
st<<"RealTimeResult_";
st1<<"TotalResult_";
st2<<"Log_";
if(ALGTYPE_LENGTH==1){
if(ALGTYPE_COUPLE==1){
st<<"Alg1";
st1<<"Alg1";
st2<<"Alg1";
}
else if(ALGTYPE_COUPLE==2){
st<<"Alg2";
st1<<"Alg2";
st2<<"Alg2";
}
else if(ALGTYPE_COUPLE==3){
st<<"Alg3";
st1<<"Alg3";
st2<<"Alg3";
}
}
else if(ALGTYPE_LENGTH==2){
if(ALGTYPE_COUPLE==1){
st<<"Alg4";
st1<<"Alg4";
st2<<"Alg4";
}
else if(ALGTYPE_COUPLE==2){
st<<"Alg5";
st1<<"Alg5";
st2<<"Alg5";
}
else if(ALGTYPE_COUPLE==3){
st<<"Alg6";
st1<<"Alg6";
st2<<"Alg6";
}
}
if(FEASTYPE==1){
st<<"_SUF";
st1<<"_SUF";
st2<<"_SUF";
}
else if(FEASTYPE==2){
st<<"_PBG_SUF";
st1<<"_PBG_SUF";
st2<<"_PBG_SUF";
}
else if(FEASTYPE==3){
st<<"_PBG_MWIS";
st1<<"_PBG_MWIS";
st2<<"_PBG_MWIS";
}
else if(FEASTYPE==4){
st<<"_PBG_NEC_MWIS";
st1<<"_PBG_NEC_MWIS";
st2<<"_PBG_NEC_MWIS";
}
else if(FEASTYPE==5){
st<<"_PBG_SUF_MWIS";
st1<<"_PBG_SUF_MWIS";
st2<<"_PBG_SUF_MWIS";
}
else if(FEASTYPE==6){
st<<"_PBG_SUF_NEC_MWIS";
st1<<"_PBG_SUF_NEC_MWIS";
st2<<"_PBG_SUF_NEC_MWIS";
}
st<<"_"<<argv[1]<<"_"<<argv[2]<<".txt";
st1<<"_"<<argv[1]<<"_"<<argv[2]<<".txt";
st2<<"_"<<argv[1]<<"_"<<argv[2]<<".txt";
st>>resultfile;
st1>>resultfile1;
st2>>resultfile2;
Rresult.open(resultfile.c_str());
Tresult.open(resultfile1.c_str());
flog.open(resultfile2.c_str());
//초기화
ReadSN(argv[1]);
cout<<"ReadSN() is DONE"<<endl;
MakeVNs(argv[2]);
cout<<"MakeVNs() is DONE"<<endl;
MakeOriginCG();
cout<<"MakeOriginCG() is DONE"<<endl;
Calcspaths();
cout<<"Calcspaths() is DONE"<<endl;
// ShortestTest(1, 20);
bufPN = new PNet(*PN);
tempPN = new PNet(*PN);
nicePN = new PNet(*PN);
tempVN = new VNet(*VNs[0]);
niceVN = new VNet(*VNs[0]);
bufVN = new VNet(*VNs[0]);
cout<<"==Initializing is DONE=="<<endl;
////////////////////////////////////////////////////////////////
Tresult<<"============================================"<<endl;
Tresult<<" Physical Network"<<endl;
Tresult<<"============================================"<<endl;
Tresult<<"# of PNodes: "<<(PN->NumNode)<<endl;
Tresult<<"# of PLinks: "<<(PN->NumLink)<<endl;
Tresult<<"Area : "<<XRANGE<<" [m] x "<<YRANGE<<" [m] (x,y)"<<endl;
if(argv[1][0]=='4'&&argv[1][1]=='9'){
Tresult<<"Topology : Grid"<<endl;//("<<NumRow<<" x "<<NumCol<<")"<<endl;
}
else if(argv[1][0]=='1'&&argv[1][1]=='0'){
Tresult<<"Topology : Random"<<endl;
}
else if(argv[1][0]=='2'&&argv[1][1]=='0'){
Tresult<<"Topology : Random"<<endl;
}
else if(argv[1][0]=='3'&&argv[1][1]=='0'){
Tresult<<"Topology : Random"<<endl;
}
Tresult<<"Density : "<<(double)(PN->NumLink)/(PN->NumNode)<<endl;
Tresult<<"PNode CPU : "<<SNWMIN<<" - "<<SNWMAX<<endl;
Tresult<<"PLink Cap : "<<SLWMIN<<" - "<<SLWMAX<<endl;
Tresult<<"============================================"<<endl;
Tresult<<" Virtual Network Requests"<<endl;
Tresult<<"============================================"<<endl;
Tresult<<"# of VNodes: "<<MINVNODENUM<<" - "<<MAXVNODENUM<<endl;
Tresult<<"VNode CPU : "<<VNWMIN<<" - "<<VNWMAX<<endl;
Tresult<<"VLink Cap : "<<VLWMIN<<" - "<<VLWMAX<<endl;
Tresult<<"Link Pr. : "<<MINPRVNLINK<<" - "<<MAXPRVNLINK<<" % "<<endl;
Tresult<<"Arrival : "<<POIMEAN<<"(Poisson)"<<endl;
Tresult<<"Duration : "<<EXPMEAN<<"(Exp. RV)"<<endl;
Tresult<<"============================================"<<endl;
Tresult<<" Algorithm Type"<<endl;
Tresult<<"============================================"<<endl;
if(ALGTYPE_COUPLE == 1){
Tresult<<"COUPLE : NON"<<endl;
}
else if(ALGTYPE_COUPLE == 2){
Tresult<<"COUPLE : MID (or Well)"<<endl;
}
else if(ALGTYPE_COUPLE == 3){
Tresult<<"COUPLE : FULL"<<endl;
}
if(ALGTYPE_LENGTH == 1){
Tresult<<"INTERFERING: HOP Count"<<endl;
}
else if(ALGTYPE_LENGTH == 2){
Tresult<<"INTERFERING: Weight"<<endl;
}
Tresult<<"# of Candi.: "<<TRY<<endl;
if(NORMTYPE == 1){
Tresult<<"Norm Type : 1-norm(SUM)"<<endl;
}
else if(NORMTYPE > 1){
Tresult<<"Norm Type : "<<NORMTYPE<<"-norm"<<endl;
}
else if(NORMTYPE < 0){
Tresult<<"Norm Type : inf-norm(MAX)"<<endl;
}
if(VNORDER == 1){
Tresult<<"VN Order : Random (arrive)"<<endl;
}
else if(VNORDER == 2){
Tresult<<"VN Order : 1 / Density"<<endl;
}
else if(VNORDER == 3){
Tresult<<"VN Order : Revenue"<<endl;
}
else if(VNORDER == 4){
Tresult<<"VN Order : Revenue * time"<<endl;
}
else if(VNORDER == 5){
Tresult<<"VN Order : Revenue / Density"<<endl;
}
else if(VNORDER == 6){
Tresult<<"VN Order : Revenue * time / Density"<<endl;
}
Tresult<<" ALPHA : "<<ALPHA<<endl;
Tresult<<"============================================"<<endl;
Tresult<<" Feasibility"<<endl;
Tresult<<"============================================"<<endl;
if(FEASTYPE == 1)
Tresult<<"TYPE : Sufficient"<<endl;
else if(FEASTYPE == 2){
Tresult<<"TYPE : PBG + Sufficient"<<endl;
}
else if(FEASTYPE == 3){
Tresult<<"TYPE : PBG + MWIS"<<endl;
}
else if(FEASTYPE == 4){
Tresult<<"TYPE : PBG, Necessary, 1-"<<EPS<<"MWIS"<<endl;
Tresult<<"PBG poly : "<<P<<"*log(CGNnode*r^"<<Q<<")"<<endl;
}
else if(FEASTYPE == 5){
Tresult<<"TYPE : PBG, Sufficient, 1-"<<EPS<<"MWIS"<<endl;
Tresult<<"PBG poly : "<<P<<"*log(CGNnode*r^"<<Q<<")"<<endl;
}
else if(FEASTYPE == 6){
Tresult<<"TYPE : PBG, Sufficient, Necessary, 1-"<<EPS<<"MWIS"<<endl;
Tresult<<"PBG poly : "<<P<<"*log(CGNnode*r^"<<Q<<")"<<endl;
}
Tresult<<"============================================"<<endl;
Tresult<<" Run Time Parameter"<<endl;
Tresult<<"============================================"<<endl;
Tresult<<"# of Wind. : "<<WINNUM<<endl;
Tresult<<"MWIS SLOT : "<<LONGSLOT<<endl;
if(FORCECUT == 0)
Tresult<<"FORCECUT : No"<<endl;
else if(FORCECUT == 1)
Tresult<<"FORCECUT : Yes"<<endl;
Rresult<<"\n winnum CurrentRevenue TotalRevenue AverageRevenue ";
Rresult<<"\n CurrentTry CurrentAccept TotalTry TotalAccept ";
Rresult<<"\n CurrentAcceptRate TotalAcceptRate ";
Rresult<<"\n CurrentLinkAccept CurrentNodeAccept LinkAccept NodeAccept ";
Rresult<<"\n CurrentAcceptDensity AcceptDensity ";
Rresult<<"\n CurrentCpuAccept CurrentCapAccept CpuAccept CapAccept ";
Rresult<<"\n CurrentAvgCpuRatio CurrentAvgCapRatio CurrentVarCpuRatio CurrentVarCapRatio ";
Rresult<<"\n CurrentAvgCpuRatio_ON CurrentAvgCapRatio_ON CurrentVarCpuRatio_ON CurrentVarCapRatio_ON ";
Rresult<<"\n CurrentOnNode CurrentOnLink ";
Rresult<<"\n TotCpuRatio TotCapRatio TotSqrCpuRatio TotSqrCapRatio ";
Rresult<<"\n TotOnLink TotOnNode ";
Rresult<<"\n AvgCpuRatio AvgCapRatio AvgVarCpuRatio AvgVarCapRatio ";
Rresult<<"\n AvgCpuRatio_ON AvgCapRatio_ON AvgVarCpuRatio_ON AvgVarCapRatio_ON ";
Rresult<<"\n AvgOnLink AvgOnNode ";
Rresult<<"\n EmbeddedVNs"<<endl;
////////////////////////////////////////////////////////////////
time_t St, End, runtime;
time(&St);
winnum = 1;
while1 = true;
Time = 0;
while(while1){
Time += TWIN;
flog<<"Time Window "<<winnum<<" : "<<Time<<endl;
// Enqueue VN req. arrived in the winnum into WindowQ
for(i=0;i<VNNUM;i++){
temp = (VNs[i]->startT);
if(Time==TWIN && temp==0){
WindowQ.enqueue(i);
VNcount++;
}
if((temp>(Time-TWIN))&&(temp<=Time)){
WindowQ.enqueue(i);
VNcount++;
}
}
flog<<winnum<<" : Enqueuing VNs is DONE"<<endl;
//while1 Break condition
if(winnum>WINNUM)
break; // break while1
if(WindowQ.isEmpty() && EmbeddedQ.isEmpty()){
flog<<winnum<<" : Queue Empty -> checking left VNs "<<endl;
while1 = false;//break;
for(i=0;i<VNNUM;i++){
if((VNs[i]->startT)>Time) while1 = true;
}
if(!while1){
// flog<<winnum<<" : Embedding is finished"<<endl;
continue; // i.e., break;
}
}
//Window handling
EmbeddedQ.sort(0); // Service order
// flog<<winnum<<" : Handling 'going out' VNs "<<endl;
for(i=0;i<EmbeddedQ.size;i++){
if(VNs[EmbeddedQ.storage[i]]->endT<=Time){
temp = EmbeddedQ.dequeue();
flog<<winnum<<" : "<<temp<<" is going out"<<endl;
Unmap(temp);
}
else{
break;
}
}
if(EmbeddedQ.size == 0)
flog<<winnum<<" : no going out"<<endl;
//dequeue -> mapping
//Sort
WindowQ.sort(VNORDER);
flog<<winnum<<" : Start to Embedding"<<endl;
while2 = true;
windowqsize = WindowQ.size;
while(while2){
mapVnet = WindowQ.dequeue();
windowqsize--;
if(mapVnet == -1){
flog<<winnum<<" : WindowQ empty"<<endl;
while2 = false;
continue; // i.e., break;
}
//mapping
mapped = false;
embmetric = 9999;
trycount++;
NodeMapOrder(mapVnet, VOrderArr);
flog<<winnum<<" : Node mapping order of VN"<<mapVnet<<" : ";
for(i=0;i<MAXVNODENUM;i++){
flog<<" "<<VOrderArr[i];
}
flog<<endl;
SNodeOrder(SOrderArr);
flog<<winnum<<" : Node order of SN : ";
for(i=0;i<(PN->NumNode);i++)
flog<<" "<<SOrderArr[i];
flog<<endl;
/////////////////////////////////////////////////////////////////////////////
if(ALGTYPE_COUPLE == 3){ // full couple
/////////////////////////////////////////////////////////////////////////////
delete tempVN; // tempVn << VNs[mapVnet]
tempVN = new VNet(*VNs[mapVnet]);
for(j=0;j<TRY;j++){
EmbMetric[j] = -1;
}
// Calculate EmbMetric
for(j=0;j<TRY;j++){
delete bufPN;
bufPN = new PNet(*PN);
delete VNs[mapVnet];
VNs[mapVnet] = new VNet(*tempVN);
flog<<winnum<<" : Trying Embedding - "<<j<<"'th time"<<endl;
temp = SOrderArr[j];
for(i=0;i<SNODENUM;i++){
EmdArr[i]=-1;
}
if((VNs[mapVnet]->Nodes[VOrderArr[0]]->cpu) > (bufPN->Nodes[SOrderArr[j]]->cpu) - (bufPN->Nodes[SOrderArr[j]]->filledW)){
continue;
}
NEmbedTo(mapVnet, VOrderArr[0], SOrderArr[j]);
EmdArr[SOrderArr[j]]=VOrderArr[0];
for(i=1;i<(VNs[mapVnet]->NumNode);i++){
// flog<<winnum<<" : Node Embed VN: "<<mapVnet<<", Nodenum: "<<VOrderArr[i]<<endl;
if(NORMTYPE == -1) // MAX NORM
nodemapok = Embed_MAX_Weight_PBGON(mapVnet, VOrderArr[i], EmdArr);
else{
if(FEASTYPE == 1){
nodemapok = Embed_SUM_PBGOFF(mapVnet, VOrderArr[i], EmdArr);
}
else{
nodemapok = Embed_SUM_PBGON(mapVnet, VOrderArr[i], EmdArr);
}
}
// flog<<winnum<<" : Node Embedding Result is "<<nodemapok<<endl;
if(!nodemapok)
i = MAXVNODENUM;
}
if(nodemapok){
EmbMetric[j]= bufPN->embmetric();
}
}
// EmbMetric increasing order
for(j=0;j<TRY;j++){
embmetric = EmbMetric[j];
sort_index = j;
for(i=j+1;i<TRY;i++){
if(embmetric > EmbMetric[i] && (EmbMetric[i]!=-1)){
sort_index = i;
embmetric = EmbMetric[i];
}
}
sort_temp = SOrderArr[sort_index];
SOrderArr[sort_index] = SOrderArr[j];
SOrderArr[j] = sort_temp;
EmbMetric[sort_index] = EmbMetric[j];
EmbMetric[j] = embmetric;
}
for(j=0;j<TRY;j++){
delete VNs[mapVnet];
VNs[mapVnet] = new VNet(*tempVN);
delete bufPN;
bufPN = new PNet(*PN);
flog<<winnum<<" : Trying Embedding - "<<j<<"'th time"<<endl;
temp = SOrderArr[j]; // check!!!
for(i=0;i<SNODENUM;i++)
EmdArr[i]=-1;
if(VNs[mapVnet]->Nodes[VOrderArr[0]]->cpu > bufPN->Nodes[SOrderArr[j]]->cpu - bufPN->Nodes[SOrderArr[j]]->filledW)
continue;
NEmbedTo(mapVnet, VOrderArr[0], temp);
EmdArr[temp]=VOrderArr[0];
for(i=1;i<(VNs[mapVnet]->NumNode);i++){
// flog<<winnum<<" : Node Embed VN: "<<mapVnet<<", Nodenum: "<<VOrderArr[i]<<endl;
if(NORMTYPE == -1) // MAX NORM
nodemapok = Embed_MAX_Weight_PBGON(mapVnet, VOrderArr[i], EmdArr);
else{
if(FEASTYPE == 1){
nodemapok = Embed_SUM_PBGOFF(mapVnet, VOrderArr[i], EmdArr);
}
else{
nodemapok = Embed_SUM_PBGON(mapVnet, VOrderArr[i], EmdArr);
}
}
// flog<<winnum<<" : Node Embedding Result is "<<nodemapok<<endl;
if(!nodemapok)
i = MAXVNODENUM;
}
feas = false;
if(nodemapok && (EmbMetric[i]!=-1)){
if(FEASTYPE==1){ // Sufficient condition
feas = FeasCheck_SUF(*bufPN);
if(feas) SUF_O++;
else SUF_X++;
}
else if(FEASTYPE==2){ // PBG, SUF
feas = FeasCheck_SUF(*bufPN);
if(feas) PBG_O_SUF_O++;
else PBG_O_SUF_X++;
}
else if(FEASTYPE==3){ // PBG, MWIS
if(MWISTYPE == 1)
feas = FeasCheck_MWIS(*bufPN);
if(MWISTYPE == 2)
feas = FeasCheck_MWIS_NEC(*bufPN);
if(feas) PBG_O_MWIS_O++;
else PBG_O_MWIS_X++;
}
else if(FEASTYPE==4){ // PBG, NEC, MWIS
feas = Necessary_PBG(*bufPN);
if(feas){
PBG_O_NEC_O++; // Necessary suc
if(MWISTYPE == 1)
feas = FeasCheck_MWIS(*bufPN);
if(MWISTYPE == 2)
feas = FeasCheck_MWIS_NEC(*bufPN);
if(feas) PBG_O_NEC_O_MWIS_O++; // MWIS suc
else PBG_O_NEC_O_MWIS_X++; // MWIS fail
}
else{ // Necessary fail
PBG_O_NEC_X ++;
}
}
else if(FEASTYPE==5){ // PBG, SUF, MWIS
feas = FeasCheck_SUF(*bufPN);
if(feas){
PBG_O_SUF_O++; // SUF suc
}
else{ // SUF fail
PBG_O_SUF_X ++;
if(MWISTYPE == 1)
feas = FeasCheck_MWIS(*bufPN);
if(MWISTYPE == 2)
feas = FeasCheck_MWIS_NEC(*bufPN);
if(feas) PBG_O_SUF_X_MWIS_O++; // MWIS pass
else PBG_O_SUF_X_MWIS_X++; // MWIS fail
}
}
else if(FEASTYPE==6){ // PBG, SUF, NEC, MWIS
feas = FeasCheck_SUF(*bufPN);
if(feas){
PBG_O_SUF_O++; // SUF suc
}
else{ // SUF fail
PBG_O_SUF_X ++;
feas = Necessary_PBG(*bufPN);
if(feas){// Necessary suc
PBG_O_SUF_X_NEC_O++;
if(MWISTYPE == 1)
feas = FeasCheck_MWIS(*bufPN);
if(MWISTYPE == 2)
feas = FeasCheck_MWIS_NEC(*bufPN);
if(feas) PBG_O_SUF_X_NEC_O_MWIS_O++; // MWIS suc
else PBG_O_SUF_X_NEC_O_MWIS_X++; // MWIS fail
}
else
PBG_O_SUF_X_NEC_X++; // Necessary fail
}
}
/////
if(feas){
delete nicePN;
nicePN = new PNet(*bufPN);
VNs[mapVnet]->isEmbedded = true;
mapped =true;
nice = j;
delete niceVN;
niceVN = new VNet(*VNs[mapVnet]);
break;
}
}
}