master > master: src - fct properties als radiobuttons
This commit is contained in:
parent
cbee2b33dd
commit
011fe1d9d9
@ -23,6 +23,21 @@ __all__ = [
|
|||||||
'FunctionDiagramWidget',
|
'FunctionDiagramWidget',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# EXPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
class FunctionProperty(Enum):
|
||||||
|
NOTHING = '—';
|
||||||
|
INJECTIVE = 'injektiv';
|
||||||
|
SURJECTIVE = 'surjektiv';
|
||||||
|
NOT_INJECTIVE = '¬ injektiv';
|
||||||
|
NOT_SURJECTIVE = '¬ surjektiv';
|
||||||
|
INJECTIVE_NOT_SURJECTIVE = 'injektiv + ¬ surjektiv';
|
||||||
|
NOT_INJECTIVE_SURJECTIVE = '¬ injektiv + surjektiv';
|
||||||
|
BOTH = 'injektiv + surjektiv';
|
||||||
|
NEITHER = '¬ injektiv + ¬ surjektiv';
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# Class
|
# Class
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -73,8 +88,9 @@ class FunctionDiagramWidget():
|
|||||||
|
|
||||||
def handler_plot(self, N: int, show_labels: bool, **kwargs):
|
def handler_plot(self, N: int, show_labels: bool, **kwargs):
|
||||||
cardinalities = [ kwargs[f'card_{k}'] for k in range(N+1)];
|
cardinalities = [ kwargs[f'card_{k}'] for k in range(N+1)];
|
||||||
injective = [ kwargs[f'injective_{k}'] for k in range(N)];
|
properties = [ option_to_property(kwargs[f'property_{k}']) for k in range(N)];
|
||||||
surjective = [ kwargs[f'surjective_{k}'] for k in range(N)];
|
injective = list(map(is_injective, properties));
|
||||||
|
surjective = list(map(is_surjective, properties));
|
||||||
X = [ XX[:card] for XX, card in zip(self.setsfrom, cardinalities) ];
|
X = [ XX[:card] for XX, card in zip(self.setsfrom, cardinalities) ];
|
||||||
comp = Functions(*[
|
comp = Functions(*[
|
||||||
Function(
|
Function(
|
||||||
@ -86,18 +102,18 @@ class FunctionDiagramWidget():
|
|||||||
for k in range(N)
|
for k in range(N)
|
||||||
]);
|
]);
|
||||||
fig, axs = comp.draw(show_labels=show_labels);
|
fig, axs = comp.draw(show_labels=show_labels);
|
||||||
# for k in range(N):
|
# # for k in range(N):
|
||||||
# [m, n] = cardinalities[k:][:2];
|
# # [m, n] = cardinalities[k:][:2];
|
||||||
# inj = injective[k];
|
# # inj = injective[k];
|
||||||
# surj = surjective[k];
|
# # surj = surjective[k];
|
||||||
# if m < n and surj:
|
# # if m < n and surj:
|
||||||
# print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht surjektiv sein');
|
# # print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht surjektiv sein');
|
||||||
# if m > n and inj:
|
# # if m > n and inj:
|
||||||
# print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht injektiv sein');
|
# # print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht injektiv sein');
|
||||||
# if n == 1 and not surj:
|
# # if n == 1 and not surj:
|
||||||
# print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht nicht-surjektiv sein');
|
# # print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht nicht-surjektiv sein');
|
||||||
# if m == 1 and not inj:
|
# # if m == 1 and not inj:
|
||||||
# print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht nicht-injektiv sein');
|
# # print(f'\x1b[1m{self.fnames[k]}\x1b[0m kann nicht nicht-injektiv sein');
|
||||||
return;
|
return;
|
||||||
|
|
||||||
def handler_wrapper(self, N: int):
|
def handler_wrapper(self, N: int):
|
||||||
@ -121,45 +137,19 @@ class FunctionDiagramWidget():
|
|||||||
)
|
)
|
||||||
for setname, XX in zip(self.setnames[:(N+1)], self.setsfrom[:(N+1)])
|
for setname, XX in zip(self.setnames[:(N+1)], self.setsfrom[:(N+1)])
|
||||||
];
|
];
|
||||||
controls_injective = [
|
controls_property = [
|
||||||
widgets.Checkbox(
|
widgets.RadioButtons(
|
||||||
value = False,
|
options = [e.value for e in FunctionProperty],
|
||||||
description = f'{fname} injektiv?',
|
value = FunctionProperty.NOTHING.value,
|
||||||
style = {
|
layout = {
|
||||||
'description_width': 'initial',
|
'description_width': 'initial',
|
||||||
|
'width': 'initial',
|
||||||
},
|
},
|
||||||
visible = True,
|
# description = f'Eigenschaften von {self.fnames[k]}',
|
||||||
|
disabled = False,
|
||||||
)
|
)
|
||||||
for fname in self.fnames[:N]
|
for k in range(N)
|
||||||
];
|
];
|
||||||
controls_surjective = [
|
|
||||||
widgets.Checkbox(
|
|
||||||
value = False,
|
|
||||||
description = f'{fname} surjectiv?',
|
|
||||||
style = {
|
|
||||||
'description_width': 'initial',
|
|
||||||
},
|
|
||||||
visible = True,
|
|
||||||
)
|
|
||||||
for fname in self.fnames[:N]
|
|
||||||
];
|
|
||||||
# controls_func = [None for _ in range(2*N)];
|
|
||||||
# controls_func[::2] = controls_injective;
|
|
||||||
# controls_func[1::2] = controls_surjective;
|
|
||||||
# controls_func = [
|
|
||||||
# widgets.RadioButtons(
|
|
||||||
# options = [ None, 'inj', 'surj', 'bij' ],
|
|
||||||
# # default:
|
|
||||||
# value = 'inj',
|
|
||||||
# layout = {
|
|
||||||
# 'description_width': 'initial',
|
|
||||||
# 'width': 'max-content',
|
|
||||||
# },
|
|
||||||
# description = f'{self.fnames[k]}',
|
|
||||||
# disabled = False,
|
|
||||||
# )
|
|
||||||
# for k in range(N)
|
|
||||||
# ];
|
|
||||||
ui = widgets.VBox(
|
ui = widgets.VBox(
|
||||||
[ button_refresh ] \
|
[ button_refresh ] \
|
||||||
+ [ button_show_labels ] \
|
+ [ button_show_labels ] \
|
||||||
@ -168,15 +158,19 @@ class FunctionDiagramWidget():
|
|||||||
widgets.HBox(
|
widgets.HBox(
|
||||||
[
|
[
|
||||||
widgets.VBox(
|
widgets.VBox(
|
||||||
[control_injective, control_surjective],
|
[
|
||||||
|
widgets.Text(f'Eigenschaften von {fname}'),
|
||||||
|
control_property
|
||||||
|
],
|
||||||
layout = {
|
layout = {
|
||||||
|
'description_width': 'initial',
|
||||||
|
'width': 'initial',
|
||||||
'display': 'flex',
|
'display': 'flex',
|
||||||
'align_items': 'stretch',
|
'align_items': 'stretch',
|
||||||
'width': '100%',
|
|
||||||
'overflow': 'hidden',
|
'overflow': 'hidden',
|
||||||
},
|
}
|
||||||
)
|
)
|
||||||
for control_injective, control_surjective in zip(controls_injective, controls_surjective)
|
for fname, control_property in zip(self.fnames[:N], controls_property)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@ -186,8 +180,33 @@ class FunctionDiagramWidget():
|
|||||||
f = self.handler_plot,
|
f = self.handler_plot,
|
||||||
controls = { 'N': control_nr, 'show_labels': button_show_labels } \
|
controls = { 'N': control_nr, 'show_labels': button_show_labels } \
|
||||||
| { f'card_{k}': controls_card[k] for k in range(N+1) } \
|
| { f'card_{k}': controls_card[k] for k in range(N+1) } \
|
||||||
| { f'injective_{k}': controls_injective[k] for k in range(N) } \
|
| { f'property_{k}': controls_property[k] for k in range(N) } \
|
||||||
| { f'surjective_{k}': controls_surjective[k] for k in range(N) } \
|
|
||||||
| { 'refresh': button_refresh }
|
| { 'refresh': button_refresh }
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# AUXILIARY METHODS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def option_to_property(option: str) -> Optional[FunctionProperty]:
|
||||||
|
try:
|
||||||
|
return FunctionProperty(option);
|
||||||
|
except:
|
||||||
|
return None;
|
||||||
|
|
||||||
|
def is_injective(property: Optional[FunctionProperty]) -> Optional[bool]:
|
||||||
|
match property:
|
||||||
|
case FunctionProperty.INJECTIVE | FunctionProperty.INJECTIVE_NOT_SURJECTIVE | FunctionProperty.BOTH:
|
||||||
|
return True;
|
||||||
|
case FunctionProperty.NOT_INJECTIVE | FunctionProperty.NOT_INJECTIVE_SURJECTIVE | FunctionProperty.NEITHER:
|
||||||
|
return False;
|
||||||
|
return None;
|
||||||
|
|
||||||
|
def is_surjective(property: Optional[FunctionProperty]) -> Optional[bool]:
|
||||||
|
match property:
|
||||||
|
case FunctionProperty.SURJECTIVE | FunctionProperty.NOT_INJECTIVE_SURJECTIVE | FunctionProperty.BOTH:
|
||||||
|
return True;
|
||||||
|
case FunctionProperty.NOT_SURJECTIVE | FunctionProperty.INJECTIVE_NOT_SURJECTIVE | FunctionProperty.NEITHER:
|
||||||
|
return False;
|
||||||
|
return None;
|
||||||
|
Loading…
Reference in New Issue
Block a user