MODEL-ORIENTED PROGRAMMING

The problem of complex multi-component system processing arises in many fields of science and engineering. A system can be described in terms of its components, behavior, and interaction. This work proposes a new declarative Turing complete “model-oriented” programming paradigm based on the concept of “model-component” a complex structure with well-defined characteristics and behavior, and no external methods. The set of model-components is closed under the union operation of model-components into “model-complex”. The proposed approach allows the program to describe the complex system and behavior of its components in a declarative way, possesses a higher level of encapsulation than the object-oriented paradigm, involves a reduced amount of imperative programming, and is naturally focused on parallel computations. UDC Classification: 004.42, DOI: https://doi.org/10.12955/pns.v2.144


Introduction
Nowadays, the processing of complex systems plays an important role in many fields of science and engineeringfrom demographics and economics (Belotelov et al., 2008) to biology, physics (Auyang, 1998), and software development (Jennings, 2001). In many cases, modeling and simulation are the only way to analyze the behavior and characteristics of such systems. As defined in the paper by Brodsky (2015), a complex system can be viewed as a compound object whose parts can be viewed as systems naturally united together according to certain principles or defined sets of relations. It means that components of a complex system can be complex systems themselves and that the arrangements of system "atoms", their behavior, and the rules of their interaction are well known. Once a formal description of the system is available, computer realization of its simulation model is possible (Brodsky, 2013(Brodsky, , 2014. Due to the complexity of the problem, it is preferred that the design and realization of the model are performed in some automated way to reduce the time spent on programming and the number of potential errors. Simulation modeling One possible approach to simulation modeling is the deductive approach which builds the model from top to bottom, starting from general ideas and concepts and gradually moving to more specific cases. In software development, this method can be related to object-oriented programming. It allows creating new models by building hierarchies of classes or applying class composition to reflect the structure of the systems under analysis. However, the organization of computational processes requires the application of an imperative paradigm by the developer to create the desired sequence of object method calls. The inductive approach is the opposite way of solving the problem. It takes advantage of the atomistic nature of complex systems where each component has its well-defined fixed characteristics and behavior, and the components often may not have a strict hierarchy. This approach works from bottom to top, starting from basic primitives and generalizing them into the whole model of a system. In this work, we will focus on the inductive approach and show how it can be applied to simulation modeling and that it can also be considered as a standalone programming paradigm.

Proposed approach
In this work, we propose a new declarative Turing complete "model-oriented" programming paradigm which is based on the concepts of "model-component" and "model synthesis" (Brodsky, 2013). A model-component is a complex structure with well-defined characteristics and behavior and with no external methods. Model-components are used as building blocks to synthesize the model of the whole system. This process is feasible since the set of model-components is closed under the union operation of model-components into a "model-complex". Hence, the whole system can be viewed as a single model-component, and each model-component can be processed by a common universal procedure. The behavior of each model-component can be described in terms of transitions between its internal states and corresponding internal methods, which can be executed in parallel. Such complex knowledge of the system and the behavior of its components can be programmed in a declarative way, and only internal methods may require limited imperative programming (if convenient).

Model-component
A "model-component" of a system is the main concept of the proposed approach. It can be considered as a building block of the system which has some characteristics and behavior. Several modelcomponents can be combined into an aggregated structure called "model-complex", which can be viewed as a model-component itself. Hence the whole system under analysis can be considered as a model-component. Each model-component has a set of internal and external characteristics and several internal methods. Internal characteristics can be considered as the states of the model-component. External characteristics are the parameters of the environment that affect the behavior of the model-component. Internal characteristics may depend on each other as well as on external characteristics. In contrast to the objectoriented approach, methods of the model-component cannot be called from the outside. The behavior of the model-component is defined by its internal characteristics and corresponding internal methods, and it can be changed by the occurrence of eventspoints where the response from the system is required to reflect the changes of the environment (the external characteristics). Several methods can be executed simultaneously (by parallel processes) as they are not allowed to change the same characteristics. Socalled "fast" methods occur instantly concerning modeling time and are used to calculate discrete characteristics of the system. "Slow" methods require non-zero modeling time and are used to calculate continuous characteristics of the system. A model of a system can be formally defined as an algorithm which determines the values of internal characteristics at the next step of the modeling process (Brodsky & Pavlovsky, 2009): where is the vector of internal characteristics at a time , is the vector of external characteristics at a time , = +1 − is the modeling time interval.

Closeness hypothesis
The existence of such an algorithm means that the system is closed: it is assumed that we have enough knowledge of the system to construct its model which can reproduce its dynamics (i.e. its internal characteristics ) at every point of modeling time of some time segment [0, ] if its initial state 0 and external characteristics are known (Brodsky, 2013).
More formally, the model is called (locally) closed at time point ∈ [0, ) if there exists > 0, + ∈ (0, ] such that: 1. it is possible to infer from internal characteristics ( ) and external characteristics ( ) if there exists calculable discontinuity (a gap) ( ) at point , 2. on the interval ( , + ] ( ) is a continuous function of time with value ( )+ ( ) at point . Hence, "fast" methods of a model-component are used to calculate the gaps, and "slow" methods are used to calculate continuous intervals of ( ) (Brodsky, 2013). The local closeness of a model is the necessary condition of model realization: if there exists a point at which even a small-time step is not possible, then it is unclear how to build the model. However, this condition is not sufficient (Brodsky 2013(Brodsky , 2014. The counterexample is the fly from the "train fly problem" whose speed has two limits at the time point when both trains meet. The additional requirement of left continuity of internal characteristics ( ) at any time point ∈ [0, ) make the condition sufficient (Brodsky 2013(Brodsky , 2014. This requirement means that any state of the model, except the initial, is the result of its prehistory. Based on the described conditions (namely functional dependency of the gap of internal characteristics, their continuous evolution, and the need to calculate the gap at each modeling step), a common universal procedure for processing any model-component can be defined. Events Events are the points of synchronization between methods of the model-componentpoints at which the values of internal and external characteristics require the reaction of the model-component. Formally, the event is a function of the model internal and external characteristics = ( , ) which returns the predicted time of its occurrence at the beginning of the simulation step. Occurrence of the event at a time is defined by the equation: ( , ) = 0.
Events control the switch between methods of the model-component: for each ordered pair of switchable methods { 1 , 2 } there exists a unique event { 1 , 2 } that defines the switch. Simultaneous occurrence of events { 1 , 2 } and { 1 , 3 } indicates an error in the design of the model.

Model behavior
The behavior of a model component is given by a procedure that defines the rules of its simulation calculations. It is assumed that at the beginning of every simulation step, all internal characteristics and current methods are known, and external characteristics can be observed at any time point. An appropriate default modeling time step is fixed. The procedure implements the following algorithm: 1. Compute the events which are associated with each current method : = { , } ( , ). 2. If any events corresponding to fast methods occur (i.e. some = 0), switch current methods accordingly, execute the methods and go to step 1. 3. If any events corresponding to slow methods occur, switch current methods accordingly. 4. Calculate the next modeling time step = ( , ). 5. Execute all current slow methods with calculated modeling time step , go to step 1.
The algorithm defines a common universal procedure for the execution process of any modelcomponent.

Model-complex
Several models-components can be combined into a higher-level element called "model-complex", where some model-components may explicitly model external characteristics of some other modelcomponents. To describe a model-complex it is enough to specify: 1. which models-components are included in the model-complex, 2. the number of included model-components of each type, 3. commutation of models-components inside the model-complex: which internal characteristics of which models-components are the external characteristics of model-components. When combining model-components into a model-complex, the unambiguity of the computational process may be lost. This might happen if, for some reason, several components calculate the same internal characteristics of the system under analysis. In this case, a new model-component should be included in the model-complex that treats all these characteristics as external characteristics and deterministically calculates the only value, which in turn represents a new internal characteristic of the complex (Brodsky, 2013).

Model-complex synthesis
A model-complex consisting of many models-components can be viewed as a single model-component. The union operation of model-components into a model-complex is defined by the following rules (Brodsky, 2013): 1. The internal characteristics of the complex are the union of the internal characteristics of all its components. 2. The processes of the complex are the union of the processes of all its components. 3. The methods of the complex are the union of the methods of all its components. 4. The events of the complex are the union of the events of all its components. 5. The external characteristics of the complex are the union of the external characteristics of all its components, except the ones that are explicitly modeled by some component of the complex. The fact that the set of model-components is closed under the union operation (i.e. that a model-complex can be treated as a model-component) is the basic idea of model synthesis, which allows developers to design and implement simulation models of complex multi-component systems of any required nesting and guarantees the existence of the aforementioned universal processing procedure.

Model-oriented paradigm
The proposed model-oriented approach allows designing and building programs from more aggregate elements (model-components) with a higher level of encapsulation than the object-oriented approach: methods of a model-component are internal and cannot be called manually; they are always executed automatically, thus demonstrating the behavior of the model. An important aspect of the approach is that the methods can be executed in parallel at each iterationit is guaranteed by the fact that the methods represent functional dependencies and are not allowed to change the same internal characteristics. As each synthesized model-complex (and hence the whole system itself) can be viewed as a modelcomponent, the computational process of model behavior can be implemented as a common universal procedure that allows parallelization of most calculations. All this allows creating models of systems with deep and complex nesting. The model-oriented paradigm splits the process of programming into two main steps: 1. Declarative programming of model-components and model-complexes. 2. Functional (or imperative if convenient) programming of internal methods. Hence the structure and interaction of components of the system under analysis are programmed in a declarative way which makes it possible to significantly reduce the time spent on programming and the number of potential errors compared to the imperative approach (Brodsky, 2013). The proposed approach paradigm is Turing complete which means that it can be successfully applied to a wider class of problems than just modeling of complex systems.

Turing completeness
We will show Turing completeness of the proposed model-oriented approach by the realization of Turing machine with semi-infinite tape (which is equivalent to Turing machine with finite tape as shown by Karpov (2003) = 0 is the initial state.
∈ is the blank symbol. 9. The set ∈ \ { } of allowed values of internal characteristics represent the set of input symbols. 10. The set = { , . . . , } ⊂ represents the initialized tape cells, ∉ are initially blank. 11. The transition function is represented by the "fast" internal method ( , , ) which changes the value of the current cell for the current state and value of current cell , updates the value of the current state and either increments, decrements, or does not modify the index of the current cell. 12. Execution of transition method is triggered by an empty event , at the beginning of each modeling step. 13. Execution is terminated if the value of the current state characteristic represents some final state, i.e.

= ∈
This construction provides the Turing machine with semi-infinite tape, thus proving Turing completeness of the proposed model-oriented programming paradigm.

Conclusion
In this paper, a new model-oriented programming paradigm has been proposed. It is a declarative approach that possesses a higher level of encapsulation than the object-oriented paradigm, involves a reduced amount of imperative programming, and is naturally focused on parallel computations. The proposed approach is Turing complete and is applicable for a wide class of problems, including simulation modeling of complex multi-component systems. The model-oriented paradigm has been successfully used to implement models of complex systems (Brodsky, 2013), and several tools for system simulation have been created (Brodsky & Lebedev, 1991;Brodsky, 2010). The scope of future work includes further development of the programming system for the model-oriented paradigm and extending its mathematical basis.