ml4cps.cps.base module¶
The module provides base classes to represent the dynamics of cyber-physical systems (CPS): - CPS, and, - CPSComponent.
Author: Nemanja Hranisavljevic, hranisan@hsu-hh.de
- class ml4cps.cps.base.CPS(sys_id, components)¶
- Bases: - object- CPS class represents a cyber-physical system. It is used to model the hierarchy in the system as each CPS can contain a mixture of other CPS and CPS components. The leaves of the hierarchy are only CPS component objects which define their dynamics and communication with other components. - id¶
- Identifier of the object. - Type:
- str 
 
 - com¶
- Property. A collection of components. - Type:
- OrderedDict 
 
 - copy()¶
 - finish_condition()¶
 - get_all_components(exclude=None)¶
- Returns a list of all child components (not only direct) except those with ids possibly provided in exclude. - Parameters:
- exclude (iterable) – A list of component ids to exclude in the returned list. 
 
 - get_component(name)¶
 - get_component_by_full_id(full_id)¶
 - get_components(exclude=None)¶
- Returns a list of all direct child components except those with ids possibly provided in exclude. - Parameters:
- exclude (iterable) – A list of component ids to exclude in the returned list (default is None). 
 
 - get_execution_data(flat=False)¶
 - items()¶
 - property overall_system¶
 - property parent_system¶
- Gets the parent system by accessing _parent_system private attribute. - Returns:
- The parent system. 
- Return type:
- (CPS) 
 
 - reinitialize(t=0, state=None)¶
- The function re-initializes the CPS components of this CPS with the given state values. :param t: Current time to set to the components. :param state: State of the CPS (it’s components) given as a dictionary of dictionaries … of tuples (according to the CPS hierarchy). The tuplus are created as values concatenated values of discrete-event state variables, time-continuous state variables and time-discrete state variables. - Returns:
 
 - set_child_component(id, com)¶
- Set component with the id. - Parameters:
- id (str) – ID of the component to add. 
- com ((CPS, CPSComponent)) – Component of subsystem to add. 
 
 
 - simulate(finish_time, verbose=False, save_choices=False)¶
- Simulates behaviour of the system until the finish_time is reached. - Parameters:
- finish_time (Time when simulation finishes.) 
- verbose (Should the execution log be printed in detail (default is False).) 
- save_choices (Should the choices for each component be saved to json files after) 
- False). (the simulation is finished (default is) 
 
 
 - property state¶
 
- class ml4cps.cps.base.CPSComponent(id, t=0, initial_q=(), initial_xt: list = (), initial_xk: list = (), dt=-1.0, p=None, cont_state_names=None, discr_state_names=None, discr_output_names=None, cont_output_names=None, unknown_state='Unknown')¶
- Bases: - PythonModel,- Simulator- General hybrid system class based on scipy and simpy. - apply_sim_event(e, env=None)¶
- The event e is applied in this component’s simpy execution, this means that the process must wait for an event. :param e: Event to apply. :return: 
 - context(q, past_t, past_p, t) tuple¶
 - continuous_dynamics_process(env, max_time, verbose=False)¶
 - copy()¶
 - discrete_dynamics_process(env, max_time, verbose=False)¶
 - discrete_event_dynamics(q, xt, xk, p) tuple¶
 - property discrete_state¶
 - discrete_time_dynamics_process(env, max_time, verbose=False)¶
 - finish(t, **kwargs)¶
 - finish_condition()¶
 - property full_id¶
 - get_alternatives(state, system_state)¶
 - get_decision_state(state, overall_state)¶
 - get_execution_data()¶
 - get_sim_state()¶
 - guards(q, x)¶
 - input(q, clock) tuple¶
 - invariants(q, clock, xc, xd, y)¶
 - is_decision(state, overall_state)¶
 - on_entry(q, context)¶
 - output_d(q, xt, xk)¶
 - output_y(q, xt, xk)¶
 - property overall_system¶
 - property parent_system¶
 - reinitialize(t, state=None)¶
 - set_sim_state(q, e, p, y, block_event)¶
 - simulate(finish_time, verbose=False, save_choices=False)¶
- Simulates behaviour of the system until the finish_time is reached. - Parameters:
- finish_time (Time when simulation finishes.) 
- verbose (Should the execution log be printed in detail (default is False).) 
- save_choices (Should the choices for each component be saved to json files after) 
- False). (the simulation is finished (default is) 
 
 
 - simulation_process_simpy(env, max_time, verbose=False)¶
- The function simulates single concurrent thread of one component (CPSComponent). :param env: It is simpy environment used to synchronize multiple parallel threads during simulation. :type env: simpy.Environment :param max_time: It is the maximum time that the simulation will perform. :type max_time: float :param verbose: Should the function print execution logs (default is False). :type verbose: bool 
 - property state¶
- System state is a vector of all state variables. :return: 
 - time_continuous_dynamics(t, xt, xk, q, u, p, y)¶
 - time_discrete_dynamics(q, p, x, u)¶
 - timed_event(q, xc, xd)¶
- Calculates if and when the next time event will happen and the new state values. :param t: Current time. :param q: Discrete-event part of the state. :param xc: Time-continuous part of the state. :param xd: Time-discrete part of the state. :return: Time delay of the timed event, new state value. 
 - update_input(u)¶
 - wait(q)¶