Beispiel #1
0
static inline void creatUnit(IPackage&p,IConnection*c)
{
        uint32 subnet;
        uint16 numunits;
        SUnit unit,ounit;
        p>>subnet>>numunits;
        IPackage op("set");
        op<<QString("create unit");
        op<<subnet<<numunits;
        int num,err;
        //yet no check for subnet/layer defined, SNNS itself gives damn
        //buffer for string ops:
        char buf[256];
        //create units
        for(int i=0;i<numunits;i++){
                getUnit(unit,p);
                ounit=unit;
                num=krui_createDefaultUnit();
                if(num<0){//error
                        ounit.mask=UERR;
                        ounit.errcode=(QString)krui_error(-num);
                        setUnit(ounit,op);
                        //proceed with next unit
                        continue;
                }else{//success
                        ounit.mask|=UNUM;
                        ounit.id=num;
                }
                //subnet/layer
                krui_setUnitLayerNo(num,subnet&0xffff);
                int subn=(subnet>>16)&0xffff;
                subn-=32736;
                krui_setUnitSubnetNo(num,subn);
                //name
                if(unit.mask&UNAME){
                        err=krui_setUnitName(num,CHR(buf,unit.name));
                        if(err){
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                        }
                }
                //output function
                if(unit.mask&UOUTF){
                        err=krui_setUnitOutFunc(num,CHR(buf,unit.outfunc));
                        if(err){
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                        }
                }//must be for error and nomask, doesn't hurt anyway
                ounit.mask|=UOUTF;
                ounit.outfunc=krui_getUnitOutFuncName(num);
                //activation function
                if(unit.mask&UACTF){
                        err=krui_setUnitActFunc(num,CHR(buf,unit.actfunc));
                        if(err){
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                        }
                }
                ounit.mask|=UACTF;
                ounit.actfunc=krui_getUnitActFuncName(num);
                //initial activation
                if(unit.mask&UIACT)
                        krui_setUnitInitialActivation(num,unit.iact);
                //activation
                if(unit.mask&UACT)
                        krui_setUnitActivation(num,unit.act);
                //bias
                if(unit.mask&UBIAS)
                        krui_setUnitBias(num,unit.bias);
                //prototype
                if(unit.mask&UPROTO){
                        err=krui_setUnitFType(num,CHR(buf,unit.prototype));
                        if(err){
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                                ounit.prototype=(char*)0;
                                //take this as non-fatal and proceed
                        }
                }
                //position
                if(unit.mask&UPOS){
                        struct PosType pos;
                        pos.x=unit.xpos;
                        pos.y=unit.ypos;
                        pos.z=unit.zpos;
                        krui_setUnitPosition(num,&pos);
                        //the above doesn't transport errors, so ...
                        krui_getUnitPosition(num,&pos);
                        ounit.xpos=pos.x;
                        ounit.ypos=pos.y;
                        ounit.zpos=pos.z;
                }else {
                        struct PosType pos;
                        ounit.mask|=UPOS;
                        krui_getUnitPosition(num,&pos);
                        ounit.xpos=pos.x;
                        ounit.ypos=pos.y;
                        ounit.zpos=pos.z;
                }
                //send back
                setUnit(ounit,op);
        }
        c->send(op);
}
Beispiel #2
0
/*****************************************************************************
  FUNCTION : bn_artmap_make_layer

  PURPOSE  : make a complete layer
  NOTES    :

  UPDATE   : 20.1.1993
******************************************************************************/
krui_err SnnsCLib::bn_artmap_make_layer (int  units, int  rows, int  cols, 
				      int  Xbegin, int  Ybegin,
				      char *name_prefix, int  unit_ttype, 
				      char *actfuncname, char *outfuncname,
				      int  NoOfSites, char **SiteNames,
				      char **SiteFuncNames)

