-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf_c.py
45 lines (42 loc) · 3.66 KB
/
f_c.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import numpy as np
def f_c(components: list, components_prime: list):
"""
This functions tells us how similar two components of the two models are. It calculates the proportion of attributes that are equal.\n
Input:
- components: list of components of the model A.\n
- components_prime: list of components of the model B.\n
Output:
- matrix of dimension len(components) x len(components_prime).
"""
# Auxiliary variables
len_comp = len(components)
len_comp_prime = len(components_prime)
# Initialize the matrix
f_c_matrix = np.zeros((len_comp, len_comp_prime))
# Go through every component of model A and every component of model B and calculate the proportion of equal attributes
for c in range(len_comp):
for c_prime in range(len_comp_prime):
# Check if the components are of the same type and if they are, calculate the proportion of equal attributes. There are exceptions/special cases for the bearing types, stage_gear_data types and the coupling types. They may be matched with each other.
if (components[c].type == "concept_bearing" and components_prime[c_prime].type in ["concept_bearing", "rolling_bearing_with_catalog_geometry", "rolling_bearing_with_detailed_geometry", "slide_bearing"]) or (components[c].type == "rolling_bearing_with_catalog_geometry" and components_prime[c_prime].type in ["concept_bearing", "rolling_bearing_with_catalog_geometry", "rolling_bearing_with_detailed_geometry", "slide_bearing"]) or (components[c].type == "rolling_bearing_with_detailed_geometry" and components_prime[c_prime].type in ["concept_bearing", "rolling_bearing_with_catalog_geometry", "rolling_bearing_with_detailed_geometry"]) or (components[c].type == "slide_bearing" and components_prime[c_prime].type in ["concept_bearing", "slide_bearing"]) or (components[c].type =="stage_gear_data" and "stage_gear_data" in components_prime[c_prime].type) or ("stage_gear_data" in components[c].type and components_prime[c_prime].type == "stage_gear_data") or (components[c].type in ["coupling", "switchable_coupling" ] and components_prime[c_prime].type in ["coupling", "switchable_coupling"]) or (components[c].type == components_prime[c_prime].type):
total_number_attributes = max(len(components[c].attributes), len(components_prime[c_prime].attributes)) # Calculate the max number of attributes
# Special case: both components have zero attributes
if len(components[c].attributes) == 0 and len(components_prime[c_prime].attributes) == 0:
f_c_matrix[c][c_prime] = 1
# Special case: one component has zero attributes
elif min(len(components[c].attributes), len(components_prime[c_prime].attributes)) == 0:
f_c_matrix[c][c_prime] = 0.1
# General case: calculate the proportion of equal attributes
else:
number_attributes_equal = 0
attributes = components[c].attributes
attributes_prime = components_prime[c_prime].attributes
for attribute in attributes:
for attribute_prime in attributes_prime:
if attribute.id == attribute_prime.id:
if attribute.param_value == attribute_prime.param_value:
number_attributes_equal += 1
f_c_matrix[c][c_prime] = number_attributes_equal/total_number_attributes
# If the components are not of the same type, set the value of the matrix to -10
else:
f_c_matrix[c][c_prime] = -10
return f_c_matrix