home *** CD-ROM | disk | FTP | other *** search
/ Windoware / WINDOWARE_1_6.iso / miscprog / atre20 / atree.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-08  |  8.7 KB  |  194 lines

  1. /*****************************************************************************
  2.  ****                                                                     ****
  3.  **** atree.h                                                             ****
  4.  ****                                                                     ****
  5.  **** atree release 2.0 for PC, Windows                                   ****
  6.  **** Adaptive Logic Network (ALN) simulation program.                    ****
  7.  **** Copyright (C) A. Dwelly, R. Manderscheid, W.W. Armstrong,           ****
  8.  **** M. Thomas, 1991                                                     ****
  9.  **** License:                                                            ****
  10.  **** A royalty-free license is granted for the use of this software for  ****
  11.  **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or     ****
  12.  **** modified provided this notice appears in its entirety and unchanged ****
  13.  **** in all derived source programs.  Persons modifying the code are     ****
  14.  **** requested to state the date, the changes made and who made them     ****
  15.  **** in the modification history.                                        ****
  16.  ****                                                                     ****
  17.  **** Patent License:                                                     ****
  18.  **** The use of a digital circuit which transmits a signal indicating    ****
  19.  **** heuristic responsibility is protected by U. S. Patent 3,934,231     ****
  20.  **** and others assigned to Dendronic Decisions Limited of Edmonton,     ****
  21.  **** W. W. Armstrong, President.  A royalty-free license is granted      ****
  22.  **** by the company to use this patent for NON_COMMERCIAL PURPOSES to    ****
  23.  **** adapt logic trees using this program and its modifications.         ****
  24.  ****                                                                     ****
  25.  **** Limited Warranty:                                                   ****
  26.  **** This software is provided "as is" without warranty of any kind,     ****
  27.  **** either expressed or implied, including, but not limited to, the     ****
  28.  **** implied warrantees of merchantability and fitness for a particular  ****
  29.  **** purpose.  The entire risk as to the quality and performance of the  ****
  30.  **** program is with the user.  Neither the authors, nor the             ****
  31.  **** University of Alberta, its officers, agents, servants or employees  ****
  32.  **** shall be liable or responsible in any way for any damage to         ****
  33.  **** property or direct personal or consequential injury of any nature   ****
  34.  **** whatsoever that may be suffered or sustained by any licensee, user  ****
  35.  **** or any other party as a consequence of the use or disposition of    ****
  36.  **** this software.                                                      ****
  37.  ****                                                                     ****
  38.  **** Modification history:                                               ****
  39.  ****                                                                     ****
  40.  **** 90.09.05 Initial implementation, A.Dwelly                           ****
  41.  **** 91.04.15 Port to PC and minor bug fixes, R. Manderscheid            ****
  42.  **** 91.05.31 Port to Windows & Windows Extensions, M. Thomas            ****
  43.  **** 91.07.17 atree v2.0 for Windows, M. Thomas                          ****
  44.  ****                                                                     ****
  45.  *****************************************************************************/
  46.  
  47. /*****************************************************************************
  48.  ****                                                                     ****
  49.  **** bit_vec                                                             ****
  50.  ****                                                                     ****
  51.  **** A bit_vec is a packed vector of bits, stored in an array of chars.  ****
  52.  *****************************************************************************/
  53.  
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56.  
  57. typedef struct bit_vec_strc
  58. {
  59.     int len;    /* The length of the vector in bits */
  60.     LPSTR bv;
  61. }
  62. bit_vec;
  63.  
  64. typedef bit_vec far *LPBIT_VEC;
  65.  
  66. /*****************************************************************************
  67.  ****                                                                     ****
  68.  **** atree                                                               ****
  69.  ****                                                                     ****
  70.  **** An atree is the fundamental structure used by these routines; it is ****
  71.  **** a binary tree with nodes taking one of four logical functions, AND, ****
  72.  **** OR, LEFT or RIGHT depending on initialization or the training it    ****
  73.  **** has undergone.  The tree is randomly connected to input variables   ****
  74.  **** and their complements.                                              ****
  75.  ****                                                                     ****
  76.  *****************************************************************************/
  77.  
  78. typedef union atree_type {
  79.  
  80.   union atree_node_type {
  81.     union atree_node_type far *next;    /* for free list management */
  82.     struct {
  83.       char cnt_right;
  84.       char cnt_left;
  85.       unsigned int tag : 3;
  86.       unsigned int sig_right : 2;
  87.       unsigned int sig_left : 2;
  88.       union atree_type far *child[2];
  89.     } data;
  90.   } node;
  91.  
  92.   union atree_leaf_type {
  93.     union atree_leaf_type far *next;
  94.     struct {
  95.       unsigned int bit_no;
  96.       unsigned char tag;
  97.       unsigned char comp;
  98.     } data;
  99.   } leaf;
  100.  
  101. } atree;
  102.  
  103. typedef atree far *LPATREE;
  104.  
  105. #define c_tag       node.data.tag   /* common tag */
  106. #define l_bit_no    leaf.data.bit_no
  107. #define l_comp      leaf.data.comp
  108. #define n_sig_right node.data.sig_right
  109. #define n_sig_left  node.data.sig_left
  110. #define n_cnt_right node.data.cnt_right
  111. #define n_cnt_left  node.data.cnt_left
  112. #define n_child     node.data.child
  113.  
  114. typedef union atree_node_type atree_node;
  115. typedef atree_node far *LPATREE_NODE;
  116.  
  117. typedef union atree_leaf_type atree_leaf;
  118. typedef atree_leaf far *LPATREE_LEAF;
  119.  
  120. typedef struct fast_tree_struct {
  121.   struct fast_tree_struct far *next[2];
  122.   short bit_no;
  123.   short comp;
  124. } fast_tree;
  125.  
  126. typedef fast_tree far *LPFAST_TREE;
  127.  
  128. typedef struct code_struct {
  129.   int vector_count;
  130.   int width;
  131.   float low;
  132.   float high;
  133.   float step;
  134.   LPBIT_VEC vector;
  135. } code_t;
  136.  
  137. typedef code_t far *LPCODE_T;
  138.  
  139. /* Import public routines */
  140.  
  141. void FAR PASCAL         Windows_Interrupt(DWORD);
  142.  
  143. void FAR PASCAL         atree_init(HANDLE);
  144. void FAR PASCAL         atree_quit(void);
  145. LPATREE FAR PASCAL      atree_create(int, int);
  146. void FAR PASCAL         atree_print(LPATREE, int);
  147. BOOL FAR PASCAL         atree_eval(LPATREE, LPBIT_VEC);
  148. BOOL FAR PASCAL         atree_train(LPATREE, LPBIT_VEC, LPBIT_VEC,int,int,int,int,int);
  149. LPBIT_VEC FAR PASCAL    atree_rand_walk(int, int, int);
  150. void FAR PASCAL         atree_free(LPATREE);
  151.  
  152. LPATREE FAR PASCAL      atree_fold(LPATREE);
  153. LPFAST_TREE FAR PASCAL  atree_compress(LPATREE);
  154. int FAR PASCAL          atree_fast_eval(LPFAST_TREE, LPBIT_VEC);
  155. void FAR PASCAL         atree_fast_print(LPFAST_TREE);
  156.  
  157. int FAR PASCAL          atree_store(LPATREE, LPSTR);
  158. LPATREE FAR PASCAL      atree_load(LPSTR);
  159. int FAR PASCAL          atree_write(FILE *, LPATREE);
  160. LPATREE FAR PASCAL      atree_read(FILE *);
  161.  
  162. int FAR PASCAL          atree_set_code(LPCODE_T, double, double, int, int, int);
  163. int FAR PASCAL          atree_encode(double, LPCODE_T);
  164. int FAR PASCAL          atree_decode(LPBIT_VEC, LPCODE_T);
  165. int FAR PASCAL          atree_write_code(FILE *, LPCODE_T);
  166. LPCODE_T FAR PASCAL     atree_read_code(FILE *, LPCODE_T);
  167.  
  168. int FAR PASCAL          bv_diff(LPBIT_VEC, LPBIT_VEC);
  169. LPBIT_VEC FAR PASCAL    bv_create(int);
  170. LPBIT_VEC FAR PASCAL    bv_pack(LPSTR, int);
  171. LPBIT_VEC FAR PASCAL    bv_concat(int, LPBIT_VEC FAR *);
  172. LPBIT_VEC FAR PASCAL    bv_copy(LPBIT_VEC);
  173. void FAR PASCAL         bv_set(int,LPBIT_VEC,BOOL);
  174. BOOL FAR PASCAL         bv_extract(int,LPBIT_VEC);
  175. BOOL FAR PASCAL         bv_equal(LPBIT_VEC, LPBIT_VEC);
  176. void FAR PASCAL         bv_free(LPBIT_VEC);
  177. int FAR PASCAL          bv_print(FILE *, LPBIT_VEC);
  178.  
  179. LPSTR FAR PASCAL        WinMem_Malloc(WORD, WORD);
  180. LPSTR FAR PASCAL        WinMem_Free(LPSTR);
  181.  
  182. /* some public Macros */
  183.  
  184. #define MEMCHECK(p) \
  185.         if (p == NULL){ \
  186.                        char szBuffer[50]; \
  187.                        wsprintf(szBuffer,"Could not allocate requested memory");\
  188.                        MessageBox(NULL,szBuffer,"atree",MB_OK | MB_ICONSTOP);\
  189.                        exit(0);\
  190.                       }
  191. #define RANDOM(b) (rand() % (b))
  192. #define Malloc(cb) WinMem_Malloc(LMEM_MOVEABLE | LMEM_ZEROINIT, (WORD) cb)
  193. #define Free(p)    WinMem_Free((LPSTR) p)
  194.