matchWall.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import utils.conf
  2. import utils.getarray
  3. # 判断能否摆下组件的贴墙边
  4. from utils import getarray
  5. # 判断当前边能否放下指定模块
  6. def canMatch(wallLength, moduleLengths):
  7. moduleTotalLength = 0;
  8. for item in moduleLengths:
  9. moduleTotalLength = moduleTotalLength + item
  10. return (moduleTotalLength <= wallLength)
  11. # matchResult = canMatch(3,(1,1,2))
  12. # print(matchResult)
  13. # 获取当前位置的所有摆法
  14. def matchWalls(roomLengths, moduleLengths):
  15. m = len(roomLengths)
  16. n = len(moduleLengths)
  17. a = getarray.getAllPosition(m, n)
  18. canMatchTop = canMatch(roomLengths[2], moduleLengths)
  19. if(canMatchTop):
  20. print("begin to calc top")
  21. matchTopWall(roomLengths[2],moduleLengths)
  22. else:
  23. for item in a:
  24. matchWall(roomLengths,moduleLengths,a[item])
  25. # 获取单边墙的模块摆放顺序
  26. def changeModuleIndex(wallModules, param):
  27. newIndexModules = []
  28. print("before changeModuleIndex:",wallModules)
  29. for index in range(len(param)):
  30. newIndexModules.append(wallModules[param[index]-1])
  31. print("after changeModuleIndex:",newIndexModules)
  32. # 摆放带顺序的单边墙
  33. def matchSingleWallWithIndex(wallLength, wallModules):
  34. for item in wallModules:
  35. pass
  36. # 摆放单边墙
  37. def matchSingleWall(wallLength, wallModules,wallIndex):
  38. print("wallLength",wallLength)
  39. print("wallModules",wallModules)
  40. print("wallIndex",wallIndex)
  41. if(canMatch(wallLength,wallModules)):
  42. a = getarray.jiechenarray(len(wallModules))
  43. for item in a:
  44. changeModuleIndex(wallModules,a[item])
  45. matchSingleWallWithIndex(wallLength, wallModules)
  46. else:
  47. print("this array not match")
  48. # 摆放所有墙
  49. def matchWall(roomLengths, moduleLengths, positions):
  50. m = len(roomLengths)
  51. n = len(moduleLengths)
  52. a = getarray.getitemIndexAndPositionArray(positions,m,n)
  53. for item in a:
  54. if(a[item][0] == 1):
  55. position = a[item][1][0]
  56. wallModules = {};
  57. wallModules[0] = moduleLengths[position]
  58. matchSingleWall(roomLengths[position],wallModules,position)
  59. if(a[item][0] > 1):
  60. wallModules = {};
  61. for modulePosition in a[item][1]:
  62. moduleIndex = a[item][1][modulePosition]
  63. wallModules[modulePosition] = moduleLengths[moduleIndex]
  64. matchSingleWall(roomLengths[item],wallModules,a[item][1][0])
  65. pass
  66. #一字摆法
  67. def matchTopWall(roomLengths,moduleLengths):
  68. matchSingleWall(roomLengths, moduleLengths, "012")
  69. matchWalls([1,2,3,4],[1,2,1])
  70. # changeModuleIndex([100,200,313],[2,1,3])