最近我们小组做了建模训练,选择的题目是21年的国赛C题,我负责软件部分,这题我刚好会做,第一次独自完成了代码,有点激动,和大家分享一下,共同学习,不过因为我个人比较懒,讲解的不怎么多。。。不过会分享一下完整的代码
其实我的代码还有点问题,转运方案没有按照它的要求,当时没注意到这个问题,所以输出的结果和题目给的表格不太一样。
我路子可能比较野,写的代码有点杂乱无章,感觉算小屎堆了(悲)
因为事后没有整理,所以代码会有一些多余的部分,是当时用过后发,之后又不用的。。。
我也是个建模新手,还有很多不足的地方,欢迎大家指出我的错误,一起交流
大家会看到一个Excel,叫‘问题1评分排名.xlsx’,当时鬼迷心窍弄成这样,现在一看实属脱裤子放屁。这个表格大家复制就能用了
供应商ID | 材料成本 | 总供货量 | 订单数 | 达标率 | 评分 | 排名 |
S001 | 1.1 | 49 | 25 | 0.208791 | 6.15234E-05 | 289 |
S002 | 1.2 | 273 | 71 | 0.673684 | 0.000692156 | 105 |
S003 | 1 | 13138 | 191 | 0.854271 | 0.036944482 | 43 |
S004 | 1.1 | 64 | 33 | 0.203883 | 0.000103899 | 245 |
S005 | 1.2 | 6912 | 107 | 0.903509 | 0.019399394 | 54 |
S006 | 1 | 30 | 13 | 0.2 | 1.01257E-05 | 387 |
S007 | 1.2 | 6948 | 240 | 0.866667 | 0.019501409 | 53 |
S008 | 1 | 41 | 15 | 0.25 | 3.79261E-05 | 313 |
S009 | 1.1 | 31 | 19 | 0.15 | 1.51885E-05 | 348 |
S010 | 1.1 | 170 | 32 | 0.227273 | 0.000400748 | 129 |
S011 | 1 | 85 | 32 | 0.651163 | 0.00016209 | 187 |
S012 | 1.2 | 29 | 12 | 0.147059 | 8.21066E-06 | 397 |
S013 | 1 | 44 | 20 | 0.655172 | 4.70146E-05 | 304 |
S014 | 1.2 | 28 | 16 | 0.592593 | 1.05163E-05 | 381 |
S015 | 1.2 | 28 | 15 | 0.277778 | 9.81485E-06 | 388 |
S016 | 1.2 | 37 | 17 | 0.727273 | 2.77322E-05 | 324 |
S017 | 1.2 | 138 | 25 | 0.313433 | 0.000310438 | 153 |
S018 | 1.1 | 66 | 31 | 0.347222 | 0.00010913 | 233 |
S019 | 1.1 | 109 | 12 | 0.155172 | 0.00022839 | 173 |
S020 | 1 | 72 | 33 | 0.235955 | 0.000126006 | 210 |
S021 | 1.2 | 80 | 42 | 0.629032 | 0.000149329 | 195 |
S022 | 1.2 | 140 | 16 | 0.19697 | 0.000315793 | 150 |
S023 | 1 | 1631 | 133 | 0.60625 | 0.00451823 | 59 |
S024 | 1.1 | 124 | 45 | 0.441558 | 0.000272282 | 163 |
S025 | 1 | 375 | 126 | 0.859259 | 0.000981768 | 91 |
S026 | 1.2 | 28 | 14 | 0.823529 | 9.11532E-06 | 392 |
S027 | 1.2 | 81 | 30 | 0.595745 | 0.000150732 | 193 |
S028 | 1.1 | 106 | 19 | 0.346939 | 0.000220167 | 175 |
S029 | 1.1 | 68 | 29 | 0.211111 | 0.000114417 | 228 |
S030 | 1.2 | 162 | 28 | 0.965517 | 0.000378089 | 133 |
S031 | 1.1 | 41207 | 240 | 0.925 | 0.11604338 | 30 |
S032 | 1 | 71 | 30 | 0.390625 | 0.000122868 | 215 |
S033 | 1 | 30 | 17 | 0.842105 | 1.25537E-05 | 364 |
S034 | 1 | 30 | 14 | 0.090909 | 1.07151E-05 | 379 |
S035 | 1.2 | 144 | 55 | 0.42 | 0.000329074 | 145 |
S036 | 1.1 | 124 | 49 | 0.87037 | 0.000272614 | 162 |
S037 | 1 | 50686 | 157 | 0.900621 | 0.142755327 | 25 |
S038 | 1.2 | 36 | 22 | 0.1875 | 2.69251E-05 | 327 |
S039 | 1 | 385 | 45 | 0.634921 | 0.001006506 | 87 |
S040 | 1.1 | 31905 | 240 | 0.904167 | 0.089830187 | 31 |
S041 | 1 | 71 | 28 | 0.322581 | 0.000122644 | 216 |
S042 | 1.2 | 138 | 25 | 0.339286 | 0.000310438 | 152 |
S043 | 1.2 | 39 | 18 | 0.220588 | 3.32102E-05 | 318 |
S044 | 1 | 30 | 14 | 0.764706 | 1.07163E-05 | 377 |
S045 | 1.1 | 31 | 20 | 0.219512 | 1.57757E-05 | 346 |
S046 | 1.2 | 197 | 140 | 0.654088 | 0.000486107 | 119 |
S047 | 1.1 | 66 | 28 | 0.202247 | 0.000108744 | 237 |
S048 | 1.1 | 65 | 26 | 0.44 | 0.000105729 | 243 |
S049 | 1.2 | 38 | 19 | 0.44186 | 3.08765E-05 | 320 |
S050 | 1.1 | 66 | 29 | 0.90625 | 0.000108869 | 235 |
S051 | 1.2 | 29 | 15 | 0.196721 | 1.02113E-05 | 385 |
S052 | 1.2 | 54 | 25 | 0.533333 | 7.51754E-05 | 271 |
S053 | 1.2 | 77 | 31 | 1 | 0.000139675 | 200 |
S054 | 1.1 | 413 | 113 | 0.744186 | 0.001087772 | 70 |
S055 | 1.1 | 24041 | 240 | 0.9 | 0.067669324 | 35 |
S056 | 1.2 | 28 | 17 | 0.295455 | 1.12168E-05 | 375 |
S057 | 1.1 | 50 | 22 | 0.344828 | 6.37202E-05 | 285 |
S058 | 1.1 | 34 | 20 | 0.210526 | 2.15241E-05 | 337 |
S059 | 1 | 47 | 47 | 0.346939 | 6.25025E-05 | 288 |
S060 | 1 | 86 | 10 | 0.36 | 0.000163567 | 186 |
S061 | 1 | 84 | 30 | 0.373134 | 0.000159113 | 189 |
S062 | 1.2 | 75 | 5 | 0.235294 | 0.000132477 | 203 |
S063 | 1 | 30 | 21 | 0.207792 | 1.51106E-05 | 350 |
S064 | 1.2 | 397 | 126 | 0.902985 | 0.001043531 | 80 |
S065 | 1.2 | 189 | 64 | 0.613636 | 0.000455845 | 123 |
S066 | 1.2 | 388 | 132 | 0.851064 | 0.001018631 | 84 |
S067 | 1 | 233 | 169 | 0.988166 | 0.000589569 | 112 |
S068 | 1 | 42 | 16 | 0.15942 | 4.08295E-05 | 309 |
S069 | 1.1 | 169 | 70 | 0.561224 | 0.000400273 | 130 |
S070 | 1 | 46 | 26 | 0.742857 | 5.36666E-05 | 300 |
S071 | 1.2 | 191 | 12 | 0.083333 | 0.000459402 | 122 |
S072 | 1.2 | 28 | 17 | 0.317073 | 1.12168E-05 | 374 |
S073 | 1.1 | 32 | 17 | 0.73913 | 1.59024E-05 | 345 |
S074 | 1 | 13051 | 171 | 0.721311 | 0.03669927 | 44 |
S075 | 1.2 | 390 | 125 | 0.850746 | 0.001023817 | 83 |
S076 | 1 | 376 | 197 | 0.915423 | 0.00099024 | 89 |
S077 | 1.1 | 128 | 12 | 0.172414 | 0.000281908 | 161 |
S078 | 1.2 | 8553 | 101 | 0.794393 | 0.024023726 | 50 |
S079 | 1.1 | 64 | 24 | 0.403846 | 0.000102722 | 248 |
S080 | 1 | 19237 | 240 | 0.875 | 0.054131604 | 37 |
S081 | 1.1 | 49 | 23 | 0.677419 | 6.11551E-05 | 290 |
S082 | 1.2 | 58 | 27 | 0.277778 | 8.64829E-05 | 263 |
S083 | 1.2 | 28 | 14 | 0.375 | 9.11406E-06 | 393 |
S084 | 1 | 70 | 18 | 0.211268 | 0.000118955 | 220 |
S085 | 1 | 46 | 23 | 0.357143 | 5.3017E-05 | 301 |
S086 | 1 | 17949 | 206 | 0.842105 | 0.050501943 | 39 |
S087 | 1.2 | 64 | 27 | 0.657895 | 0.000103073 | 246 |
S088 | 1.1 | 425 | 139 | 0.823529 | 0.001122924 | 64 |
S089 | 1.2 | 141 | 25 | 0.55814 | 0.00031888 | 149 |
S090 | 1 | 145 | 29 | 0.627907 | 0.000330292 | 144 |
S091 | 1.2 | 73 | 29 | 0.519231 | 0.000128321 | 206 |
S092 | 1.1 | 398 | 126 | 0.884615 | 0.001046339 | 77 |
S093 | 1.2 | 36 | 12 | 0.169492 | 2.38267E-05 | 333 |
S094 | 1 | 41 | 24 | 0.411765 | 4.00253E-05 | 311 |
S095 | 1.1 | 32 | 13 | 0.140845 | 1.40651E-05 | 358 |
S096 | 1.2 | 73 | 28 | 0.462963 | 0.000128216 | 208 |
S097 | 1.2 | 63 | 30 | 0.297297 | 0.000100704 | 249 |
S098 | 1.1 | 413 | 206 | 0.92823 | 0.001094404 | 68 |
S099 | 1.2 | 60 | 25 | 0.536585 | 9.17327E-05 | 259 |
S100 | 1 | 42 | 16 | 0.098901 | 4.08295E-05 | 310 |
S101 | 1.2 | 56 | 25 | 0.232877 | 8.06782E-05 | 266 |
S102 | 1.2 | 131 | 50 | 0.5 | 0.000292281 | 158 |
S103 | 1 | 30 | 18 | 0.253968 | 1.31827E-05 | 363 |
S104 | 1.2 | 155 | 25 | 0.263889 | 0.000358284 | 137 |
S105 | 1.1 | 120 | 25 | 0.345455 | 0.000259803 | 167 |
S106 | 1.2 | 77 | 37 | 0.923077 | 0.00014037 | 197 |
S107 | 1 | 69 | 29 | 0.365079 | 0.000117194 | 224 |
S108 | 1.1 | 240950 | 240 | 0.945833 | 0.678923185 | 4 |
S109 | 1.2 | 36 | 19 | 0.321429 | 2.58355E-05 | 328 |
S110 | 1 | 426 | 128 | 0.707792 | 0.001125096 | 63 |
S111 | 1.1 | 31 | 16 | 0.368421 | 1.34925E-05 | 361 |
S112 | 1.1 | 123 | 5 | 0.3125 | 0.000267727 | 165 |
S113 | 1 | 385 | 126 | 0.901515 | 0.001009839 | 86 |
S114 | 1.2 | 10931 | 229 | 0.852814 | 0.030725282 | 45 |
S115 | 1.2 | 398 | 121 | 0.723404 | 0.001046052 | 79 |
S116 | 1.2 | 75 | 23 | 0.594595 | 0.000133342 | 202 |
S117 | 1.1 | 123 | 61 | 0.438776 | 0.000270995 | 164 |
S118 | 1.1 | 66 | 28 | 0.357143 | 0.000108744 | 236 |
S119 | 1.2 | 29 | 9 | 0.170213 | 6.27734E-06 | 401 |
S120 | 1.1 | 33 | 16 | 0.40625 | 1.75815E-05 | 343 |
S121 | 1.2 | 137 | 26 | 0.444444 | 0.000307664 | 154 |
S122 | 1.2 | 73 | 31 | 0.644444 | 0.000128543 | 205 |
S123 | 1.2 | 6449 | 240 | 0.808333 | 0.018095272 | 56 |
S124 | 1.1 | 34 | 14 | 0.4 | 1.92079E-05 | 340 |
S125 | 1.1 | 49 | 16 | 0.186441 | 6.01054E-05 | 292 |
S126 | 1 | 47540 | 91 | 0.84 | 0.133889811 | 27 |
S127 | 1.2 | 158 | 24 | 0.328125 | 0.000366697 | 135 |
S128 | 1.2 | 133 | 51 | 0.661972 | 0.00029796 | 157 |
S129 | 1 | 1525 | 192 | 0.778325 | 0.004220692 | 60 |
S130 | 1.2 | 60 | 28 | 0.197917 | 9.21415E-05 | 258 |
S131 | 1.1 | 137512 | 240 | 0.908333 | 0.387432777 | 11 |
S132 | 1.2 | 63 | 28 | 0.54 | 0.00010043 | 250 |
S133 | 1 | 71 | 26 | 0.766667 | 0.000122436 | 217 |
S134 | 1.1 | 52 | 21 | 0.276923 | 6.90704E-05 | 280 |
S135 | 1 | 87 | 5 | 0.238095 | 0.000166287 | 183 |
S136 | 1 | 42 | 19 | 0.409091 | 4.1421E-05 | 308 |
S137 | 1.1 | 33 | 19 | 0.178571 | 1.89143E-05 | 341 |
S138 | 1.1 | 411 | 142 | 0.761006 | 0.001083814 | 72 |
S139 | 1.1 | 151862 | 222 | 0.96875 | 0.427871368 | 10 |
S140 | 1.1 | 302047 | 219 | 0.886364 | 0.851095789 | 3 |
S141 | 1.1 | 420 | 120 | 0.853846 | 0.001107806 | 67 |
S142 | 1.1 | 121 | 15 | 0.304348 | 0.00026226 | 166 |
S143 | 1.2 | 82787 | 240 | 0.895833 | 0.233216619 | 20 |
S144 | 1.2 | 28 | 3 | 0.15 | 1.40666E-06 | 402 |
S145 | 1.2 | 63 | 28 | 0.30137 | 0.00010043 | 251 |
S146 | 1.1 | 352 | 169 | 0.71123 | 0.000920596 | 98 |
S147 | 1.1 | 108 | 8 | 0.35 | 0.000225495 | 174 |
S148 | 1.2 | 59 | 27 | 0.175 | 8.92396E-05 | 260 |
S149 | 1 | 251 | 72 | 0.864198 | 0.000630385 | 108 |
S150 | 1.2 | 1806 | 240 | 0.795833 | 0.005013227 | 57 |
S151 | 1 | 194498 | 240 | 0.954167 | 0.548020493 | 5 |
S152 | 1.2 | 398 | 124 | 0.708029 | 0.001046223 | 78 |
S153 | 1.1 | 175 | 13 | 0.178571 | 0.000414334 | 128 |
S154 | 1.2 | 7634 | 77 | 0.615385 | 0.02143393 | 52 |
S155 | 1.2 | 40 | 19 | 0.277778 | 3.60939E-05 | 315 |
S156 | 1.2 | 28 | 16 | 0.229167 | 1.05157E-05 | 384 |
S157 | 1.2 | 395 | 120 | 0.840909 | 0.001037569 | 81 |
S158 | 1.2 | 37 | 20 | 0.352941 | 2.86471E-05 | 321 |
S159 | 1.2 | 215 | 47 | 0.463415 | 0.000527955 | 116 |
S160 | 1 | 45 | 20 | 0.220588 | 4.97234E-05 | 303 |
S161 | 1 | 47 | 20 | 0.194444 | 5.51741E-05 | 298 |
S162 | 1 | 28 | 14 | 0.101124 | 9.11309E-06 | 394 |
S163 | 1.2 | 252 | 46 | 0.461538 | 0.000632024 | 107 |
S164 | 1 | 72 | 22 | 0.217949 | 0.000124864 | 212 |
S165 | 1.2 | 75 | 63 | 0.589474 | 0.000139395 | 201 |
S166 | 1.1 | 32 | 16 | 0.307692 | 1.54154E-05 | 347 |
S167 | 1.2 | 136 | 28 | 0.3 | 0.000304934 | 155 |
S168 | 1.1 | 31 | 17 | 0.2 | 1.40455E-05 | 359 |
S169 | 1.1 | 359 | 118 | 0.95122 | 0.000936361 | 94 |
S170 | 1.2 | 135 | 24 | 0.512195 | 0.000301959 | 156 |
S171 | 1 | 72 | 29 | 0.396825 | 0.000125537 | 211 |
S172 | 1.1 | 356 | 128 | 0.861314 | 0.000928584 | 96 |
S173 | 1 | 372 | 16 | 0.358974 | 0.000969456 | 92 |
S174 | 1.1 | 346 | 125 | 0.984127 | 0.000900333 | 100 |
S175 | 1.1 | 366 | 138 | 0.964539 | 0.000957316 | 93 |
S176 | 1.1 | 51 | 51 | 0.4875 | 7.36843E-05 | 274 |
S177 | 1 | 47 | 21 | 0.233766 | 5.53475E-05 | 297 |
S178 | 1.2 | 163 | 45 | 1 | 0.000381681 | 131 |
S179 | 1.1 | 31 | 14 | 0.162162 | 1.24307E-05 | 366 |
S180 | 1.1 | 52 | 52 | 0.847458 | 7.65001E-05 | 269 |
S181 | 1.2 | 36 | 16 | 0.189655 | 2.48761E-05 | 331 |
S182 | 1 | 153 | 27 | 0.541667 | 0.000352724 | 139 |
S183 | 1 | 28 | 15 | 0.146341 | 9.81411E-06 | 390 |
S184 | 1.2 | 73 | 26 | 0.415094 | 0.000128016 | 209 |
S185 | 1.2 | 64 | 26 | 0.240964 | 0.000102951 | 247 |
S186 | 1 | 377 | 122 | 0.787879 | 0.000987137 | 90 |
S187 | 1.2 | 74 | 26 | 0.27381 | 0.000130808 | 204 |
S188 | 1.1 | 51 | 23 | 0.884615 | 6.66242E-05 | 283 |
S189 | 1.2 | 8892 | 151 | 0.855346 | 0.024979151 | 48 |
S190 | 1.1 | 48 | 3 | 0.142857 | 5.63779E-05 | 296 |
S191 | 1.1 | 351 | 119 | 0.75188 | 0.000913968 | 99 |
S192 | 1 | 30 | 16 | 0.176471 | 1.19304E-05 | 368 |
S193 | 1.1 | 101 | 25 | 0.8 | 0.000206402 | 176 |
S194 | 1 | 101365 | 240 | 0.945833 | 0.285569797 | 17 |
S195 | 1.2 | 36 | 17 | 0.341463 | 2.51805E-05 | 330 |
S196 | 1.2 | 40 | 20 | 0.416667 | 3.63449E-05 | 314 |
S197 | 1.1 | 354 | 119 | 0.848 | 0.000922388 | 97 |
S198 | 1.2 | 54 | 22 | 0.149425 | 7.47328E-05 | 273 |
S199 | 1.1 | 130 | 30 | 0.5625 | 0.000288156 | 159 |
S200 | 1.1 | 65 | 30 | 0.328767 | 0.00010623 | 242 |
S201 | 1.2 | 81989 | 28 | 0.530612 | 0.23096779 | 21 |
S202 | 1.1 | 400 | 127 | 0.87218 | 0.001052014 | 76 |
S203 | 1.2 | 36 | 23 | 0.821429 | 2.73152E-05 | 325 |
S204 | 1.2 | 81 | 5 | 0.148148 | 0.000149381 | 194 |
S205 | 1.2 | 60 | 30 | 0.295775 | 9.24397E-05 | 256 |
S206 | 1 | 31 | 14 | 0.933333 | 1.24321E-05 | 365 |
S207 | 1 | 154 | 44 | 0.406593 | 0.000356347 | 138 |
S208 | 1.2 | 8757 | 90 | 0.531746 | 0.02459858 | 49 |
S209 | 1.2 | 163 | 37 | 0.39726 | 0.000381269 | 132 |
S210 | 1 | 15694 | 118 | 0.661871 | 0.044147185 | 41 |
S211 | 1.2 | 58 | 54 | 0.83871 | 9.2344E-05 | 257 |
S212 | 1 | 31 | 10 | 0.088235 | 1.05487E-05 | 380 |
S213 | 1 | 246 | 163 | 0.957831 | 0.00062473 | 109 |
S214 | 1.1 | 52 | 52 | 0.451613 | 7.64999E-05 | 270 |
S215 | 1.1 | 50 | 14 | 0.131579 | 6.26627E-05 | 287 |
S216 | 1.1 | 425 | 129 | 0.716216 | 0.001122343 | 65 |
S217 | 1.2 | 139 | 20 | 0.372093 | 0.000313084 | 151 |
S218 | 1 | 15483 | 240 | 0.929167 | 0.043552818 | 42 |
S219 | 1.2 | 36 | 25 | 0.666667 | 2.81304E-05 | 322 |
S220 | 1 | 70 | 28 | 0.387097 | 0.000119861 | 219 |
S221 | 1.2 | 392 | 123 | 0.97619 | 0.001029315 | 82 |
S222 | 1.1 | 32 | 15 | 0.384615 | 1.49461E-05 | 351 |
S223 | 1 | 28 | 17 | 0.378378 | 1.12163E-05 | 376 |
S224 | 1.1 | 108 | 95 | 0.781818 | 0.000234872 | 172 |
S225 | 1.1 | 32 | 14 | 0.8125 | 1.44962E-05 | 352 |
S226 | 1.2 | 200 | 34 | 0.440678 | 0.000485251 | 120 |
S227 | 1.2 | 254 | 30 | 0.692308 | 0.000637197 | 106 |
S228 | 1 | 151 | 15 | 0.22807 | 0.000346755 | 140 |
S229 | 1.2 | 354887 | 240 | 0.945833 | 0.999999989 | 1 |
S230 | 1.1 | 52 | 25 | 0.676471 | 6.96937E-05 | 279 |
S231 | 1 | 31 | 16 | 0.141026 | 1.34922E-05 | 362 |
S232 | 1.1 | 119 | 26 | 0.575 | 0.000257038 | 169 |
S233 | 1.1 | 179 | 57 | 0.564706 | 0.000427327 | 127 |
S234 | 1 | 45 | 45 | 0.277228 | 5.69767E-05 | 295 |
S235 | 1.1 | 189 | 31 | 0.763158 | 0.000454188 | 124 |
S236 | 1 | 28 | 16 | 0.6 | 1.05158E-05 | 383 |
S237 | 1.2 | 328 | 119 | 0.942149 | 0.00084944 | 102 |
S238 | 1.1 | 32 | 3 | 0.036364 | 1.13591E-05 | 372 |
S239 | 1 | 430 | 145 | 0.986207 | 0.001137328 | 61 |
S240 | 1.1 | 49 | 5 | 0.078125 | 5.92449E-05 | 293 |
S241 | 1 | 28 | 11 | 0.142857 | 7.01013E-06 | 398 |
S242 | 1.2 | 79 | 29 | 0.384615 | 0.000145053 | 196 |
S243 | 1.2 | 63 | 27 | 0.22093 | 0.000100301 | 253 |
S244 | 1 | 16406 | 240 | 0.870833 | 0.046153833 | 40 |
S245 | 1 | 386 | 152 | 0.803681 | 0.001014384 | 85 |
S246 | 1 | 44 | 18 | 0.180556 | 4.66366E-05 | 305 |
S247 | 1 | 56698 | 240 | 0.945833 | 0.159697306 | 24 |
S248 | 1.1 | 69 | 30 | 0.305882 | 0.000117314 | 223 |
S249 | 1.1 | 67 | 31 | 0.45 | 0.000111897 | 229 |
S250 | 1.2 | 35 | 12 | 0.578947 | 2.11804E-05 | 338 |
S251 | 1.2 | 36 | 6 | 0.092593 | 2.28153E-05 | 335 |
S252 | 1 | 48 | 24 | 0.322034 | 5.86212E-05 | 294 |
S253 | 1 | 223 | 68 | 0.930556 | 0.000551517 | 114 |
S254 | 1.2 | 161 | 26 | 0.533333 | 0.000375206 | 134 |
S255 | 1.2 | 36 | 18 | 0.444444 | 2.55005E-05 | 329 |
S256 | 1.1 | 411 | 123 | 0.853846 | 0.001082681 | 73 |
S257 | 1 | 31 | 13 | 0.196078 | 1.19263E-05 | 370 |
S258 | 1.1 | 414 | 125 | 0.75 | 0.00109122 | 69 |
S259 | 1.1 | 67 | 30 | 0.518519 | 0.000111767 | 231 |
S260 | 1.1 | 184 | 128 | 0.751724 | 0.000448532 | 125 |
S261 | 1.1 | 69 | 31 | 0.415385 | 0.000117437 | 222 |
S262 | 1 | 28 | 13 | 0.178571 | 8.41215E-06 | 395 |
S263 | 1 | 427 | 132 | 0.789474 | 0.00112813 | 62 |
S264 | 1.1 | 32 | 5 | 0.5 | 1.16162E-05 | 371 |
S265 | 1.2 | 141 | 59 | 0.6 | 0.000321021 | 148 |
S266 | 1.2 | 6519 | 240 | 0.870833 | 0.018292525 | 55 |
S267 | 1 | 82 | 62 | 0.539326 | 0.000158066 | 190 |
S268 | 1 | 129786 | 240 | 0.9375 | 0.365660752 | 15 |
S269 | 1.2 | 211 | 143 | 0.845161 | 0.000525212 | 117 |
S270 | 1 | 92 | 58 | 0.859375 | 0.000184726 | 177 |
S271 | 1 | 247 | 49 | 0.709677 | 0.000618063 | 111 |
S272 | 1.1 | 32 | 14 | 0.777778 | 1.44961E-05 | 353 |
S273 | 1.2 | 9484 | 90 | 0.838384 | 0.026647274 | 46 |
S274 | 1.2 | 77 | 32 | 0.591837 | 0.000139782 | 198 |
S275 | 1.2 | 158553 | 240 | 0.945833 | 0.446726745 | 8 |
S276 | 1.1 | 52 | 19 | 0.192308 | 6.87995E-05 | 281 |
S277 | 1 | 30 | 16 | 0.146341 | 1.19303E-05 | 369 |
S278 | 1.2 | 62 | 26 | 0.216867 | 9.74022E-05 | 255 |
S279 | 1 | 89 | 36 | 0.693878 | 0.000173641 | 179 |
S280 | 1.1 | 127 | 75 | 0.474138 | 0.000283765 | 160 |
S281 | 1.2 | 36 | 15 | 0.265306 | 2.4588E-05 | 332 |
S282 | 1.2 | 169340 | 240 | 0.9875 | 0.477124733 | 7 |
S283 | 1.2 | 30 | 14 | 0.088235 | 1.07157E-05 | 378 |
S284 | 1 | 46597 | 240 | 1 | 0.131232498 | 28 |
S285 | 1.2 | 35 | 19 | 0.177215 | 2.34169E-05 | 334 |
S286 | 1.1 | 67 | 30 | 0.725 | 0.000111767 | 230 |
S287 | 1.1 | 66 | 6 | 0.1 | 0.000107142 | 239 |
S288 | 1.2 | 30 | 13 | 0.333333 | 1.01264E-05 | 386 |
S289 | 1.2 | 40 | 14 | 0.214286 | 3.50228E-05 | 316 |
S290 | 1 | 31 | 19 | 0.246575 | 1.51885E-05 | 349 |
S291 | 1.2 | 7984 | 219 | 0.86036 | 0.022420682 | 51 |
S292 | 1.2 | 9160 | 90 | 0.618644 | 0.025734238 | 47 |
S293 | 1.2 | 192 | 8 | 0.119403 | 0.000462181 | 121 |
S294 | 1 | 18842 | 240 | 0.879167 | 0.053018492 | 38 |
S295 | 1.2 | 56 | 56 | 0.590361 | 8.782E-05 | 262 |
S296 | 1.2 | 62 | 33 | 0.62 | 9.84036E-05 | 254 |
S297 | 1 | 31 | 14 | 0.162162 | 1.24306E-05 | 367 |
S298 | 1.1 | 51 | 13 | 0.764706 | 6.53583E-05 | 284 |
S299 | 1.2 | 62 | 62 | 0.345588 | 0.000104921 | 244 |
S300 | 1.2 | 299 | 8 | 0.636364 | 0.000763699 | 104 |
S301 | 1 | 89 | 31 | 0.75 | 0.000173181 | 180 |
S302 | 1.2 | 59 | 25 | 0.191011 | 8.89639E-05 | 261 |
S303 | 1.1 | 54 | 9 | 0.642857 | 7.3483E-05 | 275 |
S304 | 1.2 | 156 | 88 | 0.83 | 0.000365824 | 136 |
S305 | 1 | 28 | 16 | 0.75 | 1.05162E-05 | 382 |
S306 | 1 | 126096 | 240 | 0.954167 | 0.355262256 | 16 |
S307 | 1.2 | 78196 | 171 | 0.97093 | 0.220279065 | 22 |
S308 | 1.1 | 136998 | 240 | 0.916667 | 0.385984315 | 12 |
S309 | 1.2 | 37 | 18 | 0.592593 | 2.80229E-05 | 323 |
S310 | 1.1 | 406 | 125 | 0.8125 | 0.001068749 | 74 |
S311 | 1.1 | 65 | 31 | 0.3125 | 0.000106366 | 240 |
S312 | 1.2 | 77 | 32 | 0.508197 | 0.000139782 | 199 |
S313 | 1 | 384 | 38 | 0.463768 | 0.00100355 | 88 |
S314 | 1 | 1670 | 235 | 0.778723 | 0.004630083 | 58 |
S315 | 1.1 | 32 | 12 | 0.423077 | 1.36576E-05 | 360 |
S316 | 1.1 | 69 | 28 | 0.581395 | 0.000117079 | 225 |
S317 | 1.2 | 29 | 21 | 0.2 | 1.43009E-05 | 354 |
S318 | 1.2 | 346 | 99 | 0.88785 | 0.000898758 | 101 |
S319 | 1.1 | 66 | 31 | 0.338028 | 0.00010913 | 234 |
S320 | 1 | 42 | 20 | 0.225806 | 4.16399E-05 | 307 |
S321 | 1.1 | 33 | 2 | 0.166667 | 1.41077E-05 | 356 |
S322 | 1.1 | 68 | 29 | 0.390625 | 0.000114417 | 227 |
S323 | 1.2 | 29 | 12 | 0.461538 | 8.21116E-06 | 396 |
S324 | 1.1 | 424 | 126 | 0.860294 | 0.001119367 | 66 |
S325 | 1 | 73 | 29 | 0.393443 | 0.000128321 | 207 |
S326 | 1 | 82 | 30 | 0.33871 | 0.000153525 | 191 |
S327 | 1.1 | 35 | 17 | 0.517241 | 2.26922E-05 | 336 |
S328 | 1.1 | 33 | 4 | 0.081081 | 1.42463E-05 | 355 |
S329 | 1.2 | 156518 | 240 | 0.941667 | 0.440992074 | 9 |
S330 | 1.1 | 136652 | 240 | 0.9125 | 0.38500928 | 13 |
S331 | 1 | 70 | 50 | 0.513514 | 0.00012324 | 213 |
S332 | 1.2 | 305 | 46 | 0.901961 | 0.000781228 | 103 |
S333 | 1.1 | 178 | 97 | 0.612903 | 0.000428024 | 126 |
S334 | 1 | 148 | 10 | 0.069444 | 0.000338221 | 141 |
S335 | 1.1 | 50 | 18 | 0.288462 | 6.31314E-05 | 286 |
S336 | 1.2 | 144 | 31 | 0.638298 | 0.000327566 | 146 |
S337 | 1.2 | 36 | 22 | 0.7 | 2.69255E-05 | 326 |
S338 | 1.1 | 30109 | 204 | 0.941176 | 0.084768989 | 32 |
S339 | 1 | 44 | 44 | 0.583333 | 5.4236E-05 | 299 |
S340 | 1.1 | 171426 | 240 | 0.941667 | 0.483003123 | 6 |
S341 | 1.2 | 63 | 27 | 0.35 | 0.000100301 | 252 |
S342 | 1 | 224 | 39 | 0.975 | 0.000552974 | 113 |
S343 | 1 | 28 | 11 | 0.114286 | 7.0101E-06 | 399 |
S344 | 1.1 | 54 | 9 | 0.111111 | 7.34829E-05 | 276 |
S345 | 1 | 87 | 14 | 0.393939 | 0.000166513 | 182 |
S346 | 1.1 | 23240 | 240 | 0.870833 | 0.065412097 | 36 |
S347 | 1 | 82 | 28 | 0.347826 | 0.000153346 | 192 |
S348 | 1.2 | 92421 | 194 | 0.919598 | 0.26036541 | 18 |
S349 | 1 | 42 | 23 | 0.571429 | 4.23596E-05 | 306 |
S350 | 1.2 | 39 | 20 | 0.226667 | 3.37387E-05 | 317 |
S351 | 1 | 44 | 37 | 0.948718 | 5.16705E-05 | 302 |
S352 | 1.2 | 89031 | 240 | 0.916667 | 0.250812336 | 19 |
S353 | 1.1 | 68 | 33 | 0.825 | 0.000114931 | 226 |
S354 | 1.2 | 57 | 23 | 0.265625 | 8.3165E-05 | 265 |
S355 | 1 | 31 | 7 | 0.259259 | 9.44272E-06 | 391 |
S356 | 1 | 130307 | 240 | 0.95 | 0.36712894 | 14 |
S357 | 1 | 220 | 54 | 0.75 | 0.000542333 | 115 |
S358 | 1.1 | 34 | 10 | 0.666667 | 1.80475E-05 | 342 |
S359 | 1 | 86 | 33 | 0.645833 | 0.000164977 | 184 |
S360 | 1.1 | 405 | 131 | 0.682119 | 0.001066291 | 75 |
S361 | 1 | 328080 | 240 | 0.879167 | 0.924457321 | 2 |
S362 | 1 | 91 | 69 | 0.985714 | 0.000183823 | 178 |
S363 | 1.2 | 56 | 19 | 0.347826 | 7.99072E-05 | 267 |
S364 | 1.1 | 28763 | 240 | 0.941667 | 0.080975983 | 33 |
S365 | 1 | 41631 | 240 | 0.95 | 0.11723822 | 29 |
S366 | 1.1 | 49 | 49 | 0.770492 | 6.80754E-05 | 282 |
S367 | 1.1 | 26335 | 240 | 0.9 | 0.074133845 | 34 |
S368 | 1 | 86 | 13 | 0.366667 | 0.000163662 | 185 |
S369 | 1 | 146 | 26 | 0.328358 | 0.000332988 | 143 |
S370 | 1.2 | 58 | 25 | 0.48 | 8.61984E-05 | 264 |
S371 | 1.1 | 54 | 24 | 0.242857 | 7.50215E-05 | 272 |
S372 | 1.2 | 29 | 10 | 0.25641 | 6.9109E-06 | 400 |
S373 | 1.2 | 30 | 15 | 0.169014 | 1.13179E-05 | 373 |
S374 | 1 | 49224 | 240 | 0.995833 | 0.138635433 | 26 |
S375 | 1.1 | 112 | 13 | 0.131148 | 0.000236863 | 171 |
S376 | 1.1 | 358 | 121 | 0.789855 | 0.00093374 | 95 |
S377 | 1 | 71 | 31 | 0.491228 | 0.000122986 | 214 |
S378 | 1.1 | 49 | 21 | 0.309091 | 6.08165E-05 | 291 |
S379 | 1 | 249 | 36 | 0.972973 | 0.000623265 | 110 |
S380 | 1 | 85 | 25 | 0.46 | 0.000161506 | 188 |
S381 | 1.2 | 201 | 28 | 0.84375 | 0.000487885 | 118 |
S382 | 1 | 28 | 15 | 0.378378 | 9.81437E-06 | 389 |
S383 | 1 | 147 | 27 | 0.735294 | 0.000335839 | 142 |
S384 | 1 | 89 | 19 | 0.326087 | 0.000172362 | 181 |
S385 | 1.1 | 53 | 24 | 0.243902 | 7.22719E-05 | 277 |
S386 | 1.1 | 119 | 41 | 0.703704 | 0.000257968 | 168 |
S387 | 1.1 | 33 | 13 | 0.171053 | 1.64103E-05 | 344 |
S388 | 1.1 | 114 | 64 | 0.901408 | 0.00024634 | 170 |
S389 | 1.1 | 69 | 31 | 0.543478 | 0.000117437 | 221 |
S390 | 1.1 | 66 | 13 | 0.204082 | 0.000107415 | 238 |
S391 | 1 | 70 | 31 | 0.303797 | 0.000120211 | 218 |
S392 | 1.1 | 412 | 129 | 0.847826 | 0.00108583 | 71 |
S393 | 1.1 | 33 | 1 | 0 | 1.40902E-05 | 357 |
S394 | 1.2 | 144 | 10 | 0.136364 | 0.000326951 | 147 |
S395 | 1.2 | 75843 | 74 | 0.869048 | 0.213648241 | 23 |
S396 | 1.2 | 38 | 25 | 0.21978 | 3.28205E-05 | 319 |
S397 | 1.1 | 52 | 52 | 0.864407 | 7.65001E-05 | 268 |
S398 | 1 | 41 | 16 | 0.35 | 3.81135E-05 | 312 |
S399 | 1.1 | 65 | 30 | 0.360656 | 0.00010623 | 241 |
S400 | 1.1 | 53 | 13 | 0.166667 | 7.0951E-05 | 278 |
S401 | 1.1 | 67 | 29 | 0.373134 | 0.000111642 | 232 |
S402 | 1.1 | 35 | 8 | 0.054795 | 2.03274E-05 | 339 |
第一问选取了
材料成本 | 总供货量 | 订单数 | 达标率 |
几个指标,利用熵权topsis法进行排名,取前五十名
不过数据处理的代码里还有一些计算其他的,写了但是没用上。。。
熵权topsis代码非原创,是借鉴了某位大佬的,不过我忘记是哪位的了。。。。
如果大佬不满意的话请联系我,我把它删掉
%%第一问代码
%处理数据
clc;clear
[num,txt,raw]=xlsread('附件1 近5年402家供应商的相关数据.xlsx',1);
[num2,txt2,raw2]=xlsread('附件1 近5年402家供应商的相关数据.xlsx',2);
%计算供给达标周数
sum_hege=zeros(402,1);
[m,n]=size(num);
for j=1:m
for i=1:n
if num(j,i)~=0&&num2(j,i)>=num(j,i)
sum_hege(j,1)=sum_hege(j,1)+1;%计算供给达标的周数
end
end
end
num_gongji=sum(num~=0,2);%计算企业要求供应商供给的周数
num2_sum=sum(num2,2);%求出供应商一共提供了多少材料;
num2_mean=mean(num2,2);%得出平均每个星期提供的材料数量;
num2_gongji=sum(num2~=0,2);%计算供应商有供货的周数;
num2_wugongji=sum(num2==0,2);%计算没有供货的周数;
num2_month=num2_mean*4;
dabiaolv=sum_hege./num_gongji;
%将材料量化
cailiao=ones(402,1);
xunzhaoA = strcmp(txt2(2:end,2),'A');%找出A,标记为1
mA=find(xunzhaoA==1);%找出字符串所在的索引
xunzhaoB = strcmp(txt2(2:end,2),'B');%找出A,标记为1
mB=find(xunzhaoB==1);%找出字符串所在的索引
cailiao(mA)=1.2;
cailiao(mB)=1.1;
data=[cailiao num2_sum num2_gongji dabiaolv];
bingtu=[sum(num2_sum<100),sum(num2_sum>=100&num2_sum<1000),sum(num2_sum>=1000&num2_sum<10000),sum(num2_sum>=10000)];
pie3(bingtu)
legend('供货量小于100','供货量100-1000','供货量1000-10000','供货量大于10000')
%%
%熵权topsis
x=data;%导入数据
[n,m]=size(x);
% 数据的归一化处理
[X,ps]=mapminmax(x',0,1);
ps.ymin=0.002; % 归一化后的最小值
ps.ymax=0.996; % 归一化后的最大值
ps.yrange=ps.ymax-ps.ymin; % 归一化后的极差
X=mapminmax(x',ps);
X=X'; % X为归一化后的数据
% 计算比重
for i=1:n
for j=1:m
p(i,j)=X(i,j)/sum(X(:,j));
end
end
%计算熵值
k=1/log(n);
for j=1:m
e(j)=-k*sum(p(:,j).*log(p(:,j)));
end
d=ones(1,m)-e; % 计算信息熵冗余度
w=d./sum(d); % 求权值w
%TOPSIS综合评价
A=data;%评价矩阵
W=w%权重
[ma,na]=size(A);
for i=1:na
B(:,i)=A(:,i)*W(i); %得到加权标准化矩阵
end
V1=zeros(1,na); %初始化正理想解和负理想解
V2=zeros(1,na);
BMAX=max(B); %取加权标准化矩阵每列的最大值和最小值
BMIN=min(B);
for i=1:na
V1(i)=BMAX(i);
V2(i)=BMIN(i);
end
for i=1:ma
C1=B(i,:)-V1;
S1(i)=norm(C1); %S1,S2分别为离正理想点和负理想点的距离
C2=B(i,:)-V2;
S2(i)=norm(C2);
T(i)=S2(i)/(S1(i)+S2(i));
end
output=T'%得出评分
xlswrite('评分.xlsx',output)
为了省事,我直接选择只从以上五十家购买材料,我发现,好像,应该,可能只购买材料A或者只购买材料C,最便宜,不过我当时在储存费用方面考虑欠佳。然后限制条件吧啦吧啦,懒得码字了,直接贴代码了。。。大家有不明白的,或者发现我问题的,欢迎在评论区和我交流
%若出现错误,可能是内存问题,重新运行即可
clc;clear;
[num,txt,raw]=xlsread('问题1评分排名.xlsx');
data=xlsread('附件1 近5年402家供应商的相关数据.xlsx',2);
index=1:402;
num2=[index' num];
num3=sortrows(num2,7);%对排名进行升序
wushi=num3(1:50,:);
indexC=find(wushi(:,2)==1);
C=wushi(indexC,:);
for i=1:20
Max(i)=max(data(C(i,1),:));
end
T=28200*0.72;
changku=0;%表示出库材料存量
buy=zeros(20,24);
A=0;
f=100000000;%初始化
X=1000;%模拟次数
count=1;
for Xunhuan=1:X
for i=1:20
buy(i,1)=min(6000,randi(round([Max(i)*0.3,Max(i)*0.6])));
end
if sum(buy(:,1))>=T
changku=sum(buy(:,1))-T;
Changku(1)=changku;
for j=2:24%星期
for i=1:20%供应商
fanwei=min(6000,round([Max(i)*0.3,Max(i)*0.6]));
if sum(buy(:,j))<=T||changku<=2*T
buy(i,j)=randi(fanwei);
if sum(buy(:,j))>=T
changku=changku+sum(buy(:,j))-T;
if changku>=2*T
continue
end
end
end
end
if sum(buy(:,j))<=T
changku=changku-(T-sum(buy(:,j)));
end
Changku(j)=changku;%记录每周仓库的存储数量
end
end
%数据合并
Buy=zeros(402,24)*nan;
Buy(C(:,1),:)=buy;
%%
%模拟转运损耗
into=xlsread('附件2 近5年8家转运商的相关数据.xlsx','B2:IG9');
yunshu=zeros(5,24)
for j=1:8%第j个转运商
hang=into(j,:);
%sunhao=unique(hang);
%[m,n]=size(sunhao);
for i=1:24
xunzhe=randi(240)
yunshu(j,i)=hang(xunzhe)
end
end
%%
%实施转运
p=1:8;;
a=1;%第a列
transport=zeros(20,24);
for i=1:24%24周
a=1;%第a行
R=0;%运输量
yunshu2=[p' yunshu(:,i)];
yunshu2(find(yunshu2(:,2)==0),:)=[];%剔除不运输的转运商
[m,n]=size(yunshu2);
yunshu3=sortrows(yunshu2,2)%进行降序
for j=1:20%20家供应商
indexT=yunshu3(a,1);
if R<=6000
R=R+buy(j,i);
transport(j,i)=indexT;
else
a=a+1;
if a>m
a=m;
end
transport(j,i)=yunshu3(a,1);
R=0;
R=R+buy(j,i);
end
end
end
Transport=zeros(402,24)*nan;
Transport(C(:,1),:)=transport;
%%
%计算损失
Sunshi=zeros(20,24)*nan;
for j=1:24;%周
for i=1:20%供应商
Shunshi(i,j)=buy(i,j)*yunshu(transport(i,j),j)
end
end
Shunshi2=zeros(402,24);
Shunshi2(C(:,1),:)=Shunshi;
if length(find(Changku>=0))==24 && changku>2*T
F(count)=sum(sum(buy))*1.5+sum(Changku)*0.5;
count=count+1
if F(count-1)
我的第三问其实和第二问差不多,还是选第一问得出的五十家供应商,只不过变成三种材料都采购了,并且给采购ABC的数量加了个权重,大概就是随机出三个大于0的数,它们的和为1,之后排序,储存在r2里,通过乘这个权重,达到多买A,少买C
这个代码感觉还有非常大大大的优化空间
因为有的时候会模拟出一些离谱的订单方案,比如说连仓库都欠账了之类的所以在最后加了一个判定,通过判定了才是有效模拟,直接count+1,有效模拟次数是count-1。
其实这个判定和 有效模拟次数 这玩意,第二问原本是没的,但是我在第三问写了这玩意之后,就有一种感觉“不行,第二问也要写,多水点图片”,所以每个问都有了
%第三问代码
%若出现某些错误,导致终止程序,可能是内存问题,重新运行即可
clc;clear;
[num,txt,raw]=xlsread('问题1评分排名.xlsx');
data=xlsread('附件1 近5年402家供应商的相关数据.xlsx',2);
index=1:402;
num2=[index' num];
num3=sortrows(num2,7);%对排名进行升序
wushi=num3(1:50,:);
%找出卖A的
indexA=find(wushi(:,2)==1.2);
A=wushi(indexA,:);
%找出卖B的
indexB=find(wushi(:,2)==1.1);
B=wushi(indexB,:);
%找出卖C的
indexC=find(wushi(:,2)==1);
C=wushi(indexC,:);
for i=1:16
MaxA(i)=max(data(A(i,1),:));
end
for i=1:14
MaxB(i)=max(data(B(i,1),:));
end
for i=1:20
MaxC(i)=max(data(C(i,1),:));
end
F=[]
Buy2=[];
R2=[];
Transport=[];
Shunshi2=[];
f=1000000000;
count=1;
X=100%模拟次数
for Xunhuan=1:X
x=rand(1,3);y=sum(x);r=x/y;
r2=sort(r,2)
%TA=28200*0.6*r2(3);
%TB=28200*0.66*r2(2);
%TC=28200*0.72*r2(1);
if TC<1
TC=1
end
changkuA=0;
changkuB=0;
changkuC=0;%表示出库材料存量
buyA=zeros(16,24);
buyB=zeros(14,24);
buyC=zeros(20,24);
%%
%购买材料A
for i=1:16
buyA(i,1)=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
end
if sum(buyA(:,1))>=TA
changkuA=sum(buyA(:,1))-TA;
ChangkuA(1)=changkuA;
for j=2:24%星期
for i=1:16%供应商
fanwei=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
if fanwei==0;
fanwei=1
end
if sum(buyA(:,j))<=TA||changkuA<=2*TA
buyA(i,j)=randi(fanwei);
if sum(buyA(:,j))>=TA
changkuA=changkuA+sum(buyA(:,j))-TA;
if changkuA>=2*TA
continue
end
end
end
end
if sum(buyA(:,j))<=TA
changkuA=changkuA-(TA-sum(buyA(:,j)));
end
ChangkuA(j)=changkuA;%记录每周仓库的存储数量
end
end
%%
%购买材料B
for i=1:14
buyB(i,1)=min(round(TB*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
end
if sum(buyB(:,1))>=TB
changkuB=sum(buyB(:,1))-TB;
ChangkuB(1)=changkuB;
for j=2:24%星期
for i=1:14%供应商
fanwei=min(round(TC*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
if fanwei==0;
fanwei=1;
end
if sum(buyB(:,j))<=TB||changkuB<=2*TB
buyB(i,j)=randi(fanwei);
if sum(buyB(:,j))>=TB
changkuB=changkuB+sum(buyB(:,j))-TB;
if changkuB>=2*TB
continue
end
end
end
end
if sum(buyB(:,j))<=TB
changkuB=changkuB-(TB-sum(buyB(:,j)));
end
ChangkuB(j)=changkuB;%记录每周仓库的存储数量
end
end
%%
%购买材料C
for i=1:20
buyC(i,1)=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
end
if sum(buyC(:,1))>=TC
changkuC=sum(buyC(:,1))-TC;
ChangkuC(1)=changkuC;
for j=2:24%星期
for i=1:20%供应商
fanwei=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
if fanwei==0
fanwei=1
end
if sum(buyC(:,j))<=TC||changkuC<=2*TC
buyC(i,j)=randi(fanwei);
if sum(buyC(:,j))>=TC
changkuC=changkuC+sum(buyC(:,j))-TC;
if changkuC>=2*TC
continue
end
end
end
end
if sum(buyC(:,j))<=TC
changkuC=changkuC-(TC-sum(buyC(:,j)));
end
ChangkuC(j)=changkuC;%记录每周仓库的存储数量
end
end
Buy=zeros(50,24);
Buy(A(:,7),:)=buyA;
Buy(B(:,7),:)=buyB;
Buy(C(:,7),:)=buyC;
%数据合并
buy=zeros(402,24)*nan;
buy(A(:,1),:)=buyA;
buy(B(:,1),:)=buyB;
buy(C(:,1),:)=buyC;
%xlswrite('订购方案2',buy);
%%
%模拟转运损耗
fujian2=xlsread('附件2 近5年8家转运商的相关数据.xlsx','B2:IG9');
yunshu=zeros(5,24);
for j=1:8%第j个转运商
hang=fujian2(j,:);
%sunhao=unique(hang);
%[m,n]=size(sunhao);
for i=1:24
xunzhe=randi(240);
yunshu(j,i)=hang(xunzhe);
end
end
%%
%实施转运
p=1:8;%运输排名
transport=zeros(50,24);
for i=1:24%24周
a=1;%第a行
R=0;%运输量
yunshu2=[p' yunshu(:,i)];
yunshu2(find(yunshu2(:,2)==0),:)=[];%剔除不运输的转运商
[m,n]=size(yunshu2);
yunshu3=sortrows(yunshu2,2);%进行降序
for j=1:50%50家供应商
indexT=yunshu3(a,1);
if Buy(j,i)==0
continue
end
if R<=6000
R=R+Buy(j,i);
transport(j,i)=indexT;
else
a=a+1;
if a>m
a=m;
end
transport(j,i)=yunshu3(a,1);
R=0;
R=R+Buy(j,i);
end
end
end
Transport2=ones(402,24)*nan;
Transport2(wushi(:,1),:)=transport;
%%
%计算损失
Sunshi=zeros(50,24);
for j=1:24%周
for i=1:50%供应商
if transport(i,j)==0
continue
end
Shunshi(i,j)=Buy(i,j)*yunshu(transport(i,j),j);
end
end
Shunshi2=ones(402,24)*nan;
Shunshi2(wushi(:,1),:)=Shunshi;
if length(find(ChangkuA>=0))==24&&length(find(ChangkuB>=0))==24&&length(find(ChangkuC>=0))==24&&sum(sum(Buy))>406080
F(count)=sum(sum(buyA))*1.2+sum(sum(buyB))*1.1+sum(sum(buyC))+0.5*(sum(ChangkuA)+sum(ChangkuB)+sum(ChangkuC))+sum(sum(Buy))*0.5;
count=count+1;
if F(count-1)
第四问和第三问类似,受到另外一篇文章启发,画图发现购买材料C越来越多,B相对平稳,A逐步下降,所以那个权重就变成了多买C,少买A,然后为了产能增加,我经过乱七八糟的计算,我直接取了个产量最多的年份的平均周产量,其实就是算年的之后除48(小声bb),然后取了40625,我就不负责的假设他为了有这么多生产能力
关于生产力提高这方面,我个人认为也能用预测模型预测,未来能达到的产量,预测好之后也能直接放到我这个代码,这个改起来很简单
第四问代码
这个代码被我删删改改,丢了一部分。。。。
%%
%前五十供应商画图
clc;clear
[num2,txt2,~]=xlsread('问题1评分排名.xlsx');
index=1:402;
num3=[index' num2];
num4=sortrows(num3,7);%对排名进行升序
num5=num4(1:50,:);
wushi=sortrows(num5,1);
indexA=find(wushi(:,2)==1.2);
A=wushi(indexA,:);
indexB=find(wushi(:,2)==1.1);
B=wushi(indexB,:);
indexC=find(wushi(:,2)==1);
C=wushi(indexC,:);
%平均每周
a1=A(:,3)./420
b1=B(:,3)./420
c1=C(:,3)./420
%平均每月
a2=A(:,3)./60
b2=B(:,3)./60
c2=C(:,3)./60
%每月画图
plot(A(:,1),a2,'-k*','linewidth',1)
title('\fontname{宋体}材料A每月平均供应量');
xlabel('\fontname{宋体}供应商\fontname{Times New Roman}ID');
ylabel('\fontname{宋体}材料供应量');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,240])
figure
plot(B(:,1),b2,'-k*','linewidth',1)
title('\fontname{宋体}材料B每月平均供应量');
xlabel('\fontname{宋体}供应商\fontname{Times New Roman}ID');;
ylabel('\fontname{宋体}材料供应量');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,240])
figure
plot(C(:,1),c2,'-k*','linewidth',1)
title('\fontname{宋体}材料C每月平均供应量');
xlabel('\fontname{宋体}供应商\fontname{Times New Roman}ID');
ylabel('\fontname{宋体}材料供应量');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,240])
%%
%分离附件1订单材料ABC
clc;clear
[num,txt,~]=xlsread('附件1 近5年402家供应商的相关数据.xlsx',1);
cailiao=ones(402,1);
xunzhaoA = strcmp(txt(2:end,2),'A');%找出A,标记为1
mA=find(xunzhaoA==1);%找出字符串所在的索引
xunzhaoB = strcmp(txt(2:end,2),'B');%找出A,标记为1
mB=find(xunzhaoB==1);%找出字符串所在的索引
xunzhaoC = strcmp(txt(2:end,2),'C');%找出A,标记为1
mC=find(xunzhaoC==1);%找出字符串所在的索引
cailiao(mA)=1.2;
cailiao(mB)=1.1;
cailiao(mC)=1;
indexA=find(cailiao(:,1)==1.2);
A=num(indexA,:);
indexB=find(cailiao(:,1)==1.1);
B=num(indexB,:);
indexC=find(cailiao(:,1)==1);
C=num(indexC,:);
shengchanli=sum(reshape(sum(A),48,5))./0.6+sum(reshape(sum(B),48,5))./0.66+sum(reshape(sum(C),48,5))./0.72;
plot(shengchanli)
%第四问模拟代码
%若出现某些错误,终止程序,可能是内存问题,重新运行即可
clc;clear;
[num,txt,raw]=xlsread('问题1评分排名.xlsx');
data=xlsread('附件1 近5年402家供应商的相关数据.xlsx',2);
index=1:402;
num2=[index' num];
num3=sortrows(num2,7);%对排名进行升序
wushi=num3(1:50,:);
%找出卖A的
indexA=find(wushi(:,2)==1.2);
A=wushi(indexA,:);
%找出卖B的
indexB=find(wushi(:,2)==1.1);
B=wushi(indexB,:);
%找出卖C的
indexC=find(wushi(:,2)==1);
C=wushi(indexC,:);
for i=1:16
MaxA(i)=max(data(A(i,1),:));
end
for i=1:14
MaxB(i)=max(data(B(i,1),:));
end
for i=1:20
MaxC(i)=max(data(C(i,1),:));
end
F=[]
Buy2=[];
R2=[];
Transport=[];
Shunshi2=[];
f=1000000000;
count=1;
X=1000%模拟次数
for Xunhuan=1:X
x=rand(1,3);
y=sum(x);
r=x/y;
r2=sort(r,2)
TA=40625*0.6*r2(1);
TB=40625*0.66*r2(2);
TC=40625*0.72*r2(3);
if TA<1
TA=1
end
changkuA=0;
changkuB=0;
changkuC=0;%表示出库材料存量
buyA=zeros(16,24);
buyB=zeros(14,24);
buyC=zeros(20,24);
%%
%购买材料A
for i=1:16
buyA(i,1)=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
end
if sum(buyA(:,1))>=TA
changkuA=sum(buyA(:,1))-TA;
ChangkuA(1)=changkuA;
for j=2:24%星期
for i=1:16%供应商
fanwei=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
if fanwei==0;
fanwei=1
end
if sum(buyA(:,j))<=TA||changkuA<=2*TA
buyA(i,j)=randi(fanwei);
if sum(buyA(:,j))>=TA
changkuA=changkuA+sum(buyA(:,j))-TA;
if changkuA>=2*TA
continue
end
end
end
end
if sum(buyA(:,j))<=TA
changkuA=changkuA-(TA-sum(buyA(:,j)));
end
ChangkuA(j)=changkuA;%记录每周仓库的存储数量
end
end
%%
%购买材料B
for i=1:14
buyB(i,1)=min(round(TB*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
end
if sum(buyB(:,1))>=TB
changkuB=sum(buyB(:,1))-TB;
ChangkuB(1)=changkuB;
for j=2:24%星期
for i=1:14%供应商
fanwei=min(round(TC*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
if fanwei==0;
fanwei=1;
end
if sum(buyB(:,j))<=TB||changkuB<=2*TB
buyB(i,j)=randi(fanwei);
if sum(buyB(:,j))>=TB
changkuB=changkuB+sum(buyB(:,j))-TB;
if changkuB>=2*TB
continue
end
end
end
end
if sum(buyB(:,j))<=TB
changkuB=changkuB-(TB-sum(buyB(:,j)));
end
ChangkuB(j)=changkuB;%记录每周仓库的存储数量
end
end
%%
%购买材料C
for i=1:20
buyC(i,1)=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
end
if sum(buyC(:,1))>=TC
changkuC=sum(buyC(:,1))-TC;
ChangkuC(1)=changkuC;
for j=2:24%星期
for i=1:20%供应商
fanwei=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
if fanwei==0
fanwei=1
end
if sum(buyC(:,j))<=TC||changkuC<=2*TC
buyC(i,j)=randi(fanwei);
if sum(buyC(:,j))>=TC
changkuC=changkuC+sum(buyC(:,j))-TC;
if changkuC>=2*TC
continue
end
end
end
end
if sum(buyC(:,j))<=TC
changkuC=changkuC-(TC-sum(buyC(:,j)));
end
ChangkuC(j)=changkuC;%记录每周仓库的存储数量
end
end
Buy=zeros(50,24);
Buy(A(:,7),:)=buyA;
Buy(B(:,7),:)=buyB;
Buy(C(:,7),:)=buyC;
%数据合并
buy=zeros(402,24)*nan;
buy(A(:,1),:)=buyA;
buy(B(:,1),:)=buyB;
buy(C(:,1),:)=buyC;
%xlswrite('订购方案2',buy);
%%
%模拟转运损耗
fujian2=xlsread('附件2 近5年8家转运商的相关数据.xlsx','B2:IG9');
yunshu=zeros(5,24);
for j=1:8%第j个转运商
hang=fujian2(j,:);
%sunhao=unique(hang);
%[m,n]=size(sunhao);
for i=1:24
xunzhe=randi(240);
yunshu(j,i)=hang(xunzhe);
end
end
%%
%实施转运
p=1:8;%运输排名
transport=zeros(50,24);
for i=1:24%24周
a=1;%第a行
R=0;%运输量
yunshu2=[p' yunshu(:,i)];
yunshu2(find(yunshu2(:,2)==0),:)=[];%剔除不运输的转运商
[m,n]=size(yunshu2);
yunshu3=sortrows(yunshu2,2);%进行降序
for j=1:50%50家供应商
indexT=yunshu3(a,1);
if Buy(j,i)==0
continue
end
if R<=6000
R=R+Buy(j,i);
transport(j,i)=indexT;
else
a=a+1;
if a>m
a=m;
end
transport(j,i)=yunshu3(a,1);
R=0;
R=R+Buy(j,i);
end
end
end
Transport2=ones(402,24)*nan;
Transport2(wushi(:,1),:)=transport;
%%
%计算损失
Sunshi=zeros(50,24);
for j=1:24%周
for i=1:50%供应商
if transport(i,j)==0
continue
end
Shunshi(i,j)=Buy(i,j)*yunshu(transport(i,j),j);
end
end
Shunshi2=ones(402,24)*nan;
Shunshi2(wushi(:,1),:)=Shunshi;
if length(find(ChangkuA>=0))==24&&length(find(ChangkuB>=0))==24&&length(find(ChangkuC>=0))==24&&sum(sum(Buy))>702000
F(count)=sum(sum(buyA))*1.2+sum(sum(buyB))*1.1+sum(sum(buyC))+0.5*(sum(ChangkuA)+sum(ChangkuB)+sum(ChangkuC))+sum(sum(Buy))*0.5;
count=count+1;
if F(count-1)
其实还有一个模型检验的代码,不过太敷衍了,我就不放出来了
关于转运方案,改一改代码就能换成对应的表格了,我当时没注意它的表格格式,弄成了和订单一样的样子。。。
我这个用是蒙特卡洛模拟的思想
最后,欢迎大家和我交流