数值范围

(类来自 pyomo.core.base.range)

class pyomo.core.base.range.NumericRange(start, end, step, closed=(True, True))[source]

基础类:Mixin

数字范围的表示。

这个类表示一个连续的数字范围。该类模仿了Pyomo(不是 Python)的range API,具有开始、结束和步长。步长是一个有符号的整数。如果步长为0,则范围是连续的。结束包含在范围内。范围是闭合的,除非closed被指定为一个由两个布尔值组成的元组。只有连续的范围可以是开放的(或部分开放的)。

闭合范围不一定是严格有限的,因为允许End值为None(对于连续范围,Start值也允许为None)。

Parameters:
  • 开始 (float) – 此NumericRange的起始值

  • end (float) – 此NumericRange的最后一个值

  • step (int) – 值之间的间隔。0表示连续范围。负值表示向后走的离散范围。

  • closed (tuple of bool, optional) – 一个包含两个布尔值的元组,用于指示范围的开始和结束是否闭合。开放范围仅适用于连续的NumericRange对象。

__init__(start, end, step, closed=(True, True))[source]

方法

__init__(start, end, step[, closed])

isdiscrete()

isdisjoint(other)

isfinite()

issubset(other)

normalize_bounds()

规范化此NumericRange。

range_difference(other_ranges)

返回此范围与一系列其他范围之间的差异。

range_intersection(other_ranges)

返回此范围与一组其他范围之间的交集。

属性

start

end

step

closed

成员文档

normalize_bounds()[source]

规范化此NumericRange。

如果NumericRange的步长小于零,则通过反转lb和ub返回一个归一化的范围。如果lb和ub被反转,则closed将被更新以反映该变化。

Return type:

lb, ub, closed

range_difference(other_ranges)[source]

返回此范围与一系列其他范围之间的差异。

Parameters:

other_ranges (iterable) – 一个可迭代的其他范围对象,用于从此范围中减去

range_intersection(other_ranges)[source]

返回此范围与一组其他范围之间的交集。

Parameters:

other_ranges (iterable) – 一个可迭代的其他范围对象,用于与此范围相交