Automata and intelligent behavior. The main provisions of the concept (approach) Amosova N.M.





Continuing one of the topics raised in the publication of Alexander Ershov ( Ustas ) "Neural network visual search" , I suggest that Habr's readers dive into the world of N.M. Amosova, heri-models, M-nets and machines. I hope they are the most likely candidates for the role of the "silver bullet", which will allow enthusiasts of "strong intelligence" or, in other terminology, "artificial intelligence" to come closer to understanding the ways of its implementation.



In this article, the author tried to summarize the main provisions of the concept of Nikolai Mikhailovich Amosov in an extremely concise (concise) manner. This approach is described in sufficient detail in the collective monograph β€œAutomata and Reasonable Behavior. Modeling experience ”, the authors of which was N.. Amosov and his associates: AM Kasatkin, L.M. Kasatkina and S.A. Talayev. I can say that this is the only monograph of all works on the topic of "artificial intelligence" with which I have been able to get acquainted to this day, containing a clear, detailed, comprehensive, systematic and at the same time convincing, and, in some places, even highly artistic ( I say this without the slightest bit of irony) - an exposition of the theoretical foundations of the author's concept of "artificial intelligence", as well as the experimental results obtained on its basis.



I appeal to everyone who has enthusiasm, a burning interest in the topic of "artificial intelligence", as well as a desire to get to know more about NM's approach. Amosova - read on ...



Foreword



Do what you believe in and believe in what you do. Everything else is a waste of energy and time.

Nisargadatta Maharaj

, (1973), , : , , . . β€” . , .. β€” , ( , , ). [3] (. , .. .. ). , , .. , , 1990-. , , , , , , Β« Β» . , . , , .. . , , .. , , , .



:



1. , . , , . , .. .



2. .. Β«M- Β». , .



3. «» «» [3]. «» β€” [3].



4. . , .. . , , β€” .



5. - . :

–

– .

- ( ), – ( ).

, -.



5. ( ) , .



6. :



– .. ;

– .. ( ), ;

– «» «» β€” , «» .



1.





:



1. .



2. : , , .



3. , β€” , , .



4. β€” , , .



5. , , .



6. () , , .



1
, , , . .


7. , , . , «» «» , .



8. , ( , ), . , . - , .



9. .



10. ( ) .



11. , β€” Β« Β».



12. ( ) - . .



13. .



14. . . , β€” . . , .



15. β€” (arousal, ). . , , , .



2
, , β€” .


16. , - , .



17. , β€” . , .



18. . , ( ) .



19. , , .



20. , .



21. β€” , .



22. , .



23. , - (). β€” .



24. ( ) . . , (), . , , , .



25. :



– ,

– (),

– , (),

– β€” , ().



Β« , , , Β» [3, . 57].



26. , , . ( ), . , «» .



27. , , , , .



28. , . , . , , , () .



29. , , , . () . , .



30. , - -. , , .. , . , , , , .



31. , :



– – ;

– ;

– .



32. , , , . , , .



, , β€” .



-



, .



β€” , . . . , , .





1. , , , -.



2. - , , i-.



3. i- .



4. i- , . - , .



5. - , , .



.



6. i- , , , .



6.1. i- , .



6.2. i- . i- , .



6.2.1. i- .



6.2.2. i- , Ξ , . j- i- t Ξ  t j.



6.2.3. i- , i- .



7. i- , , . :



7.1. i - i- j i-.



7.2. i- , .



7.3. i- .



7.4. R, , , , .



, i- j i- i, t Rtij.



8. i- : -, , i- , , - β€” , i- .



9. Rtij Rtij=⟨rij,˜rij,r(0)ij~,r(0)ij⟩, rij,˜rij β€” , r(0)ij,˜r(0)ij β€” .



10. , Rtij, , , , i- i. rij,˜rij. , rijβ‰«Λœrij Rtij, β€” .



r(0)ij≀rij(1and)





˜r(0)ijβ‰€Λœrij...(1b)



.



10.1. Rtij=0 Rtij, .. ⟨0.0,0.0,0.0,0.0⟩.



10.2. , i-:



Rtij=R(Ξ ti,Ξ tj,Rt-1ij,Ξ”t)(2)



Ξ”t β€” -. i- . , - β€” -, . Ξ”t. Ξ”t .



10.3. t , Rtij=0. Rt-1ij=0 Rtij>0, , t Rtij. , . (2) , ,



Rtij=R1(Ξ ti,Ξ tj,Ξ”t)(3)



(3) .



10.4. , . Rtij , t0 Rtij≠0 Πi=0 Πj=0.



rtij=r1(rt-1ij,rt(0)ij)(4and)



˜rtij=r2(˜rt-1ij,˜rt(0)ij)(4b)



(4) (4) , rtij ˜rtij, , .



rt(0)ij=r3(rt-1(0)ij)(fiveand)



˜rt(0)ij=r4(˜rt-1(0)ij)(fiveb)



, rt(0)ij ˜rt(0)ij . , . , t0, Rtij (« »). rtij ˜rtij rt(0)ij ˜rt(0)ij, , (1) , Rtij (5) (5), .. (« »).



10.5. Ei (˜Ei) i- i rtij (˜rtij) i- j- i- Πj. i- i- (Ei) (˜Ei) :



Ei=E(Ξ t1,Ξ t2,...,rti1,rti2,.........)(6a)



˜Ei=˜E(Πt1,Πt2,...,˜rti1,˜rti2,.........)(6b)



11. i-.



11.1. i- , i- . i-, . i- .



11.2. i- i- . β€” i- ΞΈti, Eti i- i- t. β€” TO. TO β€” (Kti), ˜Eti, (Ktni). Ktni ΞΈti , Kti.



11.3. , i- , :



Kti=Φ(Ktni,˜Eti)(7)



11.4. , i- :



Ξ ti=T(Pit-1i,Ktni)(eight)



(8) i- Β« Β» i-.



11.4. , i- i- :



Ξ ti=Ξ (Kti,ΞΈti,Eti)(nine)



11.5. Ktni ΞΈti i-:



ΞΈti=ΞΈ(ΞΈt-1i,Ξ ti)(tena)



Ktni=K(Ktni,Ξ ti)(tenb)



(10) (10) , . , i-, , , («»). i- . i- , (10) (10) («»).



12. - i- .



12.1. - , , , , .



12.2. - :



– i- ;

– i- ;

– C ;

– i- ;

– J i-.



β€” - .



12.3. - , . i- . , i- «» .



12.4. - i-, , i-. -. , i-, . , .. i-, .



-





- , , - i- - .



, -, , . , - i-, . - i-, , . (.. ) i- . i- .



t - 1 i- . (6), i- . , (7) i- , (8) β€” , «», t - 1 t. , , (9) i- t, . , i- t , (6-9) :



Π t i = Φ ( E t i , ˜ E t i , Π t - 1 i , K t - 1 n i , θ t - 1 i )( 11 )



i- -, i-, -. - .



i- , t. , i- (). , t + 1, t + 2, ... ... ... , -.



i- . ( , ) i- -. i-, , β€” - .



, - i-. . .. , .



- i-, - . i- , . : i- «» () «» (). - i- , , Ξ”t=Ξ tPR-Ξ tHPR.



3
, Ξ”t, .



.. .. [5, 6]. , . . .


, - . Ξ” -, .





- :



1. «» i- (10) θ K. , i-.



2. «» i- (2) (4) (5) -.



3. - (2) , .. , i-. , .



4. - i-, , i- . i- . , , i-. . .



. i- -. i- (2) . , , «», .. i- i-, , i-, .



i- , i- . - . i- . - , (. ).



According to the authors, the processes of self-learning and self-organization can lead to education i- "second layer" models, i.e. ensembles from the originali-models, which, in turn, can form ensembles of the "third layer", etc. Ensembles of this kind can be viewed as new functional elements of the M-network, and the process of their formation - as the process of forming new complex concepts on the basis of previously available ones.





Figure 1. An object and its reflection in models of different levels of generalization. "Inputs" and "Outputs": En - energy; B - substance. Reproduced Fig. 12 from [4].

The processes described in cl. 1 and 2, the authors call self-learning processes , and the processes described in p. 3 and 4, called the processes of self-organization of the M-network.



Formal definition of an M-net



The previously introduced characteristics of the elements of the M-net (i- ) :



– ;

– ;

– .



, (11). (6)-(9).



(3)-(5), i-.



(2) -.



-. - ΞΌ :



μ = ⟨ P , S , R , L , F , C , I ⟩ ,( 12 )



P β€” i-; S β€” i-; R β€” ; L β€” ; F β€” ; C β€” ; I β€” i-.



– ()





- i- . i- . i- , – . i-, ( ), , - i- -. , i-, -, - . . - Β« Β», Β« Β» i-: - «» «» «» i- (- i- ).





, i-models - in this case, the probability of a positive feedback in the M-automaton is high: this will lead to a situation of unlimited (exponential) growth of the excitation of such a cluster i-models. Positive feedback betweeni-models are also possible with their "closure of connections" through the external environment: a natural analogue of this can be the occurrence of the so-called " ant circles of death " or circular motion in the caterpillars of a marching silkworm (a similar situation can occur not only in the world of insects - see, for example, circles in rams , unfortunately, in more complex situations, such a "walking in circles" is found in the human population).



Ant circle of death

Circular motion of the marching silkworm caterpillars

Remark 4
i- ( ).


, i- ( -). .





:



1. – ˜r – i-, ;



2. i- ( ) – ΞΈ;



3. i- ( ) – .. , (. . 11.4 – (9));



4. () – K (. . 11.3 – (8)).



… ( ), () .

, Β« Β» i- ( Β« Β») – -





, , .



Β« Β»! - . i- ( ).



5
Β« Β» , .


- .. ( , .. - Β« Β») , , . Β« Β»:



. , «» «» (), , «», – . , . – .

… . - , – – . , . , . . , , ( ), . , , . , , , () . – – , – .

.. ([2], . 49-51)

, .. (i-) – - (), ( -) i- i-.



- ( [9]):



- ( 6() [9])


( 6() [9]: ). () Β« Β»


( ) :

1. () i- ;

2. i-;

3. , ;

4. Β« Β» ;

5. Β« Β» i-.






[9, . 379]:



, [109, 110], . «» , . , , «», , .

(. 6) Β« Β», . ( ), , . . – , . , – [111-114].

[62, 89, 115] , – , .

(. [9, . 381]):



(., . [127]) . , .

9 . , , , , , . - , , . , , [128] .

Figure 2. "Heteroclinic tree" in the multidimensional phase space of a dynamic system describing the parallel and sequential activity of a large number of interacting modes involved in the performance of a certain cognitive function (a state representing a final decision or a developed behavior strategy is marked with a light disk). Figure: 9 from review [9]

Such a high-level mechanism not only makes it possible to restrain the uncontrolled increase in the excitement of certain groups i-models, but also, if necessary, break the "vicious circles" of transmission of activity within a certain set of ensembles i-models.



Basic properties



1. In the concept, the role of the SDT is to organize local positive and negative feedback in the information processing processes in the M-network. This ensures at each time interval the dominance of the information processing program, which is most important in terms of adaptation, over other programs developing in parallel in the M-network.



2. The SDT operates as follows:



2.1. Let some M-net be given.



2.2. In the process of processing information excitementi- network models are changing. The amount of excitation of eachi-model indirectly indicates the "importance" or value of the information recorded in it.



The scheme of interaction of the SDS with other elements of the M-network is shown in the following figure.





Figure 3. Scheme of SDS. S - SUT; F - strengthening of the main model; B - braking the rest; I1 and I2 - storey models of the meaning of the surrounding world; A1, A2 - storey models of actions directed outward; C1,C2 - models of programs of consciousness; e, f- models of feelings and emotions. Reproduced Fig. 19 from [2].

2.3. It is assumed that the allocation at each time of the most excitedi-model and strengthening of its influence on the general course of information processing will increase the efficiency of the network. This is exactly what the SDT solves.



2.4. Work SUT:



2.4.1. SDT at each moment of time chooses the most excitedi-model, further increases her agitation and reduces the excitability of the rest i-models (slows them down). If at some point in time the same maximum excitement haven i-models, then the additional excitement from the SDT for each of them will be in n times reduced.



2.4.2. For each "active"i-the model requires a brake "twin" (complementary i-), i-. . , ().



2.4.3. i-. i- , -.



2.4.4. i- . , i- . , , , i-, , , , . , «» , i-. , -, « » i- .



