⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 col-line.c

📁 Service Location Protocol
💻 C
📖 第 1 页 / 共 2 页
字号:
    startEventRefPt[g*nodesPerGroup] = startTime;    nextEventNode[g*nodesPerGroup] = startTime;    if (movingNode[g*nodesPerGroup])    {      if (horizontal)      {        newX = xDestRefPt[g*nodesPerGroup] = xLocRefPt[g*nodesPerGroup];        newY = yDestRefPt[g*nodesPerGroup] = getRand()*maxY;      } else {        newX = xDestRefPt[g*nodesPerGroup] = getRand()*maxX;        newY = yDestRefPt[g*nodesPerGroup] = yLocRefPt[g*nodesPerGroup];      }      dist = sqrt((newX-xLocRefPt[g*nodesPerGroup])*(newX-xLocRefPt[g*nodesPerGroup]) +                   (newY-yLocRefPt[g*nodesPerGroup])*(newY-yLocRefPt[g*nodesPerGroup]));      speed = speedRefPt[g*nodesPerGroup] = getRand()*speedRange + speedLow;      nextEventRefPt[g*nodesPerGroup] = startTime + dist/speed;      // now pick an intermediate move for the actual node      shortMove(g*nodesPerGroup, startTime);    } else {      speed = 0.0;      pauseTime = getRand()*pauseRange + pauseLow;      xDestRefPt[g*nodesPerGroup] = xLocRefPt[g*nodesPerGroup];      yDestRefPt[g*nodesPerGroup] = yLocRefPt[g*nodesPerGroup];      nextEventNode[g*nodesPerGroup] = nextEventRefPt[g*nodesPerGroup] = startTime + pauseTime;    }    if (horizontal)    {      xSep = refPtSep;      ySep = 0.0;    } else {      xSep = 0.0;      ySep = refPtSep;    }    for (n=1; n<nodesPerGroup; n++)    {      /* movingNode[g*nodesPerGroup+n] = movingRefPt[g*nodesPerGroup+n] = (getRand()>=0.5)?true:false; */      /* all group member nodes have the same moving status as the group reference point (node 0) */      movingNode[g*nodesPerGroup+n] = movingRefPt[g*nodesPerGroup+n] = movingRefPt[g*nodesPerGroup];      /* then their positions are relative to the one before them */      xLocNode[g*nodesPerGroup+n] = xLocRefPt[g*nodesPerGroup+(n-1)] + (getRand()*mult*xSep);      if (xLocNode[g*nodesPerGroup+n] < minX) xLocNode[g*nodesPerGroup+n] = minX;      if (xLocNode[g*nodesPerGroup+n] >= maxX) xLocNode[g*nodesPerGroup+n] = maxX-ZERO;      xLocRefPt[g*nodesPerGroup+n] = xLocNode[g*nodesPerGroup+n];      yLocNode[g*nodesPerGroup+n] = yLocRefPt[g*nodesPerGroup+(n-1)] + (getRand()*mult*ySep);      if (yLocNode[g*nodesPerGroup+n] < minY) yLocNode[g*nodesPerGroup+n] = minY;      if (yLocNode[g*nodesPerGroup+n] > maxY) yLocNode[g*nodesPerGroup+n] = maxY;      yLocRefPt[g*nodesPerGroup+n] = yLocNode[g*nodesPerGroup+n];      startEventRefPt[g*nodesPerGroup+n] = startTime;      nextEventNode[g*nodesPerGroup+n] = startTime;      if (movingNode[g*nodesPerGroup+n])      {        xDestRefPt[g*nodesPerGroup+n] = xDestRefPt[g*nodesPerGroup+(n-1)] + (getRand()*mult*xSep);        if (xDestRefPt[g*nodesPerGroup+n] < minX) xDestRefPt[g*nodesPerGroup+n] = minX;        if (xDestRefPt[g*nodesPerGroup+n] >= maxX) xDestRefPt[g*nodesPerGroup+n] = maxX-ZERO;        newX = xDestRefPt[g*nodesPerGroup+n];        yDestRefPt[g*nodesPerGroup+n] = yDestRefPt[g*nodesPerGroup+(n-1)] + (getRand()*mult*ySep);        if (yDestRefPt[g*nodesPerGroup+n] < minY) yDestRefPt[g*nodesPerGroup+n] = minY;        if (yDestRefPt[g*nodesPerGroup+n] >= maxY) yDestRefPt[g*nodesPerGroup+n] = maxY-ZERO;        newY = yDestRefPt[g*nodesPerGroup+n];        dist = sqrt((newX-xLocRefPt[g*nodesPerGroup+n])*(newX-xLocRefPt[g*nodesPerGroup+n]) +                     (newY-yLocRefPt[g*nodesPerGroup+n])*(newY-yLocRefPt[g*nodesPerGroup+n]));        speed = speedRefPt[g*nodesPerGroup+n] = speedRefPt[g*nodesPerGroup];        nextEventRefPt[g*nodesPerGroup+n] = startTime + dist/speed;        // now pick an intermediate move for the actual node        shortMove(g*nodesPerGroup+n, startTime);      } else {        speed = 0.0;        xDestRefPt[g*nodesPerGroup+n] = xLocRefPt[g*nodesPerGroup+n];        yDestRefPt[g*nodesPerGroup+n] = yLocRefPt[g*nodesPerGroup+n];        nextEventNode[g*nodesPerGroup+n] = nextEventRefPt[g*nodesPerGroup+n] = startTime + pauseTime;      }    }  }  for (g=0; g<numGroups; g++)  {     fprintf(stdout, "#\t### Group %d ###\n", g);    fprintf(stdout, "#\tGroup %d:  %s moving\n", g, ((movingNode[g*nodesPerGroup])?"is":"is not"));    for (n=0; n<nodesPerGroup; n++)    {      /* fprintf(stdout, "#\t(group,node) (%d,%d):  %s moving\n", g, n, ((movingNode[g*nodesPerGroup+n])?"is not":"is")); */      if (output == 'N')      {        fprintf(stdout, "$node_(%d) set X_ %.12f\n", g*nodesPerGroup+n+nodeIDstart, xLocNode[g*nodesPerGroup+n]);        fprintf(stdout, "$node_(%d) set Y_ %.12f\n", g*nodesPerGroup+n+nodeIDstart, yLocNode[g*nodesPerGroup+n]);        fprintf(stdout, "$node_(%d) set Z_ %.12f\n", g*nodesPerGroup+n+nodeIDstart, 0.0);      } else if (output == 'G') {        /* xLocNode[g*nodesPerGroup+n] = maxX/2.0; */        /* yLocNode[g*nodesPerGroup+n] = maxY/2.0; */        fprintf(stdout, "%d %.10f %.12f %.12f\n", g*nodesPerGroup+n+nodeIDstart, startTime,                         xLocNode[g*nodesPerGroup+n], yLocNode[g*nodesPerGroup+n]);      }    }    if (output == 'N')    {      fprintf(stdout, "\n");    }  }  if (output == 'N')  {    fprintf(stdout, "\n\n#\tMovements:\n");  }  /* find lowest */  lowest = endTime + 1.0;  for (i=0; i<(numGroups*nodesPerGroup); i++)  {    if (nextEventNode[i] <= lowest)    {      lowest = nextEventNode[i];      nextNode = i;      g = i/nodesPerGroup;      n = i%nodesPerGroup;    } /* if (nextEvent[i] <= lowest) */  } /* for (i=0; i<numGroups; i++) */  while (lowest <= endTime)  {    /* schedule the next event */    if (movingNode[nextNode])    {      /*         1) find out if group ref. pt. is done moving         2) if so, stop all group members and set all their next events to current + pause time         3) if not, just schedule another movement, but use updated node ref pt position      */      if (lowest >= nextEventRefPt[g*nodesPerGroup])      {        //fprintf(stdout,"#\tTook the first branch at time %lf\n", lowest);        /* the current time (lowest) is greater than the group reference point's next time,           so the group reference point is done moving */        /* stop all nodes and reference points in the group and pause them for the same time */        pauseTime = getRand()*pauseRange + pauseLow;        for (i=(g*nodesPerGroup); i<(g*nodesPerGroup + nodesPerGroup); i++)        {          movingNode[i] = movingRefPt[i] = false;          speed = 0.0;          if (output == 'N')          {            if (xLocNode[i] < minX) xLocNode[i] = minX;            if (xLocNode[i] >= maxX) xLocNode[i] = maxX-ZERO;            if (yLocNode[i] < minY) yLocNode[i] = minY;            if (yLocNode[i] >= maxY) yLocNode[i] = maxY-ZERO;            fprintf(stdout, "$ns_ at %.12f \"$node_(%d) setdest %.12f %.12f %.12f\"\n",                             nextEventNode[i], i+nodeIDstart, xLocNode[i], yLocNode[i], speed);          }          startEventRefPt[i] = nextEventRefPt[i];          nextEventNode[i] = nextEventRefPt[i] = lowest + pauseTime;        }      } else {        /* the group reference point is not done moving, so pick a new move for this node           relative to it's reference point's current location */        shortMove(nextNode, lowest);      }    } else /* not moving */ {      /*         pause time must have expired, so...         1) pick a new group ref pt destination         2) pick new node ref pt destinations based on grp ref pt dest         3) get all nodes moving according to their ref pt motion         4) be sure to set ref pt dest and ref pt loc correctly            - ref pt dest is final reference point destination            - ref pt loc is the future location of ref pt at the next event for node      */      /* pick a new destination for the group reference point */      movingNode[g*nodesPerGroup] = movingRefPt[g*nodesPerGroup] = true;      newX = xDestRefPt[g*nodesPerGroup] = getRand()*maxX;      newY = yDestRefPt[g*nodesPerGroup] = getRand()*maxY;      speed = speedRefPt[g*nodesPerGroup] = getRand()*speedRange + speedLow;      dist = sqrt((newX-xLocRefPt[g*nodesPerGroup])*(newX-xLocRefPt[g*nodesPerGroup]) +                   (newY-yLocRefPt[g*nodesPerGroup])*(newY-yLocRefPt[g*nodesPerGroup]));      /* startEventRefPt[g*nodesPerGroup] = nextEventRefPt[g*nodesPerGroup]; */      startEventRefPt[g*nodesPerGroup] = lowest;      nextEventRefPt[g*nodesPerGroup] = lowest + dist/speed;      if (fabs(newX - xLocRefPt[g*nodesPerGroup]) <= zero)      {        direction = atan(infinity);      } else {        direction = atan((newY-yLocRefPt[g*nodesPerGroup]) / (newX-xLocRefPt[g*nodesPerGroup]));      }      /* make the direction perpundicular */      //direction += PiOverTwo;      //mult = (newX > xLocRefPt[g*nodesPerGroup])?-1:1;      mult = 1;      xSep = cos(direction) * cos(direction) * refPtSep;      ySep = sin(direction) * sin(direction) * refPtSep;      /* pick new destinations for all the other reference points */      for (n=1; n<nodesPerGroup; n++)      {        /* all group member nodes have the same moving status as the group reference point (node 0) */        movingNode[g*nodesPerGroup+n] = movingRefPt[g*nodesPerGroup+n] = true;        xDestRefPt[g*nodesPerGroup+n] = xDestRefPt[g*nodesPerGroup+(n-1)] + (getRand()*mult*xSep);        if (xDestRefPt[g*nodesPerGroup+n] < minX) xDestRefPt[g*nodesPerGroup+n] = minX;        if (xDestRefPt[g*nodesPerGroup+n] >= maxX) xDestRefPt[g*nodesPerGroup+n] = maxX-ZERO;        newX = xDestRefPt[g*nodesPerGroup+n];        yDestRefPt[g*nodesPerGroup+n] = yDestRefPt[g*nodesPerGroup+(n-1)] + (getRand()*mult*ySep);        if (yDestRefPt[g*nodesPerGroup+n] < minY) yDestRefPt[g*nodesPerGroup+n] = minY;        if (yDestRefPt[g*nodesPerGroup+n] >= maxY) yDestRefPt[g*nodesPerGroup+n] = maxY-ZERO;        newY = yDestRefPt[g*nodesPerGroup+n];        //newX = xDestRefPt[g*nodesPerGroup+n] = minXdest + getRand()*(maxXdest - minXdest);        //newY = yDestRefPt[g*nodesPerGroup+n] = minYdest + getRand()*(maxYdest - minYdest);        speed = speedRefPt[g*nodesPerGroup+n] = speedRefPt[g*nodesPerGroup];        dist = sqrt((newX-xLocRefPt[g*nodesPerGroup+n])*(newX-xLocRefPt[g*nodesPerGroup+n]) +                     (newY-yLocRefPt[g*nodesPerGroup+n])*(newY-yLocRefPt[g*nodesPerGroup+n]));        /* startEventRefPt[g*nodesPerGroup+n] = nextEventRefPt[g*nodesPerGroup+n]; */        startEventRefPt[g*nodesPerGroup+n] = lowest;        nextEventRefPt[g*nodesPerGroup+n] = lowest + dist/speed;      }      /* now create and schedule short movements for all the nodes based on the reference points */      for (n=0; n<nodesPerGroup; n++)      {        shortMove(g*nodesPerGroup+n, lowest);      } /* for (n=0; n<nodesPerGroup; n++) */    } /* if (moving[nextNode]) */    /* find new lowest */    lowest = endTime + 1.0;    for (i=0; i<(numGroups*nodesPerGroup); i++)    {      if (nextEventNode[i] <= lowest)      {        lowest = nextEventNode[i];        nextNode = i;        g = i/nodesPerGroup;        n = i%nodesPerGroup;      } /* if (nextEvent[i] <= lowest) */    } /* for (i=0; i<numGroups; i++) */  } /* while (lowest <= endTime) */  if (output == 'N')  {    fprintf(stdout, "\n\n\n");  } else if (output == 'G') {    fprintf(stdout, "e\n\n");    fprintf(stdout, "set nomultiplot\n");  }  free(movingRefPt);  free(speedRefPt);  free(xLocRefPt);  free(yLocRefPt);  free(xDestRefPt);  free(yDestRefPt);  free(nextEventRefPt);  free(startEventRefPt);  free(movingNode);  free(xLocNode);  free(yLocNode);  free(nextEventNode);  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -