|
11 | 11 | % By convention, ``var`` is the variable name used for mp.sm_variable objects. |
12 | 12 | % |
13 | 13 | % mp.sm_variable Properties: |
| 14 | +% * all_continuous - true if all variables are continuous, false otherwise |
14 | 15 | % * cache - struct for caching aggregated parameters for the set |
15 | 16 | % |
16 | 17 | % mp.sm_variable Methods: |
|
21 | 22 | % * display_soln - display solution values for variables |
22 | 23 | % * get_soln - fetch solution values for specific named/indexed subsets |
23 | 24 | % * parse_soln - parse solution for variables |
| 25 | +% * are_all_continuous - return true if all variables are continuous, false otherwise |
24 | 26 | % * varsets_idx - return vector of indices into full :math:`\x` corresponding to ``vs`` |
25 | 27 | % * varsets_len - return the total number of variables specified by ``vs`` |
26 | 28 | % * varsets_x - return subset of :math:`\x` specified by ``vs`` |
|
29 | 31 | % See also mp.set_manager, mp.set_manager_opt_model. |
30 | 32 |
|
31 | 33 | % MP-Opt-Model |
32 | | -% Copyright (c) 2008-2024, Power Systems Engineering Research Center (PSERC) |
| 34 | +% Copyright (c) 2008-2026, Power Systems Engineering Research Center (PSERC) |
33 | 35 | % by Ray Zimmerman, PSERC Cornell |
34 | 36 | % |
35 | 37 | % This file is part of MP-Opt-Model. |
36 | 38 | % Covered by the 3-clause BSD License (see LICENSE file for details). |
37 | 39 | % See https://github.com/MATPOWER/mp-opt-model for more info. |
38 | 40 |
|
39 | 41 | properties |
| 42 | + all_continuous = []; |
40 | 43 | % struct for caching aggregated parameters for variables |
41 | 44 | cache = []; |
42 | 45 | end %% properties |
|
173 | 176 | obj.data.vu = subsasgn(obj.data.vu, sc, vu); %% upper bound |
174 | 177 | obj.data.vt = subsasgn(obj.data.vt, sc, vt); %% variable type |
175 | 178 | end |
| 179 | + |
| 180 | + %% update all_continuous |
| 181 | + if isempty(obj.all_continuous) |
| 182 | + obj.all_continuous = obj.are_all_continuous(); |
| 183 | + else |
| 184 | + obj.all_continuous = obj.all_continuous && all(vt == 'C'); |
| 185 | + end |
| 186 | + |
176 | 187 | if ~isempty(obj.cache) %% clear cache of aggregated params |
177 | 188 | obj.clear_cached_params(); |
178 | 189 | end |
|
214 | 225 | % |
215 | 226 | % See also add, set_params. |
216 | 227 |
|
217 | | - if nargout > 3 || ~obj.all_continuous() |
| 228 | + if nargout > 3 || ~obj.are_all_continuous() |
218 | 229 | have_vt = 1; |
219 | 230 | else |
220 | 231 | have_vt = 0; |
|
472 | 483 | if is_all && dN |
473 | 484 | obj.set_params_update_dims(dN, name, idx); |
474 | 485 | end |
| 486 | + |
| 487 | + %% update all_continuous |
| 488 | + if u.vt |
| 489 | + if isempty(obj.all_continuous) |
| 490 | + obj.all_continuous = obj.are_all_continuous(); |
| 491 | + else |
| 492 | + obj.all_continuous = obj.all_continuous && all(p.vt == 'C'); |
| 493 | + end |
| 494 | + end |
475 | 495 | end |
476 | 496 |
|
477 | 497 | function obj = display_soln(obj, soln, varargin) |
|
702 | 722 | end |
703 | 723 | end |
704 | 724 |
|
705 | | - function TorF = all_continuous(obj) |
706 | | - % Return true of all variables are continuous, false otherwise. |
| 725 | + function TorF = are_all_continuous(obj) |
| 726 | + % Return true if all variables are continuous, false otherwise. |
707 | 727 | % :: |
708 | 728 | % |
709 | | - % TorF = var.all_continous(); |
| 729 | + % TorF = var.are_all_continuous(); |
710 | 730 | % |
711 | 731 | % Output: |
712 | 732 | % TorF (logical) : true if all variables are continuous, |
713 | 733 | % false otherwise. |
714 | 734 |
|
715 | | - TorF = true; |
716 | | - if obj.get_N() |
717 | | - for k = 1:length(obj.order) |
718 | | - t = obj.data.vt.(obj.order(k).name); |
719 | | - if iscell(t) |
720 | | - for j = 1:length(t(:)) |
721 | | - if any(t{j} ~= 'C') |
| 735 | + if isempty(obj.all_continuous) |
| 736 | + %% evaluate and cache value |
| 737 | + TorF = true; |
| 738 | + if obj.get_N() |
| 739 | + for k = 1:length(obj.order) |
| 740 | + t = obj.data.vt.(obj.order(k).name); |
| 741 | + if iscell(t) |
| 742 | + for j = 1:length(t(:)) |
| 743 | + if any(t{j} ~= 'C') |
| 744 | + TorF = false; |
| 745 | + break; |
| 746 | + end |
| 747 | + end |
| 748 | + else |
| 749 | + if any(t ~= 'C') |
722 | 750 | TorF = false; |
723 | 751 | break; |
724 | 752 | end |
725 | 753 | end |
726 | | - else |
727 | | - if any(t ~= 'C') |
728 | | - TorF = false; |
729 | | - break; |
730 | | - end |
731 | 754 | end |
732 | 755 | end |
| 756 | + else %% use cached value in all_continous property |
| 757 | + TorF = obj.all_continuous; |
733 | 758 | end |
734 | 759 | end |
735 | 760 |
|
|
0 commit comments