本文整理汇总了Python中pyomo.environ.ConcreteModel.rect_length方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.rect_length方法的具体用法?Python ConcreteModel.rect_length怎么用?Python ConcreteModel.rect_length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.rect_length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_rect_strip_packing_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import rect_length [as 别名]
def build_rect_strip_packing_model():
"""Build the strip packing model."""
model = ConcreteModel(name="Rectangles strip packing")
model.rectangles = Set(ordered=True, initialize=[0, 1, 2, 3, 4, 5, 6, 7])
# Width and Length of each rectangle
model.rect_width = Param(
model.rectangles, initialize={0: 3, 1: 3, 2: 2, 3: 2, 4: 3, 5: 5,
6: 7, 7: 7})
# parameter indexed by each rectangle
# same as height?
model.rect_length = Param(
model.rectangles, initialize={0: 4, 1: 3, 2: 2, 3: 2, 4: 3, 5: 3,
6: 4, 7: 4})
model.strip_width = Param(
initialize=10, doc="Available width of the strip")
# upperbound on length (default is sum of lengths of rectangles)
model.max_length = Param(
initialize=sum(model.rect_length[i] for i in model.rectangles),
doc="maximum length of the strip (if all rectangles were arranged "
"lengthwise)")
# x (length) and y (width) coordinates of each of the rectangles
model.x = Var(model.rectangles,
bounds=(0, model.max_length),
doc="rectangle corner x-position (position across length)")
def w_bounds(m, i):
return (0, m.strip_width - m.rect_width[i])
model.y = Var(model.rectangles,
bounds=w_bounds,
doc="rectangle corner y-position (position down width)")
model.strip_length = Var(
within=NonNegativeReals, doc="Length of strip required.")
def rec_pairs_filter(model, i, j):
return i < j
model.overlap_pairs = Set(
initialize=model.rectangles * model.rectangles,
dimen=2, filter=rec_pairs_filter,
doc="set of possible rectangle conflicts")
@model.Constraint(model.rectangles)
def strip_ends_after_last_rec(model, i):
return model.strip_length >= model.x[i] + model.rect_length[i]
model.total_length = Objective(expr=model.strip_length,
doc="Minimize length")
@model.Disjunction(
model.overlap_pairs,
doc="Make sure that none of the rectangles on the strip overlap in "
"either the x or y dimensions.")
def no_overlap(m, i, j):
return [
m.x[i] + m.rect_length[i] <= m.x[j],
m.x[j] + m.rect_length[j] <= m.x[i],
m.y[i] + m.rect_width[i] <= m.y[j],
m.y[j] + m.rect_width[j] <= m.y[i],
]
return model
示例2: build_constrained_layout_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import rect_length [as 别名]
def build_constrained_layout_model():
"""Build the model."""
m = ConcreteModel(name="2-D constrained layout")
m.rectangles = RangeSet(3, doc="Three rectangles")
m.circles = RangeSet(2, doc="Two circles")
m.rect_length = Param(
m.rectangles, initialize={1: 5, 2: 7, 3: 3},
doc="Rectangle length")
m.rect_height = Param(
m.rectangles, initialize={1: 6, 2: 5, 3: 3},
doc="Rectangle height")
m.circle_x = Param(m.circles, initialize={1: 15, 2: 50},
doc="x-coordinate of circle center")
m.circle_y = Param(m.circles, initialize={1: 10, 2: 80},
doc="y-coordinate of circle center")
m.circle_r = Param(m.circles, initialize={1: 6, 2: 5},
doc="radius of circle")
@m.Param(m.rectangles, doc="Minimum feasible x value for rectangle")
def x_min(m, rect):
return min(
m.circle_x[circ] - m.circle_r[circ] + m.rect_length[rect] / 2
for circ in m.circles)
@m.Param(m.rectangles, doc="Maximum feasible x value for rectangle")
def x_max(m, rect):
return max(
m.circle_x[circ] + m.circle_r[circ] - m.rect_length[rect] / 2
for circ in m.circles)
@m.Param(m.rectangles, doc="Minimum feasible y value for rectangle")
def y_min(m, rect):
return min(
m.circle_y[circ] - m.circle_r[circ] + m.rect_height[rect] / 2
for circ in m.circles)
@m.Param(m.rectangles, doc="Maximum feasible y value for rectangle")
def y_max(m, rect):
return max(
m.circle_y[circ] + m.circle_r[circ] - m.rect_height[rect] / 2
for circ in m.circles)
m.ordered_rect_pairs = Set(
initialize=m.rectangles * m.rectangles,
filter=lambda _, r1, r2: r1 != r2)
m.rect_pairs = Set(initialize=[
(r1, r2) for r1, r2 in m.ordered_rect_pairs
if r1 < r2])
m.rect_sep_penalty = Param(
m.rect_pairs, initialize={(1, 2): 300, (1, 3): 240, (2, 3): 100},
doc="Penalty for separation distance between two rectangles.")
def x_bounds(m, rect):
return m.x_min[rect], m.x_max[rect]
def y_bounds(m, rect):
return m.y_min[rect], m.y_max[rect]
m.rect_x = Var(
m.rectangles, doc="x-coordinate of rectangle center",
bounds=x_bounds)
m.rect_y = Var(
m.rectangles, doc="y-coordinate of rectangle center",
bounds=y_bounds)
m.dist_x = Var(
m.rect_pairs, doc="x-axis separation between rectangle pair")
m.dist_y = Var(
m.rect_pairs, doc="y-axis separation between rectangle pair")
m.min_dist_cost = Objective(
expr=sum(m.rect_sep_penalty[r1, r2] *
(m.dist_x[r1, r2] + m.dist_y[r1, r2])
for (r1, r2) in m.rect_pairs))
@m.Constraint(m.ordered_rect_pairs,
doc="x-distance between rectangles")
def dist_x_defn(m, r1, r2):
return m.dist_x[
tuple(sorted([r1, r2]))] >= m.rect_x[r2] - m.rect_x[r1]
@m.Constraint(m.ordered_rect_pairs,
doc="y-distance between rectangles")
def dist_y_defn(m, r1, r2):
return m.dist_y[
tuple(sorted([r1, r2]))] >= m.rect_y[r2] - m.rect_y[r1]
@m.Disjunction(
m.rect_pairs,
doc="Make sure that none of the rectangles overlap in "
"either the x or y dimensions.")
def no_overlap(m, r1, r2):
return [
m.rect_x[r1] + m.rect_length[r1] / 2 <= (
m.rect_x[r2] - m.rect_length[r2] / 2),
m.rect_y[r1] + m.rect_height[r1] / 2 <= (
m.rect_y[r2] - m.rect_height[r2] / 2),
m.rect_x[r2] + m.rect_length[r2] / 2 <= (
#.........这里部分代码省略.........