[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ns] ad-hockey displaying last node in the top-left corner



> >On Fri, 17 Aug 2001, Andronikos Nedos wrote:
> >
> >>Thanks for your reply. Looking at the source node of ad-hockey, I 
> >>managed to get it working after some minor modifications. 
> >>
> >
> >Got diffs?
> >
> >L.
> >
> >believes in solving a problem _once_.
> 
> Attached is the patch file generated by a diff -ur ,
>     - Andronikos

Aha, it's a good old off-by-one error leading to an extra node in the
corner (which might actually be a useful check that ad-hockey is
displaying all recorded nodes; if the last node is not in the corner,
something is wrong somewhere else...)

Forwarding diff to ns-users for the record. Andronikos described this
patch as against the latest ad-hockey, but since
ftp://ftp.monarch.cs.cmu.edu/pub/monarch/wireless-sim/ad-hockey
lacks a version number (it's currently 12 Oct 99 by datestamp), future
readers could well end up inspecting the code by hand...

cheers,

L.

do diffs. distribute diffs. develop.

<[email protected]>PGP<http://www.ee.surrey.ac.uk/Personal/L.Wood/>

--- ad-hockey.orig	Fri Aug 17 13:10:04 2001
+++ ad-hockey	Fri Aug 17 13:09:29 2001
@@ -356,7 +356,7 @@
 # - if the last record has a speed 0, just leave it, since it should still
 # work properly (cause no motion from then on)
     my ($i, $j);
-    for ($i = 1; $i <= $NN; $i++) {
+    for ($i = 0; $i < $NN; $i++) {
 	for ($j = 1; $j < $NUM_TIMES[$i] - 1; $j++) {
 	    if ($MOVE[$i]->[$j]->[$SPEED] == 0.0) {
 		# remove this record and make it a pause time entry on the next 1
@@ -391,7 +391,7 @@
 sub PrintMovements {
     my ($i, $j);
     print "num nodes $NN    X $MAXX     Y $MAXY \n";
-    for ($i = 1; $i <= $NN; $i++) {
+    for ($i = 0; $i < $NN; $i++) {
 	for ($j = 0; $j < $NUM_TIMES[$i]; $j++) {
 	    printf("%d: node $i time %f speed %f pt %f tox %f toy %f\n",
 		   $j,
@@ -447,7 +447,7 @@
     }
 
     my ($node, $wp);
-    for ($node = 1; $node <= $NN; $node ++) {
+    for ($node = 0; $node < $NN; $node ++) {
 	for ($wp = $NUM_TIMES[$node] - 1; $wp > 0; $wp--) {
 	    printf(SCEN '$ns_ at %.9f "$node_(%d) setdest %.9f %.9f %.9f"%s',
 		  $MOVE[$node]->[$wp]->[$TIME] + $MOVE[$node]->[$wp]->[$PT],
@@ -685,7 +685,7 @@
        -length => '7c',
        -command => sub {
 	   my $i;
-	   for ($i = 1; $i <= $NN ; $i++) {
+	   for ($i = 0; $i < $NN ; $i++) {
 	       $CANVAS->itemconfigure(node_marker_name($i), 
 				      -fill => $node_color);
 	   }
@@ -992,7 +992,7 @@
 sub CalculateNodeColors {
     my ($i);
     @node_color = ();
-    for ($i = 1; $i <= $NN; $i++) {
+    for ($i = 0; $i < $NN; $i++) {
 	$node_color[$i] = $node_color;
     }
     $node_color[$idcolor1_id->get()] = 'cyan';
@@ -1263,7 +1263,7 @@
 	$CANVAS->delete('cobweb');
     }
 
-    for ($i = 1; $i <= $NN ; $i++) {
+    for ($i = 0; $i < $NN ; $i++) {
 
 	($x, $y) = where_node($i, $time);
 	move_node($i, $x, $y);
@@ -1831,8 +1831,6 @@
 
 sub add_node {
 
-    # node numbers are 1 based, so we inc first, then setup
-    $NN++;
 
     my $index = $NUM_TIMES[$NN];
     $MOVE[$NN]->[$index]->[$TIME] = 0.0;
@@ -1843,6 +1841,10 @@
 
     display_waypoints($NN);
     $idscale->configure(-to => $NN);
+
+    #Update the node index at the end, since 0 based now (AZN) 
+    $NN++;
+
 };
 
 ###########################################################################
@@ -3662,7 +3664,7 @@
     $#NUM_TIMES = -1;
     $trace_loaded = 0;
     my $i;
-    for ($i = 1; $i <= $NN; $i++) {
+    for ($i = 0; $i < $NN; $i++) {
 	undisplay_waypoints($i);
 	if ($EDIT[$i]->{MW} != '') {
 	    $EDIT[$i]->{MW}->destroy();
@@ -3833,7 +3835,7 @@
     $#locations = 0; # clear location of all nodes
 
     # find the positions of all nodes
-    for ($i = 1 ; $i <= $NN ; $i++) {
+    for ($i = 0 ; $i < $NN ; $i++) {
 	@from_coords = $CANVAS->coords('n'.$i);
 	$locations[$i]->[0] =  $from_coords[0];
 	$locations[$i]->[1] =  $from_coords[1];