Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SCDDS-core
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SPC
SCDDS
SCDDS-core
Commits
f23ca40d
Commit
f23ca40d
authored
4 years ago
by
Federico Felici
Browse files
Options
Downloads
Patches
Plain Diff
Update and cleanup and avoid useless saves
parent
2e400db4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
code/classes/SCDclass_algo.m
+80
-57
80 additions, 57 deletions
code/classes/SCDclass_algo.m
with
80 additions
and
57 deletions
code/classes/SCDclass_algo.m
+
80
−
57
View file @
f23ca40d
...
@@ -127,12 +127,7 @@ classdef SCDclass_algo
...
@@ -127,12 +127,7 @@ classdef SCDclass_algo
function
out
=
getdatadictionary
(
obj
)
function
out
=
getdatadictionary
(
obj
)
out
=
obj
.
datadictionary
;
out
=
obj
.
datadictionary
;
end
end
function
designDataObj
=
opendatadictionarydesigndata
(
obj
)
dict
=
Simulink
.
data
.
dictionary
.
open
(
obj
.
getdatadictionary
);
designDataObj
=
getSection
(
dict
,
'Design Data'
);
end
function
createdatadictionary
(
obj
,
varargin
)
function
createdatadictionary
(
obj
,
varargin
)
% create data dictionary in path obj.folder/obj.getdatadictionary
% create data dictionary in path obj.folder/obj.getdatadictionary
...
@@ -197,7 +192,8 @@ classdef SCDclass_algo
...
@@ -197,7 +192,8 @@ classdef SCDclass_algo
% The default value function of a tunparams can be given
% The default value function of a tunparams can be given
% as an optional third argument of addtunparamstruct
% as an optional third argument of addtunparamstruct
% method
% method
DD
=
obj
.
opendatadictionarydesigndata
;
dict
=
Simulink
.
data
.
dictionary
.
open
(
obj
.
getdatadictionary
);
DD
=
getSection
(
dict
,
'Design Data'
);
for
ii
=
1
:
numel
(
obj
.
exportedtps
)
for
ii
=
1
:
numel
(
obj
.
exportedtps
)
if
~
isempty
(
obj
.
exportedtpsdefaults
{
ii
})
if
~
isempty
(
obj
.
exportedtpsdefaults
{
ii
})
% get current value of parameters from the function
% get current value of parameters from the function
...
@@ -221,8 +217,8 @@ classdef SCDclass_algo
...
@@ -221,8 +217,8 @@ classdef SCDclass_algo
continue
;
continue
;
else
else
% replace
% replace
DD
.
deleteEntry
(
tmplname
);
fprintf
(
' %s: deleted previous entry, '
,
obj
.
getname
);
oldEntry
.
setValue
(
P
);
DD
.
addEntry
(
tmplname
,
P
);
fprintf
(
'added new %s\n'
,
tmplname
)
;
fprintf
(
'%s: replaced value of template %s since it changed\n'
,
obj
.
getname
,
tmplname
)
end
end
else
else
fprintf
(
' %s: added new %s\n'
,
obj
.
getname
,
tmplname
);
fprintf
(
' %s: added new %s\n'
,
obj
.
getname
,
tmplname
);
...
@@ -266,22 +262,15 @@ classdef SCDclass_algo
...
@@ -266,22 +262,15 @@ classdef SCDclass_algo
% Add buses to data dictionary from .m file descriptions, if
% Add buses to data dictionary from .m file descriptions, if
% available. Bus names in obj.inBus, obj.outBus
% available. Bus names in obj.inBus, obj.outBus
if
~
isempty
(
which
(
obj
.
inBus
))
&&
~
isempty
(
which
(
obj
.
outBus
))
if
~
isempty
(
which
(
obj
.
inBus
))
&&
~
isempty
(
which
(
obj
.
outBus
))
designDataObj
=
opendatadictionarydesigndata
(
obj
);
dict
=
Simulink
.
data
.
dictionary
.
open
(
obj
.
getdatadictionary
);
designDataObj
=
getSection
(
dict
,
'Design Data'
);
fprintf
(
'Add buses to data dictionary: %s, %s\n'
,
obj
.
inBus
,
obj
.
outBus
);
fprintf
(
'Add buses to data dictionary: %s, %s\n'
,
obj
.
inBus
,
obj
.
outBus
);
eval
(
obj
.
inBus
);
% eval buses in base workspace
eval
(
obj
.
inBus
);
eval
(
obj
.
outBus
);
% eval buses in base workspace
eval
(
obj
.
outBus
);
dosave
=
false
;
if
~
designDataObj
.
exist
(
obj
.
inBus
)
dosave
=
obj
.
replaceorcreateddentry
(
designDataObj
,
obj
.
inBus
,
evalin
(
'base'
,
obj
.
inBus
))
||
dosave
;
addEntry
(
designDataObj
,
obj
.
inBus
,
evalin
(
'base'
,
obj
.
inBus
));
dosave
=
obj
.
replaceorcreateddentry
(
designDataObj
,
obj
.
outBus
,
evalin
(
'base'
,
obj
.
outBus
))
||
dosave
;
else
if
dosave
,
dict
.
saveChanges
;
end
% Save if necessary
entryObj
=
getEntry
(
designDataObj
,
obj
.
inBus
);
setValue
(
entryObj
,
evalin
(
'base'
,
obj
.
inBus
));
end
if
~
designDataObj
.
exist
(
obj
.
outBus
)
addEntry
(
designDataObj
,
obj
.
outBus
,
evalin
(
'base'
,
obj
.
outBus
));
else
entryObj
=
getEntry
(
designDataObj
,
obj
.
outBus
);
setValue
(
entryObj
,
evalin
(
'base'
,
obj
.
outBus
));
end
evalin
(
'base'
,
sprintf
(
'clear %s %s'
,
obj
.
inBus
,
obj
.
outBus
));
evalin
(
'base'
,
sprintf
(
'clear %s %s'
,
obj
.
inBus
,
obj
.
outBus
));
else
else
fprintf
(
'no buses imported in datadictionary - assuming they are already there\n'
)
fprintf
(
'no buses imported in datadictionary - assuming they are already there\n'
)
...
@@ -387,38 +376,34 @@ classdef SCDclass_algo
...
@@ -387,38 +376,34 @@ classdef SCDclass_algo
end
end
function
init
(
obj
)
function
init
(
obj
)
% generate/initialize data dictionary
obj
.
createdatadictionary
;
obj
.
callinits
;
% call generic algorithm init functions
obj
.
callinits
;
% call generic algorithm init functions
% link data dictionary to model and enable access to base
obj
.
load
;
set_param
(
obj
.
getname
,
'DataDictionary'
,
obj
.
getdatadictionary
,
'EnableAccessToBaseWorkspace'
,
'on'
);
% call fixed parameter setup functions
obj
.
setupfp
;
% populate with template tunable parameters
obj
.
updatetemplatetp
;
% add buses
obj
.
setupdd
;
% setup data dictionary
obj
.
addbuses
;
end
% add configurations.sldd as referenced data dictionary, plus
% other optional data dictionaries (e.g. used by lower-level components of an algorithm)
function
setupdd
(
obj
)
dosave
=
false
;
% setup data dictionary
for
refdd
=
[
'configurations.sldd'
,
obj
.
refdatadictionaries
]
dictionaryObj
=
Simulink
.
data
.
dictionary
.
open
(
obj
.
getdatadictionary
);
% generate/initialize data dictionary
if
~
ismember
(
refdd
{:},
dictionaryObj
.
DataSources
)
obj
.
createdatadictionary
;
fprintf
(
'adding referenced data dictionary %s to %s \n'
,
refdd
{:},
obj
.
getdatadictionary
)
refddpath
=
which
(
refdd
{:});
% link data dictionary to model and enable access to base
assert
(
~
isempty
(
refddpath
),
'could not find %s'
);
obj
.
load
;
dictionaryObj
.
addDataSource
(
refdd
{:});
set_param
(
obj
.
getname
,
'DataDictionary'
,
obj
.
getdatadictionary
,
'EnableAccessToBaseWorkspace'
,
'on'
);
dosave
=
1
;
end
% call fixed parameter setup functions
if
dosave
,
dictionaryObj
.
saveChanges
;
end
obj
.
callfpinits
;
end
% populate with template tunable parameters
obj
.
updatetemplatetp
;
% add buses
obj
.
addbuses
;
% add referenced data dictionaries
obj
.
addrefdd
end
end
function
callinits
(
obj
)
function
callinits
(
obj
)
...
@@ -429,7 +414,7 @@ classdef SCDclass_algo
...
@@ -429,7 +414,7 @@ classdef SCDclass_algo
end
end
end
end
function
setupfp
(
obj
)
function
callfpinits
(
obj
)
% call initialization functions that set fixed parameters
% call initialization functions that set fixed parameters
if
~
isempty
(
obj
.
fpinits
)
if
~
isempty
(
obj
.
fpinits
)
for
ii
=
1
:
numel
(
obj
.
fpinits
)
for
ii
=
1
:
numel
(
obj
.
fpinits
)
...
@@ -441,7 +426,7 @@ classdef SCDclass_algo
...
@@ -441,7 +426,7 @@ classdef SCDclass_algo
nout
=
numel
(
targetnames
);
nout
=
numel
(
targetnames
);
if
~
isempty
(
targetnames
)
if
~
isempty
(
targetnames
)
fprintf
(
'Calling init function
''
%s
''
, assigning its output to
''
%s
''
in %s...\n'
,
...
fprintf
(
'Calling
fixed parameter
init function
''
%s
''
, assigning its output to
''
%s
''
in %s...\n'
,
...
char
(
initfunction
),
cell2mat
(
targetnames
),
workspace
);
char
(
initfunction
),
cell2mat
(
targetnames
),
workspace
);
end
end
if
ischar
(
initfunction
)
if
ischar
(
initfunction
)
...
@@ -462,22 +447,60 @@ classdef SCDclass_algo
...
@@ -462,22 +447,60 @@ classdef SCDclass_algo
% assigns in target datadictionary depending
% assigns in target datadictionary depending
% on target workspace
% on target workspace
dosave
=
false
;
dictionaryObj
=
Simulink
.
data
.
dictionary
.
open
(
obj
.
getdatadictionary
);
dd
=
getSection
(
dictionaryObj
,
'Design Data'
);
for
iout
=
1
:
nout
for
iout
=
1
:
nout
% cycle over number of output arguments of the function
% cycle over number of output arguments of the function
val
=
value
{
iout
};
val
=
value
{
iout
};
target
=
targetnames
{
iout
};
target
=
targetnames
{
iout
};
if
strcmp
(
workspace
,
'datadictionary'
)
if
strcmp
(
workspace
,
'datadictionary'
)
% assign in associated data dictionary
% assign in associated data dictionary
Simulink
.
data
.
assigninGlobal
(
obj
.
modelname
,
target
,
val
);
dosave
=
obj
.
replaceorcreateddentry
(
dd
,
target
,
val
)
||
dosave
;
elseif
strcmp
(
workspace
,
'base'
)
elseif
strcmp
(
workspace
,
'base'
)
% assign in base workspace
% assign in base workspace
assignin
(
'base'
,
target
,
val
)
assignin
(
'base'
,
target
,
val
)
end
end
end
end
if
dosave
,
dictionaryObj
.
saveChanges
;
end
end
end
end
end
end
end
function
addrefdd
(
obj
)
% add configurations.sldd as referenced data dictionary, plus
% other optional data dictionaries (e.g. used by lower-level components of an algorithm)
dosave
=
false
;
for
refdd
=
[
'configurations.sldd'
,
obj
.
refdatadictionaries
]
dictionaryObj
=
Simulink
.
data
.
dictionary
.
open
(
obj
.
getdatadictionary
);
if
~
ismember
(
refdd
{:},
dictionaryObj
.
DataSources
)
fprintf
(
'adding referenced data dictionary %s to %s \n'
,
refdd
{:},
obj
.
getdatadictionary
)
refddpath
=
which
(
refdd
{:});
assert
(
~
isempty
(
refddpath
),
'could not find %s'
);
dictionaryObj
.
addDataSource
(
refdd
{:});
dosave
=
true
;
end
if
dosave
,
dictionaryObj
.
saveChanges
;
end
end
end
function
changed
=
replaceorcreateddentry
(
obj
,
dd
,
entry
,
value
)
if
dd
.
exist
(
entry
)
oldEntry
=
dd
.
getEntry
(
entry
);
if
isequal
(
oldEntry
.
getValue
,
value
)
fprintf
(
'%s: keep old value of %s since not changed\n'
,
obj
.
getname
,
entry
);
changed
=
false
;
else
oldEntry
.
setValue
(
value
);
% replace
fprintf
(
'%s: replaced value of %s since it changed\n'
,
obj
.
getname
,
entry
);
changed
=
true
;
end
else
fprintf
(
' %s: added new %s\n'
,
obj
.
getname
,
entry
);
DD
.
addEntry
(
entry
,
value
);
changed
=
true
;
end
end
%% generic operation methods
%% generic operation methods
function
compile
(
obj
)
function
compile
(
obj
)
try
try
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment