Example #1
0
 void R_load_XGAPnames(char **filename,int* num_rows,int* num_cols,int* pos, char** rownames, char** colnames){
   rawfilestruct binfile;
   if(parsefile(filename[0],&binfile)){    
     uint newpos = (*pos);
     uint ncols = (*num_cols);
     uint nrows = (*num_rows);      
     uint *collengths,*rowlengths;
     collengths = getlengths(binfile,newpos,*num_cols);
     newpos = newpos+ (*num_cols);
     rowlengths = getlengths(binfile,newpos,*num_rows);
     newpos = newpos+ (*num_rows);
     cmatrix cname;
     cmatrix rname;
     newpos = newpos + getnames(&cname,binfile,newpos,*num_cols,collengths);
     newpos = newpos + getnames(&rname,binfile,newpos,*num_rows,rowlengths);
     //Rprintf("Parsed Flenames\n");
     for(uint r=0;r<nrows;r++){
       //Rprintf("%d->%s\n",r,rname[r]);
       rownames[r] = rname[r];
     }
     for(uint c=0;c<ncols;c++){
       colnames[c] = cname[c];
     }
     //Rprintf("In R mem\n");
     (*pos) = newpos;
     freematrix((void**)rname,nrows);
     freematrix((void**)cname,ncols);
     freememory(binfile);
   }else{
     Rprintf("Error opening file: %s",filename[0]);
   }
 } //R_load_XGAPnames
Example #2
0
  void R_load_XGAPheader(char **filename,int* num_rows,int* num_cols,int* isNumeric,int* pos){
  //  Rprintf("File to load: %s\n",filename[0]);
    rawfilestruct binfile;
    if(parsefile(filename[0],&binfile)){
      char *matrixname,*investigationname,*colname,*rowname;
      uint newpos,nrows,ncols;
      uint deciortext;
      newpos = getname(binfile,&matrixname,1);
      newpos = getname(binfile,&investigationname,newpos);
      newpos = getname(binfile,&colname,newpos);
      newpos = getname(binfile,&rowname,newpos);
      deciortext = isbinary(binfile,newpos);
    //  Rprintf("Matrix= %s\n",matrixname);
    //  Rprintf("Numeric= %i\n",deciortext);
      newpos++;
      ncols = getncols(binfile,newpos);
    //  Rprintf("Cols= %i\n",ncols);
      newpos = newpos+4;
      nrows = getnrows(binfile,newpos);
    //  Rprintf("Rows= %i\n",nrows);
      *num_rows = nrows;
      *num_cols = ncols;
      *isNumeric = deciortext;
      newpos = newpos+4;

      (*pos) = newpos;      
      freememory(binfile);
    }else{
      Rprintf("Error opening file: %s",filename[0]);
    }
  } //R_load_XGAPheader
Example #3
0
  void R_load_XGAPstring(char **filename,int* num_rows,int* num_cols,int* pos, char** data){
    rawfilestruct binfile;
  //  Rprintf("Text File to load: %s\n",filename[0]);
    if(parsefile(filename[0],&binfile)){
      uint newpos = (*pos);
     // Rprintf("pos:%d\n",newpos);    
      uint l = fixedstringlength(binfile,newpos);
      newpos++;
      uint ncols = (*num_cols);
     // Rprintf("col:%d\n",ncols);    
      uint nrows = (*num_rows);
      uint r=0;
      uint c=0;
     // Rprintf("row:%d\n",nrows);  

      cmatrix* rdata;
      if(l > 0){
        //fixed string
        //Rprintf("Fixed\n");
        getFixedStringdata(binfile,newpos,ncols,nrows,l,&rdata);
      }else{
        //Variable String
        //Rprintf("Variable\n");
        uint* lengths;
        lengths = getlengths(binfile,newpos,ncols*nrows);
        newpos = newpos+(ncols*nrows);
        getVariableStringdata(binfile,newpos,ncols,nrows,lengths,&rdata);
      }
      for( r=0;r<nrows;r++){
        for( c=0;c<ncols;c++){
          //Rprintf("%d.%d %s\n",r,c,rdata[r][c]);
          data[(r*ncols)+c] = rdata[r][c];
        }
      }
      freematrix((void**)rdata,nrows);
      freememory(binfile);      
    }else{
      Rprintf("Error opening file: %s",filename[0]);
    }
  } //R_load_XGAPstring
