我需要使用python
scipy
最大化网络的吞吐量
class optimization():
def __init__(self,nodes=nodes):
self.nodes = nodes
self.estimated_throughput_list=[] # list of throughputs
for i in self.nodes:
self.estimated_throughput_list.append(i.estimated_throughput) # adding for each node its throughput to the list
self.d= np.ones_like(self.nodes, dtype=bool) # creating a boolean matrix having the same dimensions of the estimated_throughput_list
def objective_function(self):
"""
Objective function to maximize the sum of Di * xi,
where Di is a binary variable that can take values of 0 or 1.
x is an array of values for the variables x1, x2, ..., xn,
and D is an array of values for the binary variables D1, D2, ..., Dn.
"""
return np.dot(self.d, self.estimated_throughput_list)
def constraint1(self):
summation=8* 0.5 # erlang
summation= summation+ np.dot(self.d, self.estimated_throughput_list)
return summation
def solution(self):
return linprog(c=self.nodes,A_ub=self.estimated_throughput_list,b_ub=[8* 0.5],method="revised simplex")
我有一个节点的全局列表,每个节点包含它的估计吞吐量,由estimated_throughput
表示
我试图解决的优化问题是由上传的figure:
optimzation problem提出的
为简单起见m *h^(-1)[PDR] is replaced by (8*0.5)
在main.py文件中,我只是调用函数:
opt=optimization()
print("obj:",opt.solution())
这是我第一次在python中应用优化,我不知道这是否是解决这类问题的方法。如果有人能在这个问题上进一步指导我,我将不胜感激。
结果是:c = np.array(c, dtype=np.float64, copy=True).squeeze() TypeError: float() argument must be a string or a real number, not 'myNode'
1条答案
按热度按时间wfypjpf41#
error的意思是错误的意思。如果你有一个类
myNode
,你不能把它作为scipy
方法的输入。在你的例子中,这可能发生在c=self.nodes
中,它有错误的符号和错误的类型。这很好用: