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
% Look through Xtmp names for constant
% if found, subtract from LHS
to_remove = [];
for j = 1:length(Xtmp.name)
for j = length(Xtmp.name):-1:1
if ~isnan(str2double(Xtmp.name{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
% 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
else
parsing_error('didn''t expect to arrive here', line);
end
if ~isempty(Xtmp)
to_remove = [];
for j = 1:length(Xtmp.name)
% Handle constraits
idx = find(strcmp(X.name, Xtmp.name{j}));
if ~isempty(idx)
X.(X.name{idx}) = X{idx} + Xtmp{j};
to_remove = [to_remove j];
end
end
for j = length(to_remove):-1:1
for j = length(Xtmp.name):-1:1
% Handle constraits
idx = find(strcmp(X.name, Xtmp.name{j}));
if ~isempty(idx)
X.(X.name{idx}) = X{idx} + Xtmp{j};
Xtmp = Xtmp.remove(Xtmp.name{j});
end
X = [X Xtmp];
end
X = [X Xtmp];
end
Y = Y - lhssub;