Docstoc

Appendix I Software Source Code

Document Sample
Appendix I Software Source Code Powered By Docstoc
					Appendix I

Software Source Code
This is the actual software code used in the neural network system. The
definitions of the most important functions can be found in Appendix F.
#in clud e   " ai n et dll .h "
#in clud e   < wind o ws .h>                                // Wi n32 i ncl ude
#in clud e   < sql .h>
#in clud e   < sql ext .h>
#in clud e   < st dio .h>                           // C Runti me In cl udes
#in clud e   < st dlib .h>
#in clud e   < st ri ng .h>
#in clud e   <pr o ces s .h>
#in clud e   < st dd ef .h>
#in clud e   < conio .h>
#in clud e   <io .h>
#in clud e   < mall oc. h>
#in clud e   <ti me .h>
#in clud e   < st ri ng .h>
#in clud e   <io st rea m. h>
#in clud e   < mb st ring .h>

D W OR D me a sl , cut l ,m ea s w , cut w, me a sd ,cutd , mc n c, cutj ,m ea s wj , cu twj;
SDW ORD me asl enght , c utl enght , me as wi dth , c ut widt h , me a sdep th , c utd epth , mea s cnc
,cut join , mea s widt hj , cut widt hj;
HENV h env;
HDBC dbc on;
HST M T h s t mt , hst mt w, h st mt d ,h s t mt c ,hst m t wj;
RE TC ODE r e tco d e;
int c ,w,d ,cc,wj;
c onst ch ar ain et Dl l[ ] = " ai n et 32 .d ll" ;
un si gned char         p s z SQLDSN[] = "cra ck",
                                                  p szSQLUser[ ] = "sa",
                                                  p szSQL Pa sswd[ ] = " ";

F IL E   *st e am;
F IL E   * st r e am ;
F IL E   * t e a m;
FILE     *cteam;
F IL E   *st r e am j;

/*
 * Point e rs to ain et dll fun ctions. Th ey a re mad e glob al - all fun ct ion s
 * c an u se th em .
 */

t_aiRegi st ration                         aiRegist ration;
t _ a i Get V e rs i o n                   a i Get V e rs i o n ;
t_aiC reateModel                           aiC reateModel;
t_ aiC re ateMod el Fro mC SVFil e         aiC reateMod el Fro mC SVFil e;
t _ a i Del e t e M o d e l                aiDeleteModel;
t _ a i No r ma l i z e                    a i No r ma l i z e ;
t _ a i Den o r ma l i z e                 a i Den o r ma l i z e ;

                                                    182
t _ a i P r edi ct i o n                      a i P r edi ct i o n ;
t_ ai Get Nu mb e rOfVa riabl es              ai Get Nu m berOf Vari ables;
t_ ai Get Nu mb e r OfM odelVecto r s         ai Get Nu m ber Of Mod el Vecto r s;
t_ ai Get Nu mb e rOfInput Variabl e s        ai Get Nu m berOf Inp utVari able s;
t _ a i S et Di s c re t e Fl ag              a i S e t Di s c r ete F l a g ;
t_ ai Get Di scret eFlag                      ai Get Di s cret eFl ag;
t _ a i S et Va ri a b l e                    ai S et Vari abl e;
t _ a i Get V a ri a b l e                    a i Get V a ri ab l e;
t_ ai Get Va ri abl eVB                       ai Get Va ri abl eVB ;
t_ ai GetC S VF il eModel S ize               ai GetC SVF il eModel Si ze;
// Ne w in vers ion 1 .24
t_ ai Set Cap acit y                          ai SetCap aci ty;
t_ ai GetC apac ity                           ai GetC apa city;
t_ ai Get Fre eEnt rie s                      ai Get Fre e Ent ri es;
t_ ai Ins e rtMod el Ve ct o r                ai Ins e rtMode l Ve cto r;
t_ ai Ove r wri t eM odel Vecto r             ai Ove r wri teModel Vector ;
t_ ai AppendMod el Ve ctor                    ai AppendM od el Vecto r;
t_ ai Del eteMod el Vecto r                   ai Del eteMod el Ve ct o r;
t_ ai Predi cti onEx                          ai Predi ct ionEx;
t_ aiEx cludeMod el Ve ctor                   aiEx clud eMo d el Ve cto r;
t_ aiEx cludeMod el Ve ctorR ange             aiEx clud eMo d el Ve cto rRang e;
t_ ai IsMo d el Ve cto r Ex cl ud ed          ai IsM od el Vecto r Ex clude d;
t_ ai Sav eC SVFil e                                    a i SaveC SVFi l e;

/*
 * ai net 32 .dl l module v ariabl e .
 */

HINSTANCE hLib;

/*
 * Th e lo ad_ ai Net Lib rary ( ) f un cti on i s i mpl e me nted b elo w.
 * Thi s f unct ion will loa d ain et3 2 .dl l and d ef in e point e rs to
 * ai net func tions .
 */

int l o ad_aiNe tLib r a ry (vo id );

/*
 *
 */


