-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSPLACE.m
1244 lines (1040 loc) · 47.4 KB
/
SPLACE.m
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
%{
Copyright 2013 KIOS Research Center for Intelligent Systems and Networks, University of Cyprus (www.kios.org.cy)
Licensed under the EUPL, Version 1.1 or � as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
You may not use this work except in compliance with the Licence.
You may obtain a copy of the Licence at:
http://ec.europa.eu/idabc/eupl
Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the Licence for the specific language governing permissions and limitations under the Licence.
%}
function varargout = SPLACE(varargin)
% SPLACE MATLAB code for SPLACE.fig
% SPLACE, by itself, creates a new SPLACE or raises the existing
% singleton*.
%
% H = SPLACE returns the handle to a new SPLACE or the handle to
% the existing singleton*.
%
% SPLACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SPLACE.M with the given input arguments.
%
% SPLACE('Property','Value',...) creates a new SPLACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SPLACE_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SPLACE_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help SPLACE
% Last Modified by GUIDE v2.5 17-Mar-2019 14:17:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SPLACE_OpeningFcn, ...
'gui_OutputFcn', @SPLACE_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before SPLACE is made visible.
function SPLACE_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to SPLACE (see VARARGIN)
if ~isdeployed
path(path,genpath(pwd));
end
% Choose default command line output for SPLACE
handles.output = hObject;
handles.ZoomIO=1;
% if libisloaded('epanet2')
% unloadlibrary('epanet2');
% end
pathname=[pwd,'\RESULTS\'];
save([pathname,'pathname.File'],'pathname','-mat');
% UIWAIT makes SPLACE wait for user response (see UIRESUME)
% uiwait(handles.figure1);
opening(hObject, eventdata, handles)
function opening(hObject, eventdata, handles)
set(handles.figure1,'name','S-Place: Quality Sensor Placement in Water Distribution Systems');
%ScreenSize=get(0,'ScreenSize');
position = get(handles.figure1,'Position');
set(handles.figure1,'Position',[position(1) position(2) 206.5 54])
% set(handles.figure1,'Position',[ScreenSize(3)/32 ScreenSize(4)/50 position(3) position(4)]);
set(handles.CreateScenarios,'enable','off');
set(handles.runMultipleScenarios,'enable','off');
set(handles.ComputeImpactMatrix,'enable','off');
set(handles.SolveSensorPlacement,'enable','off');
set(handles.SplaceTable,'visible','on');
set(handles.export_sensors,'visible','off');
set(handles.SaveNetwork,'visible','off');
set(handles.Zoom,'visible','off');
set(handles.NodesID,'visible','off');
set(handles.LinksID,'visible','off');
set(handles.FontsizeENplotText,'visible','off');
set(handles.FontsizeENplot,'visible','off');
set(handles.SplaceTable,'String','');
set(handles.SplaceTable,'enable','inactive');
% Functions
dir_struct = dir(strcat([pwd,'\SPLACE\SCENARIOS\'],''));
[sorted_names,~] = sortrows({dir_struct.name}');
for i=3:length(sorted_names)
[~,name1{i-2},~]=fileparts(sorted_names{i});
end
set(handles.methodsScenarios,'String',name1);
dir_struct = dir(strcat([pwd,'\SPLACE\IMPACT\'],''));
[sorted_names,~] = sortrows({dir_struct.name}');
for i=3:length(sorted_names)
[~,name2{i-2},~]=fileparts(sorted_names{i});
end
set(handles.Impacts,'String',name2);
dir_struct = dir(strcat([pwd,'\SPLACE\SIMULATE\'],''));
[sorted_names,~] = sortrows({dir_struct.name}');
for i=3:length(sorted_names)
[~,name3{i-2},~]=fileparts(sorted_names{i});
end
set(handles.Simulate,'String',name3);
dir_struct = dir(strcat([pwd,'\SPLACE\OPTIMIZATION\'],''));
[sorted_names,~] = sortrows({dir_struct.name}');
for i=3:length(sorted_names)
[~,name4{i-2},~]=fileparts(sorted_names{i});
end
set(handles.Optimization,'String',name4);
set(handles.LoadText,'Value',1);
set(handles.LoadText,'String','S-PLACE:Please Load Input File.');
try
delete(handles.dataplots);
catch err
end
try
delete(handles.previousg);
catch err
end
try
delete(handles.logo);
catch err
end
handles.dataplots=[];
handles.file=[];
handles.previousg=axes('Parent',handles.axes1);
if ~isempty(eventdata)
handles.logo=imshow([pwd,'\HELP\white.png'],'Parent',handles.previousg);
else
handles.logo=imshow([pwd,'\HELP\splace2.png'],'Parent',handles.previousg);
end
set(handles.SaveNetwork,'visible','off');
set(handles.Zoom,'visible','off');
set(handles.pan,'visible','off');
set(handles.NodesID,'visible','off');
set(handles.LinksID,'visible','off');
set(handles.FontsizeENplotText,'visible','off');
set(handles.FontsizeENplot,'visible','off');
set(handles.flowUnits,'visible','off');
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = SPLACE_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in LoadInputFile.
function LoadInputFile_Callback(hObject, eventdata, handles)
% hObject handle to LoadInputFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.CreateScenarios,'enable','inactive');
set(handles.runMultipleScenarios,'enable','inactive');
set(handles.ComputeImpactMatrix,'enable','inactive');
set(handles.SolveSensorPlacement,'enable','inactive');
set(handles.Exit,'enable','inactive');
[inputfile,~] = uigetfile('NETWORKS\*.inp');
if inputfile~=0
col = get(handles.LoadInputFile,'backg'); % Get the background color of the figure.
set(handles.LoadInputFile,'str','LOADING...','backg','w') % Change color of button.
% The pause (or drawnow) is necessary to make button changes appear.
% To see what this means, try doing this with the pause commented out.
pause(.1) % FLUSH the event queue, drawnow would work too.
% Here is where you put whatever function calls or processes that the
% pushbutton is supposed to activate.
% Next we simulate some running process. Here just sort a vector.
B=epanet(inputfile); %clc;
handles.B = B; warning off;
if exist('File0.File','file')==2
load([pwd,'\RESULTS\','File0.File'],'-mat');
file0=[];
save([pwd,'\RESULTS\','File0.File'],'file0','-mat')
end
if exist([pwd,'\RESULTS\','h1.f'])==2
delete([pwd,'\RESULTS\','h1.f'],'h1','-mat');
end
pathname=[pwd,'\RESULTS\'];
save([pwd,'\RESULTS\','pathname.File'],'pathname','-mat');
warning on;
if isempty(B.Errcode)% || isempty(B.NodeCount)
opening(hObject, 1, handles);
s = [['Could not open network "',inputfile,'".'] {'Please insert the correct filename(*.inp).'}];
set(handles.LoadText,'Value',length(s));
set(handles.LoadText,'String',s);
set(handles.LoadInputFile,'str','Load Input File','backg',col);
return;
end
% set(handles.LoadText,'String',which(inputfile));
msg=['>>Load Input File "',inputfile,'" Successful.'];
Getmsg=['>>Current version of EPANET:',num2str(B.Version)];
msg=[msg;{Getmsg}];
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.LoadText,'Value',length(msg));
set(handles.LoadText,'String',msg);
set(handles.LoadInputFile,'str','Load Input File','backg',col) % Now reset the button features.
% Update handles structure
guidata(hObject, handles);
try
delete(findobj('Tag','legend'));
catch
end
try
cla(handles.previousg)
handles.previousg=axes('Parent',handles.axes1);
B.plot('axes',handles.previousg, 'extend', 'no');
catch
end
set(handles.axes1,'HighlightColor','k')
% axis on
% set(handles.axes1,'Color','w')
% set(handles.axes1,'XTick',[])
% set(handles.axes1,'YTick',[])
set(handles.CreateScenarios,'enable','on');
set(handles.runMultipleScenarios,'enable','on');
set(handles.ComputeImpactMatrix,'enable','on');
set(handles.SolveSensorPlacement,'enable','on');
% graphs
set(handles.SaveNetwork,'visible','on');
set(handles.Zoom,'visible','on');
set(handles.NodesID,'visible','on');
set(handles.LinksID,'visible','on');
set(handles.NodesID,'value',0);
set(handles.FontsizeENplotText,'visible','on');
set(handles.FontsizeENplot,'visible','on');
set(handles.SplaceTable,'String','');
set(handles.NodesID,'value',0);
set(handles.LinksID,'value',0);
set(handles.FontsizeENplot,'String',12);
set(handles.pan,'visible','on');
set(handles.flowUnits,'visible','on');
set(handles.flowUnits,'string',['Flow Units: ',char(handles.B.LinkFlowUnits)]);
try
delete(handles.logo);
catch
end
guidata(hObject, handles);
else
if ~libisloaded('epanet2')
set(handles.CreateScenarios,'enable','off');
set(handles.runMultipleScenarios,'enable','off');
set(handles.ComputeImpactMatrix,'enable','off');
set(handles.SolveSensorPlacement,'enable','off');
else
set(handles.CreateScenarios,'enable','on');
set(handles.runMultipleScenarios,'enable','on');
set(handles.ComputeImpactMatrix,'enable','on');
set(handles.SolveSensorPlacement,'enable','on');
end
end
set(handles.Exit,'enable','on');
% --- Executes on button press in runMultipleScenarios.
function runMultipleScenarios_Callback(hObject, eventdata, handles)
set(handles.Exit,'enable','inactive');
set(handles.CreateScenarios,'enable','inactive');
set(handles.LoadInputFile,'enable','inactive');
set(handles.ComputeImpactMatrix,'enable','inactive');
set(handles.SolveSensorPlacement,'enable','inactive');
try
close(findobj('type','figure','name','Simulate All Scenarios'))
close(findobj('type','figure','name','Simulate Random Scenarios'))
catch
end
load([pwd,'\RESULTS\','pathname.File'],'pathname','-mat');
if exist('File0.File','file')==2
load([pwd,'\RESULTS\','File0.File'],'-mat');
if exist([pathname,file0],'file')==2
if ~isempty(file0)
load([pathname,file0],'-mat');
else
B.InputFile=handles.B.InputFile;
end
else
B.InputFile=[];
end
else
file0=[];
end
arguments.file0=file0(1:end-2);
arguments.B=handles.B;
arguments.LoadText = handles.LoadText;
arguments.runMultipleScenarios=handles.runMultipleScenarios;
tmp1=get(handles.Simulate,'value');
tmp2=get(handles.Simulate,'string');
%runMultipleScenariosGui(arguments);
t=str2func(tmp2{tmp1});
t(arguments);
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{['>>',tmp2{tmp1},' Selected']}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.CreateScenarios,'enable','on');
set(handles.LoadInputFile,'enable','on');
set(handles.ComputeImpactMatrix,'enable','on');
set(handles.SolveSensorPlacement,'enable','on');
set(handles.Exit,'enable','on');
% --- Executes on button press in CreateScenarios.
function CreateScenarios_Callback(hObject, eventdata, handles)
% hObject handle to CreateScenarios (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.runMultipleScenarios,'enable','inactive');
set(handles.LoadInputFile,'enable','inactive');
set(handles.ComputeImpactMatrix,'enable','inactive');
set(handles.SolveSensorPlacement,'enable','inactive');
set(handles.Exit,'enable','inactive');
try
close(findobj('type','figure','name','Create Scenarios (Grid)'));
catch
end
arguments.LoadText = handles.LoadText;
arguments.B = handles.B;
tmp1=get(handles.methodsScenarios,'value');
tmp2=get(handles.methodsScenarios,'string');
%CreateScenariosGui(arguments);
t=str2func(tmp2{tmp1});
t(arguments);
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{['>>',tmp2{tmp1},' Method Selected']}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.runMultipleScenarios,'enable','on');
set(handles.LoadInputFile,'enable','on');
set(handles.ComputeImpactMatrix,'enable','on');
set(handles.SolveSensorPlacement,'enable','on');
set(handles.Exit,'enable','on');
% --- Executes on button press in LoadText.
function LoadText_Callback(hObject, eventdata, handles)
% hObject handle to LoadText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
delete(hObject);
rmpath(genpath(pwd));
try
handles.B.unload()
catch
end
try
unloadlibrary('epanet2')
catch
end
try
delete([pwd, '\NETWORKS\*.txt'])
delete([pwd, '\NETWORKS\*_temp.inp'])
catch
end
clc;
try
close(findobj('type','figure','name','Release Location'));
close(findobj('type','figure','name','Solve Sensor Placement'));
close(findobj('type','figure','name','Compute Impact Matrix (CWCV)'));
close(findobj('type','figure','name','Solve with exhaustive method..'));
close(findobj('type','figure','name','Solve with test1 method..'));
close(findobj('type','figure','name','Solve with test2 method..'));
close(findobj('type','figure','name','Simulate All Scenarios'));
close(findobj('type','figure','name','Simulate Random Scenarios'));
close(findobj('type','figure','name','Create Scenarios (Grid)'));
catch
end
% --- Executes on button press in ComputeImpactMatrix.
function ComputeImpactMatrix_Callback(hObject, eventdata, handles)
% hObject handle to ComputeImpactMatrix (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.runMultipleScenarios,'enable','inactive');
set(handles.LoadInputFile,'enable','inactive');
set(handles.CreateScenarios,'enable','inactive');
set(handles.SolveSensorPlacement,'enable','inactive');
set(handles.Exit,'enable','inactive');
try
close(findobj('type','figure','name','Compute Impact Matrix (CWCV)'));
catch
end
load([pwd,'\RESULTS\','pathname.File'],'pathname','-mat');
if exist('File0.File','file')==2
load([pwd,'\RESULTS\','File0.File'],'-mat');
[~, file0, ~] = fileparts(file0);
if exist([pathname,file0,'.0'],'file')==2
[~, ~, ext] = fileparts(file0);
else
ext=[];
end
if length(ext)==0
file0=[file0,'.0'];
if exist([pathname,file0],'file')==2 && exist([pathname,file0(1:end-1),'c0'],'file')==2
if ~isempty(file0)
load([pathname,file0],'-mat');
else
B.InputFile=handles.B.InputFile;
end
else
B.InputFile=[];
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.LoadText,'Value',1);
msg=[msg;{'>>First must be run Simulate Scenarios.'}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.runMultipleScenarios,'enable','on');
set(handles.LoadInputFile,'enable','on');
set(handles.CreateScenarios,'enable','on');
set(handles.SolveSensorPlacement,'enable','on');
set(handles.Exit,'enable','on');
return
end
end
else
file0=[];
end
arguments.file0=file0(1:end-2);
arguments.B=handles.B;
arguments.LoadText = handles.LoadText;
tmp1=get(handles.Impacts,'value');
tmp2=get(handles.Impacts,'string');
%ComputeImpactMatricesGui(arguments);
t=str2func(tmp2{tmp1});
t(arguments);
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{['>>',tmp2{tmp1},' Selected']}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.runMultipleScenarios,'enable','on');
set(handles.LoadInputFile,'enable','on');
set(handles.CreateScenarios,'enable','on');
set(handles.SolveSensorPlacement,'enable','on');
set(handles.Exit,'enable','on');
function edit32_Callback(hObject, eventdata, handles)
% hObject handle to edit32 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit32 as text
% str2double(get(hObject,'String')) returns contents of edit32 as a double
% --- Executes during object creation, after setting all properties.
function edit32_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit32 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in SolveSensorPlacement.
function SolveSensorPlacement_Callback(hObject, eventdata, handles)
% hObject handle to SolveSensorPlacement (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.runMultipleScenarios,'enable','inactive');
set(handles.LoadInputFile,'enable','inactive');
set(handles.CreateScenarios,'enable','inactive');
set(handles.ComputeImpactMatrix,'enable','inactive');
set(handles.Exit,'enable','inactive');
try
close(findobj('type','figure','name','Solve Sensor Placement'))
catch
end
load([pwd,'\RESULTS\','pathname.File'],'pathname','-mat');
if exist('File0.File','file')==2
load([pwd,'\RESULTS\','File0.File'],'-mat');
if exist([pathname,file0],'file')==2
if ~isempty(file0)
load([pathname,file0],'-mat');
if exist([pathname,file0(1:end-2),'.w'],'file')==2
else
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.LoadText,'Value',1);
msg=[msg;{'>>Cannot find impact matrix.**'}];
set(handles.LoadText,'String',msg);
msg=[msg;{'>>Select Compute Impact Matrix.**'}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
end
else
B.InputFile=handles.B.InputFile;
end
else
B.InputFile=[];
end
else
file0=[];
end
arguments.file0=file0(1:end-2);
arguments.B=handles.B;
arguments.LoadText = handles.LoadText;
arguments.SplaceTable = handles.SplaceTable;
arguments.export_sensors = handles.export_sensors;
arguments.axes1 = handles.axes1;
tmp1=get(handles.Optimization,'value');
tmp2=get(handles.Optimization,'string');
%SolveSensorPlacementGui(arguments);
t=str2func(tmp2{tmp1});
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{['>>',tmp2{tmp1},' Method Selected']}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
t(arguments);
set(handles.runMultipleScenarios,'enable','on');
set(handles.LoadInputFile,'enable','on');
set(handles.CreateScenarios,'enable','on');
set(handles.SolveSensorPlacement,'enable','on');
set(handles.ComputeImpactMatrix,'enable','on');
set(handles.Exit,'enable','on');
% --- Executes during object creation, after setting all properties.
function LoadText_CreateFcn(hObject, eventdata, handles)
% hObject handle to LoadText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Exit.
function Exit_Callback(hObject, eventdata, handles)
% hObject handle to Exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.figure1,'Visible','off');
rmpath(genpath(pwd));
try
handles.B.unload()
catch
end
try
unloadlibrary('epanet2')
catch
end
try
delete([pwd, '\NETWORKS\*.txt'])
delete([pwd, '\NETWORKS\*_temp.inp'])
catch
end
clc;
try
close(findobj('type','figure','name','Release Location'));
close(findobj('type','figure','name','Solve Sensor Placement'));
close(findobj('type','figure','name','Compute Impact Matrix (CWCV)'));
close(findobj('type','figure','name','Solve with exhaustive method..'));
close(findobj('type','figure','name','Solve with test1 method..'));
close(findobj('type','figure','name','Solve with test2 method..'));
close(findobj('type','figure','name','Simulate All Scenarios'));
close(findobj('type','figure','name','Simulate Random Scenarios'));
close(findobj('type','figure','name','Create Scenarios (Grid)'));
catch
end
% --- Executes on selection change in SplaceTable.
function SplaceTable_Callback(hObject, eventdata, handles)
% hObject handle to SplaceTable (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns SplaceTable contents as cell array
FontSize = str2num(get(handles.FontsizeENplot,'String'));
if ~length(FontSize) || FontSize<0 || FontSize>20
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{'>>Give Font Size.'}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
return
end
lineSensors = get(handles.SplaceTable,'Value');
StringSensors = get(handles.SplaceTable,'String');
tline = StringSensors(lineSensors);
tline = regexp(tline,'\s*','split');
tline = tline{1};
if length(tline)>2
if exist([pwd,'\RESULTS\','h1.f'])==2
load([pwd,'\RESULTS\','h1.f'],'h1','h2','IndexID','-mat');
for i=1:length(IndexID)
C1='b'; C2='b';
if sum(IndexID(i)==handles.B.NodeReservoirIndex)
C2='g'; C1='g';
elseif sum(IndexID(i)==handles.B.NodeTankIndex)
C2='k'; C1='k';
end
plot(handles.B.NodeCoordinates{1}(IndexID(i)),handles.B.NodeCoordinates{2}(IndexID(i)),'o','LineWidth',2,'MarkerEdgeColor',C1,...
'MarkerFaceColor',C2,'MarkerSize',5);
try
delete(findall(handles.axes1,'Type','text'));
delete(h1(:)); h1=[];
delete(h2(:)); h2=[];
catch
end
end
end
IndexID=[];
ind = find(strcmpi(tline, 'NodesID:'))+1;
SensorsNodesID=tline(ind:end);
% SensorsNodesID=tline(6:end);
for i=1:length(SensorsNodesID)
IndexID(i)= handles.B.getNodeIndex(SensorsNodesID(i));
x{i}=handles.B.NodeCoordinates{1}(IndexID(i));
y{i}=handles.B.NodeCoordinates{2}(IndexID(i));
end
t=1;
for u=1:length(SensorsNodesID)
h2(t)=plot(x{u}(1),y{u}(1),'o','LineWidth',2,'MarkerEdgeColor','r',...
'MarkerFaceColor','r',...
'MarkerSize',5);
h1(t)=text(x{u}(1),y{u}(1),char(handles.B.NodeNameID(IndexID(u))),'FontSize',FontSize);
t=t+1;
end
save([pwd,'\RESULTS\','h1.f'],'h1','h2','IndexID', '-mat');
end
% --- Executes during object creation, after setting all properties.
function SplaceTable_CreateFcn(hObject, eventdata, handles)
% hObject handle to SplaceTable (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in Zoom.
function Zoom_Callback(hObject, eventdata, handles)
% hObject handle to Zoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str = get(handles.Zoom,'String');
set(handles.pan,'String','Pan');
if strcmp('Zoom',str)
try
zoom on;
catch
end
set(handles.Zoom,'String','Reset');
% History
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{['>>','Zoom',' Selected']}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
end
if strcmp('Reset',str)
for i=1:2
try
zoom off;
zoom out;
zoom reset;
catch
end
end
font(hObject, eventdata, handles);
% History
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{['>>','Reset',' Selected']}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.Zoom,'String','Zoom');
end
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in LinksID.
function LinksID_Callback(hObject, eventdata, handles)
% hObject handle to LinksID (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of LinksID
if ~isempty(findall(handles.axes1,'Type','text'))
delete(findall(handles.axes1,'Type','text'))
end
value=get(handles.LinksID,'Value');
FontSize = str2num(get(handles.FontsizeENplot,'String'));
if ~length(FontSize) || FontSize<0 || FontSize>30 || FontSize==0
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{'>>Font Size(max 30).'}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.FontsizeENplot,'String','12');
FontSize=12;
end
if value==1
set(handles.NodesID,'Value',0);
for i=1:handles.B.LinkCount
x1=handles.B.NodeCoordinates{1}(handles.B.NodesConnectingLinksIndex(i,1));
y1=handles.B.NodeCoordinates{2}(handles.B.NodesConnectingLinksIndex(i,1));
x2=handles.B.NodeCoordinates{1}(handles.B.NodesConnectingLinksIndex(i,2));
y2=handles.B.NodeCoordinates{2}(handles.B.NodesConnectingLinksIndex(i,2));
hLinksID(i)=text((x1+x2)/2,(y1+y2)/2,handles.B.LinkNameID(i),'FontSize',FontSize);
end
end
guidata(hObject, handles);
% --- Executes on button press in NodesID.
function NodesID_Callback(hObject, eventdata, handles)
% hObject handle to NodesID (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of NodesID
if ~isempty(findall(handles.axes1,'Type','text'))
delete(findall(handles.axes1,'Type','text'))
end
value=get(handles.NodesID,'Value');
FontSize = str2num(get(handles.FontsizeENplot,'String'));
if ~length(FontSize) || FontSize<0 || FontSize>30 || FontSize==0
load([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
msg=[msg;{'>>Font Size(max 30).'}];
set(handles.LoadText,'String',msg);
set(handles.LoadText,'Value',length(msg));
save([pwd,'\RESULTS\','ComWind.messsages'],'msg','-mat');
set(handles.FontsizeENplot,'String','12');
FontSize=12;
end
if value==1
set(handles.LinksID,'Value',0);
for i=1:handles.B.NodeCount
hNodesID(i)=text(handles.B.NodeCoordinates{1}(i),handles.B.NodeCoordinates{2}(i),char(handles.B.NodeNameID(i)),'FontSize',FontSize,'Tag','Task String');
end
end
guidata(hObject, handles);
function FontsizeENplot_Callback(hObject, eventdata, handles)
% hObject handle to FontsizeENplot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of FontsizeENplot as text
% str2double(get(hObject,'String')) returns contents of FontsizeENplot as a double
if get(handles.NodesID,'Value');
NodesID_Callback(hObject, eventdata, handles);
elseif get(handles.LinksID,'Value');
LinksID_Callback(hObject, eventdata, handles);
end
% --- Executes during object creation, after setting all properties.
function FontsizeENplot_CreateFcn(hObject, eventdata, handles)
% hObject handle to FontsizeENplot (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in methodsScenarios.
function methodsScenarios_Callback(hObject, eventdata, handles)
% hObject handle to methodsScenarios (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns methodsScenarios contents as cell array
% contents{get(hObject,'Value')} returns selected item from methodsScenarios
% --- Executes during object creation, after setting all properties.
function methodsScenarios_CreateFcn(hObject, eventdata, handles)
% hObject handle to methodsScenarios (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in CreateScenarios.
function pushbutton23_Callback(hObject, eventdata, handles)
% hObject handle to CreateScenarios (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in viewCreateScenarios.
function viewCreateScenarios_Callback(hObject, eventdata, handles)
% hObject handle to viewCreateScenarios (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
nameFunction=get(handles.methodsScenarios,'String');
index=get(handles.methodsScenarios,'Value');
open([char(nameFunction(index)),'.m']);
% --- Executes on selection change in Optimization.
function Optimization_Callback(hObject, eventdata, handles)
% hObject handle to Optimization (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Optimization contents as cell array
% contents{get(hObject,'Value')} returns selected item from Optimization
% --- Executes during object creation, after setting all properties.
function Optimization_CreateFcn(hObject, eventdata, handles)
% hObject handle to Optimization (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in SolveSensorPlacement.
function pushbutton21_Callback(hObject, eventdata, handles)
% hObject handle to SolveSensorPlacement (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton22.
function pushbutton22_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton22 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
nameFunction=get(handles.Optimization,'String');
index=get(handles.Optimization,'Value');
open([char(nameFunction(index)),'.m']);
% --- Executes on selection change in Simulate.
function Simulate_Callback(hObject, eventdata, handles)
% hObject handle to Simulate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Simulate contents as cell array
% contents{get(hObject,'Value')} returns selected item from Simulate
% --- Executes during object creation, after setting all properties.
function Simulate_CreateFcn(hObject, eventdata, handles)
% hObject handle to Simulate (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in runMultipleScenarios.
function pushbutton19_Callback(hObject, eventdata, handles)
% hObject handle to runMultipleScenarios (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)