我是mystic
作者。首先,mystic
这不是解决这个问题的最佳代码......像 in 这样的一个好的线性 MIP 求解器OR-Tools
将是一个更好的选择。Mystic 将可靠地解决 MIP/LP 问题,只是不如 OR-Tools 快。在速度方面,mystic
大约和scipy.optimize
. 随着约束变得更加非线性、复杂和受严格约束,Mystic 会放慢速度(请注意,在这种情况下,其他代码通常会失败,而mystic
不会)。下面,我将使用差分进化求解器(它比 SLSQP 更慢,但更健壮)。
请注意,一旦您有一个或多个非线性约束,您绝对应该mystic
使用... asmystic
是为具有非线性约束的全局优化而构建的。或者,如果您没有固定定价模型,而是在模型中存在一些市场波动,从而产生不确定性......并且想要最大化预期利润,或者甚至更好地建立一个最小化风险的利润模型,那么您肯定应该使用mystic
. OR-tools
而其他 LP/QP 代码最多只能将问题近似为线性或二次 - 这可能不切实际。
不管。当您询问如何mystic
解决此问题时,这里有许多解决方案的方法之一mystic
:
import mystic as my
import mystic.symbolic as ms
import mystic.constraints as mc
class item(object):
def __init__(self, id, mass, buy, net, limit):
self.id = id
self.mass = mass
self.buy = buy
self.net = net
self.limit = limit
def __repr__(self):
return 'item(%s, mass=%s, buy=%s, net=%s, limit=%s)' % (self.id, self.mass, self.buy, self.net, self.limit)
# data
masses = [10, 15, 20, 18, 34, 75, 11, 49, 68, 55]
buys = [123, 104, 149, 175, 199, 120, 164, 136, 194, 111]
nets = [13, 24, 10, 29, 29, 39, 28, 35, 33, 39]
limits = [300, 500, 200, 300, 200, 350, 100, 600, 1000, 50]
ids = range(len(limits))
# maxima
_load = 75000 # max limit on mass can carry
_spend = 350000 # max limit to spend at source
# items
items = [item(*i) for i in zip(ids, masses, buys, nets, limits)]
# profit
def fixnet(net):
def profit(x):
return sum(xi*pi for xi,pi in zip(x,net))
return profit
profit = fixnet([i.net for i in items])
# item constraints
load = [i.mass for i in items]
invest = [i.buy for i in items]
constraints = ms.linear_symbolic(G=[load, invest], h=[_load, _spend])
# bounds (on x)
bounds = [(0, i.limit) for i in items]
# bounds constraints
lo = 'x%s >= %s'
lo = '\n'.join(lo % (i,str(float(j[0])).lstrip('0')) for (i,j) in enumerate(bounds))
hi = 'x%s <= %s'
hi = '\n'.join(hi % (i,str(float(j[1])).lstrip('0')) for (i,j) in enumerate(bounds))
constraints = '\n'.join([lo, hi]).strip() + '\n' + constraints
pf = ms.generate_penalty(ms.generate_conditions(ms.simplify(constraints)))
# integer constraints
cf = mc.integers(float)(lambda x:x)
# solve
mon = my.monitors.VerboseMonitor(1, 10)
results = my.solvers.diffev2(lambda x: -profit(x), bounds, npop=400, bounds=bounds, ftol=1e-4, gtol=50, itermon=mon, disp=True, full_output=True, constraints=cf, penalty=pf)
print ('\nmax profit: %s' % -results[1])
print("load: %s <= %s" % (sum(i*j for i,j in zip(results[0], load)), _load))
print("spend: %s <= %s" % (sum(i*j for i,j in zip(results[0], invest)), _spend))
print('')
for item,quantity in enumerate(results[0]):
print("item %s: %s" % (item,quantity))
结果:
dude@borel>$ python knapsack.py
Generation 0 has ChiSquare: -58080.000000
Generation 0 has fit parameters:
[139.0, 413.0, 100.0, 271.0, 136.0, 344.0, 86.0, 404.0, 103.0, 5.0]
Generation 1 has ChiSquare: -58080.000000
Generation 2 has ChiSquare: -58080.000000
Generation 3 has ChiSquare: -58080.000000
Generation 4 has ChiSquare: -58080.000000
Generation 5 has ChiSquare: -58080.000000
Generation 6 has ChiSquare: -58080.000000
Generation 7 has ChiSquare: -58080.000000
Generation 8 has ChiSquare: -58080.000000
Generation 9 has ChiSquare: -58080.000000
Generation 10 has ChiSquare: -58080.000000
Generation 10 has fit parameters:
[139.0, 413.0, 100.0, 271.0, 136.0, 344.0, 86.0, 404.0, 103.0, 5.0]
Generation 11 has ChiSquare: -58603.000000
Generation 12 has ChiSquare: -58603.000000
Generation 13 has ChiSquare: -58603.000000
Generation 14 has ChiSquare: -58603.000000
Generation 15 has ChiSquare: -58603.000000
Generation 16 has ChiSquare: -58603.000000
Generation 17 has ChiSquare: -58603.000000
Generation 18 has ChiSquare: -58607.000000
Generation 19 has ChiSquare: -58607.000000
Generation 20 has ChiSquare: -58607.000000
Generation 20 has fit parameters:
[198.0, 406.0, 28.0, 256.0, 139.0, 239.0, 43.0, 472.0, 185.0, 36.0]
Generation 21 has ChiSquare: -59118.000000
Generation 22 has ChiSquare: -59944.000000
Generation 23 has ChiSquare: -59944.000000
Generation 24 has ChiSquare: -59944.000000
Generation 25 has ChiSquare: -59944.000000
Generation 26 has ChiSquare: -59944.000000
Generation 27 has ChiSquare: -59944.000000
Generation 28 has ChiSquare: -59944.000000
Generation 29 has ChiSquare: -60765.000000
Generation 30 has ChiSquare: -60765.000000
Generation 30 has fit parameters:
[214.0, 430.0, 24.0, 295.0, 154.0, 123.0, 77.0, 541.0, 219.0, 33.0]
Generation 31 has ChiSquare: -60765.000000
Generation 32 has ChiSquare: -60765.000000
Generation 33 has ChiSquare: -60765.000000
Generation 34 has ChiSquare: -60765.000000
Generation 35 has ChiSquare: -60765.000000
Generation 36 has ChiSquare: -61045.000000
Generation 37 has ChiSquare: -61045.000000
Generation 38 has ChiSquare: -61045.000000
Generation 39 has ChiSquare: -61045.000000
Generation 40 has ChiSquare: -61045.000000
Generation 40 has fit parameters:
[296.0, 496.0, 112.0, 292.0, 144.0, 136.0, 94.0, 347.0, 315.0, 27.0]
Generation 41 has ChiSquare: -61045.000000
Generation 42 has ChiSquare: -61045.000000
Generation 43 has ChiSquare: -61045.000000
Generation 44 has ChiSquare: -61045.000000
Generation 45 has ChiSquare: -61045.000000
Generation 46 has ChiSquare: -61045.000000
Generation 47 has ChiSquare: -61045.000000
Generation 48 has ChiSquare: -61045.000000
Generation 49 has ChiSquare: -62106.000000
Generation 50 has ChiSquare: -62106.000000
Generation 50 has fit parameters:
[295.0, 470.0, 114.0, 216.0, 170.0, 73.0, 83.0, 598.0, 225.0, 29.0]
Generation 51 has ChiSquare: -62106.000000
Generation 52 has ChiSquare: -62106.000000
Generation 53 has ChiSquare: -62106.000000
Generation 54 has ChiSquare: -62106.000000
Generation 55 has ChiSquare: -62106.000000
Generation 56 has ChiSquare: -62224.000000
Generation 57 has ChiSquare: -62224.000000
Generation 58 has ChiSquare: -62224.000000
Generation 59 has ChiSquare: -62224.000000
Generation 60 has ChiSquare: -62224.000000
Generation 60 has fit parameters:
[247.0, 441.0, 38.0, 288.0, 200.0, 175.0, 85.0, 499.0, 206.0, 11.0]
Generation 61 has ChiSquare: -62224.000000
Generation 62 has ChiSquare: -62224.000000
Generation 63 has ChiSquare: -62224.000000
Generation 64 has ChiSquare: -62224.000000
Generation 65 has ChiSquare: -62224.000000
Generation 66 has ChiSquare: -62224.000000
Generation 67 has ChiSquare: -62224.000000
Generation 68 has ChiSquare: -62224.000000
Generation 69 has ChiSquare: -62224.000000
Generation 70 has ChiSquare: -62224.000000
Generation 70 has fit parameters:
[247.0, 441.0, 38.0, 288.0, 200.0, 175.0, 85.0, 499.0, 206.0, 11.0]
Generation 71 has ChiSquare: -63795.000000
Generation 72 has ChiSquare: -63795.000000
Generation 73 has ChiSquare: -63795.000000
Generation 74 has ChiSquare: -63795.000000
Generation 75 has ChiSquare: -63795.000000
Generation 76 has ChiSquare: -63795.000000
Generation 77 has ChiSquare: -63795.000000
Generation 78 has ChiSquare: -63795.000000
Generation 79 has ChiSquare: -63795.000000
Generation 80 has ChiSquare: -63795.000000
Generation 80 has fit parameters:
[263.0, 494.0, 110.0, 293.0, 198.0, 246.0, 92.0, 529.0, 52.0, 20.0]
Generation 81 has ChiSquare: -63795.000000
Generation 82 has ChiSquare: -63795.000000
Generation 83 has ChiSquare: -63795.000000
Generation 84 has ChiSquare: -63795.000000
Generation 85 has ChiSquare: -63795.000000
Generation 86 has ChiSquare: -63795.000000
Generation 87 has ChiSquare: -63795.000000
Generation 88 has ChiSquare: -63795.000000
Generation 89 has ChiSquare: -63795.000000
Generation 90 has ChiSquare: -63795.000000
Generation 90 has fit parameters:
[263.0, 494.0, 110.0, 293.0, 198.0, 246.0, 92.0, 529.0, 52.0, 20.0]
Generation 91 has ChiSquare: -63795.000000
Generation 92 has ChiSquare: -63795.000000
Generation 93 has ChiSquare: -63795.000000
Generation 94 has ChiSquare: -63795.000000
Generation 95 has ChiSquare: -63795.000000
Generation 96 has ChiSquare: -63795.000000
Generation 97 has ChiSquare: -63795.000000
Generation 98 has ChiSquare: -63795.000000
Generation 99 has ChiSquare: -63795.000000
Generation 100 has ChiSquare: -63795.000000
Generation 100 has fit parameters:
[263.0, 494.0, 110.0, 293.0, 198.0, 246.0, 92.0, 529.0, 52.0, 20.0]
Generation 101 has ChiSquare: -63795.000000
Generation 102 has ChiSquare: -64252.000000
Generation 103 has ChiSquare: -64252.000000
Generation 104 has ChiSquare: -64252.000000
Generation 105 has ChiSquare: -64252.000000
Generation 106 has ChiSquare: -64252.000000
Generation 107 has ChiSquare: -64252.000000
Generation 108 has ChiSquare: -64252.000000
Generation 109 has ChiSquare: -64252.000000
Generation 110 has ChiSquare: -64252.000000
Generation 110 has fit parameters:
[279.0, 479.0, 96.0, 295.0, 192.0, 182.0, 83.0, 582.0, 84.0, 38.0]
Generation 111 has ChiSquare: -64252.000000
Generation 112 has ChiSquare: -64252.000000
Generation 113 has ChiSquare: -64252.000000
Generation 114 has ChiSquare: -64252.000000
Generation 115 has ChiSquare: -64252.000000
Generation 116 has ChiSquare: -64252.000000
Generation 117 has ChiSquare: -64252.000000
Generation 118 has ChiSquare: -64252.000000
Generation 119 has ChiSquare: -64252.000000
Generation 120 has ChiSquare: -64252.000000
Generation 120 has fit parameters:
[279.0, 479.0, 96.0, 295.0, 192.0, 182.0, 83.0, 582.0, 84.0, 38.0]
Generation 121 has ChiSquare: -64252.000000
Generation 122 has ChiSquare: -64252.000000
Generation 123 has ChiSquare: -64252.000000
Generation 124 has ChiSquare: -64368.000000
Generation 125 has ChiSquare: -64368.000000
Generation 126 has ChiSquare: -64368.000000
Generation 127 has ChiSquare: -64368.000000
Generation 128 has ChiSquare: -64368.000000
Generation 129 has ChiSquare: -64368.000000
Generation 130 has ChiSquare: -64368.000000
Generation 130 has fit parameters:
[292.0, 493.0, 144.0, 297.0, 174.0, 195.0, 75.0, 586.0, 53.0, 43.0]
Generation 131 has ChiSquare: -64368.000000
Generation 132 has ChiSquare: -64368.000000
Generation 133 has ChiSquare: -64368.000000
Generation 134 has ChiSquare: -64368.000000
Generation 135 has ChiSquare: -64368.000000
Generation 136 has ChiSquare: -64368.000000
Generation 137 has ChiSquare: -64368.000000
Generation 138 has ChiSquare: -64368.000000
Generation 139 has ChiSquare: -64735.000000
Generation 140 has ChiSquare: -64735.000000
Generation 140 has fit parameters:
[289.0, 483.0, 54.0, 293.0, 184.0, 263.0, 95.0, 599.0, 0.0, 29.0]
Generation 141 has ChiSquare: -64735.000000
Generation 142 has ChiSquare: -64735.000000
Generation 143 has ChiSquare: -64735.000000
Generation 144 has ChiSquare: -64735.000000
Generation 145 has ChiSquare: -64735.000000
Generation 146 has ChiSquare: -64735.000000
Generation 147 has ChiSquare: -64735.000000
Generation 148 has ChiSquare: -64735.000000
Generation 149 has ChiSquare: -64735.000000
Generation 150 has ChiSquare: -64735.000000
Generation 150 has fit parameters:
[289.0, 483.0, 54.0, 293.0, 184.0, 263.0, 95.0, 599.0, 0.0, 29.0]
Generation 151 has ChiSquare: -64735.000000
Generation 152 has ChiSquare: -64735.000000
Generation 153 has ChiSquare: -64735.000000
Generation 154 has ChiSquare: -64735.000000
Generation 155 has ChiSquare: -64735.000000
Generation 156 has ChiSquare: -64735.000000
Generation 157 has ChiSquare: -64735.000000
Generation 158 has ChiSquare: -64735.000000
Generation 159 has ChiSquare: -64735.000000
Generation 160 has ChiSquare: -64735.000000
Generation 160 has fit parameters:
[289.0, 483.0, 54.0, 293.0, 184.0, 263.0, 95.0, 599.0, 0.0, 29.0]
Generation 161 has ChiSquare: -64735.000000
Generation 162 has ChiSquare: -64897.000000
Generation 163 has ChiSquare: -65223.000000
Generation 164 has ChiSquare: -65223.000000
Generation 165 has ChiSquare: -65223.000000
Generation 166 has ChiSquare: -65223.000000
Generation 167 has ChiSquare: -65223.000000
Generation 168 has ChiSquare: -65223.000000
Generation 169 has ChiSquare: -65223.000000
Generation 170 has ChiSquare: -65223.000000
Generation 170 has fit parameters:
[295.0, 498.0, 67.0, 299.0, 190.0, 212.0, 95.0, 577.0, 47.0, 49.0]
Generation 171 has ChiSquare: -65223.000000
Generation 172 has ChiSquare: -65223.000000
Generation 173 has ChiSquare: -65223.000000
Generation 174 has ChiSquare: -65223.000000
Generation 175 has ChiSquare: -65223.000000
Generation 176 has ChiSquare: -65223.000000
Generation 177 has ChiSquare: -65223.000000
Generation 178 has ChiSquare: -65223.000000
Generation 179 has ChiSquare: -65223.000000
Generation 180 has ChiSquare: -65223.000000
Generation 180 has fit parameters:
[295.0, 498.0, 67.0, 299.0, 190.0, 212.0, 95.0, 577.0, 47.0, 49.0]
Generation 181 has ChiSquare: -65223.000000
Generation 182 has ChiSquare: -65223.000000
Generation 183 has ChiSquare: -65223.000000
Generation 184 has ChiSquare: -65223.000000
Generation 185 has ChiSquare: -65223.000000
Generation 186 has ChiSquare: -65223.000000
Generation 187 has ChiSquare: -65223.000000
Generation 188 has ChiSquare: -65223.000000
Generation 189 has ChiSquare: -65223.000000
Generation 190 has ChiSquare: -65223.000000
Generation 190 has fit parameters:
[295.0, 498.0, 67.0, 299.0, 190.0, 212.0, 95.0, 577.0, 47.0, 49.0]
Generation 191 has ChiSquare: -65223.000000
Generation 192 has ChiSquare: -65223.000000
Generation 193 has ChiSquare: -65223.000000
Generation 194 has ChiSquare: -65223.000000
Generation 195 has ChiSquare: -65223.000000
Generation 196 has ChiSquare: -65223.000000
Generation 197 has ChiSquare: -65223.000000
Generation 198 has ChiSquare: -65223.000000
Generation 199 has ChiSquare: -65223.000000
Generation 200 has ChiSquare: -65223.000000
Generation 200 has fit parameters:
[295.0, 498.0, 67.0, 299.0, 190.0, 212.0, 95.0, 577.0, 47.0, 49.0]
Generation 201 has ChiSquare: -65340.000000
Generation 202 has ChiSquare: -65340.000000
Generation 203 has ChiSquare: -65340.000000
Generation 204 has ChiSquare: -65340.000000
Generation 205 has ChiSquare: -65340.000000
Generation 206 has ChiSquare: -65340.000000
Generation 207 has ChiSquare: -65340.000000
Generation 208 has ChiSquare: -65340.000000
Generation 209 has ChiSquare: -65340.000000
Generation 210 has ChiSquare: -65340.000000
Generation 210 has fit parameters:
[298.0, 500.0, 36.0, 297.0, 199.0, 176.0, 94.0, 583.0, 87.0, 50.0]
Generation 211 has ChiSquare: -65340.000000
Generation 212 has ChiSquare: -65340.000000
Generation 213 has ChiSquare: -65340.000000
Generation 214 has ChiSquare: -65340.000000
Generation 215 has ChiSquare: -65340.000000
Generation 216 has ChiSquare: -65340.000000
Generation 217 has ChiSquare: -65340.000000
Generation 218 has ChiSquare: -65340.000000
Generation 219 has ChiSquare: -65340.000000
Generation 220 has ChiSquare: -65340.000000
Generation 220 has fit parameters:
[298.0, 500.0, 36.0, 297.0, 199.0, 176.0, 94.0, 583.0, 87.0, 50.0]
Generation 221 has ChiSquare: -65340.000000
Generation 222 has ChiSquare: -65340.000000
Generation 223 has ChiSquare: -65340.000000
Generation 224 has ChiSquare: -65340.000000
Generation 225 has ChiSquare: -65340.000000
Generation 226 has ChiSquare: -65340.000000
Generation 227 has ChiSquare: -65340.000000
Generation 228 has ChiSquare: -65340.000000
Generation 229 has ChiSquare: -65449.000000
Generation 230 has ChiSquare: -65449.000000
Generation 230 has fit parameters:
[285.0, 498.0, 18.0, 296.0, 199.0, 181.0, 96.0, 596.0, 83.0, 49.0]
Generation 231 has ChiSquare: -65449.000000
Generation 232 has ChiSquare: -65449.000000
Generation 233 has ChiSquare: -65449.000000
Generation 234 has ChiSquare: -65449.000000
Generation 235 has ChiSquare: -65449.000000
Generation 236 has ChiSquare: -65449.000000
Generation 237 has ChiSquare: -65449.000000
Generation 238 has ChiSquare: -65449.000000
Generation 239 has ChiSquare: -65449.000000
Generation 240 has ChiSquare: -65449.000000
Generation 240 has fit parameters:
[285.0, 498.0, 18.0, 296.0, 199.0, 181.0, 96.0, 596.0, 83.0, 49.0]
Generation 241 has ChiSquare: -65449.000000
Generation 242 has ChiSquare: -65449.000000
Generation 243 has ChiSquare: -65449.000000
Generation 244 has ChiSquare: -65449.000000
Generation 245 has ChiSquare: -65449.000000
Generation 246 has ChiSquare: -65449.000000
Generation 247 has ChiSquare: -65456.000000
Generation 248 has ChiSquare: -65456.000000
Generation 249 has ChiSquare: -65456.000000
Generation 250 has ChiSquare: -65456.000000
Generation 250 has fit parameters:
[297.0, 498.0, 76.0, 300.0, 192.0, 195.0, 97.0, 588.0, 57.0, 47.0]
Generation 251 has ChiSquare: -65456.000000
Generation 252 has ChiSquare: -65456.000000
Generation 253 has ChiSquare: -65456.000000
Generation 254 has ChiSquare: -65622.000000
Generation 255 has ChiSquare: -65622.000000
Generation 256 has ChiSquare: -65622.000000
Generation 257 has ChiSquare: -65622.000000
Generation 258 has ChiSquare: -65622.000000
Generation 259 has ChiSquare: -65622.000000
Generation 260 has ChiSquare: -65622.000000
Generation 260 has fit parameters:
[294.0, 496.0, 138.0, 300.0, 199.0, 221.0, 99.0, 590.0, 4.0, 48.0]
Generation 261 has ChiSquare: -65622.000000
Generation 262 has ChiSquare: -65622.000000
Generation 263 has ChiSquare: -65622.000000
Generation 264 has ChiSquare: -65622.000000
Generation 265 has ChiSquare: -65622.000000
Generation 266 has ChiSquare: -65622.000000
Generation 267 has ChiSquare: -65622.000000
Generation 268 has ChiSquare: -65622.000000
Generation 269 has ChiSquare: -65622.000000
Generation 270 has ChiSquare: -65622.000000
Generation 270 has fit parameters:
[294.0, 496.0, 138.0, 300.0, 199.0, 221.0, 99.0, 590.0, 4.0, 48.0]
Generation 271 has ChiSquare: -65622.000000
Generation 272 has ChiSquare: -65622.000000
Generation 273 has ChiSquare: -65622.000000
Generation 274 has ChiSquare: -65622.000000
Generation 275 has ChiSquare: -65622.000000
Generation 276 has ChiSquare: -65622.000000
Generation 277 has ChiSquare: -65622.000000
Generation 278 has ChiSquare: -65622.000000
Generation 279 has ChiSquare: -65622.000000
Generation 280 has ChiSquare: -65622.000000
Generation 280 has fit parameters:
[294.0, 496.0, 138.0, 300.0, 199.0, 221.0, 99.0, 590.0, 4.0, 48.0]
Generation 281 has ChiSquare: -65622.000000
Generation 282 has ChiSquare: -65622.000000
Generation 283 has ChiSquare: -65622.000000
Generation 284 has ChiSquare: -65622.000000
Generation 285 has ChiSquare: -65622.000000
Generation 286 has ChiSquare: -65622.000000
Generation 287 has ChiSquare: -65622.000000
Generation 288 has ChiSquare: -65622.000000
Generation 289 has ChiSquare: -65622.000000
Generation 290 has ChiSquare: -65622.000000
Generation 290 has fit parameters:
[294.0, 496.0, 138.0, 300.0, 199.0, 221.0, 99.0, 590.0, 4.0, 48.0]
Generation 291 has ChiSquare: -65644.000000
Generation 292 has ChiSquare: -65644.000000
Generation 293 has ChiSquare: -65691.000000
Generation 294 has ChiSquare: -65691.000000
Generation 295 has ChiSquare: -65691.000000
Generation 296 has ChiSquare: -65691.000000
Generation 297 has ChiSquare: -65691.000000
Generation 298 has ChiSquare: -65691.000000
Generation 299 has ChiSquare: -65691.000000
Generation 300 has ChiSquare: -65691.000000
Generation 300 has fit parameters:
[298.0, 500.0, 148.0, 300.0, 194.0, 206.0, 96.0, 600.0, 15.0, 46.0]
Generation 301 has ChiSquare: -65691.000000
Generation 302 has ChiSquare: -65691.000000
Generation 303 has ChiSquare: -65703.000000
Generation 304 has ChiSquare: -65703.000000
Generation 305 has ChiSquare: -65703.000000
Generation 306 has ChiSquare: -65703.000000
Generation 307 has ChiSquare: -65703.000000
Generation 308 has ChiSquare: -65703.000000
Generation 309 has ChiSquare: -65703.000000
Generation 310 has ChiSquare: -65703.000000
Generation 310 has fit parameters:
[296.0, 497.0, 38.0, 299.0, 198.0, 232.0, 96.0, 599.0, 17.0, 48.0]
Generation 311 has ChiSquare: -65703.000000
Generation 312 has ChiSquare: -65703.000000
Generation 313 has ChiSquare: -65703.000000
Generation 314 has ChiSquare: -65703.000000
Generation 315 has ChiSquare: -65703.000000
Generation 316 has ChiSquare: -65703.000000
Generation 317 has ChiSquare: -65773.000000
Generation 318 has ChiSquare: -65773.000000
Generation 319 has ChiSquare: -65773.000000
Generation 320 has ChiSquare: -65773.000000
Generation 320 has fit parameters:
[294.0, 499.0, 35.0, 299.0, 200.0, 244.0, 96.0, 600.0, 0.0, 50.0]
Generation 321 has ChiSquare: -65773.000000
Generation 322 has ChiSquare: -65773.000000
Generation 323 has ChiSquare: -65773.000000
Generation 324 has ChiSquare: -65773.000000
Generation 325 has ChiSquare: -65773.000000
Generation 326 has ChiSquare: -65773.000000
Generation 327 has ChiSquare: -65773.000000
Generation 328 has ChiSquare: -65773.000000
Generation 329 has ChiSquare: -65773.000000
Generation 330 has ChiSquare: -65773.000000
Generation 330 has fit parameters:
[294.0, 499.0, 35.0, 299.0, 200.0, 244.0, 96.0, 600.0, 0.0, 50.0]
Generation 331 has ChiSquare: -65773.000000
Generation 332 has ChiSquare: -65773.000000
Generation 333 has ChiSquare: -65773.000000
Generation 334 has ChiSquare: -65773.000000
Generation 335 has ChiSquare: -65773.000000
Generation 336 has ChiSquare: -65773.000000
Generation 337 has ChiSquare: -65773.000000
Generation 338 has ChiSquare: -65774.000000
Generation 339 has ChiSquare: -65774.000000
Generation 340 has ChiSquare: -65774.000000
Generation 340 has fit parameters:
[290.0, 500.0, 49.0, 298.0, 199.0, 243.0, 99.0, 596.0, 6.0, 46.0]
Generation 341 has ChiSquare: -65774.000000
Generation 342 has ChiSquare: -65774.000000
Generation 343 has ChiSquare: -65774.000000
Generation 344 has ChiSquare: -65774.000000
Generation 345 has ChiSquare: -65774.000000
Generation 346 has ChiSquare: -65774.000000
Generation 347 has ChiSquare: -65774.000000
Generation 348 has ChiSquare: -65774.000000
Generation 349 has ChiSquare: -65774.000000
Generation 350 has ChiSquare: -65774.000000
Generation 350 has fit parameters:
[290.0, 500.0, 49.0, 298.0, 199.0, 243.0, 99.0, 596.0, 6.0, 46.0]
Generation 351 has ChiSquare: -65774.000000
Generation 352 has ChiSquare: -65774.000000
Generation 353 has ChiSquare: -65774.000000
Generation 354 has ChiSquare: -65779.000000
Generation 355 has ChiSquare: -65779.000000
Generation 356 has ChiSquare: -65779.000000
Generation 357 has ChiSquare: -65779.000000
Generation 358 has ChiSquare: -65779.000000
Generation 359 has ChiSquare: -65779.000000
Generation 360 has ChiSquare: -65779.000000
Generation 360 has fit parameters:
[299.0, 500.0, 87.0, 300.0, 198.0, 229.0, 97.0, 596.0, 12.0, 43.0]
Generation 361 has ChiSquare: -65888.000000
Generation 362 has ChiSquare: -65888.000000
Generation 363 has ChiSquare: -65888.000000
Generation 364 has ChiSquare: -65888.000000
Generation 365 has ChiSquare: -65888.000000
Generation 366 has ChiSquare: -65888.000000
Generation 367 has ChiSquare: -65895.000000
Generation 368 has ChiSquare: -65895.000000
Generation 369 has ChiSquare: -65895.000000
Generation 370 has ChiSquare: -65895.000000
Generation 370 has fit parameters:
[300.0, 500.0, 50.0, 300.0, 198.0, 231.0, 99.0, 599.0, 12.0, 49.0]
Generation 371 has ChiSquare: -65895.000000
Generation 372 has ChiSquare: -65895.000000
Generation 373 has ChiSquare: -65895.000000
Generation 374 has ChiSquare: -65895.000000
Generation 375 has ChiSquare: -65895.000000
Generation 376 has ChiSquare: -65895.000000
Generation 377 has ChiSquare: -65895.000000
Generation 378 has ChiSquare: -65895.000000
Generation 379 has ChiSquare: -65895.000000
Generation 380 has ChiSquare: -65895.000000
Generation 380 has fit parameters:
[300.0, 500.0, 50.0, 300.0, 198.0, 231.0, 99.0, 599.0, 12.0, 49.0]
Generation 381 has ChiSquare: -65895.000000
Generation 382 has ChiSquare: -65895.000000
Generation 383 has ChiSquare: -65895.000000
Generation 384 has ChiSquare: -65895.000000
Generation 385 has ChiSquare: -65895.000000
Generation 386 has ChiSquare: -65895.000000
Generation 387 has ChiSquare: -65895.000000
Generation 388 has ChiSquare: -65895.000000
Generation 389 has ChiSquare: -65895.000000
Generation 390 has ChiSquare: -65895.000000
Generation 390 has fit parameters:
[300.0, 500.0, 50.0, 300.0, 198.0, 231.0, 99.0, 599.0, 12.0, 49.0]
Generation 391 has ChiSquare: -65895.000000
Generation 392 has ChiSquare: -65895.000000
Generation 393 has ChiSquare: -65895.000000
Generation 394 has ChiSquare: -65895.000000
Generation 395 has ChiSquare: -65895.000000
Generation 396 has ChiSquare: -65966.000000
Generation 397 has ChiSquare: -65966.000000
Generation 398 has ChiSquare: -65966.000000
Generation 399 has ChiSquare: -65966.000000
Generation 400 has ChiSquare: -65966.000000
Generation 400 has fit parameters:
[299.0, 499.0, 21.0, 299.0, 200.0, 249.0, 100.0, 597.0, 2.0, 50.0]
Generation 401 has ChiSquare: -65966.000000
Generation 402 has ChiSquare: -65966.000000
Generation 403 has ChiSquare: -65966.000000
Generation 404 has ChiSquare: -65966.000000
Generation 405 has ChiSquare: -65966.000000
Generation 406 has ChiSquare: -65966.000000
Generation 407 has ChiSquare: -65966.000000
Generation 408 has ChiSquare: -65966.000000
Generation 409 has ChiSquare: -65966.000000
Generation 410 has ChiSquare: -65966.000000
Generation 410 has fit parameters:
[299.0, 499.0, 21.0, 299.0, 200.0, 249.0, 100.0, 597.0, 2.0, 50.0]
Generation 411 has ChiSquare: -65966.000000
Generation 412 has ChiSquare: -65966.000000
Generation 413 has ChiSquare: -65966.000000
Generation 414 has ChiSquare: -65966.000000
Generation 415 has ChiSquare: -65966.000000
Generation 416 has ChiSquare: -65966.000000
Generation 417 has ChiSquare: -65966.000000
Generation 418 has ChiSquare: -65966.000000
Generation 419 has ChiSquare: -65966.000000
Generation 420 has ChiSquare: -65966.000000
Generation 420 has fit parameters:
[299.0, 499.0, 21.0, 299.0, 200.0, 249.0, 100.0, 597.0, 2.0, 50.0]
Generation 421 has ChiSquare: -65966.000000
Generation 422 has ChiSquare: -65966.000000
Generation 423 has ChiSquare: -65966.000000
Generation 424 has ChiSquare: -65966.000000
Generation 425 has ChiSquare: -65966.000000
Generation 426 has ChiSquare: -65966.000000
Generation 427 has ChiSquare: -65966.000000
Generation 428 has ChiSquare: -65966.000000
Generation 429 has ChiSquare: -65966.000000
Generation 430 has ChiSquare: -65966.000000
Generation 430 has fit parameters:
[299.0, 499.0, 21.0, 299.0, 200.0, 249.0, 100.0, 597.0, 2.0, 50.0]
Generation 431 has ChiSquare: -65966.000000
Generation 432 has ChiSquare: -65966.000000
Generation 433 has ChiSquare: -65966.000000
Generation 434 has ChiSquare: -65966.000000
Generation 435 has ChiSquare: -65966.000000
Generation 436 has ChiSquare: -65966.000000
Generation 437 has ChiSquare: -65966.000000
Generation 438 has ChiSquare: -65966.000000
Generation 439 has ChiSquare: -65966.000000
Generation 440 has ChiSquare: -65966.000000
Generation 440 has fit parameters:
[299.0, 499.0, 21.0, 299.0, 200.0, 249.0, 100.0, 597.0, 2.0, 50.0]
Generation 441 has ChiSquare: -65966.000000
Generation 442 has ChiSquare: -65966.000000
Generation 443 has ChiSquare: -65966.000000
Generation 444 has ChiSquare: -65966.000000
Generation 445 has ChiSquare: -65966.000000
STOP("ChangeOverGeneration with {'tolerance': 0.0001, 'generations': 50}")
Optimization terminated successfully.
Current function value: -65966.000000
Iterations: 445
Function evaluations: 178400
max profit: 65966.0
load: 74991.0 <= 75000
spend: 317337.0 <= 350000
item 0: 299.0
item 1: 499.0
item 2: 21.0
item 3: 299.0
item 4: 200.0
item 5: 249.0
item 6: 100.0
item 7: 597.0
item 8: 2.0
item 9: 50.0
这是我第一次尝试获得解决方案,并且未调整求解器,您可以看到可能仍有一些小的摆动空间需要改进,因为最后的收敛是尖锐而不是超级平滑 - 但是,我假设解决方案接近最优(基于约束检查)。我会尝试设置以及如何施加约束/惩罚,以查看解决方案是否可以进一步改进。