程序碎片- 生产线动态规划(循环)

这是最简单的两条生产线的情况,

算出从每个工作站出厂的最小时间。

package zboDo;

 

public class ManufactoryLineOPT {

    double [][] ToStationCost = new double [2][4];;

    double [][] InStationCost = new double [2][4];;

    double [][] OptMatrix = new double [2][4];

 

    public ManufactoryLineOPT() {

       double [] line1 = { 2, 2, 3, 1 };

       double [] line2 = { 3, 3, 4, 5 };

       ToStationCost [0] = line1;

       ToStationCost [1] = line2;

       double [] Inline1 = { 5, 5, 7, 10 };

       double [] Inline2 = { 4, 6, 9, 4 };

       InStationCost [0] = Inline1;

       InStationCost [1] = Inline2;

       for ( int i = 0; i < 2; i++)

           for ( int j = 0; j < 4; j++) {

              OptMatrix [i][j] = Integer. MAX_VALUE ;

           }

       OptMatrix [0][0] = ToStationCost [0][0] + InStationCost [0][0];

       OptMatrix [1][0] = ToStationCost [1][0] + InStationCost [1][0];

    }

 

    public void test() {

       BuildUpOptMatrix();

       System. out .print( OptMatrix [0][3] < OptMatrix [1][3] ? OptMatrix [0][3]

              : OptMatrix [1][3]);

    }

 

    private void BuildUpOptMatrix() {

       for ( int stationNumber = 1; stationNumber < 4; stationNumber++) {

           for ( int lineNumber = 0; lineNumber < 2; lineNumber++) {

              double tempMin = Integer. MAX_VALUE ;

              for ( int fromlineNumber = 0; fromlineNumber < 2; fromlineNumber++) {

                  double inStationCost = InStationCost [lineNumber][stationNumber];

                  double TransferCost = 0;

                  if (fromlineNumber != lineNumber) {

                     TransferCost = ToStationCost [lineNumber][stationNumber];

                  }

                  double tempTotalCost = inStationCost + TransferCost

                         + OptMatrix [fromlineNumber][stationNumber - 1];

                  if (tempMin > tempTotalCost) {

                     tempMin = tempTotalCost;

                  }

              }

              OptMatrix [lineNumber][stationNumber] = tempMin;

 

           }

       }

 

    }

 

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值