"""Author: Changbeom Choi (@cbchoi)Copyright (c) 2014-2020 Handong Global UniversityCopyright (c) 2021-2024 Hanbat National UniversityLicense: MIT. The full license text is available at:https://github.com/eventsim/pyjevsim/blob/main/LICENSEThis module contains CoreModel, the parent class of all Model Types. """from.system_objectimportSystemObject
[docs]classCoreModel(SystemObject):""" All forms of Models in Pyjevsim have a CoreModel as their foundation. CoreModel class serves as a base model with basic functionalities for input and output ports. """def__init__(self,_name,_type):""" Args: _name (str): Model name _type (ModelType.BEHAVIORAL or ModelType.STRUCTURAL or ModelType.UTILITY): Model type """super().__init__()# Model Typeself.model_type=_typeself._name=_name# Input Ports Declarationself.external_input_ports=[]# Output Ports Declarationself.external_output_ports=[]
[docs]defset_name(self,_name):""" Sets the name of the model. Args: _name (str): New name of the model """self._name=_name
[docs]defget_name(self):""" Returns the name of the model. Returns: str: Name of the model """returnself._name
[docs]defget_model_type(self):""" Returns the type of the model. Returns: (ModelType.BEHAVIORAL or ModelType.STRUCTURAL or ModelType.UTILITY) : Type of the model """returnself.model_type
[docs]definsert_input_port(self,port):"""Inserts an input port to the model. Args: port (str): Name of the input port """self.external_input_ports.append(port)
[docs]defretrieve_input_ports(self):""" Retrieves all input ports of the model. Returns: list: List of input ports """returnself.external_input_ports
[docs]definsert_output_port(self,port):""" Inserts an output port to the model. Args: port (str): Name of the output port """self.external_output_ports.append(port)
[docs]defretrieve_output_ports(self):""" Retrieves all output ports of the model. Returns: list: List of output ports """returnself.external_output_ports
[docs]defmodel_snapshot(self):""" Snapshot the information of the running model. Returns: dict: Dictionary containing model type, model name, and model data """model_info={"type":self.model_type,"name":self._name,"data":self}returnmodel_info