您好,欢迎来到意榕旅游网。
搜索
您的当前位置:首页function

function

来源:意榕旅游网


function[xmax,pmax]=knaps(cl,pl,m1)

%[xmax,pmax]=knaps(c1.pl,m1)

%c1 pl are raw vectorg

%ml is the 1imit

%启动定时器

tic;

%保存当前最优解

global xmax;

xmax=zeros(size(c1));

global d;

[d,xi]=sort([c1./pl]

d=1./d;

global c;

c=c1(xi);

global P;

p=pl(xi);

global pmax;

pmax=O;

global m;

m=ml;

t=search(xmax,0);

[temp,i]=sort(xi);

xmax=xmax(i);

%输出结果

disp(['time consuming:'hum2str(toc)'s' 7]);

disp(['maximum price:'num2str(pmax)]);

disp(['total weight:' num2sir(xmax*cl')]);

disp{['indication of goods:'int2str(x=xmax)]);

return

%递归函数

function y=search(x,i)

global c;

global p;

global m;

global d;

global pmax;

global xmax;

%判断结果

if i>0,

temp=x;

temp(i)=1;

dc=m-temp*c';

if dc<0,

if x*p'>pmax,

pmax=x*p';

xmax=x;

y=1;

return

end

y=1;

return

elseif dc*d(i)+x+p'Y=-1;

return;

end

if i==size(C,2),

x(i)=1;

if x*p'>pmax,

pmax=x*p';

xmax=x;

end

Y=1;

return

end

x(i)=1;

end

%新的递归

for

j=i+1:Size(c,2),

w=search(x,j);

if w==1;

break

end

end

y=1;

return

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- yrrf.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务