-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpoco_GUI.m
More file actions
2648 lines (2416 loc) · 137 KB
/
Copy pathpoco_GUI.m
File metadata and controls
2648 lines (2416 loc) · 137 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
% POCO_GUI Provides a graphical user interface for plotting resilient
% Pareto-based Optimal COntrollerplacements.
%
% Copyright 2012-2013 David Hock, Stefan Geißler, Fabian Helmschrott,
% Steffen Gebert
% Chair of Communication Networks, Uni Wuerzburg
%
function poco_GUI
% Check Matlab-version
matlabVersion=str2num(regexprep(version('-release'),'[^0-9]','')) ;
addpath('code');
addpath('images');
addpath('planetlab');
topology=[];
topology_org=[];
coordinates=[];
tm=[];
tm_org=[];
solution=[];
tmbool=0;
nk=[];
active_k=0;
optType='';
paretoidx=[];
valuex='';
valuey='';
tmindex=1;
last20plots=[];
last20plotsidx=1;
optTm=0;
nodenames={};
selectednode=[];
mValues={};
distanceMatrix=[];
distanceMatrix_org=[];
topologyName = '';
plcTopo = 0;
currPlacement=0;
textXaxis = '';
textYaxis = '';
topologyPLC=[];
coordinatesPLC=[];
tmPLC=[];
nodenamesPLC={};
controllerplacesOriginal=[];
controllernamesOriginal={};
controllerplacesPLC=[];
failedControllersPLC=[];
failedControllersOriginal=[];
failedControllerNamesOriginal={};
failedNodesPLC=[];
timeArray=[];
avgLatencyArray=[];
avgTMArray=[];
changes=[];
imbalance=[];
assignments=[];
maxmaxarrayPLC=[];
sumuncoveredarrayPLC=[];
sumbalancearrayPLC=[];
changesPLC=[];
balancevalsPLC=[];
balancevalsPLCNew=[];
maxarrayPLC=[];
uncoveredarrayPLC=[];
balancearrayPLC=[];
plcCounter=0;
plcFileCounter=11100;
newPLCCalc=0;
currentmaxidxHist=[];
% Variables to save the PLC history
tmvals=[];
latencyvals=[];
myidx='';
mycolors=[];
meanlatencyvals=[];
bestmaxidx='';
mValues={};
mValuesF={'<html><font size="2">Max node to controller latency (failure free)</font></html>', 'maxLatencyN2C',['Max node to controller latency',10,'(failure free)'];...
'<html><font size="2">Controller imbalance (failure free)</font></html>', 'controllerImbalance','Controller imbalance (failure free)';...
'<html><font size="2">Max controller to controller latency (failure free)</font></html>', 'maxLatencyC2C',['Max controller to controller',10,'latency (failure free)'];...
'<html>π<sub><i>R</i></sub><sup>max latency</sup></html>', 'maxarrayall','\pi^{max latency}_{\it{R}}';...
'<html>π<sub><i>R</i></sub><sup>imbalance</sup></html>', 'balancemaxarrayall','\pi^{imbalance}_{\it{R}}';...
'<html>π<sub><i>R</i></sub><sup>max latency</sup>(Inter-controller)</html>', 'maxarrayCCall','\pi^{max latency}_{\it{R}} (Inter-controller)';...
'<html>π<sub><i>R</i></sub><sup>controller-less</sup></html>', 'maxNumberOfControllerlessNodes','\pi^{controller-less}_{\it{R}}'};
mValuesN={'<html><font size="2">Max node to controller latency (failure free)</font></html>', 'maxLatencyN2C',['Max node to controller latency',10,'(failure free)'];...
'<html><font size="2">Controller imbalance (failure free)</font></html>', 'controllerImbalance','Controller imbalance (failure free)';...
'<html><font size="2">Max controller to controller latency (failure free)</font></html>', 'maxLatencyC2C',['Max controller to controller',10,'latency (failure free)'];...
'<html><font size="2">Max node to controller latency (up to two node failures)</font></html>', 'maxLatencyN2CAllNodeFailures',['Max node to controller latency',10,'(up to two node failures)'];...
'<html><font size="2">Controller imbalance (up to two node failures)</font></html>', 'controllerImbalanceAllNodeFailures',['Controller imbalance',10,'(up to two node failures)'];...
'<html><font size="2">Max controller to controller latency (up to two node failures)</font></html>', 'maxLatencyC2CAllNodeFailures',['Max controller to controller',10,'latency (up to two node failures)'];...
'<html><font size="2">Controller-less nodes (up to two node failures)</font></html>', 'maxNumberOfControllerlessNodes',['Controller-less nodes',10,'(up to two node failures)']};
mValuesC={'<html><font size="2">Max node to controller latency (failure free)</font></html>', 'maxLatencyN2C',['Max node to controller latency',10,'(failure free)'];...
'<html><font size="2">Controller imbalance (failure free)</font></html>', 'controllerImbalance','Controller imbalance (failure free)';...
'<html><font size="2">Max controller to controller latency (failure free)</font></html>', 'maxLatencyC2C',['Max controller to controller',10,'latency (failure free)'];...
'<html><font size="2">Max node to controller latency (up to k-1 controller failures)</font></html>', 'maxLatencyN2CAllControllerFailures',['Max node to controller latency',10,'(up to k-1 controller failures)'];...
'<html><font size="2">Max controller imbalance (up to k-1 controller failures)</font></html>', 'controllerImbalanceAllControllerFailures',['Max controller imbalance',10,'(up to k-1 controller failures)'];...
'<html><font size="2">Max controller to controller latency (up to k-1 controller failures)</font></html>', 'maxLatencyC2CAllControllerFailures',['Max controller to controller latency',10,'(up to k-1 controller failures)'];...
'<html><font size="2">Controller-less nodes (up to k-1 controller failures)</font></html>', 'maxNumberOfControllerlessNodes',['Controller-less nodes ',10,'(up to k-1 controller failures)']};
rbValuesC={'<html></html>',...
'<html><font size="2">Failure free</font></html>',...
'<html><font size="2">Worst max node to controller latency (up to k-1 controller failures)</font></html>',...
'<html><font size="2">Worst controller imbalance (up to k-1 controller failures)</font></html>'
};
rbValuesN={'<html></html>',...
'<html><font size="2">Failure free</font></html>',...
'<html><font size="2">Worst max node to controller latency (up to two node failures)</font></html>',...
'<html><font size="2">Worst controller imbalance (up to two node failures)</font></html>',...
'<html><font size="2">Worst max controller to controller latency (up to two node failures)</font></html>',...
'<html><font size="2">Worst controller-less nodes (up to two node failures)</font></html>'};
rbValues=[];
pValues={};
pValuesF={'<html></html>',...
'<html><font size="2">Max node to controller latency (failure free)</font></html>',...
'<html><font size="2">Controller imbalance (failure free)</font></html>',...
'<html><font size="2">Max controller to controller latency (failure free)</font></html>'};
pValuesC={'<html></html>',...
'<html><font size="2">Max node to controller latency (failure free)</font></html>',...
'<html><font size="2">Controller imbalance (failure free)</font></html>',...
'<html><font size="2">Max controller to controller latency (failure free)</font></html>',...
'<html><font size="2">Max node to controller latency (up to k-1 controller failures)</font></html>',...
'<html><font size="2">Controller imbalance (up to k-1 controller failures)</font></html>'
};
pValuesN={'<html></html>',...
'<html><font size="2">Max node to controller latency (failure free)</font></html>',...
'<html><font size="2">Controller imbalance (failure free)</font></html>',...
'<html><font size="2">Max controller to controller latency (failure free)</font></html>',...
'<html><font size="2">Max node to controller latency (up to two node failures)</font></html>',...
'<html><font size="2">Controller imbalance (up to two node failures)</font></html>',...
'<html><font size="2">Max controller to controller latency (up to two node failures)</font></html>',...
'<html><font size="2">Controller-less nodes (up to two node failures)</font></html>'};
screensize=get(0,'Screensize');
if screensize(3)<1000 || screensize(4)<800
initialpos=screensize-[0 -30 0 70];
else
initialpos=[screensize(3:4)-[1000 840] 1000 800];
end
hMainFigure = figure('MenuBar','none','Toolbar','none','HandleVisibility','on','Name', 'POCO','NumberTitle','off','Position',initialpos,'Resize','on','Color','w','CloseRequestFcn',@closeGUI);
hFigurePLC = figure('MenuBar','none','Toolbar','none','HandleVisibility','on','Name', 'PLC Live View','NumberTitle','off','Position',[0 0 400 300],'Resize','on','Color','w','Visible','off','CloseRequestFcn',@closePLCFig);
inputFig = '';
% For plots
hPanelAxes2 = uipanel('Parent',hMainFigure,'Units','normalized','HandleVisibility','on','Position',[0.05 0.11 0.72 0.34],'BorderWidth',0,'BackgroundColor',get(hMainFigure,'Color'));
hPanelAxes1 = uipanel('Parent',hMainFigure,'Units','normalized','HandleVisibility','on','Position',[0.05 0.5 0.72 0.47],'BorderWidth',0,'BackgroundColor',get(hMainFigure,'Color'));
hPlotAxes1 = axes('Parent', hPanelAxes1,'Units', 'normalized','HandleVisibility','on','Position',[0 0 0.98 1],'Visible','off');
hPlotAxes2 = axes('Parent', hPanelAxes2,'Units', 'normalized','HandleVisibility','on','Position',[0.08 0.25 0.9 0.7],'Visible','off');
% For plots of the Planetlab live view
hPlotAxesPLC = axes('Parent', hFigurePLC,'Units', 'normalized','HandleVisibility','on','Position',[0.03 0.57 0.94 0.43],'Visible','off');
hPlotAxesPLCbar1 = axes('Parent', hFigurePLC,'Units', 'normalized','HandleVisibility','on','Position',[0.072 0.03 0.9 0.13],'Visible','off');
hPlotAxesPLCbar2 = axes('Parent', hFigurePLC,'Units', 'normalized','HandleVisibility','on','Position',[0.07 0.21 0.38 0.13],'Visible','off');
hPlotAxesPLCbar2b = axes('Parent', hFigurePLC,'Units', 'normalized','HandleVisibility','on','Position',[0.57 0.21 0.38 0.13],'Visible','off');
hPlotAxesPLCbar3 = axes('Parent', hFigurePLC,'Units', 'normalized','HandleVisibility','on','Position',[0.07 0.39 0.38 0.13],'Visible','off');
hPlotAxesPLCbar3b = axes('Parent', hFigurePLC,'Units', 'normalized','HandleVisibility','on','Position',[0.57 0.39 0.38 0.13],'Visible','off');
% File menu
hFileMenu = uimenu('Parent',hMainFigure,'HandleVisibility','on','Label','File');
hOpenMenu = uimenu('Parent',hFileMenu,'HandleVisibility','on','Label','Open...','Callback', @OpenTopologyCallback,'Accelerator','O');
hSaveAsMenu = uimenu('Parent',hFileMenu,'HandleVisibility','on','Label','Save as','Accelerator','S','Enable','off','Callback', @SaveAsTopologyCallback);
hResetAllMenu = uimenu('Parent',hFileMenu,'Label','Close','HandleVisibility','on','Callback', @resetAllHandle,'Accelerator','W','Enable','off');
hImportMenu = uimenu('Parent',hFileMenu,'Label','Import','HandleVisibility','on','Separator','on','Enable','off');
hImportNodeWeightsMenu = uimenu('Parent',hImportMenu,'Label','Node weights','HandleVisibility','on','Callback',@importNodeWeights);
hExportMenu = uimenu('Parent',hFileMenu,'HandleVisibility','on','Label','Export','Enable','off');
hExportImageMenu = uimenu('Parent',hExportMenu,'HandleVisibility','on','Label','Save topology as image','Callback',{@exportPlotCallback,''});
hExportGephiMenu = uimenu('Parent',hExportMenu,'HandleVisibility','on','Label','Save Gephi csv','Callback',@exportGephiCSV);
hExitMenu = uimenu('Parent',hFileMenu','Label','Exit','HandleVisibility','on','Separator','on','Callback', @closeGUI);
% Edit menu
hEditMenu = uimenu('Parent',hMainFigure,'HandleVisibility','on','Label','Edit','Enable','off');
hUndoMenuitem = uimenu('Parent',hEditMenu,'Label','Undo','HandleVisibility','on','Callback', @undoPlot,'Enable','off','Accelerator','Z');
hRedoMenuitem = uimenu('Parent',hEditMenu,'Label','Redo','HandleVisibility','on','Callback', @redoPlot,'Enable','off','Accelerator','Y');
hResetFields = uimenu('Parent',hEditMenu,'Label','Reset fields','HandleVisibility','on','Callback', @resetFieldsHandle,'Accelerator','R');
hNodeOptionsMenu = uimenu('Parent',hEditMenu,'Label','Node options','HandleVisibility','on','Separator','on','Enable','off');
hToggleControllerItem = uimenu('Parent',hNodeOptionsMenu,'Label','Toggle Controller','HandleVisibility','on','Callback', @toggleController,'Accelerator','E','Separator','on');
hToggleControllerFailureItem = uimenu('Parent',hNodeOptionsMenu,'Label','Toggle Controller Failure','HandleVisibility','on','Callback', @toggleControllerFailure,'Accelerator','F');
hToggleNodeFailureItem = uimenu('Parent',hNodeOptionsMenu,'Label','Toggle Node Failure','HandleVisibility','on','Callback', @toggleNodeFailure,'Accelerator','G');
hEdgeOptionsMenu = uimenu('Parent',hEditMenu,'Label','Edge options','HandleVisibility','on');
hCreateEdgeMenuitem = uimenu('Parent',hEdgeOptionsMenu,'Label','Create edge','HandleVisibility','on','Callback',@createEdgeInput);
hDeleteEdgeMenuitem = uimenu('Parent',hEdgeOptionsMenu,'Label','Delete edge','HandleVisibility','on','Callback',@deleteEdgeInput);
hResetEdgeMenuitem = uimenu('Parent',hEdgeOptionsMenu,'Label','Reset edges','HandleVisibility','on','Callback',@resetEdges);
hNodeWeightsMenu = uimenu('Parent',hEditMenu,'Label','Node Weights','HandleVisibility','on');
hEditNodeWeightsMenuitem = uimenu('Parent',hNodeWeightsMenu,'Label','Edit','HandleVisibility','on','Callback',@editNodeWeightsInput);
hResetNodeWeightsMenuitem = uimenu('Parent',hNodeWeightsMenu,'Label','Reset','HandleVisibility','on','Callback',@resetNodeWeights);
hLatenciesMenu = uimenu('Parent',hEditMenu,'Label','Latencies','HandleVisibility','on');
hEditLatenciesMenuitem = uimenu('Parent',hLatenciesMenu,'Label','Edit','HandleVisibility','on','Callback',@editLatencies);
hResetLatenciesMenuitem = uimenu('Parent',hLatenciesMenu,'Label','Reset','HandleVisibility','on','Callback',@resetLatencies);
% Placements menu
hPlacementsMenu = uimenu('Parent',hMainFigure,'HandleVisibility','on','Label','Placements','Enable','off');
hCalculatePlacementsMenu = uimenu('Parent',hPlacementsMenu,'Label','Calculate placements','HandleVisibility','on');
hFFMenuitem.base = uimenu('Parent',hCalculatePlacementsMenu,'Label','Failure free','HandleVisibility','on');
for i=1:5
hFFMenuitem.(['FFk' num2str(i)]) = uimenu('Parent',hFFMenuitem.base,'Label',['k=' num2str(i)],'HandleVisibility','on','Callback',{@optimizeFailureFree,i});
end
hNMenuitem.base = uimenu('Parent',hCalculatePlacementsMenu,'Label','Up to two node failures','HandleVisibility','on');
for i=3:5
hNMenuitem.(['Nk' num2str(i)]) = uimenu('Parent',hNMenuitem.base,'Label',['k=' num2str(i)],'HandleVisibility','on','Callback',{@optimizeNodeFailure,i});
end
hRMenuitem = uimenu('Parent',hNMenuitem.base,'Label','Find minimum resilient k','HandleVisibility','on','Callback',@findMinimumK);
hCMenuitem.base = uimenu('Parent',hCalculatePlacementsMenu,'Label','Up to k-1 controller failures','HandleVisibility','on');
for i=1:5
hCMenuitem.(['Ck' num2str(i)]) = uimenu('Parent',hCMenuitem.base,'Label',['k=' num2str(i)],'HandleVisibility','on','Callback',{@optimizeControllerFailure,i});
end
hNodeWeightsMenuItem = uimenu('Parent',hCalculatePlacementsMenu,'Label','Use node weights','HandleVisibility','on','Checked','off','Separator','on','Callback', @toggleNodeWeights,'Visible','off','Enable','off');
hOpenPlacementsMenuitem = uimenu('Parent',hPlacementsMenu,'Label','Open...','HandleVisibility','on','Callback',@loadPlacementsCallback,'Separator','on');
hSavePlacementsMenuitem = uimenu('Parent',hPlacementsMenu,'Label','Save','HandleVisibility','on','Callback',@savePlacementsCallback,'Enable','off');
% View menu
hViewMenu = uimenu('Parent',hMainFigure,'HandleVisibility','on','Label','View','Enable','on');
hPlotOptionsMenu = uimenu('Parent',hViewMenu,'Label','Plot options','HandleVisibility','on','Enable','off');
hCheckBoxMenuIDs = uimenu('Parent',hPlotOptionsMenu,'Label','Node IDs','HandleVisibility','on','Visible','on','Callback',{@plotFiguresCallbackMenu,4},'Accelerator','4');
hCheckBoxMenuTM = uimenu('Parent',hPlotOptionsMenu,'Label','Node weights','HandleVisibility','on','Visible','on','Callback',{@plotFiguresCallbackMenu,6},'Accelerator','6');
hCheckBoxMenuDistNC = uimenu('Parent',hPlotOptionsMenu,'Label','<html>Max node to controller latency</html>','HandleVisibility','on','Visible','on','Callback',{@plotFiguresCallbackMenu,1},'Accelerator','1');
hCheckBoxMenuBalance = uimenu('Parent',hPlotOptionsMenu,'Label','<html>Controller imbalance</html>','HandleVisibility','on','Visible','on','Callback',{@plotFiguresCallbackMenu,2},'Accelerator','2');
hCheckBoxMenuDistCC = uimenu('Parent',hPlotOptionsMenu,'Label','<html>Max controller to controller latency</html>','HandleVisibility','on','Visible','on','Callback',{@plotFiguresCallbackMenu,3},'Accelerator','3');
hCheckBoxMenuHeatmap = uimenu('Parent',hPlotOptionsMenu,'Label','<html>Controller-less nodes heatmap</html>','HandleVisibility','on','Visible','on','Callback',@heatmapCheckCallbackMenu,'Accelerator','5');
hPredefinedViewsMenu = uimenu('Parent',hViewMenu,'Label','Predefined views','HandleVisibility','on','Enable','off');
hViewMaxLatencyMenuitem = uimenu('Parent',hPredefinedViewsMenu,'Label','<html>Max node to controller latency only</html>','HandleVisibility','on','Callback',{@plotFiguresCallbackMenu,7},'Accelerator','7');
hViewImbalanceMenuitem = uimenu('Parent',hPredefinedViewsMenu,'Label','<html>Controller imbalance only</html>','HandleVisibility','on','Callback',{@plotFiguresCallbackMenu,8},'Accelerator','8');
hViewMaxLatencyCCMenuitem = uimenu('Parent',hPredefinedViewsMenu,'Label','<html>Max controller to controller latency only</html>','HandleVisibility','on','Callback',{@plotFiguresCallbackMenu,9},'Accelerator','9');
hViewControllerlessMenuitem = uimenu('Parent',hPredefinedViewsMenu,'Label','<html>Controller-less nodes heatmap only</html>','HandleVisibility','on','Callback',{@plotFiguresCallbackMenu,0},'Accelerator','0');
hThemesMenu = uimenu('Parent',hViewMenu,'Label','Themes','HandleVisibility','on','Enable','on','Separator','on');
hThemesClassicMenuitem = uimenu('Parent',hThemesMenu,'Label','Classic','HandleVisibility','on','Enable','on','Callback',{@changeThemeCallback,[1 1 1], [0 0 0]},'Checked','on','Accelerator','');
hThemesDarkMenuitem = uimenu('Parent',hThemesMenu,'Label','Dark','HandleVisibility','on','Enable','on','Callback',{@changeThemeCallback,[0.26 0.26 0.26],[0.8 0.8 0.8]},'Accelerator','K');
hViewModeMenu = uimenu('Parent',hViewMenu,'Label','Mode','HandleVisibility','on','Enable','on');
hFullViewMenuitem = uimenu('Parent',hViewModeMenu,'Label','Full','HandleVisibility','on','Callback',@fullView,'Checked','on','Accelerator','');
hCompactViewMenuitem = uimenu('Parent',hViewModeMenu,'Label','Compact','HandleVisibility','on','Callback',@compactView,'Accelerator','T');
hExtractMenuitem = uimenu('Parent',hViewMenu,'Label','Duplicate plot','HandleVisibility','on','Callback', @duplicatePlot,'Accelerator','D','Separator','on','Enable','off');
% PLC Menu
hPLCMenu = uimenu('Parent',hMainFigure,'HandleVisibility','on','Label','POCO PLC','Visible','on');
hInitPLCMenuitem = uimenu('Parent',hPLCMenu,'Label','Start POCO PLC','HandleVisibility','on','Callback',@InitPOCOPLC,'Accelerator','P');
hStopPLCMenuitem = uimenu('Parent',hPLCMenu,'Label','Stop POCO PLC','HandleVisibility','on','Callback',@StopPOCOPLC,'Visible','off');
hLoadHistPLCMenuitem = uimenu('Parent',hPLCMenu,'Label','Load history...','HandleVisibility','on','Callback',@loadPLCHistory,'Visible','off','Separator','on');
hSaveHistPLCMenuitem = uimenu('Parent',hPLCMenu,'Label','Save Planetlab history','HandleVisibility','on','Callback',@savePLCHistoryCallback,'Visible','off','Enable','off');
hStartPlanetlabPlotLoopMenuitem = uimenu('Parent',hPLCMenu,'Label','Start Planetlab Plot Loop','HandleVisibility','on','Callback', {@startPLCLoopCallback},'Accelerator','#','Enable','off','Visible','off','Separator','on');
hStopPlanetlabPlotLoopMenuitem = uimenu('Parent',hPLCMenu,'Label','Stop Planetlab Plot Loop','HandleVisibility','on','Callback', {@stopPLCLoopCallback},'Accelerator','-','Enable','off','Visible','off');
hStartPlanetlabCalcLoopMenuitem = uimenu('Parent',hPLCMenu,'Label','Start Planetlab Calc Loop','HandleVisibility','on','Callback', {@startPLCCalcCallback},'Accelerator','#','Enable','off','Visible','off');
hStopPlanetlabCalcLoopMenuitem = uimenu('Parent',hPLCMenu,'Label','Stop Planetlab Calc Loop','HandleVisibility','on','Callback', {@stopPLCCalcCallback},'Accelerator','-','Enable','off','Visible','off');
hFetchPlanetlabDataMenuitem = uimenu('Parent',hPLCMenu,'Label','Fetch Planetlab Data','HandleVisibility','on','Callback', {@fetchPLCdataCallback},'Accelerator','U','Visible','off');
% Help menu
hHelpMenu = uimenu('Parent',hMainFigure,'HandleVisibility','on','Label','Help');
hOnlinHelpMenu = uimenu('Parent',hHelpMenu,'Label','Open online help','HandleVisibility','on','Callback', @openOnlineHelp);
hAboutMenu = uimenu('Parent',hHelpMenu,'Label','About','HandleVisibility','on','Callback', @openAbout);
% hPlotAxes1 Controls
hLabelControllerIDs = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.91 0.17 0.02],...
'String','Controller IDs','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hLabelControllerFailureIDs = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.85 0.17 0.02],...
'String','Controller failure IDs','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hLabelNodeFailureIDs = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.79 0.17 0.02],...
'String','Node failure IDs','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hEditControllerIDs = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.88 0.14 0.03],...
'Style','edit','BackgroundColor','w','HandleVisibility','on','Visible','off','Callback',@inputMainFigureCallback);
hEditControllerFailureIDs = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.82 0.14 0.03],...
'Style','edit','BackgroundColor','w','HandleVisibility','on','Visible','off','Callback',@inputMainFigureCallback);
hEditNodeFailureIDs = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.76 0.14 0.03],...
'Style','edit','BackgroundColor','w','HandleVisibility','on','Visible','off','Callback',@inputMainFigureCallback);
hLabelPlotOptions = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.69 0.1 0.05],...
'String','Show:','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hCheckBoxIDs = uicontrol('Parent',hMainFigure,'Units','normalized','Position',[0.78 0.69 0.15 0.03],'String','Node IDs','Style','checkbox','Value',1,'BackgroundColor',get(hMainFigure,'Color'),'HandleVisibility','on','Visible','off','Callback',@plotFiguresCallback);
hCheckBoxDistNC = uicontrol('Parent',hMainFigure,'Units','normalized','Position',[0.78 0.65 0.17 0.03],'String','<html>Max node to controller latency</sup></html>','Style','checkbox','Value',0,'BackgroundColor',get(hMainFigure,'Color'),'HandleVisibility','on','Visible','off','Callback',@plotFiguresCallback);
hCheckBoxBalance = uicontrol('Parent',hMainFigure,'Units','normalized','Position',[0.78 0.61 0.2 0.03],'String','<html>Controller imbalance</html>','Style','checkbox','Value',0,'BackgroundColor',get(hMainFigure,'Color'),'HandleVisibility','on','Visible','off','Callback',@plotFiguresCallback);
hCheckBoxDistCC = uicontrol('Parent',hMainFigure,'Units','normalized','Position',[0.78 0.57 0.2 0.03],'String','<html>Max controller to controller latency</html>','Style','checkbox','Value',0,'BackgroundColor',get(hMainFigure,'Color'),'HandleVisibility','on','Visible','off','Callback',@plotFiguresCallback);
hCheckBoxHeatmap = uicontrol('Parent',hMainFigure,'Units','normalized','Position',[0.78 0.53 0.2 0.03],'String','<html>Controller-less nodes heatmap</html>','Style','checkbox','Value',0,'BackgroundColor',get(hMainFigure,'Color'),'HandleVisibility','on','Visible','off','Callback',@heatmapCheckCallback);
hCheckBoxTM = uicontrol('Parent',hMainFigure,'Units','normalized','Position',[0.78 0.49 0.2 0.03],'String','Node weights','Style','checkbox','Value',0,'BackgroundColor',get(hMainFigure,'Color'),'HandleVisibility','on','Visible','off','Callback',@plotFiguresCallback);
% Best placement and scenario menus
hResultLabel = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.4 0.17 0.02],...
'String','Best placement concerning','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hResultPopupMenu = uicontrol('Parent', hMainFigure,'Units','normalized','Position',[0.78 0.36 0.17 0.04],'HandleVisibility','on',...
'String',pValues,'Style','popupmenu','FontUnits','normalized','FontSize',0.63,'Callback',@hResultPopupMenuCallback,'Visible','off','BackgroundColor',get(hMainFigure,'Color'));
hScenarioLabel = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.78 0.32 0.14 0.02],...
'String','Scenario ','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hScenarioPopupMenu = uicontrol('Parent', hMainFigure,'Units','normalized','Position',[0.78 0.28 0.17 0.04],'HandleVisibility','on',...
'String',rbValues,'Style','popupmenu','FontUnits','normalized','FontSize',0.63,'Callback',@hScenarioPopupMenuCallback,'Visible','off','BackgroundColor',get(hMainFigure,'Color'));
% Pareto-plot controller
hXAxisLabel = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.07 0.08 0.14 0.02],...
'String','Value on x-axis','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hXAxisPopupMenu = uicontrol('Parent', hMainFigure,'Units','normalized','Position',[0.07 0.06 0.3 0.02],'HandleVisibility','on','String','','Style','popupmenu','Callback',@hAxisPopupMenuCallback,'Visible','off','BackgroundColor',get(hMainFigure,'Color'));
hYAxisLabel = uicontrol('Parent',hMainFigure,'Units','normalized','HorizontalAlignment','left','Position',[0.45 0.08 0.14 0.02],...
'String','Value on y-axis','Style','text','BackgroundColor',get(hMainFigure,'Color'),'Visible','off','FontWeight','bold');
hYAxisPopupMenu = uicontrol('Parent', hMainFigure,'Units','normalized','Position',[0.45 0.06 0.3 0.02],'HandleVisibility','on','String','','Style','popupmenu','Callback',@hAxisPopupMenuCallback,'Visible','off','BackgroundColor',get(hMainFigure,'Color'));
% Status bar
hStatusPanel = uipanel('Parent', hMainFigure,'Units','pixels','Position',[-10 -10 3000 30],'HandleVisibility','on','BorderType','beveledout');
hStatusLabel = uicontrol('Parent',hStatusPanel,'Units','pixels','FontWeight','bold','HorizontalAlignment','left','Position',[12 10 1000 17],...
'String','GUI started - Load topology to continue','Style','text','BackgroundColor',get(hStatusPanel,'BackgroundColor'));
% Data cursor mode
dcobj=datacursormode(hMainFigure);
set(dcobj,'Enable','on','SnapToDataVertex','on','UpdateFcn', @datacursorUpdateFcn);
dcobjPLC=datacursormode(hFigurePLC);
set(dcobjPLC,'Enable','on','SnapToDataVertex','on','UpdateFcn', @datacursorUpdateFcn);
plotTimer=timer('TimerFcn',@plotFiguresCallback, 'StartDelay', 0.5);
plcPlotTimer=timer('TimerFcn',@PLCPlotLoop, 'StartDelay', 0, 'Period', 3,'ExecutionMode','fixedRate');
plcCalcTimer=timer('TimerFcn',@PLCCalcLoop, 'StartDelay', 3, 'Period', 10,'ExecutionMode','fixedSpacing');
plcCalcNowTimer=timer('TimerFcn',@PLCCalcLoop, 'StartDelay', 0.5);
%----------------------------------------------------------------------
% After starting POCO, a topology needs to be loaded
OpenTopologyCallback;
%----------------------------------------------------------------------
% Loads a topology
function OpenTopologyCallback(hObject, eventdata)
[filename, pathname] = uigetfile({'*.topo.mat;*.graphml;*.xml','Graph topology (*.topo.mat, *.graphml, *.xml)';'*.topo.mat','POCO topology (*.topo.mat)';'*.graphml','GraphML / GephiGraphML topology (*.graphml)';'*.xml','SNDlib topology (*.xml)'},'Please select a valid topology file');
file = fullfile(pathname, filename);
if ~isequal(filename, 0)
reset;
if ~isempty(strfind(filename,'.topo.mat'))
[topology,coordinates,tm,nodenames,distanceMatrix]=loadMatFile(file);
elseif ~isempty(strfind(filename,'.graphml'))
[topology,coordinates,nodenames,distanceMatrix]=importGraphML(file);
if isempty(topology)
[topology,coordinates,nodenames,distanceMatrix]=importGephiGraphML(file);
end
elseif ~isempty(strfind(filename,'.xml'))
[topology,coordinates,nodenames,distanceMatrix]=importSNDlibXML(file);
else
topology = [];
end
else
return
end
topologyName = filename(1:find(filename=='.')-1);
if isempty(topology)
errordlg('The selected file is not a valid topology.','File Error');
return
end
if ~isempty(tm)
set(hNodeWeightsMenuItem,'Visible','on','Enable','on');
set(hCheckBoxTM,'Visible','on','Value',0);
end
set(hEditControllerFailureIDs,'Enable','on');
set(hEditNodeFailureIDs,'Enable','on');
set(hNMenuitem.base,'Enable','on');
set(hCMenuitem.base,'Enable','on');
set(hCheckBoxMenuHeatmap,'Enable','on');
set(hCheckBoxHeatmap,'Visible','on');
set(hPlotOptionsMenu,'Enable','on');
set(hPredefinedViewsMenu,'Enable','on');
set(hThemesMenu,'Enable','on');
set(hExtractMenuitem,'Enable','on');
distanceMatrix_org = allToAllShortestPathMatrix(topology);
topology_org = topology;
tm_org = tm;
updateCheckBoxMenu;
plotFigures;
end
%----------------------------------------------------------------------
% Starts Planetlab
function InitPOCOPLC(hObject, eventdata)
reset;
[topology,coordinates,tm,nodenames]=loadNewPLCfile(plcFileCounter);
if ~isempty(topology)
set(hStartPlanetlabPlotLoopMenuitem,'Visible','on');
set(hStopPlanetlabPlotLoopMenuitem,'Visible','on');
set(hStartPlanetlabCalcLoopMenuitem,'Visible','on');
set(hStopPlanetlabCalcLoopMenuitem,'Visible','on');
set(hFetchPlanetlabDataMenuitem,'Visible','on');
set(hInitPLCMenuitem,'Visible','off');
set(hStopPLCMenuitem,'Visible','on');
set(hLoadHistPLCMenuitem,'Visible','on');
set(hSaveHistPLCMenuitem,'Visible','on');
if strcmp(get(hThemesClassicMenuitem,'Checked'),'off')
changeTheme([1 1 1],[0 0 0]);
end
set(hThemesMenu,'Enable','off');
if ishandle(hFigurePLC)
set(hFigurePLC,'Visible','on');
else
openPLFig;
end
plcTopo = 1;
topologyName = 'POCO PLC';
if ~isempty(tm)
set(hNodeWeightsMenuItem,'Visible','on','Enable','on');
set(hCheckBoxTM,'Visible','on','Value',0);
end
set(hEditControllerFailureIDs,'Enable','on');
set(hEditNodeFailureIDs,'Enable','on');
set(hCheckBoxTM,'Value',1);
set(hNMenuitem.base,'Enable','on');
set(hCMenuitem.base,'Enable','on');
set(hCheckBoxMenuHeatmap,'Enable','on');
set(hCheckBoxHeatmap,'Visible','on');
set(hLatenciesMenu,'Visible','off');
set(hNodeWeightsMenu,'Visible','off');
set(hEdgeOptionsMenu,'Visible','off');
tmbool=1;
set(hNodeWeightsMenuItem,'Checked','on');
topology_org = topology;
tm_org = tm;
updateCheckBoxMenu;
plotFigures;
else
errordlg('The selected file is not a valid topology.','File Error');
return
end
end
%----------------------------------------------------------------------
% Stops Planetlab
function StopPOCOPLC(hObject, eventdata)
stop(plcPlotTimer);
stop(plcCalcTimer);
reset;
plotFigures;
reset;
if ishandle(hFigurePLC)
delete(hFigurePLC);
end
end
%----------------------------------------------------------------------
% Starts the plot loop for Planetlab
function startPLCLoopCallback(hObject, eventdata)
if ~ishandle(hFigurePLC)
openPLFig;
end
set(hSaveHistPLCMenuitem,'Enable','on');
start(plcPlotTimer);
end
function PLCPlotLoop(hObject, eventdata)
% Transfer current controllers by saving names
controllerplacesOriginal=str2num(get(hEditControllerIDs,'String'));
controllernamesOriginal=nodenames(controllerplacesOriginal);
failedControllersOriginal=str2num(get(hEditControllerFailureIDs,'String'));
failedControllerNamesOriginal=nodenames(failedControllersOriginal);
[topologyPLC,coordinatesPLC,tmPLC,nodenamesPLC]=loadNewPLCfile(plcFileCounter);
plcFileCounter=plcFileCounter+1;
if plcFileCounter>11199
plcFileCounter=11100;
end
if ~isempty(topologyPLC)
controllerplacesPLC=[];
for m=1:length(controllernamesOriginal)
controllerplacesPLC=[controllerplacesPLC find(~cellfun(@isempty,strfind(nodenamesPLC,controllernamesOriginal{m})))];
end
failedControllersPLC=[];
for m=1:length(failedControllersOriginal)
failedControllersPLC=[failedControllersPLC find(~cellfun(@isempty,strfind(nodenamesPLC,failedControllersOriginal{m})))];
end
failedNodesPLC=find(nansum(topology,1)==0);
drawnow
plotAxesPLC;
end
end
%----------------------------------------------------------------------
% Stops the plot loop for Planetlab
function stopPLCLoopCallback(hObject, eventdata)
stop(plcPlotTimer);
end
%----------------------------------------------------------------------
% Starts the calculation loop for Planetlab
function startPLCCalcCallback(hObject, eventdata)
if ~ishandle(hFigurePLC)
openPLFig;
end
set(hSaveHistPLCMenuitem,'Enable','on');
start(plcCalcTimer);
end
function PLCCalcLoop(hObject, eventdata)
controllerplacesOriginal=str2num(get(hEditControllerIDs,'String')); % just to check if figure still open
if ~isempty(topologyPLC)
[tildevar,maxarrayPLC,uncoveredarrayPLC,balancearrayPLC,balancevalsPLCNew]=evaluatePlacementsFast(topologyPLC,nk,tmPLC);
plcCounter=plcCounter+1;
if isempty(maxmaxarrayPLC)
maxmaxarrayPLC=maxarrayPLC;
else
maxmaxarrayPLC=nanmax([maxarrayPLC;maxmaxarrayPLC]);
end
if isempty(sumuncoveredarrayPLC)
sumuncoveredarrayPLC=uncoveredarrayPLC;
else
sumuncoveredarrayPLC=nansum([uncoveredarrayPLC;sumuncoveredarrayPLC]);
end
if isempty(sumbalancearrayPLC)
sumbalancearrayPLC=balancearrayPLC;
else
sumbalancearrayPLC=nansum([balancearrayPLC;sumbalancearrayPLC]);
end
if isempty(changesPLC)
changesPLC=zeros(size(sumbalancearrayPLC));
else
changesPLC=nansum([nansum((balancevalsPLCNew-balancevalsPLC)~=0);changesPLC]);
end
balancevalsPLC=balancevalsPLCNew;
newPLCCalc=1;
end
end
%----------------------------------------------------------------------
% Stops the calculation loop for Planetlab
function stopPLCCalcCallback(hObject, eventdata)
stop(plcCalcTimer);
end
%----------------------------------------------------------------------
% Fetches the data from the Planetlab live view and assignes it to POCO
function fetchPLCdataCallback(hObject, eventdata)
fetchPLCdata;
end
function fetchPLCdata
set(hEditControllerIDs,'String',num2str(controllerplacesPLC))
set(hEditControllerFailureIDs,'String',num2str(failedControllersPLC))
set(hEditNodeFailureIDs,'String',num2str(failedNodesPLC))
set(hStartPlanetlabPlotLoopMenuitem,'Enable','on');
set(hStopPlanetlabPlotLoopMenuitem,'Enable','on');
set(hStartPlanetlabCalcLoopMenuitem,'Enable','on');
set(hStopPlanetlabCalcLoopMenuitem,'Enable','on');
topology=topologyPLC;
tm=tmPLC;
coordinates=coordinatesPLC;
nodenames=nodenamesPLC;
if ~isempty(topology)
plotFigures;
end
end
%----------------------------------------------------------------------
% Saves the current topology as .topo.mat file
function SaveAsTopologyCallback(hObject, eventdata)
[filename, pathname] = uiputfile({'*.topo.mat','POCO topology (*.topo.mat)'},'Save topology as...');
file = fullfile(pathname, filename);
if ~isequal(filename, 0)
saveTopology(file);
end
end
function saveTopology(file)
save(file, '-mat','coordinates','nodenames','tm','topology');
end
%----------------------------------------------------------------------
function inputMainFigureCallback(hObject, eventdata)
set(hResultPopupMenu,'Value',1);
set(hScenarioPopupMenu,'Value',1);
plotFigures;
updateCheckBoxMenu;
end
%----------------------------------------------------------------------
% Calls the functions for plotting the topology and pareto-plot, and for
% updating the checkbox-menu
function plotFiguresCallback(hObject, eventdata)
plotFigures;
updateCheckBoxMenu;
end
%----------------------------------------------------------------------
% Calls the functions for plotting the topology and pareto-plot, and for
% updating the checkboxes
function plotFiguresCallbackMenu(hObject, eventdata,k)
updateCheckBoxFromMenu(k);
plotFigures;
end
%----------------------------------------------------------------------
% Updates the pareto-plot according to the selected values for x-axis and
% y-axis
function hAxisPopupMenuCallback(hObject, eventdata)
valuex=char(mValues{get(hXAxisPopupMenu,'Value'),2});
valuey=char(mValues{get(hYAxisPopupMenu,'Value'),2});
plotAxes2;
fixAxes2PlotTextColor;
end
%----------------------------------------------------------------------
% Updates the plots according to the selected best placement
function hResultPopupMenuCallback(hObject, eventdata)
if ~isempty(solution)
switch get(hResultPopupMenu,'Value')
case 2
val1=min(solution.maxLatencyN2C);
val2=min(solution.controllerImbalance(solution.maxLatencyN2C==val1));
idx=find(solution.maxLatencyN2C==val1 & solution.controllerImbalance==val2,1,'last');
currPlacement=idx;
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
case 3
val1=min(solution.controllerImbalance);
val2=min(solution.maxLatencyN2C(solution.controllerImbalance==val1));
idx=find(solution.controllerImbalance==val1 & solution.maxLatencyN2C==val2,1,'last');
currPlacement = idx;
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
case 4
val1=min(solution.maxLatencyC2C);
val2=min(solution.controllerImbalance(solution.maxLatencyC2C==val1));
idx=find(solution.maxLatencyC2C==val1 & solution.controllerImbalance==val2,1,'last');
currPlacement = idx;
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
case 5
if (strcmpi(optType,'N') || strcmpi(optType,'N2'))
maxLatencyN2CAllFailures=solution.maxLatencyN2CAllNodeFailures;
else
maxLatencyN2CAllFailures=solution.maxLatencyN2CAllControllerFailures;
end
val1=min(maxLatencyN2CAllFailures);
val2=min(solution.maxLatencyN2C(maxLatencyN2CAllFailures==val1));
idx=find(solution.maxLatencyN2C==val2 & maxLatencyN2CAllFailures==val1,1,'last');
currPlacement = idx;
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
case 6
if (strcmpi(optType,'N') || strcmpi(optType,'N2'))
controllerImbalanceAllFailures = solution.controllerImbalanceAllNodeFailures;
else
controllerImbalanceAllFailures = solution.controllerImbalanceAllControllerFailures;
end
val1=min(controllerImbalanceAllFailures);
val2=min(solution.maxLatencyN2C(controllerImbalanceAllFailures==val1));
idx=find(solution.maxLatencyN2C==val2 & controllerImbalanceAllFailures==val1,1,'last');
currPlacement = idx;
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
case 7
if (strcmpi(optType,'N') || strcmpi(optType,'N2'))
maxLatencyC2CAllFailures = solution.maxLatencyC2CAllNodeFailures;
else
maxLatencyC2CAllFailures = solution.maxLatencyC2CAllControllerFailures;
end
val1=min(maxLatencyC2CAllFailures);
val2=min(solution.maxLatencyN2C(maxLatencyC2CAllFailures==val1));
idx=find(solution.maxLatencyN2C==val2 & maxLatencyC2CAllFailures==val1,1,'last');
currPlacement = idx;
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
case 8
val1=min(solution.maxNumberOfControllerlessNodes);
val2=min(solution.maxLatencyN2C(solution.maxNumberOfControllerlessNodes==val1));
idx=find(solution.maxLatencyN2C==val2 & solution.maxNumberOfControllerlessNodes==val1,1,'last');
currPlacement = idx;
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
end
end
end
%----------------------------------------------------------------------
% Updates the placement according to the selected scenaro
function hScenarioPopupMenuCallback(hObject, eventdata)
checkScenarioSelection;
if ~isempty(topology) && ~isempty(solution) && ~~isempty(strfind(optType,'F'))
plotFigures;
end
end
function checkScenarioSelection
if ~isempty(topology) && ~isempty(solution) && ~~isempty(strfind(optType,'F'))
k=active_k;
idx=floor(currPlacement);
switch get(hScenarioPopupMenu,'Value')
case 2
set(hEditControllerFailureIDs,'String','');
set(hEditNodeFailureIDs,'String','');
case 3
[tildevar,worst_number]=max(solution.maxLatencyN2CForNFailures(:,idx));
nodesFailed=[];
controllersFailed=[];
if ~isempty(strfind(optType,'N'))
failurepatterns=combnk(1:size(topology),worst_number);
if ~isnan(solution.failurePatternIndexOfMaxLatencyN2CForNFailures(worst_number,idx))
nodesFailed=failurepatterns(solution.failurePatternIndexOfMaxLatencyN2CForNFailures(worst_number,idx),:);
else
nodesFailed=[];
end
elseif ~isempty(strfind(optType,'C'))
nk=combnk(1:size(topology,1),k);
failurepatterns=combnk(1:k,k-worst_number);
if ~isnan(solution.failurePatternIndexOfMaxLatencyN2CForNFailures(worst_number,idx))
if matlabVersion <2013
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfMaxLatencyN2CForNFailures(worst_number,idx),:)));
else
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfMaxLatencyN2CForNFailures(worst_number,idx),:),'legacy'));
end
else
controllersFailed=[];
end
end
set(hEditNodeFailureIDs,'String',num2str(nodesFailed));
set(hEditControllerFailureIDs,'String',num2str(controllersFailed));
case 4
[tildevar,worst_number]=max(solution.controllerImbalanceForNFailures(:,idx));
nodesFailed=[];
controllersFailed=[];
if ~isempty(strfind(optType,'N'))
failurepatterns=combnk(1:size(topology),worst_number);
if ~isnan(solution.failurePatternIndexOfControllerImbalanceForNFailures(worst_number,idx))
nodesFailed=failurepatterns(solution.failurePatternIndexOfControllerImbalanceForNFailures(worst_number,idx),:);
else
nodesFailed=[];
end
elseif ~isempty(strfind(optType,'C'))
nk=combnk(1:size(topology,1),k);
failurepatterns=combnk(1:k,k-worst_number);
if ~isnan(solution.failurePatternIndexOfControllerImbalanceForNFailures(worst_number,idx))
if matlabVersion < 2013
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfControllerImbalanceForNFailures(worst_number,idx),:)));
else
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfControllerImbalanceForNFailures(worst_number,idx),:),'legacy'));
end
else
controllersFailed=[];
end
end
set(hEditNodeFailureIDs,'String',num2str(nodesFailed));
set(hEditControllerFailureIDs,'String',num2str(controllersFailed));
case 6
[tildevar,worst_number]=max(solution.maxNumberOfControllerlessNodesForNFailures(:,idx));
nodesFailed=[];
controllersFailed=[];
if ~isempty(strfind(optType,'N'))
failurepatterns=combnk(1:size(topology),worst_number);
if ~isnan(solution.failurePatternIndexOfMaxNumberOfControllerlessNodesForNFailures(worst_number,idx))
nodesFailed=failurepatterns(solution.failurePatternIndexOfMaxNumberOfControllerlessNodesForNFailures(worst_number,idx),:);
else
nodesFailed=[];
end
elseif ~isempty(strfind(optType,'C'))
nk=combnk(1:size(topology,1),k);
failurepatterns=combnk(1:k,k-worst_number);
if ~isnan(solution.failurePatternIndexOfMaxNumberOfControllerlessNodesForNFailures(worst_number,idx))
if matlabVersion < 2013
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfMaxNumberOfControllerlessNodesForNFailures(worst_number,idx),:)));
else
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfMaxNumberOfControllerlessNodesForNFailures(worst_number,idx),:),'legacy'));
end
else
controllersFailed=[];
end
end
set(hEditNodeFailureIDs,'String',num2str(nodesFailed));
set(hEditControllerFailureIDs,'String',num2str(controllersFailed));
case 5
[tildevar,worst_number]=max(solution.maxLatencyC2CForNFailures(:,idx));
nodesFailed=[];
controllersFailed=[];
if ~isempty(strfind(optType,'N'))
failurepatterns=combnk(1:size(topology),worst_number);
if ~isnan(solution.failurePatternIndexOfMaxLatencyC2CForNFailures(worst_number,idx))
nodesFailed=failurepatterns(solution.failurePatternIndexOfMaxLatencyC2CForNFailures(worst_number,idx),:);
else
nodesFailed=[];
end
elseif ~isempty(strfind(optType,'C'))
nk=combnk(1:size(topology,1),k);
failurepatterns=combnk(1:k,k-worst_number);
if ~isnan(solution.failurePatternIndexOfMaxLatencyC2CForNFailures(worst_number,idx))
if matlabVersion < 2013
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfMaxLatencyC2CForNFailures(worst_number,idx),:)));
else
controllersFailed=nk(idx,setdiff(1:size(nk,2),failurepatterns(solution.failurePatternIndexOfMaxLatencyC2CForNFailures(worst_number,idx),:),'legacy'));
end
else
controllersFailed=[];
end
end
set(hEditNodeFailureIDs,'String',num2str(nodesFailed));
set(hEditControllerFailureIDs,'String',num2str(controllersFailed));
end
end
end
%----------------------------------------------------------------------
% Calculates different controller placements for k controller considering a
% failure free case
function optimizeFailureFree(hObject,eventdata,k)
if ~isempty(topology)
set(hScenarioLabel,'Visible','off');
set(hScenarioPopupMenu,'Visible','off');
set(hMainFigure,'Pointer','watch');
set(hStatusLabel,'String','Calculating placements - please wait...');
drawnow;
tmstring='';
if ~tmbool % tm not activated
set(hCheckBoxTM,'Value',0);
tmtemp=ones(1,size(topology,1));
else
set(hCheckBoxTM,'Value',1);
tmtemp=tm(tmindex,:);
optTm=1;
tmstring='with node weights';
end
tic;
if ~plcTopo
solution=evaluateSingleInstance(distanceMatrix,k,tmtemp);
else
solution=evaluateSingleInstance(allToAllShortestPathMatrix(topology),k,tmtemp);
end
calcToc=toc;
nksize=nchoosek(size(topology,1),k);
nk=combnk(1:size(topology,1),k);
currPlacement = 1;
if k < 2
set(hResultPopupMenu,'Visible','on','String',pValuesF(1,1:3));
else
set(hResultPopupMenu,'Visible','on','String',pValuesF);
end
set(hResultLabel,'Visible','on');
optType='F';
active_k=k;
mValues=mValuesF;
set(hEditControllerIDs,'String',num2str(nk(1,:)));
set(hXAxisPopupMenu,'String',mValues(1:3,1));
set(hYAxisPopupMenu,'String',mValues(1:3,1));
panelAxis1Pos = get(hPanelAxes1,'Position');
if panelAxis1Pos(4) < 0.8
set(hXAxisPopupMenu,'Visible','on');
set(hYAxisPopupMenu,'Visible','on');
set(hXAxisLabel,'Visible','on');
set(hYAxisLabel,'Visible','on');
end
valuex=char(mValues{1,2});
valuey=char(mValues{2,2});
set(hYAxisPopupMenu,'Value',2);
val1=min(solution.maxLatencyN2C);
val2=min(solution.controllerImbalance(solution.maxLatencyN2C==val1));
idx=find(solution.maxLatencyN2C==val1 & solution.controllerImbalance==val2,1,'last');
currPlacement = idx;
set(hResultPopupMenu,'Value',2);
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
set(hEditNodeFailureIDs,'String','');
set(hEditControllerFailureIDs,'String','');
plotFigures;
set(hMainFigure,'Pointer','arrow');
set(hStatusLabel,'String',sprintf('Current placements: %s considering only failure free case with k=%d controllers - %d placements, calculated in %d seconds',tmstring,k,nksize,calcToc));
set(hSavePlacementsMenuitem,'Enable','on');
set(hEditControllerIDs,'Visible','on');
set(hEditControllerFailureIDs,'Visible','on');
set(hEditNodeFailureIDs,'Visible','on');
set(hLabelControllerIDs,'Visible','on');
set(hLabelControllerFailureIDs,'Visible','on');
set(hLabelNodeFailureIDs,'Visible','on');
set(hCheckBoxDistNC,'Visible','on');
set(hCheckBoxBalance,'Visible','on');
set(hCheckBoxDistCC,'Visible','on');
set(hMainFigure,'Name','POCO - Current placements not saved');
set(hStartPlanetlabPlotLoopMenuitem,'Enable','on');
set(hStopPlanetlabPlotLoopMenuitem,'Enable','on');
set(hStartPlanetlabCalcLoopMenuitem,'Enable','on');
set(hStopPlanetlabCalcLoopMenuitem,'Enable','on');
end
end
%----------------------------------------------------------------------
% Calculates different controller placements for k controller considering
% up to two node failures
function optimizeNodeFailure(hObject,eventdata,k)
if ~isempty(topology)
set(hMainFigure,'Pointer','watch');
set(hStatusLabel,'String','Calculating placements - please wait...');
drawnow;
tmstring='';
if ~tmbool % tm not activated
set(hCheckBoxTM,'Value',0);
tmtemp=ones(1,size(topology,1));
else
set(hCheckBoxTM,'Value',1);
tmtemp=tm(tmindex,:);
optTm=1;
tmstring='with node weights';
end
tic;
solution=evaluateNodeFailure(topology,k,tmtemp);
calcToc=toc;
nksize=nchoosek(size(topology,1),k);
nk=combnk(1:size(topology,1),k);
set(hCheckBoxHeatmap,'Visible','on');
currPlacement = 1;
set(hResultPopupMenu,'Visible','on','String',pValuesN);
set(hResultLabel,'Visible','on');
set(hScenarioPopupMenu,'Visible','on','String',rbValuesN);
set(hScenarioLabel,'Visible','on');
optType='N';
active_k=k;
mValues=mValuesN;
set(hEditControllerIDs,'String',num2str(nk(1,:)));
set(hXAxisPopupMenu,'String',mValues(:,1));
set(hYAxisPopupMenu,'String',mValues(:,1));
panelAxis1Pos = get(hPanelAxes1,'Position');
if panelAxis1Pos(4) < 0.8
set(hXAxisPopupMenu,'Visible','on');
set(hYAxisPopupMenu,'Visible','on');
set(hXAxisLabel,'Visible','on');
set(hYAxisLabel,'Visible','on');
end
set(hYAxisPopupMenu,'Value',7);
valuex=char(mValues{1,2});
valuey=char(mValues{7,2});
val1=min(solution.maxLatencyN2C);
val2=min(solution.controllerImbalance(solution.maxLatencyN2C==val1));
idx=find(solution.maxLatencyN2C==val1 & solution.controllerImbalance==val2,1,'last');
currPlacement = idx;
set(hResultPopupMenu,'Value',2);
set(hScenarioPopupMenu,'Value',2);
checkScenarioSelection;
set(hEditControllerIDs,'String',num2str(nk(idx,:)));
plotFigures;
set(hMainFigure,'Pointer','arrow');
set(hStatusLabel,'String',sprintf('Current placements: %s considering up to two node failures with k=%d controllers - %d placements, calculated in %d seconds',tmstring,k,nksize,calcToc));
set(hSavePlacementsMenuitem,'Enable','on');
set(hEditControllerIDs,'Visible','on');
set(hEditControllerFailureIDs,'Visible','on');
set(hEditNodeFailureIDs,'Visible','on');
set(hLabelControllerIDs,'Visible','on');
set(hLabelControllerFailureIDs,'Visible','on');
set(hLabelNodeFailureIDs,'Visible','on');
set(hCheckBoxDistNC,'Visible','on');
set(hCheckBoxBalance,'Visible','on');
set(hCheckBoxDistCC,'Visible','on');
set(hMainFigure,'Name','POCO - Current placements not saved');
end
end
%----------------------------------------------------------------------
% Calculates different controller placements considering up to k-1
% controller failures
function optimizeControllerFailure(hObject,eventdata,k)
if ~isempty(topology)
set(hMainFigure,'Pointer','watch');
set(hStatusLabel,'String','Calculating placements - please wait...');
drawnow;
tmstring='';
if ~tmbool % tm not activated
set(hCheckBoxTM,'Value',0);
tmtemp=ones(1,size(topology,1));
else
set(hCheckBoxTM,'Value',1);
tmtemp=tm(tmindex,:);
optTm=1;
tmstring='with node weights';
end
tic;
solution=evaluateControllerFailure(topology,k,tmtemp,plcTopo);
calcToc = toc;
nksize=nchoosek(size(topology,1),k);
nk=combnk(1:size(topology,1),k);
currPlacement = 1;
set(hResultPopupMenu,'Visible','on','String',pValuesC);
set(hResultLabel,'Visible','on');
if k < 3
set(hScenarioPopupMenu,'Visible','on','String',rbValuesC(1,1:3));
else
set(hScenarioPopupMenu,'Visible','on','String',rbValuesC);