ki0073

GLPK equalize

Jul 18th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. set Day; # 日付
  2. set ProductName; # 製品名
  3. set RestrictPlan dimen 2 within Day cross ProductName; # 生産できる日が限定される場合
  4. set RestrictProduct := setof{(d,p) in RestrictPlan}(p);
  5. set AvailableDayProduct := {Day, ProductName diff RestrictProduct} union RestrictPlan; # 製品別の生産可能な日
  6.  
  7. set LotParam := {"lotSize", "workerHour", "minNLot", "maxNLot"};
  8. param productLotParam{ProductName, LotParam};
  9. param totalProductionLot{ProductName} integer;
  10.  
  11. # 設定の出力
  12. printf "期間中のロット総数 総生産数 総工数\n";
  13. for{p in ProductName}{
  14. printf "%s %8d %8d %f\n", p, totalProductionLot[p], totalProductionLot[p]*productLotParam[p,"lotSize"],totalProductionLot[p]*productLotParam[p,"workerHour"];
  15. }
  16. printf "\n";
  17.  
  18. printf (if card(RestrictPlan) >0 then "生産可能日が限定される製品\n" else "");
  19. for{p in RestrictProduct}{
  20. printf "%s ", p;
  21. printf{(d,p) in RestrictPlan} " %s", d;
  22. printf "\n";
  23. }
  24. printf (if card(RestrictPlan) >0 then "\n" else "");
  25.  
  26. var nLotTable{AvailableDayProduct} integer, >=0; # 日別製品別ロット数
  27. var totalWorkerTimeInDay{Day}; # 日別総工数
  28. var binaryForNLot{AvailableDayProduct} binary; # ロット数制限用
  29. var minimumWorkerTimeInDay; # 工数最低日の工数
  30.  
  31. s.t. sumLot{p in ProductName}: sum{d in Day: (d,p) in AvailableDayProduct}nLotTable[d,p]==totalProductionLot[p];
  32. s.t. maxLotNum{(d,p) in AvailableDayProduct}: nLotTable[d,p]<=productLotParam[p, "maxNLot"]*binaryForNLot[d,p];
  33. s.t. minLotNum{(d,p) in AvailableDayProduct}: nLotTable[d,p]>=productLotParam[p, "minNLot"]*binaryForNLot[d,p];
  34. s.t. sumWorkerTime{d in Day}: sum{p in ProductName:(d,p) in AvailableDayProduct}nLotTable[d,p]*productLotParam[p, "workerHour"]==totalWorkerTimeInDay[d];
  35. s.t. minWorkerTimeInDay{d in Day}: totalWorkerTimeInDay[d]>=minimumWorkerTimeInDay;
  36. maximize miniWT: minimumWorkerTimeInDay;
  37.  
  38. solve;
  39. # 結果出力
  40. printf "日ごとの生産数\n";
  41. for{d in Day}{
  42. printf "%s 総工数 %f\n", d, totalWorkerTimeInDay[d];
  43. printf " 製品名 ロット数  生産数  工数\n";
  44. printf{p in ProductName: (d,p) in AvailableDayProduct and nLotTable[d,p]>0} " %s %8d %8d %8.2f\n", p, nLotTable[d,p], nLotTable[d,p]*productLotParam[p,"lotSize"], nLotTable[d,p]*productLotParam[p,"workerHour"];
  45. }
  46.  
  47. data;
  48. # 製品名を列挙
  49. set ProductName := "製品A" "製品B" "製品C" "製品D" "製品E";
  50. # 一日の生産ロット数は0または1日の最低ロット数以上1日の最大ロット数以下になる
  51. # 製品名 1ロットの数量 1ロットの工数 1日の最低ロット数 1日の最大ロット数
  52. param productLotParam : lotSize workerHour minNLot maxNLot:=
  53. "製品A" 50 5.0 2 2
  54. "製品B" 50 5.0 2 2
  55. "製品C" 25 2.5 2 6
  56. "製品D" 25 2.5 2 3
  57. "製品E" 25 2.5 2 3
  58. ;
  59.  
  60. # 日付
  61. set Day:= 715 718 719 720;
  62. # 製品の総生産ロット数
  63. param totalProductionLot :=
  64. "製品A" 6
  65. "製品B" 6
  66. "製品C" 6
  67. "製品D" 12
  68. "製品E" 6
  69. ;
  70. # 生産が限定される製品があれば製品名とその日付
  71. set RestrictPlan :=
  72. # (*, "製品E") 715 718 # 先頭の#を外すと生産日が限定される
  73. ;
  74. end;
Advertisement
Add Comment
Please, Sign In to add comment