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]++;
}
Exemple #2
0
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++;
    }
   */
}
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++;
  }

}