新增修改
This commit is contained in:
395
final/scripts/f_relation1125.py
Normal file
395
final/scripts/f_relation1125.py
Normal file
@@ -0,0 +1,395 @@
|
||||
import numpy as np
|
||||
from typing import Dict
|
||||
from .utils import NetworkUtils
|
||||
|
||||
|
||||
class RelationCalculator:
|
||||
"""关系强度计算器"""
|
||||
|
||||
def __init__(self, nodes_data: Dict, cfg):
|
||||
"""
|
||||
初始化
|
||||
:param nodes_data: 节点数据
|
||||
:param auxiliary_data: 辅助数据(接口标准、角色匹配等)
|
||||
"""
|
||||
self.nodes_data = nodes_data
|
||||
self.utils = NetworkUtils()
|
||||
self.cfg = cfg
|
||||
|
||||
def _weights(self, rel: str):
|
||||
return self.cfg["W_REL"][rel]
|
||||
|
||||
def _lambda(self, rel: str):
|
||||
return self.cfg["LAMBDA"][rel]
|
||||
|
||||
def calculate_IS_relation(self, i: str, j: str) -> float:
|
||||
"""
|
||||
计算情报保障关系强度
|
||||
L_IS(i,j) = w_f·M_IS_F + w_s·M_IS_S + w_t·M_IS_T + w_p·M_IS_P + w_i·M_IS_I
|
||||
"""
|
||||
# 权重参数(根据1.3.pdf)
|
||||
w = self._weights("IS")
|
||||
# 提取节点数据
|
||||
node_i = self.nodes_data['nodes'][i]
|
||||
node_j = self.nodes_data['nodes'][j]
|
||||
|
||||
# 1. 功能维度 M_IS_F
|
||||
f_i_IA = node_i['function_vector']['f_IA']
|
||||
f_j_avg = (
|
||||
node_j['function_vector']['f_CC'] +
|
||||
node_j['function_vector']['f_IC'] +
|
||||
node_j['function_vector']['f_CS'] +
|
||||
node_j['function_vector']['f_CPS']
|
||||
) / 4
|
||||
|
||||
std_ij = self.utils.get_interface_standard(node_i, node_j)
|
||||
r_ij = self.utils.get_role_match(node_i, node_j)
|
||||
M_IS_F = f_i_IA * f_j_avg * std_ij * r_ij
|
||||
|
||||
# 2. 空间维度 M_IS_S
|
||||
d_ij = self.utils.calculate_distance(
|
||||
node_i['spatial']['position'],
|
||||
node_j['spatial']['position']
|
||||
)
|
||||
lambda_IS = self._lambda("IS")
|
||||
R_match = self.utils.calculate_range_match(
|
||||
node_i['spatial']['effective_radius'],
|
||||
node_j['spatial']['effective_radius'],
|
||||
d_ij
|
||||
)
|
||||
|
||||
s_area = self.utils.get_area_relation(node_i, node_j)
|
||||
M_IS_S = np.exp(-d_ij / lambda_IS) * R_match * s_area
|
||||
|
||||
# 3. 时间维度
|
||||
alpha = self.cfg["TIME"]["alpha"]
|
||||
beta = self.cfg["TIME"]["beta"]
|
||||
gamma = self.cfg["TIME"]["gamma"]
|
||||
|
||||
fresh_i = np.exp(-gamma * node_i['temporal']['data_age'])
|
||||
t_i_resp = np.exp(-alpha * node_i['temporal']['response_time'])
|
||||
|
||||
w_ij = self.utils.calculate_time_window_overlap(node_i, node_j)
|
||||
|
||||
M_IS_T = fresh_i * t_i_resp * w_ij
|
||||
|
||||
# 4. 性能维度 M_IS_P
|
||||
p_i_core = node_i['performance']['core_performance']
|
||||
mtbf_max = self.nodes_data['global_params']['mtbf_max']
|
||||
p_i_rel = node_i['performance']['mtbf'] / mtbf_max
|
||||
M_IS_P = p_i_core * p_i_rel
|
||||
|
||||
# 5. 交互维度 M_IS_I
|
||||
prot_ij = self.utils.get_protocol_compatibility(node_i, node_j)
|
||||
fmt_ij = self.utils.get_format_compatibility(node_i, node_j)
|
||||
sec_ij = self.utils.get_security_compatibility(node_i, node_j)
|
||||
hist_ij = self.utils.get_interaction_history(node_i, node_j)
|
||||
M_IS_I = ((prot_ij + fmt_ij + sec_ij) / 3) * hist_ij
|
||||
|
||||
# 综合计算
|
||||
L_IS = (w["w_f"] * M_IS_F + w["w_s"] * M_IS_S + w["w_t"] * M_IS_T +
|
||||
w["w_p"] * M_IS_P + w["w_i"] * M_IS_I)
|
||||
|
||||
return L_IS
|
||||
|
||||
def calculate_CC_relation(self, i: str, j: str) -> float:
|
||||
"""
|
||||
计算指挥控制关系强度
|
||||
L_CC(i,j) = w_f·M_CC_F + w_s·M_CC_S + w_t·M_CC_T + w_p·M_CC_P + w_i·M_CC_I
|
||||
"""
|
||||
# 权重参数
|
||||
w = self._weights("CC")
|
||||
lambda_CC = self._lambda("CC")# 根据公式,指挥控制距离敏感性更高
|
||||
|
||||
node_i = self.nodes_data['nodes'][i]
|
||||
node_j = self.nodes_data['nodes'][j]
|
||||
|
||||
# 1. 功能维度 M_CC_F
|
||||
f_i_CC = node_i['function_vector']['f_CC']
|
||||
f_j_sum = sum([
|
||||
node_j['function_vector']['f_IA'],
|
||||
node_j['function_vector']['f_IT'],
|
||||
node_j['function_vector']['f_IC'],
|
||||
node_j['function_vector']['f_CS'],
|
||||
node_j['function_vector']['f_DP'],
|
||||
node_j['function_vector']['f_CPS']
|
||||
])
|
||||
f_j_avg = f_j_sum / 6
|
||||
|
||||
std_ij = self.utils.get_interface_standard(node_i, node_j)
|
||||
r_ij = self.utils.get_role_match(node_i, node_j)
|
||||
M_CC_F = f_i_CC * f_j_avg * std_ij * r_ij
|
||||
|
||||
# 2. 空间维度 M_CC_S
|
||||
d_ij = self.utils.calculate_distance(
|
||||
node_i['spatial']['position'],
|
||||
node_j['spatial']['position']
|
||||
)
|
||||
|
||||
R_match = self.utils.calculate_range_match(
|
||||
node_i['spatial']['effective_radius'],
|
||||
node_j['spatial']['effective_radius'],
|
||||
d_ij
|
||||
)
|
||||
|
||||
s_area = self.utils.get_area_relation(node_i, node_j)
|
||||
M_CC_S = np.exp(-d_ij / lambda_CC) * R_match * s_area
|
||||
|
||||
# 3. 时间维度 M_CC_T
|
||||
alpha = self.cfg["TIME"]["alpha"]
|
||||
beta = self.cfg["TIME"]["beta"]
|
||||
gamma = self.cfg["TIME"]["gamma"]
|
||||
|
||||
t_i_resp = np.exp(-alpha * node_i['temporal']['response_time'])
|
||||
t_i_cycle = np.exp(-beta * node_i['temporal']['cycle_time'])
|
||||
|
||||
w_ij = self.utils.calculate_time_window_overlap(node_i, node_j)
|
||||
|
||||
M_CC_T = t_i_resp * t_i_cycle * w_ij
|
||||
|
||||
# 4. 性能维度 M_CC_P
|
||||
p_i_core = node_i['performance']['core_performance']
|
||||
p_i_surv = node_i['performance']['survivability']
|
||||
mtbf_max = self.nodes_data['global_params']['mtbf_max']
|
||||
p_i_rel = node_i['performance']['mtbf'] / mtbf_max
|
||||
M_CC_P = p_i_core * p_i_surv * p_i_rel
|
||||
|
||||
# 5. 交互维度 M_CC_I
|
||||
prot_ij = self.utils.get_protocol_compatibility(node_i, node_j)
|
||||
sec_ij = self.utils.get_security_compatibility(node_i, node_j)
|
||||
org_ij = self.utils.get_organization_relation(node_i, node_j)
|
||||
hist_ij = self.utils.get_interaction_history(node_i, node_j)
|
||||
M_CC_I = ((prot_ij + sec_ij + org_ij) / 3) * hist_ij
|
||||
|
||||
# 综合计算
|
||||
L_CC = (w["w_f"] * M_CC_F + w["w_s"] * M_CC_S + w["w_t"] * M_CC_T +
|
||||
w["w_p"] * M_CC_P + w["w_i"] * M_CC_I)
|
||||
|
||||
return L_CC
|
||||
|
||||
def calculate_SF_relation(self, i: str, j: str) -> float:
|
||||
"""
|
||||
计算状态反馈关系强度
|
||||
L_SF(i,j) = w_f·M_SF_F + w_s·M_SF_S + w_t·M_SF_T + w_p·M_SF_P + w_i·M_SF_I
|
||||
"""
|
||||
# 权重参数
|
||||
w = self._weights("SF")
|
||||
lambda_SF = self._lambda("SF")
|
||||
|
||||
node_i = self.nodes_data['nodes'][i]
|
||||
node_j = self.nodes_data['nodes'][j]
|
||||
|
||||
# 1. 功能维度 M_SF_F
|
||||
f_i_sum = sum([
|
||||
node_i['function_vector']['f_IA'],
|
||||
node_i['function_vector']['f_IT'],
|
||||
node_i['function_vector']['f_IC'],
|
||||
node_i['function_vector']['f_CS'],
|
||||
node_i['function_vector']['f_DP'],
|
||||
node_i['function_vector']['f_CPS']
|
||||
])
|
||||
f_i_avg = f_i_sum / 6
|
||||
f_j_CC = node_j['function_vector']['f_CC']
|
||||
|
||||
std_ij = self.utils.get_interface_standard(node_i, node_j)
|
||||
r_ij = self.utils.get_role_match(node_i, node_j)
|
||||
M_SF_F = f_i_avg * f_j_CC * std_ij * r_ij
|
||||
|
||||
# 2. 空间维度 M_SF_S
|
||||
d_ij = self.utils.calculate_distance(
|
||||
node_i['spatial']['position'],
|
||||
node_j['spatial']['position']
|
||||
)
|
||||
|
||||
R_match = self.utils.calculate_range_match(
|
||||
node_i['spatial']['effective_radius'],
|
||||
node_j['spatial']['effective_radius'],
|
||||
d_ij
|
||||
)
|
||||
|
||||
s_area = self.utils.get_area_relation(node_i, node_j)
|
||||
M_SF_S = np.exp(-d_ij / lambda_SF) * R_match * s_area
|
||||
|
||||
# 3. 时间维度 M_SF_T(状态反馈对时间敏感)
|
||||
alpha = self.cfg["TIME"]["alpha"]
|
||||
beta = self.cfg["TIME"]["beta"]
|
||||
gamma = self.cfg["TIME"]["gamma"]
|
||||
|
||||
fresh_i = np.exp(-gamma * node_i['temporal']['data_age'])
|
||||
t_i_resp = np.exp(-alpha * node_i['temporal']['response_time'])
|
||||
|
||||
w_ij = self.utils.calculate_time_window_overlap(node_i, node_j)
|
||||
|
||||
M_SF_T = fresh_i * t_i_resp * w_ij
|
||||
|
||||
# 4. 性能维度 M_SF_P
|
||||
p_i_core = node_i['performance']['core_performance']
|
||||
mtbf_max = self.nodes_data['global_params']['mtbf_max']
|
||||
p_i_rel = node_i['performance']['mtbf'] / mtbf_max
|
||||
M_SF_P = p_i_core * p_i_rel
|
||||
|
||||
# 5. 交互维度 M_SF_I
|
||||
prot_ij = self.utils.get_protocol_compatibility(node_i, node_j)
|
||||
fmt_ij = self.utils.get_format_compatibility(node_i, node_j)
|
||||
sec_ij = self.utils.get_security_compatibility(node_i, node_j)
|
||||
hist_ij = self.utils.get_interaction_history(node_i, node_j)
|
||||
M_SF_I = ((prot_ij + fmt_ij + sec_ij) / 3) * hist_ij
|
||||
|
||||
# 综合计算
|
||||
L_SF = (w["w_f"] * M_SF_F + w["w_s"] * M_SF_S + w["w_t"] * M_SF_T +
|
||||
w["w_p"] * M_SF_P + w["w_i"] * M_SF_I)
|
||||
|
||||
return L_SF
|
||||
|
||||
def calculate_PD_relation(self, i: str, j: str) -> float:
|
||||
"""
|
||||
计算平台部署关系强度
|
||||
L_PD(i,j) = w_f·M_PD_F + w_s·M_PD_S + w_t·M_PD_T + w_p·M_PD_P + w_i·M_PD_I
|
||||
"""
|
||||
# 权重参数
|
||||
w = self._weights("PD")
|
||||
lambda_PD = self._lambda("PD")
|
||||
|
||||
node_i = self.nodes_data['nodes'][i]
|
||||
node_j = self.nodes_data['nodes'][j]
|
||||
|
||||
# 1. 功能维度 M_PD_F
|
||||
f_i_DP = node_i['function_vector']['f_DP']
|
||||
f_J_sum = sum([
|
||||
node_j['function_vector']['f_IA'],
|
||||
node_j['function_vector']['f_IT'],
|
||||
node_j['function_vector']['f_IC'],
|
||||
node_j['function_vector']['f_CS'],
|
||||
])
|
||||
f_J_avg = f_J_sum / 4
|
||||
|
||||
# 修复:直接传递节点数据
|
||||
std_ij = self.utils.get_interface_standard(node_i, node_j)
|
||||
r_ij = self.utils.get_role_match(node_i, node_j)
|
||||
M_PD_F = f_i_DP * f_J_avg * std_ij * r_ij
|
||||
|
||||
# 2. 空间维度 M_PD_S(平台部署对空间要求高)
|
||||
d_ij = self.utils.calculate_distance(
|
||||
node_i['spatial']['position'],
|
||||
node_j['spatial']['position']
|
||||
)
|
||||
|
||||
R_match = self.utils.calculate_range_match(
|
||||
node_i['spatial']['effective_radius'],
|
||||
node_j['spatial']['effective_radius'],
|
||||
d_ij
|
||||
)
|
||||
# 修复:直接传递节点数据
|
||||
s_area = self.utils.get_area_relation(node_i, node_j)
|
||||
if d_ij <= self.cfg["PD_SGM"]:
|
||||
M_PD_S = 1
|
||||
else:
|
||||
M_PD_S = np.exp(-d_ij / lambda_PD) * R_match * s_area
|
||||
|
||||
# 3. 时间维度 M_PD_T
|
||||
alpha = self.cfg["TIME"]["alpha"]
|
||||
beta = self.cfg["TIME"]["beta"]
|
||||
gamma = self.cfg["TIME"]["gamma"]
|
||||
|
||||
t_i_resp = np.exp(-alpha * node_i['temporal']['response_time'])
|
||||
t_i_cycle = np.exp(-beta * node_i['temporal']['cycle_time'])
|
||||
|
||||
w_ij = self.utils.calculate_time_window_overlap(node_i, node_j)
|
||||
|
||||
M_PD_T = t_i_resp * t_i_cycle * w_ij
|
||||
|
||||
# 4. 性能维度 M_PD_P
|
||||
p_i_core = node_i['performance']['core_performance']
|
||||
# 部署平台的生存能力
|
||||
p_i_surv = node_i['performance']['survivability']
|
||||
M_PD_P = p_i_core * p_i_surv
|
||||
|
||||
# 5. 交互维度 M_PD_I
|
||||
prot_ij = self.utils.get_protocol_compatibility(node_i, node_j)
|
||||
fmt_ij = self.utils.get_format_compatibility(node_i, node_j)
|
||||
# 注意:这里std_ij已经在上面计算过了
|
||||
M_PD_I = (prot_ij + fmt_ij + std_ij) / 3
|
||||
|
||||
# 综合计算
|
||||
L_PD = (w["w_f"] * M_PD_F + w["w_s"] * M_PD_S + w["w_t"] * M_PD_T +
|
||||
w["w_p"] * M_PD_P + w["w_i"] * M_PD_I)
|
||||
|
||||
return L_PD
|
||||
|
||||
def calculate_CO_relation(self, i: str, j: str) -> float:
|
||||
"""
|
||||
计算协同作战关系强度
|
||||
L_CO(i,j) = w_f·M_CO_F + w_s·M_CO_S + w_t·M_CO_T + w_p·M_CO_P + w_i·M_CO_I
|
||||
"""
|
||||
# 权重参数
|
||||
w = self._weights("CO")
|
||||
lambda_CO = self._lambda("CO")
|
||||
node_i = self.nodes_data['nodes'][i]
|
||||
node_j = self.nodes_data['nodes'][j]
|
||||
|
||||
# 1. 功能维度 M_CO_F
|
||||
# 协同作战需要多个功能匹配
|
||||
f_i_avg = sum(node_i['function_vector'].values()) / len(node_i['function_vector'])
|
||||
f_j_avg = sum(node_j['function_vector'].values()) / len(node_j['function_vector'])
|
||||
|
||||
std_ij = self.utils.get_interface_standard(node_i, node_j)
|
||||
r_ij = self.utils.get_role_match(node_i, node_j)
|
||||
M_CO_F = f_i_avg * f_j_avg * std_ij * r_ij
|
||||
|
||||
# 2. 空间维度 M_CO_S
|
||||
d_ij = self.utils.calculate_distance(
|
||||
node_i['spatial']['position'],
|
||||
node_j['spatial']['position']
|
||||
)
|
||||
|
||||
R_match = self.utils.calculate_range_match(
|
||||
node_i['spatial']['effective_radius'],
|
||||
node_j['spatial']['effective_radius'],
|
||||
d_ij
|
||||
)
|
||||
|
||||
s_area = self.utils.get_area_relation(node_i, node_j)
|
||||
M_CO_S = np.exp(-d_ij / lambda_CO) * R_match * s_area
|
||||
|
||||
# 3. 时间维度 M_CO_T(协同需要时间同步)
|
||||
alpha = self.cfg["TIME"]["alpha"]
|
||||
beta = self.cfg["TIME"]["beta"]
|
||||
gamma = self.cfg["TIME"]["gamma"]
|
||||
|
||||
t_i_resp = np.exp(-alpha * node_i['temporal']['response_time'])
|
||||
t_j_resp = np.exp(-alpha * node_j['temporal']['response_time'])
|
||||
|
||||
t_i_cycle = np.exp(-beta * node_i['temporal']['cycle_time'])
|
||||
t_j_cycle = np.exp(-beta * node_j['temporal']['cycle_time'])
|
||||
|
||||
w_ij = self.utils.calculate_time_window_overlap(node_i, node_j)
|
||||
|
||||
M_CO_T = (t_i_resp + t_j_resp) * (t_i_cycle + t_j_cycle) * w_ij * 0.25
|
||||
|
||||
# 4. 性能维度 M_CO_P
|
||||
p_i_core = node_i['performance']['core_performance']
|
||||
p_j_core = node_j['performance']['core_performance']
|
||||
|
||||
mtbf_max = self.nodes_data['global_params']['mtbf_max']
|
||||
p_i_rel = node_i['performance']['mtbf'] / mtbf_max
|
||||
p_j_rel = node_j['performance']['mtbf'] / mtbf_max
|
||||
|
||||
p_i_surv = node_i['performance']['survivability']
|
||||
p_j_surv = node_j['performance']['survivability']
|
||||
# 协同性能取平均
|
||||
M_CO_P = ((p_i_core + p_j_core) / 2) * ((p_i_rel + p_j_rel) / 2) * ((p_i_surv + p_j_surv) / 2)
|
||||
|
||||
# 5. 交互维度 M_CO_I
|
||||
prot_ij = self.utils.get_protocol_compatibility(node_i, node_j)
|
||||
fmt_ij = self.utils.get_format_compatibility(node_i, node_j)
|
||||
sec_ij = self.utils.get_security_compatibility(node_i, node_j)
|
||||
org_ij = self.utils.get_organization_relation(node_i, node_j)
|
||||
hist_ij = self.utils.get_interaction_history(node_i, node_j)
|
||||
M_CO_I = ((prot_ij + fmt_ij + sec_ij + org_ij) / 4) * hist_ij
|
||||
|
||||
# 综合计算
|
||||
L_CO = (w["w_f"] * M_CO_F + w["w_s"] * M_CO_S + w["w_t"] * M_CO_T +
|
||||
w["w_p"] * M_CO_P + w["w_i"] * M_CO_I)
|
||||
|
||||
|
||||
return L_CO
|
||||
Reference in New Issue
Block a user