void place_rwalk_node (node_struct * node) { node->x_pos = (double) ((int) (randomgen (omg_param_list[node->type].min_x, omg_param_list[node->type].max_x) * 100)) / 100; node->mob->x_from = node->x_pos; node->mob->x_to = node->x_pos; node->y_pos = (double) ((int) (randomgen (omg_param_list[node->type].min_y, omg_param_list[node->type].max_y) * 100)) / 100; node->mob->y_from = node->y_pos; node->mob->y_to = node->y_pos; node->mob->speed = 0.0; node->mob->journey_time = 0.0; // LOG_D (OMG, " INITIALIZE RWALK NODE\n "); LOG_I (OMG, "#Initial position of node ID: %d type: %d (X = %.2f, Y = %.2f) speed = 0.0\n", node->id, node->type, node->x_pos, node->y_pos); node_vector_end[node->type] = (node_list *) add_entry (node, node_vector_end[node->type]); if (node_vector[node->type] == NULL) node_vector[node->type] = node_vector_end[node->type]; node_vector_len[node->type]++; }
void sleep_rwp_node (pair_struct * pair, double cur_time) { node_struct *node; node = pair->b; node->mobile = 0; node->mob->speed = 0.0; node->mob->x_from = node->mob->x_to; node->mob->y_from = node->mob->y_to; node->x_pos = node->mob->x_to; node->y_pos = node->mob->y_to; node->mob->sleep_duration = (double) ((int) (randomgen (omg_param_list[node->type].min_sleep, omg_param_list[node->type].max_sleep) * 100)) / 100; /*LOG_D (OMG, "#[RWP] node: %d \tsleep duration : %.2f\n", node->id, node->mob->sleep_duration); */ node->mob->start_journey = cur_time; pair->next_event_t = cur_time + node->mob->sleep_duration; //when to wake up // LOG_D (OMG, "[RWP] wake up at time: cur_time + sleep_duration : %.2f\n", // pair->a); }
void sleep_steadystaterwp_node (pair_struct * pair, double cur_time) { static int initial = 1; node_struct *node; node = pair->b; node->mobile = 0; node->mob->speed = 0.0; node->mob->x_from = node->mob->x_to; node->mob->y_from = node->mob->y_to; node->x_pos = node->mob->x_to; node->y_pos = node->mob->y_to; if (node->event_num == 0) { node->mob->sleep_duration = initial_pause (omg_param_list[node->type]); node->event_num++; } else { node->mob->sleep_duration = (double) ((int) (randomgen (omg_param_list[node->type].min_sleep, omg_param_list[node->type].max_sleep) * 100)) / 100; } // LOG_D (OMG, "[STEADY_RWP] node: %d \tsleep duration : %.2f\n", node->ID, // node->mob->sleep_duration); node->mob->start_journey = cur_time; pair->next_event_t = cur_time + node->mob->sleep_duration; //when to wake up // LOG_D (OMG, "[STEADY_RWP] wake up at time: cur_time + sleep_duration : %.2f\n", // pair->a); }
static inline void ParseOptions(int argc, char* argv[], ESolverOpts& Opts, string& InputFileName) { po::options_description desc("Usage and Allowed Options"); po::positional_options_description pdesc; pdesc.add("input-file", -1); desc.add_options() ("help", "produce this help message") ("input-file,i", po::value<string>(&InputFileName)->default_value(""), "SynthLib2 formatted input file") ("verbose,v", po::value<int32>(&Opts.StatsLevel)->default_value(DEFAULT_LOG_LEVEL), "Verbosity") ("memory-limit,m", po::value<uint64>(&Opts.MemoryLimit)->default_value(MEM_LIMIT_INFINITE), "Memory limit (bytes)") ("cpu-limit,t", po::value<uint64>(&Opts.CPULimit)->default_value(CPU_LIMIT_INFINITE), "CPU Time limit (seconds)") ("budget,s", po::value<uint32>(&Opts.CostBudget)->default_value(DEFAULT_BUDGET), "Maximum cost of expansions to explore") ("random,r", po::value<uint32>(&Opts.RandomSeed)->implicit_value(DEFAULT_RANDOM_SEED), "Start the solver with a random seed to the SMT solver, a random seed will be used if none specified") ("nodist,n", "Do not use distinguishability to prune search space"); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(desc).positional(pdesc).run(), vm); po::notify(vm); if(vm.count("help") > 0 || argc < 2) { cout << desc << endl; exit(0); } if((vm.count("random") > 0) && (Opts.RandomSeed == DEFAULT_RANDOM_SEED)) { // generate a random seed struct timeval TV; gettimeofday(&TV, NULL); mt19937 randomgen((uint32)TV.tv_usec); auto NumToThrow = TV.tv_sec % 1024; // throw away some bits uint32 Seed = 0; for(uint32 i = 0; i < NumToThrow; ++i) { Seed = (Seed ^ randomgen()); } Opts.RandomSeed = (Seed % (1 << 30)); } if (vm.count("nodist") > 0) { Opts.NoDist = true; } else { Opts.NoDist = false; } }
double initial_speed (omg_global_param omg_param) { double u; u = randomgen (0, 1); return pow (omg_param.max_speed, u) / pow (omg_param.min_speed, u - 1); }
int start_steadystaterwp_generator (omg_global_param omg_param_list) { static int n_id = 0; int id; double cur_time = 0.0, pause_p; node_struct *node = NULL; mobility_struct *mobility = NULL; pair_struct *pair = NULL; pause_p = pause_probability (omg_param_list); srand (omg_param_list.seed + RWP); LOG_I (OMG, "STEADY_RWP mobility model for %d %d nodes\n", omg_param_list.nodes, omg_param_list.nodes_type); for (id = n_id; id < (omg_param_list.nodes + n_id); id++) { node = create_node (); mobility = create_mobility (); node->id = id; node->type = omg_param_list.nodes_type; node->mob = mobility; node->generator = STEADY_RWP; node->event_num = 0; place_rwp_node (node); //initial positions pair = (pair_struct *) malloc (sizeof (struct pair_struct)); pair->b = node; //pause probability...some of the nodes start at pause & the other on move if (randomgen (0, 1) < pause_p) sleep_steadystaterwp_node (pair, cur_time); //sleep else move_steadystaterwp_node (pair, cur_time); job_vector_end[STEADY_RWP] = add_job (pair, job_vector_end[STEADY_RWP]); if (job_vector[STEADY_RWP] == NULL) job_vector[STEADY_RWP] = job_vector_end[STEADY_RWP]; job_vector_len[STEADY_RWP]++; } n_id += omg_param_list.nodes; if (job_vector[STEADY_RWP] == NULL) LOG_E (OMG, "[STEADY_RWP] Job Vector is NULL\n"); return (0); }
void place_steadystaterwp_node (node_struct * node) { int loc_num; double block_xmin, block_ymin; if (grid == RESTIRICTED_RWP) { loc_num = (int) randomgen (0, omg_param_list[node->type].max_vertices); node->x_pos = (double) vertice_xpos (loc_num, omg_param_list[node->type]); node->y_pos = (double) vertice_ypos (loc_num, omg_param_list[node->type]); //LOG_D(OMG,"location number %d x pos %.2f y pos %.2f \n\n",loc_num,node->x_pos,node->y_pos); } else if (grid == CONNECTED_DOMAIN) { node->block_num = (int) randomgen (0, omg_param_list[node->type].max_block_num); block_xmin = area_minx (node->block_num, omg_param_list[node->type]); block_ymin = area_miny (node->block_num, omg_param_list[node->type]); node->x_pos = (double) ((int) (randomgen (block_xmin, xloc_div + block_xmin) * 100)) / 100; node->y_pos = (double) ((int) (randomgen (block_ymin, yloc_div + block_ymin) * 100)) / 100; } else { node->x_pos = (double) ((int) (randomgen (omg_param_list[node->type].min_x, omg_param_list[node->type].max_x) * 100)) / 100; node->y_pos = (double) ((int) (randomgen (omg_param_list[node->type].min_y, omg_param_list[node->type].max_y) * 100)) / 100; } node->mob->x_from = node->x_pos; node->mob->x_to = node->x_pos; node->mob->y_from = node->y_pos; node->mob->speed = 0.0; node->mob->journey_time = 0.0; LOG_I (OMG, "#[STEADY_RWP] Initial position of node ID: %d type: %d X = %.2f, Y = %.2f\n ", node->id, node->type, node->x_pos, node->y_pos); node_vector_end[node->type] = (node_list *) add_entry (node, node_vector_end[node->type]); if (node_vector[node->type] == NULL) node_vector[node->type] = node_vector_end[node->type]; node_vector_len[node->type]++; //Initial_Node_Vector_len[RWP]++; }
int main (){ double value, S0=0, S_in, Sn; double S[N]; double deltacond, r; for (int n=0; n<N; n++){ S[n]=((m*a)/(2*hbar))*(square((i_c[n+1]-i_c[n])/a)-square(w)*((square(i_c[n+1])+square(i_c[n]))/2)); S0=S0+S[n]; printf("%0.2f\n", S0); } S_in=S0; printf("The initial action S0 is: %0.2f\n", S0); for (int j=0; j<iterations; j++){ for (int n=0; n<N; n++){ value=i_c[n]; path[j][n]=i_c[n]; /*Here I will keep the coordinates of each final path*/ for (int l=0; l<rep; l++){ Sn=0; printf("Error 0: %f\n", value); randomgen(value, delta); printf("Error 1: %f\n", value); i_c[l]=value; for (int k=0; k<N; k++){ S[k]=((m*a)/(2*hbar))*(square((i_c[k+1]-i_c[k])/a)-square(w)*((square(i_c[k+1])+square(i_c[k]))/2)); Sn=Sn+S[k]; } printf("Error 2: %f\n", Sn); if (Sn<=S0){ S0=Sn; path[j][n]=value; } else{ deltacond=(double)exp(-(Sn-S0)); r=(double)random()/(double)RAND_MAX; if (deltacond>r){ S0=Sn; path[j][n]=value; } } } } S0=S_in; } for (int j=0; j<iterations; j++){ printf("Coordenadas del path %d\n", j); for (int n=0; n<N; n++){ printf("%0.3f\n", path[j][n]); } } }
double residualtime (omg_global_param omg_param) { double u; u = randomgen (0, 1); if (u < (2 * omg_param.min_sleep / (omg_param.max_journey_time + omg_param.min_journey_time))) return u * (omg_param.max_journey_time + omg_param.min_journey_time) / 2; else return omg_param.max_journey_time - sqrtf ((1 - u) * (pow (omg_param.max_journey_time, 2) - pow (omg_param.min_sleep, 2))); }
double initial_pause (omg_global_param omg_param) { double u; u = randomgen (0, 1); if (u < (2 * omg_param.min_sleep / (omg_param.max_sleep + omg_param.min_sleep))) return u * (omg_param.max_sleep + omg_param.min_sleep) / 2; else return omg_param.max_sleep - sqrtf ((1 - u) * (pow (omg_param.max_sleep, 2) - pow (omg_param.min_sleep, 2))); }
void move_rwp_node (pair_struct * pair, double cur_time) { int loc_num; double distance, journeytime_next; double pr, block_xmin, block_ymin; //LOG_D (OMG, "[RWP] move node: %d\n", node->ID); node_struct *node; node = pair->b; node->mob->x_from = node->mob->x_to; node->mob->y_from = node->mob->y_to; node->x_pos = node->mob->x_to; node->y_pos = node->mob->y_to; node->mobile = 1; if (omg_param_list[node->type].rwp_type == RESTIRICTED_RWP) { do { loc_num = (int) randomgen (0, omg_param_list[node->type].max_vertices); node->mob->x_to = (double) vertice_xpos (loc_num, omg_param_list[node->type]); node->mob->y_to = (double) vertice_ypos (loc_num, omg_param_list[node->type]); } while (node->mob->x_to == node->mob->x_from && node->mob->y_to == node->mob->y_from); distance = fabs (node->mob->x_to - node->mob->x_from) + fabs (node->mob->y_to - node->mob->y_from); /* LOG_D(OMG,"#location number %d x pos to %.2f y pos to %.2f x pos from %.2f y pos from %.2f\n\n",loc_num,node->mob->x_to,node->mob->y_to,node->mob->x_from,node->mob->y_from); */ } else if (omg_param_list[node->type].rwp_type == CONNECTED_DOMAIN) { pr = randomgen (0, 1); if (pr <= 0.50) /*node->block_num = (int) randomgen (0, omg_param_list[node->type].max_block_num); */ node->block_num = (int) next_block (node->block_num, omg_param_list[node->type]); block_xmin = area_minx (node->block_num, omg_param_list[node->type]); block_ymin = area_miny (node->block_num, omg_param_list[node->type]); node->mob->x_to = (double) ((int) (randomgen (block_xmin, xloc_div + block_xmin) * 100)) / 100; node->mob->y_to = (double) ((int) (randomgen (block_ymin, yloc_div + block_ymin) * 100)) / 100; distance = (double) ((int) (sqrtf (pow (node->mob->x_from - node->mob->x_to, 2) + pow (node->mob->y_from - node->mob->y_to, 2)) * 100)) / 100; node->mob->azimuth = atan2 (node->mob->y_to - node->mob->y_from, node->mob->x_to - node->mob->x_from); //radian } else { node->mob->x_to = (double) ((int) (randomgen (omg_param_list[node->type].min_x, omg_param_list[node->type].max_x) * 100)) / 100; node->mob->y_to = (double) ((int) (randomgen (omg_param_list[node->type].min_y, omg_param_list[node->type].max_y) * 100)) / 100; distance = (double) ((int) (sqrtf (pow (node->mob->x_from - node->mob->x_to, 2) + pow (node->mob->y_from - node->mob->y_to, 2)) * 100)) / 100; node->mob->azimuth = atan2 (node->mob->y_to - node->mob->y_from, node->mob->x_to - node->mob->x_from); //radian } node->mob->speed = (double) ((int) (randomgen (omg_param_list[node->type].min_speed, omg_param_list[node->type].max_speed) * 100)) / 100; journeytime_next = (double) ((int) (distance / node->mob->speed * 100)) / 100; //duration to get to dest /* LOG_D (OMG, "#[RWP] %d mob->journey_time_next %.2f distance %.2f speed %.2f\n \n",node->id, journeytime_next, distance,node->mob->speed); */ node->mob->start_journey = cur_time; //LOG_D (OMG, "[RWP] start_journey %.2f\n", node->mob->start_journey); pair->next_event_t = cur_time + journeytime_next; //when to reach the destination // LOG_D (OMG, // "[RWP] reaching the destination at time : start journey + journey_time next =%.2f\n", // pair->a); /* if (node->event_num < 100) { event_sum[node->event_num] += node->mob->speed; events[node->event_num]++; node->event_num++; } */ }
int start_rwalk_generator (omg_global_param omg_param_list) { int id; static int n_id = 0; double cur_time = 0.0, pause_p, mean_pause, mean_travel; node_struct *node = NULL; mobility_struct *mobility = NULL; pair_struct *pair = NULL; srand (omg_param_list.seed + RWALK); mean_pause = (omg_param_list.max_sleep - omg_param_list.min_sleep) / 2; mean_travel = (omg_param_list.max_journey_time - omg_param_list.min_journey_time) / 2; pause_p = mean_pause / (mean_travel + mean_pause); LOG_I (OMG, "#RWALK mobility model for %d %d nodes\n", omg_param_list.nodes, omg_param_list.nodes_type); for (id = n_id; id < (omg_param_list.nodes + n_id); id++) { node = create_node (); mobility = create_mobility (); node->id = id; node->type = omg_param_list.nodes_type; node->mob = mobility; node->generator = RWALK; node->event_num = 0; place_rwalk_node (node); //initial positions pair = (pair_struct *) malloc (sizeof (struct pair_struct)); pair->b = node; // sleep_rwalk_node (pair, cur_time); //sleep //pause probability...some of the nodes start at pause & the other on move if (randomgen (0, 1) < pause_p) sleep_steadystaterwp_node (pair, cur_time); //sleep else move_steadystaterwp_node (pair, cur_time); job_vector_end[RWALK] = add_job (pair, job_vector_end[RWALK]); if (job_vector[RWALK] == NULL) job_vector[RWALK] = job_vector_end[RWALK]; job_vector_len[RWALK]++; } n_id += omg_param_list.nodes; if (job_vector[RWALK] == NULL) LOG_E (OMG, "[RWP] Job Vector is NULL\n"); return (0); }
void move_rwalk_node (pair_struct * pair, double cur_time) { double distance, x_next, y_next, journeytime_next; int i = 0; double dx, dy, x_now, y_now; double alpha, distancex, distancey; node_struct *node; node = pair->b; //LOG_D (OMG, "MOVE RWALK NODE ID: %d\n", node->ID); node->mob->x_from = node->mob->x_to; node->mob->y_from = node->mob->y_to; node->x_pos = node->mob->x_to; node->y_pos = node->mob->y_to; node->mobile = 1; node->mob->speed = randomgen (omg_param_list[node->type].min_speed, omg_param_list[node->type].max_speed); node->mob->azimuth = randomgen (omg_param_list[node->type].min_azimuth, omg_param_list[node->type].max_azimuth); if (node->event_num == 0) { node->mob->journey_time = residualtime (omg_param_list[node->type]); node->event_num++; } else { node->mob->journey_time = randomgen (omg_param_list[node->type].min_journey_time, omg_param_list[node->type].max_journey_time); } distance = node->mob->speed * node->mob->journey_time; dx = distance * cos (node->mob->azimuth * M_PI / 180); dy = distance * sin (node->mob->azimuth * M_PI / 180); x_next = (double) ((int) ((node->mob->x_from + dx) * 100)) / 100; y_next = (double) ((int) ((node->mob->y_from + dy) * 100)) / 100; /* LOG_D(OMG,"#node %d X FROM %.2f x next %.2f Y FROM %.2f y next %.2f \n\n",node->id,node->mob->x_from,x_next, node->mob->y_from,y_next); */ alpha = (node->mob->azimuth * M_PI / 180); //in radian x_now = node->mob->x_from; y_now = node->mob->y_from; while (true) { if (x_next < omg_param_list[node->type].min_x) { distancex = (omg_param_list[node->type].min_x - x_now) / cos (alpha); } else if (x_next > omg_param_list[node->type].max_x) { distancex = (omg_param_list[node->type].max_x - x_now) / cos (alpha); } else { distancex = distance; } if (y_next < omg_param_list[node->type].min_y) { distancey = (omg_param_list[node->type].min_y - y_now) / sin (alpha); } else if (y_next > omg_param_list[node->type].max_y) { distancey = (omg_param_list[node->type].max_y - y_now) / sin (alpha); } else { distancey = distance; } if ((distancex == distance && distancey == distance)) break; if (distancey < distancex) { x_now = distancey * cos (alpha) + x_now; y_now = distancey * sin (alpha) + y_now; distance = distance - distancey; dx = distance * cos (2 * M_PI - alpha); dy = distance * sin (2 * M_PI - alpha); x_next = x_now + dx; y_next = y_now + dy; alpha = 2 * M_PI - alpha; } else if (distancex < distancey) { x_now = distancex * cos (alpha) + x_now; y_now = distancex * sin (alpha) + y_now; distance = distance - distancex; dx = distance * cos (M_PI - alpha); dy = distance * sin (M_PI - alpha); x_next = x_now + dx; y_next = y_now + dy; alpha = M_PI - alpha; } i++; } node->mob->x_to = x_next; node->mob->y_to = y_next; /*LOG_D(OMG,"#node %d x to %.2f y to %.2f \n\n",node->id,node->mob->x_to,node->mob->y_to); node->mob->start_journey = cur_time; */ journeytime_next = (double) ((int) (distance / node->mob->speed * 100)) / 100; pair->next_event_t = (double) ((int) ((node->mob->start_journey + journeytime_next) * 100)) / 100; if (node->event_num < 100) { event_sum[node->event_num] += node->mob->speed; events[node->event_num]++; node->event_num++; } }
void move_steadystaterwp_node (pair_struct * pair, double cur_time) { static int initial = 1; double distance, journeytime_next, max_distance; double temp_x, temp_y, u1, u2; int loc_num; double pr, block_xmin, block_ymin; //LOG_D (OMG, "[STEADY_RWP] move node: %d\n", node->ID); node_struct *node; node = pair->b; node->mob->x_from = node->mob->x_to; node->mob->y_from = node->mob->y_to; node->x_pos = node->mob->x_to; node->y_pos = node->mob->y_to; node->mobile = 1; //initial move if (node->event_num == 0) { if (grid == CONNECTED_DOMAIN) { max_distance = 2 * yloc_div; /* sqrtf (pow (omg_param_list[node->type].max_x - omg_param_list[node->type].min_x, 2) + pow (omg_param_list[node->type].max_y - omg_param_list[node->type].min_y, 2)); */ while (true) { pr = randomgen (0, 1); if (pr <= 0.50) /*node->block_num = (int) randomgen (0, omg_param_list[node->type].max_block_num); */ node->block_num = (int) next_block (node->block_num, omg_param_list[node->type]); block_xmin = area_minx (node->block_num, omg_param_list[node->type]); block_ymin = area_miny (node->block_num, omg_param_list[node->type]); node->mob->x_to = (double) ((int) (randomgen (block_xmin, xloc_div + block_xmin) * 100)) / 100; node->mob->y_to = (double) ((int) (randomgen (block_ymin, yloc_div + block_ymin) * 100)) / 100; pr = randomgen (0, 1); if (pr <= 0.50) /*node->block_num = (int) randomgen (0, omg_param_list[node->type].max_block_num); */ node->block_num = (int) next_block (node->block_num, omg_param_list[node->type]); block_xmin = area_minx (node->block_num, omg_param_list[node->type]); block_ymin = area_miny (node->block_num, omg_param_list[node->type]); temp_x = (double) ((int) (randomgen (block_xmin, xloc_div + block_xmin) * 100)) / 100; temp_y = (double) ((int) (randomgen (block_ymin, yloc_div + block_ymin) * 100)) / 100; u1 = randomgen (0, 1); if (u1 < (sqrtf (pow (node->mob->x_to - temp_x, 2) + pow (node->mob->y_to - temp_y, 2)) / max_distance)) { u2 = randomgen (0, 1); distance = (double) ((int) (sqrtf (pow (temp_x - node->mob->x_to, 2) + pow (temp_y - node->mob->y_to, 2)) * 100)) / 100; node->mob->azimuth = atan2 (node->mob->y_to - node->mob->y_from, node->mob->x_to - node->mob->x_from); //radian node->mob->x_from = temp_x + u2 * distance * cos (node->mob->azimuth); node->mob->y_from = temp_y + u2 * distance * sin (node->mob->azimuth); break; } } } else { max_distance = sqrtf (pow (omg_param_list[node->type].max_x - omg_param_list[node->type].min_x, 2) + pow (omg_param_list[node->type].max_y - omg_param_list[node->type].min_y, 2)); while (true) { node->mob->x_to = (double) ((int) (randomgen (omg_param_list[node->type].min_x, omg_param_list[node->type].max_x) * 100)) / 100; node->mob->y_to = (double) ((int) (randomgen (omg_param_list[node->type].min_y, omg_param_list[node->type].max_y) * 100)) / 100; temp_x = (double) ((int) (randomgen (omg_param_list[node->type].min_x, omg_param_list[node->type].max_x) * 100)) / 100; temp_y = (double) ((int) (randomgen (omg_param_list[node->type].min_y, omg_param_list[node->type].max_y) * 100)) / 100; u1 = randomgen (0, 1); if (u1 < (sqrtf (pow (node->mob->x_to - temp_x, 2) + pow (node->mob->y_to - temp_y, 2)) / max_distance)) { u2 = randomgen (0, 1); node->mob->x_from = u2 * temp_x + (1 - u2) * node->mob->x_to; node->mob->y_from = u2 * temp_y + (1 - u2) * node->mob->y_to; break; } } } node->mob->speed = initial_speed (omg_param_list[node->type]); node->event_num++; distance = (double) ((int) (sqrtf (pow (node->mob->x_from - node->mob->x_to, 2) + pow (node->mob->y_from - node->mob->y_to, 2)) * 100)) / 100; } //for the next move else { if (grid == CONNECTED_DOMAIN) { pr = randomgen (0, 1); if (pr <= 0.50) /* node->block_num = (int) randomgen (0, omg_param_list[node->type].max_block_num); */ node->block_num = (int) next_block (node->block_num, omg_param_list[node->type]); block_xmin = area_minx (node->block_num, omg_param_list[node->type]); block_ymin = area_miny (node->block_num, omg_param_list[node->type]); node->mob->x_to = (double) ((int) (randomgen (block_xmin, xloc_div + block_xmin) * 100)) / 100; node->mob->y_to = (double) ((int) (randomgen (block_ymin, yloc_div + block_ymin) * 100)) / 100; distance = (double) ((int) (sqrtf (pow (node->mob->x_from - node->mob->x_to, 2) + pow (node->mob->y_from - node->mob->y_to, 2)) * 100)) / 100; node->mob->azimuth = atan2 (node->mob->y_to - node->mob->y_from, node->mob->x_to - node->mob->x_from); } else { node->mob->x_to = (double) ((int) (randomgen (omg_param_list[node->type].min_x, omg_param_list[node->type].max_x) * 100)) / 100; node->mob->y_to = (double) ((int) (randomgen (omg_param_list[node->type].min_y, omg_param_list[node->type].max_y) * 100)) / 100; distance = (double) ((int) (sqrtf (pow (node->mob->x_from - node->mob->x_to, 2) + pow (node->mob->y_from - node->mob->y_to, 2)) * 100)) / 100; } node->mob->speed = (double) ((int) (randomgen (omg_param_list[node->type].min_speed, omg_param_list[node->type].max_speed) * 100)) / 100; node->event_num++; } journeytime_next = (double) ((int) (distance / node->mob->speed * 100)) / 100; //duration to get to dest //LOG_D (OMG, "[STEADY_RWP] mob->journey_time_next %.2f\n", journeyTime_next); node->mob->start_journey = cur_time; //LOG_D (OMG, "[STEADY_RWP] start_journey %.2f\n", node->mob->start_journey); pair->next_event_t = cur_time + journeytime_next; //when to reach the destination // LOG_D (OMG, // "[STEADY_RWP] reaching the destination at time : start journey + journey_time next =%.2f\n", // pair->a); if (node->event_num < 100) { event_sum[node->event_num] += node->mob->speed; events[node->event_num]++; node->event_num++; } }
/*set new mobility for a node*/ void set_new_mob_type (int id, int node_t, int mob_t, double cur_time) { int prev_mob; node_list *tmp; //job_list *tmp2, *prev_job; pair_struct *pair; double pause_p; //find previous mobility type tmp = node_vector[node_t]; while (tmp != NULL) { if (tmp->node->id == id && tmp->node->type == node_t) { prev_mob = tmp->node->generator; break; } tmp = tmp->next; } //end if (tmp != NULL && prev_mob != mob_t) { //initialize node position if (mob_t == STATIC || mob_t == RWP || mob_t == RWALK || mob_t == STEADY_RWP) { tmp->node->x_pos = (double) ((int) (randomgen (omg_param_list[node_t].min_x, omg_param_list[node_t].max_x) * 100)) / 100; tmp->node->mob->x_from = tmp->node->x_pos; tmp->node->mob->x_to = tmp->node->x_pos; tmp->node->y_pos = (double) ((int) (randomgen (omg_param_list[node_t].min_y, omg_param_list[node_t].max_y) * 100)) / 100; tmp->node->mob->y_from = tmp->node->y_pos; tmp->node->mob->y_to = tmp->node->y_pos; tmp->node->mob->speed = 0.0; tmp->node->generator = mob_t; if (prev_mob != STATIC) job_vector[prev_mob] = remove_job (job_vector[prev_mob], id, node_t); } //end switch (mob_t) { case STATIC: break; case RWP: pair = (pair_struct *) malloc (sizeof (struct pair_struct)); pair->b = tmp->node; sleep_rwp_node (pair, cur_time); job_vector[RWP] = addjob (pair, job_vector[RWP]); break; case RWALK: pair = (pair_struct *) malloc (sizeof (struct pair_struct)); pair->b = tmp->node; sleep_rwalk_node (pair, cur_time); job_vector[RWALK] = addjob (pair, job_vector[RWALK]); break; case STEADY_RWP: tmp->node->event_num = 0; pair = (pair_struct *) malloc (sizeof (struct pair_struct)); pair->b = tmp->node; pause_p = pause_probability (omg_param_list[node_t]); if (randomgen (0, 1) < pause_p) sleep_steadystaterwp_node (pair, cur_time); else move_steadystaterwp_node (pair, cur_time); break; #ifdef SUMO_IF case SUMO: LOG_E (OMG, "not possible to change mobility type to sumo \n"); break; #endif case TRACE: LOG_E (OMG, "not possible to change mobility type to trace \n"); break; default: LOG_E (OMG, " Unsupported generator \n"); } } }