optimization - Iterating of elements in array
问题描述
I am trying to write a code of CPLEX OPL on an example of (from control systems) a typical MPC (Model Predictive Control) problem. As described, here:
With optimization variables:
With following parameters:
I have tried to write it but I am stuck at iteration of the array of variable "x" (state variable) as mentioned in the constraint of the optimization problem. The code I have so far written on OPL CPLEX is given as: (The model file as .mod extension on OPL platform)
//data
{string} state = ...;
{string} input = ...;
float A[state][state] =...;
float B[state][input] =...;
float Q[state] =...;
float R[input] =...;
//variable
dvar float State[state];
dvar float Input[input];
minimize
sum( s in state, u in input )
(State[s]*Q[s]*State[s] + Input[u]*R[u]*Input[u]);
subject to {
forall( s in state, u in input )
ct1:
A[s][s]*State[s] + B[s][u]*Input[u] == State[s+1];
}
And the data file which I am using is given as: (the data file of OPL platform with .dat extension)
state = {"x","y","vx","vy"};
input = {"ux","uy"};
A = [[1, 0, 0.2, 0],
[0, 1, 0, 0.2],
[0, 0, 1, 0 ],
[0, 0, 0, 1 ]];
B = [[0, 0],
[0, 0],
[0.2, 0],
[0, 0.2]];
Q = [[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]];
R = [[1, 1],
[1, 1]];
Therefore, I need help kindly to solve this system as I am unable to solve the matter of iteration in the variable of the state variable in the constraint of the given problem.
Your kind help will be highly appreciated as I am stuck on this one for several weeks.
解决方案
你可以把 ct1 变成
forall( s in state, u in input:s !=last( state ))
ct1:
A[s][s]*State[s] + B[s][u]*Input[u] == State[next(state,s)];
.mod
//data
{string} state = ...;
{string} input = ...;
float A[state][state] =...;
float B[state][input] =...;
float Q[state] =...;
float R[input] =...;
//variable
dvar float State[state];
dvar float Input[input];
minimize
sum( s in state, u in input )
(State[s]*Q[s]*State[s] + Input[u]*R[u]*Input[u]);
subject to {
forall( s in state, u in input:s !=last( state ))
ct1:
A[s][s]*State[s] + B[s][u]*Input[u] == State[next(state,s)];
}
.dat
state = {"x","y","vx","vy"};
input = {"ux","uy"};
A = [[1, 0, 0.2, 0],
[0, 1, 0, 0.2],
[0, 0, 1, 0 ],
[0, 0, 0, 1 ]];
B = [[0, 0],
[0, 0],
[0.2, 0],
[0, 0.2]];
Q = [1, 1, 1, 1]
;
R = [1, 1];
作品
推荐阅读
- r - trainControl 中的 p 参数
- html - 在 Bootstrap 中插入 Photobox
- docker - Docker 构建在命令上冻结
- javascript - 如何将对象数组保存在本地存储中
- node.js - 如何在 express.js Vue.js 中使用 firebase-admin
- laravel - Laravel 测试方法 assertRedirect($uri) 和 assertLocation($uri) 的区别?
- typescript - 打字稿:为所有构造函数的命名参数自动创建getter
- node.js - 每当我尝试使用 Next.js 运行“npm run dev”时,都找不到错误模块
- python - 我们如何为有很多连接、哪些连接很少、哪些没有连接的节点着色?
- angular - Angular 中的函数式编程?