class DEA(object):
def __init__(self, DMUs_Name, X, Y, AP=False):
self.m1, self.m1_name, self.m2, self.m2_name, self.AP = X.shape[1, X.columns.tolist(), Y.shape[
1, Y.columns.tolist(), AP # shape 行数 columns.tolist列名
self.DMUs, self.X, self.Y = gurobipy.multidict(
{DMU: [X.loc[DMU.tolist(), Y.loc[DMU.tolist() for DMU in DMUs_Name})
print(f'DEA(AP={AP}) MODEL RUNING...')
def __CCR(self):
for k in self.DMUs:
MODEL = gurobipy.Model()
OE, lambdas, s_negitive, s_positive = MODEL.addVar(), MODEL.addVars(self.DMUs), MODEL.addVars(
self.m1), MODEL.addVars(self.m2)
MODEL.update()
MODEL.setObjectiveN(OE, index=0, priority=1)
MODEL.setObjectiveN(-(sum(s_negitive) + sum(s_positive)), index=1, priority=0)
MODEL.addConstrs(
gurobipy.quicksum(lambdas[i * self.X[i][j for i in self.DMUs if i != k or not self.AP) + s_negitive[
j == OE * self.X[k][j for j in range(self.m1))
MODEL.addConstrs(
gurobipy.quicksum(lambdas[i * self.Y[i][j for i in self.DMUs if i != k or not self.AP) - s_positive[
j == self.Y[k][j for j in range(self.m2))
MODEL.setParam('OutputFlag', 0)
MODEL.optimize()
self.Result.at[k, ('效益分析', '综合技术效益(CCR)') = MODEL.objVal
self.Result.at[k, ('规模报酬分析',
'有效性') = '非 DEA 有效' if MODEL.objVal < 1 else 'DEA 弱有效' if s_negitive.sum().getValue() + s_positive.sum().getValue() else 'DEA 强有效'
self.Result.at[k, ('规模报酬分析',
'类型') = '规模报酬固定' if lambdas.sum().getValue() == 1 else '规模报酬递增' if lambdas.sum().getValue() < 1 else '规模报酬递减'
for m in range(self.m1):
self.Result.at[k, ('差额变数分析', f'{self.m1_name[m]}') = s_negitive[m.X
self.Result.at[k, ('投入冗余率', f'{self.m1_name[m]}') = 'N/A' if self.X[k][m == 0 else s_negitive[m.X / \
self.X[k][m
for m in range(self.m2):
self.Result.at[k, ('差额变数分析', f'{self.m2_name[m]}') = s_positive[m.X
self.Result.at[k, ('产出不足率', f'{self.m2_name[m]}') = 'N/A' if self.Y[k][m == 0 else s_positive[m.X / \
self.Y[k][m
return self.Result
def __BCC(self):
for k in self.DMUs:
MODEL = gurobipy.Model()
TE, lambdas = MODEL.addVar(), MODEL.addVars(self.DMUs)
MODEL.update()
MODEL.setObjective(TE, sense=gurobipy.GRB.MINIMIZE)
MODEL.addConstrs(
gurobipy.quicksum(lambdas[i * self.X[i][j for i in self.DMUs if i != k or not self.AP) <= TE *
self.X[k][j for j in range(self.m1))
MODEL.addConstrs(
gurobipy.quicksum(lambdas[i * self.Y[i][j for i in self.DMUs if i != k or not self.AP) >= self.Y[k][j
for j in range(self.m2))
MODEL.addConstr(gurobipy.quicksum(lambdas[i for i in self.DMUs if i != k or not self.AP) == 1)
MODEL.setParam('OutputFlag', 0)
MODEL.optimize()
self.Result.at[
k, ('效益分析', '技术效益(BCC)') = MODEL.objVal if MODEL.status == gurobipy.GRB.Status.OPTIMAL else 'N/A'
return self.Result