Я запускаю приведенный ниже код несколько раз, но ошибка возникает примерно через 2000-8000 раз.
Ошибка возникает в «prob.solve ()»
Ubuntu 18.04 / 64 PuLP == 1.6.9
ВОТ МОЙ КОД:
def optimal_split(self, ratio = 0.5):
if (sum(self.game_state) == 1):
if (randint(1,100)<=50):
return self.game_state, [0]*(self.K+1)
else:
return [0]*(self.K+1), self.game_state
else:
prob = LpProblem("Optimal split",LpMinimize)
A = []
for i in range(self.K + 1):
A += LpVariable(str(i), 0, self.game_state[i], LpInteger)
prob += sum([2**(-(self.K - i)) * c for c, i in zip(A, range(self.K + 1))]) - ratio * self.potential(self.game_state), "Objective function"
prob += sum([2**(-(self.K - i)) * c for c, i in zip(A, range(self.K + 1))]) >= ratio * self.potential(self.game_state), "Constraint"
#prob.writeLP("test.lp")
prob.solve()
Abis = [0]*(self.K+1)
for v in prob.variables():
Abis[int(v.name)] = round(v.varValue)
B = [z - a for z, a in zip(self.game_state, Abis)]
return Abis, B