-
Notifications
You must be signed in to change notification settings - Fork 270
Closed
Description
"AssertionError" is raised when I run my program. I have checked my code time and again, but I just cannot find the bug. Can anyone help me out? You have my gratitude.
The code:
import numpy as np
from pyscipopt import Model, quicksum
def QP_model(A, w, c, name='QP'):
'''
min : x'Ax/2
s.t.: w'x <= c, 0 <= x <= 1
'''
n = len(A)
model = Model(name)
x = dict()
for i in range(n):
x[i] = model.addVar('x(%d)' % i, vtype='C', lb=0.0, ub=1.0)
model.addCons(quicksum(w[i]*x[i] for i in range(n)) <= c)
objfun = quicksum(A[i][j]*x[i]*x[j]/2 for i, j in np.ndindex(n, n))
model.setObjective(objfun, 'minimize')
model.data = x
return model
def main():
'''
Main interface.
'''
# data
A = np.random.rand(3, 3)
w = np.random.rand(3)
c = np.random.rand()
# model
model = QP_model(A, w, c)
model.optimize()
if __name__ == '__main__':
print('running...')
main()
The error message:
Traceback (most recent call last):
File "<ipython-input-50-4fc84a02b499>", line 1, in <module>
runfile('D:/Essays/QMKP/example/temp.py', wdir='D:/Essays/QMKP/example')
File "d:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "d:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "D:/Essays/QMKP/example/temp.py", line 41, in <module>
main()
File "D:/Essays/QMKP/example/temp.py", line 35, in main
model = QP_model(A, w, c)
File "D:/Essays/QMKP/example/temp.py", line 21, in QP_model
model.setObjective(objfun, 'minimize')
File "src\pyscipopt\scip.pyx", line 779, in pyscipopt.scip.Model.setObjective
AssertionError
N.B. I am using Anaconda3 and Windows 10.
Metadata
Metadata
Assignees
Labels
No labels