📄 mobility_waypoint.pc
字号:
/* * GloMoSim is COPYRIGHTED software. Release 2.02 of GloMoSim is available * at no cost to educational users only. * * Commercial use of this software requires a separate license. No cost, * evaluation licenses are available for such purposes; please contact * info@scalable-networks.com * * By obtaining copies of this and any other files that comprise GloMoSim2.02, * you, the Licensee, agree to abide by the following conditions and * understandings with respect to the copyrighted software: * * 1.Permission to use, copy, and modify this software and its documentation * for education and non-commercial research purposes only is hereby granted * to Licensee, provided that the copyright notice, the original author's * names and unit identification, and this permission notice appear on all * such copies, and that no charge be made for such copies. Any entity * desiring permission to use this software for any commercial or * non-educational research purposes should contact: * * Professor Rajive Bagrodia * University of California, Los Angeles * Department of Computer Science * Box 951596 * 3532 Boelter Hall * Los Angeles, CA 90095-1596 * rajive@cs.ucla.edu * * 2.NO REPRESENTATIONS ARE MADE ABOUT THE SUITABILITY OF THE SOFTWARE FOR ANY * PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. * * 3.Neither the software developers, the Parallel Computing Lab, UCLA, or any * affiliate of the UC system shall be liable for any damages suffered by * Licensee from the use of this software. */// Use the latest version of Parsec if this line causes a compiler error.#include <stdlib.h>#include <stdio.h>#include <string.h>#include <assert.h>#include <math.h>#include "main.h"#include "message.h"#include "api.h"#include "structmsg.h"#include "glomo.h"#include "mobility.h"#include "mobility_waypoint.h"staticvoid FindNextPos( GlomoNode *node, GlomoMobilityRandomWaypoint* waypoint_mobility, int* numStepsToDestination){ GlomoCoordinates diff; double distance, time, speed; int num_steps; waypoint_mobility->dest.x = node->partitionData->terrainDimensions.x * pc_erand(node->mobilityData.seed); waypoint_mobility->dest.y = node->partitionData->terrainDimensions.y * pc_erand(node->mobilityData.seed); diff.x = waypoint_mobility->dest.x - node->position.x; diff.y = waypoint_mobility->dest.y - node->position.y; // This model assumes that the z coordinate is always 0.0 distance = sqrt(diff.x * diff.x + diff.y * diff.y); speed = waypoint_mobility->MinSpeed + (pc_erand(node->mobilityData.seed) * (waypoint_mobility->MaxSpeed - waypoint_mobility->MinSpeed)); time = distance / speed; num_steps = (int)ceil(distance / node->mobilityData.distance_granularity); waypoint_mobility->move_interval = (clocktype)((time / num_steps) * SECOND); waypoint_mobility->move_step.x = diff.x / num_steps; waypoint_mobility->move_step.y = diff.y / num_steps; *numStepsToDestination = num_steps;}/* * FUNCTION GLOMO_MobilityRandomWaypointInit * PURPOSE Initialization function for random drunken waypoint model. * * Parameters: * node: node being initialized. * nodeInput: structure containing contents of input file */void GLOMO_MobilityRandomWaypointInit(GlomoNode *node, GlomoNodeInput *nodeInput){ char buf[GLOMO_MAX_STRING_LENGTH]; char TimeString[80]; char stringTime[50]; double doubleTime; clocktype mobilityPause; BOOL retVal; clocktype startTime; GlomoMobilityRandomWaypoint* mobilityVar = (GlomoMobilityRandomWaypoint *) checked_pc_malloc(sizeof(GlomoMobilityRandomWaypoint)); node->mobilityData.mobilityVar = mobilityVar; /* Read the pause time after reaching destination */ retVal = GLOMO_ReadString(node->nodeAddr, nodeInput, "MOBILITY-WP-PAUSE", buf); assert(retVal == TRUE); mobilityPause = GLOMO_ConvertToClock(buf); /* Read the speed arrange(Min,Max) */ retVal = GLOMO_ReadDouble(node->nodeAddr, nodeInput, "MOBILITY-WP-MIN-SPEED", &mobilityVar->MinSpeed); assert(retVal == TRUE); retVal = GLOMO_ReadDouble(node->nodeAddr, nodeInput, "MOBILITY-WP-MAX-SPEED", &mobilityVar->MaxSpeed); assert(retVal == TRUE); /* average speed is set in meters per second */ node->mobilityData.avgSpeed = (mobilityVar->MaxSpeed + mobilityVar->MinSpeed ) / 2.0 ; // No Initial Pause. mobilityVar->mobilityPause = 0; mobilityVar->number_moves_left = 0; GLOMO_MobilityRandomWaypoint(node); mobilityVar->mobilityPause = mobilityPause;}/* * FUNCTION GLOMO_MobilityRandomWaypoint * PURPOSE Models the behaviour of the random drunken waypoint model * on receiving a message. * * Parameters: * node: node which received the message */void GLOMO_MobilityRandomWaypoint(GlomoNode *node) { GlomoMobilityRandomWaypoint* waypoint_mobility = (GlomoMobilityRandomWaypoint*)node->mobilityData.mobilityVar; if (waypoint_mobility->number_moves_left == 0) { int numStepsToDestination; FindNextPos(node, waypoint_mobility, &numStepsToDestination); waypoint_mobility->number_moves_left = numStepsToDestination - 1; node->mobilityData.nextMoveTime = simclock() + waypoint_mobility->mobilityPause + waypoint_mobility->move_interval; } else { waypoint_mobility->number_moves_left--; node->mobilityData.nextMoveTime = simclock() + waypoint_mobility->move_interval; }//if// node->mobilityData.next.x = node->position.x + waypoint_mobility->move_step.x; node->mobilityData.next.y = node->position.y + waypoint_mobility->move_step.y;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -