Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/superv.git] / examples / GraphSyracuseC_Gate.py
1 #  Copyright (C) 2003  CEA/DEN, EDF R&D
2 #
3 #
4 #
5 #  File   : GraphSyracuseC_Gate.py
6 #  Module : SuperVisionTest
7
8 from SuperV import *
9 # Graph creation 
10 GraphSyracuseC_Gate = Graph( 'GraphSyracuseC_Gate' )
11 GraphSyracuseC_Gate.SetName( 'GraphSyracuseC_Gate' )
12 GraphSyracuseC_Gate.SetAuthor( 'JR' )
13 GraphSyracuseC_Gate.SetComment( 'Syracuse algorithm' )
14 GraphSyracuseC_Gate.Coords( 0 , 0 )
15
16 # Creation of Factory Nodes
17 test_ISEVEN = GraphSyracuseC_Gate.FNode( 'SyrComponent' , 'SyrComponent' , 'C_ISEVEN' )
18 test_ISEVEN.SetName( 'test_ISEVEN' )
19 test_ISEVEN.SetAuthor( '' )
20 test_ISEVEN.SetContainer( 'localhost/FactoryServer' )
21 test_ISEVEN.SetComment( 'C_ISEVEN from SyrComponent' )
22 test_ISEVEN.Coords( 5 , 416 )
23 test_ISONE = GraphSyracuseC_Gate.FNode( 'SyrComponent' , 'SyrComponent' , 'C_ISONE' )
24 test_ISONE.SetName( 'test_ISONE' )
25 test_ISONE.SetAuthor( '' )
26 test_ISONE.SetContainer( 'localhost/FactoryServer' )
27 test_ISONE.SetComment( 'C_ISONE from SyrComponent' )
28 test_ISONE.Coords( 7 , 232 )
29 m3p1 = GraphSyracuseC_Gate.FNode( 'SyrComponent' , 'SyrComponent' , 'C_M3P1' )
30 m3p1.SetName( 'm3p1' )
31 m3p1.SetAuthor( '' )
32 m3p1.SetContainer( 'localhost/FactoryServer' )
33 m3p1.SetComment( 'C_M3P1 from SyrComponent' )
34 m3p1.Coords( 180 , 417 )
35 div2 = GraphSyracuseC_Gate.FNode( 'SyrComponent' , 'SyrComponent' , 'C_DIV2' )
36 div2.SetName( 'div2' )
37 div2.SetAuthor( '' )
38 div2.SetContainer( 'localhost/FactoryServer' )
39 div2.SetComment( 'C_DIV2 from SyrComponent' )
40 div2.Coords( 435 , 7 )
41 div2_ISEVEN = GraphSyracuseC_Gate.FNode( 'SyrComponent' , 'SyrComponent' , 'C_ISEVEN' )
42 div2_ISEVEN.SetName( 'div2_ISEVEN' )
43 div2_ISEVEN.SetAuthor( '' )
44 div2_ISEVEN.SetContainer( 'localhost/FactoryServer' )
45 div2_ISEVEN.SetComment( 'C_ISEVEN from SyrComponent' )
46 div2_ISEVEN.Coords( 663 , 193 )
47 div2_ISONE = GraphSyracuseC_Gate.FNode( 'SyrComponent' , 'SyrComponent' , 'C_ISONE' )
48 div2_ISONE.SetName( 'div2_ISONE' )
49 div2_ISONE.SetAuthor( '' )
50 div2_ISONE.SetContainer( 'localhost/FactoryServer' )
51 div2_ISONE.SetComment( 'C_ISONE from SyrComponent' )
52 div2_ISONE.Coords( 651 , 6 )
53 incr = GraphSyracuseC_Gate.FNode( 'SyrComponent' , 'SyrComponent' , 'C_INCR' )
54 incr.SetName( 'incr' )
55 incr.SetAuthor( '' )
56 incr.SetContainer( 'localhost/FactoryServer' )
57 incr.SetComment( 'C_INCR from SyrComponent' )
58 incr.Coords( 434 , 193 )
59
60 # Creation of intermediate Output variables and of Control Links
61 test_ISEVENOutGate = test_ISEVEN.Port( 'OutGate' )
62 m3p1InGate = GraphSyracuseC_Gate.Link( test_ISEVENOutGate , m3p1.Port( 'InGate' ) )
63 m3p1anEvenInteger = m3p1.Port( 'anEvenInteger' )
64 div2anEvenInteger = GraphSyracuseC_Gate.Link( m3p1anEvenInteger , div2.Port( 'anEvenInteger' ) )
65 div2anEvenInteger.AddCoord( 1 , 373 , 117 )
66 div2anEvenInteger.AddCoord( 2 , 373 , 528 )
67 div2anInteger = div2.Port( 'anInteger' )
68 div2_ISONEanInteger = GraphSyracuseC_Gate.Link( div2anInteger , div2_ISONE.Port( 'anInteger' ) )
69 div2_ISEVENanInteger = GraphSyracuseC_Gate.Link( div2anInteger , div2_ISEVEN.Port( 'anInteger' ) )
70 div2_ISEVENanInteger.AddCoord( 1 , 626 , 302 )
71 div2_ISEVENanInteger.AddCoord( 2 , 626 , 116 )
72
73 # Creation of Input datas
74 test_ISEVENanInteger = test_ISEVEN.Input( 'anInteger' , 31)
75 test_ISONEanInteger = test_ISONE.Input( 'anInteger' , 31)
76 m3p1anOddInteger = m3p1.Input( 'anOddInteger' , 31)
77 incraCount = incr.Input( 'aCount' , 0)
78
79 # Creation of Output variables
80 test_ISEVENBoolEven = test_ISEVEN.Port( 'BoolEven' )
81 test_ISONEBoolOne = test_ISONE.Port( 'BoolOne' )
82 div2_ISEVENBoolEven = div2_ISEVEN.Port( 'BoolEven' )
83 div2_ISONEBoolOne = div2_ISONE.Port( 'BoolOne' )
84 incraNewCount = incr.Port( 'aNewCount' )
85
86
87 GraphSyracuseC_Gate.Start()
88
89 div2InanInteger = div2.Port( 'anEvenInteger' )
90
91 m3p1.Suspend()
92
93 div2_ISEVEN.SuspendDone()
94 div2_ISONE.SuspendDone()
95
96 test_ISEVEN.Resume()
97 test_ISONE.Resume()
98
99 # Attente de fin d'execution de test
100 test_ISONE.DoneW()
101 test_ISEVEN.DoneW()
102
103 m3p1.SuspendedW()
104 incr.SuspendedW()
105 incr.SuspendDone()
106
107 # Etats et Threads des nodes
108 GraphSyracuseC_Gate.PrintThreads()
109
110 BoolOne = int( test_ISONEBoolOne.ToString() )
111 BoolEven = int( test_ISEVENBoolEven.ToString() )
112 while BoolOne == 0 :
113     if BoolEven == 0 :
114         sts = div2_ISONE.ReRunAt('m3p1')
115         if sts == 0 :
116             print 'div2_ISONE.ReRunAt error'
117             break
118         sts = incr.ReRun()
119         if sts == 0 :
120             print 'incr.ReRun error'
121             break
122         sts = m3p1.DoneW()
123         if sts == 0 :
124             print 'm3p1.DoneW error'
125             break
126         sts = incr.DoneW()
127         if sts == 0 :
128             print 'incr.DoneW error'
129             break
130         sts = incraCount.Input( int( incraNewCount.ToString() ) + 1 )
131         if sts == 0 :
132             print 'incraCount.Input error'
133             break
134         BoolEven = 1 
135         BoolOne = 0
136         Current = int( m3p1anEvenInteger.ToString() )
137         print incraNewCount.ToString(),"m3p1",Current,BoolEven
138         if Current <= 0 :
139             break
140     if Current <= 0 :
141         break
142     while BoolEven == 1 :
143         sts = incr.ReRun()
144         if sts == 0 :
145             print 'incr.ReRun error'
146             break
147         sts = div2.DoneW()
148         if sts == 0 :
149             print 'div2.DoneW error'
150             break
151         sts = div2_ISEVEN.DoneW()
152         if sts == 0 :
153             print 'div2_ISEVEN.DoneW error'
154             break
155         sts = div2_ISONE.DoneW()
156         if sts == 0 :
157             print 'div2_ISONE.DoneW error'
158             break
159         sts = incr.DoneW()
160         if sts == 0 :
161             print 'incr.DoneW error'
162             break
163         sts = incraCount.Input( incraNewCount.ToString() )
164         if sts == 0 :
165             print 'incraCount.Input error'
166             break
167         BoolOne = int( div2_ISONEBoolOne.ToString() )
168         BoolEven = int( div2_ISEVENBoolEven.ToString() )
169         Current = int( div2anInteger.ToString() )
170         print incraNewCount.ToString(),"div2",Current,BoolEven,BoolOne
171         if Current <= 0 :
172             break
173         if BoolEven == 1 :
174             sts = div2InanInteger.Input( Current )
175             if sts == 0 :
176                 print 'div2InanInteger.Input error'
177                 break
178             sts = div2_ISONE.ReRunAt('div2')
179             if sts == 0 :
180                 print 'div2_ISONE.ReRunAt error'
181                 break
182     if Current <= 0 :
183         break
184     sts = m3p1anOddInteger.Input( Current )
185     if sts == 0 :
186         print 'm3p1anOddInteger.Input error'
187         break
188     sts = m3p1InGate.InPort().Input( 1 )
189     if sts == 0 :
190         print 'm3p1InGate.InPort error'
191         break
192
193
194 GraphSyracuseC_Gate.PrintThreads()
195 m3p1.Resume()
196 div2.Resume()
197 incr.Resume()
198 div2_ISONE.Resume()
199 div2_ISEVEN.Resume()
200 GraphSyracuseC_Gate.DoneW()
201 GraphSyracuseC_Gate.PrintPorts()
202 GraphSyracuseC_Gate.PrintThreads()
203