home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- **** ****
- **** atree.h ****
- **** ****
- **** atree release 2.0 for PC, Windows ****
- **** Adaptive Logic Network (ALN) simulation program. ****
- **** Copyright (C) A. Dwelly, R. Manderscheid, W.W. Armstrong, ****
- **** M. Thomas, 1991 ****
- **** License: ****
- **** A royalty-free license is granted for the use of this software for ****
- **** NON_COMMERCIAL PURPOSES ONLY. The software may be copied and/or ****
- **** modified provided this notice appears in its entirety and unchanged ****
- **** in all derived source programs. Persons modifying the code are ****
- **** requested to state the date, the changes made and who made them ****
- **** in the modification history. ****
- **** ****
- **** Patent License: ****
- **** The use of a digital circuit which transmits a signal indicating ****
- **** heuristic responsibility is protected by U. S. Patent 3,934,231 ****
- **** and others assigned to Dendronic Decisions Limited of Edmonton, ****
- **** W. W. Armstrong, President. A royalty-free license is granted ****
- **** by the company to use this patent for NON_COMMERCIAL PURPOSES to ****
- **** adapt logic trees using this program and its modifications. ****
- **** ****
- **** Limited Warranty: ****
- **** This software is provided "as is" without warranty of any kind, ****
- **** either expressed or implied, including, but not limited to, the ****
- **** implied warrantees of merchantability and fitness for a particular ****
- **** purpose. The entire risk as to the quality and performance of the ****
- **** program is with the user. Neither the authors, nor the ****
- **** University of Alberta, its officers, agents, servants or employees ****
- **** shall be liable or responsible in any way for any damage to ****
- **** property or direct personal or consequential injury of any nature ****
- **** whatsoever that may be suffered or sustained by any licensee, user ****
- **** or any other party as a consequence of the use or disposition of ****
- **** this software. ****
- **** ****
- **** Modification history: ****
- **** ****
- **** 90.09.05 Initial implementation, A.Dwelly ****
- **** 91.04.15 Port to PC and minor bug fixes, R. Manderscheid ****
- **** 91.05.31 Port to Windows & Windows Extensions, M. Thomas ****
- **** 91.07.17 atree v2.0 for Windows, M. Thomas ****
- **** ****
- *****************************************************************************/
-
- /*****************************************************************************
- **** ****
- **** bit_vec ****
- **** ****
- **** A bit_vec is a packed vector of bits, stored in an array of chars. ****
- *****************************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
-
- typedef struct bit_vec_strc
- {
- int len; /* The length of the vector in bits */
- LPSTR bv;
- }
- bit_vec;
-
- typedef bit_vec far *LPBIT_VEC;
-
- /*****************************************************************************
- **** ****
- **** atree ****
- **** ****
- **** An atree is the fundamental structure used by these routines; it is ****
- **** a binary tree with nodes taking one of four logical functions, AND, ****
- **** OR, LEFT or RIGHT depending on initialization or the training it ****
- **** has undergone. The tree is randomly connected to input variables ****
- **** and their complements. ****
- **** ****
- *****************************************************************************/
-
- typedef union atree_type {
-
- union atree_node_type {
- union atree_node_type far *next; /* for free list management */
- struct {
- char cnt_right;
- char cnt_left;
- unsigned int tag : 3;
- unsigned int sig_right : 2;
- unsigned int sig_left : 2;
- union atree_type far *child[2];
- } data;
- } node;
-
- union atree_leaf_type {
- union atree_leaf_type far *next;
- struct {
- unsigned int bit_no;
- unsigned char tag;
- unsigned char comp;
- } data;
- } leaf;
-
- } atree;
-
- typedef atree far *LPATREE;
-
- #define c_tag node.data.tag /* common tag */
- #define l_bit_no leaf.data.bit_no
- #define l_comp leaf.data.comp
- #define n_sig_right node.data.sig_right
- #define n_sig_left node.data.sig_left
- #define n_cnt_right node.data.cnt_right
- #define n_cnt_left node.data.cnt_left
- #define n_child node.data.child
-
- typedef union atree_node_type atree_node;
- typedef atree_node far *LPATREE_NODE;
-
- typedef union atree_leaf_type atree_leaf;
- typedef atree_leaf far *LPATREE_LEAF;
-
- typedef struct fast_tree_struct {
- struct fast_tree_struct far *next[2];
- short bit_no;
- short comp;
- } fast_tree;
-
- typedef fast_tree far *LPFAST_TREE;
-
- typedef struct code_struct {
- int vector_count;
- int width;
- float low;
- float high;
- float step;
- LPBIT_VEC vector;
- } code_t;
-
- typedef code_t far *LPCODE_T;
-
- /* Import public routines */
-
- void FAR PASCAL Windows_Interrupt(DWORD);
-
- void FAR PASCAL atree_init(HANDLE);
- void FAR PASCAL atree_quit(void);
- LPATREE FAR PASCAL atree_create(int, int);
- void FAR PASCAL atree_print(LPATREE, int);
- BOOL FAR PASCAL atree_eval(LPATREE, LPBIT_VEC);
- BOOL FAR PASCAL atree_train(LPATREE, LPBIT_VEC, LPBIT_VEC,int,int,int,int,int);
- LPBIT_VEC FAR PASCAL atree_rand_walk(int, int, int);
- void FAR PASCAL atree_free(LPATREE);
-
- LPATREE FAR PASCAL atree_fold(LPATREE);
- LPFAST_TREE FAR PASCAL atree_compress(LPATREE);
- int FAR PASCAL atree_fast_eval(LPFAST_TREE, LPBIT_VEC);
- void FAR PASCAL atree_fast_print(LPFAST_TREE);
-
- int FAR PASCAL atree_store(LPATREE, LPSTR);
- LPATREE FAR PASCAL atree_load(LPSTR);
- int FAR PASCAL atree_write(FILE *, LPATREE);
- LPATREE FAR PASCAL atree_read(FILE *);
-
- int FAR PASCAL atree_set_code(LPCODE_T, double, double, int, int, int);
- int FAR PASCAL atree_encode(double, LPCODE_T);
- int FAR PASCAL atree_decode(LPBIT_VEC, LPCODE_T);
- int FAR PASCAL atree_write_code(FILE *, LPCODE_T);
- LPCODE_T FAR PASCAL atree_read_code(FILE *, LPCODE_T);
-
- int FAR PASCAL bv_diff(LPBIT_VEC, LPBIT_VEC);
- LPBIT_VEC FAR PASCAL bv_create(int);
- LPBIT_VEC FAR PASCAL bv_pack(LPSTR, int);
- LPBIT_VEC FAR PASCAL bv_concat(int, LPBIT_VEC FAR *);
- LPBIT_VEC FAR PASCAL bv_copy(LPBIT_VEC);
- void FAR PASCAL bv_set(int,LPBIT_VEC,BOOL);
- BOOL FAR PASCAL bv_extract(int,LPBIT_VEC);
- BOOL FAR PASCAL bv_equal(LPBIT_VEC, LPBIT_VEC);
- void FAR PASCAL bv_free(LPBIT_VEC);
- int FAR PASCAL bv_print(FILE *, LPBIT_VEC);
-
- LPSTR FAR PASCAL WinMem_Malloc(WORD, WORD);
- LPSTR FAR PASCAL WinMem_Free(LPSTR);
-
- /* some public Macros */
-
- #define MEMCHECK(p) \
- if (p == NULL){ \
- char szBuffer[50]; \
- wsprintf(szBuffer,"Could not allocate requested memory");\
- MessageBox(NULL,szBuffer,"atree",MB_OK | MB_ICONSTOP);\
- exit(0);\
- }
- #define RANDOM(b) (rand() % (b))
- #define Malloc(cb) WinMem_Malloc(LMEM_MOVEABLE | LMEM_ZEROINIT, (WORD) cb)
- #define Free(p) WinMem_Free((LPSTR) p)
-