用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和内点法实现带有时变不等式约束的分布式优化 的相关文章

  • 是否有一个函数可以检查矩阵是否对角占优(行占优)

    矩阵是对角占优 http en wikipedia org wiki Diagonally dominant matrix 按行 如果对角线处的值在绝对意义上大于该行中所有其他绝对值的总和 对于列也是如此 只是相反 matlab中有没有函数
  • 在 Matlab 中显示有理数

    我有两个整数 m n 它们一起形成 m n 形式的有理数 现在我只想以这种理性的形式在 Matlab 中显示它们 我可以通过这样做来做到这一点 char sym m n 所以 如果 例如m 1 n 2 Matlab将显示1 2 然而 如果m
  • 频域和空间域的汉明滤波器

    我想通过在 MATLAB 中应用汉明滤波器来消除一维信号中的吉布斯伪影 我所拥有的是k1这是频域中的信号 我可以通过应用 DFT 来获取时域信号k1 s1 ifft ifftshift k1 该信号具有吉布斯伪影 现在 我想通过 A 乘以汉
  • 如何加载具有可变文件名的 .mat 文件?

    select all mat files oar dir oar mat n oar name loop through files for l 1 length oar load pat oar l lt this is the mat
  • 从 Java 运行 MATLAB 函数

    我在 MATLAB 中有一个 m 文件 我想从 Java 调用该文件 并以字符串或 Java 中的任何形式获取解决方案 这听起来很简单 但由于某种原因我无法让它发挥作用 我试过这个 matlab nosplash wait nodeskto
  • 在Matlab中选择图像上的像素时,索引指的是什么?

    当在Matlab中查看图像的单个像素时 该索引指的是什么 X Y 指的是像素的坐标 RGB 指的是颜色 但是关于索引是什么有什么想法吗 为了澄清一下 当我在 Matlab 中查看图形并使用数据光标选择一个点时 显示的三行是 X Y 指数 R
  • Matlab颜色检测

    我试图一致地检测同一场景的图像之间的某种颜色 这个想法是根据颜色配置文件识别一组对象 因此 例如 如果给我一个带有绿色球的场景 并且我选择绿色作为我的调色板的一部分 我想要一个具有反映它检测到球的矩阵的函数 任何人都可以为这个项目推荐一些
  • 如何为已编译的 MATLAB 创建安装程序并要求用户接受我们的许可条款?

    我正在 MATLAB 中编写程序分发给 Windows 用户 我使用 MATLAB 编译器和 MATLAB r2014a 版本来创建程序 我可以使用 MATLAB 应用程序编译器创建 Windows 安装程序 并且它的工作效果可以接受 但是
  • 在Matlab中对字符进行分组并形成矩阵

    我有 26 个字符 A 到 Z 我将 4 个字符组合在一起 并用空格分隔以下 4 个字符 如下所示 abcd efgh ijkl mnop qrst uvwx yz 我的Matlab编码如下 str abcdefghijklmnopqrst
  • 如何在向量中的所有点之间绘制线?

    我有一个包含二维空间中一些点的向量 我希望 MATLAB 用从每个点到每个其他点绘制的线来绘制这些点 基本上 我想要一个所有顶点都连接的图 你能用情节来做到这一点吗 如果可以 怎么做 一种解决方案是使用该函数为每个点组合创建一组索引MESH
  • 在 matlab 代码中使用 dll 文件

    我需要使用 Matlab 中由 dll 文件定义的函数 我有一个例子 那个家伙将 dll 转换为 mexw32 文件 但我知道我是如何做到这一点的 我尝试使用加载库但它没有创建任何文件 我怎样才能做到这一点 loadlibrary http
  • Matlab 一个图上有多个图例 2014b

    我想在一个地块上有多个传说 该解决方案在 2014b 版本之前完美运行 我试图弄清楚如何使用手柄优雅地制作它 但到目前为止还没有成功 欢迎任何想法 2013b 的示例 x 1 50 y1 sin x 2 y2 cos x 2 f figur
  • 从 MATLAB 调用 Java?

    我想要Matlab程序调用java文件 最好有一个例子 需要考虑三种情况 Java 内置库 也就是说 任何描述的here http docs oracle com javase 6 docs api 这些项目可以直接调用 例如 map ja
  • 在 MATLAB 中模拟 C++ 模板

    我试图找出创建 C 模板或 Java 通用对象的替代方案的最佳方法 出于多种不同的原因 我过去曾多次想这样做 但现在我想做的是为几个相关的类创建 saveobj 和 loadobj 函数 我的想法是 我想要一组通用的例程来创建默认结构 然后
  • 命令 A(~A) 在 matlab 中的真正作用是什么

    我一直在寻找找到矩阵非零最小值的最有效方法 并在论坛上找到了这个 设数据为矩阵A A A nan minNonZero min A 这是非常短且高效的 至少在代码行数方面 但我不明白当我们这样做时会发生什么 我找不到任何关于此的文档 因为它
  • 在matlab中,如何读取python pickle文件?

    在 python 中 我生成了一个 p 数据文件 pickle dump allData open myallData p wb 现在我想在Matlab中读取myallData p 我的Matlab安装在Windows 8下 其中没有Pyt
  • 获取向量幂的有效方法

    我编写了一个代码 在数值上使用勒让德多项式直至某个高 n 阶 例如 case 8 p 6435 x 8 12012 x 6 6930 x 4 1260 x 2 35 128 return case 9 如果向量x太长这会变得很慢 我发现说之
  • MATLAB 除法...29/128 应该返回 0 吗?

    我真的不认为这是一个精度问题 答案应该是0 226左右 这是确切的代码 val I i j bucketSize pos val bucketSize I只是我从中获取值的矩阵 以下是 MATLAB 的输出 val 29 bucketSiz
  • MATLAB - 通过垂直连接子矩阵重新排列矩阵

    我在执行以下任务时遇到问题 假设一个 3x6 矩阵 A 0 2787 0 2948 0 4635 0 8388 0 0627 0 0435 0 6917 0 1185 0 3660 0 1867 0 2383 0 7577 0 6179 0
  • 在 Matlab 中保存 Kinect 深度图像?

    通过使用 Kinect 我可以获得深度图像 其中每个深度图像像素存储相机和物体之间的距离 以毫米为单位 现在我想保存它们以便以后使用 最好的推荐是什么 我正在考虑将深度图像保存为图像 jpg png等 然而 该值通常是从50毫米到10000

随机推荐

  • 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