• Validate the problem structure by running it: [x,fval] = fminunc(problem) x = 8.4420 -110.2602 fval = 435.2573 Create a MultiStart object, and set the object to use parallel processing and iterative ...

Write a function file to compute the objective:
function f = sawtoothxy(x,y)
[t r] = cart2pol(x,y); % change to polar coordinates
h = cos(2*t - 1/2)/2 + cos(t) + 2;
g = (sin(r) - sin(2*r)/2 + sin(3*r)/3 - sin(4*r)/4 + 4) ...
.*r.^2./(r+1);
f = g.*h;
end
Create the problem structure:
problem = createOptimProblem('fminunc',...
'objective',@(x)sawtoothxy(x(1),x(2)),...
'x0',[100,-50],'options',...
optimoptions(@fminunc,'Algorithm','quasi-newton'));
Validate the problem structure by running it:
[x,fval] = fminunc(problem)
x =
8.4420 -110.2602
fval =
435.2573
Create a MultiStart object, and set the
object to use parallel processing and iterative display:
ms = MultiStart('UseParallel',true,'Display','iter');
Set up parallel processing:
parpool
Starting parpool using the 'local' profile ... connected to 4 workers.
ans =
Pool with properties:
Connected: true
NumWorkers: 4
Cluster: local
AttachedFiles: {}
IdleTimeout: 30 minute(s) (30 minutes remaining)
SpmdEnabled: true
Run the problem on 50 start points:
[x,fval,eflag,output,manymins] = run(ms,problem,50);
Running the local solvers in parallel.
Run Local Local Local Local First-order
Index exitflag f(x) # iter F-count optimality
17 2 3953 4 21 0.1626
16 0 1331 45 201 65.02
34 0 7271 54 201 520.9
33 2 8249 4 18 2.968
... Many iterations omitted ...
47 2 2740 5 21 0.0422
35 0 8501 48 201 424.8
50 0 1225 40 201 21.89
MultiStart completed some of the runs from the start points.
17 out of 50 local solver runs converged with a positive
local solver exit flag.
Notice that the run indexes look random. Parallel MultiStart runs
its start points in an unpredictable order.
Notice that MultiStart confirms parallel processing
in the first line of output, which states: “Running the local
solvers in parallel.”
When finished, shut down the parallel environment:
delete(gcp)
Parallel pool using the 'local' profile is shutting down.

展开全文
• 下面是我用fmincon，globalsearch和multistart分别的结果： GetS.m: function S = GetS(data) % 待优化函数 % 输出S 为待优化的面积 z(x)与x轴围成的面积 r1 = data(1);r2 = data(2);l1 = data(3);l2 = data(4); ...

