Может кто-нибудь исправить меня, что не так в этом коде?
Я пытаюсь написать ограничение, как показано на рисунке.
Но повышение TypeError
<ipython-input-189-be5360af354c> in <module>()
1 balance_energy = m.addConstrs((quicksum(electricity_demand[t, u, app, task] * x[t, u, app, task] + gas_demand[t, u, app, task] * y[t, u, app, task]+ hotwater_demand[t, u, app, task] * z[t, u, app, task] for t in time_slots) ==
2 (task_electricity_req[app][task] + task_gas_req[app][task] + task_hotwater_req[app][task])
----> 3 for u in users for app in appliances for task in task_appliances[app]), name = "balance_energy")
4
model.pxi in gurobipy.Model.addConstrs (../../src/python/gurobipy.c:89287)()
<ipython-input-189-be5360af354c> in <genexpr>(.0)
1 balance_energy = m.addConstrs((quicksum(electricity_demand[t, u, app, task] * x[t, u, app, task] + gas_demand[t, u, app, task] * y[t, u, app, task]+ hotwater_demand[t, u, app, task] * z[t, u, app, task] for t in time_slots) ==
2 (task_electricity_req[app][task] + task_gas_req[app][task] + task_hotwater_req[app][task])
----> 3 for u in users for app in appliances for task in task_appliances[app]), name = "balance_energy")
4
TypeError: must be str, not int
Я пробовал это до сих пор
balance_energy = m.addConstrs((quicksum(
electricity_demand[t, u, app, task] * x[t, u, app, task]
+ gas_demand[t, u, app, task] * y[t, u, app, task]
+ hotwater_demand[t, u, app, task] * z[t, u, app, task]
for t in time_slots) ==
(task_electricity_req[app][task]
+ task_gas_req[app][task]
+ task_hotwater_req[app][task])
for u in users for app in appliances for task in task_appliances[app]),
name = "balance_energy")
Здесь Непрерывные переменные
electricity_demand[t, u, app, task]
gas_demand[t, u, app, task]
hotwater_demand[t, u, app, task]
Двоичные переменные
x[t, u, app, task]
y[t, u, app, task]
z[t, u, app, task]
Параметры: Словарь, содержащий целочисленное значение
task_electricity_req[app][task]
task_gas_req[app][task]
task_hotwater_req[app][task]
Решение: Выполнение описанного ниже трюка решило мою проблему.
balance_energy = m.addConstrs((quicksum(electricity_demand[t, u, app, task] * x[t, u, app, task]
+ gas_demand[t, u, app, task] * y[t, u, app, task]
+ hotwater_demand[t, u, app, task] * z[t, u, app, task] for t in time_slots) ==
(float(task_electricity_req[app][task]) + float(task_gas_req[app][task]) + float(task_hotwater_req[app][task]))
for u in users for app in appliances for task in task_appliances[app]), name = "balance_energy")
Спасибо