BestResult.groovy 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. class BestResult {
  2. CutConfigEx configEx
  3. int bestCount = 0
  4. double PaperUtilizationE = 0
  5. static Map calcEx(List<CutConfigEx> cutConfigExList, String size, int calcType) {
  6. int inputLength = Integer.valueOf(size.split("\\*")[0])
  7. int inputWidth = Integer.valueOf(size.split("\\*")[1])
  8. //当 opType = 0 , 只用 0 和1 去找, 当他 = 1, 用全部
  9. //传入一个尺寸,然后用传入的尺寸 使用上面的 cutConfigExList 里的 X 和Y 计算出来一个开数(长 宽相除 向下取整,)每一个都计算一边,然后
  10. // 然后把使用率最高的那个 cutConfigExList 中 cutTypex 和 cutCountx 的值返回给我。,
  11. BestResult bestResult = new BestResult()
  12. cutConfigExList.each {
  13. if (calcType == 0 || calcType == 1) {
  14. if (calcType != it.cutTypex) return
  15. }
  16. int xCount1 = (int) Math.floor(it.cutSizeX / inputLength)
  17. int yCount1 = (int) Math.floor(it.cutSizeY / inputWidth)
  18. int total1 = xCount1 * yCount1
  19. int xCount2 = (int) Math.floor(it.cutSizeY / inputLength)
  20. int yCount2 = (int) Math.floor(it.cutSizeX / inputWidth)
  21. int total2 = xCount2 * yCount2
  22. int currentTotal = total1 > total2 ? total1 : total2
  23. //计算拼版面积
  24. double CountS = currentTotal * inputLength * inputWidth
  25. //计算纸张利用率
  26. double PaperUtilization = CountS / (it.cutSizeX * it.cutSizeY)
  27. //以上循环计算出来纸张利用率,然后取 纸张利用率最大的那一次的 Cut.cutTypex ConfigEx和CutConfigEx.cutCountx * currentTotal 的结果返回给我
  28. if (bestResult.PaperUtilizationE < PaperUtilization) {
  29. bestResult.PaperUtilizationE = PaperUtilization
  30. bestResult.bestCount = currentTotal
  31. bestResult.configEx = it
  32. }
  33. }
  34. Map<String, Integer> map1 = new HashMap<>()
  35. int cutTypeS = 0;
  36. int cutCountS = 0;
  37. int cutSizeX = 0
  38. int cutSizeY = 0
  39. if(bestResult.configEx) {
  40. cutTypeS = bestResult.configEx.cutTypex
  41. cutCountS = bestResult.configEx.cutCountx * bestResult.bestCount
  42. cutSizeX = bestResult.configEx.cutSizeX
  43. cutSizeY = bestResult.configEx.cutSizeY
  44. }
  45. int bestCountS = bestResult.bestCount
  46. map1.put("cutTypeS", cutTypeS)
  47. map1.put("cutCountS", cutCountS)
  48. map1.put("bestCountS", bestCountS)
  49. map1.put("cutSizeX",cutSizeX)
  50. map1.put("cutSizeY",cutSizeY)
  51. return map1
  52. }
  53. }