Troubleshooting and Analysis of simulation problems in leaching (1)

Source: Internet
Author: User

Simulation problem handling and analysis:

(Zz mentioned on the Internet directly uses test and leach_test carried by leaching)

(1) Open cygwin and enter the command startxwin. bat and press enter to enter X ~ Environment.

(2) Enter .. /Under the ns-2.27 directory

(3) then enter the command./Test

./Test to generate many files. The results are also in the mit/uAMPS/sims Folder: wireless. alive, wireless. energy, and wireless. data.
Wireless. the first line of alive is the running time, the second line is the node ID, and the third line records the node status. If it is 1, it indicates that the node is still alive. If it is 0, the node is killed. Other files have similar structures. After the simulation is complete, you need to analyze the results.

(4) Go To The leach_sims folder; Do not open those files of LEACH_ALIVE and just refresh them, check whether the files are being refreshed constantly when they become larger. (The refresh is to make it more intuitive to see the changes in the file. In fact, you don't have to refresh it yourself. TDMAschedule.240.txt files are also increasing to tdmaschedule.520.txt ended ), until it does not change. When a lot of TDMAschedule files are generated, the size of the LEACH_ALIVE file is about 47 k, which is not changed (waiting for 500 seconds). The specific number is only for reference. The most important thing is that it will be enough until it does not change.

(5) In the ns-allinone-2.27/ns-2.27/mit/leach_sims folder, we create a new test. awk file, and then copy the following code, use awk, write a script, extract the information you need, extract the leaching. the data information in the alive file.

{A ready-made awk script (from http://blog.baisi.net /? 105639/viewspace-3105 )}
"Begin {

Countcyl = 0; // counter record wheel ???? (Not sure if it is a round) Number
Totalleft = 0; // The counter temporarily records the total number of active nodes in the current time period (wheel)

Lasttime = 0; // record the current last time
Time [0] = 0; // time for storing each segment
Node = 0;
Total [0] = 100; // the initial value of the number of remaining nodes at each time point is 100.
}; # The code is executed before processing the data in the leaching. Alive mode. In fact, some data is initialized. Initialize the action after only one in operation (statement body)
{

Simtime = $1; // the value in the first column of the file, running time
Nodeid = $2; // value of the second column of the file, node ID
Statenode = $3; // value of the third column of the file, node status

If (simtime> lasttime ){
Countcyl ++;
Lasttime = simtime;
Time [countcyl] = simtime;
Totalleft = 0;
} // Assign the run time simtime of the current wheel to lasttime until the condition simtime> lasttime is met in the next round of simtime change, and execute the statement in curly brackets

If (statenode = 1)
Totalleft ++;
Total [countcyl] = totalleft;
}; # These codes are executed once for each line of the leaching. alive process. It means that the time [I] of the number of remaining nodes in the total [I] storage round I is the time value corresponding to the round I.
END {
For (I = 0; I <= countcyl; I ++)
Printf ("% f % d/n", time [I], total [I]);
}; # This code is executed after processing the last line of leaching. alive, where data is written to the output file.

Note: printf ("% f % d/n", time [I], total [I]);

Add a space between % f and % d!
(6) This AWK file is mainly used to process the leaching. alive file (we remember in the CD to the ns-allinone-2.27/ns-2.27/mit/leach_sims folder ,)

Run cd mit/leach_sims to enter the mit/leach_sims directory.

Then enter the command

Gawk-f test. awk leaching. alive> data. gnuplot this command uses the AWK file to process the files of the leaching. alive and store the processing results to data. gnuplot.

(7) The next step is my last step. Use gnuplot to draw images! Note: gnuplot is run in startxwin.

(Still unchanged under the directory just now (ns-allinone-2.27/ns-2.27/mit/leach_sims ,)

Enter the command gnuplot and press Enter.

Enter the command plot 'data. gnuplot 'with linespoints (w linesp short form) after gnuplot> and press enter to generate the following figure.

The simulation figure of the leaching is OK.


 

 

 

 

Resolution:

 

(1) If we change init_energy 2/to init_energy 10/

That is, the energy of the node has increased by 5 times! In 270 seconds, no node will die! Because they consume up to 2J of energy

(2) The X coordinate of the simulation image drawn by Data. gnuplot represents time, and the Y coordinate represents the total number of current nodes.

(3) We define one hundred nodes. In the first 270 seconds, the total number of nodes is always 100. Until the energy consumption of nodes is completed, the red point will be less than 100! Your figure shows a downward trend in the overall trend! It is in line with our inference! Therefore, this simulation is effective.

 

(4) Where the awk is modified

Printf ("% f % d/n", time [I], total [I]);

A space is added between % f and % d!

 

I would like to thank a good friend for his help. Many of the results have been obtained through our joint discussion.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.