-
-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bijectionist/improve init #39313
Merged
Merged
Bijectionist/improve init #39313
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,6 +357,7 @@ | |
sage: A = B = [permutation for n in range(4) for permutation in Permutations(n)] | ||
sage: tau = Permutation.longest_increasing_subsequence_length | ||
sage: bij = Bijectionist(A, B, tau, value_restrictions=((Permutation([1, 2]), [4, 5]),)) | ||
sage: next(bij.solutions_iterator()) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: no possible values found for singleton block [[1, 2]] | ||
|
@@ -494,7 +495,7 @@ | |
Check that large input sets are handled well:: | ||
|
||
sage: A = B = range(20000) | ||
sage: bij = Bijectionist(A, B) # long time | ||
sage: bij = Bijectionist(A, B) | ||
""" | ||
# glossary of standard letters: | ||
# A, B, Z, W ... finite sets | ||
|
@@ -612,7 +613,7 @@ | |
for a in p: | ||
self._P.union(p[0], a) | ||
|
||
self._compute_possible_block_values() | ||
self._possible_block_values = None | ||
|
||
def constant_blocks(self, singletons=False, optimal=False): | ||
r""" | ||
|
@@ -1093,8 +1094,7 @@ | |
if not self._possible_block_values[p]: | ||
if len(block) == 1: | ||
raise ValueError(f"no possible values found for singleton block {block}") | ||
else: | ||
raise ValueError(f"no possible values found for block {block}") | ||
raise ValueError(f"no possible values found for block {block}") | ||
|
||
def set_distributions(self, *elements_distributions): | ||
r""" | ||
|
@@ -1789,13 +1789,18 @@ | |
# veto new value and try again | ||
tmp_constraints.append(bmilp._x[p, solution[p]] == 0) | ||
|
||
# create dictionary to return | ||
possible_values = {} | ||
for p in blocks: | ||
for a in self._P.root_to_elements_dict()[p]: | ||
if optimal: | ||
# create dictionary to return | ||
possible_values = {} | ||
for p in blocks: | ||
for a in self._P.root_to_elements_dict()[p]: | ||
possible_values[a] = solutions[p] | ||
else: | ||
else: | ||
# create dictionary to return | ||
if self._possible_block_values is None: | ||
self._compute_possible_block_values() | ||
possible_values = {} | ||
for p in blocks: | ||
for a in self._P.root_to_elements_dict()[p]: | ||
possible_values[a] = self._possible_block_values[p] | ||
|
||
return possible_values | ||
|
@@ -2124,11 +2129,6 @@ | |
In particular, if `P` consists only if singletons, this | ||
method has no effect. | ||
|
||
.. TODO:: | ||
|
||
create one test with one and one test with two | ||
intertwining relations | ||
|
||
.. TODO:: | ||
|
||
it is not clear whether this method makes sense | ||
|
@@ -2144,6 +2144,17 @@ | |
sage: bij._P | ||
{{'a'}, {'b'}, {'c'}, {'d'}} | ||
|
||
However, adding that `'a'` and `'c'` are in the same block, | ||
we can infer that also `'b'` and `'d'` are in the same | ||
block:: | ||
|
||
sage: bij.set_constant_blocks([['a', 'c']]) | ||
sage: bij._P | ||
{{'a', 'c'}, {'b'}, {'d'}} | ||
sage: bij._preprocess_intertwining_relations() | ||
sage: bij._P | ||
{{'a', 'c'}, {'b', 'd'}} | ||
|
||
Let a group act on permutations:: | ||
|
||
sage: A = B = Permutations(3) | ||
|
@@ -2152,6 +2163,11 @@ | |
sage: bij._preprocess_intertwining_relations() | ||
sage: bij._P | ||
{{[1, 2, 3]}, {[1, 3, 2]}, {[2, 1, 3]}, {[2, 3, 1]}, {[3, 1, 2]}, {[3, 2, 1]}} | ||
|
||
Thus, in this case we do not detect the constant blocks:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also in #39310 |
||
|
||
sage: bij.constant_blocks(optimal=True) | ||
{{[1, 2, 3], [3, 2, 1]}, {[1, 3, 2], [2, 3, 1]}, {[2, 1, 3], [3, 1, 2]}} | ||
""" | ||
A = self._A | ||
P = self._P | ||
|
@@ -3119,7 +3135,7 @@ | |
sage: bij = Bijectionist(sum(As, []), sum(Bs, [])) | ||
sage: bij.set_statistics((lambda x: x[0], lambda x: x[0])) | ||
sage: bij.set_intertwining_relations((2, c1, c1), (1, c2, c2)) | ||
sage: l = list(bij.solutions_iterator()); len(l) # long time -- (2.7 seconds with SCIP on AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx) | ||
64 | ||
|
||
A brute force check would be difficult:: | ||
|
@@ -3147,7 +3163,7 @@ | |
sage: A = sum(As, []) | ||
sage: respects_c1 = lambda s: all(c1(a1, a2) not in A or s[c1(a1, a2)] == c1(s[a1], s[a2]) for a1 in A for a2 in A) | ||
sage: respects_c2 = lambda s: all(c2(a1) not in A or s[c2(a1)] == c2(s[a1]) for a1 in A) | ||
sage: l2 = [s for s in it if respects_c1(s) and respects_c2(s)] # long time -- (17 seconds on AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx) | ||
sage: sorted(l1, key=lambda s: tuple(s.items())) == l2 # long time | ||
True | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also in #39310
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I branched from the other PR.