•  Gurobi Staff

Hi,

Could you please clarify what type your variables have? For example, which ones are Gurobi model variables, and which are constants? Or, better yet, provide a self-contained code example so we can see what is what.

Silke

•   Hi,

Please find the definition of the parameters and variables below:

# Parametersnum_region = 5 #number of regions, including depotnum_period = 2 #number of planning periodsregions = []for i in range(num_region):    regions.append(i)periods = []for i in range(num_period):    periods.append(i+1) # periods = [1, 2, ...]depot = regionsrate = 1 # detection rate of UAVsdivisor = 10 # used to trun S to S_init; S = divisor*S_initminn = 0 # minimum search time/divisor      maxx = int(dur/divisor) # maximum search time/divisorpeople = {depot: 0} #number of people who need help in each regionfor i in [reg for reg in regions if reg != depot]:    people[i] = random.randint(50, 100)weights = list(np.linspace(0,1, num_period+1))weights.sort(reverse=True)  # victims prefer to be visited during the earlier periodsw = {} #periods' discount weightsfor i in periods:    w[i] = weights[i]# additional linearization parametersQ_1 = []for i in range(minn, maxx+1):    Q_1.append(divisor*i)Q_2 = {}for t in [per for per in periods if per != periods]:    Q_2[t] = []    for i in range(minn, maxx*(t-1)+1):        Q_2[t].append(divisor*i)Q_3 = {}for t in [per for per in periods if per != periods]:    Q_3[t] = []    for i in range(minn, maxx*(t)+1):        Q_3[t].append(divisor*i)# Create modelmodel = Model("linear")# Create the variables# additional linearization variablesgamma_1 = {}for i in [reg for reg in regions if reg != depot]:    for q in Q_1:        gamma_1[i, q] = model.addVar(vtype=GRB.BINARY, name="gamma_1_%s,%s" %(i,q))gamma_2 = {}for i in [reg for reg in regions if reg != depot]:    for t in [per for per in periods if per != periods]:        for q in Q_2[t]:            gamma_2[i, t, q] = model.addVar(vtype=GRB.BINARY, name="gamma_2_%s,%s,%s" %(i, t, q))gamma_3 = {}for i in [reg for reg in regions if reg != depot]:    for t in [per for per in periods if per != periods]:        for q in Q_3[t]:            gamma_3[i, t, q] = model.addVar(vtype=GRB.BINARY, name="gamma_3_%s,%s,%s" %(i, t, q))
•  Gurobi Staff

Hi,

Thanks for posting your code. This looks as though some of the parentheses may be misplaced. Your objective expression is pretty long and convoluted. Maybe different formatting can help break this up a bit and make it easier to parse (and maintain). E.g.:

obj = quicksum(        people[i]*(1-            quicksum(math.exp(-rate*q)*gamma_1[i,q] for q in Q_1)        )         for i in regions if i != depot    ) + quicksum(        w[t]*(            quicksum(                people[i]*(                    quicksum((-rate*q)*gamma_2[i,t,q] for q in Q_2[t])                    - quicksum((-rate*q)*gamma_3[i,t,q] for q in Q_3[t])                )                 for i in regions if i != depot            )        )         for t in periods if t != periods    )

In this code, I moved one of the closing parenthesis before "for i in regions if i != depot" behind this expression. Now I don't get the error.

Silke

•   Hi Silke,

Thank you! My problem is resolved!