我是在 Python 中使用 Gekko 的新手。
当我运行以下代码时,我收到了这个错误:
Exception: @error: Vector Index
APM model error: problem with vector index
line number: 21
line string:
p2>((0+((0+((v1)*([54.54545455])))+((v3)*([45.45454545]))))+((0+((v2)*([54.5454
5455])))+((v4)*([45.45454545]))))
non-integer value: 45.4545454500000
STOPPING..
使用以下代码:
from gekko import GEKKO
def Optimization_Approach(Processing_Time_Remote,Total_Time_local,Total_Time_Remote,Total_Energy_Consumption_Local,Total_Energy_Consumption_Remote,parameters):
number_of_users=parameters.number_of_users
number_of_tasks=parameters.number_of_tasks
data_rate=parameters.available_data_rate
Input_Size_Task=parameters.input_size_for_task_users
Edge_Capability_Mobile=parameters.edge_capability_mobile_users
Bandwidth=data_rate*number_of_users # All available data rate
Edge_Server_Capability=parameters.edge_server_capability
Edge_Server_Caching_Storage=parameters.edge_server_storage_capability
#Create a python model object
m = GEKKO()
#define parameter
B = m.Param(value=Bandwidth)
F_c=m.Param(value=Edge_Server_Capability)
F_s=m.Param(value=Edge_Server_Caching_Storage)
#define Variables
x = m.Array(m.Var,(number_of_users,number_of_tasks))
y = m.Array(m.Var,(number_of_users,number_of_tasks))
#Constraint 1
m.Equation(B>=sum([sum([x[i][j]*data_rate for i in range(number_of_users)]) for j in range(number_of_tasks)]))
#Constraint 2
m.Equation(F_c>=sum([sum([x[i][j]*Edge_Capability_Mobile[i] for i in range(number_of_users)]) for j in range(number_of_tasks)]))
# Constraint 3
m.Equation(F_s>=sum([sum([x[i][j]*Input_Size_Task[i][j] for i in range(number_of_users)]) for j in range(number_of_tasks)]))
#define Objective
m.Obj(sum([sum([(y[i][j]*Processing_Time_Remote[i][j])+((1-y[i][j])*((1-x[i][j])*Total_Time_local+x[i][j]*Total_Time_Remote)) +((1-y[i][j])*((1-x[i][j])*Total_Energy_Consumption_Local+x[i][j]*Total_Energy_Consumption_Remote)) for i in range(number_of_users)]) for j in range(number_of_tasks)]))
#Solve Model
m.solve()
print('Results')
print(x)
print(y)
请问,谁能帮帮我?另外,如何使变量m.array
二进制?