//void itsHybridContinuousInteractingAntColony::addAnt( vector<double> aPoint, vector<double> aMoveRange, double aProbaUseMemory ) void itsHybridContinuousInteractingAntColony::addAnt( vector<double> aPoint, double aMoveRange, double aProbaUseMemory ) { // variables antProbaMemory.push_back( aProbaUseMemory ); //antMoveRange.push_back( aMoveRange ); antMoveRange.push_back( aMoveRange ); antCurrentPoint.push_back( aPoint ); // initialisations itsPoint p; p.setSolution( aPoint ); antCurrentValue.push_back( evaluate( p ).getValues()[0] ); antState.push_back( 0 ); // ini piles messages vector<double> nullValuesStack; double nullValue = 0; nullValuesStack.push_back( nullValue ); antIncomingValues.push_back( nullValuesStack ); vector< vector<double> > nullPointsStack; vector<double> nullPoint( this->getProblem()->getDimension(), 0 ); nullPointsStack.push_back( nullPoint ); antIncomingPoints.push_back( nullPointsStack ); }
void parseTriangle(GLfloat refractIndex){ char * token; ShapeData parsedShape; parsedShape.type = TRIANGLE; /*Coordinates of vertex 1*/ token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[0].x = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 1 'x' position.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[0].y = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 1 'y' position.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[0].z = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 1 'z' position.\n", globals.numberOfShapes); return; } /*Coordinates of vertex 2*/ token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[1].x = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 2 'x' position.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[1].y = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 2 'y' position.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[1].z = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 2 'z' position.\n", globals.numberOfShapes); return; } /*Coordinates of vertex 3*/ token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[2].x = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 3 'x' position.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[2].y = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 3 'y' position.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.theShape.triangle.points[2].z = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Vertex 3 'z' position.\n", globals.numberOfShapes); return; } /*Colour*/ token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.colour.red = (GLfloat)atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Red colour amount.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.colour.green = (GLfloat)atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Green colour amount.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.colour.blue = (GLfloat)atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Blue colour amount.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.reflectivity = atof(token); } else{ printf("Parse error: Missing parameter for shape %d (triangle): Reflectivity.\n", globals.numberOfShapes); return; } token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.opacity = atof(token); token = strtok(NULL, PARSE_DELIMITERS); if(token != NULL){ parsedShape.refractionIndex = atof(token); } else{ printf("Warning: Missing parameter for shape %d (triangle): Index of Refraction.\n", globals.numberOfShapes); printf("Setting to default: Air refraction index\n"); parsedShape.refractionIndex = AIR_REFRACTION_INDEX; } } else{ printf("Parse error: Missing parameter for shape %d (triangle): Opacity.\n", globals.numberOfShapes); printf("Setting opacity to default: 1.0\n"); parsedShape.opacity = 1.0; parsedShape.refractionIndex = AIR_REFRACTION_INDEX; } parsedShape.theShape.triangle.normal.direction = nullPoint(); parsedShape.theShape.triangle.normal = getNormal(parsedShape, parsedShape.theShape.triangle.points[0]); globals.shapes = realloc(globals.shapes, sizeof(ShapeData) * (globals.numberOfShapes + 1)); globals.shapes[globals.numberOfShapes] = parsedShape; printShape(globals.shapes[globals.numberOfShapes]); globals.numberOfShapes++; }
/*Lens intersection. Basically the same as a sphere except with another check for concavity*/ Point3D lensIntersection(LensData lens, Vector3D ray){ Point3D intersection1; Point3D intersection2; double quadraticA = 1; double quadraticB; double quadraticC; double discriminant; double quadraticNegativeT; double quadraticPositiveT; double inter1Length; double inter2Length; quadraticB = 2 * ((ray.direction.x * (ray.position.x - lens.position.x)) + (ray.direction.y * (ray.position.y - lens.position.y)) + (ray.direction.z * (ray.position.z - lens.position.z))); quadraticC = pow((ray.position.x - lens.position.x), 2) + pow((ray.position.y - lens.position.y), 2) + pow((ray.position.z - lens.position.z), 2) - pow(lens.radius, 2); discriminant = (pow(quadraticB, 2) - (4 * quadraticA * quadraticC)); /*Test discriminant, if not negative an intersection exists*/ if(discriminant >= 0){ quadraticNegativeT = (-quadraticB - sqrt(discriminant)) / 2; quadraticPositiveT = (-quadraticB + sqrt(discriminant)) / 2; intersection1.x = ray.position.x + (ray.direction.x * quadraticNegativeT); intersection1.y = ray.position.y + (ray.direction.y * quadraticNegativeT); intersection1.z = ray.position.z + (ray.direction.z * quadraticNegativeT); intersection2.x = ray.position.x + (ray.direction.x * quadraticPositiveT); intersection2.y = ray.position.y + (ray.direction.y * quadraticPositiveT); intersection2.z = ray.position.z + (ray.direction.z * quadraticPositiveT); inter1Length = getLength(ray.position, intersection1); inter2Length = getLength(ray.position, intersection2); /*Check concavity, take the correct intersection*/ if(lens.isConvex == true){ /*The closest intersection is the convex one*/ if((isInRayPath(ray, intersection1)) && (inter1Length > 0.01)){ return intersection1; } else{ return nullPoint(); } } else{ /*Concave - the farthest intersection is the concave one*/ if((isInRayPath(ray, intersection2)) && (inter2Length > 0.01)){ return intersection2; } else{ //printVector(ray); return nullPoint(); } } } return nullPoint(); }
/********** routine de d�lacement **********/ void itsHybridContinuousInteractingAntColony::antMove( int antId ) { printDebug( "antState", antState[0]); // si fourmi viens de faire un simplexe if ( antState[antId] == 0 ) { // re-placement al�toire : vector<double> aPoint; aPoint.reserve( this->getProblem()->getDimension() ); // tirage al�toire uniforme sur l'hypercube de l'espace de recherche // aPoint = RandomVector_Cube( getBoundsMinima(), getBoundsMaxima() ); // tirage al�toire dans la zone de visibilit� //aPoint = RandomVector_Noise( antCurrentPoint[antId], antMoveRange[antId] ); vector<double> tempVec( this->getProblem()->getDimension(),antMoveRange[antId] ); aPoint = noiseUniform( antCurrentPoint[antId], tempVec ); antMoveTo(antId, aPoint); // efface la pile de message vector<double> nullValuesStack; double nullValue = 0; nullValuesStack.push_back( nullValue ); antIncomingValues[antId] = nullValuesStack; vector< vector<double> > nullPointsStack; vector<double> nullPoint( this->getProblem()->getDimension(), 0 ); nullPointsStack.push_back( nullPoint ); antIncomingPoints[antId] = nullPointsStack; // fin de cet �at antState[antId]=0.0001; spotsEvaporate(); return; } else { // fourmi n'as pas encore fait de simplexe // d�lacement normal // choix du d�lacement int ok=0; int choice; // si choix des spots choice = thresholdChoice( antProbaMemory[antId], probaUseMemoryThreshold, probaUseMemoryPower, 'e' ); if ( choice ) { ok += antMoveSpots( antId ); } else { // choix des messages ok += antMoveMessages( antId ); } // si d�lacement spots/message fait if ( ok > 0 ) { spotsEvaporate(); return; } // teste motivation simplexe choice = thresholdChoice( antState[antId], probaUseNMSThreshold, probaUseNMSPower, 'e' ); if ( choice ) { // intensification par simplexe ok += antMoveNMS(antId); // d�ot spot antSpotLay( antId, antCurrentPoint[antId], antCurrentValue[antId] ); // a fait son intensification antState[antId] = 0; } else { // pas motiv� pour le simplexe // test envoi de message choice = thresholdChoice( 1 - antState[antId], probaUseNMSThreshold, probaUseNMSPower, 'e' ); if ( choice ) { // envoi de message antMessageSend( antId, antMessageChooseMate(antId) ); // augmentation motivation antIncreaseState(antId); } } // si d�lacement simplexe impossible if ( ok == 0 ) { antMoveRandom( antId ); spotsEvaporate(); return; } } spotsEvaporate(); }