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

User defined constraints, variables and costs - most.build_model = false; most.solve_model = true; #76

Closed
lordleoo opened this issue Aug 9, 2019 · 1 comment

Comments

@lordleoo
Copy link

lordleoo commented Aug 9, 2019

MOST does not support adding custom user-defined constraints, yet.
Indeed MATPOWER allows that through the "add_userfcn" function, but MOST doesn't

A manual work-around is:

  1. Building the MOST model, without solving it. that is: set the mpoptions to:
    build_model = true; solve_model = false;

  2. Use the functions:
    build the A, L, U and VS variables to add a new constraint; using the functions: init_indexed_name and add_lin_constraint. To understand how they work, you need to take a deep look at the MOST.m file

  3. set build_most = false; solve_most = true; and call MOST a second time, with your modified model as the input to MOST

now the bug is here:
line 359 of MOST.m has this if statement:
if mpopt.most.build_model
.
.
.
line 553: om = opt_model
< the remaining some-1000 lines >
end

There is no "ELSE" statement.
the OPT_MODEL was declared the first time inside the if-statement. if for some-reason the program didn't enter this IF statement, then an OM=OPT_MODEL does not exist.
you can not pass an existing (readily built) OM to MOST. The input arguments to MOST are: (MDI) and (MPOPT).

Therefore, there is no way to make use of your modified OM model.
The combination: build_most = false; solve_most = true would throw an error.

The work around is simple though, right before the end of this if-statement, add a single line:
.
.
.
else; om = mdi.om;
end

Note:
you have to add you new constraints and variables with the commands:
init_indexed_name and add_lin_constraint.

modifying the structure: mdi.QP.A, mdi.QP.l, mdi.QP.u
would not help, because they are over-written inside MOST.m

The owners of MOST.m may want to change that kind of behavior, because generating mdi.QP takes a lot of time for large models.

a messy workaround is to build your own A, l and u and call the solver manually and outside most.m, that is:

if UC
[mdo.QP.x, mdo.QP.f, mdo.QP.exitflag, mdo.QP.output, mdo.QP.lambda ] = ...
miqps_matpower( mdi.QP.H, mdi.QP.C, mdi.QP.A, ...
mdi.QP.l, mdi.QP.u, mdi.QP.xmin, mdi.QP.xmax, ...
[], mdi.QP.vtype, mdo.QP.opt);
else
[mdo.QP.x, mdo.QP.f, mdo.QP.exitflag, mdo.QP.output, mdo.QP.lambda ] = ...
qps_matpower( mdi.QP.H, mdi.QP.C, mdi.QP.A, ...
mdi.QP.l, mdi.QP.u, mdi.QP.xmin, mdi.QP.xmax, ...
[], mdo.QP.opt);
end

@lordleoo lordleoo closed this as completed Aug 9, 2019
@lordleoo lordleoo changed the title Several MOST issues: Part 2 - build_model = false; solve_model = true; User defined constraints, variables and costs - most.build_model = false; most.solve_model = true; Aug 9, 2019
@rdzman
Copy link
Member

rdzman commented Aug 9, 2019

See MATPOWER/most#6 and MATPOWER/most#8.

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