/* Chad Brewbaker 5-24-2002 seedMixer.c This program searches the space of golomb seeds by making a greedy construction with a seed, and then using random elements out of that construction as new seeds */ #include #include #include //Play with these #define RULER_SIZE 8 //Length of the completed ruler #define SEED_SIZE 4 //Size of the seed #define GENERATIONS 1000 //Number of random starts #define LOOPS 100 //How long each random seed is evolved //Mess with these at your own peril. Quick hack aritifacts. #define MAX_NUM 90//Maximum size of a seed number #define RULER_NUM 100//population size #define PXOVER .80 #define PMUTATE .1 #define LUT_SIZE 500//look up table size #define PENALTY_MULT 200 int seeds[RULER_NUM][SEED_SIZE];//population storage int newSeeds[RULER_NUM][SEED_SIZE];//nextPopulation storage double seedFit[RULER_NUM];//a seed's fitness double rSeedFit[RULER_NUM];//relative fitness double cSeedFit[RULER_NUM];//cumulative fitness int worstFit;//worst score for each generation //stores the superseed int elete[SEED_SIZE]; int superScore; int usedTable[MAX_NUM*MAX_NUM];//array used for sorting/searching int rulerMap[RULER_SIZE];//a copy of the completed ruler //circular buffer //-New element:kill off the oldest and replace with new //-Old element:swap oldest with the current and incrament buffer // // int lookUpTable[LUT_SIZE][SEED_SIZE]; double lookUpTableFit[LUT_SIZE]; int oldest=0;//oldest member of the lookup table void exchange(int i, int j) { int temp; temp=usedTable[i]; usedTable[i]=usedTable[j]; usedTable[j]=temp; } int partition(int p,int r) { int i,j; int x; x=usedTable[r]; i=p-1; for(j=p; j<=r-1; j++) { if(usedTable[j]<=x) { i+=1; exchange(i,j); } } exchange(i+1,r); return i+1; } void quicksort(int p, int r) { int q; if(pbest) best=rulerMap[i]; } return best; } int growRuler(int rulerNum, int printMe) { int i,j,k,l; int temp; int tableSize=0; int oldTableSize=0; int good; int mapSize; int score; int outer; int maximal; int *pItem; int sameCount; int seedDifs; int properLength; int penalty; int tempTableSize; if(printMe) { printf("\nSEED:{"); for(i=0;imaximal) maximal=rulerMap[i+1]; } mapSize=SEED_SIZE+1; //add unique seed diferences to usedTable tableSize=0; for(i=0;irulerMap[j]) { temp = rulerMap[j]; rulerMap[j]=rulerMap[j-1]; rulerMap[j-1]=temp; } } } return score+penalty; } void crossover(void) { int i,j; int count=0; int size,position; int store,temp; double x; for(i=0;i=cSeedFit[j] && probseedCopy[j+1]) { sortMore=1; temp=seedCopy[j]; seedCopy[j]=seedCopy[j+1]; seedCopy[j+1]=temp; } } if(sortMore==0) break; } //match to the lookup table temp=-1; for(i=0;ilength) length=rulerMap[i]; } if(length==fitness) { if(length