Skip to content

Commit

Permalink
Simplify cardinality expression render (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtth authored May 24, 2023
1 parent f8b1022 commit 201eba2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions opvious/model/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,17 @@ class _CardinalityExpression(Expression):
domain: Domain

def render(self, _precedence=0) -> str:
with local_formatting_scope(self.domain.quantifiers):
return f"\\lvert \\{{ {self.domain.render()} \\}} \\rvert"
qs = self.domain.quantifiers
with local_formatting_scope(qs):
if len(qs) == 1 and self.domain.mask is None:
key = _quantifier_grouping_key(qs[0])
if isinstance(key, tuple):
sp = render_identifier(key[0], *key[1])
else:
sp = key.render()
else:
sp = f"\\{{ {self.domain.render()} \\}}"
return f"\\lvert {sp} \\rvert"


@dataclasses.dataclass(frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "opvious"
version = "0.12.0rc23"
version = "0.12.0rc24"
description = "Opvious Python SDK"
authors = ["Opvious Engineering <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def one_value_per_box(self):

class BinPacking(om.Model):
items = om.Dimension()
bins = om.interval(0, om.size(items), name="B")
bins = om.interval(1, om.size(items))

weight = om.Parameter.non_negative(items)
bin_max_weight = om.Parameter.non_negative()
Expand Down

0 comments on commit 201eba2

Please sign in to comment.