Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Add Linear Constraints to a Simple Transmission Cross Section in a Standard OPF? #239

Open
hygge-coder opened this issue Jul 17, 2024 · 4 comments

Comments

@hygge-coder
Copy link

Hi Dr. Zimmerman,
Here is my code,

    function [ om ] = userfcn_case9lineartest(om,mpopt,args)
    mpc = om.get_mpc();
    BranchNum = size(mpc.branch, 1);
    line_indices = [1,4,7]; 
    Line_num = length(line_indices);
    A =sparse(1, line_indices, ones(1, Line_num), 1, BranchNum);
    l=-Inf;
    u=300/mpc.baseMVA;
    om = om.add_lin_constraint('line_flow_limit1', A, l, u,{'Pf'});

I want to add a transmission section constraint by limiting the sum of the transmission power of a few transmission lines of the branch matrix, and then apply this simple linear constraint using add_userfcn(mpc, 'formulation', @userfcn_case9lineartest, []); however Since 'Pf' is not the default variable of matpower, unlike the default variable 'Pg' of matpower which is so easy to use, how should I use the add_var statement to reach the optimization of the branch matrix's transmission power
Kind Regards
hygge

@rdzman
Copy link
Member

rdzman commented Jul 18, 2024

Does toggle_iflims(), described in Section 7.6.2 in the MATPOWER User's Manual do what you want?

@hygge-coder
Copy link
Author

Does toggle_iflims(), described in Section 7.6.2 in the MATPOWER User's Manual do what you want?

Dr. Zimmerman, I understand it can be done, but I would like to become more familiar with MATPOWER by writing this example myself. Could you please guide me on how to use the add_var statement to call Pf data? Thank you.

@rdzman
Copy link
Member

rdzman commented Jul 18, 2024

As you mention, Pf is not a variable, but it is a linear function of the Va variables. It can be computed using the Bf and Pfinj returned by makeBdc() as Pf = Br * Va + Pfinj.

So as you can see here ...

%% form constraints
ifidx = unique(iflims(:, 1)); %% interface number list
nifs = length(ifidx); %% number of interfaces
Aif = sparse(nifs, n);
lif = zeros(nifs, 1);
uif = zeros(nifs, 1);
for k = 1:nifs
%% extract branch indices
br = ifmap(ifmap(:, 1) == ifidx(k), 2);
if isempty(br)
error('userfcn_iflims_formulation: interface %d has no in-service branches', k);
end
d = sign(br);
br = abs(br);
Ak = sparse(1, n); %% Ak = sum( d(i) * Bf(i, :) )
bk = 0; %% bk = sum( d(i) * Pfinj(i) )
for i = 1:length(br)
Ak = Ak + d(i) * Bf(br(i), :);
bk = bk + d(i) * Pfinj(br(i));
end
Aif(k, :) = Ak;
lif(k) = iflims(k, 2) / baseMVA - bk;
uif(k) = iflims(k, 3) / baseMVA - bk;
end
%% add interface constraint
om.add_lin_constraint('iflims', Aif, lif, uif, {'Va'}); %% nifs

... we use that to build up the constraint matrices and bounds as functions of Va.

@hygge-coder
Copy link
Author

Thank you, Dr. Zimmerman. I have resolved the issue, thanks to your assistance. I appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants