I tried getting out of the problem by assigning allow_multiple = 1 for
add_userfcn. But I couldn't get past this error:
Error using opt_model/add_constraints (line 87)
Error detected on worker 4.
@opt_model/add_constraints: linear constraint set named 'Va' already exists

Could you guide me as to how I can overwrite this too?
Thank you sir

Regards
Viswanath

On Fri, Oct 13, 2017 at 11:22 AM, Viswanath Hariharan <vhari...@buffalo.edu>
wrote:

> Sir
> So I used the toggle_myconstraints method you had suggested to add Voltage
> angle constraints to the problem. After getting the solution, I update the
> constraints set and call toggle_myconstraints again. But this time, I get
> an error :
> Caused by:
>     Error using add_userfcn (line 119)
>     add_userfcn: the function 'userfcn_myconstraints_formulation' has
> already been added
>
> How do I avoid this problem? Is there a way to overwrite what's already
> written in both add_userfcn and the linear constraints section in om (in
> this case 'Va')?
>
> Regards
> Viswanath
>
> On Fri, Oct 13, 2017 at 10:04 AM, Viswanath Hariharan <
> vhari...@buffalo.edu> wrote:
>
>> Thank you for your help sir. I think I was doing something wrong. It
>> works alright now.
>>
>> Regards
>> Viswanath
>>
>> On Oct 12, 2017 10:03 AM, "Ray Zimmerman" <r...@cornell.edu> wrote:
>>
>>> Are you saying that your solution includes voltage angles whose absolute
>>> value is greater than 0.26 radians or 14.9 degrees?
>>>
>>>    Ray
>>>
>>>
>>> On Oct 11, 2017, at 8:52 PM, Viswanath Hariharan <vhari...@buffalo.edu>
>>> wrote:
>>>
>>> First, thank you so much for your time, Sir.
>>> So I tried the first approach first. I want to added box constraints for
>>> Voltage angle, -0.26 < theta < 0.26.  I created the A matrix and l and u
>>> vectors and passed it to the opf function. The solution converged and I did
>>> get results. But the problem is that the added constraints look like they
>>> had no effect on the result.
>>>
>>> I also tried the toggle_reserves() method you suggested in the previous
>>> email of this thread where you asked me rename toggle_reserves and all the
>>> callback functions within it and modify its contents to toggle the addition
>>> of constraints. I did that too. results = runopf(mpc) and results.om
>>> had 5 linear constraints added to it. But again this had no effect on the
>>> results. I even tried changing the bounds to see if there was any
>>> difference but there wasn't.
>>>
>>> What is it that I'm missing out here?
>>>
>>> Regards
>>> Viswanath
>>>
>>>
>>>
>>> On Tue, Oct 10, 2017 at 9:09 AM, Ray Zimmerman <r...@cornell.edu> wrote:
>>>
>>>> It appears you have fundamentally misunderstood callback functions and
>>>> how they work. I suggest that you read carefully the entirety of sections
>>>> 7.2–7.5 in the User’s Manual and make sure you understand the
>>>> toggle_reserves() example used to illustrate the approach.
>>>>
>>>> To implement your own constraints, I would recommend copying and
>>>> renaming toggle_reserves() to something like toggle_myconstraints().
>>>> Then rename all of the callback functions defined in that file to e.g.
>>>> userfcn_myconstraints_ext2int(), userfcn_myconstraints_formulation(),
>>>> etc., and modify their contents to reflect the constraints you want to add
>>>> (as opposed to those implemented for the zonal reserves case). The
>>>> “formulation” callback is where you’ll be calling add_constraints().
>>>> Then you can simply toggle your constraints on and use runopf()
>>>> normally.
>>>>
>>>> mpc = loadcase('<mycase>');
>>>> mpc = toggle_myconstraints(mpc, 'on');
>>>> results = runopf(mpc);
>>>>
>>>> Hope this helps,
>>>>
>>>>     Ray
>>>>
>>>>
>>>>
>>>> On Oct 5, 2017, at 12:18 PM, Viswanath Hariharan <vhari...@buffalo.edu>
>>>> wrote:
>>>>
>>>> Sir
>>>>
>>>> I tried adding constraints using the callback functions method
>>>> described in Section 7.2 but I am not sure I followed it correctly.
>>>>     mpopt = mpoption;
>>>>     om = opf_setup(mpc, mpopt);
>>>>     om = add_constraints(om, 'Vm', A1, l1, u1);
>>>>     om = add_constraints(om, 'Va', A2, l2, u2);
>>>>     mpc = get_mpc(om)
>>>>     results2 = runopf(mpc);
>>>>
>>>> om gets updated with 10 linear constraints (case5 is being used here).
>>>> But mpc doesn't get updated and hence when I run this code and check and
>>>> results.var.mu.l.Va <http://results.var.mu.l.va/>, the constraints
>>>> aren't updated. Not only that, the mpc file isn't getting updated as well.
>>>> I think I am making some mistake with this line : mpc = get_mpc(om) because
>>>> om is fine. What am I missing here? Or should I take another approach?
>>>> Thank you so much for your time Sir.
>>>>
>>>> Regards
>>>> Viswanath Hariharan
>>>>
>>>> On Thu, Oct 5, 2017 at 10:27 AM, Ray Zimmerman <r...@cornell.edu>
>>>> wrote:
>>>>
>>>>> You only need to use the add_constraints() function if you are using
>>>>> Callback Functions as described in Section 7.2 as opposed to Direct
>>>>> Specification as described in Section 7.1 of the User’s Manual
>>>>> <http://www.pserc.cornell.edu/matpower/docs/MATPOWER-manual-6.0.pdf>.
>>>>>
>>>>> You convergence failure my just imply that your variable bounds are
>>>>> tight enough that there is no feasible solution. Try relaxing the limits
>>>>> and see if it converges.
>>>>>
>>>>> Vm, Pg and Qg all have limits specified directly in the bus and gen
>>>>> matrices. Vm is bounded by the VMIN and VMAX columns in the bus matrix.
>>>>> Pg and Qg are bounded by the PMIN, PMAX and QMIN, QMAX columns of the
>>>>> gen matrix, respectively. Va is not normally constrained (except at
>>>>> the reference bus), so the bus matrix doesn’t contain bounds for it. In
>>>>> that case, you have to use the standard linear constraints of equation
>>>>> (6.25) to impose bounds.
>>>>>
>>>>> At a lower lever, variable bounds are defined when variables are added
>>>>> via the add_vars() method. The Va, Vm, Pg and Qg variables are added
>>>>> automatically (with their bounds) in opf_setup(), so you can’t really
>>>>> modify them there. But for any variables you add later, you supply the
>>>>> bounds when you call add_vars().
>>>>>
>>>>>    Ray
>>>>>
>>>>>
>>>>>
>>>>> On Oct 4, 2017, at 3:52 PM, Viswanath Hariharan <vhari...@buffalo.edu>
>>>>> wrote:
>>>>>
>>>>> So I do not need to use the add_constraints function? Because when I
>>>>> used the code you mentioned and then runopf(mpc), convergence fails. In
>>>>> general, how to add box constraints for Va,Vm, Pg and Qg of xr (r =
>>>>> runopf(mpc); r.raw.xr).
>>>>> If I have to use the add_constraints function, how do I do that?
>>>>>
>>>>> Regards
>>>>> Viswanath Hariharan
>>>>>
>>>>> On Wed, Sep 27, 2017 at 1:39 PM, Ray Zimmerman <r...@cornell.edu>
>>>>> wrote:
>>>>>
>>>>>> Voltage magnitude constraints are already included. Simply set the
>>>>>> VMIN and VMAX columns in the bus matrix to the desired values.
>>>>>>
>>>>>> For voltage angles, simply define the A, l and u corresponding to
>>>>>> equation (6.25) in the User’s Manual
>>>>>> <http://www.pserc.cornell.edu/matpower/docs/MATPOWER-manual-6.0.pdf>.
>>>>>> Something like the following …
>>>>>>
>>>>>> mpc = loadcase(<your-case-name>);
>>>>>> nb = size(mpc.bus, 1);
>>>>>> ng = size(mpc.gen, 1);
>>>>>> mpc.A = sparse(1:nb, 1:nb, 1, nb
>>>>>> <https://maps.google.com/?q=1:nb,+1,+nb&entry=gmail&source=g>,
>>>>>> 2*nb+2*ng);
>>>>>> mpc.u = 0.26 * ones(nb, 1);
>>>>>> mpc.u = -mpc.l;
>>>>>>
>>>>>> — Ray
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Sep 23, 2017, at 5:25 PM, Viswanath Hariharan <
>>>>>> vhari...@buffalo.edu> wrote:
>>>>>>
>>>>>> Hello Sir
>>>>>>
>>>>>> I want to add voltage magnitude and voltage angle constraints to the
>>>>>> opf solver but I am not able to figure out how to.
>>>>>>
>>>>>> Voltage magnitude constraints --->  0.9 <= Vm <= 1.1
>>>>>> Voltage angle constraints ---> - 0.26 <= Va <= 0.26 (Unrelaxed form)
>>>>>>
>>>>>> I read a post where you mentioned to add these constraints to the case
>>>>>> struct which looked pretty simple in the post but I didn't know how
>>>>>> to add
>>>>>> that to the case struct.
>>>>>> I was wondering if you can guide me on how to do it. Hoping to hear
>>>>>> from
>>>>>> you soon.
>>>>>>
>>>>>> Regards
>>>>>> Viswanath Hariharan
>>>>>> Graduate Research Assistant
>>>>>> Electrical Engineering
>>>>>> University at Buffalo
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>

Reply via email to