本帖最后由 wwwjjj7008 于 2018-3-21 10:24 编辑
问题描述：从四个参数的给定范围r1[200 300]、r2[50 100]、l1[150 200]、l2[150 250]中，任取一组数，代入：
h = sqrt(l2*l2-(3*r1/2-3*l1*cos(t)/2-90.9).^2 -(3^0.5*r1/2-3^0.5*l1*cos(t)/2-119.1).^2);
x = 0.39*r1-0.16*r2-0.39*l1*cos(t)-0.54*h+8.24 ;
z = 1.39*r1 - 1.16*r2 - 1.39 * l1 * cos(t) + l1*sin(t) +0.46*h+14.41;
其中t的变化范围是：50*pi/180~57*pi/180
得到xz曲线，求曲线关于坐标轴所围成面积最大时的那组参数，并输出面积和最大时的图像。
下面是我用fmincon，globalsearch和multistart分别的结果：
GetS.m:
function S = GetS(data)
% 待优化函数
% 输出S 为待优化的面积 z(x)与x轴围成的面积
r1 = data(1);r2 = data(2);l1 = data(3);l2 = data(4);
syms t;
h = sqrt(l2*l2-(3*r1/2-3*l1*cos(t)/2-90.9).^2 -(3^0.5*r1/2-3^0.5*l1*cos(t)/2-119.1).^2);
x = 0.39*r1-0.16*r2-0.39*l1*cos(t)-0.54*h+8.24 ;
z = 1.39*r1 - 1.16*r2 - 1.39 * l1 * cos(t) + l1*sin(t) +0.46*h+14.41;
% x(t)的一阶导数
x_ = diff(x);
del = 100;
t = linspace(50*pi/180,57*pi/180,del);
% 将t代入上述表达式中 求解对应的x,z
xda = subs(x);
zda = subs(z);
x_da = subs(x_);
digits(10);
% 将数据格式转化为double
zda = double(vpa(zda));
xda = double(vpa(xda));
x_da = double(vpa(x_da));
% 忽略虚数解
zda = zda(abs(imag(zda))<=1e-6);
xda = xda(abs(imag(xda))<=1e-6);
x_da = x_da(abs(imag(x_da))<=1e-6);
% 参数方程的积分方法
deltat = pi/(2*del);
% 积分  原理有附图解释
S = sum(x_da.*zda*deltat);
% 用trapz也可以
% S = trapz(xda,zda);
% 为了优化 取负
S = -S;
end
plotxz.m:
function y = plotxz( data )
% 输入函数data为数组 分别对应 r1 r2 l1 l2
% 函数功能：画函数图像z(x)
% data分别对应r1 r2 l1 l2
r1 = data(1);r2 = data(2);l1 = data(3);l2 = data(4);
% 定义符号变量 t
syms t;
h = sqrt(l2*l2-(3*r1/2-3*l1*cos(t)/2-90.9).^2 -(3^0.5*r1/2-3^0.5*l1*cos(t)/2-119.1).^2);
x = 0.39*r1-0.16*r2-0.39*l1*cos(t)-0.54*h+8.24 ;
z = 1.39*r1 - 1.16*r2 - 1.39 * l1 * cos(t) + l1*sin(t) +0.46*h+14.41;
% t 生成100个50*pi/180~57*pi/180之间的数
t = linspace(50*pi/180,57*pi/180,100);
% 将t代入上述表达式中 求解对应的x,z
xda = subs(x);
zda = subs(z);
% 将数据格式转化为double
zda = double(vpa(zda));
xda = double(vpa(xda));
% 忽略虚数解
zda = zda(abs(imag(zda))<=1e-6);
xda = xda(abs(imag(xda))<=1e-6);
figure
plot(xda,zda)
grid on
y=1;
end
%下面是主函数
% 设置优化约束条件
options.TolCon = 1e-15;
options.TolX = 1e-15;
options.TolFun = 1e-15;
% 设置迭代优化代数：500
options = gaoptimset(options, 'Generations', 500);
%上边界
LB = [200,50,150,150];
% 上边界
UB = [300,100,200,250];
% 优化初始值
x0 = [200,50,180,180];
关键是下面用三种不同的优化主函数，得到的结果不同，而且对初始值非常敏感：
(1)用fmincon优化的主函数
main.m:
options = optimset('LargeScale','off');
% 优化函数 fmincon 待优化函数为 GetS函数
[ANSW,FVAL] = fmincon(@(data)GetS(data),x0,[],[],[],[],LB,UB,[],options);
% 优化结果r1 r2 l1 l2 存放在ANSW数组里面
plotxz( ANSW );
% 优化求解的最大面积
S=-FVAL

结果1.png (13.45 KB, 下载次数: 1)
2018-3-21 10:22 上传

结果2.png (13.25 KB, 下载次数: 1)
2018-3-21 10:22 上传
(2)用globalsearch优化的主函数
main.m:
f = @(data)GetS(data);
problem = createOptimProblem('fmincon','objective',f,'x0',x0,'lb',LB,'ub',UB,'options',optimset('Algorithm','SQP','DISP','none'));
gs = GlobalSearch;
xgs = run(gs,problem);
% 优化结果r1 r2 l1 l2 存放在xgs数组里面
plotxz( xgs );
xgs
S = -GetS(xgs)

结果1.png (7.58 KB, 下载次数: 1)
2018-3-21 10:23 上传

