void CellBump(Grid* W,Cell* c){/* cells with overlapping radii get force vectors applied to them to bounce off each other*/ double usageColor=c->myBody->usageB/(BINSIZE*NUMBINS*0.7); //usageColor=0.7<usageColor?0.7:usageColor; addColor(W,c->color,usageColor,usageColor,usageColor,EVOLUTIONVIEW); LL* touching=withinRad(W,c->CellPos,CELLRAD,c,0); if(touching){ for(LL* curr=touching;curr!=NULL;curr=curr->next){ //AddNeuron(&c->myBrain->inputs[1],0.5,__func__); Cell* touching=curr->val; double dist=getDist(c->CellPos,touching->CellPos); //double forceMag=(1-(dist/pow((2*CELLRAD),3)))*0.1;//function to bounce cells with differing severity double forceMag=(1-(pow(dist/(2.0*CELLRAD),BUMP_FUNCTION_EXPONENT))); /*BUMP_FUNCTION_EXPONENT combined with BUMP_FORCE_MULT dictate how strongly bumping cells repel each other*/ double diff[]={touching->CellPos[0]-c->CellPos[0],touching->CellPos[1]-c->CellPos[1]}; double touchLoc[]={c->CellPos[0]+diff[0]/2,c->CellPos[1]+diff[1]/2}; double scale=(forceMag*BUMP_FORCE_MULT)/dist; double xyComp[]={-(touching->CellPos[0]-c->CellPos[0])*scale,-(touching->CellPos[1]-c->CellPos[1])*scale}; /*Force is applied from the touching location to the center of the cell (for single cells exerts no torque)*/ FORCE_FUN(W,c->myBody,touchLoc,xyComp,0); //here we force closest cells to separate instantly! no matter what, by rewinding time until they are fully apart //applyImpulse(W,c,touching); c->myBody->touching=1; //c->dxy[0]-=distx*(forceMag/dist); //c->dxy[1]-=disty*(forceMag/dist); } freeLL(touching); } else{ //AddNeuron(&c->myBrain->inputs[1],-0.5,__func__); } }
// Show all stops inside a certain radius apvector <ID> withinOneRadius(apvector <apstring> & id, apmatrix <int> & dist, double rad, apstring theid) { int n = id.length(); // double rad; // cout << "Enter the desired radius to be searched in: "; // ?? should radius be *100 or not?? // cin >> rad; // apstring theid; // we hate getline // cout << "Enter the stop ID for which you would like the radii: "; // getline(cin, theid); // theid = "2051051WB007 "; // now should search the stopID file for the value of the node in id int row = 0; while ( theid != id[row] ) // assumes that id1 was entered correctly { // cout << id[row]; row++; } apvector <ID> withinRad(n + 1); ID temp; int col, count = 0; for ( col = 0; col < dist.numcols(); col++) { if ( convertDistance(dist[row][col]) <= rad ) { temp.stopID = id[col]; temp.distance = convertDistance(dist[row][col]); // the distance is dist[row][col], will eventually be added to a data structure? // cout << id[col] << " is within the radius with distance of " << convertDistance(dist[row][col]) << endl; withinRad[count] = temp; count ++; } } withinRad.resize(count + 1); // resize the array to be smaller and not wasteful return withinRad; }
// Show all stops inside a certain radius for all stops apvector <apvector <ID> > withinAllRadius(apvector <apstring> & id, apmatrix <int> & dist, double rad) { int n = id.length(); // double rad; // cout << "Enter the desired radius to be searched in: "; // ?? should radius be *100 or not?? // cin >> rad; int row = 0; int col; int count = 0; apvector <ID> withinRad(n + 1); ID temp; apvector <apvector <ID> > allRadii(n + 1); for ( row = 0; row < dist.numrows(); row++) { for ( col = 0; col < dist.numcols(); col++) { if ( convertDistance(dist[row][col]) <= rad && row != col) { temp.stopID = id[col]; temp.distance = convertDistance(dist[row][col]); // the distance is dist[row][col], will eventually be added to a data structure? // cout << convertDistance(dist[row][col]) << '\t'; withinRad[count] = temp; count ++; } } allRadii[row] = withinRad; // cout << endl << "--------------------------------------------" << endl; } return allRadii; }