LayerPackingConstraints.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace wms.service.Help.LayerPacking.model
  4. {
  5. /// <summary>
  6. /// 层配装箱约束条件
  7. /// </summary>
  8. public class LayerPackingConstraints
  9. {
  10. /// <summary>
  11. /// 产品目标值
  12. /// </summary>
  13. public decimal P { get; set; }
  14. /// <summary>
  15. /// 产品偏差范围
  16. /// </summary>
  17. public decimal P1 { get; set; }
  18. /// <summary>
  19. /// 激进搜索策略中箱扭转目标值偏差范围放宽比例
  20. /// </summary>
  21. public decimal BR { get; set; } = 1m;
  22. /// <summary>
  23. /// 激进搜索策略中层扭转目标值偏差范围放宽比例
  24. /// </summary>
  25. public decimal LR { get; set; } = 1m;
  26. /// <summary>
  27. /// 箱总扭转目标值
  28. /// </summary>
  29. private decimal? _x;
  30. /// <summary>
  31. /// 层总扭转目标值
  32. /// </summary>
  33. private decimal? _c;
  34. /// <summary>
  35. /// 箱总产品数
  36. /// </summary>
  37. private int _productsPerBox;
  38. /// <summary>
  39. /// 箱总产品数
  40. /// </summary>
  41. public int ProductsPerBox
  42. {
  43. get => _productsPerBox;
  44. set
  45. {
  46. _productsPerBox = value;
  47. // 重新计算相关值
  48. _x = null;
  49. _c = null;
  50. }
  51. }
  52. /// <summary>
  53. /// 层总产品数
  54. /// </summary>
  55. private const int PRODUCTS_PER_LAYER = 12;
  56. /// <summary>
  57. /// 层总产品数
  58. /// </summary>
  59. public int ProductsPerLayer => PRODUCTS_PER_LAYER;
  60. /// <summary>
  61. /// 箱总层数
  62. /// </summary>
  63. public int LayersPerBox => ProductsPerBox / PRODUCTS_PER_LAYER;
  64. /// <summary>
  65. /// 箱总扭转目标值
  66. /// </summary>
  67. public decimal X
  68. {
  69. get => _x ?? P * ProductsPerBox;
  70. set => _x = value;
  71. }
  72. /// <summary>
  73. /// 箱总扭转目标偏差范围
  74. /// </summary>
  75. public decimal X1 { get; set; }
  76. /// <summary>
  77. /// 层总扭转目标值
  78. /// </summary>
  79. public decimal C
  80. {
  81. get => _c ?? P * PRODUCTS_PER_LAYER;
  82. set => _c = value;
  83. }
  84. /// <summary>
  85. /// 层总扭转目标偏差范围
  86. /// </summary>
  87. public decimal C1 { get; set; }
  88. /// <summary>
  89. /// 最大焊点盘数
  90. /// </summary>
  91. public int SolderMaxCount { get; set; }
  92. /// <summary>
  93. /// 最大焊点数
  94. /// </summary>
  95. public int PerSolderMaxCount { get; set; }
  96. /// <summary>
  97. /// 最小产品扭转目标值
  98. /// </summary>
  99. public decimal MinProductValue => P - P1;
  100. /// <summary>
  101. /// 最大产品扭转目标值
  102. /// </summary>
  103. public decimal MaxProductValue => P + P1;
  104. /// <summary>
  105. /// 是产品最小扭转目标值
  106. /// </summary>
  107. public bool IsAtMinTarget { get; private set; }
  108. /// <summary>
  109. /// 是产品最大扭转目标值
  110. /// </summary>
  111. public bool IsAtMaxTarget { get; private set; }
  112. /// <summary>
  113. /// 最小箱总目标值
  114. /// </summary>
  115. public decimal MinBoxTotal
  116. {
  117. get
  118. {
  119. if (X == P - P1 * ProductsPerBox)
  120. return X;
  121. if (X == P + P1 * ProductsPerBox)
  122. return X - X1;
  123. return X - X1;
  124. }
  125. }
  126. /// <summary>
  127. /// 最大箱总目标值
  128. /// </summary>
  129. public decimal MaxBoxTotal
  130. {
  131. get
  132. {
  133. if (X == P + P1 * ProductsPerBox)
  134. return X;
  135. if (X == P - P1 * ProductsPerBox)
  136. return X + X1;
  137. return X + X1;
  138. }
  139. }
  140. /// <summary>
  141. /// 最小层总目标值
  142. /// </summary>
  143. public decimal MinLayerTotal
  144. {
  145. get
  146. {
  147. if (C == P - P1 * PRODUCTS_PER_LAYER)
  148. return C;
  149. if (C == P + P1 * PRODUCTS_PER_LAYER)
  150. return C - C1;
  151. return C - C1;
  152. }
  153. }
  154. /// <summary>
  155. /// 最大层总目标值
  156. /// </summary>
  157. public decimal MaxLayerTotal
  158. {
  159. get
  160. {
  161. if (C == P + P1 * PRODUCTS_PER_LAYER)
  162. return C;
  163. if (C == P - P1 * PRODUCTS_PER_LAYER)
  164. return C + C1;
  165. return C + C1;
  166. }
  167. }
  168. /// <summary>
  169. /// 更新箱层目标值
  170. /// </summary>
  171. /// <param name="products"></param>
  172. public void UpdateTargetValues(List<LayerPackingProduct> products)
  173. {
  174. if (products == null || !products.Any()) return;
  175. decimal avgValue = products.Average(p => p.TorsChkValue);
  176. decimal effectiveProductTarget; // 有效产品目标值 --计算箱层目标值时使用的产品目标值
  177. if (avgValue <= MinProductValue)
  178. {
  179. effectiveProductTarget = MinProductValue;
  180. IsAtMinTarget = true;
  181. IsAtMaxTarget = false;
  182. }
  183. else if (avgValue >= MaxProductValue)
  184. {
  185. effectiveProductTarget = MaxProductValue;
  186. IsAtMinTarget = false;
  187. IsAtMaxTarget = true;
  188. }
  189. else
  190. {
  191. effectiveProductTarget = avgValue;
  192. IsAtMinTarget = false;
  193. IsAtMaxTarget = false;
  194. }
  195. _x = effectiveProductTarget * ProductsPerBox;
  196. _c = effectiveProductTarget * PRODUCTS_PER_LAYER;
  197. X1 = P1 * ProductsPerBox;
  198. C1 = P1 * PRODUCTS_PER_LAYER;
  199. }
  200. /// <summary>
  201. /// 获取焊点在装箱中的约束方案
  202. /// </summary>
  203. /// <returns></returns>
  204. public SolderConstraintType GetSolderConstraintType()
  205. {
  206. if (SolderMaxCount <= 0) return SolderConstraintType.NoConstraint;
  207. else if (PerSolderMaxCount <= 0) return SolderConstraintType.OnlyProductCount;
  208. else return SolderConstraintType.BothConstraints;
  209. }
  210. }
  211. /// <summary>
  212. /// 焊点约束条件
  213. /// </summary>
  214. public enum SolderConstraintType
  215. {
  216. /// <summary>
  217. /// 无约束条件
  218. /// </summary>
  219. NoConstraint,
  220. /// <summary>
  221. /// 仅产品数
  222. /// </summary>
  223. OnlyProductCount,
  224. /// <summary>
  225. /// 同时满足产品数和焊点数
  226. /// </summary>
  227. BothConstraints
  228. }
  229. }