{
   krui_err             ret_code = KRERR_NO_ERROR;

   int                  row;
   int                  col;
   int                  count;
   int                  last_col;
   int                  unit_no;
   struct PosType       unit_pos;
   char                 *site_name, *site_func_name;
   int                  site_no;
   char                 name[100];

   unit_pos.z = 0;

   /* Create Site Table Entries */
   site_no = 1;
   while (site_no <= NoOfSites) {
      site_name= *(SiteNames+(site_no-1));
      site_func_name= *(SiteFuncNames+(site_no-1));

      if ((site_name != NULL) && (site_func_name != NULL)) {
         ret_code = krui_createSiteTableEntry(site_name, site_func_name);
         CHECK_RETURN (ret_code);
      } /*if*/

      site_no++;
   }  /*while*/

   /* Create Units */
   for (row = 1, count = 0; row <= rows; row++) {

      if ((units % rows) > 0) {
         last_col = POS_SIGN((units-count) % (rows-row+1));
      } else {
         last_col = 1;
      } /*if*/

      for (col = 1; col <= (cols-1+last_col); col++) {

         count++;

         unit_no = krui_createDefaultUnit();
         if (unit_no < 0)  CHECK_RETURN (unit_no);

         ret_code = krui_setUnitTType (unit_no, unit_ttype);
         CHECK_RETURN( ret_code );

         ret_code = krui_setUnitActFunc(unit_no, actfuncname);
         CHECK_RETURN (ret_code);

         ret_code = krui_setUnitOutFunc(unit_no, outfuncname);
         CHECK_RETURN (ret_code);

         if (units > 1) {
            sprintf (name,"%s%d",name_prefix,count);
         } else {
            sprintf (name,"%s",name_prefix);
         } /*if*/

         ret_code = krui_setUnitName (unit_no, name);
         CHECK_RETURN (ret_code);

         unit_pos.x = Xbegin + col - 1;
         unit_pos.y = Ybegin + row - 1;
         krui_setUnitPosition( unit_no, &unit_pos );

         ret_code = krui_setCurrentUnit (unit_no);
         CHECK_RETURN (ret_code);

         /* Add Sites */
         site_no = 1;
         while (site_no <= NoOfSites) {
             site_name= *(SiteNames+(site_no-1));

             if (site_name != NULL) {
                ret_code = krui_addSite (site_name);
                CHECK_RETURN (ret_code);
             } /*if*/

             site_no++;
         } /*while*/

      } /*for*/

   } /*for*/

   return (ret_code);
} 
Beispiel #3
0
static inline void modifUnit(IPackage&p,IConnection*c)
{
        uint32 subnet;
        uint16 numunits;
        int err;
        SUnit unit,ounit;
        IPackage op("set");
        op<<QString("modify unit");
        op<<subnet<<numunits;
        char buf[256];
        for(int i=0;i<numunits;i++){
                getUnit(unit,p);
                ounit=unit;
                //check for existance
                if(!(unit.mask&UNUM)){
                      int num=krui_createDefaultUnit();
                      if(num<0){
                              ounit.errcode="Unable to create unit.";
                              setUnit(ounit,op);
                              continue;
                      }
                      unit.id=ounit.id=num;
                }
                if(unit.id==0||unit.id>krui_getNoOfUnits()){
                        ounit.mask=UERR|UNUM;
                        ounit.errcode="Unit doesn't exist.";
                        setUnit(ounit,op);
                        continue;
                }
                //prototype
                if(unit.mask&UPROTO){
                        err=krui_setUnitFType(unit.id,CHR(buf,unit.prototype));
                        if(err){
                                ounit.prototype=krui_getUnitFTypeName(unit.id);
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                        }
                }
                //position
                if(unit.mask&UPOS){
                        PosType pos;
                        pos.x=unit.xpos;
                        pos.y=unit.ypos;
                        pos.z=unit.zpos;
                        krui_setUnitPosition(unit.id,&pos);
                        krui_getUnitPosition(unit.id,&pos);
                        ounit.xpos=pos.x;
                        ounit.ypos=pos.y;
                        ounit.zpos=pos.z;
                }
                //bias
                if(unit.mask&UBIAS){
                        krui_setUnitBias(unit.id,unit.bias);
                }
                //i_activation
                if(unit.mask&UIACT){
                        krui_setUnitInitialActivation(unit.id,unit.iact);
                }
                //activation
                if(unit.mask&UACT){
                        err=krui_setUnitActivation(unit.id,unit.act);
                        if(err){
                                ounit.act=krui_getUnitActivation(unit.id);
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                        }
                }
                //actfunc
                if(unit.mask&UACTF){
                        err=krui_setUnitActFunc(unit.id,CHR(buf,unit.actfunc));
                        if(err){
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                                ounit.actfunc=krui_getUnitActFuncName(unit.id);
                        }
                }
                //outfunc
                if(unit.mask&UOUTF){
                        err=krui_setUnitOutFunc(unit.id,CHR(buf,unit.outfunc));
                        if(err){
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                                ounit.outfunc=krui_getUnitOutFuncName(unit.id);
                        }
                }
                //name
                if(unit.mask&UNAME){
                        err=krui_setUnitName(unit.id,CHR(buf,unit.name));
                        if(err){
                                ounit.mask|=UERR;
                                ounit.errcode=krui_error(err);
                                ounit.name=krui_getUnitName(unit.id);
                        }
                }
                //store
                setUnit(ounit,op);
        }
        c->send(op);
}