MP-Opt-Model
============
[MP-Opt-Model][1] is a package of MATLAB/Octave M-files for constructing
and solving mathematical programming and optimization problems. It provides
an easy-to-use, object-oriented interface for building and solving your
model. It also includes a unified interface for calling numerous LP, QP,
mixed-integer and nonlinear solvers, with the ability to switch solvers
simply by changing an input option.
It is based on code that was originally developed by Ray D. Zimmerman of
Cornell University as part of [MATPOWER][2].
System Requirements
-------------------
* [MATLAB][3] version 7.5 (R2007b) or later, or
* [GNU Octave][4] version 4 or later
* [MP-Test][5], for running the MP-Opt-Model test suite
* [MATPOWER Interior Point Solver (MIPS)][6]
Installation
------------
**Note to [MATPOWER][2] users:** _MP-Opt-Model and its prerequisites, MIPS
and MP-Test, are included when you install [MATPOWER][2]. There is generally
no need to install MP-Opt-Model separately. You can skip directly to step 3
to verify._
Installation and use of MP-Opt-Model requires familiarity with the basic operation
of MATLAB or Octave, including setting up your MATLAB/Octave path.
1. Clone the repository or download and extract the zip file of the MP-Opt-Model
distribution from the [MP-Opt-Model project page][1] to the location of your
choice. The files in the resulting `mp-opt-model` or `mp-opt-modelXXX` directory,
where `XXX` depends on the version of MP-Opt-Model, should not need to be
modified, so it is recommended that they be kept separate from your
own code. We will use `<MPOM>` to denote the path to this directory.
2. Add the following directories to your MATLAB or Octave path:
* `<MPOM>/lib`
* `<MPOM>/lib/t`
3. At the MATLAB/Octave prompt, type `test_mp_opt_model` to run the test suite and
verify that MP-Opt-Model is properly installed and functioning. (Note: The
tests require functioning installations of both [MP-Test][5] and
[MIPS][6]) The result should resemble the following:
```
>> test_mp_opt_model
t_have_fcn..............ok
t_nested_struct_copy....ok
t_nleqs_master..........ok (30 of 150 skipped)
t_pnes_master...........ok
t_qps_master............ok (100 of 432 skipped)
t_miqps_master..........ok (68 of 288 skipped)
t_nlps_master...........ok
t_opt_model.............ok
t_om_solve_leqs.........ok
t_om_solve_nleqs........ok (36 of 194 skipped)
t_om_solve_pne..........ok
t_om_solve_qps..........ok (81 of 387 skipped)
t_om_solve_miqps........ok (14 of 118 skipped)
t_om_solve_nlps.........ok
All tests successful (3430 passed, 329 skipped of 3759)
Elapsed time 4.22 seconds.
```
Sample Usage
------------
Suppose we have the following constrained 4-dimensional quadratic
programming (QP) problem with two 2-dimensional variables, _y_ and _z_,
and two constraints, one equality and the other inequality, along with
lower bounds on all of the variables.
```
min 1/2 [y; z]' * Q * [y; z]
y,z
subject to:
A1 * [y; z] = b1
A2 * y <= u2
y >= ymin
z <= zmax
```
And suppose the data for the problem is provided as follows.
```matlab
%% variable initial values
y0 = [1; 0];
z0 = [0; 1];
%% variable lower bounds
ymin = [0; 0];
zmax = [0; 2];
%% constraint data
A1 = [ 6 1 5 -4 ]; b1 = 4;
A2 = [ 4 9 ]; u2 = 2;
%% quadratic cost coefficients
Q = [ 8 1 -3 -4;
1 4 -2 -1;
-3 -2 5 4;
-4 -1 4 12 ];
```
Below, we will show two approaches to construct and solve the problem.
The first method, based on the the Optimization Model class `opt_model`,
allows you to add variables, constraints and costs to the model
individually. Then `opt_model` automatically assembles and solves the
full model automatically.
```matlab
%%----- METHOD 1 -----
%% build model
om = opt_model;
om.add_var('y', 2, y0, ymin);
om.add_var('z', 2, z0, [], zmax);
om.add_lin_constraint('lincon1', A1, b1, b1);
om.add_lin_constraint('lincon2', A2, [], u2, {'y'});
om.add_quad_cost('cost', Q, []);
%% solve model
[x, f, exitflag, output, lambda] = om.solve();
```
The second method requires you to construct the parameters for the full
problem manually, then call the solver function directly.
```matlab
%%----- METHOD 2 -----
%% assemble model parameters manually
xmin = [ymin; -Inf(2,1)];
xmax = [ Inf(2,1); zmax];
x0 = [y0; z0];
A = [ A1; A2 0 0];
l = [ b1; -Inf ];
u = [ b1; u2 ];
%% solve model
[x, f, exitflag, output, lambda] = qps_master(Q, [], A, l, u, xmin, xmax, x0);
```
The above examples are included in `<MPOM>/lib/t/qp_ex1.m` along with
some commands to print the results, yielding the output below for
each approach:
```
f = 1.875 exitflag = 1
var bound shadow prices
x lambda.lower lambda.upper
0.5000 0.0000 0.0000
0.0000 5.1250 0.0000
-0.0000 0.0000 8.7500
-0.2500 0.0000 0.0000
constraint shadow prices
lambda.mu_l lambda.mu_u
1.2500 0.0000
0.0000 0.6250
```
An options struct can be passed to the `solve` method or the
`qps_master` function to select a specific solver, control the level of
progress output, or modify a solver's default parameters.
Both approaches can be applied to each of the types of problems that
MP-Opt-Model handles, namely, LP, QP, MILP, MIQP, NLP and nonlinear equations.
There are also examples in the test files in `<MPOM>/lib/t`, as well as in
the [`opf_setup()`][12] and [`opf_execute()`][13] functions in [MATPOWER][2].
Documentation
-------------
There are two primary sources of documentation for MP-Opt-Model.
The first is the [MP-Opt-Model User's Manual][7]. It can be found in
your MP-Opt-Model distribution at `<MPOM>/docs/MP-Opt-Model-manual.pdf`
and the latest version is always available at:
<https://github.com/MATPOWER/mp-opt-model/blob/master/docs/MP-Opt-Model-manual.pdf>.
And second is the built-in `help` command. As with the built-in
functions and toolbox routines in MATLAB and Octave, you can type `help`
followed by the name of a command or M-file to get help on that particular
function. Many of the M-files in MP-Opt-Model have such documentation and this
should be considered the main reference for the calling options for each
function, e.g.: `qps_master`, `miqps_master`, and `nlps_master`.
[Citing MP-Opt-Model][10]
-------------------------
We request that publications derived from the use of MP-Opt-Model
explicitly acknowledge that fact by citing the [MP-Opt-Model User's Manual][7].
The citation and DOI can be version-specific or general, as appropriate.
For version 4.1, use:
> R. D. Zimmerman. *MP-Opt-Model User's Manual, Version 4.1*. 2022.
[Online]. Available: https://matpower.org/docs/MP-Opt-Model-manual-4.1.pdf
doi: [10.5281/zenodo.7434250](https://doi.org/10.5281/zenodo.7434250)
For a version non-specific citation, use the following citation and DOI,
with *\<YEAR\>* replaced by the year of the most recent release:
> R. D. Zimmerman. *MP-Opt-Model User's Manual*. *\<YEAR\>*.
[Online]. Available: https://matpower.org/docs/MP-Opt-Model-manual.pdf
doi: [10.5281/zenodo.3818002][11]
A list of versions of the User's Manual with release dates and
version-specific DOI's can be found via the general DOI at
https://doi.org/10.5281/zenodo.3818002.
Contributing
------------
Please see our [contributing guidelines][8] for details on how to
contribute to the project or report issues.
License
-------
MP-Opt-Model is distributed under the [3-clause BSD license][9].
----
[1]: https://github.com/MATPOWER/mp-opt-model
[2]: https://matpower.org/
[3]: https://www.mathworks.com/
[4]: https://www.gnu.org/software/octave/
[5]: https://github.com/MATPOWER/mptest
[6]: https://github.com/MATPOWER/mips
[7]: docs/MP-Opt-Model-manual.pdf
[8]: CONTRIBUTING.md
[9]: LICENSE
[10]: CITATION
[11]: https://doi.org/10.5281/zenodo.3818002
[12]: https://github.com/MATPOWER/matpower/b
没有合适的资源?快使用搜索试试~ 我知道了~
MATLAB资源 MP选择模型 仅供学习参考用代码.rar
共173个文件
m:153个
md:10个
rst:1个
需积分: 5 0 下载量 135 浏览量
2023-05-27
16:42:39
上传
评论
收藏 433KB RAR 举报
温馨提示
MATLAB资源 MP选择模型 仅供学习参考用代码
资源推荐
资源详情
资源评论
收起资源包目录
MATLAB资源 MP选择模型 仅供学习参考用代码.rar (173个子文件)
AUTHORS 117B
MIPS-manual.aux 12KB
make.bat 804B
CITATION 871B
matpower.css 37B
ipopt_options.m 86KB
t_opt_model.m 71KB
pnes_master.m 31KB
set_params.m 19KB
t_pnes_master.m 19KB
t_om_solve_pne.m 19KB
nlps_knitro.m 17KB
miqps_mosek.m 17KB
nlps_ipopt.m 15KB
nlps_fmincon.m 15KB
t_om_solve_nlps.m 15KB
qps_bpmpd.m 14KB
miqps_cplex.m 14KB
miqps_gurobi.m 13KB
qps_mosek.m 13KB
opt_model.m 13KB
miqps_ot.m 13KB
miqps_glpk.m 12KB
qps_ot.m 12KB
display_soln.m 12KB
pne_callback_default.m 12KB
t_nlps_master.m 11KB
qps_master.m 11KB
t_om_solve_qps.m 11KB
solve.m 11KB
qps_gurobi.m 11KB
nlps_master.m 11KB
qps_clp.m 11KB
mp_idx_manager.m 11KB
cplex_options.m 11KB
qps_cplex.m 10KB
t_miqps_master.m 10KB
qps_glpk.m 10KB
nleqs_fd_newton.m 10KB
get_soln.m 9KB
miqps_master.m 9KB
qps_ipopt.m 9KB
t_qps_master.m 9KB
qps_osqp.m 8KB
t_om_solve_miqps.m 8KB
t_om_solve_nleqs.m 8KB
params_quad_cost.m 8KB
mosek_options.m 7KB
pne_detect_events.m 7KB
nested_struct_copy.m 7KB
params_lin_constraint.m 6KB
have_fcn.m 6KB
nleqs_newton.m 6KB
nleqs_core.m 6KB
t_nleqs_master.m 6KB
nleqs_master.m 6KB
set_type_idx_map.m 6KB
mpopt2qpopt.m 5KB
add_named_set.m 5KB
gurobi_options.m 5KB
eval_nln_constraint.m 5KB
t_nested_struct_copy.m 5KB
nleqs_fsolve.m 5KB
eval_nln_cost.m 5KB
nleqs_gauss_seidel.m 5KB
eval_quad_cost.m 5KB
parse_soln.m 5KB
add_nln_constraint.m 5KB
params_var.m 5KB
t_om_solve_leqs.m 5KB
problem_type.m 4KB
eval_nln_constraint_hess.m 4KB
params_nln_constraint.m 4KB
init_indexed_name.m 4KB
osqp_options.m 4KB
add_named_set.m 4KB
add_quad_cost.m 4KB
pne_callback_target_lam.m 4KB
add_var.m 4KB
get_idx.m 3KB
add_lin_constraint.m 3KB
glpk_options.m 3KB
clp_options.m 3KB
nlp_hessfcn.m 3KB
add_nln_cost.m 3KB
mpopt2nlpopt.m 3KB
nlp_consfcn.m 3KB
pne_register_events.m 3KB
mpopt2pneopt.m 3KB
pne_register_callbacks.m 3KB
t_have_fcn.m 3KB
mpopt2nleqopt.m 3KB
get_idx.m 3KB
init_indexed_name.m 3KB
varsets_x.m 2KB
varsets_idx.m 2KB
eval_lin_constraint.m 2KB
qp_ex1.m 2KB
have_feature_glpk.m 2KB
have_feature_ipopt.m 2KB
共 173 条
- 1
- 2
资源评论
极客11
- 粉丝: 357
- 资源: 2433
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功