Repository navigation
Linear expansion pockets #71
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
Changes from 5 commits
e4cd375
c818fbc
0c7ec7c
d87f8b2
c4ecfeb
5fe88ed
0057ad8
aa5e7ad
bd39296
86eba63
43a8b6b
215b82b
b034448
1654aa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,46 +114,67 @@ def is_pocket_max(qbaf_initial: QBAFramework, | |
|
|
||
|
|
||
| def determine_max_pockets(qbaf_initial: QBAFramework, | ||
| qbaf_collection: list[QBAFramework], | ||
| topic_argument_1: str, | ||
| topic_argument_2: str, | ||
| pocket: set[str] = 0, | ||
| depth = 0)-> set[list[str]]: | ||
| qbaf_collection: list[QBAFramework], | ||
| topic_argument_1: str, | ||
| topic_argument_2: str, | ||
| current_subset: set[str]= set(), | ||
| pocket_list: list[set[str]]= [], | ||
| depth = 0)-> list[set[str]]: | ||
|
|
||
| """ | ||
| Returns the set of all maximal pockets with respect to qbaf_initial and qbaf_collection. | ||
| Args: | ||
| qbaf_initial (QBAFramework): The initial QBAF. | ||
| Checks whether pocket is a pocket of consistency with respect to qbaf_initial and qbaf_collection as per the subset relation. | ||
|
|
||
| Args: | ||
| qbaf_initial (QBAFramework): The initial QBAF. | ||
| qbaf_collection (list[QBAFramework]): The collection of QBAFs to be considered. | ||
| pocket (set[str]): The pocket to be considered, initialised to the set of all new arguments to start with. | ||
| topic_argument_1 (str): The first topic argument to be considered. | ||
| topic_argument_2 (str): The second topic argument to be considered. | ||
|
|
||
| Returns: | ||
| set[list[str]]: returns the set of all maximal pockets with respect to qbaf_intial and qbaf-collection. | ||
| bool: Returns True if pocket is a pocket of consistency; False otherwise. | ||
| """ | ||
|
|
||
| if (depth == 0): | ||
| pocket = list(new_arguments(qbaf_initial, qbaf_collection)) | ||
| considered_subset = set(new_arguments(qbaf_initial, qbaf_collection)) | ||
| else: | ||
| considered_subset = current_subset | ||
|
|
||
| if(is_pocket_max(qbaf_initial, | ||
| qbaf_collection, | ||
| considered_subset, | ||
| topic_argument_1, | ||
| topic_argument_2)): | ||
| return [considered_subset] | ||
|
|
||
| if (is_pocket_max(qbaf_initial, qbaf_collection, pocket, topic_argument_1, topic_argument_2)): | ||
| return [pocket] | ||
|
|
||
| if (len(pocket) == 1 or len(pocket) == 0): | ||
| return [] | ||
|
|
||
| nxt_itr = combinations(pocket, len(pocket)-1) | ||
| max_p = list() | ||
|
|
||
| for subsets in nxt_itr: | ||
| max_p = max_p + determine_max_pockets(qbaf_initial, | ||
| qbaf_collection, | ||
| topic_argument_1, | ||
| topic_argument_2, | ||
| list(subsets), depth + 1) | ||
|
|
||
| next_itr = [set(x) for x in combinations(considered_subset, | ||
| len(considered_subset)-1)] | ||
|
|
||
| next_itr_modified = [x for x in next_itr if not any(x.issubset(y) | ||
| for y in pocket_list)] | ||
|
Owner
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. Can you add a comment explaining what this does? |
||
|
|
||
| return max_p | ||
|
|
||
|
|
||
| for subset in next_itr_modified: | ||
| pocket_list = pocket_list + determine_max_pockets(qbaf_initial, | ||
| qbaf_collection, | ||
| topic_argument_1, | ||
| topic_argument_2, | ||
| subset, | ||
| pocket_list, | ||
| depth + 1) | ||
|
|
||
| if depth != 0: | ||
|
Owner
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. Why this condition? Can you add a code comment? |
||
| return pocket_list | ||
| else: | ||
| max_p = [x for x in pocket_list if (not any( (x != y and x.issubset(y)) for y in pocket_list))] | ||
|
Owner
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. use a more descriptive variable name |
||
| unique_pockets = [] | ||
|
|
||
| for x in max_p: | ||
|
Owner
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. use a more descriptive variable name |
||
| if x not in unique_pockets: | ||
| unique_pockets.append(x) | ||
| return unique_pockets | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -227,3 +248,39 @@ def explanation_of_robustness_violation(qbaf_initial: QBAFramework, | |
| explanations.append((pocket, x)) | ||
|
|
||
| return explanations | ||
|
|
||
|
|
||
| def determine_linear_max_pockets(qbaf_initial: QBAFramework, | ||
| qbaf_collection: list[QBAFramework], | ||
| topic_argument_1: str, | ||
| topic_argument_2: str) -> list[list[str]]: | ||
|
|
||
| """ | ||
| Determines the pockets when the qbaf_collection is a linear chain. | ||
|
Owner
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. pockets or max pockets? |
||
|
|
||
| Args: | ||
| qbaf_initial (QBAFramework): The initial QBAF. | ||
| qbaf_collection (list[QBAFramework]): The collection of QBAFs to be considered. | ||
| topic_argument_1 (str): The first topic argument to be considered. | ||
| topic_argument_2 (str): The second topic argument to be considered. | ||
|
|
||
| Returns: | ||
| set[list[str]]: returns the set of all maximal pockets with respect to qbaf_intial and qbaf-collection. | ||
| """ | ||
|
|
||
| collection_index = 0 | ||
| new_args = list(new_arguments(qbaf_initial, qbaf_collection)) | ||
|
|
||
| while (collection_index < len(qbaf_collection)): | ||
|
Owner
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. Can't this be a for loop? For loops are simpler than while loops so typically one should use for loops instead of while loops where possible. |
||
| if (qbaf_initial.are_strength_consistent(qbaf_collection[collection_index], | ||
| topic_argument_1, | ||
| topic_argument_2) == False): | ||
| break | ||
|
Owner
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. What does this loop do? It looks like it increments the index and executes the check for the if condition but nothing else. So I think it's best to wrap this into its own function and use a return instead of a break (and a for loop, that uses enumerate(list) such that you can use the index). This would also mean that you have to document that new function, which makes it easier to understand why you are doing this :) |
||
| else: | ||
| collection_index = collection_index+1 | ||
|
|
||
|
|
||
| args = set(new_arguments(qbaf_initial,[qbaf_collection[collection_index]])) | ||
|
Owner
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. Add a comment above this line describing what the code in the lines below does. |
||
| p_set = [set(x) for x in combinations(new_args, len(new_args)-1)] | ||
|
Owner
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. Can you rename this to something more descriptive? |
||
| pocket_list = [list(x) for x in p_set if (args.issubset(x) == False)] | ||
| return pocket_list | ||
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.
In the function signature above it says that it returns a list of strings.