From 48fb1364369dd540e82e02138951cc0afbf51314 Mon Sep 17 00:00:00 2001 From: raj_mathe Date: Thu, 16 Jun 2022 22:27:29 +0200 Subject: [PATCH] master > master: code py - darstellung alignment von summen --- .../python/src/algorithms/rucksack/display.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/code/python/src/algorithms/rucksack/display.py b/code/python/src/algorithms/rucksack/display.py index 422f119..4607143 100644 --- a/code/python/src/algorithms/rucksack/display.py +++ b/code/python/src/algorithms/rucksack/display.py @@ -111,14 +111,16 @@ def display_branch_and_bound(values: np.ndarray, steps: List[Step]) -> str: used_choices.append(step.choice); expr = display_sum(choice=step.choice, values=values, as_maximum=False, order=step.order, indexes=step.indexes); else: - expr = f'{step.bound_subtree:g}'; + expr = ''; + bound_str = f'{step.bound:+g}'; pad_str = ('' if step.pad == MaskValue.UNSET else step.pad.value); move_str = ('' if step.move == EnumBranchAndBoundMove.NONE else step.move.value); if i == index_soln: - move_str = f'{move_str} *'; + bound_str = f'* \x1b[92;1m{bound_str}\x1b[0m'; rows.append({ - 'bound': f'{step.bound:+g}', - 'bound_subtree': expr, + 'bound': f'{bound_str}', + 'bound_subtree': f'{step.bound_subtree:g}', + 'bound_subtree_sum': expr, 'stack': step.stack_str, 'pad': f'\x1b[2m{pad_str}\x1b[0m', 'move': f'\x1b[2m{move_str}\x1b[0m', @@ -128,10 +130,10 @@ def display_branch_and_bound(values: np.ndarray, steps: List[Step]) -> str: # benutze pandas-Dataframe + tabulate, um schöner darzustellen: repr = tabulate( table, - headers=['bound', 'g(TOP(S))', 'S — stack', '\x1b[2mpad?\x1b[0m', '\x1b[2mmove\x1b[0m'], + headers=['bound', 'g(TOP(S))', '', 'S — stack', '\x1b[2mpad?\x1b[0m', '\x1b[2mmove\x1b[0m'], showindex=False, - colalign=('left', 'left', 'right', 'center', 'left'), - tablefmt='rst' + colalign=('right', 'right', 'left', 'right', 'center', 'left'), + tablefmt='simple' ); return repr; @@ -169,5 +171,5 @@ def display_sum( expr = '\x1b[2m+\x1b[0m'.join(map(render, parts)); if as_maximum: - return f'{value:g} \x1b[2m=\x1b[0m {expr}'; - return f'-{value:g} \x1b[2m= -(\x1b[0m{expr}\x1b[2m)\x1b[0m'; + return f'\x1b[2m=\x1b[0m {expr}'; + return f'\x1b[2m= -(\x1b[0m{expr}\x1b[2m)\x1b[0m';