214
X-Machines for Agent-Based Modeling: FLAME Perspectives
int result = (int) round(totalAngle / 360 * 8);
if (result == 0) {
return 8;
}
return result;
}
void detectPheromone(double* pheromoneX, double* pheromoneY) {
double pheromoneLife = -1;
double currentX = ANTX;
double currentY = ANTY;
int direction = ANTDIRECTION;
int nextdir = (direction + 1) > 8 ? 1 : direction + 1;
int prevdir = (direction - 1) < 1 ? 8 : direction - 1;
pheromoneInformation_message = get_first_pheromoneInformation_message();
double distanceToPheromone = 0;
double randomNumber1 = ((double) rand() / ((double) RAND_MAX));
//leaving trail probability
if (randomNumber1 <= 0.001){
pheromoneLife = -1;
*pheromoneX = -1;
*pheromoneY = -1;
}
else {
while (pheromoneInformation_message) {
double pheromoneLocalX = pheromoneInformation_message->pheromoneX;
double pheromoneLocalY = pheromoneInformation_message->pheromoneY;
double pheromoneLocalLife = pheromoneInformation_message->life;
distanceToPheromone = getDistance(pheromoneLocalX,
pheromoneLocalY, currentX, currentY);
if (distanceToPheromone <= antStepSize && pheromoneLocalLife >= 0.2
&& distanceToPheromone > minPheromoneDistance)
{
int newDirection = getDirection(ANTX, ANTY,
pheromoneLocalX, pheromoneLocalY);
if (newDirection == direction || newDirection == nextdir ||
newDirection == prevdir) {
if (pheromoneLife <= pheromoneLocalLife) {
pheromoneLife = pheromoneLocalLife;
*pheromoneX = pheromoneLocalX;
*pheromoneY = pheromoneLocalY;
}
}
}
pheromoneInformation_message = get_next_pheromoneInformation_message
(pheromoneInformation_message);
}
}
}
int turningKernel() {
X-Machines for Agent-Based Modeling: FLAME Perspectives
int result = (int) round(totalAngle / 360 * 8);
if (result == 0) {
return 8;
}
return result;
}
void detectPheromone(double* pheromoneX, double* pheromoneY) {
double pheromoneLife = -1;
double currentX = ANTX;
double currentY = ANTY;
int direction = ANTDIRECTION;
int nextdir = (direction + 1) > 8 ? 1 : direction + 1;
int prevdir = (direction - 1) < 1 ? 8 : direction - 1;
pheromoneInformation_message = get_first_pheromoneInformation_message();
double distanceToPheromone = 0;
double randomNumber1 = ((double) rand() / ((double) RAND_MAX));
//leaving trail probability
if (randomNumber1 <= 0.001){
pheromoneLife = -1;
*pheromoneX = -1;
*pheromoneY = -1;
}
else {
while (pheromoneInformation_message) {
double pheromoneLocalX = pheromoneInformation_message->pheromoneX;
double pheromoneLocalY = pheromoneInformation_message->pheromoneY;
double pheromoneLocalLife = pheromoneInformation_message->life;
distanceToPheromone = getDistance(pheromoneLocalX,
pheromoneLocalY, currentX, currentY);
if (distanceToPheromone <= antStepSize && pheromoneLocalLife >= 0.2
&& distanceToPheromone > minPheromoneDistance)
{
int newDirection = getDirection(ANTX, ANTY,
pheromoneLocalX, pheromoneLocalY);
if (newDirection == direction || newDirection == nextdir ||
newDirection == prevdir) {
if (pheromoneLife <= pheromoneLocalLife) {
pheromoneLife = pheromoneLocalLife;
*pheromoneX = pheromoneLocalX;
*pheromoneY = pheromoneLocalY;
}
}
}
pheromoneInformation_message = get_next_pheromoneInformation_message
(pheromoneInformation_message);
}
}
}
int turningKernel() {
