用MATLAB和内点法实现带有时变不等式约束的分布式优化

2023-11-15

问题描述

考虑代价函数
f i ( x i , t ) = ∥ x i − x i ∗ ( t ) ∥ 2 . f_i(x_i,t)=\|x_i-x_i^*(t)\|^2. fi(xi,t)=xixi(t)2.
求解一个简单的优化问题实例:
min ⁡ 1 2 ∑ i = 1 n f i ( x i , t ) s.t. ⁡ f i ( x i , t ) ≤ 1 x i − x j = 0 \begin{aligned} \min &\quad \frac{1}{2}\sum_{i=1}^n f_i(x_i,t)\\ \operatorname{s.t.} &\quad f_i(x_i,t)\leq 1\\ &\quad x_i-x_j=0 \end{aligned} mins.t.21i=1nfi(xi,t)fi(xi,t)1xixj=0

如下图所示,参考位置 x i ∗ ( t ) x_i^*(t) xi(t)由菱形表示,初始位置 x i ( 0 ) x_i(0) xi(0)由小圆圈表示,不等式约束 f i ( x i , t ) ≤ 1 f_i(x_i,t)\leq 1 fi(xi,t)1由大圆圈表示。

内点法

设计barrier构建带惩罚项的代价函数
L i ( x , t ) = f i ( x , t ) − 1 ρ ( t ) log ⁡ ( 1 − ρ ( t ) ( f i ( x i , t ) − 1 ) ) , ρ ( t ) = a 1 e a 2 t , a 1 , a 2 > 0 , L_i(x,t) = f_i(x,t)-\frac{1}{\rho(t)}\log(1-\rho(t)(f_i(x_i,t)-1)),\quad \rho(t)=a_1e^{a_2t},\quad a_1,a_2>0, Li(x,t)=fi(x,t)ρ(t)1log(1ρ(t)(fi(xi,t)1)),ρ(t)=a1ea2t,a1,a2>0
其中,梯度、Hessian和关于时间的变化率为
∇ L i ( x i , t ) = ∇ f i ( x i , t ) + ∇ f i ( x i , t ) 1 − ρ ( t ) ( f i ( x i , t ) − 1 ) ∂ ∂ t ∇ L i ( x i , t ) = ∂ ∂ t ∇ f i ( x i , t ) + ∂ ∇ f i ( x i , t ) / ∂ t 1 − ρ ( t ) ( f i ( x i , t ) − 1 ) + ( ρ ˙ ( t ) ( f i ( x i , t ) − 1 ) + ρ ( t ) ∂ f i ( x i , t ) / ∂ t ) ∇ f i ( x i , t ) ( 1 − ρ ( t ) ( f i ( x i , t ) − 1 ) ) 2 ∇ 2 L i ( x i , t ) = ∇ 2 f i ( x i , t ) + ∇ 2 f i ( x i , t ) 1 − ρ ( t ) ( f i ( x i , t ) − 1 ) + ρ ( t ) ∇ f i ( x i , t ) ∇ f i ( x i , t ) T 1 − ρ ( t ) ( f i ( x i , t ) − 1 ) \begin{aligned} \nabla L_i(x_i,t)&=\nabla f_i(x_i,t)+\frac{\nabla f_i(x_i,t)}{1-\rho(t)(f_i(x_i,t)-1)}\\ \frac{\partial}{\partial t}\nabla L_i(x_i,t)&=\frac{\partial}{\partial t}\nabla f_i(x_i,t)+\frac{\partial\nabla f_i(x_i,t)/\partial t}{1-\rho(t)(f_i(x_i,t)-1)}\\ &\quad+\frac{(\dot \rho(t)(f_i(x_i,t)-1)+\rho(t)\partial f_i(x_i,t)/\partial t)\nabla f_i(x_i,t)}{(1-\rho(t)(f_i(x_i,t)-1))^2}\\ \nabla^2 L_i(x_i,t)&=\nabla^2 f_i(x_i,t)+\frac{\nabla^2 f_i(x_i,t)}{1-\rho(t)(f_i(x_i,t)-1)}+\frac{\rho(t)\nabla f_i(x_i,t)\nabla f_i(x_i,t)^T}{1-\rho(t)(f_i(x_i,t)-1)} \end{aligned} Li(xi,t)tLi(xi,t)2Li(xi,t)=fi(xi,t)+1ρ(t)(fi(xi,t)1)fi(xi,t)=tfi(xi,t)+1ρ(t)(fi(xi,t)1)fi(xi,t)/t+(1ρ(t)(fi(xi,t)1))2(ρ˙(t)(fi(xi,t)1)+ρ(t)fi(xi,t)/t)fi(xi,t)=2fi(xi,t)+1ρ(t)(fi(xi,t)1)2fi(xi,t)+1ρ(t)(fi(xi,t)1)ρ(t)fi(xi,t)fi(xi,t)T
参考Sun 20201,设计如下控制律
u i = − β ( ∇ 2 L i ( x i , t ) ) − 1 ∑ j ∈ N i sgn ⁡ ( x i − x j ) + ϕ i ( t ) ϕ i ( t ) = − ( ∇ 2 L i ( x i , t ) ) − 1 ( ∇ L i ( x i , t ) + ∂ ∂ t ∇ L i ( x i , t ) ) \begin{aligned} u_i&=-\beta(\nabla^2L_i(x_i,t))^{-1}\sum_{j\in\mathcal N_i}\operatorname{sgn}(x_i-x_j)+\phi_i(t)\\ \phi_i(t)&=-(\nabla^2L_i(x_i,t))^{-1}\left(\nabla L_i(x_i,t)+\frac{\partial}{\partial t}\nabla L_i(x_i,t) \right) \end{aligned} uiϕi(t)=β(2Li(xi,t))1jNisgn(xixj)+ϕi(t)=(2Li(xi,t))1(Li(xi,t)+tLi(xi,t))

