-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
127 lines (108 loc) · 4.88 KB
/
main.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
%% main function, requires the configuration file as input
function main
%% put a java.opts file in mcr_root/<ver>/bin/<arch> with
%% -Xmx2096m
% the required jar files
javaaddpath(fullfile(pwd,'lib/db-retriever-0.0.1-SNAPSHOT.jar'));
javaaddpath(fullfile(pwd,'lib/lqnUpdater-0.0.1-SNAPSHOT.jar'));
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.SimpleTimeZone;
%addpath(fullfile(libpath,'modaclouds-fg-demand-master'));
% if matlabpool('size') == 0
% matlabpool open
% setmcruserdata('ParallelProfile','clusterProfile.settings');
% parallel.importProfile('clusterProfile.settings')
% end
while 1
file = 'configuration_FG.xml';
xDoc = xmlread(file);
rootNode = xDoc.getDocumentElement.getChildNodes;
node = rootNode.getFirstChild;
nbMetric = 0;
nbParameter = 0;
while ~isempty(node)
if strcmp(node.getNodeName, 'metric')
subNode = node.getFirstChild;
while ~isempty(subNode)
if strcmpi(subNode.getNodeName, 'algorithm')
algorithm{nbMetric+1} = char(subNode.getTextContent);
nbMetric = nbMetric + 1;
end
if strcmpi(subNode.getNodeName, 'timeStep')
period(nbMetric) = str2double(subNode.getTextContent)*1000
end
if strcmpi(subNode.getNodeName, 'reportDataFolder')
reportDataFolder = char(subNode.getTextContent);
end
if strcmpi(subNode.getNodeName, 'dataHorizon')
dataHorizon = char(subNode.getTextContent);
dataHorizon = java.lang.String(dataHorizon);
horizonValue = str2double(dataHorizon);
if isnan(horizonValue)
try
horizons = dataHorizon.split('-');
sdf = SimpleDateFormat('HH.dd.MM.yyyy');
sdf.setTimeZone(SimpleTimeZone(SimpleTimeZone.UTC_TIME, 'UTC'));
date = sdf.parse(horizons(1));
startTime = num2str(date.getTime());
date = sdf.parse(horizons(2));
endTime = num2str(date.getTime());
catch err
err.message
disp('Please input correct horizons');
exit
end
else
endTime = java.lang.System.currentTimeMillis();
startTime = endTime - horizonValue*60*1000;
endTime = num2str(endTime);
startTime = num2str(startTime);
end
end
if strcmpi(subNode.getNodeName, 'localDBIP')
IP = char(subNode.getTextContent);
end
if strcmpi(subNode.getNodeName, 'parameter')
nbParameter = nbParameter + 1;
parameters{nbMetric}{nbParameter,1} = char(subNode.getAttribute('name'));
parameters{nbMetric}{nbParameter,2} = char(subNode.getAttribute('value'));
end
subNode = subNode.getNextSibling;
end
end
node = node.getNextSibling;
end
[pauseTime, index] = min(period);
nextPauseTime = period - pauseTime;
pause(pauseTime/1000)
ldbURI = strcat('http://',IP,':3030/ds/query');
%queryString = 'SELECT * {?s ?p ?o}';
queryString = strcat(['SELECT ?g ?s ?p ?o WHERE { GRAPH ?g { ?s ?p ?o} GRAPH ?g {' ...
'?s <http://www.modaclouds.eu/rdfs/1.0/monitoringdata#timestamp> ?t FILTER (?t >= '],startTime,' && ?t <= ',endTime,') } }')
tic;
[ resources, category_list ] = dataGeneration(ldbURI,queryString,parameters{index});
if flag ~= -1
tic
[demand, N, Z] = estimation(lower(algorithm{index}),parameters{index},resources,category_list,reportDataFolder);
estimation_time = toc
% switch lower(type{index})
% case 'ci'
% value = estimation('ci',parameters{index},resources);
% case 'rps'
% value = estimation('rps',parameters{index},resources);
% case 'gibbs'
% value = estimation('gibbs',parameters{index},resources);
% end
if length(demand) ~=1 || demand+1 ~=0
updateModel( parameters{index}, category_list, demand, resources, N, Z )
end
end
nextPauseTime = nextPauseTime - toc*1000;
for i = 1:length(nextPauseTime)
if nextPauseTime(i) < 0
nextPauseTime(i) = 0;
end
end
nextPauseTime(index) = max(period(index)-toc*1000,0);
end