diff --git a/problem1-1终稿.ipynb b/problem1-1终稿.ipynb index e8ce878..7cb81ee 100644 --- a/problem1-1终稿.ipynb +++ b/problem1-1终稿.ipynb @@ -582,7 +582,7 @@ " for l in LandName:\n", " for y in years:\n", " for s in SeasonNum:\n", - " if is_feasible(c, l, y, s):\n", + " if is_feasible(c, l, y, s): # 最小面积约束和加强版01约束\n", " model += X[c, l, y, s] <= LandArea[l] * Y[c, l, y, s], f\"LandAreaConstraint_{c}_{l}_{y}_{s}\"\n", " model += X[c, l, y, s] >= min_area * (\n", " 1 if Y[c, l, y, s] else 0), f\"MinAreaConstraint_{c}_{l}_{y}_{s}\"" @@ -611,7 +611,7 @@ " X[c, l, y, s] * unit_profit_lsc[LandType[l[0]]][s][c]\n", " for l in LandName for s in SeasonNum if is_feasible(c, l, y, s)\n", " )\n", - " \n", + "\n", " # 惩罚超过需求的部分:将每个地块、每个季节的单位成本与种植量相乘\n", " penalty_term = lpSum(\n", " X[c, l, y, s] * unit_cost_lsc[LandType[l[0]]][s][c]\n", @@ -620,7 +620,7 @@ " unit_cost_lsc[LandType[l[0]]][s][c]\n", " for l in LandName for s in SeasonNum if is_feasible(c, l, y, s)\n", " )\n", - " \n", + "\n", " # 累积到总目标函数中\n", " total_profit += profit_term - penalty_term\n", "\n", @@ -631,26 +631,6 @@ "outputs": [], "execution_count": 25 }, - { - "metadata": { - "ExecuteTime": { - "end_time": "2024-09-08T08:14:19.193505Z", - "start_time": "2024-09-08T08:14:19.178490Z" - } - }, - "cell_type": "code", - "source": [ - "# # 添加需求约束\n", - "# for c in CropName:\n", - "# for y in years:\n", - "# model += lpSum(\n", - "# X[c, l, y, s] for l in LandName for s in SeasonNum if is_feasible(c, l, y, s)\n", - "# ) <= crop_demand[c] + Excess[c, y], f\"demand_constraint_{c}_{y}\"" - ], - "id": "a2fe5874538f1596", - "outputs": [], - "execution_count": 26 - }, { "cell_type": "code", "id": "7e13de7700d38f19", @@ -707,7 +687,7 @@ " if l[0] == \"D\":\n", " for y in years:\n", " for c in CropType[\"全蔬菜\"]:\n", - " if is_feasible(c,l,y,2):\n", + " if is_feasible(c, l, y, 2):\n", " model += Y[\"水稻\", l, y, 1] + Y[c, l, y, 2] <= 1, f\"IrrigatedConstraint0_{l}_{y}_{c}\"\n" ], "outputs": [],