Skip to main content

calcTreatmentOptimizationCost.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% This function calculates the cost function values for all treatment
% optimization modules (tracking, verification and design optimization).
%
% (struct, string, struct, struct, struct) -> (2D matrix)
%


function cost = calcTreatmentOptimizationCost( ...
costTermCalculations, allowedTypes, values, modeledValues, auxdata)
cost = [];
for i = 1:length(auxdata.costTerms)
costTerm = auxdata.costTerms{i};
if costTerm.isEnabled
if isfield(costTermCalculations, costTerm.type) && ...
any(ismember(allowedTypes, costTerm.type))
fn = costTermCalculations.(costTerm.type);
cost = cat(2, ...
cost, ...
fn(values, modeledValues, auxdata, costTerm));
% else
% throw(MException('', ['Cost term type ' costTerm.type ...
% ' does not exist for this tool.']))
end
end
end
end