Skip to content

Commit 216699c

Browse files
committed
-
1 parent 5bd2943 commit 216699c

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

source_py3/python_toolbox/combi/comb_space.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ class CombSpace(PermSpace):
1010
1111
Every item in a `CombSpace` is a `Comb`.
1212
'''
13-
def __init__(self, iterable_or_length, n_elements, fixed_map=None,
14-
slice_=None, _domain_for_checking=None,
15-
_degrees_for_checking=None):
13+
def __init__(self, iterable_or_length, n_elements, slice_=None,
14+
_domain_for_checking=None, _degrees_for_checking=None):
1615
PermSpace.__init__(
1716
self, iterable_or_length=iterable_or_length, n_elements=n_elements,
18-
fixed_map=fixed_map, is_combination=True, slice_=slice_,
19-
domain=_domain_for_checking, degrees=_degrees_for_checking
17+
is_combination=True, slice_=slice_, domain=_domain_for_checking,
18+
degrees=_degrees_for_checking
2019
)
2120

2221

@@ -26,12 +25,11 @@ def __repr__(self):
2625
sequence_repr = \
2726
''.join((sequence_repr[:35], ' ... ', sequence_repr[-1]))
2827

29-
return '<%s: %s%s%s>%s' % (
28+
return '<%s: %s%s>%s' % (
3029
type(self).__name__,
3130
sequence_repr,
3231
(', n_elements=%s' % (self.n_elements,)) if self.is_partial
3332
else '',
34-
(', fixed_map=%s' % (self.fixed_map,)) if self.is_fixed else '',
3533
('[%s:%s]' % (self.slice_.start, self.slice_.stop)) if
3634
self.is_sliced else ''
3735
)

source_py3/python_toolbox/combi/perm_space.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ def __call__(cls, *args, **kwargs):
4646
from .comb_space import CombSpace
4747
arguments_profile = python_toolbox.arguments_profiling. \
4848
ArgumentsProfile(PermSpace.__init__, None, *args, **kwargs)
49-
# if arguments_profile.get('fixed_map', None):
50-
# raise UnallowedVariationSelectionException(
51-
# {variations.Variation.FIXED: True,
52-
# variations.Variation.COMBINATION: True,}
53-
# )
49+
if arguments_profile.get('fixed_map', None):
50+
raise UnallowedVariationSelectionException(
51+
{variations.Variation.FIXED: True,
52+
variations.Variation.COMBINATION: True,}
53+
)
5454
return super(PermSpaceType, CombSpace).__call__(
5555
iterable_or_length=arguments_profile['iterable_or_length'],
5656
n_elements=arguments_profile['n_elements'],
57-
fixed_map=arguments_profile['fixed_map'],
5857
slice_=arguments_profile['slice_'],
5958
_domain_for_checking=arguments_profile['domain'],
6059
_degrees_for_checking=arguments_profile['degrees'],
@@ -582,12 +581,37 @@ def __getitem__(self, i):
582581
(value in reserved_values and available_values.count(value)
583582
== reserved_values.count(value)))):
584583
wip_perm_sequence_dict[j] = unused_value
584+
585+
###########################################################
586+
# #
587+
# Tricky thing here: Trying to put as much as we can in a
588+
# sequence head that'll shorten the sequence we'll give to
589+
# the candidate space instead of using a fixed map, if
590+
# possible. This is crucial for `CombSpace` which can't use
591+
# `fixed_map`.
592+
head = []
593+
fixed_map_to_use = dict(wip_perm_sequence_dict)
594+
n_elements_to_use = self.n_elements
595+
for i in sequence_tools.CuteRange(infinity):
596+
try:
597+
head.append(wip_perm_sequence_dict[i])
598+
except KeyError:
599+
break
600+
else:
601+
del wip_perm_sequence_dict[i]
602+
n_elements_to_use -= 1
603+
sequence_to_use = list(self.sequence)
604+
for item in head:
605+
sequence_to_use.remove(item)
606+
585607
candidate_sub_perm_space = PermSpace(
586-
self.sequence,
587-
n_elements=self.n_elements,
588-
fixed_map=wip_perm_sequence_dict,
608+
sequence_to_use,
609+
n_elements=n_elements_to_use,
610+
fixed_map=fixed_map_to_use,
589611
is_combination=self.is_combination
590612
)
613+
# #
614+
###########################################################
591615

592616
if wip_i < candidate_sub_perm_space.length:
593617
available_values.remove(unused_value)

source_py3/python_toolbox/combi/variations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Variation(nifty_collections.CuteEnum):
4343
{Variation.DEGREED: True, Variation.COMBINATION: True,},
4444
{Variation.DEGREED: True, Variation.PARTIAL: True,},
4545
{Variation.DEGREED: True, Variation.RECURRENT: True,},
46-
# {Variation.COMBINATION: True, Variation.FIXED: True,},
46+
{Variation.COMBINATION: True, Variation.FIXED: True,},
4747
{Variation.RAPPLIED: False, Variation.RECURRENT: True,},
4848
)
4949

0 commit comments

Comments
 (0)