Пример #1
0
 // Vary node density and keep constant the fraction of n_source_nodes
 // 1044s per iteration at ee-modalap
 public static void averSize(int tst_nr, int n_averages, int plot)
 {
     Console.WriteLine("Executing {0}({1:d2},{2:d6},{3})", G.current(),
             tst_nr, n_averages, plot);
     double tx_rg = 2;
     double x = 2 * tx_rg;
     double[] y_v_n = new double[] {2, 3};// y vector normalized by tx_rg
     int[] types = new int[] {0, 3, 9};
     if (tst_nr == 1)
     {
         y_v_n = new double[] {2, 3, 4, 5, 6};
         types = new int[] {0, 1, 3, 4, 5, 9};
     }
     double[] y_v = new double[y_v_n.Length];
     for (int i = 0; i < y_v.Length; i++)
         y_v[i] = y_v_n[i] * tx_rg;
     double rho = 10;
     int sched_lgth = 20;
     int n_tx_frames = 5000;
     double infid_thresh = 0.15;
     // Parameters for the all-transmit-in-all approach: number of blocks
     // and packets per block.
     int blocks = 200;
     int n_packets = 8;
     // Number of tree reconfiguration cycles used to balance the energy
     // consumption.
     int n_tree_reconf = 5;
     int buffer_size = 30;
     G.VB = false;
     G.rx_consum = 0.001;
     double[,] consum_mean = new double[y_v.Length, types.Length];
     double[,] consum_median = new double[y_v.Length, types.Length];
     double[,] consum_max = new double[y_v.Length, types.Length];
     double[,] rate_min_v = new double[y_v.Length, types.Length - 1];
     for (int k = 0; k < n_averages; k++) {
         Console.WriteLine("Repetition {0,4:D}. Total {1}", k,
                 G.elapsed());
         for (int a = 0; a < y_v.Length; a++) {
             int n = (int)(rho * x * y_v[a] / Math.PI / tx_rg / tx_rg);
             int source_min = (int) (0.4 * (double) n);
             Console.WriteLine("Simulating {0:d} nodes", n);
             G.rgen = new Random(k);
             AverTree at = new AverTree(n, x, y_v[a], tx_rg);
             for (int d = 0; d < types.Length; d++) {
                 double[] tot_consum1 = new double[n];
                 G.rgen = new Random(k);
                 if (types[d] == 9) {
                     for (int h = 0; h < n_tree_reconf; h++) {
                         at.get_tree(tot_consum1);
                         LossTree e = new LossTree(at.fv, at.ps,
                                 buffer_size);
                         e.simulate_it2(blocks, n_packets, h);
                         for (int i = 0; i < n; i++)
                             tot_consum1[i] += e.nodes[i].consum /
                                 n_tree_reconf;
                     }
                 }
                 else {
                     for (int h = 0; h < n_tree_reconf; h++) {
                         double[] consum_old = new double[n];
                         double expon = 1.05;
                         for (double rate =0.1; ; rate *= expon) {
                             at.get_tree(tot_consum1);
                             LossTree t = new LossTree(at.fv, at.ps,
                                     buffer_size);
                             t.find_schedule(sched_lgth, source_min);
                             // This is supposed to show the optimal rate.
                             // Console.WriteLine(((double)t.count.Count /
                             // sched_lgth));
                             int [] results = t.simulate_it(n_tx_frames,
                                     rate, types[d], h);
                             // Fraction of reporting intervals with
                             // insufficient count
                             double infid_ratio = 0.0;
                             foreach (int m in results)
                                 if (m < source_min)
                                     infid_ratio +=
                                         1.0/(double)results.Length;
                             // This rate yields sufficiently low
                             // infid_ratio.  Record the consumption in
                             // case this is the last rate to yield
                             // sufficiently low infid_ratio.
                             if (infid_ratio < infid_thresh)
                                 for (int q = 0; q < n; q++)
                                     consum_old[q] = t.nodes[q].consum;
                             else {
                                 // Record statistics in permanent
                                 // variable This rate is the smallest
                                 // rate that is too high.  Record
                                 // consumption of the previous
                                 // iteration.
                                 rate_min_v[a,d] +=rate/expon/
                                     n_tree_reconf / n_averages;
                                 for (int r=0; r < n; r++)
                                     tot_consum1[r] += consum_old[r] /
                                         n_tree_reconf;
                                 break;
                             }
                         }
                     }
                 }
                 consum_mean[a,d] += G.Mean(tot_consum1) / n_averages;
                 consum_median[a,d] += G.Median(tot_consum1) / n_averages;
                 consum_max[a,d] += G.Max(tot_consum1) / n_averages;
             }
         }
     }
     string[] legv = new string[types.Length];
     for (int i = 0; i < types.Length; i++)
         legv[i] = types[i].ToString();
     Pgf g = new Pgf();
     string xaxis = "normalized y-v";
     g.add(xaxis, "consum-mean");
     g.mplot(y_v_n, consum_mean, legv);
     g.add(xaxis, "consum-median");
     g.mplot(y_v_n, consum_median, legv);
     g.add(xaxis, "consum-max");
     g.mplot(y_v_n, consum_max, legv);
     double[,] gain_mean = new double [y_v_n.Length, types.Length - 1];
     double[,] gain_median = new double [y_v_n.Length, types.Length -1];
     double[,] gain_max = new double [y_v_n.Length, types.Length - 1];
     int refz = types.Length - 1; // Column used as a benchmark
     for (int q = 0; q < y_v_n.Length; q++)
         for (int s = 0; s < types.Length - 1; s++)
         {
             gain_mean[q, s] = 100 * (consum_mean[q, refz] -
                     consum_mean[q, s]) / consum_mean[q, refz];
             gain_median[q, s] = 100 * (consum_median[q, refz] -
                     consum_median[q, s]) / consum_median[q, refz];
             gain_max[q, s] = 100 * (consum_max[q, refz] -
                     consum_max[q, s]) / consum_max[q, refz];
         }
     string[] legv2 = new string[types.Length - 1];
     for (int i = 0; i < types.Length - 1; i++)
             legv2[i] = types[i].ToString();
     g.add(xaxis, "normalized load");
     g.mplot(y_v_n, rate_min_v, legv2);
     g.add(xaxis, "gain-mean");
     g.mplot(y_v_n, gain_mean, legv2);
     g.add(xaxis, "gain-median");
     g.mplot(y_v_n, gain_median, legv2);
     g.add(xaxis, "gain-max");
     g.mplot(y_v_n, gain_max, legv2);
     g.add(xaxis, "max-rate");
     g.mplot(y_v_n, rate_min_v, legv2);
     string filename = String.Format("{0}_{1:d2}_{2:d6}", G.current(),
             tst_nr, n_averages);
     g.save(filename, plot);
     //Console.WriteLine("consum_mean   = {0,8:F3}   {1,8:F3}   {2,8:F3}",
     //        consum_mean[0], consum_mean[1], consum_mean[2]);
     //Console.WriteLine("consum_median = {0,8:F3}   {1,8:F3}   {2,8:F3}",
     //        consum_median[0], consum_median[1], consum_median[2]);
     //Console.WriteLine("consum_max    = {0,8:F3}   {1,8:F3}   {2,8:F3}",
     //        consum_max[0], consum_max[1], consum_max[2]);
 }
