Python 古洛比:我怎样才能对一个变量的一部分求和呢?

Python 古洛比:我怎样才能对一个变量的一部分求和呢?,python,for-loop,matrix,constraints,gurobi,Python,For Loop,Matrix,Constraints,Gurobi,我有以下型号: from gurobipy import * n_units = 1 n_periods = 3 n_ageclasses = 4 units = range(1,n_units+1) periods = range(1,n_periods+1) periods_plus1 = periods[:] periods_plus1.append(max(periods_plus1)+1) ageclasses = range(1,n_ageclasses+1) nothicket

我有以下型号:

from gurobipy import *

n_units = 1
n_periods = 3
n_ageclasses = 4

units = range(1,n_units+1)
periods = range(1,n_periods+1)
periods_plus1 = periods[:]
periods_plus1.append(max(periods_plus1)+1)
ageclasses = range(1,n_ageclasses+1)
nothickets = ageclasses[1:]


model = Model('MPPM')

HARVEST = model.addVars(units, periods, nothickets, vtype=GRB.INTEGER, name="HARVEST")
FOREST = model.addVars(units, periods_plus1, ageclasses, vtype=GRB.INTEGER, name="FOREST")


model.addConstrs((quicksum(HARVEST[(k+1), (t+1), nothicket] for k in range(n_units) for t in range(n_periods) for nothicket in nothickets)  == FOREST[unit, period+1, 1] for unit in units for period in periods if period < max(periods_plus1)), name="A_Thicket")
有人能帮我重新制定这个约束吗?

这对我来说很有效:

 model.addConstrs((HARVEST.sum(unit, period, '*') == ...
这对我很有用:

 model.addConstrs((HARVEST.sum(unit, period, '*') == ...
 model.addConstrs((HARVEST.sum(unit, period, '*') == ...