Added the computation of average loss rate

This commit is contained in:
Adam Dunkels 2011-02-26 22:07:46 +01:00
parent f0c27340c6
commit f7d0b7908e

View file

@ -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;
@ -18,7 +21,6 @@ while(<STDIN>) {
$num++;
}
}
print "Range $range num $num override range $override_range\n";
if($override_range) {
$range = $override_range;
@ -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;
}
}
}
@ -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";