📄 param.c
字号:
/* Optann, a Khepera simulator including a separate GA and ANN (Genetic Algoritm, Artificial Neural Net). Copyright (C) 2000 Johan Carlsson (johanc@ida.his.se) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "param.h"/* Serial thingis*//** Option, use of serial line (binary). */int useSerialLine=0; /** List of serial devices to use, if \a useSerialDevice */char **serialDevice; /** List of baud rates, one for each for \a serialDevice */ int *baudRate; /** Option, number of robots to simulate. */int paramNrOfRobots=1; /** Option, Delay for gui update @obselute */int updateDelay= 1000;/** Option, use compass sensor (binary). */ int useCompass=0;/** Option, use energy sensor (binary). */int useEnergy=0; /** Option, use ground sensor (binary). */ int useGround=0;/** Option, use light bulb sensor (binary). */int useLightbulbSensors=0;/** Option, number of front sensor to use. */ int nrOfFrontInfrared=6; /** Option, use robot back infra red sensors (binary). */int nrOfBackInfrared=0; /** Option, use gripper sensor of gripper arm (binary). */int gripperSensor=1; /** Option, scaling of simulator window. */float xScale=0.5; /** Global, trajactory robot. */int notTrajactoryRobot=0; /** Option, selection method to use (in main simulation loop). */int selectionMethod=0; /** Option, the probability that a bit will mutate. */int bitMutateProbability=2;/** Global, random seed */int seed=0; /** Option, number of epochs to run each individ. */int amoebaEpochs=10; /** Option, number of generations to run simulation. */int nrOfGenerations=10; /** Option, number of individs for each generation. */int nrOfIndivids=100;/** Option, number of kids for each father. */int nrOfKids=5;/** Option, number of fathers that make kids for each generation. */int nrOfFathers=20;/** Option, start generation (>=0 means load weights). */int startGeneration = -1; /** Option, verbose level (0 - 1 - 2, used binary for now). */int verboseLevel=1; /** Option, save only the best N amoebas each generation. */int saveNrOfIndivids; /** Option, noise on sensors (binary). */int sensorNoise=0; /** Option, amount of noise to add to sensor inputs. */float amountOfNoise=0.1; /** Option, test start from the same position (binary). */int testSameStartPosition=0;/** Option, fitness function to use (in main simulation loop). */ int ffitness=1; /** Option, use gripper arm (binary). */int useGripper=0; /** Option, use the rod sensor (binary). */int useRodSensor=0; /** Option, use noise on rod sensor (binary). */int useRodNoise=0; /** Option, use noise on gripper sensor (binary). */int gripperNoise=1; /** Option, nr of time steps to run each epoch (100 ms/step). */int nrOfSteps = 200; /** Option, reposition obstacles between epochs. */int moveObstacles=1; /** Global, GUI simulator area update (binary). */int gfxUpdate=1; /** Global, GUI update of user windows (binary). */int userUpdate=1; /** USED ?!? */float energyDecrease=0; /** Option, nr of individs to log fitness for after each generation. */int nrOfIndividsToLog=1; /** Option, save weights of each x'th generation. */int saveGeneration=100; /** Option, filename of the picture to use for drawing of robots (not used). */char robotPicFile[100]; /** Option, filename of the picture to use for drawing the world (not used). */char worldPicFile[100]; /** Option, path to where logs should be saved. */char logPath[100]; /** Option, path to the world file. */char worldPath[100]; /** Option, path to the camera files. */char cameraPath[100]; /** Option, filename of the world to use. */char worldFile[100]; /** Option, camera file for small round obstacles. */char smallCamera[100]; /** Option, camera file for round obstacles. */char bigCamera[100]; /** Option, camera file for robot. */char robotCamera[100]; /** Option, camera file for walls. */char wallCamera[100]; /** Option, camera file for light sources. */char lightCamera[100]; /** Option, camera file for robot movements. */char motorCamera[100]; /** Option, filename for the file to save individ weights to. */char weightsFile[100]; /** Option, filename for the file to write fitness log to. */char fitnessFile[100]; /* Network input values *//** Global, mapping of \a input arrar to ann [NR_OF_ROBOTS][NETWORK_INPUTS]. */int **mapping; /** Global, array where sensor values for the robots are stored [NR_OF_ROBOTS][NETWORK_INPUTS]. */double **input; /** Global, copy of input [NR_OF_ROBOTS][NETWORK_INPUTS]. */double **simoutput;FILE *fp;char **lineBuffer;int nrOfLines=0;int readLines=0;char* readLine(){ char ch[120]; if(fgets(ch,120,fp)==NULL) return(NULL); else return(strdup(ch));}void readFile(){ int i; lineBuffer = (char**) malloc(sizeof(char*)*CONFIG_FILE_LINES); for(i=0; i < CONFIG_FILE_LINES && (lineBuffer[i]=readLine())!=NULL; i++); nrOfLines=i; printf("Read %3d config lines\n",nrOfLines); readLines=nrOfLines;}void freeBuffers(){ int i; for(i=0; i<nrOfLines; i++){ free(lineBuffer[i]); } free(lineBuffer);}int lineCompare(const void *str1, const void *str2){ return strcasecmp(*((char**)str1),*((char**)str2));}void sortFile(){ qsort(lineBuffer,nrOfLines,sizeof(char*),lineCompare);}void printFile(){ int i; printf("\nLinenumber String\n"); for(i=0; i < nrOfLines; i++){ printf("%4d -%s",i,lineBuffer[i]); }}char *mojsiNator(char *strToStrip){ char *brainWashed; int chop,i,beg; beg = 1; brainWashed = strdup(strToStrip); for(i=0,chop=0; i <(int) strlen(strToStrip); i++){ switch(strToStrip[i]){ case ' ': if(beg==0){ if(strToStrip[i+1]==' '){ /* Do nothing */ } else{ brainWashed[chop]=strToStrip[i]; chop++; } } break; case '\t': if(beg==0){ if(strToStrip[i+1]!='\t' && strToStrip[i+1]!=' '){ brainWashed[chop]=' '; chop++; } } break; default: brainWashed[chop]=strToStrip[i]; beg = 0; chop++; break; } } brainWashed[chop]='\0'; free(strToStrip); return brainWashed;}void removeMojs(){ int i,q; for(i=0; i < nrOfLines; i++) lineBuffer[i]=mojsiNator(lineBuffer[i]); for(i=0; i < nrOfLines; i++){ if(lineBuffer[i][0]=='#' || lineBuffer[i][0]=='\n' || \ lineBuffer[i][0]=='\0' || lineBuffer[i][0]==' '){ free(lineBuffer[i]); for(q=i;q < nrOfLines-1; q++){ lineBuffer[q]=lineBuffer[q+1]; } nrOfLines--; i--; /* We have to test the new string on place i */ } }}char *removeToken(char **str){ char *tmp; int i; char strToken[40]; sscanf(*str,"%s %d",strToken,&i); tmp = *str+strlen(strToken); strcpy(*str,tmp); return strdup(strToken);}void parseGetNext(int *i,char **findThis){ (*i)++; *findThis = removeToken(&lineBuffer[*i]);}void parseFile(){ int i; int baudCount=0; char *findThis; findThis=NULL; i=0; for(int z=0; z < nrOfLines; z++) printf("%s",lineBuffer[z]); findThis = removeToken(&lineBuffer[i]); /* They must lay in alphabetic order */ if(strcmp("A_#ROBOTS",findThis)==0){ sscanf(lineBuffer[i],"%d",¶mNrOfRobots); free(findThis); parseGetNext(&i,&findThis); } if(strcmp("BACK_INFRARED",findThis)==0){ sscanf(lineBuffer[i],"%d",&nrOfBackInfrared); free(findThis); parseGetNext(&i,&findThis); } baudRate = (int*) malloc(sizeof(int)*paramNrOfRobots); while(strcmp("BAUD_RATE",findThis)==0 && baudCount < paramNrOfRobots){ sscanf(lineBuffer[i],"%d",&baudRate[baudCount++]); free(findThis); parseGetNext(&i,&findThis); } if(strcmp("BIG_CAMERA",findThis)==0){ sscanf(lineBuffer[i],"%s",bigCamera); free(findThis); parseGetNext(&i,&findThis); } if(strcmp("BIT_MUTATION",findThis)==0){ sscanf(lineBuffer[i],"%d",&bitMutateProbability); free(findThis); parseGetNext(&i,&findThis); } if(strcmp("CAMERA_PATH",findThis)==0){ sscanf(lineBuffer[i],"%s",cameraPath);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -