动态规划设备更新问题

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

动态规划中关于设备更新问题的算法实现#includeiostreamusingnamespacestd;typedefinttype;#defineTRUE1#defineFALSE0#definen5#defineD2//charD='D';typeupdete(typer[][n+2],typem[][n+2],typeu[][n+2],boolp[]){inti,j,k;/typeoptg,rem;type(*f)[n+1]=newtype[n+2][n+1];bool(*x)[n+1]=newbool[n+1][n+1];for(i=1;i=n;i++)f[n+1][i]=0;for(i=n;i0;i--)for(j=1;j=i;j++){if(ij)f[i][j]=r[i][0]-m[i][0]-u[i-j][j]+f[i+1][1];elsef[i][j]=r[i][0]-m[i][0]-u[0][j-1+D]+f[i+1][1];x[i][j]=TRUE;if(ij)rem=r[i-j][j]-m[i-j][j]+f[i+1][j+1];elserem=r[0][j-1+D]-m[0][j-1+D]+f[i+1][j+1];if(f[i][j]rem)f[i][j]=rem;x[i][j]=FALSE;}coutf[i][j]=f[i][j]endl;/}j=1;for(i=1;i=n;i++){p[i]=x[i][j];if(p[i])j=1;elsej=j+1;}optg=f[1][1];deletef;deletex;returnoptg;}voidmain(){typer[n+1][n+2]={{0,0,13,12,11,10,9},{16,15,14,13,12},{17,16,15,14},{18,17,16},{19,18},{20}};typem[n+1][n+2]={{0,0,2,3,4,4,5},{1,1,2,2,3},{1,1,2,2},{1,1,2},{1,1},{1}};typeu[n+1][n+2]={{0,0,25,26,27,28,29},{20,22,24,25,26},{20,22,24,25},{20,22,24},{21,22},{21}};//boolp[n+1];typef=updete(r,m,u,p);/cout最优利润是fendl;for(inti=1;i=n;i++){cout第i年的决策是:;if(p[i])cout更新;elsecout不更新?;coutendl;}system(pause);}

1 / 2
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功