Skip to content

Commit 6868261

Browse files
committed
move iterator over all solutions to _BijectionistMILP
1 parent a573bb4 commit 6868261

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src/sage/combinat/bijectionist.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2499,17 +2499,7 @@ def solutions_iterator(self):
24992499
"""
25002500
if self._bmilp is None:
25012501
self._bmilp = _BijectionistMILP(self)
2502-
bmilp = self._bmilp
2503-
index = 0
2504-
while True:
2505-
solution = bmilp.solution(False, [], index)
2506-
if solution is None:
2507-
return
2508-
index += 1
2509-
yield solution
2510-
if get_verbose() >= 2:
2511-
print("after vetoing")
2512-
bmilp.show(variables=False)
2502+
yield from self._bmilp
25132503

25142504

25152505
class _BijectionistMILP():
@@ -2843,6 +2833,32 @@ def solution(self, on_blocks, constraints, index=0):
28432833
break
28442834
return mapping
28452835

2836+
def __iter__(self):
2837+
r"""
2838+
Iterate over all solutions of the MILP.
2839+
2840+
EXAMPLES::
2841+
2842+
sage: A = B = 'abc'
2843+
sage: bij = Bijectionist(A, B, lambda x: B.index(x) % 2, solver="GLPK")
2844+
sage: from sage.combinat.bijectionist import _BijectionistMILP
2845+
sage: list(_BijectionistMILP(bij))
2846+
[{'a': 0, 'b': 1, 'c': 0},
2847+
{'a': 1, 'b': 0, 'c': 0},
2848+
{'a': 0, 'b': 0, 'c': 1}]
2849+
2850+
"""
2851+
index = 0
2852+
while True:
2853+
solution = self.solution(False, [], index)
2854+
if solution is None:
2855+
return
2856+
index += 1
2857+
yield solution
2858+
if get_verbose() >= 2:
2859+
print("after vetoing")
2860+
self.show(variables=False)
2861+
28462862
def add_alpha_beta_constraints(self):
28472863
r"""
28482864
Add constraints enforcing that `(alpha, s)` is equidistributed

0 commit comments

Comments
 (0)