Skip to content

Commit

Permalink
Add max_pwl_cost() methods to mp.cost_table and mp.cost_table_utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdzman committed Jan 18, 2024
1 parent 112a0be commit 5ecf4db
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ For change history for [MOST][3], see [most/CHANGES.md](most/CHANGES.md).
since 8.0b1
-----------

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

#### 12/22/23
- Add class `mp.cost_table` to allow reuse of cost tables (e.g for
`legacy_dcline` example).

#### 12/20/23
- Add class `mp_table_subclass`.

#### 12/19/23
- Add a 533-bus distribution system based on real system data from the
local DSO Kraftringen in southern Sweden, including two net-load
Expand Down
36 changes: 27 additions & 9 deletions lib/+mp/cost_table.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
% * cost_table - construct object
% * poly_params - create struct of polynomial parameters from mp.cost_table
% * pwl_params - create struct of piecewise linear parameters from mp.cost_table
% * max_pwl_cost - get maximum cost component used to specify pwl costs
%
% An mp.cost_table has the following columns:
%
Expand Down Expand Up @@ -89,13 +90,13 @@
obj@mp_table_subclass(args{:});
end

function p = poly_params(cost, idx, pu_base)
function p = poly_params(obj, idx, pu_base)
% ::
%
% p = poly_params(cost, idx, pu_base)
% p = poly_params(obj, idx, pu_base)
%
% Inputs:
% cost (mp.cost_table) : the cost table
% obj (mp.cost_table) : the cost table
% idx: (integer) : index vector of rows of interest, empty
% for all rows
% pu_base (double) : base used to scale quantities to per unit
Expand All @@ -115,17 +116,17 @@
%
% Implementation in mp.cost_table_utils.poly_params.

p = mp.cost_table_utils.poly_params(cost, idx, pu_base);
p = mp.cost_table_utils.poly_params(obj, idx, pu_base);
end

function p = pwl_params(cost, idx, pu_base, varargin)
function p = pwl_params(obj, idx, pu_base, varargin)
% ::
%
% p = pwl_params(cost, idx, pu_base)
% p = pwl_params(cost, idx, pu_base, ng, dc)
% p = pwl_params(obj, idx, pu_base)
% p = pwl_params(obj, idx, pu_base, ng, dc)
%
% Inputs:
% cost (mp.cost_table) : the cost table
% obj (mp.cost_table) : the cost table
% idx: (integer) : index vector of rows of interest, empty
% for all rows
% pu_base (double) : base used to scale quantities to per unit
Expand All @@ -143,7 +144,24 @@
%
% Implementation in mp.cost_table_utils.pwl_params.

p = mp.cost_table_utils.pwl_params(cost, idx, pu_base, varargin{:});
p = mp.cost_table_utils.pwl_params(obj, idx, pu_base, varargin{:});
end

function maxc = max_pwl_cost(obj)
% ::
%
% maxc = max_pwl_cost(obj)
%
% Input:
% obj (mp.cost_table) : the cost table
%
% Output:
% maxc (double) : maximum cost component of all breakpoints
% used to specify piecewise linear costs
%
% Implementation in mp.cost_table_utils.max_pwl_cost.

maxc = mp.cost_table_utils.max_pwl_cost(obj);
end
end %% methods

Expand Down
12 changes: 12 additions & 0 deletions lib/+mp/cost_table_utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
% mp.cost_table_util Methods:
% * poly_params - create struct of polynomial parameters from mp.cost_table
% * pwl_params - create struct of piecewise linear parameters from mp.cost_table
% * max_pwl_cost - get maximum cost component used to specify pwl costs
%
% See also mp.cost_table.

Expand Down Expand Up @@ -150,5 +151,16 @@

p = struct('n', ny, 'i', ipwl, 'A', Ay, 'b', by);
end

function maxc = max_pwl_cost(cost)
% ::
%
% maxc = mp.cost_table_utils.max_pwl_cost(cost)
%
% Implementation for mp.cost_table.max_pwl_cost. See
% mp.cost_table.max_pwl_cost for details.

maxc = max(max(cost.pwl_cost));
end
end %% methods (Static)
end %% classdef
4 changes: 2 additions & 2 deletions lib/+mp/dme_gen_opf.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@

function maxgc = max_pwl_gencost(obj)
%
maxgc = max(max(obj.tab.cost_pg.pwl_cost));
maxgc = max_pwl_cost(obj.tab.cost_pg);
if ismember('cost_qg', obj.tab.Properties.VariableNames) && ...
~isempty(obj.tab.cost_qg.pwl_cost)
maxgc = max(maxgc, max(max(obj.tab.cost_qg.pwl_cost)));
maxgc = max(maxgc, max_pwl_cost(obj.tab.cost_qg));
end
end

Expand Down

0 comments on commit 5ecf4db

Please sign in to comment.