我正在考虑购买Matlab +优化模块供家庭使用,但我不确定它是否能做我想做的事情。
我有一个外部进程(而不是Matlab),它接收输入、运行进程并生成输出。我想把输入和输出绑定到Matlab中,这样Matlab就可以“优化”这些输入,完全无视离散过程本身。Matlab是否具有离散优化功能,还是其所有优化功能都依赖于对流程本身的内部访问?
谢谢!
-Stephen
发布于 2016-03-24 19:05:53
如果您的外部进程能够吸收参数并使用任何方法(例如,命令行或文件)对外部程序进行响应,则可以配置您的目标函数将参数和响应数据发送和读取到外部进程。
对于离散优化,优化工具箱不处理离散优化问题,但文档给出了将参数舍入目标函数,然后在响应变量中再次运行的提示。
例如,这可以是一个函数,用于优化用python编写的外部程序中编码的棱镜的体积(仅用于演示使用单个明显的遗传算法(ga)):
function f = optim(x)
%Optimization criteria
l = round(x(1));
h = round(x(2));
w = round(x(3));
%String to produce the external proccess call as a system command
commandStr = ['python -c "print ' num2str(l) ' * ' num2str(h) ' * ' num2str(w) ' "'];
%Execute the system command, status = 0 for good execution
[status, commandOut] = system(commandStr);
%Convert the output of the external program from strin to doble and assign as the response of the optimization funcition
f = str2double(commandOut)然后,您可以使用这个函数来使用optimtool,如下所示:

然后将结果导出到工作区并对其进行round()。
或者用这样的代码对其进行编程:
function [x,fval] = runOptimization(lb,ub)
options = gaoptimset;
options = gaoptimset(options,'Display', 'off');
[x,fval] =ga(@optim,3,[],[],[],[],lb,ub,[],[],options);
x = round(x)
fval = optim(x)并以
[x,fval] = runOptimization([1 1 1],[3 4 5])注意到。round()函数仅用于演示如何按照文档中的建议进行离散优化。
https://stackoverflow.com/questions/36206468
复制相似问题