Пример #2
0
 // 438 seconds per iteration in ee-moda
 public static void averSource(int tst_nr, int n_averages, int plot)
 {
     Console.WriteLine("Executing {0}({1:d2},{2:d6},{3})", G.current(),
             tst_nr, n_averages, plot);
     double tx_rg = 2;
     double x = 3 * tx_rg;
     double y = 3 * tx_rg;
     double rho = 9;
     int n = (int)(rho * x * y / Math.PI / tx_rg / tx_rg);
     int sched_lgth = 20;
     int n_tx_frames = 5000;
     double infid_thresh = 0.15;
     // Parameters for the all-transmit-in-all approach: number of blocks
     // and packets per block.
     int blocks = 200;
     int n_packets = 8;
     int[] source_min_v = new int[] {3, 5, 8, 11, 14, 17, 20};
     Console.WriteLine("Simulating {0:d} nodes", n);
     // Number of tree reconfiguration cycles used to balance the energy
     // consumption.
     int n_tree_reconf = 5;
     int buffer_size = 30;
     int[] types = new int[] {0, 3, 9};
     G.VB = false;
     G.rx_consum = 0.001;
     double[,] consum_mean = new double[source_min_v.Length, 3];
     double[,] consum_median = new double[source_min_v.Length, 3];
     double[,] consum_max = new double[source_min_v.Length, 3];
     for (int k = 0; k < n_averages; k++)
     {
         Console.WriteLine("Repetition {0,4:D}. Total {1}", k,
                 G.elapsed());
         Console.WriteLine("                    Current time is {0}",
                 DateTime.Now.ToString("u"));
         G.rgen = new Random(k);
         AverTree at = new AverTree(n, x, y, tx_rg);
         for (int a = 0; a < source_min_v.Length; a++)
         {
             for (int d = 0; d < types.Length; d++)
             {
                 double[] tot_consum1 = new double[n];
                 G.rgen = new Random(k);
                 if (types[d] == 9)
                 {
                     for (int h = 0; h < n_tree_reconf; h++)
                     {
                         at.get_tree(tot_consum1);
                         LossTree e = new LossTree(at.fv, at.ps,
                                 buffer_size);
                         e.simulate_it2(blocks, n_packets, h);
                         for (int i = 0; i < n; i++)
                             tot_consum1[i] += e.nodes[i].consum /
                                 n_tree_reconf;
                     }
                 }
                 else
                 {
                     for (int h = 0; h < n_tree_reconf; h++)
                     {
                         double[] consum_old = new double[n];
                         for (double rate =0.1; ; rate *= 1.05)
                         {
                             at.get_tree(tot_consum1);
                             LossTree t = new LossTree(at.fv, at.ps,
                                     buffer_size);
                             t.find_schedule(sched_lgth, source_min_v[a]);
                             // This is supposed to show the optimal rate.
                             // Console.WriteLine(((double)t.count.Count /
                             // sched_lgth));
                             int [] results = t.simulate_it(n_tx_frames,
                                     rate, types[d], h);
                             // Fraction of reporting intervals with
                             // insufficient count
                             double infid_ratio = 0.0;
                             foreach (int m in results)
                             {
                                 if (m < source_min_v[a])
                                     infid_ratio
                                         +=1.0/(double)results.Length;
                             }
                             if (infid_ratio < infid_thresh)
                             {
                                 // This rate yields sufficiently low
                                 // infid_ratio.  Record the consumption in
                                 // case this is the last rate to yield
                                 // sufficiently low infid_ratio.
                                 for (int q = 0; q < n; q++)
                                     consum_old[q] = t.nodes[q].consum;
                             }
                             else
                             {
                                 // Record statistics in permanent
                                 // variable This rate is the smallest
                                 // rate that is too high.  Record
                                 // consumption of the previous
                                 // iteration.
                                 for (int r=0; r < n; r++)
                                     tot_consum1[r] += consum_old[r] /
                                         n_tree_reconf;
                                 break;
                             }
                         }
                     }
                 }
                 consum_mean[a,d] += G.Mean(tot_consum1) / n_averages;
                 consum_median[a,d] += G.Median(tot_consum1) / n_averages;
                 consum_max[a,d] += G.Max(tot_consum1) / n_averages;
             }
         }
     }
     string[] legv = new string[] {"0", "3", "9"};
     Pgf g = new Pgf();
     g.extra_body.Add(String.Format("\n\nThe number of nodes is {0:d}",
                 n));
     for (int i = 0; i < 2; i++)
     {
         string xaxis = "source.min";
         double[] xvec = new double[source_min_v.Length];
         if (i == 0)
             for (int q = 0; q < source_min_v.Length; q++)
                 xvec[q] = (double) source_min_v[q];
         else if (i == 1)
         {
             for (int q = 0; q < source_min_v.Length; q++)
                 xvec[q] = 100 * source_min_v[q] / (double) (n-1);
             xaxis = "percent source.min";
         }
         g.add(xaxis, "consum-mean");
         g.mplot(xvec, consum_mean, legv);
         g.add(xaxis, "consum-median");
         g.mplot(xvec, consum_median, legv);
         g.add(xaxis, "consum-max");
         g.mplot(xvec, consum_max, legv);
         double[,] gain_mean = new double [source_min_v.Length, 2];
         double[,] gain_median = new double [source_min_v.Length, 2];
         double[,] gain_max = new double [source_min_v.Length, 2];
         for (int q = 0; q < source_min_v.Length; q++)
             for (int s = 0; s < 2; s++)
             {
                 gain_mean[q, s] = 100 * (consum_mean[q, 2] -
                         consum_mean[q, s]) / consum_mean[q, 2];
                 gain_median[q, s] = 100 * (consum_median[q, 2] -
                         consum_median[q, s]) / consum_median[q, 2];
                 gain_max[q, s] = 100 * (consum_max[q, 2] -
                         consum_max[q, s]) / consum_max[q, 2];
             }
         string[] legv2 = new string[] {"0", "3"};
         g.add(xaxis, "gain-mean");
         g.mplot(xvec, gain_mean, legv2);
         g.add(xaxis, "gain-median");
         g.mplot(xvec, gain_median, legv2);
         g.add(xaxis, "gain-max");
         g.mplot(xvec, gain_max, legv2);
     }
     string filename = String.Format("{0}_{1:d2}_{2:d6}", G.current(),
                                     tst_nr, n_averages);
     g.save(filename, plot);
         //Console.WriteLine("consum_mean   = {0,8:F3}   {1,8:F3}
         //{2,8:F3}",
         //        consum_mean[0], consum_mean[1], consum_mean[2]);
         //Console.WriteLine("consum_median = {0,8:F3}   {1,8:F3}
         //{2,8:F3}",
         //        consum_median[0], consum_median[1], consum_median[2]);
         //Console.WriteLine("consum_max    = {0,8:F3}   {1,8:F3}
         //{2,8:F3}",
         //        consum_max[0], consum_max[1], consum_max[2]);
 }