2.4.5. i-. . i-. , - ( i- ). , , -.



2.4.6. «» , ( , i- ).



2.4.7. , i- . i- : i-, , i-. , , , () . .



3. , , , -. , i- . i-, .



, , :





Figure 4. Organization diagram of a hierarchical SDS. Shown are three fields of "working" models, as well as neurons of the first (I) and the second (II) floors of the SDT with their amplifying (Have) and brake (T) elements. Reproduced Fig. 20 from work [2].

3.1. Let alli- network models are conventionally combined into several non-overlapping groups for some reason. These are groups of the first (lowest) level. These groups can, in turn, be combined into larger second-level groups, the latter into third-level groups, etc. The top-level group includes all the groups of the previous and therefore alli- network models. The total number of levels of such a "pyramid" in each specific case can be determined depending on the complexity of the M-network and the complexity of the tasks for which the automaton is being built.



The following figures show the organization diagrams of a hierarchical SDT and the principle of its interaction with levels. i-models of the M-network.



3.2. To each such groupi-models, one of the SDT subsystems is associated: in the M-network, as many SDT subsystems function simultaneously as there are groups of different levels in it.





Figure 5. Scheme of interaction of a hierarchical SDT with levels i-models of the M-network. A, B - "working" zones of the cortex with models a – a – a,b – b – b,c – c – c,d – d – d...

Most excited model a – a – a in the zone A, in the zone B model c – c – c less inhibited than d – d – d...



Element N FROMHaveT-I reinforced, element M inhibited from FROMHaveT-II; T - braking; Have - gain.



Reproduced Fig. 21 from work [2].



3.3. As one of the possible options for implementation may provide a trace. work algorithm:



3.3.1. subsystems of SDS of one level (the levels of subsystems will be allocated in accordance with the levels of the groups on which they work) compare the excitations, amplify the isolated and inhibition of the resti-models only within their groups. Subsystems of the SDT of the next level, each within its own group, compare the already average excitations of the groupsi-models of the lower level.





Figure 6. Example of a relationship i-models of the M-network. A - top floor model; a, b, c - lower floor models; 1,2,......... - adjacent models; D - model-antagonist; T - braking; K - quality models; H1,H2- models of feelings. Dotted lines show braking paths. Reproduced Fig. 22 from work [2].

3.3.2. The gain is not applied to a singlei-models, but to all i-models of the currently allocated group; i- models of other groups of the same level are braked proportionally.



3.4. i-, , i- .



3.5. , -.



i-



, , : « - i- , i-, «», , . , , , . i-, . , «» i- . i-, «» » [3].



, , i- , . β€” i-.



1. , i-, i-, Β« Β» : i-, , . : i-.



2. , i-, : «». β€” Β« Β». «» : , «» , , β€” Β« Β», .



- . : Β« , , ( ), - Β«-Β» , ..Β» [3].



3. i- , - , «» . « ».



4. i-, , β€” , , β€” , . . , , Β« Β» . i- , - «» , «», .



5. i- :



– i-, .

– i-. -, , «» «» .

– () , , , .



-



1. i-, . -. , i- «» i-, , . , , i- . i-.



2. -:



2.1. i- , .. , i- , i- β€” . β€” , i- . , i-, , «» i-. , , .



2.2. i- . i-. «» () , . , , , , .



2.3. i- β€” , . i- - i-. «» .



2.4. - : i- β€” «» . i- i- . «» , .. , «» , - .



2.5. When establishing links betweeni-models of various ensembles, the strength (permeability) of which depends on the frequency of joint excitations included in the ensemble i-models, the state of the integral centers for the assessment of Pr and NPr and some other factors, strongly related i-models have a greater likelihood of consistent selection by the boost-braking system compared to the rest i- network models. Accordingly, when selecting SDTi-model belonging to one of two strongly connected ensembles, there is a high probability that after a few moments of time the SDT will switch to one of the i-models of the second ensemble.





Figure 7. Possible (and not final) version of the class diagram for individual elements and their relationships in the concept of N.. Amosov.

3. Changes in arousal i- , β€” . , .



4. - , . i-. , , «» , i- .



-



-



, (12), - ΞΌ. (12) -. - t t + 1.



:



1) , (11); i- - t+1;



2) , i-;



3) , «», -; i- «» ;



4) , , -;



5) ; (., , , , .).



- . . , , -. , , - . , A -.



- ⟨μ,A⟩: - μ and includes an algorithm for its functioning A... In general, the work of the M-automaton can be represented as follows:





Figure 8. Block diagram of the M-automaton functioning algorithm. Reproduced fig. 5 from work [3].

If M-net ΞΌis given in the form (12), such an M-automaton is complete .



It is possible to construct M-automata, in which not all functions of the M-net are realized.



Self-learning M-automata are distinguished depending on the completeness of the M-network task:



ΞΌ=⟨P,S,R,L,βˆ…,C,I⟩,(13)



and non-learning M-automata;



ΞΌ=⟨P,S,R,βˆ…,βˆ…,C,I⟩,(fourteen)



sign βˆ… indicates that the corresponding item is not being entered.



Algorithm AND in the case of a self-learning M-automaton does not contain a block F or a group of characteristics of self-organization, and in the case of a non-learner - blocks F and L - groups of characteristics of self-learning.



( ) ( ) (, ) . -. - .



- -, AND .



:



1. - (-) i-.



2. i- i- , . i- i- () -.



-



, . - :



1. , (: ) .



2. . 1 -. -, .



3. , .



4. Β« Β» -, .. .



5. «» .



6. . 3 , . i-.



7. . 3 i-.



8. , i- . . , , .



9. ( ) . .. 6-8 , , .. . 3.



, .. 7 8 . , , , .



10. -.



11. A.



12. - .



2.



Start by doing what's necessary then do what's possible and suddenly you are doing the impossible.

, . , . , .

.

, .. . - - - . . .



, 6.





:



//------------------------------------------------------------------------------
  type
//------------------------------------------------------------------------------
{$REGION ' '}
//------------------------------------------------------------------------------
// 
    TConnection    = class;
//  
    TConnections   = class;
//------------------------------------------------------------------------------
// 
    TRelation      = class;
//  
    TRelations     = class;
//   i-
    TOutputs       = class;
//   i-
    TInputs        = class;
//------------------------------------------------------------------------------
// i-
    TModel         = class;
//  i-
    TModels        = class;
//------------------------------------------------------------------------------
//   i–:
//   
    TQualia        = class;
// 
    TPercept       = class;
//   - 
    TEffector      = class;
//------------------------------------------------------------------------------
// -,  i- ()
    TModelGroup    = class;
//  -
    TActivateInhibiteSystem = class;
//------------------------------------------------------------------------------
// -
    TAutomate      = class;
//------------------------------------------------------------------------------
// 
    TPlatform      = class;
//------------------------------------------------------------------------------
{$ENDREGION ' '}
//------------------------------------------------------------------------------


, , . .







.. – TRelation

– :



      property CurrActivateCoeff: double read GetCurrActivateCoeff write SetCurrActivateCoeff;


– :



      property ResidualActivateCoeff: double read GetResidualActivateCoeff write SetResidualActivateCoeff;


– :



      property CurrInhibitCoeff: double read GetCurrInhibitCoeff write SetCurrInhibitCoeff;


– :



      property ResidualInhibitCoeff: double read GetResidualInhibitCoeff write SetResidualInhibitCoeff;


.



i- :



  TRelation = class(..............)
  private
      FModelSource: TModel;              //   -    
      FModelTarget: TModel;              //    
      FConnection: TConnection;          // , .  
  private
      FSourceId: int64;                  //  - 
      FTargetId: int64;                  //   
  private
      FCurrActivateCoeff: double;
      FResidualActivateCoeff: double;
      FCurrInhibitCoeff: double;
      FResidualInhibitCoeff: double;
  protected
//................................................    
//................................................    
//................................................    
  public
//................................................    
//................................................    
//................................................    
  end;    


, (), , : .



, , , i-. , , , TRelation , , i- . , i-.



6
, CRUD-, .




, .

.. , :

1. (2):



    procedure Defrosting(ACoModel: TModel; const AQuality: double); overload; virtual;


2. (3):



    procedure Setting(ACoModel: TModel; const AQuality: double); overload; virtual;


3. (4):



    procedure AttenuationCurrActivation(); overload; virtual;


4. (4):



    procedure DampingCurrentInhibit(); overload; virtual;


5. (5):



    procedure AttenuationResidualActivation(); overload; virtual;


6. (5):



    procedure AttenuationResidualInhibit(); overload; virtual;


7. (6):



    function Activation(): double; overload; virtual;


8. (6):



    function Inhibition(): double; overload; virtual;


7
, .


TRelation



  TRelation = class(..............)
  private
//................
  protected
//   (2):
    procedure Defrosting(ACoModel: TModel; const AQuality: double); overload; virtual;
//   (3):
    procedure Setting(ACoModel: TModel; const AQuality: double); overload; virtual;
//      (4):
    procedure AttenuationCurrActivation(); overload; virtual;
//      (4):
    procedure DampingCurrentInhibit(); overload; virtual;
//      (5):
    procedure AttenuationResidualActivation(); overload; virtual;
//      (5):
    procedure AttenuationResidualInhibit(); overload; virtual;
//    (6):
    function Activation(): double; overload; virtual;
//    (6):
    function Inhibition(): double; overload; virtual;
//................
  end;    


, .

:

– (6) – Activation(…),

– (6) – Inhibition(…)



TModel, TRelation.



:



1. . TRelation , . , .

2. -, .

3. Activation(…) Inhibition(…) .

4. 7 8:



//................
    function TRelation.Activation(): double;
    begin
      Result := ResidualActivateCoeff + (System.Math.Max(CurrActivateCoeff, 0.0) * FModelSource.Arousal);
    end;
    function TRelation.Inhibition(): double;
    begin
      Result := ResidualInhibitCoeff + (System.Math.Max(CurrInhibitCoeff, 0.0) * FModelSource.Arousal);
    end;
//................


: () () -.



- -.





1. / ( XML) TConnection – :



  TConnection = class
  private
      FOwner: TConnections;
  private
      FSourceId: int64;
      FTargetId: int64;
  private
      FCurrActivateCoeff: double;
      FResidualActivateCoeff: double;
      FCurrInhibitCoeff: double;
      FResidualInhibitCoeff: double;
  protected
  ....
  public
    function Equals(AObject: TObject): boolean; overload; override;
  public
    function IsDefrosting(): boolean; overload; virtual;
  published
  [XMLAttribute('Source')]
      property SourceId: int64 read GetSourceId write SetSourceId;
  [XMLAttribute('Target')]
      property TargetId: int64 read GetTargetId write SetTargetId;
  published
  //   .
  [XMLAttribute('CurrActivate')]
      property CurrActivateCoeff: double read GetCurrActivateCoeff write SetCurrActivateCoeff;
  //   .
  [XMLAttribute('ResidualActivate')]
      property ResidualActivateCoeff: double read GetResidualActivateCoeff write SetResidualActivateCoeff;
  //   .
  [XMLAttribute('CurrInhibitCoeff')]
      property CurrInhibitCoeff: double read GetCurrInhibitCoeff write SetCurrInhibitCoeff;
  //   .
  [XMLAttribute('ResidualInhibitCoeff')]
      property ResidualInhibitCoeff: double read GetResidualInhibitCoeff write SetResidualInhibitCoeff;
  end;


2. , TConnection , - (-) – - /.

3. TConnection TRelation: . , TRelation. , Owner – . TRelation TConnection : , , TRelation - , TConnection. : TConnection, TRelation . , - : - / i-. , – .

4. Equals ( , ):



    function TConnection.Equals(AObject: TObject): boolean;
    begin
      if (SourceId <> TConnection(AObject).SourceId) then exit(false);
      Result := (TargetId = TConnection(AObject).TargetId);
    end;


5. , TConnection



    constructor Create(); overload; virtual;
    constructor Create(const ASourceId, ATargetId: int64;
      const AResidualActivateCoeff: double = 0.0;
      const AResidualInhibitCoeff: double = 0.0;
      const ACurrActivateCoeff: double = 0.0;
      const ACurrInhibitCoeff: double = 0.0); overload; virtual;
    //  .
    constructor Create(const ASourceConnection: TConnection); overload; virtual;


6. - IsDefrosting(): boolean – , :