MATLAB实现

下面给出MATLAB仿真结果和源代码。

仿真结果

仿真结果动图如下所示。

每一个 x i x_i xi的轨迹如下图所示,可以看出所有agent的状态一致且收敛到优化问题的解。

源代码

robot_num = 5;

% reference
angle_central = 2*pi/robot_num;
if ~mod(robot_num,2)
    pos_ref = [cos([0 kron(1:(robot_num-1)/2,[1,-1]) robot_num/2]*angle_central)',...
        sin([0 kron(1:(robot_num-1)/2,[1,-1]) robot_num/2]*angle_central)']/2;
else
    pos_ref = [cos([0 kron(1:(robot_num-1)/2,[1,-1])]*angle_central)',...
        sin([0 kron(1:(robot_num-1)/2,[1,-1])]*angle_central)']/2;
end

% topology
graph = selectTopology(robot_num,pos_ref);

% initial position
pos_rob = pos_ref*rot2(2*pi/3);

% initial control
u_rob = zeros(size(pos_rob));

% reference control
u_ref_func = @(t) pos_ref./normby(pos_ref,1)*sin(pi*t)/2.*(-1).^(0:robot_num-1)';
u_ref = u_ref_func(0);

% plot
color_list = ['b','g','m','r','c'];
for i=1:robot_num
    hg_pos_rob(i) = plot(pos_rob(i,1),pos_rob(i,2),[color_list(i) 'o']); hold on
    pos_circ = circle_(pos_ref(i,:),1);
    hg_pos_circ(i) = plot(pos_circ(:,1),pos_circ(:,2),color_list(i));
    hg_pos_ref(i) = plot(pos_ref(i,1),pos_ref(i,2),[color_list(i) 'd']); 
    hg_u_ref(i) = quiver(pos_ref(i,1),pos_ref(i,2),u_ref(i,1),u_ref(i,2),'color',color_list(i),'LineStyle', '--');
    axis([-2 2 -2 2])
end
hold off

% functions
a1 = 1; a2 = 1; rho = a1*exp(a2*0); cost_hessian = 2*eye(2);
cost_ref = @(i,pos_rob,pos_ref) (pos_rob(i,:)-pos_ref(i,:))*(pos_rob(i,:)-pos_ref(i,:))';
cost_ref_dot = @(i,pos_rob,u_ref) -2*(pos_rob(i,:)-pos_ref(i,:))*u_ref(i,:)';
cost_ref_nabla = @(i,pos_rob,pos_ref) 2*(pos_rob(i,:)-pos_ref(i,:))';
cost_ref_nabla_dot = @(i,u_ref) -2*u_ref(i,:)';
cost_penalty = @(i,pos_rob,rho) cost_ref(i,pos_rob,pos_ref)-(1/rho)*log(1-rho*(cost_ref(i,pos_rob,pos_ref)-1));
cost_penalty_nabla = @(i,pos_rob,pos_ref,rho) cost_ref_nabla(i,pos_rob,pos_ref)*(1+1/(1-rho*(cost_ref(i,pos_rob,pos_ref)-1)));
cost_penalty_nabla_dot = @(i,pos_rob,pos_ref,rho) cost_ref_nabla_dot(i,u_ref)*(1+1/(1-rho*(cost_ref(i,pos_rob,pos_ref)-1)))+...
    rho*(a2*(cost_ref(i,pos_rob,pos_ref)-1)+cost_ref_dot(i,pos_rob,u_ref))/(1-rho*(cost_ref(i,pos_rob,pos_ref)-1))^2;
cost_penalty_hessian = @(i,pos_rob,pos_ref,rho) cost_hessian*(1+1/(1-rho*(cost_ref(i,pos_rob,pos_ref)-1)))+...
    rho*cost_ref_nabla(i,pos_rob,pos_ref)*cost_ref_nabla(i,pos_rob,pos_ref)'/(1-rho*(cost_ref(i,pos_rob,pos_ref)-1));
% test error
cost_ref(i,pos_rob,pos_ref);
cost_ref_dot(i,pos_rob,u_ref);
cost_ref_nabla(i,pos_rob,pos_ref);
cost_ref_nabla_dot(i,u_ref);
cost_penalty(i,pos_rob,rho);
cost_penalty_nabla(i,pos_rob,pos_ref,rho);
cost_penalty_nabla_dot(i,pos_rob,pos_ref,rho);
cost_penalty_hessian(i,pos_rob,pos_ref,rho);
disp('All functions are correct.');

% simulation
pos_data = pos_rob;
dt = 0.005;
T = 10;
loop = 0;
playspeed = 4;
video_on = true;
for t=0:dt:T
    loop = loop+1;
    % control
    u_ref = u_ref_func(t);
    beta = 1; hessian_inv = []; u_rob_tp = u_rob';
    for i=1:robot_num
       phi(:,i) = -cost_penalty_hessian(i,pos_rob,pos_ref,rho)^-1*...
           (cost_penalty_nabla(i,pos_rob,pos_ref,rho)+cost_penalty_nabla_dot(i,pos_rob,pos_ref,rho));
       hessian_inv = blkdiag(hessian_inv,cost_penalty_hessian(i,pos_rob,pos_ref,rho)^-1);
    end
    sign_rob = (graph.incidence*sign(graph.incidence'*pos_rob))';
    u_rob_tp(:) = -beta*hessian_inv*sign_rob(:)+phi(:);
    u_rob = u_rob_tp';
    % update
    pos_ref = pos_ref+dt*u_ref;
    pos_rob = pos_rob+dt*u_rob;
    pos_data(:,:,loop) = pos_rob;
    % plot
    for i=1:robot_num
        set(hg_pos_rob(i),'xdata',pos_rob(i,1),'ydata',pos_rob(i,2)); 
        pos_circ = circle_(pos_ref(i,:),1);
        set(hg_pos_circ(i),'xdata',pos_circ(:,1),'ydata',pos_circ(:,2));
        set(hg_pos_ref(i),'xdata',pos_ref(i,1),'ydata',pos_ref(i,2));
        set(hg_u_ref(i),'xdata',pos_ref(i,1),'ydata',pos_ref(i,2),...
            'udata',u_ref(i,1),'vdata',u_ref(i,2));
        axis([-2 2 -2 2])
    end
    % video
    if mod(loop,playspeed)==0&&video_on
        frame(loop/playspeed) = getframe(gcf);
    end
    drawnow
end

% write video
if video_on 
    savevideo('video',frame);
end

% result
figure 
t_data = 0:dt:T;
xpos_data = squeeze(pos_data(:,1,:));
ypos_data = squeeze(pos_data(:,2,:));
plot3(kron(ones(robot_num,1),t_data)',xpos_data',ypos_data');
xlabel('time/s');ylabel('x/m');zlabel('y/m');grid

源代码我已上传至我的GitHub,见项目paper-simulation。运行Sun2020Distributed文件夹下的文件time_varying_optimization.m,即可得到上面的仿真结果。代码中部分函数用到了RTB,下载和安装说明点击这里

如果喜欢,欢迎点赞和fork。


  1. Sun, S., & Ren, W. (2020). Distributed Continuous-Time Optimization with Time-Varying Objective Functions and Inequality Constraints. Retrieved from http://arxiv.org/abs/2009.02378 ↩︎

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

用MATLAB和内点法实现带有时变不等式约束的分布式优化 的相关文章

  • MATLAB 中最有效的矩阵求逆

    在 MATLAB 中计算某个方阵 A 的逆矩阵时 使用 Ai inv A should be the same as Ai A 1 MATLAB 通常会通知我这不是最有效的求逆方法 那么什么是更有效率的呢 如果我有一个方程系统 可能会使用
  • 如何使用matlab生成不同频率的正弦波?

    对于我的项目 我需要使用 matlab 生成一个正弦波 它有 100 000 个样本 并且频率在每 10 000 个样本后随机变化 采样率和频率可以根据方便而定 matlab中有没有函数可以生成这个 好的另一个例子 生成 5 个随机频率 r
  • MATLAB 中的多个捕获组

    我有一个包含数字或字母的字符串a 可能紧随其后的是r or l 在 MATLAB 中 以下正则表达式返回为 gt gt regexp 10r 0 9 a l r match ans 10r 我希望10 and r分开 因为我有两个捕获组 有
  • 在 matlab 中求 3d 峰的体积

    现在我有一个带有峰值的 3D 散点图 我需要找到其体积 我的数据来自图像 因此 x 和 y 值表示 xy 平面上的像素位置 z 值是每个像素的像素值 这是我的散点图 scatter3 x y z 20 z filled 我试图找到数据峰值的
  • 不等间隔时间序列的移动平均线

    我有一个证券交易所股票价格的数据集 时间 价格 但数据点之间的间隔并不相等 从 1 到 2 分钟不等 在这种情况下计算移动平均值的最佳实践是什么 如何在Matlab中实现呢 我倾向于认为 点的权重应该取决于自上一个点以来的最后时间间隔 Ma
  • MATLAB - 如何将子图一起缩放?

    我在一张图中有多个子图 每个图的 X 轴是相同的变量 时间 每个图上的 Y 轴都不同 无论是它所代表的内容还是数据的大小 我想要一种同时放大所有图的时间尺度的方法 理想情况下 可以在其中一张图上使用矩形缩放工具 并让其他图相应地更改其 X
  • MATLAB 特征函数

    我很好奇哪里可以找到完整的描述FEATURE功能 它接受哪些论点 没有找到文档 我只听说过memstats and getpid 还要别的吗 gt gt which feature built in undocumented 注意 更完整的
  • MATLAB:具有复数的 printmat

    我想使用 MATLAB 的printmat显示带有标签的矩阵 但这不适用于复数 N 5 x rand N 1 y rand N 1 z x 1i y printmat x y z fftdemo N 1 2 3 4 5 x y x iy O
  • 有没有办法在matlab中进行隐式微分

    我经常使用 matlab 来帮助我解决数学问题 现在我正在寻找一种在 matlab 中进行隐式微分的方法 例如 我想区分y 3 sin x cos y exp x 0关于dy dx 我知道如何使用数学方法通常做到这一点 但我一直在努力寻找使
  • Matlab 和 Python 中的优化算法(dog-leg trust-region)

    我正在尝试使用 Matlab 和 Python 中的狗腿信赖域算法求解一组非线性方程 在Matlab中有fsolve https www mathworks com help optim ug fsolve html其中此算法是默认算法 而
  • 括号中的波形符字符

    在 MATLAB 中 以下代码执行什么操作 m func returning matrix 波浪号运算符 的作用是什么 在 Matlab 中 这意味着不要将函数中相应的输出参数分配到赋值的右侧 因此 如果func returning mat
  • 在 Matlab 中高效获取像素坐标

    我想在 Matlab 中创建一个函数 给定一个图像 该函数将允许人们通过单击图像中的像素来选择该像素并返回该像素的坐标 理想情况下 人们能够连续单击图像中的多个像素 并且该函数会将所有相应的坐标存储在一个矩阵中 有没有办法在Matlab中做
  • matlab中的排列函数是如何工作的

    这是一个有点愚蠢的问题 但我似乎无法弄清楚排列在 matlab 中是如何工作的 以文档为例 A 1 2 3 4 permute A 2 1 ans 1 3 2 4 到底是怎么回事 这如何告诉 matlab 3 和 2 需要交换 哇 这是我迄
  • 通过 Matlab 访问 Physionet 的 ptbdb 中的数据库

    我首先设置系统 old path which rdsamp if isempty old path rmpath old path 1 end 8 end wfdb url http physionet org physiotools ma
  • 如何在放置颜色条后保持子图大小不变

    假设我们有一个 1 2 子图 我们在其中绘制了一些图形 如下所示 subplot 1 2 1 surf peaks 20 subplot 1 2 2 surf peaks 20 然后我们要添加一个颜色条 colorbar 我不希望结果中的正
  • 了解 fminunc 参数和匿名函数、函数处理程序

    请多多包涵 问题在最后 我试图找出 fminunc 调用方式的差异 这个问题源于 Andrew Ng 在他的 Coursera 机器学习课程中的第 3 周材料 我正在回答这个问题 Matlab Andrew Ng 机器学习课程中 t cos
  • Matlab 的 imresize 函数中用于插值的算法是什么?

    我正在使用 Matlab Octaveimresize 对给定的二维数组重新采样的函数 我想了解如何使用特定的插值算法imresize works 我在Windows上使用八度 e g A 1 2 3 4 是一个二维数组 然后我使用命令 b
  • 快速有效地计算已知特征值的特征向量

    我的问题的简短版本 计算矩阵特征向量的最佳方法是什么A 如果我们已经知道属于特征向量的特征值呢 更长的解释 我有一个很大的随机矩阵A由于它是随机的 因此具有非负左特征向量x 这样A Tx x 我正在寻找快速有效的方法来数值计算这个向量 最好
  • MATLAB:在不使用循环的情况下提取矩阵的多个部分

    我有一个巨大的 2D 矩阵 我想从中提取 15 个不同的 100x100 部分 我有两个向量 x 和 y 其中保存了零件的左上角索引 我用过这样的东西 result cam1 x 1 end x 1 end 99 y 1 end y 1 e
  • 小矩阵乘以大矩阵

    我试图将小矩阵 假设为 2x2 中的每个元素与大矩阵 假设为 4x4 中的每个位置逐个元素相乘 所以我想要 1 2 3 4 1 0 3 0 1 0 1 2 3 4 0 0 0 0 0 0 x 1 2 3 4 1 0 3 0 1 2 3 4

随机推荐

  • kvm内存管理

    qemu kvm 进程很像一个普通的linux程序 它通过通常的malloc和mmap调用来申请内存 如果一个客户系统想使用1G物理内存 qemu kvm将会做一个malloc 1 lt lt 30 调用 在主机上申请1G的虚拟地址 然而
  • 固定阈值threshold Expected cv::UMat for argument 'mat'

    出错的原因是左边少了一个变量名 你的写法可能是这样 正确的应该是 加上那个变量名 后面用不着 但这里不加会报错 就好了
  • 6-JS的Fetch 跨域问题

    跨域访问 只要协议 主机 端口之一不同 就不同源 例如 http localhost 7070 a 和 https localhost 7070 b 就不同源 同源检查是浏览器的行为 而且只针对 fetch xhr 请求 如果是其它客户端
  • python常见方法汇总

    排序方法 sorted 对列表排序 sorted list 默认升序 对字典排序 def sorted by value dict data reverse True 字典按值降序排序 param dict data dict数据 reve
  • mysql error 1093(HY000) You can‘t specify target table ‘xx‘ for update in FROM clause

    错误代码 update sc set grade grade 1 1 where sno in select sno from sc group by sno having avg grade gt 75 报错详情 You can t sp
  • element UI的使用方法

    1 找官网 http element eleme io zh CN component quickstart 2 安装 cnpm i element ui S S表示 save 3 引入element UI的css 和 插件 import
  • MongoDB连接超时

    在java连接MongoDB时出现了如下连接超时的错误 解决如下 在MongoDB的配置文件中添加了bind ip 0 0 0 0表示任意地址都可以访问
  • WIFI探针原理

    WIFI 探针原理 WIFI 是基于IEEE802 11a b g n 协议 在标准协议中 定义了AP 无线接入点 和STA 站或客户端 的两种工作模式 协议中规定了BEACON ACK DATA PROBE 等多种无线数据帧类型 在站连接
  • Angular反向代理实现前端跨域

    angular2 提供了反向代理可以直接在前端代码中就可以实现跨域 具体的方法如下 在angular项目根目录新建了个proxy conf json配置文件 代码示例如下 api 将http localhost 4200 api通过代理实际
  • Failed to read artifact descriptor for

    使用idea建立的maven项目 pom文件报错 Failed to read artifact descriptor for org slf4j jcl over slf4j jar 1 7 22 less Ctrl F1 Inspect
  • 计量经济学学习与Stata应用笔记(二)小样本最小二乘法

    最小二乘法 OLS 是最基本的线性回归模型估计方法 小样本OLS 古典线性回归模型假定 古典线性回归模型有以下几个假定 线性假定 总体模型为 y i 1
  • excel函数把a列相同的数据所对应的b列整合到同一行

    把A列复制到C列 并删除重复值 然后再D列第一行使用如下函数 函数 TEXTJOIN TRUE IF A A C1 B B 写入函数之后 按Ctrl shift enter键
  • 学习笔记:yolo识别图片

    版权声明 本文为博主原创文章 未经博主允许不得转载 作用说明 我是菜鸟 这学习笔记 主要用于自我记录 YOLO 官方https pjreddie com darknet yolo 最新版本是YOLOv2 在使用前 要先安装Darknet 通
  • Java Math的 floor,round和ceil的总结

    floor 返回不大于的最大整数 round 则是4舍5入的计算 入的时候是到大于它的整数 round方法 它表示 四舍五入 算法为Math floor x 0 5 即将原来的数字加上0 5后再向下取整 所以 Math round 11 5
  • linux——Firewalld与iptables的基本配置

    Firewalld Firewalld概述 动态防火墙后台程序 firewalld 提供了一个动态管理的防火墙 用以支持网络 zones 以分配对一个网络及其相关链接和界面一定程度的信任 它具备对 IP v4 和 IP v6 防火墙设置的支
  • HIVE取整和取余

    1 四舍五入 round select round 47 54452 round保留l两位小数 45 54 2 向下取整 floor select floro 47 54452 48 3 向上取整 ceiling select ceilin
  • 【深度学习】1-权重参数全相同值初始化,导致无法训练

    前言 活动地址 CSDN21天学习挑战赛 博主主页 清风莫追 今天学到了多层感知机的softmax回归 在调整超参数观察它对于实验结果的影响时 突然发现我遇到了一个问题 在超参数不变的情况下 多次模型训练的结果也可能是不同的 这种不同并不是
  • JavaScript 生成流程图

    插件地址 dagre d3 引用的资源 d3 v3 min js http d3js org d3 v3 min js dagre d3 min js http cpettitt github io project dagre d3 v0
  • 创建Web项目时,Maven更新失败,Cannot resolve plugin org.apache.maven.plugins:maven-surefire-plugin:2.22.2

    创建Web项目时 Maven更新失败 Cannot resolve plugin org apache maven plugins maven surefire plugin 2 22 2 错误图片 这个问题是由于本地仓库和idea自带仓库
  • 用MATLAB和内点法实现带有时变不等式约束的分布式优化

    文章目录 问题描述 内点法 MATLAB实现 仿真结果 源代码 问题描述 考虑代价函数 f i x i