ragraph.analysis.compatibility
¶
Compatibility analysis¶
Calculate compatibility between different variants for several functional elements.
CompatibilityAnalysis
¶
CompatibilityAnalysis(
graph: Graph,
variants: Dict[str, List[Node]],
interface_method: Optional[
Callable[[Graph, Node, Node], bool]
] = None,
compatibility_method: Callable[
[Graph, Node, Node], bool
] = get_compatibility_method(
compatibility_kind="compatibility",
incompatibility_kind=None,
),
interface_compatibility: bool = True,
score_method: Callable[
[Tuple[Node, ...]], float
] = get_score_method(
variant_agg="sum", config_agg="sum", weights=None
),
constraints: Optional[List[Node]] = None,
applicability_method: Callable[
[Graph, Node, Node], bool
] = get_applicability_method(
applicability_kind="applicability",
inapplicability_kind=None,
),
)
Compatibility analysis class.
The input graph is expected to contain nodes that represent variants of certain (functional) elements. A variant is a variation of an element that fulfills the same functionality as other variants of that elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph containing compatibility data between different variants. |
required |
variants
|
Dict[str, List[Node]]
|
Dictionary of element names to lists of variant nodes. |
required |
interface_method
|
Optional[Callable[[Graph, Node, Node], bool]]
|
An optional method accepting a Graph and two variant nodes
that returns whether the two given variants have an interface. Acts as a
guard for whether compatibility checking is necessary when
|
None
|
compatibility_method
|
Callable[[Graph, Node, Node], bool]
|
A method accepting a Graph and two variant nodes to check
whether the two given variants are compatible (by returning |
get_compatibility_method(compatibility_kind='compatibility', incompatibility_kind=None)
|
interface_compatibility
|
bool
|
When set, the compatibility of two variants is only checked when they share an interface. |
True
|
score_method
|
Callable[[Tuple[Node, ...]], float]
|
A method accepting a tuple of variant nodes and
returning a single performance score. See
|
get_score_method(variant_agg='sum', config_agg='sum', weights=None)
|
constraints
|
Optional[List[Node]]
|
Optional list of constraint nodes ("project scope") for which variants must be applicable in order to be taken into account. |
None
|
applicability_method
|
Callable[[Graph, Node, Node], bool]
|
A method accepting a graph, a variant node and a constraint node that returns whether a variant is applicable when that constraint is set. |
get_applicability_method(applicability_kind='applicability', inapplicability_kind=None)
|
Source code in ragraph/analysis/compatibility/__init__.py
applicability_method
instance-attribute
¶
applicability_method = applicability_method
A method accepting a graph, a variant node and a constraint node that returns whether a variant is applicable when that constraint is set.
compatibility_method
instance-attribute
¶
compatibility_method = compatibility_method
A method accepting a Graph and two variant nodes to check whether the two given variants
are compatible (by returning True
).
disabled_elements
property
¶
Disabled elements with no applicable variant.
See self.constraints
and self.applicability_method
.
elements
property
¶
Enabled elements with at least one applicable variant.
See self.constraints
and self.applicability_method
.
graph
instance-attribute
¶
graph = graph
Graph containing compatibility data between different variants.
interface_compatibility
instance-attribute
¶
interface_compatibility = interface_compatibility
When set, the compatibility of two variants is only checked when they share an interface.
interface_method
instance-attribute
¶
interface_method = interface_method
An optional method accepting a Graph and two variant nodes that returns whether the two
given variants have an interface. Acts as a guard for whether compatibility checking is
necessary when interface_compatibility
is set.
score_method
instance-attribute
¶
score_method = score_method
A method accepting a tuple of variant nodes and returning a single performance score.
See get_score_method
.
variants_list
property
¶
variants_list: List[Node]
Flat list of applicable variants sorted by (enabled) element.
get_compatibility_matrix
¶
get_compatibility_matrix(
variants: Optional[List[Node]] = None,
) -> Union[ndarray, List[List[float]]]
Compatibility matrix between variants.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variants
|
Optional[List[Node]]
|
Optional list of variants to return the compatibility matrix for.
Also see |
None
|
Returns:
Type | Description |
---|---|
Union[ndarray, List[List[float]]]
|
Compatibility matrix as a list of lists or numpy array (if numpy is |
Union[ndarray, List[List[float]]]
|
available). |
Source code in ragraph/analysis/compatibility/__init__.py
get_config_score
¶
get_config_score(config: Tuple[Node, ...]) -> float
Score a configuration. Does NOT check if the supplied config is valid!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Tuple[Node, ...]
|
Configuration as a tuple of variant nodes. |
required |
Returns:
Type | Description |
---|---|
float
|
Configuration score. |
Source code in ragraph/analysis/compatibility/__init__.py
get_plot_graph
¶
get_plot_graph() -> Graph
Get a plot ready graph for the current compatibility analysis problem.
Source code in ragraph/analysis/compatibility/__init__.py
get_ranked_configurations
¶
get_ranked_configurations(
descending: bool = True,
) -> List[Tuple[Tuple[Node, ...], float]]
Get the feasible configurations, sorted by score.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
descending
|
bool
|
Whether highest scores should go first. |
True
|
Returns:
Type | Description |
---|---|
List[Tuple[Tuple[Node, ...], float]]
|
Sorted tuples of configurations and scores. |
Source code in ragraph/analysis/compatibility/__init__.py
has_interface
¶
Whether two variants have an interface that needs a compatibility check.
is_applicable
¶
is_applicable(variant: Node) -> bool
Whether a variant is applicable to the currently set of constraints.
Source code in ragraph/analysis/compatibility/__init__.py
is_compatible
¶
Whether the two given variants are compatible according to
self.applicability_method
Source code in ragraph/analysis/compatibility/__init__.py
plot
¶
plot(**mdm_args) -> Figure
Visualize the compatibility analysis problem.
Source code in ragraph/analysis/compatibility/__init__.py
write_csv
¶
Write feasible configurations and optional scores to a CSV file.
Source code in ragraph/analysis/compatibility/__init__.py
yield_feasible_configurations
¶
yield_feasible_configurations() -> (
Generator[Tuple[Node, ...], None, None]
)
Yield the feasible configurations for this problem.
Source code in ragraph/analysis/compatibility/__init__.py
get_applicability_method
¶
get_applicability_method(
applicability_kind: Optional[str] = "applicability",
inapplicability_kind: Optional[str] = None,
) -> Callable[[Graph, Node, Node], bool]
Get a method dat signals whether an element is applicable when a certain constraint is active.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
applicability_kind
|
Optional[str]
|
Optional Edge kind that signals variant applicability. |
'applicability'
|
inapplicability_kind
|
Optional[str]
|
Optional Edge kind that signals variant inapplicability. |
None
|
Returns:
Type | Description |
---|---|
Callable[[Graph, Node, Node], bool]
|
Method of checking applicability of an element for a constraint. Takes a Graph |
Callable[[Graph, Node, Node], bool]
|
containing Edge data and an element and a constraint node to check. |
Source code in ragraph/analysis/compatibility/__init__.py
get_compatibility_method
¶
get_compatibility_method(
compatibility_kind: Optional[str] = "compatibility",
incompatibility_kind: Optional[str] = None,
) -> Callable[[Graph, Node, Node], bool]
Get a method dat signals whether two variants are compatible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compatibility_kind
|
Optional[str]
|
Optional Edge kind that signals variant compatibility. |
'compatibility'
|
incompatibility_kind
|
Optional[str]
|
Optional Edge kind that signals variant incompatibility. |
None
|
Returns:
Type | Description |
---|---|
Callable[[Graph, Node, Node], bool]
|
Method of checking compatibility of two variants as nodes. Takes a Graph |
Callable[[Graph, Node, Node], bool]
|
containing Edge data and an A and a B node to check. |
Source code in ragraph/analysis/compatibility/__init__.py
get_configuration_score
¶
Score a configuration by aggregating variant scores by either taking the sum or product.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variant_scores
|
Iterable[float]
|
List of scores for all selected variants. |
required |
Returns:
Type | Description |
---|---|
float
|
Config score. |
Source code in ragraph/analysis/compatibility/__init__.py
get_interface_method
¶
get_interface_method(
interface_kind: Optional[str] = None,
) -> Callable[[Graph, Node, Node], bool]
Get a basic interface checking method. Will check for the existence of edges between the ascendants of the variants (optionally filtered with an edge kind).
Source code in ragraph/analysis/compatibility/__init__.py
get_score_method
¶
get_score_method(
variant_agg: str = "sum",
config_agg: str = "sum",
weights: Optional[List[str]] = None,
) -> Callable[[Tuple[Node, ...]], float]
Get a configuration scoring method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variant_agg
|
str
|
Variant node weights aggregation method. Either "sum" or "product". |
'sum'
|
config_agg
|
str
|
Variant nodes' score aggregation method. Either "sum" or "product". |
'sum'
|
weights
|
Optional[List[str]]
|
Optional selection of node weights to take into account. |
None
|
Returns:
Type | Description |
---|---|
Callable[[Tuple[Node, ...]], float]
|
A method accepting a tuple of variant nodes and returning a single |
Callable[[Tuple[Node, ...]], float]
|
performance score. |
Source code in ragraph/analysis/compatibility/__init__.py
get_variant_score
¶
get_variant_score(
variant: Node,
weights: Optional[List[str]] = None,
aggregation: str = "sum",
) -> float
Score a single variant node as an aggregation of selected weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
variant
|
Node
|
Variant node. |
required |
weights
|
Optional[List[str]]
|
Optional list of weights to take into account. |
None
|
aggregation
|
str
|
Aggregation method, either "sum" or "product". |
'sum'
|
Returns:
Type | Description |
---|---|
float
|
Variant score. |
Source code in ragraph/analysis/compatibility/__init__.py
is_feasible
¶
is_feasible(
compat: Union[ndarray, List[List[Union[bool, int]]]],
config: Tuple[int, ...],
) -> bool
Return whether this configuration is feasible based on a compatibility matrix.
Source code in ragraph/analysis/compatibility/__init__.py
bdd
¶
Binary Decision Diagram compatibility calculation¶
Binary Decision Diagram (BDD) implementation of the compatibility problem.
_recursive
¶
Construct a recursive operation function over all items.
Source code in ragraph/analysis/compatibility/bdd.py
_yield_ranges
¶
yield_feasible_configurations
¶
yield_feasible_configurations(
compat: Union[ndarray, List[List[Union[bool, int]]]],
comp_variant_nums: List[int],
) -> Generator[Tuple[int, ...], None, None]
Get the feasible configurations based on a compatibility matrix between different variants of elements and the "bucket" sizes (number of variants of each element).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
compat
|
Union[ndarray, List[List[Union[bool, int]]]]
|
Compatibility matrix (square) between different variants of elements. Size is determined by the total number of variants. |
required |
comp_variant_nums
|
List[int]
|
The number of variants for each element. The matrix has to be sorted accordingly. |
required |
Returns:
Type | Description |
---|---|
None
|
Feasible configurations as a tuple with a variant's (absolute) index for |
None
|
each element. |