Dado el siguiente código: from \_\_future\_\_ import annotations
import classes.Component as C
import classes.SimulatorPacket as SP
import classes.Mediator as B3
import classes.Parameters as P
import numpy as np

class BinarySymmetricChannel(C.Component):
 def \_\_init\_\_(self, whoAmI: str, mainOutputTo: str, mediator: B3.Mediator = None) -> None:
 super().\_\_init\_\_(whoAmI, mainOutputTo, mediator) 

 self.probability\_error = 1e-3 #1e-3 #<------------ LA PROBABILIDAD DE ERROR DE BITS AFECTA BASTANTE A LA SIMULACIÓN. DEBERÍA HABER UN MÁXIMO NÚMERO DE REINTENTOS O UN TIMER PARA CERRAR EL ENLACE EN CASO DE QUE SIEMPRE HAYA ERRORES.

 #Parámtros establecidos al inicio de la simulación
 self.satellite\_velocity = 0 #m/s
 self.satellite\_altitude = 0
 self.theta\_open\_link = 0
 self.theta\_close\_link = 0

 #Constantes #<--------------------DESPUES USAR LAS CONSTANTES DEFINIDAS EN LA CLASE Parameters
 self.earth\_radius = 6370 #km
 self.earth\_mass = 5.972e24 #kg
 self.speed\_of\_light = 299792458 #m/s
 self.gravitational\_constant = 6.67e-11 #N^2m^2/kg
 

 #Parámetros calculados
 self.gamma\_max\_open = 0
 self.distance\_max\_open = 0
 self.distance\_min = 0

 #Parámetros calculados dinámicamente
 #self.distance = 0
 #self.anglestamp = 0
 #self.proptime = 0

 self.iterator = 0
 self.activate\_satellite\_model = True
 self.default\_prop\_time = 25.0
 self.distances = []
 self.timestamps = []
 """
 def set\_parameters(self, satellite\_altitude: float, theta\_open\_link: float, theta\_close\_link: float, probability\_error: float, activate\_satellite\_model: bool, default\_prop\_time: float):
 self.satellite\_altitude = satellite\_altitude
 self.theta\_open\_link = theta\_open\_link
 self.theta\_close\_link = theta\_close\_link
 self.probability\_error = probability\_error
 self.activate\_satellite\_model = activate\_satellite\_model
 self.default\_prop\_time = default\_prop\_time
 self.set\_secondary\_parameters()
 """
 def set\_parameters(self, parameters: P.Parameters, downlink):
 self.satellite\_altitude = parameters.satellite\_altitude
 self.theta\_open\_link = parameters.open\_link\_elevation\_angle
 self.theta\_close\_link = parameters.close\_link\_elevation\_angle
 self.activate\_satellite\_model = parameters.activate\_satellite\_model
 self.default\_prop\_time = parameters.default\_prop\_time
 self.parameters = parameters

 if downlink:
 self.probability\_error = parameters.probability\_error\_downlink
 else:
 self.probability\_error = parameters.probability\_error\_uplink

 self.set\_secondary\_parameters()
 def set\_secondary\_parameters(self):
 delta\_min\_open = np.pi / 2 + self.theta\_open\_link
 delta\_min\_close = np.pi / 2 + self.theta\_close\_link
 self.distance\_max\_open = self.compute\_distance\_by\_delta(delta=delta\_min\_open)
 self.distance\_max\_close = self.compute\_distance\_by\_delta(delta=delta\_min\_close)
 self.distance\_min = self.compute\_distance\_by\_delta(delta = np.pi)
 self.gamma\_max\_open = np.arcsin(self.distance\_max\_open \* (np.sin(delta\_min\_open)) / (self.earth\_radius + self.satellite\_altitude)) #Ecuación 3.14
 self.gamma\_max\_close = np.arcsin(self.distance\_max\_close \* (np.sin(delta\_min\_close)) / (self.earth\_radius + self.satellite\_altitude)) #Ecuación 3.14
 self.satellite\_velocity = np.sqrt((self.gravitational\_constant\*self.earth\_mass)/((self.earth\_radius+self.satellite\_altitude)\*1000))
 def compute\_distance\_by\_delta(self, delta: float) -> float:
 radicand = (self.satellite\_altitude + self.earth\_radius) \*\* 2 + (self.earth\_radius \*\* 2) \* (np.cos(delta) \*\* 2 - 1)
 return self.earth\_radius \* np.cos(delta) + np.sqrt(radicand)
 def compute\_distance\_by\_gamma(self, gamma: float):
 radicand = 2 \* (1 - np.cos(gamma)) \* (self.earth\_radius \*\* 2 + self.satellite\_altitude \* self.earth\_radius) + self.satellite\_altitude \*\* 2
 return np.sqrt(radicand)
 #Dinámicamente:
 def compute\_anglestamp(self, timestamp: float) -> float:
 gamma\_increment = (self.satellite\_velocity \* timestamp) / ((self.earth\_radius + self.satellite\_altitude)\*1000)
 return self.gamma\_max\_open - gamma\_increment
 

 def compute\_distance(self, anglestamp: float) -> float:
 return self.compute\_distance\_by\_gamma(anglestamp)
 

 def compute\_prop\_time(self, distance: float) -> float:
 return distance\*1000 / self.speed\_of\_light
 def add\_error\_vector(self, bit\_stream):
 bit\_stream\_len = len(bit\_stream)
 #error\_vector = [random.random() < self.error\_probability for \_ in range(0, bit\_stream\_len)]
 error\_vector = np.random.rand(bit\_stream\_len) < self.probability\_error
 result = (bit\_stream ^ error\_vector) 
 return result
 def receive(self, simulator\_packet: SP.SimulatorPacket) -> None:
 if simulator\_packet.type == 2:
 
 #Agregar tiempo de propagación en el canal.
 if self.activate\_satellite\_model:
 anglestamp = self.compute\_anglestamp(simulator\_packet.timestamp)

 if anglestamp <= -self.gamma\_max\_close: #Cierre del enlace
 sp = SP.SimulatorPacket()
 sp.tracking\_id = simulator\_packet.tracking\_id
 sp.timestamp = simulator\_packet.timestamp
 sp.data = "close\_link\_elevation\_angle\_achieved"
 sp.type = -2
 self.mediator.send(self.whoAmI, "A1", sp)
 distance = self.compute\_distance(anglestamp)
 self.parameters.distance = distance #Agregado
 self.distances.append(distance)
 self.timestamps.append(simulator\_packet.timestamp)
 prop\_time = self.compute\_prop\_time(distance)
 self.parameters.prop\_time = prop\_time #Agregado
 simulator\_packet.timestamp = simulator\_packet.timestamp + prop\_time
 else:
 simulator\_packet.timestamp = simulator\_packet.timestamp + self.default\_prop\_time
 self.parameters.prop\_time = self.default\_prop\_time
 ######################################

 """
 if self.whoAmI == "A4-D": #Si es el downlink, introducir el error, porque así está en la prueba
 if self.iterator == 1 or self.iterator == 2 or self.iterator == 6:
 simulator\_packet.data[0][7] = simulator\_packet.data[0][7] ^ 1 #introducir un error 
 simulator\_packet.data[0][9] = simulator\_packet.data[0][9] ^ 1 #introducir un error
 self.iterator = self.iterator + 1
 """ 
 
 """
 vectors = []
 for vector in simulator\_packet.data:
 vectors.append( self.add\_error\_vector(vector) )#Agregar errores
 """

 error\_vector = np.random.rand(simulator\_packet.data.shape[0], simulator\_packet.data.shape[1]) < self.probability\_error
 vectors = (simulator\_packet.data ^ error\_vector) 

 

 #print("HOLA")

 sp = SP.SimulatorPacket()
 sp.tracking\_id = simulator\_packet.tracking\_id
 sp.timestamp = simulator\_packet.timestamp
 sp.data = vectors
 sp.type = 2
 #sp.tracking\_ids\_tuple = simulator\_packet.tracking\_ids\_tuple
 self.mediator.send(self.whoAmI, self.mainOutputTo, sp)

 else:
 self.mediator.send(self.whoAmI, self.mainOutputTo, simulator\_packet)
