simplify common parsing

time-shift
Houtan Bastani 2019-01-17 17:00:42 +01:00
parent b62ec7dc55
commit cfd9eff6fb
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
1 changed files with 14 additions and 22 deletions

View File

@ -124,39 +124,31 @@ while ~isempty(plus_node) || ~isempty(last_node_to_parse)
% Handle constraits % Handle constraits
% Look through Xtmp names for constant % Look through Xtmp names for constant
% if found, subtract from LHS % if found, subtract from LHS
to_remove = []; for j = length(Xtmp.name):-1:1
for j = 1:length(Xtmp.name)
if ~isnan(str2double(Xtmp.name{j})) if ~isnan(str2double(Xtmp.name{j}))
lhssub = lhssub + str2double(Xtmp.name{j}) * Xtmp{j}; lhssub = lhssub + str2double(Xtmp.name{j}) * Xtmp{j};
to_remove = [to_remove j]; Xtmp = Xtmp.remove(Xtmp.name{j});
else
% Multiply by -1 now so that it can be added together below
% Otherwise, it would matter which was encountered first,
% a parameter on its own or a linear constraint
Xtmp.(Xtmp.name{j}) = -1 * Xtmp{j};
end end
% Multiply by -1 now so that it can be added together below
% Otherwise, it would matter which was encountered first,
% a parameter on its own or a linear constraint
Xtmp.(Xtmp.name{j}) = -1 * Xtmp{j};
end
for j = length(to_remove):-1:1
Xtmp = Xtmp.remove(Xtmp.name{j});
end end
end end
else else
parsing_error('didn''t expect to arrive here', line); parsing_error('didn''t expect to arrive here', line);
end end
if ~isempty(Xtmp)
to_remove = []; for j = length(Xtmp.name):-1:1
for j = 1:length(Xtmp.name) % Handle constraits
% Handle constraits idx = find(strcmp(X.name, Xtmp.name{j}));
idx = find(strcmp(X.name, Xtmp.name{j})); if ~isempty(idx)
if ~isempty(idx) X.(X.name{idx}) = X{idx} + Xtmp{j};
X.(X.name{idx}) = X{idx} + Xtmp{j};
to_remove = [to_remove j];
end
end
for j = length(to_remove):-1:1
Xtmp = Xtmp.remove(Xtmp.name{j}); Xtmp = Xtmp.remove(Xtmp.name{j});
end end
X = [X Xtmp];
end end
X = [X Xtmp];
end end
Y = Y - lhssub; Y = Y - lhssub;