Skip to content

Commit

Permalink
Rename is_index_name() method of mp.mapped_array to has_name().
Browse files Browse the repository at this point in the history
  • Loading branch information
rdzman committed Jan 18, 2024
1 parent 5ecf4db commit 2028dec
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ For change history for [MOST][3], see [most/CHANGES.md](most/CHANGES.md).
since 8.0b1
-----------

#### 1/18/24
- Rename the `is_index_name()` method of `mp.mapped_array` to `has_name()`.

#### 1/9/24
- Add `mp.cost_table_utils` with static methods for use by `mp.cost_table`.

Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# -- Project information -----------------------------------------------------

project = 'MATPOWER Documentation'
copyright = '1996-2023, Power Systems Engineering Research Center (PSERC)'
copyright = '1996-2024, Power Systems Engineering Research Center (PSERC)'
author = 'Ray D. Zimmerman, Carlos E. Murillo-Sánchez, Hongye Wang, et. al.'

# The full version, including alpha/beta/rc tags
Expand Down
4 changes: 2 additions & 2 deletions lib/+mp/data_model.m
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
% Output:
% n (integer) : number of online elements

if obj.elements.is_index_name(name)
if obj.elements.has_name(name)
n = obj.elements.(name).n;
else
n = 0;
Expand Down Expand Up @@ -411,7 +411,7 @@ function display(obj)
%% suppress output detail (default for large systems)
suppress = mpopt.out.suppress_detail;
if suppress == -1
if obj.elements.is_index_name('bus') && ...
if obj.elements.has_name('bus') && ...
obj.elements.bus.nr > 500
suppress = 1;
else
Expand Down
2 changes: 1 addition & 1 deletion lib/+mp/dm_converter.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@

for k = 1:length(dm.elements)
dme = dm.elements{k};
if obj.elements.is_index_name(dme.name)
if obj.elements.has_name(dme.name)
dmce = dme.dm_converter_element(obj);
if all_vars
vars = dme.main_table_var_names();
Expand Down
2 changes: 1 addition & 1 deletion lib/+mp/dme_bus.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
obj.vm_ub = bus.vm_ub(obj.on);

%% update bus type and starting vm based on connected gen status
if dm.elements.is_index_name('gen')
if dm.elements.has_name('gen')
gen_dme = dm.elements.gen;
[gbus, ig] = obj.gbus_vector(gen_dme);
nb = obj.n;
Expand Down
2 changes: 1 addition & 1 deletion lib/+mp/dme_bus3p.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
obj.vm3_start = bus.vm3(obj.on);

%% update bus type and starting vm based on connected gen status
if dm.elements.is_index_name('gen3p')
if dm.elements.has_name('gen3p')
gen_dme = dm.elements.gen3p;
[gbus, ig] = obj.gbus_vector(gen_dme);
nb = obj.n;
Expand Down
12 changes: 6 additions & 6 deletions lib/+mp/mapped_array.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
% ma.delete_elements('height');
%
% % check for named element
% ma.is_index_name('color');
% ma.has_name('color');
%
% mp.mapped_array Methods:
% * mapped_array - constructor
Expand All @@ -37,7 +37,7 @@
% * add_names - add or modify names of elements
% * add_elements - append elements to the end of the mapped array
% * delete_elements - delete elements from the mapped array
% * is_index_name - return ``true`` if the name exists in the mapped array
% * has_name - return ``true`` if the name exists in the mapped array
% * name2idx - return the index corresponding to a name
% * subsref - called when indexing a mapped array to retrieve data
% * subsasgn - called when indexing a mapped array to assign data
Expand Down Expand Up @@ -251,11 +251,11 @@
end
end

function TorF = is_index_name(obj, name)
function TorF = has_name(obj, name)
% Return ``true`` if the name exists in the mapped array.
% ::
%
% TorF = obj.is_index_name(name);
% TorF = obj.has_name(name);
%
% Input:
% name (char array) : name to check
Expand Down Expand Up @@ -298,8 +298,8 @@
end
else %% method calls or properties
switch s(1).subs
case 'is_index_name'
varargout{1} = is_index_name(obj, s(2).subs{:});
case 'has_name'
varargout{1} = has_name(obj, s(2).subs{:});
case 'name2idx'
varargout{1} = name2idx(obj, s(2).subs{:});
case 'length'
Expand Down
2 changes: 1 addition & 1 deletion lib/+mp/math_model_pf_acps.m
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
%% modify data model to form Bp (B prime)
if nargout > 1 %% for both Bp and Bpp
dm1 = dm.copy();
if dm1.elements.is_index_name('shunt')
if dm1.elements.has_name('shunt')
dm1.elements.shunt.tab.bs(:) = 0; %% zero out shunts at buses
end
dm2 = dm1.copy();
Expand Down
4 changes: 2 additions & 2 deletions lib/+mp/nm_element.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
if nargin < 3
name = obj.name;
end
if mm.elements.is_index_name(name)
if mm.elements.has_name(name)
mme = mm.elements.(name);
else
mme = [];
Expand Down Expand Up @@ -520,7 +520,7 @@
[nidx{:}] = deal(zeros(dme.n, 1));

