Skip to content

Commit

Permalink
Added the computation of average loss rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Dunkels committed Feb 26, 2011
1 parent f0c2734 commit f7d0b79
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions tools/csc/csc-compute-neighbor-stats
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ while(<STDIN>) {
if(/\<transmitting_range\>([\d.]+)\<\//) {
$range = $1;
}
if(/\<success_ratio_rx\>([\d.]+)\<\//) {
$success_ratio_rx = $1;
}

if(/\<x\>([\d.]+)\</) {
$x[$num] = $1;
Expand All @@ -18,7 +21,6 @@ while(<STDIN>) {
$num++;
}
}
print "Range $range num $num override range $override_range\n";

if($override_range) {
$range = $override_range;
Expand All @@ -27,15 +29,26 @@ if($override_range) {
$no_neighbors = 0;
$all_neighbors = 0;
$total_neighbors = 0;
# Go through all nodes, find how many are in their range.

# Go through all nodes, find how many are in their range and compute
# the average reception probability. Make sure we only count each neighbor once.
for($i = 0; $i < $num; $i++) {
$neighbors = 0;
for($j = 0; $j < $num; $j++) {
if($i != $j) {
if(($x[$i] - $x[$j]) * ($x[$i] - $x[$j]) +
($y[$i] - $y[$j]) * ($y[$i] - $y[$j]) <=
$range * $range) {
$distance2 = ($x[$i] - $x[$j]) * ($x[$i] - $x[$j]) +
($y[$i] - $y[$j]) * ($y[$i] - $y[$j]);
$range2 = $range * $range;
if($distance2 <= $range2) {
$neighbors++;

$ratio = $distance2 / $range2;
if($ratio > 1) {
$reception_probability = 0;
} else {
$reception_probability = 1 - $ratio * (1 - $success_ratio_rx);
}
$reception_probability_sum += $reception_probability;
}
}
}
Expand All @@ -47,8 +60,16 @@ for($i = 0; $i < $num; $i++) {
}
$total_neighbors += $neighbors;
}
print "Num nodes $num, average neighbors " . ($total_neighbors / $num) .

print "$num $range " . ($total_neighbors / $num) .
" " . ($no_neighbors / $num) .
" " . ($all_neighbors / $num) .
" " . ($reception_probability_sum / $total_neighbors) .
"\n";
print "# Range $range number of nodes $num override range $override_range\n";
print "# Num nodes $num, average neighbors " . ($total_neighbors / $num) .
", $no_neighbors nodes (" . (100 * $no_neighbors / $num) .
"%) have no neighbors, $all_neighbors (" . (100 * $all_neighbors / $num) .
"%) have all nodes as neighbors\n";

"%) have all other nodes as neighbors\n";
print "# Average reception probability " .
($reception_probability_sum / $total_neighbors) . "\n";

0 comments on commit f7d0b79

Please sign in to comment.