Error executing code using PuLP: PulpSolverError

Asked 2 years ago, Updated 2 years ago, 20 views

Introduction to Python Graphic Filling Algorithm
http://www.orsj.or.jp/archive2/or63-12/or63_12_762.pdf

I am trying the following program (after the error comment) with reference to .n=11 works, but n=12 gets an error.Can you resolve the error?

error message

PulpSolverError Traceback (most recent call last)
<ipython-input-32-fb1f7af9cbf3>in<module>
     40 solver=PULP_CBC_CMD (presolve=1, fracGap=0, options=['maxsol10', maxSeconds=100)
     41 
--- > 42 status = m.solve (solver)
     43 
     44# Time measurement completed

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pulp\pulp.py in solution (self, solver, **kwargs)
   1669#timeit
   1670 self.solutionTime=-clock()
->1671 status=solver.actualSolve(self,**kwargs)
   1672self.solutionTime+=clock()
   1673self.restoreObjective (wasNone, dummyVar)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pulp\solvers.py in actualSolve (self, lp, **kwargs)
   1365 defaultSolve (self, lp, **kwargs):
   1366 "Solve a well-formed lp problem"
->1367 return self.solve_CBC(lp,**kwargs)
   1368 
   1369 def available (self):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\pulp\solvers.py in solution_CBC (self, lp, use_mps)
   1432pipe.close()
   1433 if notos.path.exists(tmpSol):
->1434 raise PulpSolverError ("Pulp: Error while executing" + self.path)
   1435 if use_mps:
   1436 lp.status, values, reducedCosts, shadowPrices, slacks=self.readsol_MPS(

PullSolverError: Pull: Error while executing C:\Users\mes83341\AppData\Local\Continuum\anaconda3\lib\site-packages\pulp\solverdir\cbc\win\32\cbc.exe

source code

from pull import*
import time
n = 11
w = [9.1, 4.2, 4.3, 7.4, 5.9, 5.8, 5.7, 5.6, 5.5, 7.5, 3.3, 2.5, 8.6, 1.5]
h = [4.1, 10.2, 9.3, 9.4, 10.5, 5.6, 5.7, 5.8, 5.9, 9.1, 4.2, 4.3, 7.4, 5.9, 5.8]
W = 20
UB = 50
m=LpProblem (sense=LpMinimize)

x = [LpVariable("x%d"%i, lowBound=0, upBound=W, cat='Integer') for i in range(n)]###
y = [LpVariable("y%d"%i, lowBound=0, upBound=UB, cat='Integer') for i in range(n)]###

u = [[LpVariable("u%d%d"%(i,j), cat=LpBinary) for jin range(n)] for i in range(n)]
v=[LpVariable("v%d%d"%(i,j), cat=LpBinary) for jin range(n)] for i in range(n)]
H=LpVariable("H")
m+ = H
for i in range(n):
  for jin range(n):
    m+=x[i]+w[i]<=x[j]+W*(1-u[i][j])
    m+=y[i]+h[i]<=y[j]+UB*(1-v[i][j])
    if <j:
      m+=u[i][j]+u[j][i]+v[i][j]+v[j][i]>=1
for i in range(n):
  m+=x[i]<=W-w[i]
  m+=y[i]<=H-h[i]

# start of time measurement
time_start = time.perf_counter()   
print(time_start)

solver=PULP_CBC_CMD (presolve=1, fracGap=0.5, options=['maxsol10', maxSeconds=100)  

status=m.solve(solver)

# completion of time measurement
time_stop = time.perf_counter()   
ttt = time_stop-time_start
print(ttt)

print("Obj:", value(m.objective))
print("Status", pull.LpStatus[status])

UB=value(m.objective)+1##############

for i in range(n):
  print("Box", i, ":", value(x[i]), value(y[i]))

import matplotlib.pyplot asplt

config=plt.figure()

ax=fig.add_subplot(111, expect='equal')

W1, H=W, UB
ax.set_xlim ([0,W1])

ax.set_ylim([0,H])

for i in range(n):

 a, b, c, d = value(x[i]), value(y[i]), w[i], h[i]

 rect=plt.Rectangle((a,b), c,d,fc="burlywood", ec="black")

 ax.add_patch(rect)

for i in range(n):
 a, b, c, d = value(x[i]), value(y[i]), w[i], h[i]
 rect=plt.Rectangle((a,b), c,d,fc="burlywood", ec="black")
 ax.add_patch(rect)
 ax.text((2*a+c)/2,(2*b+d)/2, i, size=8, color="blue")

config.savefig("picture.eps")

python

2022-09-30 10:27

2 Answers

I got a reply via a different route.

The reason was that the variable name was covered.
Both u(1,11) and u(11,1) will be u111. It will happen for the first time at n=12.
For example, if you change the code as shown below, it will work.
(Underscore (anything) between %d%d)

Original Code

u=[LpVariable("u%d%d"%(i,j), cat=LpBinary) for jin range(n)] for i in range(n)]
v=[LpVariable("v%d%d"%(i,j), cat=LpBinary) for jin range(n)] for i in range(n)]

Modified Code

u=[LpVariable("u%d_%d"%(i,j), cat=LpBinary) for jin range(n)] for i in range(n)]
v=[LpVariable("v%d_%d"%(i,j), cat=LpBinary) for jin range(n)] for i in range(n)]


2022-09-30 10:27

A list of variable names can be found in the code below.

 from collections import Counter
variables=[v.name for vin m.variables()]
counter=Counter(variables)
fork, vin counter.items():
    if v>1:
        print('Dupulate',k,v)


2022-09-30 10:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.