Example #4
0
main(){
	build_database();
	build_hashconstant();
	int i,j,tmp;
	float temp;

    for(i=0;i<HASHTABLESIZE;i++)
        hash[i]=NULL;
	
	scanf("%d",&balls);
	while(balls>0){
		for(i=0;i<BOARDSIZE;i++){
			for(j=0;j<BOARDSIZE;j++){
				scanf("%d",&tmp);
				board.size[j][i]=tmp;
			}
		}
		if(TESTING){
            printf("%f\n",calc());
            continue;
        }
		do{
			level=-1,temp=search();
			printf("%d %d score=%f\n",besty,bestx,temp);
			freememory();
			splash(bestx,besty);
			for(i=0;i<BOARDSIZE;i++){
				for(j=0;j<BOARDSIZE;j++){
					tmp=board.size[j][i];
					printf("%d ",tmp);
				}
				printf("\n");
			}
			scanf("%d",&balls);
		}while(balls>0);
		scanf("%d",&balls);
	}
}
Example #5
0
 void R_load_XGAPdouble(char **filename,int* num_rows,int* num_cols,int* pos,double* data){
   rawfilestruct binfile;
   //Rprintf("Numeric File to load: %s\n",filename[0]);
   if(parsefile(filename[0],&binfile)){
     uint newpos = (*pos);
     uint ncols = (*num_cols);
     uint nrows = (*num_rows);
     dmatrix rdata;
     getDecimaldata(binfile,newpos,ncols,nrows,&rdata);
     for(uint r=0;r<nrows;r++){
       for(uint c=0;c<ncols;c++){
         //Rprintf("%d.%d %d\n",r,c,(r*ncols)+c);
         data[(r*ncols)+c] = rdata[r][c];
         //Rprintf("Done: %d\n",(r*ncols)+c);
       }
     }
     freematrix((void**)rdata,nrows);
     freememory(binfile);      
     //Rprintf("Done ? \n");
   }else{
     Rprintf("Error opening file: %s",filename[0]);
   }
 } //R_load_XGAPdouble
Example #6
0
static int lp_create(lua_State *L)
{
	int err;
	loski_Process *proc;
	const char *exec;
	const char *path = NULL;
	char **argv = NULL;
	char *const *envl = NULL;
	FILE *stdin = NULL;
	FILE *stdout = NULL;
	FILE *stderr = NULL;
	
	if (lua_isstring(L, 1)) {
		
		int i;
		int argc = lua_gettop(L);
		argv = allocargs(L, argc); /* TODO: memory leak in case of arg erros */
		argv[0] = (char *)luaL_checkstring(L, 1);
		for (i = 1; i < argc; ++i)
			argv[i] = (char *)luaL_checkstring(L, i+1);
		exec = argv[0];
		
	} else if (lua_istable(L, 1)) {
		
		lua_settop(L, 1);
		exec = getstrfield(L, 1, "execfile");
		path = optstrfield(L, 1, "runpath", path);
		stdin = optfilefield(L, 1, "stdin");
		stdout = optfilefield(L, 1, "stdout");
		stderr = optfilefield(L, 1, "stderr");
		
		lua_getfield(L, 1, "arguments");
		if (lua_istable(L, 2)) {
			size_t i;
			size_t argc = lua_rawlen(L, 2);
			argv = allocargs(L, argc+1); /* TODO: memory leak in case of arg erros */
			argv[0] = (char *)exec;
			for(i = 1; i <= argc; ++i) {
				lua_rawgeti(L, 2, i);
				luaL_argcheck(L, 1, !lua_isstring(L, 3),
					"field "LUA_QL("arguments")" must contain only strings");
				argv[i] = (char *)lua_tostring(L, 3);
				lua_pop(L, 1); /* pop an argument string */
			}
		} else if (!lua_isnil(L, 2)) {
			luaL_argerror(L, 1, "field "LUA_QL("arguments")" must be a table");
		}
		lua_pop(L, 1); /* pop field 'arguments' */
		
		lua_getfield(L, 1, "environment");
		if (lua_istable(L, 2)) {
			envl = table2env(L);
		} else if (!lua_isnil(L, 2)) {
			luaL_argerror(L, 1, "field "LUA_QL("environment")" must be a table");
		}
		lua_pop(L, 1); /* pop field 'environment' */
		
	} else {
		return luaL_argerror(L, 1, "table or string expected");
	}
	proc = newproc(L); /* push a new proc structure on the stack */
	err = loski_createprocess(proc, exec, path, argv, envl, stdin, stdout, stderr);
	freememory(L, (void *)argv);
	freememory(L, (void *)envl);
	return pushresults(L, 1, err); /* return process */
}
Example #7
0
File: aco.c Project: Yu-Che-Gao/GA
main(int argc , char *argv[])
{
inpfname = argv[1];
int runno, itno, antno;
double time_used;


read_data(inpfname);
print_data();

init_out(inpfname);


time_used = elapsed_time( VIRTUAL );
printf("Initialization took %.10f seconds\n",time_used);

for(runno=0;runno<runs;runno++)
{
seed = (long int ) time(NULL);
 start_timers();

 initialize_ants_variables(runno);


 initialize_trail();

 for(itno=0;  bestant.ofn != 436.00 &&  itno<ncmax ;itno++)
 {
	 
 iteration_init(itno);
  
 find_values();
  
 analysis( itno);
 

update_stats(itno,runno);

#if (usels == 1)

if(lswithitbest ==1)
{
ls(&itbestval,itno);
lsstats(itno,runno);
}

if(lswithbest ==1)
{
ls(&bestval,itno);
lsstats(itno,runno);
}

#endif

 trail();

if(!(itno%statsafterit))
{ print_itstats(itno ,runno);}

}//end of nc max iterations

update_stats(itno,runno);
report_run(runno);

}//end of runs

final_stats();

freememory();


}//end of main