for i = 1:length(cxn_type)
if dm.elements.is_index_name(cxn_type{i})
if dm.elements.has_name(cxn_type{i})
jxn_dme = dm.elements.(cxn_type{i}); %% data model element for cxn_type{i}
jxn_nme = nm.elements.(cxn_type{i}); %% corresp. net model element
ni = nm.get_node_idx(cxn_type{i}); %% corresponding node indices
Expand Down
2 changes: 1 addition & 1 deletion lib/+mp/task.m
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ function save_soln(obj, fname)
~isempty(mpopt.exp.exclude_elements)
ex = mpopt.exp.exclude_elements;
for k = length(ex):-1:1
if ~dmc.elements.is_index_name(ex{k})
if ~dmc.elements.has_name(ex{k})
ex(k) = []; %% skip missing exclusions
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/t/+mp/dme_branch_node_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
%% get bus mapping info
obj.nbet = length(obj.cxn_type);
for k = obj.nbet:-1:1
if dm.elements.is_index_name(obj.cxn_type{k})
if dm.elements.has_name(obj.cxn_type{k})
bus_dme{k} = dm.elements.(obj.cxn_type{k});
b2i_k{k} = bus_dme{k}.ID2i; %% bus element num to idx mapping
else
Expand Down Expand Up @@ -72,7 +72,7 @@
function obj = update_status(obj, dm)
%% get bus status info
for k = 1:obj.nbet
if dm.elements.is_index_name(obj.cxn_type{k})
if dm.elements.has_name(obj.cxn_type{k})
bus_dme = dm.elements.(obj.cxn_type{k});
bs = bus_dme.tab.status; %% bus element status

Expand Down
4 changes: 2 additions & 2 deletions lib/t/+mp/dme_gen_node_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
%% get bus mapping info
obj.nbet = length(obj.cxn_type);
for k = obj.nbet:-1:1
if dm.elements.is_index_name(obj.cxn_type{k})
if dm.elements.has_name(obj.cxn_type{k})
bus_dme{k} = dm.elements.(obj.cxn_type{k});
b2i_k{k} = bus_dme{k}.ID2i;
else
Expand Down Expand Up @@ -67,7 +67,7 @@
function obj = update_status(obj, dm)
%% get bus status info
for k = 1:obj.nbet
if dm.elements.is_index_name(obj.cxn_type{k})
if dm.elements.has_name(obj.cxn_type{k})
bus_dme = dm.elements.(obj.cxn_type{k});
bs = bus_dme.tab.status; %% bus element status

Expand Down
2 changes: 1 addition & 1 deletion lib/t/+mp/mme_branch_opf_acp_node_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
%% from makeAang()
nb = 0;
for k = 1:dme.nbet
if dm.elements.is_index_name(dme.cxn_type{k})
if dm.elements.has_name(dme.cxn_type{k})
nb = nb + dm.elements.(dme.cxn_type{k}).n;
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/t/t_mp_data_model.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
t_ok(isa(dm.elements, 'mp.mapped_array'), [t 'isa(dm.elements, ''mp.mapped_array'')']);
t_is(length(dm.elements), 5, 12, [t 'length(dm.elements)']);
t_ok(isa(dm.elements, 'mp.mapped_array'), [t 'isa(dm.elements, ''mp.mapped_array'')']);
t_ok(dm.elements.is_index_name('bus'), [t 'dm.elements.is_index_name(''bus'')']);
t_ok(dm.elements.is_index_name('gen'), [t 'dm.elements.is_index_name(''gen'')']);
t_ok(dm.elements.is_index_name('load'), [t 'dm.elements.is_index_name(''load'')']);
t_ok(dm.elements.is_index_name('branch'), [t 'dm.elements.is_index_name(''branch'')']);
t_ok(dm.elements.is_index_name('shunt'), [t 'dm.elements.is_index_name(''shunt'')']);
t_ok(dm.elements.has_name('bus'), [t 'dm.elements.has_name(''bus'')']);
t_ok(dm.elements.has_name('gen'), [t 'dm.elements.has_name(''gen'')']);
t_ok(dm.elements.has_name('load'), [t 'dm.elements.has_name(''load'')']);
t_ok(dm.elements.has_name('branch'), [t 'dm.elements.has_name(''branch'')']);
t_ok(dm.elements.has_name('shunt'), [t 'dm.elements.has_name(''shunt'')']);
t_is(dm.elements.name2idx('bus'), 1, 12, [t 'dm.elements.name2idx(''bus'')']);
t_is(dm.elements.name2idx('gen'), 2, 12, [t 'dm.elements.name2idx(''gen'')']);
t_is(dm.elements.name2idx('load'), 3, 12, [t 'dm.elements.name2idx(''load'')']);
Expand Down
12 changes: 6 additions & 6 deletions lib/t/t_mp_mapped_array.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
t_ok(isequal(A.p_.vals, vals), [t 'vals']);
t_ok(isequal(A.p_.names, names), [t 'names']);

t = 'is_index_name : ';
t_ok(A.is_index_name('vector'), [t 'vector']);
t_ok(A.is_index_name('cellstr'), [t 'cellstr']);
t_ok(A.is_index_name('struct'), [t 'struct']);
t_ok(A.is_index_name('object'), [t 'object']);
t_ok(~A.is_index_name('random'), [t 'random']);
t = 'has_name : ';
t_ok(A.has_name('vector'), [t 'vector']);
t_ok(A.has_name('cellstr'), [t 'cellstr']);
t_ok(A.has_name('struct'), [t 'struct']);
t_ok(A.has_name('object'), [t 'object']);
t_ok(~A.has_name('random'), [t 'random']);

t = 'name2idx : ';
t_is(A.name2idx('vector'), 1, 12, [t 'vector']);
Expand Down

0 comments on commit 2028dec

Please sign in to comment.