다음 코드를 추가합니다. \_\_future\_\_에서 어노테이션을 가져옵니다.classes.Component를 C로 임포트classes.SimulatorPacket을 SP로 임포트classes.Mediator를 B3로 임포트classes.Parameters를 P로 가져옵니다.numpy를 np로 가져옵니다.클래스 BinarySymmetricChannel(C.Component): def \_\_init\_\_(self, whoAmI: str, mainOutputTo: str, mediator: B3.Mediator = None) -> None: super().\_\_init\_\_(whoAmI, mainOutputTo, mediator)  self.probability\_error = 1e-3 #1e-3 #<------------ 비트 오류 확률은 시뮬레이션에 영향을 미칩니다. 항상 오류가 발생할 경우를 대비하여 최소한의 재시도 횟수 또는 링크를 끊는 타이머가 있어야합니다. 시뮬레이션 시작 시 설정된 #파라미터 self.satellite\_velocity = 0 #m/s self.satellite\_altitude = 0 self.theta\_open\_link = 0 self.theta\_close\_link = 0 #상수 #<--------------------정의된 상수를 사용해야 함 매개 변수 self.earth\_radius = 6370 #km self.earth\_mass = 5.972e24 #kg self.speed\_of\_light = 299792458 #m/s self.gravitational\_상수 = 6.67e-11 #N^2m^2/kg  #계산된 매개변수 self.감마\_max\_open = 0 self.distance\_max\_open = 0 self.distance\_min = 0 #동적으로 계산된 매개변수 #self.distance = 0 #self.anglestamp = 0 #self.프롭타임 = 0 self.iterator = 0 self.activate\_satellite\_model = True self.default\_prop\_time = 25.0 self.distances = [] self.timestamps = [] """ def set\_parameters(self, satellite\_altitude: float, theta\_open\_link: float, theta\_close\_link: float, probability\_error: float, activate\_satellite\_model: bool, default\_prop\_time: float): self.satellite\_altitude = satellite\_altitude self.theta\_open\_link = theta\_open\_link self.theta\_close\_link = theta\_close\_link self.probability\_error = 확률\_error self.activate\_satellite\_model = 활성화\_satellite\_model self.default\_prop\_time = 기본값\_prop\_time self.set\_secondary\_parameters() """ def set\_parameters(self, 매개변수: P.Parameters, 다운링크): self.satellite\_altitude = parameters.satellite\_altitude self.theta\_open\_link = parameters.open\_link\_elevation\_angle self.theta\_close\_link = parameters.close\_link\_elevation\_angle self.activate\_satellite\_model = parameters.activate\_satellite\_model self.default\_prop\_time = parameters.default\_prop\_time self.parameters = 매개변수 다운링크인 경우 self.probability\_error = parameters.probability\_error\_downlink else: self.probability\_error = parameters.probability\_error\_uplink self.set\_secondary\_parameters() def set\_secondary\_parameters(self): delta\_min\_open = np.pi / 2 + self.theta\_open\_link 델타\_분\_닫기 = np.파이 / 2 + self.세타\_닫기\_링크 self.distance\_max\_open = self.compute\_distance\_by\_delta(delta=delta\_min\_open) self.distance\_max\_close = self.compute\_distance\_by\_delta(delta=delta\_min\_close) self.distance\_min = self.compute\_distance\_by\_delta(delta = np.pi) self.gamma\_max\_open = np.arcsin(self.distance\_max\_open \* (np.sin(delta\_min\_open)) / (self.earth\_radius + self.satellite\_altitude)) #예제 3.14 self.gamma\_max\_close = np.arcsin(self.distance\_max\_close \* (np.sin(delta\_min\_close)) / (self.earth\_radius + self.satellite\_altitude)) #예제 3.14 self.satellite\_velocity = np.sqrt((self.gravitational\_constant\*self.earth\_mass)/((self.earth\_radius+self.satellite\_altitude)\*1000)) def compute\_distance\_by\_delta(self, delta: float) -> float: radicand = (self.satellite\_altitude + self.earth\_radius) \*\* 2 + (self.earth\_radius \*\* 2) \* (np.cos(delta) \*\* 2 - 1) 반환 self.earth\_radius \* np.cos(delta) + np.sqrt(radicand) def compute\_distance\_by\_gamma(self, gamma: float): radicand = 2 \* (1 - np.cos(감마)) \* (self.earth\_radius \*\* 2 + self.satellite\_altitude \* self.earth\_radius) + self.satellite\_altitude \*\* 2 반환 np.sqrt(radicand) #동적으로: def compute\_anglestamp(self, timestamp: float) -> float: gamma\_increment = (self.satellite\_velocity \* timestamp) / ((self.earth\_radius + self.satellite\_altitude)\*1000) 반환 self.gamma\_max\_open - gamma\_increment  def compute\_distance(self, anglestamp: float) -> float: 반환 self.compute\_distance\_by\_gamma(anglestamp)  def compute\_prop\_time(self, distance: float) -> float: 반환 거리\*1000 / self.speed\_of\_light def add\_error\_vector(self, bit\_stream): bit\_stream\_len = len(bit\_stream) #error\_vector = [random.random() < self.error\_probability for \_ in range(0, bit\_stream\_len)] error\_vector = np.random.rand(bit\_stream\_len) < self.probability\_error 결과 = (비트\_스트림 ^ 오류\_벡터)  결과 반환 def receive(self, simulator\_packet: SP.SimulatorPacket) -> None: if simulator\_packet.type == 2:  #채널에 전파 시간을 추가합니다. if self.activate\_satellite\_model: anglestamp = self.compute\_anglestamp(시뮬레이터\_패킷.timestamp) if anglestamp <= -self.gamma\_max\_close: #링크 닫기 sp = SP.