Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6d7ab9c
initial commit
mantepse Oct 18, 2022
6149eb2
make the linter happier
mantepse Oct 18, 2022
9d4bfb9
remove useless assignment
mantepse Oct 18, 2022
6ee34e1
make initialisation more efficient
mantepse Oct 18, 2022
1a14bcf
consistently name variable
mantepse Oct 18, 2022
0901ec7
slightly improve documentation
mantepse Oct 19, 2022
c39d653
non-copying intersection, to save memory when there are almost no res…
mantepse Nov 2, 2022
2f0bb0e
Merge branch 'develop' of trac.sagemath.org:sage into t/33238/a_bijec…
mantepse Dec 5, 2022
321ba43
start to cache solutions
mantepse Dec 5, 2022
306395c
finish implementation of cache
mantepse Dec 21, 2022
1a8e564
Merge branch 'develop' of trac.sagemath.org:sage into t/33238/a_bijec…
mantepse Dec 21, 2022
1ac0978
add some documentation and doctests, slightly simplify code
mantepse Dec 21, 2022
47945ac
add missing documentation in table of contents
mantepse Dec 22, 2022
19c3d8f
mark doctests as long, slightly simplify logic
mantepse Dec 22, 2022
eca857e
slightly simplify, more doctests
mantepse Dec 22, 2022
a04d146
doctest _find_counter_example
mantepse Dec 22, 2022
3508426
doctest add_distribution_constraints and add_intertwing_relation_cons…
mantepse Dec 22, 2022
0ac618c
doctest _preprocess_intertwining_relations, _solution, _show_bmilp, _…
mantepse Dec 22, 2022
d50b62c
expand docstring of main class
mantepse Dec 23, 2022
288e391
copy milp instead of adding and removing constraints
mantepse Dec 23, 2022
d57c8e5
derandomize a test, mark example as random
mantepse Dec 23, 2022
7353fb5
correct typo, remove useless assignment
mantepse Dec 23, 2022
db850f0
add and remove constraints instead of copying the whole program
mantepse Dec 23, 2022
ec3271c
fix problem with SCIP, add timings
mantepse Dec 23, 2022
dfdc6ba
use convert for MixedIntegerLinearProgram.get_values
mantepse Dec 24, 2022
d0836cb
include information on MILP also in public documentation
mantepse Dec 25, 2022
563af98
remove unnecessary copy
mantepse Dec 25, 2022
590bae2
add possibility to constrain to involutions
mantepse Dec 26, 2022
da0655b
correct indentation
mantepse Dec 26, 2022
03b1fb8
better handling of empty constraints
mantepse Dec 29, 2022
a3364de
move _show to the _BijectionistMILP class
mantepse Dec 29, 2022
9d83a6c
remove unused code for backends that do not support removing constraints
mantepse Dec 30, 2022
864029d
make _solution a public method of _BijectionistMILP, simplify solve
mantepse Dec 30, 2022
64101a8
eliminate _initialize_new_bmilp
mantepse Dec 30, 2022
2d34911
slightly simplify logic of _forced_constant_blocks, use defaultdict
mantepse Dec 30, 2022
c2f0062
slight simplification
mantepse Dec 30, 2022
78968ae
copy (instead of deepcopy) should be correct
mantepse Dec 31, 2022
6ddaeae
slightly simplify _preprocess_intertwining_relations
mantepse Dec 31, 2022
60286e6
slightly improve non_copying_intersection
mantepse Dec 31, 2022
c38f5b9
add some internal documentation
mantepse Dec 31, 2022
6fb06f0
untangle _preprocess_intertwining_relations
mantepse Jan 2, 2023
706056e
add possibility to require a homomesy
mantepse Jan 2, 2023
d8a0663
Merge branch 'u/mantepse/mixedintegerlinearprogram_add_constraint__re…
mantepse Jan 2, 2023
4e90280
Merge branch 'u/mantepse/allow_to_remove_no_constraints' of trac.sage…
mantepse Jan 2, 2023
65b0c4a
preserve the cache of solutions after computing the optimal constant …
mantepse Jan 2, 2023
21cb54f
make _BijectionistMILP.solution the only entrypoint
mantepse Jan 3, 2023
a573bb4
remove unnecessary calls to list in doctests
mantepse Jan 3, 2023
6868261
move iterator over all solutions to _BijectionistMILP
mantepse Jan 3, 2023
61e97bc
merge _solve, solution and __iter__
mantepse Jan 4, 2023
db8947b
pycodestyle stuff
mantepse Jan 4, 2023
9678717
Merge branch 'develop' of trac.sagemath.org:sage into t/33238/a_bijec…
mantepse Jan 20, 2023
53506aa
rename pseudo_inverse to quadratic
mantepse Jan 20, 2023
d61c630
Merge branch 'u/mantepse/a_bijectionist_s_toolkit' of https://github.…
mantepse Feb 10, 2023
fefe54a
Merge branch 'develop' of github.com:sagemath/sage into develop
mantepse Feb 10, 2023
31bfb69
fix docstrings, simplify some tests
mantepse Feb 11, 2023
24e4084
change lambda to def
mantepse Feb 11, 2023
e7e063d
Merge branch 'develop' into develop
mantepse Feb 13, 2023
dc3009a
reviewer's suggestions
mantepse Feb 13, 2023
a457b99
Merge branch 'develop' of github.com:mantepse/sage into develop
mantepse Feb 13, 2023
6a738b6
Merge branch 'develop' into develop
mantepse Feb 13, 2023
cb2c82a
Merge branch 'develop' into develop
mantepse Feb 20, 2023
109f9e4
Merge branch 'develop' into develop
mantepse Mar 11, 2023
f87c437
sort result of doctest to avoid random failures
mantepse Mar 11, 2023
a72bd65
Merge pull request #1 from mantepse/bijectionist
mantepse Mar 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
non-copying intersection, to save memory when there are almost no res…
…trictions on the values of a block
  • Loading branch information