//................
function TConnection.IsDefrosting(): boolean;
begin
  if (FCurrActivateCoeff <> 0.0) then exit(true);
  if (FResidualActivateCoeff <> 0.0) then exit(true);
  if (FCurrInhibitCoeff <> 0.0) then exit(true);
  if (FResidualInhibitCoeff <> 0.0) then exit(true);
  exit(false);
end;


TRelation



TRelation .

, , :

1. i- TModel : ;

2. - -;

3. TRelation TConnection.

4. , TRelation , -, -, :



  TRelation = class(..............)
  private
      FModelSource: TModel;
      FModelTarget: TModel;
      FConnection: TConnection;
  //................................................    
  protected
  //................................................    
      property Connection: TConnection read GetConnection write SetConnection;
  //................................................    
  public
  //................................................    
  published
      property ModelSource: TModel read GetModelSource write SetModelSource;
      property ModelTarget: TModel read GetModelTarget write SetModelTarget;
  published
      property SourceId: int64 read GetSourceId write SetSourceId;
      property TargetId: int64 read GetTargetId write SetTargetId;
      property SourceName: string read GetSourceName write SetSourceName;
      property TargetName: string read GetTargetName write SetTargetName;
  //................................................    
  end;


5. TRelation :

– β€” ;

– i-;

– ;

– -;

– () .

,



//................................................    
  public
//   .
    constructor Create(); overload; virtual;
//        i-.
    constructor Create(const ASourceId, ATargetId: int64); overload; virtual;
//      - (    ).
    constructor Create(const ASourceId: int64; ATarget: TModel); overload; virtual;
//        (   -).
    constructor Create(ASource: TModel; const ATargetId: int64); overload; virtual;
//      -  .
    constructor Create(ASource, ATarget: TModel; AConnection: TConnection); overload; virtual;
//................................................    
  end;


6. TRelation :



    destructor TRelation.Destroy();
    begin
//  ""   . 
      FResidualInhibitCoeff := -1.0;
      FCurrInhibitCoeff := -1.0;
      FResidualActivateCoeff := -1.0;
      FCurrActivateCoeff := -1.0;
// ""   .
      FTargetId := -1;
      FSourceId := -1;
//    .
      if (Assigned(FModelSource.Outputs)) then
        FModelSource.Outputs.Extract(Self);
//    .
      if (Assigned(FModelTarget.Inputs)) then
        FModelTarget.Inputs.Extract(Self);
//  . .
      if (Assigned(FConnection.Owner)) then
        FConnection.Owner.Remove(FConnection);
      System.SysUtils.FreeAndNil(FConnection);
      inherited Destroy();
    end;


, i-.







[XMLROOT('Connections')]
  TConnections = class(TVector<TConnection>)
  private
      FOwner: TAutomate;
  public
    constructor Create(); overload; override;
    constructor Create(AOwner: TAutomate); overload; virtual;
    destructor Destroy(); override;
  public
    function Add(const AValue: TConnection): int64; overload; override;
    function Insert(const AIndex: longint; const AValue: TConnection): int64; overload; override;
  end;
  TConnectionsClass = class of TConnections;


8
, TVector<T> TList<T>.


:

1. -. , , i- -, -. / -.

2. – .

3. -:



  TConnectionComparer = class(TComparer<TConnection>)
  protected
    function Equal(const ALeft, ARight: TConnection): boolean; overload; override;
    function LessThan(const ALeft, ARight: TConnection): boolean; overload; override;
    function GreaterThan(const ALeft, ARight: TConnection): boolean; overload; override;
  public
    constructor Create(); overload; override;
    destructor Destroy(); override;
  end;
  TConnectionComparerClass = class of TConnectionComparer;


TConnectionComparer ,



    function TConnectionComparer.Equal(const ALeft, ARight: TConnection): boolean;
    begin
      if (ALeft.SourceId <> ARight.SourceId) then exit(false);
      Result := (ALeft.TargetId = ARight.TargetId);
    end;
    function TConnectionComparer.LessThan(const ALeft, ARight: TConnection): boolean;
    begin
      if (ALeft.SourceId < ARight.SourceId) then exit(true);
      if (ALeft.SourceId > ARight.SourceId) then exit(false);
      Result := (ALeft.TargetId < ARight.TargetId);
    end;
    function TConnectionComparer.GreaterThan(const ALeft, ARight: TConnection): boolean;
    begin
      if (ALeft.SourceId > ARight.SourceId) then exit(true);
      if (ALeft.SourceId < ARight.SourceId) then exit(false);
      Result := (ALeft.TargetId > ARight.TargetId);
    end;


4. Add .

5. Insert , Owner : .

6. :



    constructor TConnections.Create();
    begin
      inherited Create(TConnectionComparer.Create()); //   -.
      FreeObjects := true;
      Sorted := true;
      Unique := true;
      ClassUnique := dupError;
      FOwner := nil;
    end;






, β€” TRelations – (TInputs) (TOutputs).

β€” TRelations:

TRelations:



  TRelations = class(TVector<TRelation>)
  private
      FOwner: TModel;
  protected
    function GetOwner(): TModel; overload; virtual;
    procedure SetOwner(const AValue: TModel); overload; virtual;
  protected
    function TryInnerInsert(const AIndex: longint; const AValue: TRelation; out AOutIndex: int64): boolean; overload; virtual;
    function Add(const AValue: int64): int64; overload; virtual;
  public
    constructor Create(); overload; override;
    constructor Create(AOwner: TModel); overload; virtual;
    destructor Destroy(); override;
  public
    function Add(const AValue: TRelation): int64; overload; override;
    function Insert(const AIndex: longint; const AValue: TRelation): int64; overload; override;
  public
      property Owner: TModel read GetOwner write SetOwner;
  end;




1. :

– ;

– ;

– CRUD-.

2. TRelations :

2.1. i- ( )



      function Add(const AValue: int64): int64; overload; virtual;


( ) (-). TOutputs TInputs.

2.2. ( ) i-



      function Add(const AValue: TRelation): int64; overload; override;


, .

2.3.



      function Insert(const AIndex: longint; const AValue: TRelation): int64; overload; override;


, , , .



      function TRelations.Insert(const AIndex: longint; const AValue: TRelation): int64;
      var
        AConnection: TConnection;
      begin
        try
//  TryInnerInsert     !
          if (TryInnerInsert(AIndex, AValue, Result)) then exit;
          Result := inherited Insert(AIndex, AValue);
          if (Result < 0) then exit;
          if (not Assigned(AValue.Connection)) then
            begin
              Owner.Automate.Connections.Add(AValue.CreateConnect());
            end;
        except
          Result := -1;
        end;
      end;


TryInnerInsert.

2.4. TryInnerInsert



//.......................................................
    protected
      function TryInnerInsert(const AIndex: longint; const AValue: TRelation; out AOutIndex: int64): boolean; overload; virtual;
//.......................................................
    end; 


:

– , – ;

– ,

– ;

– .

TryInnerInsert . , . , .



TryInnerInsert
      function TRelations.TryInnerInsert(const AIndex: longint; const AValue: TRelation; out AOutIndex: int64): boolean;
      var
        AIndexOf: integer;
      begin
        AOutIndex := AIndex;
        Result := false;
        if (Assigned(AValue.ModelSource) and Assigned(AValue.ModelTarget)) then exit;
// -   !
        if (Self is TInputs) then
          begin
            if ((AValue.TargetId >= 0) and (AValue.TargetId <> Owner.ObjectID)) then
              begin
//     ! !
                raise Exception.CreateFmt(RSErrorUnknowIds,[AValue.SourceId,AValue.TargetId, Owner.ObjectID, Self.ClassName]);
              end;
//    !
            if (AValue.SourceId < 0) then
              begin
//  !
                raise Exception.CreateFmt(RSErrorUnknowIds,[AValue.SourceId,AValue.TargetId, Owner.ObjectID, Self.ClassName]);
              end;
//  SourceId  TargetId!
//    !
            for AIndexOf := 0 to Self.Count - 1 do
              begin
                if (this[AIndex].SourceId <> AValue.SourceId) then continue;
                raise Exception.CreateFmt(RSErrorNotUniqueRelation,[AValue.SourceId,AValue.TargetId, Owner.ObjectID, Self.ClassName]);
              end;
            if (AValue.TargetId < 0) then
              begin
                AValue.TargetId := Owner.ObjectID;
              end;
//  -  -.
            if (not Assigned(AValue.ModelSource)) then
              AValue.ModelSource := Owner.Automate.FindById(AValue.SourceId);
            if (not Assigned(AValue.ModelTarget)) then
              AValue.ModelTarget := Owner;
          end;
        if (Self is TOutputs) then
          begin
            if ((AValue.SourceId >= 0) and (AValue.SourceId <> Owner.ObjectID)) then
              begin
//     ! !
                raise Exception.CreateFmt(RSErrorUnknowIds,[AValue.SourceId,AValue.TargetId, Owner.ObjectID, Self.ClassName]);
              end;
//    !
            if (AValue.TargetId < 0) then
              begin
// ...   !
                raise Exception.CreateFmt(RSErrorUnknowIds,[AValue.SourceId,AValue.TargetId, Owner.ObjectID, Self.ClassName]);
              end;
//  SourceId  TargetId!
//    !
            for AIndexOf := 0 to Self.Count - 1 do
              begin
                if (this[AIndex].TargetId <> AValue.TargetId) then continue;
                raise Exception.CreateFmt(RSErrorNotUniqueRelation,[AValue.SourceId,AValue.TargetId]);
              end;
            if (AValue.SourceId < 0) then
              begin
                AValue.SourceId := Owner.ObjectID;
              end;
//  -  -.
            if (not Assigned(AValue.ModelSource)) then
              AValue.ModelSource := Owner;
            if (not Assigned(AValue.ModelTarget)) then
              AValue.ModelTarget := Owner.Automate.FindById(AValue.TargetId);
          end;
        AOutIndex := AValue.ModelSource.Outputs.Insert(AIndex, AValue);
        AOutIndex := AValue.ModelTarget.Inputs.Insert(AIndex, AValue);
        Result := true;
      end;




TRelations – : TRelation.





:



    TInputs = class(TRelations)
    protected
      function Add(const AValue: int64): int64; overload; override;
    public
      constructor Create(); overload; override;
      destructor Destroy(); override;
    public
      function Insert(const AIndex: longint; const AValue: TRelation): int64; overload; override;
    end;
    TInputsClass = class of TInputs;
//..............................................................................
    TOutputs = class(TRelations)
    protected
      function Add(const AValue: int64): int64; overload; override;
    public
      constructor Create(); overload; override;
      destructor Destroy(); override;
    public
      function Insert(const AIndex: longint; const AValue: TRelation): int64; overload; override;
    end;
    TOutputsClass = class of TOutputs;


, Add, i-:



      function TInputs.Add(const AValue: int64): int64;
      begin
        Result := Add(TRelation.Create(AValue, Owner));
      end;
//..............................................................................
      function TOutputs.Add(const AValue: int64): int64;
      begin
        Result := Add(TRelation.Create(Owner, AValue));
      end;


AValue i-.



i-







i-, .. , :

– (Arousal),

– (Threshold),

– (ResidualActivateCoeff),

– (ActivateCoeff),

– (Inputs).

– (Outputs),



:

– , , ObjectId (int64).



, TNamedObject. :

– (ObjectId: int64);

– (Name: string);

– (NameShort: string);

– (Code: string).





i- i-:

– – Ativation(…) (9);

– – Inhibit(…) (7);

– – Attenuation(…) (8);

– – Overgrowth(…) (10);

– – Adaptation(…) (10).

, i-



    TModel = class(TNamedObject)
    private
//................................................    
    protected
//  : R (4.2).
      function Winding(AR: TRelation): TRelation; overload; virtual;
//  : R_1 (4.3).
      function Setting(AR: TRelation): TRelation; overload; virtual;
//  : (4.4, 4.4, 4.5  4.5).
      function Attenuation(AR: TRelation): TRelation; overload; virtual;
    protected
//    (9).
      function Ativation(): double; overload; virtual;
//  : (7).
      function Inhibit(): double; overload; virtual;
//     (8).
      function Attenuation(): double; overload; virtual;
//    (10).
      function Overgrowth(): double; overload; virtual;
//    (10).
      function Adaptation(): double; overload; virtual;
    protected
//     -  .
        property Arousal: double read GetArousal write SetArousal;
//  : (4.6).
        property ActivateEffect: double read GetActivateEffect write SetActivateEffect;
//  : (4.6).
        property InhibitEffect: double read GetInhibitEffect write SetInhibitEffect;
//   .
        property Threshold: double read GetThreshold write SetThreshold;