Пример #3
0
 public static void averRxConsum(int tst_nr, int n_averages, int plot)
 {
     Console.WriteLine("Executing {0}({1:d2},{2:d6},{3})", G.current(),
             tst_nr, n_averages, plot);
     double tx_rg = 2;
     double x = 3 * tx_rg;
     double y = 3 * tx_rg;
     double rho = 9;
     int n = (int)(rho * x * y / Math.PI / tx_rg / tx_rg);
     int sched_lgth = 20;
     int n_tx_frames = 5000;
     double infid_thresh = 0.15;
     // Parameters for the all-transmit-in-all approach: number of blocks
     // and packets per block.
     int blocks = 200;
     int n_packets = 8;
     int source_min = 1;
     if (tst_nr == 0)
         source_min = 3;//(int) (n * 0.2);
     else if (tst_nr == 1)
         source_min = 5;
     else if (tst_nr == 2)
         source_min = 8;
     else
         throw new Exception("Invalid tst_nr");
     Console.WriteLine("source_min = {0:d}", source_min);
     Console.WriteLine("Simulating {0:d} nodes", n);
     // Number of tree reconfiguration cycles used to balance the energy
     // consumption.
     int n_tree_reconf = 5;
     double [] tx_factor_v = new double[] {0, 4, 8, 12, 16};
     double [] rx_consum_v = new double[tx_factor_v.Length];
     for (int i = 0; i < tx_factor_v.Length; i++)
     {
         rx_consum_v[i] = Math.Pow(10, - tx_factor_v[i] / 10);
         Console.WriteLine(rx_consum_v[i]);
     }
     int buffer_size = 30;
     int[] types = new int[] {0, 3, 9};
     G.VB = false;
     double[,] consum_mean = new double[rx_consum_v.Length, 3];
     double[,] consum_median = new double[rx_consum_v.Length, 3];
     double[,] consum_max = new double[rx_consum_v.Length, 3];
     for (int k = 0; k < n_averages; k++)
     {
         G.rgen = new Random(k);
         AverTree at = new AverTree(n, x, y, tx_rg);
         for (int a = 0; a < rx_consum_v.Length; a++)
         {
             G.rx_consum = rx_consum_v[a];
             for (int d = 0; d < types.Length; d++)
             {
                 double[] tot_consum1 = new double[n];
                 G.rgen = new Random(k);
                 if (types[d] == 9)
                 {
                     for (int h = 0; h < n_tree_reconf; h++)
                     {
                         at.get_tree(tot_consum1);
                         LossTree e = new LossTree(at.fv, at.ps,
                                 buffer_size);
                         e.simulate_it2(blocks, n_packets, h);
                         for (int i = 0; i < n; i++)
                             tot_consum1[i] += e.nodes[i].consum /
                                 n_tree_reconf;
                     }
                 }
                 else
                 {
                     for (int h = 0; h < n_tree_reconf; h++)
                     {
                         double[] consum_old = new double[n];
                         for (double rate =0.1; ; rate *= 1.05)
                         {
                             at.get_tree(tot_consum1);
                             LossTree t = new LossTree(at.fv, at.ps,
                                     buffer_size);
                             t.find_schedule(sched_lgth, source_min, false);
                             // This is supposed to show the optimal rate.
                             // Console.WriteLine(((double)t.count.Count /
                             // sched_lgth));
                             int [] results = t.simulate_it(n_tx_frames,
                                     rate, types[d], h);
                             // Fraction of reporting intervals with
                             // insufficient count
                             double infid_ratio = 0.0;
                             foreach (int m in results)
                             {
                                 if (m < source_min)
                                     infid_ratio
                                         +=1.0/(double)results.Length;
                             }
                             if (infid_ratio < infid_thresh)
                             {
                                 // This rate yields sufficiently low
                                 // infid_ratio.  Record the consumption in
                                 // case this is the last rate to yield
                                 // sufficiently low infid_ratio.
                                 for (int q = 0; q < n; q++)
                                     consum_old[q] = t.nodes[q].consum;
                             }
                             else
                             {
                                 // Record statistics in permanent
                                 // variable This rate is the smallest
                                 // rate that is too high.  Record
                                 // consumption of the previous
                                 // iteration.
                                 for (int r=0; r < n; r++)
                                     tot_consum1[r] += consum_old[r] /
                                         n_tree_reconf;
                                 break;
                             }
                         }
                     }
                 }
                 consum_mean[a,d] += G.Mean(tot_consum1) / n_averages;
                 consum_median[a,d] += G.Median(tot_consum1) / n_averages;
                 consum_max[a,d] += G.Max(tot_consum1) / n_averages;
             }
         }
     }
     string[] legv = new string[] {"0", "3", "9"};
     Pgf g = new Pgf();
     string xaxis = "$10\\,\\mathrm{log}_{10}(P_{tx}/P_{rx})$";
     g.add(xaxis, "consum-mean");
     g.mplot(tx_factor_v, consum_mean, legv);
     g.add(xaxis, "consum-median");
     g.mplot(tx_factor_v, consum_median, legv);
     g.add(xaxis, "consum-max");
     g.mplot(tx_factor_v, consum_max, legv);
     double[,] gain_mean = new double [rx_consum_v.Length, 2];
     double[,] gain_median = new double [rx_consum_v.Length, 2];
     double[,] gain_max = new double [rx_consum_v.Length, 2];
     for (int q = 0; q < rx_consum_v.Length; q++)
         for (int s = 0; s < 2; s++)
         {
             gain_mean[q, s] = 100 * (consum_mean[q, 2] -
                     consum_mean[q, s]) / consum_mean[q, 2];
             gain_median[q, s] = 100 * (consum_median[q, 2] -
                     consum_median[q, s]) / consum_median[q, 2];
             gain_max[q, s] = 100 * (consum_max[q, 2] -
                     consum_max[q, s]) / consum_max[q, 2];
         }
     string[] legv2 = new string[] {"0", "3"};
     g.add(xaxis, "gain-mean");
     g.mplot(tx_factor_v, gain_mean, legv2);
     g.add(xaxis, "gain-median");
     g.mplot(tx_factor_v, gain_median, legv2);
     g.add(xaxis, "gain-max");
     g.mplot(tx_factor_v, gain_max, legv2);
     string filename = String.Format("{0}_{1:d2}_{2:d6}", G.current(),
             tst_nr, n_averages);
     g.save(filename, plot);
     //Console.WriteLine("consum_mean   = {0,8:F3}   {1,8:F3}   {2,8:F3}",
     //        consum_mean[0], consum_mean[1], consum_mean[2]);
     //Console.WriteLine("consum_median = {0,8:F3}   {1,8:F3}   {2,8:F3}",
     //        consum_median[0], consum_median[1], consum_median[2]);
     //Console.WriteLine("consum_max    = {0,8:F3}   {1,8:F3}   {2,8:F3}",
     //        consum_max[0], consum_max[1], consum_max[2]);
 }