mantepse committed Nov 2, 2022
commit c39d653071d1d00b73fca4bf961bab8d4a7ba360
51 changes: 39 additions & 12 deletions src/sage/combinat/bijectionist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
# subdistributions with "smallest" (e.g., in the sorting order
# defined above) elements first?

# Priorities:

# 1) for an all-knowing user, code should be as fast as possible
# 2) code should be easy to understand
# 3) anticipate that a user computes things in a bad order

r"""
A bijectionist's toolkit

Expand Down Expand Up @@ -492,7 +498,7 @@ def __init__(self, A, B, tau=None, alpha_beta=tuple(), P=[], pi_rho=tuple(), ele

Check that large input sets are handled well::

sage: A = B = list(range(7000))
sage: A = B = list(range(20000))
sage: bij = Bijectionist(A, B)
"""
# glossary of standard letters:
Expand Down Expand Up @@ -1062,19 +1068,13 @@ def _compute_possible_block_values(self):
r"""
Update the dictionary of possible values of each block.

This has to be called whenever `self._P` was modified.

.. TODO::

If `self._Z` is large, this is very memory expensive. In
this case it would be good if equal values of the dictionary
`self._possible_block_values` would share memory.

This has to be called whenever ``self._P`` was modified.
"""
self._possible_block_values = {} # P -> Power(Z)
for p, block in self._P.root_to_elements_dict().items():
self._possible_block_values[p] = set.intersection(*[self._restrictions_possible_values[a] for a in block],
*[self._statistics_possible_values[a] for a in block])
sets = ([self._restrictions_possible_values[a] for a in block]
+ [self._statistics_possible_values[a] for a in block])
self._possible_block_values[p] = _non_copying_intersection(sets)
if not self._possible_block_values[p]:
if len(block) == 1:
raise ValueError(f"No possible values found for singleton block {block}")
Expand Down Expand Up @@ -2435,7 +2435,6 @@ def _generate_and_solve_initial_bmilp(self):
r"""
Generate a ``_BijectionistMILP``, add all relevant constraints
and call ``MILP.solve()``.

"""
preimage_blocks = self._preprocess_intertwining_relations()
self._compute_possible_block_values()
Expand Down Expand Up @@ -2670,6 +2669,34 @@ def _disjoint_set_roots(d):
return d.root_to_elements_dict().keys()


def _non_copying_intersection(sets):
"""
Return the intersection of the sets.

If the intersection is equal to one of the sets, return this
set.

EXAMPLES::

sage: from sage.combinat.bijectionist import _non_copying_intersection
sage: A = set(range(7000)); B = set(range(8000));
sage: _non_copying_intersection([A, B]) is A
True

"""
sets = sorted(sets, key=len)
result = set.intersection(*sets)
n = len(result)
if n < len(sets[0]):
return result
for s in sets:
N = len(s)
if N > n:
return result
if s == result:
return s


"""
TESTS::

Expand Down