如何使用CPLEX中的决策变量使用地板功能? TypeError:必须是实际数字,而不是Linearexpr
我正在解决Python中DOCPLEX的优化问题。我想使用Math.dloor函数将决策变量X1 [a]的值舍入至最接近的数字,并带有1/6步。
我定义了一个名为iNCETE_TIME(x,a)的函数。我使用此功能将X1 [a]离散化,这是一个决策变量。
但是我收到“ TypeError:必须是实际数字,而不是线性元素”。
Ayone是否知道如何解决此错误?如何在决策变量上使用地板功能?
事先感谢您的帮助!
def discret_time(x,a): #x = time in hours, a = length of dicretization steps in hours for example a = 1/6 means discretization in 1/6 hour intervals
return math.floor(x/a)*a
labels = ['home', 'study', 'work']
x1 = m.continuous_var_dict(labels, lb = 0, name = 'x1') #start time
for a in labels:
discret_start_a1 = discret_time(x1[a], 1/6)
I am solving an optimization problem with docplex in python. I want to use the math.floor function to round down the value of a decision variable x1[a] to the nearest number with 1/6 steps.
I have defined a function named discrete_time(x,a). I use this function to discretize x1[a] which is a decision variable.
But I receive "TypeError: must be real number, not LinearExpr."
Does ayone know how can I solve this error and how can I use floor function on a decision variable?
Thanks in advance for your help!
def discret_time(x,a): #x = time in hours, a = length of dicretization steps in hours for example a = 1/6 means discretization in 1/6 hour intervals
return math.floor(x/a)*a
labels = ['home', 'study', 'work']
x1 = m.continuous_var_dict(labels, lb = 0, name = 'x1') #start time
for a in labels:
discret_start_a1 = discret_time(x1[a], 1/6)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的
iNCETE_TIME()
更改为:[或]
Math.floor()期望仅整数类型。
Change your
discrete_time()
to:[OR]
math.floor() expects only integer type.
您应该地板应该
查看
You should linéarize floor
See example