//   .
        property ActivateCoeff: double read GetActivateCoeff write SetActivateCoeff;
//  ()   .
        property ResidualActivateCoeff: double read GetResidualActivateCoeff write SetResidualActivateCoeff;
   protected
//     -  .
        property Arousal: double read GetArousal write SetArousal;
//  : (4.6).
        property ActivateEffect: double read GetActivateEffect write SetActivateEffect;
//  : (4.6).
        property InhibitEffect: double read GetInhibitEffect write SetInhibitEffect;
//   .
        property Threshold: double read GetThreshold write SetThreshold;
//   .
        property ActivateCoeff: double read GetActivateCoeff write SetActivateCoeff;
//  ()   .
        property ResidualActivateCoeff: double read GetResidualActivateCoeff write SetResidualActivateCoeff;
    protected
//................................................    
    end;


- , . «» , : 0.0.





i- TModel Exec(…) InternalExec(…). true, i- - .



    TModel = class(TNamedObject)
    private
//................................................    
    protected
      function InternalExec(): boolean; overload; virtual;
//................................................    
    public
      function Exec(): boolean; overload; virtual;
//................................................    
    end;


InternalExec(…) i- -. false.



i-



i-:



    TModel = class(TNamedObject)
    private
        FAutomate: TAutomate;
        FModels: TModels;
        FOwner: TModel;
    private
        FArousal: double;
        FActivateEffect: double;
        FInhibitEffect: double;
    private
        FThreshold: double;
        FActivateCoeff: double;
        FResidualActivateCoeff: double;
    private
        FOutputs: TOutputs;
        FInputs: TInputs;
    protected
      function GetThis(): TObject; overload; virtual;
    protected
      procedure SetObjectName(const AValue: TNameObject); overload; override;
      procedure SetObjectNameShort(const AValue: TNameShort); overload; override;
      procedure SetObjectCode(const AValue: TObjectName); overload; override;
    protected
      function GetOwner(): TModel; overload; virtual;
      procedure SetOwner(const AValue: TModel); overload; virtual;
    protected
      function GetThreshold(): double; overload; virtual;
      procedure SetThreshold(const AValue: double); overload; virtual;
      function GetArousal(): double; overload; virtual;
      procedure SetArousal(const AValue: double); overload; virtual;
      function GetActivateEffect(): double; overload; virtual;
      procedure SetActivateEffect(const AValue: double); overload; virtual;
      function GetInhibitEffect(): double; overload; virtual;
      procedure SetInhibitEffect(const AValue: double); overload; virtual;
      function GetActivateCoeff(): double; overload; virtual;
      procedure SetActivateCoeff(const AValue: double); overload; virtual;
      function GetResidualActivateCoeff(): double; overload; virtual;
      procedure SetResidualActivateCoeff(const AValue: double); overload; virtual;
    protected
      function GetOutputs(): TOutputs; overload; virtual;
      procedure SetOutputs(const AValue: TOutputs); overload; virtual;
      function GetInputs(): TInputs; overload; virtual;
      procedure SetInputs(const AValue: TInputs); overload; virtual;
    protected
      function GetAutomate(): TAutomate; overload; virtual;
      procedure SetAutomate(const AValue: TAutomate); overload; virtual;
      function GetPlatform(): TPlatform; overload; virtual;
      procedure SetPlatform(AValue: TPlatform); overload; virtual;
    protected
      procedure InternalExtract(); overload; virtual;
    protected
        property Models: TModels read FModels;
    protected
//................................................    
    protected
//     -  .
        property Arousal: double read GetArousal write SetArousal;
//  : (4.6).
        property ActivateEffect: double read GetActivateEffect write SetActivateEffect;
//  : (4.6).
        property InhibitEffect: double read GetInhibitEffect write SetInhibitEffect;
//   .
        property Threshold: double read GetThreshold write SetThreshold;
//   .
        property ActivateCoeff: double read GetActivateCoeff write SetActivateCoeff;
//  ()   .
        property ResidualActivateCoeff: double read GetResidualActivateCoeff write SetResidualActivateCoeff;
    protected
      class function GetClassInputs(): TInputsClass; overload; virtual;
      class function GetClassOutputs(): TOutputsClass; overload; virtual;
    protected
      function InternalExec(): boolean; overload; virtual;
      procedure ChangeArousal(AActivateInhibiteSystem: TActivateInhibiteSystem); overload; virtual;
    public
      constructor Create(); overload; override;
      constructor Create(const AObjectId: int64; const AName: string; const ANameShort: string = ''; const ACode: string = ''); overload; virtual;
      destructor Destroy(); override;
    public
      function Exec(): boolean; overload; virtual;
      function Perform(): boolean; overload; virtual;
    public
      procedure Reset(); overload; virtual;
    public
//................................................    
    public
        property Owner: TModel read GetOwner write SetOwner;
    published
        property Outputs: TOutputs read GetOutputs write SetOutputs;
        property Inputs: TInputs read GetInputs write SetInputs;
    published
        property Automate: TAutomate read GetAutomate write SetAutomate;
        property Platform: TPlatform read GetPlatform write SetPlatform;
    end;
    TModelClass = class of TModel;
            -:
    TModel = class(TNamedObject)
//................................................    
    public
//................................................    
      function Connect(ATarget: TModel; AConnection: TConnection): TModel; overload; virtual;
//................................................    
    end;


i-



.. i-. i-.

, i-:



[XMLROOT('Models')]
    TModels = class(TVector<TModel>)
    private
        FOwner: TAutomate;
    private
        FMapById: TMap<int64, int64>;
        FMapByName: TMap<string, int64>;
    private
        FIsTerminated: boolean;
    protected
      function GetOwner(): TAutomate; overload; virtual;
      procedure SetOwner(const AValue: TAutomate); overload; virtual;
      procedure InnerSetAutomate(const AModel: TModel); overload; virtual;
    protected
        property Owner: TAutomate read GetOwner;
    public
      constructor Create(); overload; override;
      constructor Create(const AComparer: JOBLIB.Core.Comparers.IComparer<TModel>); overload; override;
      constructor Create(AOwner: TAutomate); overload; virtual;
      destructor Destroy(); override;
    public
      function GetObjectId(): int64; overload; virtual;
    public
      function Add(const AValue: TModel): int64; overload; override;
      function Insert(const AIndex: longint; const AModel: TModel): int64; overload; override;
      function Extract(const AModel: TModel): TModel; overload; override;
      procedure Delete(const AIndex: longint); overload; override;
    public
      function FindById(const AModelId: int64): TModel; overload; virtual;
      function FindByName(const AModelName: string): TModel; overload; virtual;
    public
      procedure Reorder(const AStartIndex: integer); overload; override;
    end;
    TModelsClass = class of TModels;


  1. TModels TVector
    <TModel>
    .
  2. TModels ( : FreeObjects := true false).


  3.   procedure TModels.InnerSetAutomate(const AModel: TModel);
      begin
        AModel.Automate := Owner;
      end;


    , , .



    ( Insert):

      function TModels.Insert(const AIndex: longint; const AModel: TModel): int64;
      begin
        if (AModel.Name.Trim().IsEmpty()) then exit(-1);
        Result := inherited Insert(AIndex, AModel);
        if (AModel.ObjectID < 0) then
          begin
            AModel.ObjectID := GetObjectId();
          end;
        try
          if (AModel.ObjectID < 0) then
            raise Exception.Create(RSErrorIncorrectAutomate);
          FMapById.Add(AModel.ObjectID, Result);
          FMapByName.Add(AModel.Name, Result);
          InnerSetAutomate(AModel);
          Reorder(AIndex);
        except
          Result := -1;
        end;
      end;




      function FindById(const AModelId: int64): TModel; overload; virtual;
      function FindByName(const AModelName: string): TModel; overload; virtual;


    . :

    FMapById: TMap<int64, int64>;
    FMapByName: TMap<string, int64>;


    GUID i-.





      function TModels.Extract(const AModel: TModel): TModel;
      var
        AIndexOf: int64;
        AModelGroup: TModelGroup;
        ASubmodel: TSubmodel;
        AIndexSubmodelOf: integer;
      begin
        Result := inherited Extract(AModel);
        if (FIsTerminated) then exit;
        if (Assigned(AModel)) then
          begin
            if (FMapById.TryGetValue(AModel.ObjectID, AIndexOf)) then
              begin
                FMapById.Remove(AModel.ObjectID);
                FMapByName.Remove(AModel.Name);
                Reorder(AIndexOf);
              end;
          end;
      end;
      procedure TModels.Delete(const AIndex: longint);
      begin
        FMapById.Remove(this[AIndex].ObjectID);
        FMapByName.Remove(this[AIndex].Name);
        inherited Delete(AIndex);
        Reorder(AIndex);
      end;


    ObjectId :

      function GetObjectId(): int64; overload; virtual;




        property Owner: TAutomate read GetOwner;


    , - ( ), , - ( – -):

      function TModels.GetObjectId(): int64;
      begin
        Result := Owner.GetSequence().NextVal();
      end;


    , - - .





      procedure Reorder(const AStartIndex: integer); overload; override;


    , i-, i- .





    i-



    i-.

    - , i-:

    – – i-, – TPercept,

    – (qualia) – i-, i- – TQualia,

    – – i-, – TEffector.



    (qualia)



    TModel . TModel , Threshold Arousal ( ):



        TQualia = class(TModel)
        public
          constructor Create(); overload; override;
          destructor Destroy(); override;
        published
    [XMLAttribute('Threshold')]
            property Threshold;
    [XMLAttribute('Arousal')]
            property Arousal;
        end;




    (TPercept) (TEffector) TQualia:



        TPercept = class(TQualia)
        private
            FPlatform: TPlatform;
        protected
          function GetPlatform(): TPlatform; overload; override;
          procedure SetPlatform(AValue: TPlatform); overload; override;
        protected
          function InternalExec(): boolean; overload; override;
        public
          constructor Create(); overload; override;
          destructor Destroy(); override;
        public
          function Exec(): boolean; overload; override;
        published
            property Platform;
        end;




        TEffector = class(TQualia)
        private
            FPlatform: TPlatform;
        protected
          function GetPlatform(): TPlatform; overload; override;
          procedure SetPlatform(AValue: TPlatform); overload; override;
        protected
          function InternalExec(): boolean; overload; override;
        public
          constructor Create(); overload; override;
          destructor Destroy(); override;
        public
          function Exec(): boolean; overload; override;
        published
            property Platform;
        end;


    , Platform, () «» ( ):



        private
            FPlatform: TPlatform;
        protected
          function GetPlatform(): TPlatform; overload; override;
          procedure SetPlatform(AValue: TPlatform); overload; override;
        protected
    ..................................
        public
    ..................................
        public
    ..................................
        published
            property Platform;
        end;




          function Exec(): boolean; overload; override;


    «» «» , TPercept:



          function TPercept.Exec(): boolean;
          begin
            try
              if (not Assigned(Platform)) then
                raise Exception.Create('      !');
              Result := InternalExec();
            except
              Result := false;
            end;
          end;


    TEffector:



          function TEffector.Exec(): boolean;
          begin
            try
              if (not Assigned(Platform)) then
                raise Exception.Create('   !');
              Result := InternalExec();
            except
              Result := false;
            end;
          end;


    i- InternalExec(). , , TPercept TEffector.



    9
    Β« Β» , i-, .


    i-



    , i- :

    – () – i-, i-

    – – i-, - () i-, («» i-), i- (, , - ..). .. , ( [3] : . , ). , (.. i-). . , . .

    i-

    – (, ) – i- i-. , -, , -;

    – (, , , , -, , , - .) – i-, () ( ) .



    () i-



    ,



    , .. i-, i- (), i-, i-, i-. i-: .. , i- , «» ( , ).

    «» / :

    – TModel;

    – TGroupModel;

    – TSubmodel, TSubmodels.

    TSubmodel :

    1. TSubmodel () TModel ();

    2. TModel TSubmodel ( : () TModel);

    3. -;

    4. ;

    5. ;

    5.1. - ,

    5.2. i- () / ,

    6. / i- ();

    7. .



    , :



    :

    1. . , ; . 1, 2, 4, 5.1, 5.2 ( ). : 3, 6 7; TModel TInterfacedObject .

    2. . .

    3. - ( ). . : .

    4. - . :

    1. TSubmodel, :

    – , – Prototype: TModel;

    – – Refer: int64;

    – i-; i- – Prev: TSubmodel Next: TSubmodel;

    – i- ;

    – . OrderId: int64, .

    2. TModel:

    – (HeadSubmodel: TSubmodel) i-. , i-;

    – -, ;

    – FreeSubmodel(…) ;

    – OnAfterDisposeSubmodel, . CheckFreeModel(ASubmodel: TSubmodel): boolean.

    3. TSubmodels :

    3.1. TSubmodel -;

    3.2. Insert TSubmodels:

    – BindSubmodel -; :



          procedure TAutomate.BindSubmodel(ASubmodel: TSubmodel);
          begin
            if (not Ready) then exit;
            if (not Assigned(ASubmodel.Prototype)) then
              ASubmodel.Prototype := FindById(ASubmodel.Refer);
            if (not Assigned(ASubmodel.Owner)) then
              raise Exception.CreateFmt(' .    : %d',[ASubmodel.Refer]);
            ASubmodel.Prototype.HeadSubmodel := ASubmodel;
          end;


    – ( . 8). , ;

    – .

    3.2. BindSubmodel -:

    – Prototype , Refer;

    – HeadSubmodel ( – ) .

    4. () - ( - ):

    4.1. -.

    4.2. : -: Ready = false.

    4.3. -; BindSubmodel.

    4.4.

    – -

    – - (. ).

    5. :

    5.1. Delete(…) :

    – ( );

    – - ( FreeSubmodel).

    – ( inherited Delete(…));

    – - ( FreeSubmodel) – FreePrototype -.

    5.2. - ( FreeSubmodel TModel):

    – HeadSubmodel -;

    – ;

    – -

    – .

    6. -?

    6.1. - . :

    6.1.1. HeadSubmodel;

    6.1.2. (Extract) ;

    6.1.3. (Prev) ;

    6.1.4. Prev nil: «» Prev.Next;

    6.1.5. ACurrSubmodel;

    6.1.6. .

    6.2. .

    7. -, , () FreeSubmodel ( - ) . .

    8. () - ( – ) . «» . , , :



    10
    , - , .. .


    8.1. ;

    8.2. (not Submodels.IsEmpty()). Β« Β» , ;

    8.3. ;

    8.4. Β« Β»: Β« Β». , – . , , «» , .



    11
    Β« …! …! …!Β». ? ? – …


    8.5. : - , – , !

    ? : , «» « » . «» , / . :

    8.5.1. « » « (DAG, directed acyclic graph)» «» ;

    8.5.2. «» ;

    8.5.3. – β€” :

    – «» ;

    – «» .

    «» . , , – .

    8.5.4. : – «» ? : , , , . .

    8.6. , . 8.1-8.5 / .

    8.7. . 8.5. , . 8.3. 8.4.

    :



    //.......................................................................
          function TSubmodel.IsEqualsChild(AModel: TModel): boolean;
          begin
            // 8.3.
            if (Prototype.Equals(AModel)) then exit(false);
            // 8.4.
            if ((Prototype as TModelGroup).Contains(AModel.ObjectID)) then exit(false);
            Result := true;
          end;
    //.......................................................................
          function TSubmodels.CyclicDependencyCheck(ASubmodel: TSubmodel): boolean;
          var
            AParent: TModel;
            ACurrSubmodel: TSubmodel;
            AMapUnique: TMapUnique;
            AModelQueue: Queue<TModel>;
          begin
            if (not Assigned(Owner.Automate)) then exit(true);
            if (not Owner.Automate.Ready) then exit(true); //    !
          // 8.1.
            if (not (ASubmodel.Prototype is TModelGroup)) then exit(true);
          // 8.2.    ,          !
            if ((ASubmodel.Prototype as TModelGroup).Submodels.IsEmpty()) then exit(true);
          // 8.5.     !
            AMapUnique := TMapUnique.Create();
            try
              AModelQueue.Enqueue(Owner);
              Result := true;
              while (not AModelQueue.IsEmpty()) do
                begin
                  AParent := AModelQueue.Dequeue();
                  Result := ASubmodel.IsEqualsChild(AParent);
                  if (not Result) then break;
                  ACurrSubmodel := AParent.HeadSubmodel;
    // Assigned(ACurrSubmodel) = false -   AParent -  !
                  while (Assigned(ACurrSubmodel)) do
                    begin //    !    !
                      if (ACurrSubmodel.Owner is TModelGroup) then
                        begin
                          if (not AMapUnique.ContainsKey(ACurrSubmodel.Refer)) then
                            begin
                              AMapUnique.Add(ACurrSubmodel.Refer,0);
                              AModelQueue.Enqueue(ACurrSubmodel.Owner);
                            end;
                        end;
                      ACurrSubmodel := ACurrSubmodel.Prev;
                    end;
                end;
              while (not AModelQueue.IsEmpty()) do
                AModelQueue.Dequeue();
            finally
              System.SysUtils.FreeAndNil(AMapUnique);
            end;
          end;


    12
    Β« Β» Β« Β» ( , ).


    9. i-; : ( ) , , .

    : , – , – . , . .







    . 1 TSubmodel :



    [XMLROOT('Submodel')]
        TSubmodel = class(TReference<TModel>)
        private
            FOwner: TModel;
            FOrderId: int64;
            FSubmodelName: string;
        private
            FPrevSubmodel: TSubmodel;
            FNextSubmodel: TSubmodel;
        protected
          function GetRefer(): int64; overload; override;
        protected
          function GetOrderId(): int64; overload; virtual;
          procedure SetOrderId(const AValue: int64); overload; virtual;
          function GetName(): string; overload; virtual;
          procedure SetName(const AValue: string); overload; virtual;
        protected
          function GetOwner(): TModel; overload; virtual;
          procedure SetOwner(const AValue: TModel); overload; virtual;
        protected
          function GetPrevSubmodel(): TSubmodel;
          procedure SetPrevSubmodel(const AValue: TSubmodel);
          function GetNextSubmodel(): TSubmodel;
          procedure SetNextSubmodel(const AValue: TSubmodel);
        public
          constructor Create(); overload; override;
          constructor Create(APrototype: TModel); overload; virtual;
          destructor Destroy(); override;
        public
          function IsEqualsChild(AModel: TModel): boolean; overload; virtual;
        public
            property Prototype;
        public
            property Prev: TSubmodel read GetPrevSubmodel write SetPrevSubmodel;
            property Next: TSubmodel read GetNextSubmodel write SetNextSubmodel;
        published
            property Owner: TModel read GetOwner write SetOwner;
        published
    [XMLAttribute('Refer')]
            property Refer;
    [XMLAttribute('OrderId')]
            property OrderId: int64 read GetOrderId write SetOrderId;
    [XMLAttribute('Name')]
            property Name: string read GetName write SetName;
        end;
        TSubmodelClass = class of TSubmodel;


    TSubmodel TReference<T: class, constructor>. , :



        TReference<T: class, constructor> = class
        private
            FRefer: int64;
            FPrototype: T;
        protected
          function GetPrototype(): T; overload; virtual;
          procedure SetPrototype(const AValue: T); overload; virtual;
          function GetRefer(): int64; overload; virtual;
          procedure SetRefer(const AValue: int64); overload; virtual;
        protected
            property Prototype: T read GetPrototype write SetPrototype;
            property Refer: int64 read GetRefer write SetRefer;
        public
          constructor Create(); overload; virtual;
          destructor Destroy(); override;
        end;


    , TSubmodel.



    TModel



    4, . 2 (. ), TModel.

    1. , . :

    – ,

    – ,

    – .

    , FreePrototype() -.

    , :



       TModeFreePrototype =
         (
             mdpFreePrototype              // 1- .
           , mdpUseRequestFreePrototype    // 2- .
           , mdpUseDefaultMode             // 3- .
         );
       TModesFreePrototype = set of TModeFreePrototype;


    2. :



       TOnAfterDisposeSubmodel = function (APrototypeModel: TModel; ASubmodel: TSubmodel): boolean of object;


    , , TModel (. ):



    TModel
    [XMLROOT('Model')]
        TModel = class(TNamedObject)
        private
            FAutomate: TAutomate;
            FOwner: TModel;
            FModesFreePrototype: TModesFreePrototype;
            FHeadSubmodel: TSubmodel;
            FOnAfterDisposeSubmodel: TOnAfterDisposeSubmodel;
        private
            FArousal: double;
            FActivateEffect: double;
            FInhibitEffect: double;
        private
            FThreshold: double;
            FActivateCoeff: double;
            FResidualActivateCoeff: double;
        private
            FOutputs: TOutputs;
            FInputs: TInputs;
        protected
          function GetThis(): TObject; overload; virtual;
        protected
          procedure SetObjectName(const AValue: TNameObject); overload; override;
          procedure SetObjectNameShort(const AValue: TNameShort); overload; override;
          procedure SetObjectCode(const AValue: TObjectName); overload; override;
        protected
          function GetOwner(): TModel; overload; virtual;
          procedure SetOwner(const AValue: TModel); overload; virtual;
        protected
          function GetThreshold(): double; overload; virtual;
          procedure SetThreshold(const AValue: double); overload; virtual;
          function GetArousal(): double; overload; virtual;
          procedure SetArousal(const AValue: double); overload; virtual;
          function GetActivateEffect(): double; overload; virtual;
          procedure SetActivateEffect(const AValue: double); overload; virtual;
          function GetInhibitEffect(): double; overload; virtual;
          procedure SetInhibitEffect(const AValue: double); overload; virtual;
          function GetActivateCoeff(): double; overload; virtual;
          procedure SetActivateCoeff(const AValue: double); overload; virtual;
          function GetResidualActivateCoeff(): double; overload; virtual;
          procedure SetResidualActivateCoeff(const AValue: double); overload; virtual;
        protected
          function GetOutputs(): TOutputs; overload; virtual;
          procedure SetOutputs(const AValue: TOutputs); overload; virtual;
          function GetInputs(): TInputs; overload; virtual;
          procedure SetInputs(const AValue: TInputs); overload; virtual;
        protected
          function GetAutomate(): TAutomate; overload; virtual;
          procedure SetAutomate(const AValue: TAutomate); overload; virtual;
          function GetPlatform(): TPlatform; overload; virtual;
          procedure SetPlatform(AValue: TPlatform); overload; virtual;
        protected
          procedure InternalExtract(); overload; virtual;
          procedure FreeHeadSubmodels(); overload; virtual;
        protected
          function CheckFreeModel(ASubmodel: TSubmodel): boolean;
          function FreeSubmodel(ASubmodel: TSubmodel): boolean; overload; virtual;
        protected
          function GetHeadSubmodel(): TSubmodel; overload; virtual;
          procedure SetHeadSubmodel(const AValue: TSubmodel); overload; virtual;
          function GetModesFreePrototype(): TModesFreePrototype; overload; virtual;
          procedure SetModesFreePrototype(const AValue: TModesFreePrototype); overload; virtual;
        protected
          function GetOnAfterDisposeSubmodel: TOnAfterDisposeSubmodel;
          procedure SetOnAfterDisposeSubmodel(const AValue: TOnAfterDisposeSubmodel); overload; virtual;
        protected
    //  : R (4.2).
          function Winding(AR: TRelation): TRelation; overload; virtual;
    //  : R_1 (4.3).
          function Setting(AR: TRelation): TRelation; overload; virtual;
    //  : (4.4, 4.4, 4.5  4.5).
          function Attenuation(AR: TRelation): TRelation; overload; virtual;
        protected
    //    (9).
          function Ativation(): double; overload; virtual;
    //  : (7).
          function Inhibit(): double; overload; virtual;
    //     (8).
          function Attenuation(): double; overload; virtual;
    //    (10).
          function Overgrowth(): double; overload; virtual;
    //    (10).
          function Adaptation(): double; overload; virtual;
        protected
    //     -  .
            property Arousal: double read GetArousal write SetArousal;
    //  : (4.6).
            property ActivateEffect: double read GetActivateEffect write SetActivateEffect;
    //  : (4.6).
            property InhibitEffect: double read GetInhibitEffect write SetInhibitEffect;
    //   .
            property Threshold: double read GetThreshold write SetThreshold;
    //   .
            property ActivateCoeff: double read GetActivateCoeff write SetActivateCoeff;
    //  ()   .
            property ResidualActivateCoeff: double read GetResidualActivateCoeff write SetResidualActivateCoeff;
        protected
            property HeadSubmodel: TSubmodel read GetHeadSubmodel write SetHeadSubmodel;
        protected
          class function GetClassInputs(): TInputsClass; overload; virtual;
          class function GetClassOutputs(): TOutputsClass; overload; virtual;
        protected
          function InternalExec(): boolean; overload; virtual;
          procedure ChangeArousal(AActivateInhibiteSystem: TActivateInhibiteSystem); overload; virtual;
        public
          constructor Create(); overload; override;
          constructor Create(const AObjectId: int64; const AName: string; const ANameShort: string = ''; const ACode: string = ''); overload; virtual;
          destructor Destroy(); override;
        public
          function Exec(): boolean; overload; virtual;
          function Perform(): boolean; overload; virtual;
        public
          procedure Reset(); overload; virtual;
        public
          function Connect(ATarget: TModel; AConnection: TConnection): TModel; overload; virtual;
        public
            property Owner: TModel read GetOwner write SetOwner;
        published
            property Outputs: TOutputs read GetOutputs write SetOutputs;
            property Inputs: TInputs read GetInputs write SetInputs;
        published
            property Automate: TAutomate read GetAutomate write SetAutomate;
            property Platform: TPlatform read GetPlatform write SetPlatform;
        published
            property ModesFreePrototype: TModesFreePrototype read GetModesFreePrototype write SetModesFreePrototype;
        published
            property OnAfterDisposeSubmodel: TOnAfterDisposeSubmodel read GetOnAfterDisposeSubmodel write SetOnAfterDisposeSubmodel;
        end;
        TModelClass = class of TModel;


    , :

    – CheckFreeModel – , :



          function TModel.CheckFreeModel(ASubmodel: TSubmodel): boolean;
          begin
            Result := false;
            if (TModeFreePrototype.mfpUseRequestFreePrototype in ModesFreePrototype) then
              begin
                if (Assigned(OnAfterDisposeSubmodel)) then
                  begin
                    Result := OnAfterDisposeSubmodel(Self, ASubmodel);
                  end
                else if (TModeFreePrototype.mfpUseDefaultMode in ModesFreePrototype) then
                  begin
                    Result := (TModeFreePrototype.mfpFreePrototype in FModesFreePrototype);
                  end;
              end
            else
              begin
                Result := (TModeFreePrototype.mfpFreePrototype in ModesFreePrototype);
              end;
          end;


    – FreeSubmodel – :



          function TModel.FreeSubmodel(ASubmodel: TSubmodel): boolean;
          var
            APrevSubmodel: TSubmodel;
            ANextSubmodel: TSubmodel;
          begin
            Result := false;
            if (ASubmodel.Equals(FHeadSubmodel)) then
              begin
                FHeadSubmodel := ASubmodel.Prev;
                ASubmodel.Prev := nil;
                if (Assigned(FHeadSubmodel)) then
                  begin
                    FHeadSubmodel.FNextSubmodel := nil;
                  end
                else
                  begin //     -!
    //     !
                    Result := ASubmodel.Owner.CheckFreeModel(ASubmodel);
                    exit;
                  end;
              end
            else
              begin
                Result := false;
    //     !
                if (Assigned(ASubmodel.Prev)) then
                  begin
                    ASubmodel.Prev.Next := ASubmodel.Next;
                    if (Assigned(ASubmodel.Next)) then
                      begin
                        ASubmodel.Next.Prev := ASubmodel.Prev;
                      end;
                  end
                else
                  begin
                    if (Assigned(ASubmodel.Next)) then
                      begin
                        ASubmodel.Next.Prev := nil;
                      end;
    //   not Assigned(ASubmodel.Next) -   
    //    (ASubmodel = FHeadSubmodel),     
    //  !
                  end;
    //  !
                ASubmodel.Prev := nil;
                ASubmodel.Next := nil;
              end;
          end;


    – SetHeadSubmodel – :



          procedure TModel.SetHeadSubmodel(const AValue: TSubmodel);
          begin
            if (not Assigned(FHeadSubmodel)) then
              begin //      !
                FHeadSubmodel := AValue;
    //   !
                FHeadSubmodel.Prev := nil;
              end
            else
              begin
                if (FHeadSubmodel.Equals(AValue)) then exit;
                FHeadSubmodel.Next := AValue;
                AValue.Prev := FHeadSubmodel;
                FHeadSubmodel := AValue;
              end;
      //   !
              FHeadSubmodel.Next := nil;
          end;


    , Destroy() – , :



          destructor TModel.Destroy();
          begin
            InternalExtract();
            FResidualActivateCoeff := 0.0;
            FActivateCoeff := 0.0;
            FInhibitEffect := 0.0;
            FActivateEffect := 0.0;
            FArousal := 0.0;
            FThreshold := 0.0;
            System.SysUtils.FreeAndNil(FOutputs);
            System.SysUtils.FreeAndNil(FInputs);
            FHeadSubmodel := nil;
            FModesFreePrototype := [TModeFreePrototype.mfpFreePrototype];
            FOwner := nil;
            FOnAfterDisposeSubmodel := nil;
            inherited Destroy();
          end;






    , TModelGroup:



    [XMLROOT('Group')][CINC(10,'')][ClassVarInherited()]
        TModelGroup = class(TQualia)
        private
            FSubmodels: TSubmodels;
        protected
          function GetSubmodels(): TSubmodels; overload; virtual;
          procedure SetSubmodels(const AValue: TSubmodels); overload; virtual;
        protected
          class function GetClassSubmodels(): TSubmodelsClass; overload; virtual;
        protected
          function InternalExec(): boolean; overload; override;
        public
          constructor Create(); overload; override;
          destructor Destroy(); override;
        public
          procedure Prepare(); overload; virtual;
        public
          function Exec(): boolean; overload; override;
          procedure Reset(); overload; override;
        public
          function Add(AModel: TModel): TModel; overload; virtual;
          procedure Clear(); overload; virtual;
        public
          function FindById(const AModelId: int64): TSubmodel; overload; virtual;
          function FindByName(const AModelName: string): TSubmodel; overload; virtual;
          function Contains(const ASubmodel: int64): boolean; overload; virtual;
        published
    [XMLARRAY('Submodels','Submodel')]
            property Submodels: TSubmodels read GetSubmodels write SetSubmodels;
        end;
        TModelGroupClass = class of TModelGroup;


    TModelGroup:

    1. TModelGroup – TQualia.

    2. , , .

    3. :



    //.......................................................
        public
          function Add(AModel: TModel): TModel; overload; virtual;
          procedure Clear(); overload; virtual;
        public
          function FindById(const AModelId: int64): TModel; overload; override;
          function FindByName(const AModelName: string): TModel; overload; override;
    //.......................................................
        end;


    4. Prepare():



    //......................................................
        public
    //......................................................
          procedure Prepare(); overload; virtual;
    //......................................................
        end;


    . – , , .



    1. InternalExec(…) Exec(…):

      ..............................
      protected
        function InternalExec(): boolean; overload; virtual;
      ..............................
      ..............................
      ..............................
      public
      ..............................
      ..............................
      public
        function Exec(): boolean; overload; override;
      ..............................
      ..............................
      end;


      :

        function TModelGroup.InternalExec(): boolean;
        var
          AModel: TModel;
        begin
          for AModel in Models do
            begin
              Result := AModel.Exec();
              if (not Result) then break;
            end;
        end;
        function TModelGroup.Exec(): boolean;
        begin
          Result := InternalExec();
        end;


      , InternalExec(): i- , . i- - «» – false. , i-, , InternalExec().

      ( InternalExec(…)) :

      2.

        function TModelGroup.InternalExec(): boolean;
        var
          AModel: TModel;
        begin
          for AModel in Models do
            begin
              Result := AModel.Exec();
              Result := AIS.Exec(Result, AModel);
              if (not Result) then break;
            end;
        end;


      3.

        function TModelGroup.InternalExec(): boolean;
        var
          AModel: TModel;
        begin
          for AModel in Models do
            begin
              Result := AModel.Exec();
              if (not Result) then break;
            end;
          Result := AIS.Exec(Result);
        end;


      4.

        function TModelGroup.Exec(): boolean;
        begin
          Result := InternalExec();
          Result := AIS.Exec(Result);
        end;


      - , InternalExec(…) Exec(…).





      -



      i- – -.





      - :



          TActivateInhibiteSystem = class(TModelGroup)
          private
              FClamping: double;
              FQueuePerformModels: TQueuePerformModels;
          protected
            function GetClamping(): double; overload; virtual;
            procedure SetClamping(const AValue: double); overload; virtual;
          protected
            function InternalExec(const AStatus: boolean): boolean; overload; virtual;
            function InternalExec(const AStatus: boolean; AModel: TModel): boolean; overload; virtual;
          protected
            class function GetClassSubmodels(): TSubmodelsClass; overload; override;
          protected
            function Check(ASubmodel: TSubmodel): boolean; overload; virtual;
            procedure BeforePerform(); overload; virtual;
            function EnqueuePerformModels(): TQueuePerformModels; overload; virtual;
            function Accept(ASubmodel: TSubmodel): boolean; overload; virtual;
            function InternalExec(): boolean; overload; override;
          public
            constructor Create(); overload; override;
            destructor Destroy(); override;
          public
            procedure OrderBy(AIndexStart: longint = 0; AIndexFinish: longint = -1); overload; virtual;
            procedure OrderBy(AComparer: JOBLIB.Core.Comparers.IComparer<TSubmodel>; AIndexStart: longint = 0; AIndexFinish: longint = -1); overload; virtual;
          public
            function Perform(): boolean; overload; override;
          public
            function Exec(const AStatus: boolean): boolean; overload; virtual;
            function Exec(const AStatus: boolean; AModel: TModel): boolean; overload; virtual;
          published
              property Clamping: double read GetClamping write SetClamping;
          end;


      , :

      1. ( TModelGroup).

      2. Clamping – , i-. .. (Arousal), i-: i- ( ) , . , Clamping . - Clamping .

      3. QueuePerformModels: TQueuePerformModels. .

      4. 4- () :



          TActivateInhibiteSystem = class(TModelGroup)
      ..............................
      ..............................
          protected
            function InternalExec(const AStatus: boolean): boolean; overload; virtual;
            function InternalExec(const AStatus: boolean; AModel: TModel): boolean; overload; virtual;
      ..............................
      ..............................
          public
      ..............................
      ..............................
          public
            function Exec(const AStatus: boolean): boolean; overload; virtual;
            function Exec(const AStatus: boolean; AModel: TModel): boolean; overload; ..............................
      ..............................
      virtual;
          published
      ..............................
      ..............................
          end;


      5. , , :

      5.1. i-, , «». i- «» i-, - «» . i-, « » .

      5.2. , . , ModesFreePrototype, [] ( Β«- Β»). , TActivateInhibiteSystem :



            constructor TActivateInhibiteSystem.Create();
            begin
              inherited Create();
      // -       !
              FModesFreePrototype := [];
              FClamping := 0.0;
              FQueuePerformModels := TQueuePerformModels.Create();
            end;


      SetModesFreePrototype :



            procedure TActivateInhibiteSystem.SetModesFreePrototype(const AValue: TModesFreePrototype);
            begin
            end;


      , Β« Β».



      13
      «» . i-.


      6. . :



      procedure OrderBy(AIndexStart: longint = 0; AIndexFinish: longint = -1); overload; virtual;
      procedure OrderBy(AComparer: JOBLIB.Core.Comparers.IComparer<TModel>; AIndexStart: longint = 0; AIndexFinish: longint = -1); overload; virtual;


      6.1. (, (Arousal) i-). i- -. , -.

      6.2. - i- . :



          TDefaultAISModelComparer = class(TComparer<TSubmodel>)
          protected
            function Equal(const ALeft, ARight: TSubmodel): boolean; overload; override;
            function LessThan(const ALeft, ARight: TSubmodel): boolean; overload; override;
            function GreaterThan(const ALeft, ARight: TSubmodel): boolean; overload; override;
          public
            constructor Create(); overload; override;
            destructor Destroy(); override;
          end;
          TDefaultAISModelComparerClass = class of TDefaultAISModelComparer;


      - TComparer<TSubmodel> : Equal, LessThan GreaterThan. System.Generics.Defaults.

      :



            function TDefaultAISModelComparer.Equal(const ALeft, ARight: TSubmodel): boolean;
            begin
      //  ,       !
      //       .
              Result := (Abs(ALeft.Prototype.Arousal - ARight.Prototype.Arousal) < 1.0e-5);
            end;
            function TDefaultAISModelComparer.LessThan(const ALeft, ARight: TSubmodel): boolean;
            begin
              Result := (ALeft.Prototype.Arousal < ARight.Prototype.Arousal);
            end;
            function TDefaultAISModelComparer.GreaterThan(const ALeft, ARight: TSubmodel): boolean;
            begin
              Result := (ALeft.Prototype.Arousal > ARight.Prototype.Arousal);
            end;


      7. - - i-, i- ! , :



            constructor TAISSubmodels.Create();
            begin
              inherited Create(TDefaultAISModelComparer.Create());
            end;
            constructor TAISSubmodels.Create(AOwner: TModel);
            begin
              Create();
              FOwner := AOwner;
            end;


      :

      7.1. TActivateInhibiteSystem



            class function GetClassSubmodels(): TSubmodelsClass; overload; override;




            class function TActivateInhibiteSystem.GetClassSubmodels(): TSubmodelsClass;
            begin
              Result := TAISSubmodels; // inherited GetClassSubmodels();
            end;


      7.2. i- ObjectId : .

      7.3. :

      – ;



            procedure TAISModels.InnerSetOwner(const AModel: TSubmodel);
            begin
            end;


      – ObjectId



            function TAISModels.FindById(const AModelId: int64): TSubmodel;
            var
              AIndexOf: int64;
            begin
              if (not FMapById.TryGetValue(AModelId, AIndexOf)) then exit(nil);
              Result := this[AIndexOf];
            end;
            function TAISModels.FindByName(const AModelName: string): TSubmodel;
            var
              AIndexOf: int64;
            begin
              if (not FMapByName.TryGetValue(AModelName, AIndexOf)) then exit(nil);
              Result := this[AIndexOf];
            end;


      –



            procedure TAISModels.Reorder(const AStartIndex: integer);
            var
              AIndexOf: integer;
            begin
              for AIndexOf := AStartIndex to Count - 1 do
                begin
                  FMapById.AddOrSetValue(this[AIndexOf].ObjectID, AIndexOf);
                  FMapByName.AddOrSetValue(this[AIndexOf].Name, AIndexOf);
                end;
              end;
            end;


      AStartIndex, 0!

      7.3. , - :



          TAISSubmodels = class(TSubmodels)
          protected
            procedure InnerSetOwner(const AModel: TSubmodel); overload; override;
          protected
              property Owner: TModel read GetOwner;
          public
            constructor Create(); overload; override;
            constructor Create(AOwner: TModel); overload; override;
            destructor Destroy(); override;
          public
            function FindById(const AModelId: int64): TSubmodel; overload; override;
            function FindByName(const AModelName: string): TSubmodel; overload; override;
          public
            procedure Reorder(const AStartIndex: integer); overload; override;
         end;
         TAISSubmodelsClass = class of TAISSubmodels;




      1. .

      .. i-



            function TModelGroup.InternalExec(): boolean;
            var
              AModel: TModel;
            begin
              for AModel in Models do
                begin
                  Result := AModel.Exec();
                  if (not Result) then break;
                end;
            end;


      :

      – i-;

      – i- (arousal) / Clamping - ( ),

      – ( );

      – ( ) () i- ( – );

      – ( ) - ;

      – -.

      2. ,

      2.1. TModel Perform(…)



            TModel = class(................)
      //.......................................................
            public
      //.......................................................
              function Perform(): boolean; overload; virtual;
      //.......................................................
            end;


      i- . - . , true, – false. – true.



      14
      : Exec(…) i-, Perform() «» – i- .


      2.2. i- TQueuePerformModels ( - )



          TQueuePerformModels = class(TQueue<TModel>)
          public
      //.......................................................
            constructor Create(); overload; override;
            destructor Destroy(); override;
      //.......................................................
          end;
      //.......................................................
            constructor TQueuePerformModels.Create();
            begin
              inherited Create();
              FreeObjects := false;
            end;
            destructor TQueuePerformModels.Destroy();
            begin
              inherited Destroy();
            end;
      //.......................................................


      TActivateInhibiteSystem FQueuePerformModels, , EnqueuePerformModels(…), , , :



          TActivateInhibiteSystem = class(TModelGroup)
          private
      //.......................................................
              FQueuePerformModels: TQueuePerformModels;
          protected
      //.......................................................
          public
            constructor Create(); overload; override;
            destructor Destroy(); override;
          public
      //.......................................................
          public
            function Perform(): boolean; overload; override;
      //.......................................................
          end;
      //.......................................................
          TActivateInhibiteSystem = class(TModelGroup)
          private
      //.......................................................
              FQueuePerformModels: TQueuePerformModels;
          protected
      //.......................................................
          public
            constructor Create(); overload; override;
            destructor Destroy(); override;
          public
            function Perform(): boolean; overload; override;
      //.......................................................
          end;
      //.......................................................
            constructor TActivateInhibiteSystem.Create();
            begin
              inherited Create();
              Models.FreeObjects := false;
              FClamping := 0.0;
              FQueuePerformModels := TQueuePerformModels.Create();
            end;
            destructor TActivateInhibiteSystem.Destroy();
            begin
              System.SysUtils.FreeAndNil(FQueuePerformModels);
              FClamping := 0.0;
              Models.FreeObjects := false;
              inherited Destroy();
            end;
      //.......................................................
            function TActivateInhibiteSystem.EnqueuePerformModels(): TQueuePerformModels;
            var
              ASubmodel: TSubmodel;
            begin
              Result := FQueuePerformModels;
      //   .
              OrderBy();
      //  .
              Submodels.Reorder();
      //  
              for ASubmodel in Submodels do
                begin
      //    ,    
      //       .
                  if (not Check(ASubmodel)) then break;
                  Result.Enqueue(ASubmodel);
                end;
            end;
      //.......................................................


      Perform() :



      //.......................................................
            procedure TActivateInhibiteSystem.BeforePerform();
            var
              ASubmodel: TSubmodel;
            begin
              for ASubmodel in Submodels do
                begin
                  ASubmodel.Prototype.ChangeArousal(Self);
                end;
            end;
      //.......................................................
            function TActivateInhibiteSystem.Perform(): boolean;
            var
              AModel: TModel;
            begin
              Result := true;
              BeforePerform();
      //  
              EnqueuePerformModels();
      //     .
              while (not FQueuePerformModels.IsEmpty()) do
                begin
                  if (Accept(FQueuePerformModels.Dequeue())) then continue;
                  Result := false;
                  break;
                end;
      //    ,    .
              while (not FQueuePerformModels.IsEmpty()) do
                FQueuePerformModels.Dequeue();
            end;
      //.......................................................


      2.3. Check(…), BeforePerform(…) Accept(…). Check – . :



      //.......................................................
            function TActivateInhibiteSystem.Check(ASubmodel: TSubmodel): boolean;
            begin
      //   !
              Result := (ASubmodel.Prototype.Arousal >= Clamping);
            end;
      //.......................................................


      Accept ,



      //.......................................................
      Result := AModel.Perform();
      //.......................................................


      , i- , . true, , – false . .

      TActivateInhibiteSystem.Perform i- .

      BeforePerform(…) i-



            procedure TActivateInhibiteSystem.BeforePerform();
            var
              ASubmodel: TSubmodel;
            begin
              for ASubmodel in Submodels do
                begin
                  ASubmodel.Prototype.ChangeArousal(Self);
                end;
            end;


      , TModel ChangeArousal(…)



            procedure TModel.ChangeArousal(AActivateInhibiteSystem: TActivateInhibiteSystem);
            begin
            end;


      - i-. , , .



      -



      -.

      - :



          TModelsNet = class(TModelGroup)
          private
              FPlatform: TPlatform;
          private
      // 
              Fontentment: double;
              FAIS: TActivateInhibiteSystem;
          protected
            function Getontentment(): double; overload; virtual;
            procedure Setontentment(const AValue: double); overload; virtual;
            function GetPlatform(): TPlatform; overload; override;
            procedure SetPlatform(AValue: TPlatform); overload; override;
          protected
              property Contentment: double read Getontentment write Setontentment;
          protected
              property AIS: TActivateInhibiteSystem read FAIS;
              property Platform: TPlatform read GetPlatform write SetPlatform;
          protected
            class function GetClassSubmodels(): TSubmodelsClass; overload; virtual;
            class function GetClassAIS(): TActivationInhibitionSystemClass; overload; virtual;
          public
            constructor Create(); overload; override;
            destructor Destroy(); override;
          public
            function Exec(): boolean; overload; override;
          end;
          TModelsNetClass = class of TModelsNet;


      :



            constructor TModelsNet.Create();
            begin
              inherited Create();
              Fontentment := 0.0;
              FAIS := GetClassAIS().Create(Self);
              FAIS.Owner := Self;
              FPlatform := nil;
              AIS.Prepare();
            end;
            destructor TModelsNet.Destroy();
            begin
              FPlatform := nil;
              System.SysUtils.FreeAndNil(FAIS);
              Fontentment := 0.0;
              inherited Destroy();
            end;
            class function TModelsNet.GetClassSubmodels(): TSubmodelsClass;
            begin
              Result := TSubmodels;
            end;
            class function TModelsNet.GetClassAIS(): TActivationInhibitionSystemClass;
            begin
              Result := TActivateInhibiteSystem;
            end;
            function TModelsNet.Exec(): boolean;
            begin
              Result := InternalExec();
      //     ,     
      //     InternalExec().
              Result := AIS.Perform();
            end;
            function TModelsNet.Getontentment(): double;
            begin
              Result := Fontentment;
            end;
            procedure TModelsNet.Setontentment(const AValue: double);
            begin
      //        FVitality := AValue;
            end;
            function TModelsNet.GetPlatform(): TPlatform;
            begin
              Result := FPlatform;
            end;
            procedure TModelsNet.SetPlatform(AValue: TPlatform);
            var
              ASubmodel: TSubmodel;
            begin
              FPlatform := AValue;
              for ASubmodel in Submodels do
                begin
                  ASubmodel.Prototype.Platform := Self.Platform;
                end;
            end;


      Prepare(…):



      //.......................................................
          AIS.Prepare();
      //.......................................................


      - . Prepare(…),



      //.......................................................
          TSpeedyAIS = class(TActivateInhibiteSystem)
      //.......................................................
          public
            procedure Prepare(); overload; overrride; 
      //.......................................................
          end;
      //.......................................................
            procedure TSpeedyAIS.Prepare(); 
            begin
      //.......................................................
              Submodels.Add(TSubmodel.Create(Owner.Automate.FindByName('')));
              Submodels.Add(TSubmodel.Create(Owner.Automate.FindByName('')));
      //.......................................................
            end;
      //.......................................................


      , , -, .

      Prepare(…) , – - , , - . !

      - :

      1. - , - .

      2. - - () .

      3. - .

      - , …



      -



      -



      - – , - .

      - :

      1. .

      2. i- () () () -.

      3. i-

      4. .

      :

      1. i- -;

      2. i- ();

      3. i- ;

      4. - ( - , - – );

      5. -;

      6. -;

      -:



      [XMLROOT('TAutomate')][XMLSerializerMode([soOrderSerialize])]
          TAutomate = class(TDesignate)
          private
      //   i-.
              FSequence: TSequence;
          private
              FReady: boolean;
          private
      //   "".
              Fontentment: double;
          private
      //   i-.
              FModels: TModels;
              FMNet: TModelsNet;
      //    i-.
              FConnections: TConnections;
          private
      //    i-.
              FEngine: TEngineConveyor;
          private
      //  - .
              FPlatform: TPlatform;
          private
              FOnBeforeExecute: TOnAutomateExecuteBefore;
              FOnAutomateBeforeAction: TOnActionExecuteBefore;
              FOnAutomateAfterAction: TOnActionExecuteAfter;
              FOnAfterExecute: TOnAutomateExecuteAfter;
          private
            function GetObjectName(): TNameObject; overload; override;
            procedure SetObjectName(const AValue: TNameObject); overload; override;
            function GetObjectNameShort(): TNameShort; overload; override;
            procedure SetObjectNameShort(const AValue: TNameShort); overload; override;
            function GetObjectCode(): TObjectName; overload; override;
            procedure SetObjectCode(const AValue: TObjectName); overload; override;
          protected
            function GetSequence(): TSequence; overload; virtual;
            procedure SetSequence(const AValue: TSequence); overload; virtual;
          protected
            function GetReady(): boolean; overload; virtual;
            procedure SetReady(const AValue: boolean); overload; virtual;
          protected
            function Getontentment(): double; overload; virtual;
            procedure Setontentment(const AValue: double); overload; virtual;
            function GetModels(): TModels; overload; virtual;
            procedure SetModels(const AValue: TModels); overload; virtual;
            function GetConnections: TConnections; overload; virtual;
            procedure SetConnections(const AValue: TConnections); overload; virtual;
            function GetEngine(): TEngineConveyor; overload; virtual;
            procedure SetEngine(const AValue: TEngineConveyor); overload; virtual;
            function GetPlatform(): TPlatform; overload; virtual;
            procedure SetPlatform(const AValue: TPlatform); overload; virtual;
          protected
            function GetOnAutomateBeforeExecute(): TOnAutomateExecuteBefore; overload; virtual;
            procedure SetOnAutomateBeforeExecute(const AValue: TOnAutomateExecuteBefore); overload; virtual;
            function GetOnBeforeAction(): TOnActionExecuteBefore; overload; virtual;
            procedure SetOnBeforeAction(const AValue: TOnActionExecuteBefore); overload; virtual;
            function GetOnAfterAction(): TOnActionExecuteAfter; overload; virtual;
            procedure SetOnAfterAction(const AValue: TOnActionExecuteAfter); overload; virtual;
            function GetOnAutomateAfterExecute(): TOnAutomateExecuteAfter; overload; virtual;
            procedure SetOnAutomateAfterExecute(const AValue: TOnAutomateExecuteAfter); overload; virtual;
          protected
            class function GetClassModels(): TModelsClass; overload; virtual;
            class function GetClassConnections(): TConnectionsClass; overload; virtual;
            class function GetClassEngineConveyor(): TEngineConveyorClass; overload; virtual;
            class function GetClassModelNet(): TModelsNetClass; overload; virtual;
          protected
            procedure Binding(); overload; virtual;
            procedure BindSubmodel(ASubmodel: TSubmodel); overload; virtual;
          protected
            function ExecBeforeExecute(): boolean; overload; virtual;
            function ExecBeforeAction(): boolean; overload; virtual;
            procedure ExecAfterAction(var AStatus: boolean); overload; virtual;
            procedure ExecAfterExecute(var AStatus: boolean); overload; virtual;
          public
            constructor Create(); overload; override;
            destructor Destroy(); override;
          public
            procedure Clear(); overload; virtual;
          public
            function FindById(const AModelId: int64): TModel; overload; virtual;
            function FindByName(const AModelName: string): TModel; overload; virtual;
          public
            procedure LoadFromFile(const AFileName: string); overload; virtual;
            procedure SaveToFile(const AFileName: string); overload; virtual;
          public
            function Next(): boolean; overload; virtual;
            function Exec(): boolean; overload; virtual;
            procedure Reset(); overload; virtual;
          public
            function Connect(ASourceId, ATargetId: int64): boolean; overload; virtual;
            function Disconnect(ASourceId, ATargetId: int64): boolean; overload; virtual;
            function ConnectBy(ASourceId, ATargetId: int64): boolean; overload; virtual;
          public
              property Ready: boolean read GetReady write SetReady;
          public
              property Platform: TPlatform read GetPlatform write SetPlatform;
          published
      [XMLEmbedding('Sequence')]
              property Sequence: TSequence read GetSequence write SetSequence;
          published
      [XMLARRAY('Models','Model')]
              property Models: TModels read GetModels write SetModels;
      [XMLARRAY('Connections','Connection')]
              property Connections: TConnections read GetConnections write SetConnections;
      [XMLARRAY('Conveyor','Model')]
              property Engine: TEngineConveyor read GetEngine write SetEngine;
          published
      [XMLAttribute('Vitality')]
              property Contentment: double read Getontentment write Setontentment;
          published
              property OnBeforeExecute: TOnAutomateExecuteBefore read GetOnAutomateBeforeExecute write SetOnAutomateBeforeExecute;
              property OnBeforeAction: TOnActionExecuteBefore read GetOnBeforeAction write SetOnBeforeAction;
              property OnAfterAction: TOnActionExecuteAfter read GetOnAfterAction write SetOnAfterAction;
              property OnAfterExecute: TOnAutomateExecuteAfter read GetOnAutomateAfterExecute write SetOnAutomateAfterExecute;
          end;
          TAutomateClass = class of TAutomate;


      -:

      1. TDesignate, ;

      2. , ,

      3. ontentment – «» -, «» - ;

      4. Ready, - ( ).

      5. - :

      – OnBeforeExecute (OnAfterExecute) – () / -;

      – OnBeforeAction (OnAfterAction) – () / i-.

      .

      6. / - :

      – Next(): boolean – / -:



            function TAutomate.Next(): boolean;
            begin
              if (not ExecBeforeAction()) then exit(false);
              Result := Exec();
              ExecAfterAction(Result);
            end;


      – Exec(): boolean – / - , «» -:



            function TAutomate.Exec(): boolean;
            begin
              if (not ExecBeforeExecute()) then exit(false);
              repeat
                Result := Next();
              until (not Result);
              ExecAfterExecute(Result);
            end;


      7. :

      – Clear() – -;

      – FindById(const AModelId: int64) – ;

      – FindByName(const AModelName: string) – ;

      – LoadFromFile(const AFileName: string) – - :



            procedure TAutomate.LoadFromFile(const AFileName: string);
            var
              AlterPath: string;
              ANameFile: JOBLIB.FileName.TFileName;
            begin
              ANameFile := AFileName;
              if (TFile.Exists(ANameFile)) then
                begin
                  Ready := false;
                  TSerializer.LoadFromFile(Self, AFileName);
                  Ready := true;
                  Binding();
                  Modified := false;
                  exit;
                end;
              Modified := true;
              TSerializer.SaveToFile(Self, AFileName);
              Modified := false;
            end;


      – SaveToFile(const AFileName: string) – - ;

      – Reset() – - ;

      – Binding() – - :



            procedure TAutomate.Binding();
            var
              AModel: TModel;
              ASubmodel: TSubmodel;
              AGroupModels: TModelGroup;
              AConnection: TConnection;
            begin
              Fontentment := 0.0;
      //     !
              for AModel in Models do
                begin
                  AModel.Automate := Self;
                  if (not (AModel is TModelGroup)) then continue;
                  AGroupModels := (AModel as TModelGroup);
                  for ASubmodel in AGroupModels.Submodels do
                    begin
                      BindSubmodel(ASubmodel);
                    end;
                end;
      //    !
              for AConnection in Connections do
                begin
                  with AConnection do
                    begin
                      FindById(SourceId).Connect(FindById(TargetId), AConnection);
                    end;
                end;
            end;


      – BindSubmodel(ASubmodel: TSubmodel) – () - ( ).

      8. -, -, – .





      . -,

      – i-

      – /.

      TEngineConveyor:



          TEngineConveyor = class(TModelGroup)
          private
              FCurrModel: int64;
          protected
            procedure SetModesFreePrototype(const AValue: TModesFreePrototype); overload; override;
          public
            constructor Create(); overload; override;
            constructor Create(AOwner: TAutomate); overload; virtual;
            destructor Destroy(); override;
          public
            procedure Reset(); overload; virtual;
            function Next(): boolean; overload; virtual;
            function Perform(): boolean; overload; override;
            function Exec(): boolean; overload; override;
          end;
          TEngineConveyorClass = class of TEngineConveyor;


      , :



            procedure TEngineConveyor.Reset();
            begin
              FCurrModel := 0;
            end;
            function TEngineConveyor.Next(): boolean;
            begin
              if (not Automate.ExecBeforeAction()) then exit(false);
              Result := false;
              if (FCurrModel < Submodels.Count) then
                begin
                  Result := Submodels[FCurrModel].Prototype.Exec();
                  System.Inc(FCurrModel);
                end;
              Automate.ExecAfterAction(Result);
            end;
            function TEngineConveyor.Exec(): boolean;
            begin
              Reset();
              if (not Automate.ExecBeforeExecute()) then exit(false);
              repeat
                Result := Next();
              until (not Result);
              Automate.ExecAfterExecute(Result);
            end;
            function TEngineConveyor.Perform(): boolean;
            begin
            end;


      , Exec Next -



            function TAutomate.Next(): boolean;
            begin
              Result := Engine.Next();
            end;
            function TAutomate.Exec(): boolean;
            begin
              Result := Engine.Exec();
            end;




            procedure TEngineConveyor.SetModesFreePrototype(const AValue: TModesFreePrototype);
            begin
            end;


      - ( TEngineConveyor FModesFreePrototype := []).



      ()



      () -

      – ,

      – , .

      , , , . :



          TPlatform = class(TModel)
          private
              FOnBeforeExecute: TOnAutomateExecuteBefore;
              FOnAutomateBeforeAction: TOnActionExecuteBefore;
              FOnAutomateAfterAction: TOnActionExecuteAfter;
              FOnAfterExecute: TOnAutomateExecuteAfter;
          protected
            function GetOnAutomateBeforeExecute(): TOnAutomateExecuteBefore; overload; virtual;
            procedure SetOnAutomateBeforeExecute(const AValue: TOnAutomateExecuteBefore); overload; virtual;
            function GetOnBeforeAction(): TOnActionExecuteBefore; overload; virtual;
            procedure SetOnBeforeAction(const AValue: TOnActionExecuteBefore); overload; virtual;
            function GetOnAfterAction(): TOnActionExecuteAfter; overload; virtual;
            procedure SetOnAfterAction(const AValue: TOnActionExecuteAfter); overload; virtual;
            function GetOnAutomateAfterExecute(): TOnAutomateExecuteAfter; overload; virtual;
            procedure SetOnAutomateAfterExecute(const AValue: TOnAutomateExecuteAfter); overload; virtual;
          protected
            function HandleBeforeExecute(AAutomate: TAutomate): boolean; overload; virtual;
            function HandleAutomateBeforeAction(AAutomate: TAutomate): boolean; overload; virtual;
            function HandleAutomateAfterAction(AAutomate: TAutomate; const AStatus: boolean): boolean; overload; virtual;
            function HandleAfterExecute(AAutomate: TAutomate; const AStatus: boolean): boolean; overload; virtual;
          public
            constructor Create(); overload; override;
            destructor Destroy(); override;
          public
            procedure Prepare(); overload; virtual;
          public
            function Exec(): boolean; overload; override;
          published
              property OnBeforeExecute: TOnAutomateExecuteBefore read GetOnAutomateBeforeExecute write SetOnAutomateBeforeExecute;
              property OnBeforeAction: TOnActionExecuteBefore read GetOnBeforeAction write SetOnBeforeAction;
              property OnAfterAction: TOnActionExecuteAfter read GetOnAfterAction write SetOnAfterAction;
              property OnAfterExecute: TOnAutomateExecuteAfter read GetOnAutomateAfterExecute write SetOnAutomateAfterExecute;
          end;
          TPlatformClass = class of TPlatform;


      1. () -;

      2. ;

      3. Exec:



            function TPlatform.Exec(): boolean;
            begin
              Prepare();
              Result := Automate.Exec();
            end;


      4. , - («») . …





      , -, , , – . , :

      1. «», () -.

      2. :

      2.1. -.

      2.2. () - i- .

      2.3. (, ) i- .

      2.4. -.

      2.5.1. - ( ).

      2.5.2. - ( ).

      3. () - - ().

      4. () -.

      5. () i-, ().

      6.1. () (DLL / BPL), .

      6.2. i- , , (, ZeroMQ), .

      7. «» - .





      , .. .

      1. , [3] .. . :

      – Β« Β»,

      – -, (M- ).

      2. , , [3], [2, 4]. , .. , , [3] , : [4], [1] [2].

      3. , «» , -.

      4. [3] «» , .. , - , , «-» . !

      5. , [3] . () .. : , i- . .. , , , .. [7] .. [8].

      6. i- – (, ) – , ( , , ) .

      7. - . - . , , , - Β« Β» . , - - . . .

      , , , , !

      , .



      (Ustas) open-source , .




      1. .. . – , 1965.

      2. .. . – , 1969.

      3. .., .., .., .. : . – , 1973.

      4. .. – , 1979.

      5. .. . – ., 1981.

      6. .. . – ., 1987.

      7. .., .., .. – «» β€” . , Β« Β». ., 1975; . 152–171 Β« Β». ., 2010; . 61-81.

      8. Demin A.V., Vityaev E.E. The animat control system based on the theory of functional systems by P.K. Anokhina

      9. Rabinovich M.I., Myezinolu M.K. Nonlinear dynamics of the brain: emotions and intellectual activity - Physics Β± Uspekhi, vol. 180 (2010), p. 371-387




All Articles