Hello Dailan
I hope to help.
1. The best example for you understanding is the toggle_reserves
function. This example is referred to add reserves. you must pay attention to
the "function om = userfcn_reserves_formulation(om, args)". This part is the
main of the all function that modify the objective functions and add
constraints.
2. If you only add variables, the function objective is no affected,
because the new variable needs to be linked to existing variables. For this
cause, you need the constraints. In the example with reserves, the constraint:
om = add_constraints(om, 'Pg_plus_R', Ar, [], ur, {'Pg', 'R'}); is the limit
the generation of all generators plus the reserve requirements. On the other
hand the cost is need if you wish add the new cost to the objective function.
3. You need to build an A matrix that has all constraints or diferents A
matrix with differents constraints. I.e., you will be adding additional rows
for the constraints that include your new variables, as power factor.
Best Regards
Santiago
De: [email protected] [mailto:[email protected]] En nombre de Dailan Xu
Enviado el: lunes, 20 de junio de 2011 14:29
Para: Santiago Chamba
Asunto: Re: Adding variable
Dear Santiago
Thank U very very much for your help.
1. When I run the code I can't get the results(there is an error). If U give me
an example I will be appreciated.
2. When I add a variable, is it necessary to add the constraints to cost
function? I only want to add another variable to objective function.
3. Also, I have another problem I have written a code to define a specified
power factor of 0.95 for generators (another constraint). How can I combine
these 2 codes. I am so sorry I disturbed you again.
The code is as follows:
define_constants;
mpc = loadcase('case30');
nb = size(mpc.bus, 1);
ng = size(mpc.gen, 1);
pf = 0.95;
QPratio = sqrt(1/pf^2 -1);
%% add constraint that QPratio * Pg(i) - Qg(i) = 0, for i = 2 .. ng
mpc.A = sparse([1:ng 1:ng]', [2*nb+(1:ng) 2*nb+ng+(1:ng)]',
[QPratio*ones(ng,1); -ones(ng,1)], ng, 2*nb+2*ng);
mpc.A = mpc.A(2:end, :);
mpc.l = zeros(ng-1, 1);
mpc.u = mpc.l;
runopf(mpc)
Best Regards
D. Xu
On Mon, Jun 20, 2011 at 19:16, Santiago Chamba <[email protected]> wrote:
Hello Dailan
In my problem, I added piecewise linear cost for each line. For this, I worked
with DC OPF because in Matpower is very easy introduce variable and linear
constrains.
You are going to need to modify the OPF model (om). The "om" object is
constructed to encapsulate the data defining the problem. This object maintains
all of the relevant indexing information for named blocks of variables,
constraints and costs as they are added.
For example:
mpc = loadcase( 'case9');
mpopt = mpoption('VERBOSE', 0, 'OUT_ALL', 0, 'PF_DC',1,'OPF_ALG_DC',100);
om=opf_setup(mpc,mpopt);
Later, you have define the new variables and constraints to the system. For
this, you must define the matrix's size the nwe variables and constraints. For
example,
define_constants;
mpc = get_mpc(om);
%%Added the new variable
om1 = add_vars(om, 'F', nl, [], [], []);
%% Adeed the constraints:
om1 = add_constraints(om1, 'Fc', Flin, Fmin, Fmax, {'Va'});
om1 = add_constraints(om1, 'Eq', Feq, Feqmin, Feqmax, {'Va','F'});
And, to added cost in a system, you colud added the following:
om1 = add_costs(om1, 'Fcost',struct('N',I,'Cw',Fcost1), {'F'});
you can look that om initial is modify it and the new estructure is om1. To
run the opf, you have that run with the new structure, as:
Results=opf_execute(om1,mpopt);
I recommend you read: MATPOWER’s Extensible Optimal Power Flow Architecture.
This paper is a summary that describes the optimal power flow (OPF)
architecture implemented in MATPOWER.
Best Regards
Santiago
De: [email protected] [mailto:[email protected]] En nombre de Dailan Xu
Enviado el: lunes, 20 de junio de 2011 12:38
Para: [email protected]
Asunto: Adding variable
Dear Santiago
I hope you will be good.
I saw in MATPOWER archive list that you have added variables to objective
function.
Could you please let me know how can I add an optimization variable to run in
runmarket?for example in 'case9', how can I add another optimization variable?
Best Regards
D. Xu