void main (voi d )
{

         int i , b ,e ,k ,j;
         int v er si on;

         aiM odel * m od el = NULL;                            // The ain et mod el v e ctors are sp e cifi ed
h e re
         aiM odel      * m od el w = NULL;
         aiM odel      * m od eld = NULL;
         aiM odel      * m od elc = NULL;
         aiM odel      * m od el wj = NULL;

         if( !load_ ai NetLi b ra ry () )
         {
                 exit (E XIT_FAILURE);
                                                      183
      }

      //Th e c r ack d at a are r e ad in belo w and th e sel e ct s tat em en ts are c re at ed f o r
      // th e d ata ba se .

         char bot t[90] = "SELECT MEASLENGHT,C UTLENGHT FR OM LENGHT WHER E
M E A S L E NGHT > ";
         char to ppp[20 ] = " AND M E ASLENGHT < ";
         int mid , top, b ott o m;
         cha r bot [10 ];
         cha r to pp[1 0 ];
         cout < < "Ent er Crack Le nght: ";
         cin > > mid;
         top = m id + ( mi d/5 );
         botto m = mid - (mid/5 );
         _ito a ( to p , topp , 10 );
         _ito a ( bot tom, b o t , 10 );
         st r cat ( bott , bo t );
         st rcat ( bott , t oppp );
         st rcat ( bott , t opp );

      cha r bot tc[80 ] = " SEL EC T C NC ,J OINE D FR OM C NC WHER E C NC > " ;
      char to pppc[15 ] = " AND C NC < ";
      int midc , top c, bot to mc;
      cha r bot c[10 ];
      cha r to ppc[10 ];
      cout < < "Ent er Cl osed Ne xt Crack : ";
      cin > > midc;
      top c = mid c + ( midc/2 );
      botto mc = mi d c - (midc /2 );
      _ito a ( to p c, t opp c, 10 );
      _ito a ( bot tomc , b otc , 10 );
      st rcat( bottc, botc);
      st rcat ( bott c, t oppp c);
      st rcat ( bott c, t oppc );

    char wbott w[80 ] = "SELEC T MEASW IDTH,CUTW IDTH FR OM W I DTH W HERE
MEASWIDT H > ";
    char wtopp pw[20 ] = " AND M E ASW IDT H < ";
    int mid w, t op w, bott o mw;
    cha r bot w[10 ];
    cha r to pp w[10 ];
    cout < < "\nEnt e r C ra ck wi dth: ";
    cin > > midw;
    top w = midw + (mid w/5 );
    botto m w = mi d w - (m i dw/5 );
    _ito a ( to p w, topp w, 10 );
    _ito a ( bot tomw, b ot w, 10 );
    st rcat ( wb ott w, bot w);
    st rcat ( wb ott w, wtopp pw);
    st r c a t ( wb o t t w , t o p p w);

      char wbott wj[80 ] = "SELECT MEASW IDTH,CUTW IDTH FROM WIDTHJOIN
W HER E MEASW IDT H > ";
      char wtopp pwj[20 ] = " AND MEASW I DTH < ";
      int top wj , bo tto mwj ;
      cha r bot wj [10 ];
      cha r to pp wj[10 ];
      top wj = midw + ( mid w/5 );
                                                    184
       botto m wj = m id w - ( mi dw/5 );
       _ito a ( to p wj, t opp wj , 10 );
       _ito a ( bot tomwj , bot wj , 10 );
       st r cat ( wb ott wj , bo t wj );
       st rcat ( wb ott wj , wt opppwj );
       st r cat ( wb ott wj , t opp wj );

     char bot td[80 ] = "SELECT MEASDE PTH,C UTDEPTH FROM DEPT H WHERE
MEASDEPTH > ";
     cha r to pppd[20 ] = " AND M E ASDEPTH < ";
     int midd , topd , bot to md;
     cha r bot d[1 0 ];
     cha r to ppd[10 ];
     cout < < "\nEnt e r C ra ck d epth: ";
     cin > > midd;
     topd = midd + (midd/ 2 );
     botto md = midd - (mi dd/ 2 );
     _ito a ( to pd , toppd , 10 );
     _ito a ( bot tomd , b otd , 10 );
     st rcat ( bottd, b otd );
     st rcat ( bottd, t opppd );
     st rcat ( bottd, t oppd );

       un signed   cha r   *i n st ruction wj = ((u nsign ed ch a r* )wbot t wj );
       un signed   cha r   *i n st ruction w = ((unsign ed cha r*)wbot t w);
       un signed   cha r   *i n st ructiond = ((un sign ed cha r* )bo ttd );
       un signed   cha r   *i n st ruction c = ((un si gn ed char* ) bott c);
       un signed   cha r   *i n st ruction = ((unsign ed cha r* )bot t );

       /*
        * Se arch for Lenght
        */

         re tcod e = SQL Al lo c Env (&h env );          / * En vi ron ment h and le */
         i f ( r et c o d e = = SQL _ S U C C E SS ) {
  re t co de = SQLAll o cConn ect (h env, & db con ); / * Conn ecti on h andl e */
  i f (r e t c o d e = = SQL _ S U C C E S S) {

     / * Set l ogin ti meout to 5 se cond s . */

     SQLSe tConne ct Opt ion (db con, SQL_ LOGIN_ TIMEOUT, 5 );

     / * C onn ect to d ata s ou rce */

       ret code = SQLConn ect (d b con , p szSQLDSN, SQL_ NTS, p s zSQLUs er, SQL_ NT S,
p sz SQ L P a s s w d , SQL _ NT S ) ;

                if (retcod e == SQL_ SUCCESS || retcode == SQL_ SUCCESS_ W ITH_ INFO){

        / * Pro cess d ata a fter su c ce s sful connecti on */
                   s t e am = f op en ( "d : \ \ n m\ \ c o n l e n .cs v " , " w " );
                   f p ri n t f (st e a m, "                                           ");
        re t cod e = SQLAllo c St mt (dbc on , &hst mt ); /* St at ement h andle */
        i f (ret cod e == SQL _ SUCC E SS) {
                                         r et cod e = SQL Ex ecDi rec t (hst mt ,i nst ru ction , S QL_ NT S);
                                         if (ret cod e == SQL_ SUC CE SS) {
                                                   wh il e ( TRUE ) {
                                                             ret cod e = SQL Fet ch (h st mt );


                                                      185
                                                           if (ret cod e == SQL_ ERR OR || re t cod e ==
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                     p ri ntf (" The re s a s tuffu p!" ) ;
                                                                     b reak;
                                                           }
                                                           if (ret cod e == SQL_ SUC CESS || re t code = =
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                     /* Get d ata f o r colu mn s 1 and 2 */
                                                                     /* Print th e ro w of d ata                   */
                                                                     SQL G e t D at a ( h st m t , 1 , S Q L _ C_ S HO RT ,
&measl , 0 , &me asl enght );
                                                                     SQL G e t D at a ( h st m t , 2 , S Q L _ C_ S HO RT ,
&cutl , 0 , &c utl enght );

                                                                     fp rint f(st eam, " \ n%d ,%d " , me asl , c utl );
                                                                     p ri ntf ("\ n %d , %d " , me as l , cutl ) ;

                                                                   c+ +;
                                                           } else {

                                                                     b reak;
                                                           }

                                                  }

                                         }
                                         S QL F r ee S tmt (h st mt , S QL_ DR OP);
           }
                                re wind (s te am );
                                fp rint f(st eam,"0 .15 ,0 ,0 ,%i , 2 ,0\nMl eng ,Cl eng\ n I ,O\ n", c );
                                fclose(steam);
                                p ri ntf ("\ n %i\n " , c);

                        SQLDisconn ect (d b con );
       }
       SQLFr e eC onn ect (db con );
   }
   S Q L Fr e e E n v ( h e n v );
         }

          /*
           * Se arch for C NC
           */

          re tcod e = SQL Al lo c Env (&h env );           / * En vi ron ment h and le */
          i f ( r et c o d e = = SQL _ S U C C E SS ) {
   re t co de = SQLAll o cConn ect (h env, & db co n ); / * Conn ecti on h andl e */
   i f (retcode == SQL_ SUCCESS) {

       / * Set l ogin ti meout to 5 se cond s . */

       SQLSe tConne ct Opt ion (db con, SQL_ LOGIN_ TIMEOUT, 5 );

       / * C onn ect to d ata s ou rce */

       ret code = SQLConn ect (d b con , p szSQLDSN, SQL_ NTS, p s zSQLUs er, SQL_ NT S,
p sz SQ L P a s s w d , SQL _ NT S ) ;

                     if (retcod e == SQL_ SUCCESS || retcode == SQL_ SUCCESS_ W ITH_ INFO){
                                                           186
           / * Pro cess d ata a fter su c ce s sful connecti on */
                      ct ea m = fo p en ( "d:\\ nm\\ con cnc .cs v" , " w" );
                      f p ri n t f (c t e a m ,"                                              " );
           re t cod e = SQLAllo c St mt (dbc on , &hst mt c); /* Stat eme nt h andle */
           i f (ret cod e == SQL _ SUCC E SS) {
                                             r et cod e = SQL Ex ecDi rec t (hst mt c,ins t ru ct ion c, SQL _ NT S );
                                             if (ret cod e == SQL_ SUC CE SS) {
                                                       wh il e ( TRUE ) {
                                                                 r et cod e = SQL F et ch (h st mt c );
                                                                 if (ret cod e == SQL_ ERR OR || re t cod e ==
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                           p ri ntf (" The re s a s tuffu p!" ) ;
                                                                           b reak;
                                                                 }
                                                                 if (ret cod e == SQL_ SUC CESS || re t code = =
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                           /* Get d ata f o r colu mn s 1 and 2 */
                                                                           /* Print th e ro w of d ata            */
                                                                           SQL Get Dat a( hst m tc , 1 ,
S QL _ C _ S HO R T , & m cn c , 0 , & me as c n c );
                                                                           SQL Get Dat a( hst m tc , 2 ,
S QL _ C _ S HO R T , & c u tj, 0 , & c u tjo in ) ;

                                                                     fp rint f ( ct eam , " \ n%d , %d " , mcn c, cutj );
                                                                     p ri ntf ("\ n %d , %d " , mc n c, cut j );

                                                                    cc++ ;
                                                            } else {

                                                                     b reak;
                                                            }

                                                  }

                                         }
                                         S QL F r ee S tmt (h st mt c , S QL _ DR OP) ;
           }
                                re wind (ct ea m);
                                fp rint f(ct eam ,"0 . 15 ,0 ,0 ,%i ,2 ,0\n C NC ,Joined\n I ,O\ n ", cc );
                                fclose(cteam);
                                p ri ntf ("\ n %i\n ",cc );

                        SQLDisconn ect (d b con );
       }
       SQLFr e eC onn ect (db con );
   }
   S Q L Fr e e E n v ( h e n v );
         }

          /*
           * Se arch for Wi dth
           */

          re tcod e = SQL Al lo c Env (&h env );          / * Env i ron ment h and le */
          i f ( r et c o d e = = SQL _ S U C C E SS ) {
   re t co de = SQLAll o cConn ect (h env, & db con ); / * Conn ecti on h andl e */
   i f (retcode == SQL_ SUCCESS) {


                                                            187
        / * Set l ogin ti meout to 5 se cond s . */

        SQLSe tConne ct Opt ion (db con, SQL_ LOGIN_ TIMEOUT, 5 );

        / * C onn ect to d ata s ou rce */

       ret code = SQLConn ect (d b con , p szSQLDSN, SQL_ NTS, p s zSQLUs er, SQL_ NT S,
p sz SQ L P a s s w d , SQL _ NT S ) ;

                      if (retcod e == SQL_ SUCCESS || retcode == SQL_ SUCCESS_ W ITH_ INFO){

            / * Pro cess d ata a fter su c ce s sful connecti on */

                            st r ea m = f op en ( "d:\\ nm\\ con wi d .cs v" , " w" );
                            fp rin t f ( st re a m, "                                            " );
           re t cod e = SQLAllo c St mt (dbc on , &hst mt w); /* St at em ent h andle */
           i f (ret cod e == SQL _ SUCC E SS) {
                                        r et cod e = SQL Ex ecDi rec t (hst mt w,in s t ruct ion w, S QL _ NTS ) ;
                                        if (ret cod e == SQL_ SUC CE SS) {
                                                   wh il e ( TRUE ) {
                                                             ret cod e = SQL Fet ch (h st mt );
                                                             if (ret cod e == SQL_ ERR OR || re t cod e ==
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                      p ri ntf (" The re s a s tuffu p!" ) ;
                                                                      b reak;
                                                             }
                                                             if (ret cod e == SQL_ SUC CESS || re t code = =
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                      /* Get d ata f o r colu mn s 1 and 2 */
                                                                      /* Print th e ro w of d ata            */
                                                                      SQL Get Dat a( hst m t w, 1,
S QL _ C _ S HO R T , & m e a s w , 0 , & m e a s wi d t h );
                                                                      SQL Get Dat a( hst m t w, 2,
SQL_ C_ SHORT, &cutw, 0 , & cut width );

                                                                         fp rint f ( st re am, " \ n%d , %d " , me as w,
c ut w );
                                                                         p ri n t f ("\ n % d , % d " , me a s w, cut w) ;

                                                                       w+ +;
                                                               } else {

                                                                         b reak;
                                                               }

                                                     }

                                           }
                                           S QL F r ee S tmt (h st mt w, S QL _ DR OP);
            }
                                 re wind (s t r ea m) ;
                                 fp rint f ( st re am, "0 .15 ,0 ,0 , %i , 2 ,0\ nWi d ,C W id\n I , O\n " , w);
                                 f c l o s e ( st re am );
                                 p ri ntf ("\ n %i\n ",w);
                                 SQLDisconn ect (d b con );
        }
        SQLFr e eC onn ect (db con );
    }
    S Q L Fr e e E n v ( h e n v );
                                                               188
             }

             /*
              * Se arch for Wi dthjoi n
              */

           re tcod e = SQL Al lo c Env (&h env );          / * En vi ron ment h and le */
           i f ( r et c o d e = = SQL _ S U C C E SS ) {
    re t co de = SQLAll o cConn ect (h env, & db con ); / * Conn ecti on h andl e */
    i f (retcode == SQL_ SUCCESS) {

        / * Set l ogin ti meout to 5 se cond s . */

        SQLSe tConne ct Opt ion (db con, SQL_ LOGIN_ TIMEOUT, 5 );

        / * C onn ect to d ata s ou rce */

       ret code = SQLConn ect (d b con , p szSQLDSN, SQL_ NTS, p s zSQLUs er, SQL_ NT S,
p sz SQ L P a s s w d , SQL _ NT S ) ;

                        if (ret cod e == SQL_ SUC CE SS || re t code = = SQL_ SUC CESS_ W IT H_ INFO){

                 / * Pro cess d ata a fter su c ce s sful connecti on */

                           st r e a mj = f o p e n ( "d: \ \ n m\ \ c o n wid j .cs v " , " w " );
                           fp rin t f ( st re a mj , "                                             ");
          re t cod e = SQLAllo c St mt (dbc on , &hst mt wj ); / * St ate men t h andle */
          i f (ret cod e == SQL _ SUCC E SS) {
                                       r et cod e = SQL Ex ecDi rec t (hst mt wj ,i n st ruction wj , SQL_ NT S);
                                       if (ret cod e == SQL_ SUC CE SS) {
                                                  wh il e ( TRUE ) {
                                                             r et cod e = SQL Fet ch (h st mt wj );
                                                             if (ret cod e == SQL_ ERR OR || re t cod e ==
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                        p ri ntf (" The re s a s tuffu p!" ) ;
                                                                        b reak;
                                                             }
                                                             if (ret cod e == SQL_ SUC CESS || re t code = =
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                        /* Get d ata f o r colu mn s 1 and 2 */
                                                                        /* Print th e ro w of d ata            */
                                                                        SQL Get Dat a( hst m t wj , 1 ,
SQL_ C_ SHOR T, &measwj , 0 , & meas widthj );
                                                                        SQL Get Dat a( hst m t wj , 2 ,
SQL_ C_ SHORT, &cutwj , 0 , &cutwidt hj );

                                                                    fp rint f ( st re amj , " \ n%d ,%d " , me a s wj ,
c ut wj );
                                                                    p ri ntf ("\ n %d , %d " , me as wj , cut wj ) ;

                                                                   wj ++ ;
                                                           } else {

                                                                    b reak;
                                                           }

                                                  }

                                         }
                                                           189
                                         S QL F r ee S tmt (h st mt wj , SQL _ DR OP) ;
           }
                                re wind (s t rea mj );
                                fp rint f(st re amj ,"0 .15 ,0 ,0 ,%i ,2 ,0\nWid ,CWid\n I ,O\ n ", wj );
                                f c l o s e ( st re am j );
                                p ri ntf ("\ n %i\n ",wj );
                                SQLDisconn ect (d b con );
       }
       SQLFr e eC onn ect (db con );
   }
   S Q L Fr e e E n v ( h e n v );
         }



          /*
           * Se arch for Depth
           */


          re tcod e = SQL Al lo c Env (&h env );          / * En vi ron ment h and le */
          i f ( r et c o d e = = SQL _ S U C C E SS ) {
   re t co de = SQLAll o cConn ect (h env, & db con ); / * Conn ecti on h andl e */
   i f (retcode == SQL_ SUCCESS) {

       / * Set l ogin ti meout to 5 se cond s . */

       SQLSe tConne ct Opt ion (db con, SQL_ LOGIN_ TIMEOUT, 5 );

       / * C onn ect to d ata s ou rce */

       re t code = SQLConn ect (db con , p szSQLDSN, SQL_ NTS, p s z SQL Us er, SQL_ NT S,
p sz SQ L P a s s w d , SQL _ NT S ) ;

                     if (retcod e == SQL_ SUCCESS || retcode == SQL_ SUCCESS_ W ITH_ INFO){

           / * Pro cess d ata a fter su c ce s sful connecti on */

                                t ea m = f op en ( "d:\\ n m\\ con dep . c sv", " w" ) ;
                       f p r i n t f (t e a m ,"                                            ");
           re t cod e = SQLAllo c St mt (dbc on , &hst mt d ); / * St atemen t h andl e */
           i f (ret cod e == SQL _ SUCC E SS) {
                                             ret cod e = SQLEx ecDi rec t (hst mt d ,i nst r uctiond , SQL_ NT S) ;
                                             if (ret cod e == SQL_ SUC CE SS) {
                                                      wh il e ( TRUE ) {
                                                                r et cod e = SQL F et ch (h st mtd );
                                                                if (ret cod e == SQL_ ERR OR || re t cod e ==
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                          p ri ntf (" The re s a s tuffu p!" ) ;
                                                                          b reak;
                                                                }
                                                                if (ret cod e == SQL_ SUC CESS || re t code = =
S QL _ S UC C E SS _ W IT H_ I N FO ) {
                                                                          /* Get d ata f o r colu mn s 1 and 2 */
                                                                          /* Print th e ro w of d ata            */
                                                                          SQL Get Dat a( hst m td , 1 ,
S QL _ C _ S HO R T , & m e a s d , 0 , & me as d ept h );
                                                                          SQL Get Dat a( hst m td , 2 ,
SQL_ C_ SHORT, &cutd, 0 , &cutd epth );
                                                           190
                                                                         fp rint f ( te a m, " \n %d , %d", me a s d , cutd );
                                                                         p ri n t f ("\ n % d , % d " , me a s d , cu t d ) ;

                                                                      d++;
                                                              } else {

                                                                         b reak;
                                                              }

                                                     }

                                            }
                                            SQLFree Stmt (h st mtd , SQL_ DR OP);
             }
                                   re wind (t eam);
                                   fp rint f(te a m,"0 .15 ,0 ,0 ,%i ,2 ,0\nMde pth ,CDepth\ n I ,O\ n", d );
                                   f clos e (t eam );
                                   p ri ntf ("\ n %i\n " ,d );

                         SQLDisconn ect (d b con );
        }
        SQLFr e eC onn ect (db con );
    }
    S Q L Fr e e E n v ( h e n v );

           /*
            * Cal culat e Lenght
            */

           const ch a r *fluffy;
           fl uffy = "d:\\ n m\\ conl en.c sv ";

           fl o at p r edict[1 ][ 2 ] = { { mi d ,99 9}};         /* v e ct o rs to b e p r edi cted */


           v ersio n = aiGe t Versi on ();
           p ri ntf ( "\n aiNe t DLL v e rsion %i .%i ! (C) Copy right by ai Net , 1996", v ersion/1 00 ,
v e rs ion %100 );
           p ri n t f ( "\n - - - -- - -- - - - - - - -- - - -- - -- - - -- - - - - - - -- - -- - - -- - - -- - -- - - \ n " );
           aiRegi st ration ( "h axi s ", "lp c9kdj uc9 " );

           mod el = aiC r eat eMod elFro m C S VFil e( fl uf f y ); / /Model creat ed

           if(!model) {
                  p rintf ( "\n Erro r: So mething went wrong du ring mo del cre ati on !" );
                  exit (E XIT_FAILURE);
           }

           p ri ntf (     "\n           M ode l n a me: aiNet DL L t est 1 ( %8 s ) " , f luffy ) ;
           p ri ntf (     "\n Nu mb er o f mod el v ect o rs : %i " , ai GetNu mb er Of Mod el Ve ct o rs (m od el ));
           p ri ntf (     "\n Nu m be r of v a riabl e s: %i " , ai Get Nu mb er Of Vari able s ( mod el ) );
           p ri ntf (     "\n       Va ri ab le n a mes: Me asu redLenght Cut L enght " );
           p ri n t f (   "\n        D i s c r et e fl ag: % i ,           % i ",
                                   ai Get Di s cre te Flag ( mod el ,1 ) ,
                                   ai Get Di s cre te Flag ( mod el ,2 ) );

           cout < < "\n";


                                                              191
/*
 * No rm al ize th e mod el
 */

ai No rmali ze(mod el , NOR M AL I ZE_RE GUL AR );

p ri ntf ( "\n\ n Pe n alty coeffi cient: 0 .35 " );
p ri ntf ( "\n         Pe n alt y met hod: nea rest " );
p ri ntf ( "\n\ t Ml enght , Cl eng ht " );
fo r ( i= 0; i<1; i+ + ) {
           a i Prediction (m od el , p r edi ct[i ] , 0 .5 , PE NAL T Y_NE AR E ST );
           p rintf ( "\n\t%7 .4lf , %7 .4l f", p redic t[i ][0 ],p redi ct [i ][1 ]);
}

/*
 * Deno r mali ze t he mod el (in thi s cas e it i s not n ece ss a ry )
 */

ai Deno rmaliz e (model );
cout < < "\n";
ai Del eteMod el ( mod el );

/*
 * C NC C alc u lati o n
 */

const ch a r *fluffy c;
fl uff y c = "d: \\n m\\ concn c. csv ";

fl o at p redict c[1 ][2 ] = { { mi dc ,999}};           / * ve cto rs t o b e p re dict ed */

mod el c = aiC r eat eM odel Fro mC SVFil e ( f luf f yc ) ;

if(!modelc) {
       p rintf ( "\n Erro r: So mething went wrong du ring mo del cre ati on !" );
       exit (E XIT_FAILURE);
}

p ri ntf (     "\n           M ode l n a me: aiNet DL L t es t 1 ( %8 s ) " , f luffy c );
p ri ntf (     "\n Nu mb er o f mod el v ect o rs : %i " , ai GetNu mb er Of Mod el Ve ct o rs (m od el c) );
p ri ntf (     "\n Nu m be r of v a riabl e s: %i " , ai Get Nu mb er Of Vari able s ( mod el c ) );
p ri ntf (     "\n       Va ri ab le n a mes: CNC Join ed" );
p ri n t f (   "\n        D i s c r et e fl ag: % i , %i",
                        ai Get Di s cre te Flag ( mod elc ,1 ) ,
                        ai Get Di s cre te Flag ( mod elc ,2 ) );

cout < < "\n";
        /*
 * No rm al ize th e mod el
 */

ai No rmali ze(mod el , NOR M AL I ZE_RE GUL AR );


p ri ntf ( "\n\ n Pe n alty coeffi cient: 0 .01 " );
p ri ntf ( "\n        Pe n alt y met hod: nea rest " );
p ri ntf ( " \n\ t C NC , J oi n ed" ) ;
fo r ( k=0 ; k< 1; k++ ) {
           a i Prediction (m od el c, p re dict c[ k ], 0 .01 , PE NALT Y_ NE AR EST ) ;
                                                   192
               p rintf ( "\n\t%7 . 4lf ,   %7 .4l f", p redic tc[k ][0 ],p re dict c[k ][1 ]);
}

/*
 * Deno r mali ze t he mod el (in thi s cas e it i s not n ece ss a ry )
 */

ai Deno rmaliz e (model c);
cout < < "\n";
ai Del eteMod el ( mod elc );



/*
 * Wi dth Cal culation
 */

const ch a r *fluffy w;
fl uffy w = "d:\\ n m\\ conwid .csv ";

fl o at p redict w[1 ][2 ] = { { mi d w,999} };           /* vecto rs to b e p re dict ed */

mod el w = aiC reat eModel Fro m C SVFil e( fl uf f y w );

if(!modelw) {
       p rintf ( "\n Erro r: So mething went wrong du ring mo del cre ati on !" );
       exit (E XIT_FAILURE);
}

p ri ntf (     "\n           M ode l n a me: aiNet DL L t est 1 ( %8 s ) " , f luffy w);
p ri ntf (     "\n Nu mb er o f mod el v ect o rs : %i " , ai GetNu mb er Of Mod el Ve ct o rs (m od el w) );
p ri ntf (     "\n Nu m be r of v a riabl e s: %i " , ai Get Nu mb er Of Vari able s ( mod el w));
p ri ntf (     "\n       Va r i ab le n a mes: Me asu r edW idth CutW idt h " );
p ri n t f (   "\n        D i s c r et e fl ag: % i ,          % i ",
                        ai Get Di s cre te Flag ( mod el w,1 ),
                        ai Get Di s cre te Flag ( mod el w,2 ));

cout < < "\n";
        /*
 * No rm al ize th e mod el
 */

ai No rmali ze(mod el w,NOR M ALIZE_REGULAR);

          p rintf ( " \n\n Pe n al ty coe ff i cient: 0 . 50 " );
p ri ntf ( "\n         Pe n alt y met hod: nea rest " );
p ri ntf ( "\n\ t MWidth , C W idt h" );
fo r ( b=0 ; b< 1; b++ ) {
          a i Prediction (m od el w, p redict w[ b ] , 0.5 , PE NAL TY_ NE ARE ST );
          p rintf ( " \n\t%7 . 4lf , %7 .4l f " , p r edic t w[ b ][ 0 ] , p re dict w[ b ] [1] ) ;
}


/*
 * Deno r mali ze t he mod el (in thi s cas e it i s not n ece ss a ry )
 */

ai Deno rmaliz e (model w);
cout < < "\n";
                                                    193
ai Del eteMod el ( mod el w) ;

/*
 * Wi dthjoin ed Cal cul ati on
 */

const ch a r *fluffy wj;
fl uffy wj = "d:\ \n m\ \ con wi dj .csv ";

fl o at p r edict wj[ 1 ][2 ] = { { m id w,99 9 }};        /* vect o rs to b e p r edict ed * /

mod el wj = ai C r eat eMode l F ro mC S VFi l e( fl uffywj );

i f ( ! mo d e l wj ) {
            p rintf ( "\n Erro r: So mething went wrong du ring mo del cre ati on !" );
            exit (E XIT_FAILURE);
}

p ri ntf (     "\n           M ode l n a me: aiNet DL L t est 1 ( %8 s ) " , f luffy wj ) ;
p ri ntf (     "\n Nu mb er o f mod el v ect o rs : %i " , ai GetNu mb er Of Mod el Ve ct o rs (m od el wj ) );
p ri ntf (     "\n Nu m be r of v a riabl e s: %i " , ai Get Nu mb er Of Vari able s ( mod el wj ) );
p ri ntf (     "\n       Va r i ab le n a mes: Me asu r edW idth CutW idt h " );
p ri n t f (   "\n        D i s c r et e fl ag: % i ,          % i ",
                        ai Get Di s cre te Flag ( mod el wj ,1 ) ,
                        ai Get Di s cre te Flag ( mod el wj ,2 ) );


cout < < "\n";
        /*
 * No rm al ize th e mod el
 */

ai No rmali ze(mod el wj , NORM AL I ZE_RE GUL AR );

p ri ntf ( "\n\ n Pe n alty coeffi cient: 0 .50 " );
p ri ntf ( "\n          Pe n alt y met hod: nea rest " );
p ri ntf ( "\n\ t MWidth , C W idt h" );
fo r ( j= 0; j<1; j+ + ) {
           a i Prediction (m od el wj , predi ct wj [ j ] , 0 .5 , PE NALT Y_ NE AREST );
           p rintf ( " \n\t%7 . 4lf , %7 .4l f " , p r edic t wj[j ][ 0 ], predi ct wj [ j ][1 ] );
}


/*
 * Deno r mali ze t he mod el (in thi s cas e it i s not n ece ss a ry )
 */

ai Deno rmaliz e (model wj);
cout < < "\n";
ai Del eteMod el ( mod el wj );

/*
 * Dept h C al cul at ion
 */

const ch a r *fluffyd;
fl uffyd = "d:\\ n m\\ cond ep .csv ";

fl o at p redictd[1 ][2 ] = { { mi dd ,999}};            / * ve cto rs t o b e p re dict ed */
                                                   194
mod eld = aiC reat eModel F ro mC S VFi l e( fl uf fyd ) ;

if(!modeld) {
       p rintf ( "\n Erro r: So mething went wrong du ring mo del cre ati on !" );
       exit (E XIT_FAILURE);
}

p ri ntf (     "\n           M ode l n a me: aiNet DL L t est 1 ( %8 s ) " , f luffyd ) ;
p ri ntf (     "\n Nu mb er o f mod el v ect o rs : %i " , ai GetNu mb er Of Mod el Ve ct o rs (m od el d ));
p ri ntf (     "\n Nu m be r of v a riabl e s: %i " , ai Get Nu mb er Of Vari able s ( mod eld ) );
p ri ntf (     "\n       Va r i ab le n a mes: Me asu r ed Depth C ut Dept h" ) ;
p ri n t f (   "\n        D i s c r et e fl ag: % i ,          % i ",
                        ai Get Di s cre te Flag ( mod eld ,1 ) ,
                        ai Get Di s cre te Flag ( mod eld ,2 ) );


cout < < "\n";
        /*
 * No rm al ize th e mod el
 */

ai No r mali ze( mod eld , NORM AL I ZE_RE GUL AR );

p ri ntf ( "\n\ n Pe n alty coeffi cient: 0 .50 " );
p ri ntf ( "\n         Pe n alt y met hod: nea rest " );
p ri ntf ( " \n\ t M Dept h , C Dep th " );
fo r ( e=0; e<1; e++ ) {
           a i Pr ediction (m od el d , p redi ct d[ e ] , 0 .1 , PE NALTY_ NE ARE ST );
           p rintf ( "\n\t%7 . 4lf , %7 .4l f ", p r edic td[e][0 ],p re dictd[ e][1 ] );
}

/*
 * Deno r mali ze t he mod el (in thi s cas e it i s not n ece ss a ry )
 */

ai Deno rmaliz e (modeld );
cout < < "\n";
ai Del eteMod el ( mod eld );
p ri ntf ( "\n\ n\t%7 . 4lf , %7 .4lf ", p r edi ct[0 ][0 ],p re dict [ 0 ][1 ]);
p ri ntf ( "\n\ t%7 .4l f , % 7 .4lf " , p r edi ct w[ 0 ][0 ], p red ict w[0 ] [ 1] );
p ri ntf ( "\n\ t%7 .4l f , % 7 .4lf " , p r edi ctd [0 ][0 ] ,p re dictd[0 ][ 1 ]);
p ri ntf ( "\n\ t%7 .4l f , % 7 .4lf " , p r edi ctc[ 0 ] [0 ] ,p redi ct c[ 0 ][1 ] ) ;
p ri ntf ( "\n\ t%7 .4l f , % 7 .4lf " , p r edi ct wj [0 ][ 0 ] ,pre dict wj [ 0 ][1 ] );
fl o at l enght , d ept h , width , volu me;
l en ght = p redi ct[0 ][1 ];
d ept h = p r edi ctd[ 0 ][1 ];
fl o at s wit = p redict c[0 ][1 ];
if ( s wi t < 0 .3 )
{
            widt h = p r edi ct w[ 0 ][1 ];
}
els e
{
            widt h = p r edi ct wj[0 ][1 ];
}
volu me = (l enght * width * dep th )/1000;
p ri ntf ("\n Volu me i s : %7 .4lf cm^3 ", vol u me );
Free Lib r a ry(h Li b );
                                                   195
}

}
int l o ad_aiNe tLib r a ry ()
{
  /*
   * L o ad th e Dyn ami c Li nk Lib ra ry AI NET32 . DL L
   */

    h Lib = LoadLi b r ary ( ai n et Dl l );
    i f ((un si gne d )hLi b<= HINSTANCE_ERR OR){
         c h a r b f r[40 ];
         wsp rin tf(bf r, "Fa il ure lo ading lib ra ry: %s", a inet Dll );
         M es s ag e B o x ( N U L L , b f r , " E rro r" , M B _ O K |M B _ A P PL M ODAL ) ;
         r e t u rn 0 ;
    }

    /*
     * Get all th e ent ry point s f o r t h e f un ctions in ai n et 32 .d ll
     */

  a i R e g i st rat i o n                          = (t _ ai R e g i st r a t i o n )
           Ge t Pro cAddre ss(hLib , "a iR egi st ration " );
  a i Get V e r sio n                               = (t _ ai Ge t Ve r si o n )
           Ge t P ro cAddr e s s (hLib , " a i Get Ve rsi on " );
  ai C reateModel                                   = (t _ ai C reateMod el )
           Ge t Pro cAddre ss(hLib , "a iC re ateMod el");
  ai C r eateModel Fro mC SVFi le                   = (t _ ai C reateMod el Fro mC SVFi le)
Ge t Pro c Address (hLi b , "ai C reateMod el Fro mC SVFil e " );
  ai Del eteModel                                   = (t _ ai Del eteMod el )
           Ge t Pro cAddre ss(hLib , "a i Del eteMod el");
  a i No r m al i z e                               = (t _ ai No r mal i z e )
           Ge t Pro cAddre ss(hLib , "a i No rmaliz e");
  a i Den o r ma l i z e                            = (t _ ai De n o r ma l i z e )
           Ge t Pro cAddre ss(hLib , "a i Deno rmaliz e");
  a i Pre d i c t i o n                             = (t _ ai P r ed i c t i o n )
           Ge t Pro cAddre ss(hLib , "a i Predicti on");
  a i Get Nu m b e r Of Va ri a b l e s             = (t _ ai Ge t Nu mb e r Of V a ri a b l e s )
           Ge t Pro cAddre s s (hLib , " a i Get Nu mberOfVa ri ables " );
  ai Get Nu m b er Of ModelVe ct o rs               = (t _ ai Get Nu mb erOfMod el Ve ct o rs )
           Ge t Pro cAddre ss(hLib , "a i Get Nu mberOfM od el Vecto rs");
  ai Get Nu m b erOf InputVa ri abl es              =
(t_ ai Get Numb e rOfInput Va riabl e s)Get Pro cAddre ss(hLib ,
"ai Get Nu mbe rOf Input Va riabl e s");
  a i Se t Di s c r e t e F l a g                   = (t _ ai S e t Dis c r et eFl a g )
           Ge t P ro cAddre s s (hLib , " a i S et Dis c rete Fl ag" );
  a i Get Di scr e t e Fl a g                       = (t _ ai Ge t Di s c r e t e Fl a g )
           Ge t P ro cAddre s s (hLib , " a i Get Di sc r et eFl ag" );
  a i Se t Va ri a b l e                            = (t _ ai S e t Var i a b l e )
           Ge t P ro cAddre s s (hLib , " a i S et Vari abl e" );
  ai Get Va ria ble                                 = (t _ ai Get Va r iabl e)
           Ge t P ro cAddr e s s (hLib , " a i Get Va ri abl e" );
  a i Get V a ri a b l e VB                         = (t _ ai Ge t Va r i a b l e VB )
           Ge t P ro cAddr e s s (hLib , " a i Get Va ri abl e VB" );
  ai GetC SVF il eModel S iz e                      = (t _ ai GetC SVFi leMode l Si ze)
           Ge t P ro cAddre s s (hLib , " a i GetC S VFi l eModel Si ze " );
  ai Se tCapacity                                   = (t _ ai S e t C a p a ci t y )
           Ge t P ro cAddr e s s (hLib , " a i S et Cap acit y " );
                                                             196
  a i Get C ap a c i t y                          = (t _ ai Ge t C a p a c i t y )
           Ge t Pro cAddre ss(hLib , "a i GetCapa ci ty ");
  a i Get F r e e E n t r i e s                   = (t _ ai Ge t F r e e E n t ri e s )
           Ge t Pro cAddre ss(hLib , "a i Get Fre e Ent ri es");
  a i Ins ertM o d el Ve c t o r                  = (t _ ai In s e rt M o d el V e c t o r )
           Ge t Pro cAddre ss(hLib , "a i Inse rtMode l Ve ct o r");
  ai Ov erwrit eModel Vect o r                    = (t _ ai Ove r wri t eModelVe cto r )
           Ge t Pro cAddre ss(hLib , "a i Ove rwrit eM odel Vector");
  ai Ap pendM odel Vector                         = (t _ ai App endM odel Vec to r)
           Ge t Pro cAddre ss(hLib , "a i AppendMod el Ve cto r");
  ai DeleteModelVector                            = (t _ ai Del eteMod el Vect o r)
           Ge t Pro cAddre ss(hLib , "a i Del eteMod el Vecto r");
  ai Pred ictionEx                                = (t _ ai Pred ict ionEx )
           Ge t Pro cAddre ss(hLib , "a i Predicti onEx " );
  a i E x cl u d eM o d el Ve c t o r             = (t _ ai E x cl u d eM o d el Ve c t o r )
           Ge t Pro cAddre ss(hLib , "a iEx cludeMod el Ve cto r");
  ai Ex cl udeM odel VectorRange                  = (t _ ai Ex cl ud eM odel Vecto rRang e )
Ge t Pro c Address (hLi b , "ai Ex cl udeMod el Vecto rRang e " );
  ai Is Mod elVecto r Ex clud ed                  = (t _ ai IsM od el Vecto r Ex cluded )
           Ge t Pro cAddre ss(hLib , "a i IsMod el Ve cto rEx cl ude d");
  a i Sa v eC SV F i l e                          = (t _ ai S a v eC SVF i l e )
           Ge t P ro cAddre s s (hLib , " a i S aveC SVF il e " );

  /*
    * G e t Pr o c A d d re s s r et u rn s n u l l o n f ai l u r e
    */
  i f ( aiR egist rati on = = NUL L
        || ai GetVersion == NULL
        || aiC rea teMod el == NULL
        || aiC rea teModelFro mC SVFile == NULL
        || ai DeleteMod el == NULL
        || ai Normali ze == NULL
        || ai Deno rmali ze = = NULL
        || ai Predi ct ion == NULL
        || ai GetNu mb erOf Variabl es == NULL
        || ai GetNu mb erOfMod el Vecto rs == NULL
        || ai GetNu mb erOf Inp ut Variables == NULL
        | | a i S e t D i sc r et e Fl a g = = NUL L
        || ai GetDi s cret eFl ag == NULL
        || ai SetVariabl e == NULL
        || ai GetVari abl e == NULL
        || ai GetVari abl eVB = = NULL
        || ai GetC SVFileMod el Si ze == NULL
                           || a i Set C apacit y = = NULL
        || ai GetCap acity == NULL
        || ai GetFreeEnt ri es = = NULL
        || ai In se rtModel Vect o r = = NULL
        || ai Overwri t eMode l Vecto r == NULL
        || ai App endM odel Vecto r = = NULL
        || ai DeleteMod el Vect o r == NULL
        || ai Predi ct ionEx == NULL
        || ai Exclud eMo d elVecto r = = NULL
        || ai Exc lud eMo d elVe cto rRange = = NUL L
        || ai IsM odel VectorExclud ed = = NULL
        || ai SaveC SVFil e = = NULL ) {
                          Me s sag eBox ( NULL , " Fa ilu re l ocati ng p ro c edu re s . " , " E r ro r " ,
               M B _ O K |M B _ APPL M O D AL ) ;
       r e t u rn 0 ;
             }
                                                              197
    re t u rn 1;
}




                   198

				
DOCUMENT INFO