1 /*****************************************************************************
2 FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/kernel/sources/kr_art2.c,v $
3 SHORTNAME : kr_art2
4 SNNS VERSION : 4.2
5
6 PURPOSE : SNNS Kernel Functions for ART2 networks
7 NOTES :
8
9 AUTHOR : Kai-Uwe Herrmann
10 DATE : 17.05.92
11
12 CHANGED BY : Sven Doering
13 RCS VERSION : $Revision: 2.8 $
14 LAST CHANGE : $Date: 1998/03/03 14:08:36 $
15
16 Copyright (c) 1990-1995 SNNS Group, IPVR, Univ. Stuttgart, FRG
17 Copyright (c) 1996-1998 SNNS Group, WSI, Univ. Tuebingen, FRG
18
19 ******************************************************************************/
20 #include <config.h>
21
22 /*#################################################
23
24 GROUP: include files
25
26 #################################################*/
27
28
29
30
31 #include <stdlib.h>
32
33 #ifndef NULL /* if NULL pointer is not defined include stdio.h */
34 #include <stdio.h>
35 #endif
36
37 #include <string.h>
38
39 #include <math.h>
40
41
42 #include "kr_const.h"
43 #include "kr_mac.h"
44 #include "kr_def.h"
45 #include "kr_typ.h"
46 #include "kr_funcs.h"
47 #include "kernel.h"
48 #include "glob_typ.h"
49 #include "kr_art.h" /* Function prototypes for ART networks */
50 #include "krart_df.h" /* Definitions for ART networks */
51 #include "kr_art2.ph"
52
53
54
55
56
57
58 /*#################################################
59
60 GROUP: declaration of module functions
61
62 #################################################*/
63
64
65
66
67 /*#################################################
68
69 GROUP: IMPLEMENTATION SECTION of
70 ART 2 kernel functions visible to other
71 modules
72 by Kai-Uwe Herrmann
73
74 #################################################*/
75
76
77
78
79
80
81 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_sort(void)82 krui_err kra2_sort (void)
83 {
84
85 TopoPtrArray topo_ptr = topo_ptr_array;
86 int ret_code = KRERR_NO_ERROR;
87
88 int no_of_w_units = 0;
89 int no_of_x_units = 0;
90 int no_of_u_units = 0;
91 int no_of_v_units = 0;
92 int no_of_p_units = 0;
93 int no_of_q_units = 0;
94 int no_of_r_units = 0;
95 int no_of_rst_units = 0;
96
97 /* initialize ART2 sorting
98 */
99 krart_init_sorting ();
100
101
102 /* get no of input units and no of recognition units
103 */
104 NoOfInputUnits = krart_get_NoOfInputUnits ();
105 Art2_NoOfRecUnits = kra2_get_NoOfRecUnits ();
106
107 if (NoOfInputUnits == 0) {
108 ret_code = KRERR_NO_INPUT_UNITS;
109 return (ret_code);
110 } /*if*/
111
112 if (Art2_NoOfRecUnits == 0) {
113 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("recognition");
114 } /*if*/
115
116
117 /* insert a NULL pointer to topo ptr array for left limitation
118 */
119 *topo_ptr++ = NULL;
120
121
122 /* determine unit types and insert them into topo ptr array
123 */
124
125 topo_layer[0] = topo_ptr;
126
127
128 /* determine input units
129 */
130 topo_layer[0] = topo_ptr;
131 ret_code = kra2_get_InpUnits (&topo_ptr);
132
133 if (ret_code != KRERR_NO_ERROR) {
134 return (ret_code);
135 } /*if*/
136
137 *topo_ptr++ = NULL;
138
139 /* determine w units
140 */
141 topo_layer[1] = topo_ptr;
142 ret_code = kra2_get_WUnits (&topo_ptr, &no_of_w_units);
143
144 if (ret_code != KRERR_NO_ERROR) {
145 return (ret_code);
146 } /*if*/
147
148 if (no_of_w_units != NoOfInputUnits) {
149 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("w");
150 } /*if*/
151
152 *topo_ptr++ = NULL;
153
154
155 /* determine x units
156 */
157 topo_layer[2] = topo_ptr;
158 ret_code = kra2_get_XUnits (&topo_ptr, &no_of_x_units);
159
160 if (ret_code != KRERR_NO_ERROR) {
161 return (ret_code);
162 } /*if*/
163
164 if (no_of_x_units != NoOfInputUnits) {
165 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("x");
166 } /*if*/
167
168 *topo_ptr++ = NULL;
169
170
171 /* determine u units
172 */
173 topo_layer[3] = topo_ptr;
174 ret_code = kra2_get_UUnits (&topo_ptr, &no_of_u_units);
175
176 if (ret_code != KRERR_NO_ERROR) {
177 return (ret_code);
178 } /*if*/
179
180 if (no_of_u_units != NoOfInputUnits) {
181 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("u");
182 } /*if*/
183
184 *topo_ptr++ = NULL;
185
186
187 /* determine v units
188 */
189 topo_layer[4] = topo_ptr;
190 ret_code = kra2_get_VUnits (&topo_ptr, &no_of_v_units);
191
192 if (ret_code != KRERR_NO_ERROR) {
193 return (ret_code);
194 } /*if*/
195
196 if (no_of_v_units != NoOfInputUnits) {
197 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("v");
198 } /*if*/
199
200 *topo_ptr++ = NULL;
201
202
203 /* determine p units
204 */
205 topo_layer[5] = topo_ptr;
206 ret_code = kra2_get_PUnits (&topo_ptr, &no_of_p_units);
207
208 if (ret_code != KRERR_NO_ERROR) {
209 return (ret_code);
210 } /*if*/
211
212 if (no_of_p_units != NoOfInputUnits) {
213 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("p");
214 } /*if*/
215
216 *topo_ptr++ = NULL;
217
218
219 /* determine q units
220 */
221 topo_layer[6] = topo_ptr;
222 ret_code = kra2_get_QUnits (&topo_ptr, &no_of_q_units);
223
224 if (ret_code != KRERR_NO_ERROR) {
225 return (ret_code);
226 } /*if*/
227
228 if (no_of_q_units != NoOfInputUnits) {
229 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("q");
230 } /*if*/
231
232 *topo_ptr++ = NULL;
233
234
235 /* determine r units
236 */
237 topo_layer[7] = topo_ptr;
238 ret_code = kra2_get_RUnits (&topo_ptr, &no_of_r_units);
239
240 if (ret_code != KRERR_NO_ERROR) {
241 return (ret_code);
242 } /*if*/
243
244 if (no_of_r_units != NoOfInputUnits) {
245 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("r");
246 } /*if*/
247
248 *topo_ptr++ = NULL;
249
250
251 /* determine rec units
252 */
253 topo_layer[8] = topo_ptr;
254 ret_code = kra2_get_RecUnits (&topo_ptr);
255
256 if (ret_code != KRERR_NO_ERROR) {
257 return (ret_code);
258 } /*if*/
259
260 *topo_ptr++ = NULL;
261
262
263 /* determine rst units
264 */
265 topo_layer[9] = topo_ptr;
266 ret_code = kra2_get_RstUnits (&topo_ptr, &no_of_rst_units);
267
268 if (ret_code != KRERR_NO_ERROR) {
269 return (ret_code);
270 } /*if*/
271
272 if (no_of_rst_units != Art2_NoOfRecUnits) {
273 TOPO_MSG_NO_OF_UNITS_IN_LAYER ("reset");
274 } /*if*/
275
276 *topo_ptr++ = NULL;
277
278
279 /* check if the logical type of really all units is determined
280 */
281 if (krart_check_undeterminedUnits ()) {
282 ret_code = topo_msg.error_code;
283 return (ret_code);
284 } /*if*/
285
286
287 /* Now check the topo ptr array
288 */
289 ret_code = kra2_TopoPtrArray ();
290
291 if (ret_code != KRERR_NO_ERROR) {
292 return (ret_code);
293 } /*if*/
294
295
296 /* Check link structure
297 */
298 topo_ptr = topo_ptr_array + 1;
299
300 /* Check links of input units
301 */
302 ret_code = kra2_LinksToInpUnits (&topo_ptr);
303
304 if (ret_code != KRERR_NO_ERROR) {
305 return (ret_code);
306 } /*if*/
307
308
309 /* Check links of w units
310 */
311 ret_code = kra2_LinksToWUnits (&topo_ptr);
312
313 if (ret_code != KRERR_NO_ERROR) {
314 return (ret_code);
315 } /*if*/
316
317
318 /* Check links of x units
319 */
320 ret_code = kra2_LinksToXUnits (&topo_ptr);
321
322 if (ret_code != KRERR_NO_ERROR) {
323 return (ret_code);
324 } /*if*/
325
326
327 /* Check links of u units
328 */
329 ret_code = kra2_LinksToUUnits (&topo_ptr);
330
331 if (ret_code != KRERR_NO_ERROR) {
332 return (ret_code);
333 } /*if*/
334
335
336 /* Check links of v units
337 */
338 ret_code = kra2_LinksToVUnits (&topo_ptr);
339
340 if (ret_code != KRERR_NO_ERROR) {
341 return (ret_code);
342 } /*if*/
343
344
345 /* Check links of p units
346 */
347 ret_code = kra2_LinksToPUnits (&topo_ptr);
348
349 if (ret_code != KRERR_NO_ERROR) {
350 return (ret_code);
351 } /*if*/
352
353
354 /* Check links of q units
355 */
356 ret_code = kra2_LinksToQUnits (&topo_ptr);
357
358 if (ret_code != KRERR_NO_ERROR) {
359 return (ret_code);
360 } /*if*/
361
362
363 /* Check links of r units
364 */
365 ret_code = kra2_LinksToRUnits (&topo_ptr);
366
367 if (ret_code != KRERR_NO_ERROR) {
368 return (ret_code);
369 } /*if*/
370
371
372 /* Check links of rec units
373 */
374 ret_code = kra2_LinksToRecUnits (&topo_ptr);
375
376 if (ret_code != KRERR_NO_ERROR) {
377 return (ret_code);
378 } /*if*/
379
380
381 /* Check links of rst units
382 */
383 ret_code = kra2_LinksToRstUnits (&topo_ptr);
384
385 if (ret_code != KRERR_NO_ERROR) {
386 return (ret_code);
387 } /*if*/
388
389
390 /*--------------------------------------------------------------------*/
391 #if 0
392 /* this was the preliminary version of the sorting routine for testing*/
393 *topo_ptr++ = NULL;
394 topo_layer[ART2_INP_LAY-1] = topo_ptr;
395
396 Art2_NoOfRecUnits = 0;
397 FOR_ALL_UNITS (unit_ptr) {
398 if (IS_SPECIAL_UNIT (unit_ptr)) {
399 Art2_NoOfRecUnits++;
400 } /*if*/
401 } /*FOR_ALL_UNITS*/
402
403
404 unit_ptr = unit_array + 1;
405
406 for (i=1; i<= NoOfInputUnits; i++, unit_ptr++) {
407 *topo_ptr++ = unit_ptr;
408 unit_ptr->lln = ART2_INP_LAY;
409 } /*for*/
410
411 *topo_ptr++ = NULL;
412 topo_layer[ART2_W_LAY-1] = topo_ptr;
413
414 for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
415 *topo_ptr++ = unit_ptr;
416 unit_ptr->lln = ART2_W_LAY;
417 } /*for*/
418
419 *topo_ptr++ = NULL;
420 topo_layer[ART2_X_LAY-1] = topo_ptr;
421
422 for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
423 *topo_ptr++ = unit_ptr;
424 unit_ptr->lln = ART2_X_LAY;
425 } /*for*/
426
427 *topo_ptr++ = NULL;
428 topo_layer[ART2_U_LAY-1] = topo_ptr;
429
430 for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
431 *topo_ptr++ = unit_ptr;
432 unit_ptr->lln = ART2_U_LAY;
433 } /*for*/
434
435 *topo_ptr++ = NULL;
436 topo_layer[ART2_V_LAY-1] = topo_ptr;
437
438 for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
439 *topo_ptr++ = unit_ptr;
440 unit_ptr->lln = ART2_V_LAY;
441 } /*for*/
442
443 *topo_ptr++ = NULL;
444 topo_layer[ART2_P_LAY-1] = topo_ptr;
445
446 for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
447 *topo_ptr++ = unit_ptr;
448 unit_ptr->lln = ART2_P_LAY;
449 } /*for*/
450
451 *topo_ptr++ = NULL;
452 topo_layer[ART2_Q_LAY-1] = topo_ptr;
453
454 for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
455 *topo_ptr++ = unit_ptr;
456 unit_ptr->lln = ART2_Q_LAY;
457 } /*for*/
458
459
460 *topo_ptr++ = NULL;
461 topo_layer[ART2_R_LAY-1] = topo_ptr;
462
463 for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
464 *topo_ptr++ = unit_ptr;
465 unit_ptr->lln = ART2_R_LAY;
466 } /*for*/
467
468
469 *topo_ptr++ = NULL;
470 topo_layer[ART2_REC_LAY-1] = topo_ptr;
471
472 for (i=1; i<=Art2_NoOfRecUnits; i++, unit_ptr++) {
473 *topo_ptr++ = unit_ptr;
474 unit_ptr->lln = ART2_REC_LAY;
475 } /*for*/
476
477 *topo_ptr++ = NULL;
478 topo_layer[ART2_RST_LAY-1] = topo_ptr;
479
480 for (i=1; i<=Art2_NoOfRecUnits; i++, unit_ptr++) {
481 *topo_ptr++ = unit_ptr;
482 unit_ptr->lln = ART2_RST_LAY;
483 } /*for*/
484
485 *topo_ptr++ = NULL;
486 *topo_ptr = NULL;
487 #endif /*#if 0*/
488 /*-----------------------------------------------------------------*/
489
490 return (ret_code);
491
492 } /* kra2_sort () */
493 /*___________________________________________________________________________*/
494
495
496 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_init_propagate(void)497 krui_err kra2_init_propagate (void)
498 {
499 int ret_code = KRERR_NO_ERROR;
500
501 ret_code = kra2_init_i_act ();
502
503 if (ret_code != KRERR_NO_ERROR) {
504 return (ret_code);
505 } /*if*/
506
507 ret_code = kra2_init_fix_weights ();
508
509 if (ret_code != KRERR_NO_ERROR) {
510 return (ret_code);
511 } /*if*/
512
513 ret_code = krart_reset_activations ();
514
515 if (ret_code != KRERR_NO_ERROR) {
516 return (ret_code);
517 } /*if*/
518
519 NoOfDelaySteps = 0;
520
521 return (ret_code);
522
523 } /* kra2_init_propagate () */
524 /*___________________________________________________________________________*/
525
526
527
528
529 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_set_params(FlintType rho,FlintType a,FlintType b,FlintType c,FlintType d,FlintType theta)530 krui_err kra2_set_params (FlintType rho, FlintType a, FlintType b, FlintType c, FlintType d, FlintType theta)
531 {
532 Param_rho = rho;
533 Param_a = a;
534 Param_b = b;
535 Param_c = c;
536 Param_d = d;
537 Param_theta = theta;
538 return (KRERR_NO_ERROR);
539 } /* kra2_set_theta () */
540 /*___________________________________________________________________________*/
541
542
543
544
545 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_rho(void)546 FlintType kra2_get_rho (void)
547 {
548 return (Param_rho);
549 } /* kra2_get_Param_rho () */
550 /*___________________________________________________________________________*/
551
552
553
554 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_a(void)555 FlintType kra2_get_a (void)
556 {
557 return (Param_a);
558 } /* kra2_get_Param_a () */
559 /*___________________________________________________________________________*/
560
561
562
563 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_b(void)564 FlintType kra2_get_b (void)
565 {
566 return (Param_b);
567 } /* kra2_get_Param_b () */
568 /*___________________________________________________________________________*/
569
570
571
572 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_c(void)573 FlintType kra2_get_c (void)
574 {
575 return (Param_c);
576 } /* kra2_get_Param_c () */
577 /*___________________________________________________________________________*/
578
579
580
581 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_d(void)582 FlintType kra2_get_d (void)
583 {
584 return (Param_d);
585 } /* kra2_get_Param_d () */
586 /*___________________________________________________________________________*/
587
588
589
590 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_theta(void)591 FlintType kra2_get_theta (void)
592 {
593 return (Param_theta);
594 } /* kra2_get_Param_theta () */
595 /*___________________________________________________________________________*/
596
597
598
599 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_checkReset(void)600 void kra2_checkReset (void)
601 {
602 FlintType NormR;
603
604 NormR = ART2_PARAM_e + kra2_L2_Norm (ART2_R_LAY);
605
606 if ((kra2_f1_stable()) && (kra2_topdn_phase()) && (kra2_get_rho() / NormR > 1)) {
607 GlobalReset = TRUE;
608 } else {
609 GlobalReset = FALSE;
610 } /*if*/
611
612 } /* kra2_checkReset () */
613 /*___________________________________________________________________________*/
614
615
616
617 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_Reset(void)618 bool kra2_Reset (void)
619 {
620 return (GlobalReset);
621 } /* kra2_Reset () */
622 /*___________________________________________________________________________*/
623
624
625
626
627
628 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_init_pattern(void)629 void kra2_init_pattern (void)
630 {
631 TopDownPhase = FALSE;
632 f1_stable = FALSE;
633 GlobalReset = FALSE;
634 } /* kra2_init_phase () */
635 /*___________________________________________________________________________*/
636
637
638
639
640
641 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_topdn_phase(void)642 bool kra2_topdn_phase (void)
643 {
644 return (TopDownPhase);
645 } /* kra2_topdn_phase () */
646 /*___________________________________________________________________________*/
647
648
649
650
651
652
653
654 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_compute_norms(void)655 void kra2_compute_norms (void)
656 {
657 NormInp = kra2_compute_l2_norm (ART2_INP_LAY);
658 NormW = kra2_compute_l2_norm (ART2_W_LAY);
659 NormU = kra2_compute_l2_norm (ART2_U_LAY);
660 NormV = kra2_compute_l2_norm (ART2_V_LAY);
661 NormP = kra2_compute_l2_norm (ART2_P_LAY);
662 NormR = kra2_compute_l2_norm (ART2_R_LAY);
663 } /* kra2_compute_norms () */
664 /*___________________________________________________________________________*/
665
666
667
668
669
670
671 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_L2_Norm(int Layer)672 FlintType kra2_L2_Norm (int Layer)
673 {
674 switch (Layer) {
675 case ART2_INP_LAY:
676 return (NormInp);
677 case ART2_W_LAY:
678 return (NormW);
679 case ART2_U_LAY:
680 return (NormU);
681 case ART2_V_LAY:
682 return (NormV);
683 case ART2_P_LAY:
684 return (NormP);
685 case ART2_R_LAY:
686 return (NormR);
687 default :
688 return (0.0);
689 } /* switch */
690 } /* kra2_L2_Norm () */
691 /*___________________________________________________________________________*/
692
693
694
695
696 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_classified(void)697 bool kra2_classified (void)
698 {
699
700 /* if the F1-Layer is actually stable, then it is necessary to continue
701 propagation for MIN_NO_OF_DELAY_STEPS cycles. Then the information
702 has been forwarded from recognition layer to r-units and it may be
703 decided about a reset.
704
705 if there occurs a reset during the delay propagation steps the no. of
706 executed delay propagation steps is reset to 0 and FALSE is returned.
707
708 if the F1-Layer becomes unstable during the delay propagation steps, the
709 no. of executed delay propagation steps is reset to 0, too and FALSE is
710 returned.
711 */
712
713 if (kra2_topdn_phase() && kra2_f1_stable()) {
714 if (NoOfDelaySteps >= MIN_NO_OF_DELAY_STEPS) {
715 if ( ! kra2_Reset()) {
716 return (TRUE);
717 } else {
718 NoOfDelaySteps = 0;
719 return (FALSE);
720 } /*if*/
721 } else {
722 NoOfDelaySteps++;
723 return (FALSE);
724 } /*if*/
725 } else {
726 NoOfDelaySteps = 0;
727 return (FALSE);
728 } /*if*/
729
730 } /* kra2_classified () */
731 /*___________________________________________________________________________*/
732
733
734
735
736 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_not_classifiable(void)737 bool kra2_not_classifiable (void)
738 {
739 TopoPtrArray topo_ptr = topo_layer[ART2_RST_LAY-1];
740
741
742 /* if there is one local reset unit that is inactive, then the
743 pattern may still be classifiable
744 */
745 while (*topo_ptr != NULL) {
746 if ((*topo_ptr)->Out.output < 0.1) {
747 return (FALSE);
748 } /*if*/
749 topo_ptr++;
750 } /*while*/
751
752
753 /* all local reset units are active -> pattern not classifiable */
754 return (TRUE);
755
756 } /* kra2_classified () */
757 /*___________________________________________________________________________*/
758
759
760
761
762
763 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_save_for_stability_check(void)764 void kra2_save_for_stability_check (void)
765 {
766 register TopoPtrArray topo_ptr ;
767
768 topo_ptr = topo_layer[ART2_W_LAY-1];
769
770 while (*topo_ptr != NULL) {
771 (*topo_ptr)->value_a = (*topo_ptr)->act;
772 topo_ptr++;
773 } /*while*/
774
775 topo_ptr = topo_layer[ART2_X_LAY-1];
776
777 while (*topo_ptr != NULL) {
778 (*topo_ptr)->value_a = (*topo_ptr)->act;
779 topo_ptr++;
780 } /*while*/
781
782 topo_ptr = topo_layer[ART2_U_LAY-1];
783
784 while (*topo_ptr != NULL) {
785 (*topo_ptr)->value_a = (*topo_ptr)->act;
786 topo_ptr++;
787 } /*while*/
788
789 topo_ptr = topo_layer[ART2_V_LAY-1];
790
791 while (*topo_ptr != NULL) {
792 (*topo_ptr)->value_a = (*topo_ptr)->act;
793 topo_ptr++;
794 } /*while*/
795
796 topo_ptr = topo_layer[ART2_P_LAY-1];
797
798 while (*topo_ptr != NULL) {
799 (*topo_ptr)->value_a = (*topo_ptr)->act;
800 topo_ptr++;
801 } /*while*/
802
803 topo_ptr = topo_layer[ART2_Q_LAY-1];
804
805 while (*topo_ptr != NULL) {
806 (*topo_ptr)->value_a = (*topo_ptr)->act;
807 topo_ptr++;
808 } /*while*/
809
810 topo_ptr = topo_layer[ART2_R_LAY-1];
811
812 while (*topo_ptr != NULL) {
813 (*topo_ptr)->value_a = (*topo_ptr)->act;
814 topo_ptr++;
815 } /*while*/
816
817 } /* kra2_save_for_stability_check () */
818 /*___________________________________________________________________________*/
819
820
821
822
823
824 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_check_f1_stability(void)825 void kra2_check_f1_stability (void)
826 {
827 register TopoPtrArray topo_ptr;
828
829 if (f1_stable && ( ! kra2_topdn_phase())) {
830 TopDownPhase = TRUE;
831 } /*if*/
832
833 if (kra2_Reset() && kra2_topdn_phase()) {
834 TopDownPhase = FALSE;
835 f1_stable = FALSE;
836 } /*if*/
837
838
839 topo_ptr = topo_layer[ART2_W_LAY-1];
840
841 while (*topo_ptr != NULL) {
842 if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
843 f1_stable = FALSE;
844 return;
845 } /*if*/
846 topo_ptr++;
847 } /*while*/
848
849 topo_ptr = topo_layer[ART2_X_LAY-1];
850
851 while (*topo_ptr != NULL) {
852 if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
853 f1_stable = FALSE;
854 return;
855 } /*if*/
856 topo_ptr++;
857 } /*while*/
858
859 topo_ptr = topo_layer[ART2_U_LAY-1];
860
861 while (*topo_ptr != NULL) {
862 if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
863 f1_stable = FALSE;
864 return;
865 } /*if*/
866 topo_ptr++;
867 } /*while*/
868
869 topo_ptr = topo_layer[ART2_V_LAY-1];
870
871 while (*topo_ptr != NULL) {
872 if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
873 f1_stable = FALSE;
874 return;
875 } /*if*/
876 topo_ptr++;
877 } /*while*/
878
879 topo_ptr = topo_layer[ART2_P_LAY-1];
880
881 while (*topo_ptr != NULL) {
882 if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
883 f1_stable = FALSE;
884 return;
885 } /*if*/
886 topo_ptr++;
887 } /*while*/
888
889 topo_ptr = topo_layer[ART2_Q_LAY-1];
890
891 while (*topo_ptr != NULL) {
892 if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
893 f1_stable = FALSE;
894 return;
895 } /*if*/
896 topo_ptr++;
897 } /*while*/
898
899 topo_ptr = topo_layer[ART2_R_LAY-1];
900
901 while (*topo_ptr != NULL) {
902 if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
903 f1_stable = FALSE;
904 return;
905 } /*if*/
906 topo_ptr++;
907 } /*while*/
908
909 f1_stable = TRUE;
910
911 return;
912
913 } /* kra2_check_f1_stability () */
914 /*___________________________________________________________________________*/
915
916
917
918
919 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_f1_stable(void)920 bool kra2_f1_stable (void)
921 {
922 return (f1_stable);
923 } /* kra2_f1_stable () */
924 /*___________________________________________________________________________*/
925
926
927
928 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_getClassNo(void)929 int kra2_getClassNo (void)
930 {
931 TopoPtrArray topo_ptr = topo_layer[ART2_REC_LAY-1];
932 int i;
933
934 /* if ART2 sorting wasn't performed then return negative value
935 to indicate mistake
936 */
937 if (topo_ptr == NULL) {
938 return (-1);
939 } /*if*/
940
941 /* look for winning unit */
942 for (i = 1;
943 (i <= Art2_NoOfRecUnits) || ((*topo_ptr)->Out.output == kra2_get_d());
944 i++, topo_ptr++
945 );
946
947 if ((i > Art2_NoOfRecUnits) && ((*topo_ptr)->Out.output < kra2_get_d())) {
948 return (-1);
949 } else {
950 return (topo_ptr - topo_layer[ART2_REC_LAY-1] + 1);
951 } /*if*/
952
953 } /* kra2_getClassNo () */
954 /*___________________________________________________________________________*/
955
956
957
958
959 /*#################################################
960
961 GROUP: IMPLEMENTATION SECTION of
962 ART 2 kernel functions, local to this module
963 by Kai-Uwe Herrmann
964
965 #################################################*/
966
967
968
969
970
971 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_set_fix_weight(struct Unit * src_unit,struct Unit * trgt_unit,FlintType * weight)972 static void kra2_set_fix_weight (struct Unit *src_unit, struct Unit *trgt_unit, FlintType *weight)
973 {
974
975 if ((src_unit == NULL) || (trgt_unit == NULL)) {
976 return;
977 } /*if*/
978
979 switch (src_unit->lln) {
980
981 case ART2_INP_LAY:
982
983 switch (trgt_unit->lln) {
984 case ART2_W_LAY:
985 *weight = ART2_LINK_INP_W;
986 break;
987 case ART2_R_LAY:
988 *weight = ART2_LINK_INP_R;
989 break;
990 } /*switch*/
991
992 break;
993
994 case ART2_W_LAY:
995
996 switch (trgt_unit->lln) {
997 case ART2_X_LAY:
998 *weight = ART2_LINK_W_X;
999 break;
1000 } /*switch*/
1001 break;
1002
1003 case ART2_X_LAY:
1004
1005 *weight = ART2_LINK_X_V;
1006 break;
1007
1008 case ART2_U_LAY:
1009
1010 switch (trgt_unit->lln) {
1011 case ART2_W_LAY:
1012 *weight = ART2_LINK_U_W(kra2_get_a());
1013 break;
1014 case ART2_P_LAY:
1015 *weight = ART2_LINK_U_P;
1016 break;
1017 default :
1018 break;
1019 } /* switch */
1020 break;
1021
1022 case ART2_V_LAY:
1023
1024 switch (trgt_unit->lln) {
1025 case ART2_U_LAY:
1026 *weight = ART2_LINK_V_U;
1027 break;
1028 default :
1029 break;
1030 } /* switch */
1031 break;
1032
1033 case ART2_P_LAY:
1034
1035 switch (trgt_unit->lln) {
1036 case ART2_Q_LAY:
1037 *weight = ART2_LINK_P_Q;
1038 break;
1039 case ART2_R_LAY:
1040 *weight = ART2_LINK_P_R(kra2_get_c());
1041 break;
1042 default :
1043 break;
1044 } /* switch */
1045 break;
1046
1047 case ART2_Q_LAY:
1048
1049 *weight = ART2_LINK_Q_V(kra2_get_b());
1050 break;
1051
1052 case ART2_R_LAY:
1053
1054 /* doesn't have outgoing links because Norm of R is computed
1055 within the function kra2_L2_Norm and not in a unit
1056 */
1057 break;
1058
1059 case ART2_REC_LAY:
1060
1061 if (trgt_unit->lln == ART2_RST_LAY) {
1062 *weight = ART2_LINK_REC_RST;
1063 } /*if*/
1064 break;
1065
1066 case ART2_RST_LAY:
1067
1068 switch (trgt_unit->lln) {
1069 case ART2_RST_LAY:
1070 *weight = ART2_LINK_RST_RST;
1071 break;
1072 case ART2_REC_LAY:
1073 *weight = ART2_LINK_RST_REC(kra2_get_d());
1074 break;
1075 default :
1076 break;
1077 } /* switch */
1078 break;
1079
1080 } /* switch */
1081
1082
1083 } /* kra2_set_fix_weights () */
1084 /*___________________________________________________________________________*/
1085
1086
1087
1088 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_compute_l2_norm(int Layer)1089 static FlintType kra2_compute_l2_norm (int Layer)
1090 {
1091 register TopoPtrArray topo_ptr = topo_layer[Layer-1];
1092 register FlintType sum = 0.0;
1093 register FlintType val;
1094
1095 while (*topo_ptr != NULL) {
1096 val = (*topo_ptr)->Out.output;
1097 sum += val * val;
1098 topo_ptr++;
1099 } /*while*/
1100 return ( sqrt((double) sum) );
1101 }
1102 /*___________________________________________________________________________*/
1103
1104
1105
1106 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_NoOfRecUnits(void)1107 static int kra2_get_NoOfRecUnits (void)
1108 {
1109 register struct Unit *unit_ptr;
1110 int count = 0;
1111
1112
1113 FOR_ALL_UNITS (unit_ptr) {
1114
1115 if (IS_SPECIAL_UNIT(unit_ptr)) {
1116 count++;
1117 } /*if*/
1118
1119 } /*FOR_ALL_UNITS*/
1120
1121 return (count);
1122
1123
1124 } /* kra2_get_NoOfRecUnits () */
1125 /*___________________________________________________________________________*/
1126
1127
1128
1129 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_InpUnits(TopoPtrArray * topo_ptr)1130 static krui_err kra2_get_InpUnits (TopoPtrArray *topo_ptr)
1131 {
1132 register struct Unit *unit_ptr;
1133
1134 krui_err ret_code = KRERR_NO_ERROR;
1135
1136
1137 FOR_ALL_UNITS (unit_ptr) {
1138
1139 if (IS_INPUT_UNIT (unit_ptr)) {
1140
1141 if (!(CHECK_ACT_FUNC(unit_ptr, ART2_ACTF_INP))) {
1142 TOPO_MSG_ACT_FUNC (unit_ptr);
1143 } /*if*/
1144
1145 if (!(CHECK_OUT_FUNC(unit_ptr, ART2_OUTFUNC))) {
1146 TOPO_MSG_OUT_FUNC (unit_ptr);
1147 } /*if*/
1148
1149 unit_ptr->lln = ART2_INP_LAY;
1150 **topo_ptr = unit_ptr;
1151 unit_ptr->flags |= UFLAG_REFRESH;
1152 (*topo_ptr)++;
1153 } /*if*/
1154
1155 } /*FOR_ALL_UNITS*/
1156
1157 return (ret_code);
1158
1159 } /* kra2_get_InpUnits () */
1160 /*___________________________________________________________________________*/
1161
1162
1163
1164 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_WUnits(TopoPtrArray * topo_ptr,int * no_of_w_units)1165 static krui_err kra2_get_WUnits (TopoPtrArray *topo_ptr, int *no_of_w_units)
1166 {
1167 register struct Unit *unit_ptr;
1168 register struct Unit *unit_ptr2;
1169 register struct Link *link_ptr;
1170 register struct Link *link_ptr2;
1171
1172 bool has_link_to_inp = FALSE;
1173 bool has_outgoing_links = FALSE;
1174
1175 krui_err ret_code = KRERR_NO_ERROR;
1176
1177
1178 /* look for w units */
1179
1180 FOR_ALL_UNITS (unit_ptr) {
1181
1182 if (unit_ptr->lln == 0) {
1183
1184 /* check if unit has direct inputs and link to inp unit */
1185
1186 if (UNIT_HAS_SITES (unit_ptr)) {
1187 TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
1188 } else {
1189
1190 has_link_to_inp = FALSE;
1191 has_outgoing_links = FALSE;
1192
1193 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1194 if (link_ptr->to->lln == ART2_INP_LAY) {
1195 has_link_to_inp = TRUE;
1196 break;
1197 } /*if*/
1198 } /*FOR_ALL_UNITS*/
1199
1200 /* check if unit_ptr-> has outgoing links */
1201
1202 FOR_ALL_UNITS (unit_ptr2) {
1203 if (UNIT_HAS_SITES (unit_ptr2)) {
1204 TOPO_MSG_UNEXPECTED_SITES (unit_ptr2);
1205 } else {
1206 FOR_ALL_LINKS (unit_ptr2, link_ptr2) {
1207 if (link_ptr2->to == unit_ptr) {
1208 has_outgoing_links = TRUE;
1209 break;
1210 } /*if*/
1211 } /*FOR_ALL_LINKS*/
1212 } /*if*/
1213
1214 if (has_outgoing_links) {
1215 break;
1216 } /*if*/
1217 } /*FOR_ALL_UNITS*/
1218
1219 /* if unit has link to input unit and has outgoing links it
1220 is a w unit
1221 */
1222 if (has_link_to_inp && has_outgoing_links) {
1223
1224 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_W))) {
1225 TOPO_MSG_ACT_FUNC (unit_ptr);
1226 } /*if*/
1227
1228 if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
1229 TOPO_MSG_OUT_FUNC (unit_ptr);
1230 } /*if*/
1231
1232 if (! (UNIT_REFRESHED (unit_ptr))) {
1233 unit_ptr->lln = ART2_W_LAY;
1234 (*no_of_w_units)++;
1235 **topo_ptr = unit_ptr;
1236 unit_ptr->flags |= UFLAG_REFRESH;
1237 (*topo_ptr)++;
1238 } /*if*/
1239
1240 } /*if*/
1241
1242 } /*if*/
1243
1244 } /*if*/
1245
1246 } /*FOR_ALL_UNITS*/
1247
1248 return (ret_code);
1249
1250 } /* kra2_get_WUnits () */
1251 /*___________________________________________________________________________*/
1252
1253
1254
1255 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_XUnits(TopoPtrArray * topo_ptr,int * no_of_x_units)1256 static krui_err kra2_get_XUnits (TopoPtrArray *topo_ptr, int *no_of_x_units)
1257 {
1258 krui_err ret_code = KRERR_NO_ERROR;
1259
1260 register struct Unit *unit_ptr;
1261 register struct Link *link_ptr;
1262
1263 bool has_link_to_w;
1264
1265 FOR_ALL_UNITS (unit_ptr) {
1266
1267 if (UNIT_HAS_SITES (unit_ptr)) {
1268 TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
1269 } else {
1270
1271 has_link_to_w = FALSE;
1272
1273 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1274 if (link_ptr->to->lln == ART2_W_LAY) {
1275 has_link_to_w = TRUE;
1276 break;
1277 } /*if*/
1278 } /*FOR_ALL_LINKS*/
1279 } /*if*/
1280
1281 if (has_link_to_w) {
1282
1283 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_X))) {
1284 TOPO_MSG_ACT_FUNC (unit_ptr);
1285 } /*if*/
1286
1287 if (! (UNIT_REFRESHED (unit_ptr))) {
1288 unit_ptr->lln = ART2_X_LAY;
1289 (*no_of_x_units)++;
1290 **topo_ptr = unit_ptr;
1291 unit_ptr->flags |= UFLAG_REFRESH;
1292 (*topo_ptr)++;
1293 } /*if*/
1294
1295 } /*if*/
1296
1297 } /*FOR_ALL_UNITS*/
1298
1299 return (ret_code);
1300
1301 } /* kra2_get_XUnits () */
1302 /*___________________________________________________________________________*/
1303
1304
1305
1306 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_UUnits(TopoPtrArray * topo_ptr,int * no_of_u_units)1307 static krui_err kra2_get_UUnits (TopoPtrArray *topo_ptr, int *no_of_u_units)
1308 {
1309 register struct Unit *unit_ptr1;
1310 register struct Unit *unit_ptr2 = NULL;
1311 register struct Link *link_ptr;
1312
1313 bool is_u_unit;
1314
1315 krui_err ret_code = KRERR_NO_ERROR;
1316
1317 FOR_ALL_UNITS (unit_ptr1) {
1318
1319 if (unit_ptr1->lln == ART2_W_LAY) {
1320
1321 is_u_unit = FALSE;
1322
1323 FOR_ALL_LINKS (unit_ptr1, link_ptr) {
1324
1325 unit_ptr2=link_ptr->to;
1326 if (unit_ptr2->lln != ART2_INP_LAY) {
1327 is_u_unit = TRUE;
1328 break;
1329 } /*if*/
1330
1331 } /*FOR_ALL_LINKS*/
1332
1333
1334 if (is_u_unit) {
1335
1336 if (!(CHECK_ACT_FUNC (unit_ptr2, ART2_ACTF_U))) {
1337 TOPO_MSG_ACT_FUNC (unit_ptr2);
1338 } /*if*/
1339
1340 if (!(CHECK_OUT_FUNC (unit_ptr2, ART2_OUTFUNC))) {
1341 TOPO_MSG_OUT_FUNC (unit_ptr2);
1342 } /*if*/
1343
1344 if (! (UNIT_REFRESHED (unit_ptr2))) {
1345 unit_ptr2->lln = ART2_U_LAY;
1346 (*no_of_u_units)++;
1347 **topo_ptr = unit_ptr2;
1348 unit_ptr2->flags |= UFLAG_REFRESH;
1349 (*topo_ptr)++;
1350 } /*if*/
1351
1352 } /*if*/
1353
1354 } /*if*/
1355
1356 } /*FOR_ALL_UNITS*/
1357
1358 return (ret_code);
1359
1360 } /* kra2_get_UUnits () */
1361 /*___________________________________________________________________________*/
1362
1363
1364
1365 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_VUnits(TopoPtrArray * topo_ptr,int * no_of_v_units)1366 static krui_err kra2_get_VUnits (TopoPtrArray *topo_ptr, int *no_of_v_units)
1367 {
1368 register struct Unit *unit_ptr;
1369 register struct Link *link_ptr;
1370 bool has_link_to_x;
1371
1372 krui_err ret_code = KRERR_NO_ERROR;
1373
1374 FOR_ALL_UNITS (unit_ptr) {
1375
1376 if (unit_ptr->lln == 0) {
1377
1378 if (UNIT_HAS_SITES (unit_ptr)) {
1379 TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
1380 } else {
1381 has_link_to_x = FALSE;
1382 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1383 if (link_ptr->to->lln == ART2_X_LAY) {
1384 has_link_to_x = TRUE;
1385 break;
1386 } /*if*/
1387 } /*FOR_ALL_LINKS*/
1388 } /*if*/
1389
1390 if (has_link_to_x) {
1391
1392 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_V))) {
1393 TOPO_MSG_ACT_FUNC (unit_ptr);
1394 } /*if*/
1395
1396 if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
1397 TOPO_MSG_OUT_FUNC (unit_ptr);
1398 } /*if*/
1399
1400 if (! (UNIT_REFRESHED (unit_ptr))) {
1401 unit_ptr->lln = ART2_V_LAY;
1402 (*no_of_v_units)++;
1403 **topo_ptr = unit_ptr;
1404 unit_ptr->flags |= UFLAG_REFRESH;
1405 (*topo_ptr)++;
1406 } /*if*/
1407
1408 } /*if*/
1409
1410 } /*if*/
1411
1412 } /*FOR_ALL_UNITS*/
1413
1414 return (ret_code);
1415
1416 } /* kra2_get_VUnits () */
1417 /*___________________________________________________________________________*/
1418
1419
1420
1421 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_PUnits(TopoPtrArray * topo_ptr,int * no_of_p_units)1422 static krui_err kra2_get_PUnits (TopoPtrArray *topo_ptr, int *no_of_p_units)
1423 {
1424 register struct Unit *unit_ptr;
1425 register struct Link *link_ptr;
1426
1427 bool is_p_unit;
1428
1429 krui_err ret_code = KRERR_NO_ERROR;
1430
1431 FOR_ALL_UNITS (unit_ptr) {
1432
1433 if (unit_ptr->lln == 0) {
1434
1435 if (UNIT_HAS_SITES (unit_ptr)) {
1436 TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
1437 } else {
1438
1439 is_p_unit = FALSE;
1440
1441 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1442
1443 if ((unit_ptr->lln != ART2_W_LAY) &&
1444 (link_ptr->to->lln == ART2_U_LAY)
1445 )
1446 {
1447 is_p_unit = TRUE;
1448 break;
1449 } /*if*/
1450
1451 } /*FOR_ALL_UNITS*/
1452
1453 if (is_p_unit) {
1454
1455 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_P))) {
1456 TOPO_MSG_ACT_FUNC (unit_ptr);
1457 } /*if*/
1458
1459 if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
1460 TOPO_MSG_OUT_FUNC (unit_ptr);
1461 } /*if*/
1462
1463 if (! (UNIT_REFRESHED (unit_ptr))) {
1464 unit_ptr->lln = ART2_P_LAY;
1465 (*no_of_p_units)++;
1466 **topo_ptr = unit_ptr;
1467 unit_ptr->flags |= UFLAG_REFRESH;
1468 (*topo_ptr)++;
1469 } /*if*/
1470
1471 } /*if*/
1472
1473 } /*if*/
1474
1475 } /*if*/
1476
1477 } /*FOR_ALL_UNITS*/
1478
1479 return (ret_code);
1480
1481 } /* kra2_get_PUnits () */
1482 /*___________________________________________________________________________*/
1483
1484
1485
1486 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_QUnits(TopoPtrArray * topo_ptr,int * no_of_q_units)1487 static krui_err kra2_get_QUnits (TopoPtrArray *topo_ptr, int *no_of_q_units)
1488 {
1489 register struct Unit *unit_ptr;
1490 register struct Link *link_ptr;
1491
1492 bool has_link_to_p;
1493 bool has_link_to_other;
1494
1495 krui_err ret_code = KRERR_NO_ERROR;
1496
1497 FOR_ALL_UNITS (unit_ptr) {
1498
1499 if (unit_ptr->lln == 0) {
1500
1501 if (UNIT_HAS_SITES (unit_ptr)) {
1502 TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
1503 } else {
1504
1505 has_link_to_p = FALSE;
1506 has_link_to_other = FALSE;
1507
1508 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1509
1510 switch (link_ptr->to->lln) {
1511 case ART2_P_LAY:
1512 has_link_to_p = TRUE;
1513 break;
1514 default:
1515 has_link_to_other = TRUE;
1516 break;
1517 } /*switch*/
1518
1519 } /*FOR_ALL_LINKS*/
1520
1521 if ((has_link_to_p) && (! has_link_to_other)) {
1522
1523 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_Q))) {
1524 TOPO_MSG_ACT_FUNC (unit_ptr);
1525 } /*if*/
1526
1527 if (! (UNIT_REFRESHED (unit_ptr))) {
1528 unit_ptr->lln = ART2_Q_LAY;
1529 (*no_of_q_units)++;
1530 **topo_ptr = unit_ptr;
1531 unit_ptr->flags |= UFLAG_REFRESH;
1532 (*topo_ptr)++;
1533 } /*if*/
1534
1535 } /*if*/
1536
1537 } /*if*/
1538
1539 } /*if*/
1540
1541 } /*FOR_ALL_UNITS*/
1542
1543 return (ret_code);
1544
1545 } /* kra2_get_QUnits () */
1546 /*___________________________________________________________________________*/
1547
1548
1549
1550 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_RUnits(TopoPtrArray * topo_ptr,int * no_of_r_units)1551 static krui_err kra2_get_RUnits (TopoPtrArray *topo_ptr, int *no_of_r_units)
1552 {
1553 register struct Unit *unit_ptr;
1554 register struct Link *link_ptr;
1555
1556 bool has_link_to_p;
1557 bool has_link_to_inp;
1558
1559 krui_err ret_code = KRERR_NO_ERROR;
1560
1561 FOR_ALL_UNITS (unit_ptr) {
1562
1563 if (unit_ptr->lln == 0) {
1564
1565 if (UNIT_HAS_SITES (unit_ptr)) {
1566 TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
1567 } else {
1568
1569 has_link_to_inp = FALSE;
1570 has_link_to_p = FALSE;
1571
1572 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1573
1574 switch (link_ptr->to->lln) {
1575 case ART2_INP_LAY:
1576 has_link_to_inp = TRUE;
1577 break;
1578 case ART2_P_LAY:
1579 has_link_to_p = TRUE;
1580 break;
1581 } /*switch*/
1582
1583 } /*FOR_ALL_LINKS*/
1584
1585 if (has_link_to_inp && has_link_to_p) {
1586
1587 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_R))) {
1588 TOPO_MSG_ACT_FUNC (unit_ptr);
1589 } /*if*/
1590
1591 if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
1592 TOPO_MSG_OUT_FUNC (unit_ptr);
1593 } /*if*/
1594
1595 if (! (UNIT_REFRESHED (unit_ptr))) {
1596 unit_ptr->lln = ART2_R_LAY;
1597 (*no_of_r_units)++;
1598 **topo_ptr = unit_ptr;
1599 unit_ptr->flags |= UFLAG_REFRESH;
1600 (*topo_ptr)++;
1601 } /*if*/
1602
1603 } /*if*/
1604
1605 } /*if*/
1606
1607 } /*if*/
1608
1609 } /*FOR_ALL_UNITS*/
1610
1611 return (ret_code);
1612
1613 } /* kra2_get_RUnits () */
1614 /*___________________________________________________________________________*/
1615
1616
1617
1618 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_RecUnits(TopoPtrArray * topo_ptr)1619 static krui_err kra2_get_RecUnits (TopoPtrArray *topo_ptr)
1620 {
1621 register struct Unit *unit_ptr;
1622
1623 krui_err ret_code = KRERR_NO_ERROR;
1624
1625 FOR_ALL_UNITS (unit_ptr) {
1626
1627 if ((unit_ptr->lln == 0) && (IS_SPECIAL_UNIT (unit_ptr))) {
1628
1629 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_REC))) {
1630 TOPO_MSG_ACT_FUNC (unit_ptr);
1631 } /*if*/
1632
1633 if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
1634 TOPO_MSG_OUT_FUNC (unit_ptr);
1635 } /*if*/
1636
1637 if (! (UNIT_REFRESHED (unit_ptr))) {
1638 unit_ptr->lln = ART2_REC_LAY;
1639 **topo_ptr = unit_ptr;
1640 unit_ptr->flags |= UFLAG_REFRESH;
1641 (*topo_ptr)++;
1642 } /*if*/
1643
1644 } /*if*/
1645
1646 } /*FOR_ALL_UNITS*/
1647
1648 return (ret_code);
1649
1650 } /* kra2_get_RecUnits () */
1651 /*___________________________________________________________________________*/
1652
1653
1654
1655 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_get_RstUnits(TopoPtrArray * topo_ptr,int * no_of_rst_units)1656 static krui_err kra2_get_RstUnits (TopoPtrArray *topo_ptr, int *no_of_rst_units)
1657 {
1658 register struct Unit *unit_ptr;
1659
1660 krui_err ret_code = KRERR_NO_ERROR;
1661
1662 FOR_ALL_UNITS (unit_ptr) {
1663
1664 if (unit_ptr->lln == 0) {
1665
1666 if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_RST))) {
1667 TOPO_MSG_ACT_FUNC (unit_ptr);
1668 } /*if*/
1669
1670 if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
1671 TOPO_MSG_OUT_FUNC (unit_ptr);
1672 } /*if*/
1673
1674 if (! (UNIT_REFRESHED (unit_ptr))) {
1675 unit_ptr->lln = ART2_RST_LAY;
1676 (*no_of_rst_units)++;
1677 **topo_ptr = unit_ptr;
1678 unit_ptr->flags |= UFLAG_REFRESH;
1679 (*topo_ptr)++;
1680 } /*if*/
1681
1682 } /*if*/
1683
1684 } /*FOR_ALL_UNITS*/
1685
1686 return (ret_code);
1687
1688 } /* kra2_get_RstUnits () */
1689 /*___________________________________________________________________________*/
1690
1691
1692
1693 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_TopoPtrArray(void)1694 static krui_err kra2_TopoPtrArray (void)
1695 {
1696 TopoPtrArray topo_inp_w_sep,
1697 topo_w_x_sep,
1698 topo_x_u_sep,
1699 topo_u_v_sep,
1700 topo_v_p_sep,
1701 topo_p_q_sep,
1702 topo_q_r_sep,
1703 topo_r_rec_sep,
1704 topo_rec_rst_sep,
1705 topo_ptr_array_end;
1706
1707 krui_err ret_code = KRERR_NO_ERROR;
1708
1709 topo_inp_w_sep = topo_ptr_array + NoOfInputUnits + 1;
1710 topo_w_x_sep = topo_inp_w_sep + NoOfInputUnits + 1;
1711 topo_x_u_sep = topo_w_x_sep + NoOfInputUnits + 1;
1712 topo_u_v_sep = topo_x_u_sep + NoOfInputUnits + 1;
1713 topo_v_p_sep = topo_u_v_sep + NoOfInputUnits + 1;
1714 topo_p_q_sep = topo_v_p_sep + NoOfInputUnits + 1;
1715 topo_q_r_sep = topo_p_q_sep + NoOfInputUnits + 1;
1716 topo_r_rec_sep = topo_q_r_sep + NoOfInputUnits + 1;
1717 topo_rec_rst_sep = topo_r_rec_sep + Art2_NoOfRecUnits + 1;
1718 topo_ptr_array_end = topo_rec_rst_sep + Art2_NoOfRecUnits + 1;
1719
1720 if ((*topo_inp_w_sep != NULL) ||
1721 (*topo_w_x_sep != NULL) ||
1722 (*topo_x_u_sep != NULL) ||
1723 (*topo_u_v_sep != NULL) ||
1724 (*topo_v_p_sep != NULL) ||
1725 (*topo_p_q_sep != NULL) ||
1726 (*topo_q_r_sep != NULL) ||
1727 (*topo_r_rec_sep != NULL) ||
1728 (*topo_rec_rst_sep != NULL) ||
1729 (*topo_ptr_array_end != NULL)
1730 )
1731 {
1732 ART2_RETURN_NET_ERROR (ret_code);
1733 } /*if*/
1734
1735 return (ret_code);
1736
1737 } /* kra2_TopoPtrArray () */
1738 /*___________________________________________________________________________*/
1739
1740
1741
1742 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToInpUnits(TopoPtrArray * topo_ptr)1743 static krui_err kra2_LinksToInpUnits (TopoPtrArray *topo_ptr)
1744 {
1745 register struct Unit *unit_ptr;
1746
1747 krui_err ret_code = KRERR_NO_ERROR;
1748
1749 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
1750
1751 if (UNIT_HAS_INPUTS (unit_ptr)) {
1752 topo_msg.error_code = KRERR_I_UNITS_CONNECT;
1753 topo_msg.dest_error_unit = unit_ptr-unit_array;
1754 topo_msg.src_error_unit = 0;
1755 ret_code = topo_msg.error_code;
1756 } /*if*/
1757
1758 } /*while*/
1759
1760 return (ret_code);
1761
1762 } /* kra2_LinksToInpUnits () */
1763 /*___________________________________________________________________________*/
1764
1765
1766
1767 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToWUnits(TopoPtrArray * topo_ptr)1768 static krui_err kra2_LinksToWUnits (TopoPtrArray *topo_ptr)
1769 {
1770 register struct Unit *unit_ptr;
1771 register struct Link *link_ptr;
1772 int count_inp, count_u;
1773 krui_err ret_code = KRERR_NO_ERROR;
1774
1775 krart_deleteTouchFlags();
1776
1777 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
1778
1779 count_inp = 0;
1780 count_u = 0;
1781
1782 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1783 switch (link_ptr->to->lln) {
1784 case ART2_INP_LAY:
1785 if ((UNIT_REFRESHED (link_ptr->to)) || (count_inp > 0)) {
1786 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1787 } /*if*/
1788 link_ptr->to->flags |= UFLAG_REFRESH;
1789 count_inp++;
1790 break;
1791 case ART2_U_LAY:
1792 if ((UNIT_REFRESHED (link_ptr->to)) || (count_u > 0)) {
1793 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1794 } /*if*/
1795 link_ptr->to->flags |= UFLAG_REFRESH;
1796 count_u++;
1797 break;
1798 default:
1799 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1800 } /*switch*/
1801 } /*FOR_ALL_LINKS*/
1802
1803 if ((count_inp != 1) || (count_u != 1)) {
1804 TOPO_MSG_LINK_MISSING (unit_ptr);
1805 } /*if*/
1806
1807 } /*while*/
1808
1809 return (ret_code);
1810
1811 } /* kra2_LinksToWUnits () */
1812 /*___________________________________________________________________________*/
1813
1814
1815
1816 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToXUnits(TopoPtrArray * topo_ptr)1817 static krui_err kra2_LinksToXUnits (TopoPtrArray *topo_ptr)
1818 {
1819 register struct Unit *unit_ptr;
1820 register struct Link *link_ptr;
1821 int count_w;
1822 krui_err ret_code = KRERR_NO_ERROR;
1823
1824 krart_deleteTouchFlags();
1825
1826 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
1827
1828 count_w = 0;
1829
1830 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1831 switch (link_ptr->to->lln) {
1832 case ART2_W_LAY:
1833 if ((UNIT_REFRESHED (link_ptr->to)) || (count_w > 0)) {
1834 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1835 } /*if*/
1836 link_ptr->to->flags |= UFLAG_REFRESH;
1837 count_w++;
1838 break;
1839 default:
1840 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1841 break;
1842 } /*switch*/
1843 } /*FOR_ALL_LINKS*/
1844
1845 if (count_w != 1) {
1846 TOPO_MSG_LINK_MISSING (unit_ptr);
1847 } /*if*/
1848
1849 } /*while*/
1850
1851 return (ret_code);
1852
1853 } /* kra2_LinksToXUnits () */
1854 /*___________________________________________________________________________*/
1855
1856
1857
1858 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToUUnits(TopoPtrArray * topo_ptr)1859 static krui_err kra2_LinksToUUnits (TopoPtrArray *topo_ptr)
1860 {
1861 register struct Unit *unit_ptr;
1862 register struct Link *link_ptr;
1863 int count_v;
1864 krui_err ret_code = KRERR_NO_ERROR;
1865
1866 krart_deleteTouchFlags();
1867
1868 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
1869
1870 count_v = 0;
1871
1872 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1873 switch (link_ptr->to->lln) {
1874 case ART2_V_LAY:
1875 if ((UNIT_REFRESHED (link_ptr->to)) || (count_v > 0)) {
1876 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1877 } /*if*/
1878 link_ptr->to->flags |= UFLAG_REFRESH;
1879 count_v++;
1880 break;
1881 default:
1882 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1883 break;
1884 } /*switch*/
1885 } /*FOR_ALL_LINKS*/
1886
1887 if (count_v != 1) {
1888 TOPO_MSG_LINK_MISSING (unit_ptr);
1889 } /*if*/
1890
1891 } /*while*/
1892
1893 return (ret_code);
1894
1895 } /* kra2_LinksToUUnits () */
1896 /*___________________________________________________________________________*/
1897
1898
1899
1900 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToVUnits(TopoPtrArray * topo_ptr)1901 static krui_err kra2_LinksToVUnits (TopoPtrArray *topo_ptr)
1902 {
1903 register struct Unit *unit_ptr;
1904 register struct Link *link_ptr;
1905 int count_x, count_q;
1906 krui_err ret_code = KRERR_NO_ERROR;
1907
1908 krart_deleteTouchFlags();
1909
1910 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
1911
1912 count_x = 0;
1913 count_q = 0;
1914
1915 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1916 switch (link_ptr->to->lln) {
1917 case ART2_X_LAY:
1918 if ((UNIT_REFRESHED (link_ptr->to)) || (count_x > 0)) {
1919 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1920 } /*if*/
1921 link_ptr->to->flags |= UFLAG_REFRESH;
1922 count_x++;
1923 break;
1924 case ART2_Q_LAY:
1925 if ((UNIT_REFRESHED (link_ptr->to)) || (count_q > 0)) {
1926 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1927 } /*if*/
1928 link_ptr->to->flags |= UFLAG_REFRESH;
1929 count_q++;
1930 break;
1931 default:
1932 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1933 break;
1934 } /*switch*/
1935 } /*FOR_ALL_LINKS*/
1936
1937 if ((count_x != 1) || (count_q != 1)) {
1938 TOPO_MSG_LINK_MISSING (unit_ptr);
1939 } /*if*/
1940
1941 } /*while*/
1942
1943 return (ret_code);
1944
1945 } /* kra2_LinksToVUnits () */
1946 /*___________________________________________________________________________*/
1947
1948
1949
1950 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToPUnits(TopoPtrArray * topo_ptr)1951 static krui_err kra2_LinksToPUnits (TopoPtrArray *topo_ptr)
1952 {
1953 register struct Unit *unit_ptr;
1954 register struct Link *link_ptr;
1955 int count_u, count_rec;
1956 krui_err ret_code = KRERR_NO_ERROR;
1957
1958 krart_deleteTouchFlags();
1959
1960 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
1961
1962 count_u = 0;
1963 count_rec = 0;
1964
1965 FOR_ALL_LINKS (unit_ptr, link_ptr) {
1966 switch (link_ptr->to->lln) {
1967 case ART2_U_LAY:
1968 if ((UNIT_REFRESHED (link_ptr->to)) || (count_u > 0)) {
1969 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1970 } /*if*/
1971 link_ptr->to->flags |= UFLAG_REFRESH;
1972 count_u++;
1973 break;
1974 case ART2_REC_LAY:
1975 count_rec++;
1976 break;
1977 default:
1978 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
1979 break;
1980 } /*switch*/
1981 } /*FOR_ALL_LINKS*/
1982
1983 if ((count_u != 1) || (count_rec != Art2_NoOfRecUnits)) {
1984 TOPO_MSG_LINK_MISSING (unit_ptr);
1985 } /*if*/
1986
1987 } /*while*/
1988
1989 return (ret_code);
1990
1991 } /* kra2_LinksToPUnits () */
1992 /*___________________________________________________________________________*/
1993
1994
1995
1996 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToQUnits(TopoPtrArray * topo_ptr)1997 static krui_err kra2_LinksToQUnits (TopoPtrArray *topo_ptr)
1998 {
1999 register struct Unit *unit_ptr;
2000 register struct Link *link_ptr;
2001 int count_p;
2002 krui_err ret_code = KRERR_NO_ERROR;
2003
2004 krart_deleteTouchFlags();
2005
2006 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
2007
2008 count_p = 0;
2009
2010 FOR_ALL_LINKS (unit_ptr, link_ptr) {
2011 switch (link_ptr->to->lln) {
2012 case ART2_P_LAY:
2013 if ((UNIT_REFRESHED (link_ptr->to)) || (count_p > 0)) {
2014 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2015 } /*if*/
2016 link_ptr->to->flags |= UFLAG_REFRESH;
2017 count_p++;
2018 break;
2019 default:
2020 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2021 break;
2022 } /*switch*/
2023 } /*FOR_ALL_LINKS*/
2024
2025 if (count_p != 1) {
2026 TOPO_MSG_LINK_MISSING (unit_ptr);
2027 } /*if*/
2028
2029 } /*while*/
2030
2031 return (ret_code);
2032
2033 } /* kra2_LinksToQUnits () */
2034 /*___________________________________________________________________________*/
2035
2036
2037
2038 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToRUnits(TopoPtrArray * topo_ptr)2039 static krui_err kra2_LinksToRUnits (TopoPtrArray *topo_ptr)
2040 {
2041 register struct Unit *unit_ptr;
2042 register struct Link *link_ptr;
2043 int count_inp, count_p;
2044 krui_err ret_code = KRERR_NO_ERROR;
2045
2046 krart_deleteTouchFlags();
2047
2048 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
2049
2050 count_inp = 0;
2051 count_p = 0;
2052
2053 FOR_ALL_LINKS (unit_ptr, link_ptr) {
2054 switch (link_ptr->to->lln) {
2055 case ART2_INP_LAY:
2056 if ((UNIT_REFRESHED (link_ptr->to)) || (count_inp > 0)) {
2057 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2058 } /*if*/
2059 link_ptr->to->flags |= UFLAG_REFRESH;
2060 count_inp++;
2061 break;
2062 case ART2_P_LAY:
2063 if ((UNIT_REFRESHED (link_ptr->to)) || (count_p > 0)) {
2064 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2065 } /*if*/
2066 link_ptr->to->flags |= UFLAG_REFRESH;
2067 count_p++;
2068 break;
2069 default:
2070 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2071 break;
2072 } /*switch*/
2073 } /*FOR_ALL_LINKS*/
2074
2075 if ((count_inp != 1) || (count_p != 1)) {
2076 TOPO_MSG_LINK_MISSING (unit_ptr);
2077 } /*if*/
2078
2079 } /*while*/
2080
2081 return (ret_code);
2082
2083 } /* kra2_LinksToRUnits () */
2084 /*___________________________________________________________________________*/
2085
2086
2087
2088 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToRecUnits(TopoPtrArray * topo_ptr)2089 static krui_err kra2_LinksToRecUnits (TopoPtrArray *topo_ptr)
2090 {
2091 register struct Unit *unit_ptr;
2092 register struct Link *link_ptr;
2093 int count_p, count_rst;
2094 krui_err ret_code = KRERR_NO_ERROR;
2095
2096 krart_deleteTouchFlags();
2097
2098 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
2099
2100 count_p = 0;
2101 count_rst = 0;
2102
2103 FOR_ALL_LINKS (unit_ptr, link_ptr) {
2104 switch (link_ptr->to->lln) {
2105 case ART2_P_LAY:
2106 count_p++;
2107 break;
2108 case ART2_RST_LAY:
2109 if ((UNIT_REFRESHED (link_ptr->to)) || (count_rst > 0)) {
2110 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2111 } /*if*/
2112 link_ptr->to->flags |= UFLAG_REFRESH;
2113 count_rst++;
2114 break;
2115 default:
2116 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2117 break;
2118 } /*switch*/
2119 } /*FOR_ALL_LINKS*/
2120
2121 if ((count_p != NoOfInputUnits) || (count_rst != 1)) {
2122 TOPO_MSG_LINK_MISSING (unit_ptr);
2123 } /*if*/
2124
2125 } /*while*/
2126
2127 return (ret_code);
2128
2129 } /* kra2_LinksToRecUnits () */
2130 /*___________________________________________________________________________*/
2131
2132
2133
2134 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_LinksToRstUnits(TopoPtrArray * topo_ptr)2135 static krui_err kra2_LinksToRstUnits (TopoPtrArray *topo_ptr)
2136 {
2137 register struct Unit *unit_ptr;
2138 register struct Link *link_ptr;
2139 int count_rec;
2140 krui_err ret_code = KRERR_NO_ERROR;
2141
2142 krart_deleteTouchFlags();
2143
2144 while ((unit_ptr = *(*topo_ptr)++) != NULL) {
2145
2146 count_rec = 0;
2147
2148 FOR_ALL_LINKS (unit_ptr, link_ptr) {
2149 switch (link_ptr->to->lln) {
2150 case ART2_REC_LAY:
2151 if ((UNIT_REFRESHED (link_ptr->to)) || (count_rec > 0)) {
2152 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2153 } /*if*/
2154 link_ptr->to->flags |= UFLAG_REFRESH;
2155 count_rec++;
2156 break;
2157 default:
2158 TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
2159 break;
2160 } /*switch*/
2161 } /*FOR_ALL_LINKS*/
2162
2163 if (count_rec != 1) {
2164 TOPO_MSG_LINK_MISSING (unit_ptr);
2165 } /*if*/
2166
2167 } /*while*/
2168
2169 return (ret_code);
2170
2171 } /* kra2_LinksToRstUnits () */
2172 /*___________________________________________________________________________*/
2173
2174
2175
2176 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_init_i_act(void)2177 static krui_err kra2_init_i_act (void)
2178 {
2179 int ret_code = KRERR_NO_ERROR;
2180
2181 register struct Unit *unit_ptr;
2182
2183
2184 /* set initial activation values to 0.0 and
2185 copy actual activation values of input units into value_a field to
2186 remember it
2187 */
2188
2189
2190 FOR_ALL_UNITS (unit_ptr) {
2191
2192 unit_ptr->i_act = 0.0;
2193
2194 } /*FOR_ALL_UNITS*/
2195
2196 return (ret_code);
2197
2198 } /* kra2_init_i_act () */
2199 /*___________________________________________________________________________*/
2200
2201
2202
2203 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
kra2_init_fix_weights(void)2204 static krui_err kra2_init_fix_weights (void)
2205 {
2206 int ret_code = KRERR_NO_ERROR;
2207
2208 register struct Unit *unit_ptr;
2209 register struct Site *site_ptr;
2210 register struct Link *link_ptr;
2211
2212
2213
2214
2215 FOR_ALL_UNITS (unit_ptr) {
2216
2217 if (UNIT_HAS_INPUTS (unit_ptr)) {
2218
2219 if (UNIT_HAS_DIRECT_INPUTS (unit_ptr)) {
2220
2221 FOR_ALL_LINKS (unit_ptr, link_ptr) {
2222
2223 kra2_set_fix_weight (link_ptr->to, unit_ptr, &(link_ptr->weight));
2224
2225 } /*FOR_ALL_LINKS*/
2226
2227 } else {
2228
2229 FOR_ALL_SITES_AND_LINKS (unit_ptr, site_ptr, link_ptr) {
2230
2231 kra2_set_fix_weight (link_ptr->to, unit_ptr, &(link_ptr->weight));
2232
2233 } /*FOR_ALL_SITES_AND_LINKS*/
2234
2235 } /*if*/
2236
2237 } /*if*/
2238
2239 } /*FOR_ALL_UNITS*/
2240
2241
2242 return (ret_code);
2243
2244
2245 } /* kra2_init_fix_weights () */
2246 /*___________________________________________________________________________*/
2247
2248
2249