Skip to content
Snippets Groups Projects
Commit 7d39f6e9 authored by Federico Felici's avatar Federico Felici
Browse files

Clarify algoobj sorting

parent 9b4b4a4c
No related branches found
No related tags found
No related merge requests found
...@@ -118,12 +118,13 @@ classdef SCDclass_algo ...@@ -118,12 +118,13 @@ classdef SCDclass_algo
fpinits = obj.fpinits; fpinits = obj.fpinits;
end end
function [refdd,refddparent] = getrefdd(obj) function refdd = getrefdd(obj)
refdd = obj.refdatadictionaries; refdd = obj.refdatadictionaries;
refddparent = obj.refddparentalgo;
end end
function refddparent = getrefddparentalgo(obj)
refddparent = obj.refddparentalgo;
end
%% Setup functions setter and getter %% Setup functions setter and getter
function obj = addstdinitfcn(obj,fcnhandle) function obj = addstdinitfcn(obj,fcnhandle)
......
...@@ -555,26 +555,35 @@ classdef SCDclass_expcode ...@@ -555,26 +555,35 @@ classdef SCDclass_expcode
end end
function obj = sortalgoobjlist(obj) function obj = sortalgoobjlist(obj)
% sort algoobj list such that ones without dependency on others % sort algoobj list such that no algoobj has dependency on other
% (through parents of referenced data dictionaries) come first. % algoobj that are further down the list. So running algoobj inits
% in this order ensures that everything is initialized in the correct order.
A = zeros(numel(obj.algoobjlist)); % init adiadency matrix A = zeros(numel(obj.algoobjlist)); % init adiadency matrix
% This matrix element (col,row)=(j,i) will contain 1 if the
% algorithm in algoobjlist(i) references a data dictionary which
% depends on the algoritm in algoobjlist(j).
for ii=1:numel(obj.algoobjlist) for ii=1:numel(obj.algoobjlist)
myalgoobj = obj.algoobjlist{ii}; myalgoobj = obj.algoobjlist{ii};
[~,refddparent] = myalgoobj.getrefdd; refddparentalgo = myalgoobj.getrefddparentalgo;
if isempty(refddparent) || all(cellfun(@isempty,refddparent)) if isempty(refddparentalgo) || all(cellfun(@isempty,refddparentalgo))
A(:,ii) = 0; % no dependency A(:,ii) = 0; % no dependency
else else
% populate dependencies % find indices of dependent algos
% indices of dependent algos for iref = 1:numel(refddparentalgo) % loop on possibly many dd algos
for iref = 1:numel(refddparent)
% index of this referenced parent algo in algoobjlist % index of this referenced parent algo in algoobjlist
jj = contains(obj.algonamelist,refddparent{iref}.getname); jj = contains(obj.algonamelist,refddparentalgo{iref}.getname);
A(jj,ii) = 1; A(jj,ii) = 1;
end end
end end
end end
% Use matlab tools to sort the graph. Could also write e.g. Kahn's
% algorithm explicitly (see wikipedia/topological_sorting)
D = digraph(A); % directed graph D = digraph(A); % directed graph
isort = toposort(D); % topological sorting % topological sorting, maintaining index order where possible
isort = toposort(D,'Order','stable');
obj.algoobjlist = obj.algoobjlist(isort); % sort the init obj list obj.algoobjlist = obj.algoobjlist(isort); % sort the init obj list
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment