**“我正在尝试使用Gurobipy解决卡车调度问题,但是此错误导致“ Q矩阵不是正半定(PSD)”,尽管我的所有变量都不都是二次变量,并且目标函数是凸函数,请请注意,除了tns是输入****之外,s是一个参数(槽)。
from gurobipy import*
m = Model()
#model data
import xlrd
file_location = "C:/Users/Mohamed/Desktop/Service.xlsx"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_name("servicetime")
data = [[sheet.cell_value(r, c) for c in range(sheet.ncols)] for r in range(sheet.nrows)]
Trucks=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]
Slots=[1,2,3,4,5,6,7,8,9,10]
Areas=[1,2,3,4,5]
U=[1,2]
R=[1]
tin=[0.1667,0.3333,0.1667,0.3333,0.25]
tout=[0.1667,0.3333,0.1667,0.3333,0.25]
T=[0.75]
x,g,tin,tout,ta1a2,t,U,P,V,R,T={},{},{},{},{},{},{},{},{},{},{}
#define variables
for n in Trucks:
g[n]=m.addVar(vtype=GRB.INTEGER,name="g[%s]"%(n))
for a in Areas:
R[a]=m.addVar(vtype= GRB.INTEGER,name="R[%s]"%(a))
for a in Areas:
for s in Slots:
P[a,s]=m.addVar(vtype = GRB.INTEGER,name="P[%s,%s]"%(a,s))
for n in Trucks:
for a in Areas:
U[n,a]=m.addVar(vtype=GRB.INTEGER,name="U[%s,%s]"%(n,a))
for n in Trucks:
for a in Areas:
tin[n,a]=m.addVar(vtype=GRB.CONTINUOUS,name="tin[%s,%s]"%(n,a))
for n in Trucks:
tout[n,a]=m.addVar(vtype=GRB.CONTINUOUS,name="tout[%s,%s]"%(n,a))
for n in Trucks:
ta1a2[n]=m.addVar(vtype=GRB.SEMICONT,name="ta1a2[%s]"%(n))
for n in Trucks:
for s in Slots:
t[n,s]=m.addVar(vtype=GRB.CONTINUOUS,name="t[%s,%s]"%(n,s))
for s in Slots:
V[s]=m.addVar(vtype=GRB.INTEGER,name="V[%s]"%(s))
for n in Trucks:
for s in Slots:
x[n,s]=m.addVar(vtype=GRB.BINARY,name="x[%s,%s]"%(n,s))
#Each truck is served
for n in Trucks:
cont_1 = m.addConstr(quicksum(x[n,s] for s in Slots) == 1)
#Each truck is served after its arrival
for n in Trucks:
cont_2 = m.addConstr(quicksum(s*x[n,s] for s in Slots) >= g[n] + tin[n,a])
#Each is served in time less than one time slot
for n in Trucks:
cont_3 =(tin[n,a]+ta1a2[n]+ quicksum(t[n,s]*x[n,s] for s in Slots) + tout[n,a] <= T)
#availability of resources in each area and time slot
for a in Areas:
for s in Slots:
cont_4 =m.addConstr(quicksum(U[n,a]*x[n,s] for n in Trucks) <= P[a,s]*R[a])
#terminal truck capacity
for s in Slots:
cont_5=m.addConstr(quicksum(x[n,s] for n in Trucks) <= V[s])
#objective function
m.setObjective(quicksum((s*x[n,s])-g[n] for (n,s) in x),GRB.MINIMIZE)