结果2.png (12.35 KB, 下载次数: 1)
2018-3-21 10:23 上传
(3)用multistart优化的主函数
main.m:
f = @(data)GetS(data);
problem = createOptimProblem('fmincon','objective',f,'x0',x0,'lb',LB,'ub',UB,'options',optimset('Algorithm','SQP','DISP','none'));
ms = MultiStart;
tic
xgs_m = run(ms,problem,50);
toc
% 优化结果r1 r2 l1 l2 存放在xgs_m数组里面
plotxz( xgs_m );
xgs_m
S = -GetS(xgs_m)

结果1.png (14.02 KB, 下载次数: 0)
2018-3-21 10:23 上传

结果2.png (11.04 KB, 下载次数: 2)
2018-3-21 09:55 上传
求大神指点迷津，我这到底哪里出错了？理论上globalsearch和multistart的结果应该会比fmincon的结果更优不是吗？

展开全文
• We investigate for the first time a multistart solution-based tabu search algorithm for solving the problem. The proposed algorithm combines a solution-based tabu search procedure with a multistart ...
The NP-hard Set-Union Knapsack Problem is a general model able to formulate a number of practical problems. As a variant of the popular knapsack problem, SUKP is to find a subset of candidate items (an item is composed of several distinct weighted elements) such that a profit function is maximized while a knapsack capacity constraint is satisfied. We investigate for the first time a multistart solution-based tabu search algorithm for solving the problem. The proposed algorithm combines a solution-based tabu search procedure with a multistart strategy to ensure an effective examination of candidate solutions. We report computational results on 60 benchmark instances from the literature, including new best results (improved lower bounds) for 7 large instances. We show additional experiments to shed lights on the roles of the key composing ingredients of the algorithm. The code of the algorithm will be publicly available.
展开全文
• MultiStart 求多个局部极小值 举例 rng default % For reproducibility opts = optimoptions(@fmincon,'Algorithm','active-set'); problem = createOptimProblem('fmincon','objective',... @goalfun,'x0',eta0,'...
https://ww2.mathworks.cn/help/optim/ug/fmincon.html 参考文档

举例：
//
OPTIONS = optimoptions('fmincon','Algorithm','sqp','FunctionTolerance ',1e-15,'StepTolerance ',1e-15);
[eta,fval,exitflag] = fmincon(@goalfun,eta0,A,b,[],[],[],[],[],OPTIONS);

exitflag 参考下面：   GlobalSearch 创建一个具有多个局部极小值的优化问题，并尝试使用GlobalSearch查找全局极小值。
举例
rng default % active-set
gs = GlobalSearch;
opts = optimoptions(@fmincon,'Algorithm','active-set');
problem = createOptimProblem('fmincon','x0',eta0,...
'objective',@goalfun,'Aineq',A,'bineq',b, 'options',opts);
[eta,fval,exitflag] = run(gs,problem);

MultiStart 求多个局部极小值 举例
rng default % For reproducibility
opts = optimoptions(@fmincon,'Algorithm','active-set');
problem = createOptimProblem('fmincon','objective',...
@goalfun,'x0',eta0,'Aineq',A,'bineq',b,'options',opts);
ms = MultiStart;
[eta,fval] = run(ms,problem,30);

展开全文
• mysqld_multi stop 命令必须凭借有效的 user & password 配置去管理相应的实例如果无法使用 stop 命令关闭实例，可以通过一下步骤排查解决1、在设置了实例的帐号密码后，可以检查下 mysqld_multi 的配置参数 在 ...
• 今天看了看MySQL的Manual，看到了这个mysqld_multi，对这个有点兴趣，所有就翻译了一下。水平有限，只要能看懂就好啦~~~~:)mysqld_multi是管理多个mysqld的服务进程，这些服务进程程式不同的unix socket或是监听于...
• 因为连接数的问题，我不得不在一台机器上多启 mysql instance 1. 建立两个 mysql 数据库... 启动 mysqld_multi start 1 & mysqld_multi start 2 & posted on 2011-07-12 15:59 哈哈的日子 阅读(462) 评论(0) 编辑 收藏
• django-celery的执行命令 celery -A celery_test worker -l info 后台运行的命令（celery——tasks为项目名称） celery multi start w1 -A celery_tasks -l info
• 还可以使用mysqld_multi方式。mysqld_multi是mysql设计的专门用来管理不同端口，不同socket的mysql实例的工具。它可以同时启动，停止多个mysql实例，也可以查看这些实例的状态。mysqld_multi会去配置文件my.cnf(或者...
• (注，若为加入该条语句，可能在使用service mysqldm start 命令时，也会报如上错误).这个问题纠结了我三天。无语中... 另外，还不知如上几个错误，大部分错误是以为我没有将mysql安装在/usr/local目录下面，之前一直...
• 利用mysqld_multi启动管理多实例官方管理多实例的一个脚本peer#将之前的目录清空[root@mysql01 mysql]# tree /data/mysql//data/mysql/├──mysql_3306│├──data│├──logs│├──my3306.cnf│└──tmp├─...
• 运行mysqld_multi # 启动 /usr/local/mysql/bin/mysqld_multi start # 停止 /usr/local/mysql/bin/mysqld_multi stop # 查询状态 /usr/local/mysql/bin/mysqld_multi report Mysql数据库介绍、安装和配置文件 Mysql...
• multi查看实例状态9、访问多实例数据库1、登录MySQL数据库2、修改数据库root@localhost密码10、关闭多实例数据库1/1、启动关闭实例命令总结 前言 如果手头没有过多的服务器，但是又想安装多个my
• 单机多实例可以有效的最大化服务器的利用率，mysql 多实例的实现方式也有两种：独立配置文件：每个实例有自己单独的配置文件mysqld_multi单一配置文件统一管理：实例在单一配置文件中统一配置管理这里我们使用mysqld...
• 停止所有服务 mysqld_multi stop 其他命令 mysqld_multi start 3306 # 启动单个服务 mysqld_multi report 3306 # 查看单个服务状态 mysqld_multi stop 3306 # 停止单个服务 2.1.8 登录服务 方式一 通过指定 ip 和...
• 当一台机器上需要运行多个MySQL服务器时，mysqld_multi是一个非常棒的工具，通过简单的命令，它可以启动，关闭和报告所管理的服务器的状态。下面的配置文件非常简洁，仅仅是为了测试用，所以实验前将原来的"my.cnf...
• 一、前言：在Mysql中有一mysqld_multi命令，可用于在一台物理服务器运行多个Mysql服务，今天参考一些文档，亲自测试并通过，现将操作过程共享给大家!操作系统: Redhat Enterprise AS 3，其它版的Linux应该也差不多....
• 因使用源码安装的MySQL5.7.28多实例，在导入数据库时会出现问题，所以重新研究使用mysql_multi的方法来管理多实例，经过测试环境验证之后，在各方面使用上特别在备份还原上，没有报MySQL5.7.28多实例的问题，踩了...
• 1.确保mysql软件已经安装在/mysql目录下(root用户操作)2.修改环境变量(root用户操作)修改/etc/profile文件，在文件末尾添加PATH=/mysql/bin:\$PATH...修改my.cnf文件(root用户操作)[mysqld_multi]mysqld = /mysql/...
• # mysqld_multi start # mysqld_multi --defaults-extra-file=/etc/my.cnf report Reporting MySQL servers MySQL server from group: mysqld3306 is running MySQL server from group: mysqld3307 is running 12....
• mysqld_multi 的使用方法:官方文档：https://dev.mysql.com/doc/refman/5.7/en/mysqld-multi.html 【文档有些问题，按照它的这个配置，mysqld_multi无法关闭实例】mysqld_multi无法关闭实例的解决方法：...
• /usr/bin/mysqladmin user = multi_admin password = multipass You can use mysqld_multi to start, stop, restart or report the status of a particular instance, all instances or a subset of them....
• 本文讲利用MySQL源码安装MySQL并用mysqld_multi配置多实例。1、下载MySQL源码安装版本到MySQL官网查找到相应版本下载，本文下载的是5.1版本Java代码wget-cftp://ftp.mirrorservice.org/sites/ftp.mysql....