We compile the latex file on command line:
1) latex XXX.tex
2) bibtex XXX
Notice that there is no .tex here!
3) repeat to run command "latex XXX.tex" twice
4) dvips XXX.dvi
5) ps2pdf XXX.ps
6) A pdf file is created. :)
I am a Postdoctoral Research Fellow with The SUTD-MIT International Design Centre (IDC), Singapore University of Technology and Design (SUTD). My research topic is about protocol and algorithm design, resource allocation and localisation in wireless sensor network, UAV network and Ad Hoc network. I also enjoy the mobile programming (Android and Objective-C) and web server development. Thanks for sharing.
Sep 2, 2013
Aug 14, 2013
Edit a paper with LNCS format in Latex
Some paper may require LNCS format. You can download the package from http://www.springer.com/computer/lncs?SGWID=0-164-6-793341-0. Here I use llncs2e.zip and the sample file typeinst.zip.
You can import your latex file into the sample file "typeinst.tex". Notice that if your figures include subfigure, you need to add three packages:
\usepackage{caption}
\usepackage{subcaption}
\usepackage{subfig}
If it has some equations, add:
\usepackage[cmex10]{amsmath,mathtools}
\usepackage{mdwmath}
If it includes algorithm, add:
\usepackage{algorithm}
\usepackage{algorithmic}
Then, copy two files "llncs.cls" and "splncs.bst" (can also choose "splncs_srt.bst" or "splncs03.bst") from llncs2e folder to typeinst.
If the paper has some references generated by XXXX.bib file, then at the end of the paper, add:
\bibliographystyle{splncs}
\bibliography{XXXX}
After finish the editing, we just follow the previous tutorial (http://itantenna.blogspot.com.au/2013/08/compile-latex-file-with-eps-figures.html) to compile the latex file.
You can import your latex file into the sample file "typeinst.tex". Notice that if your figures include subfigure, you need to add three packages:
\usepackage{caption}
\usepackage{subcaption}
\usepackage{subfig}
If it has some equations, add:
\usepackage[cmex10]{amsmath,mathtools}
\usepackage{mdwmath}
If it includes algorithm, add:
\usepackage{algorithm}
\usepackage{algorithmic}
Then, copy two files "llncs.cls" and "splncs.bst" (can also choose "splncs_srt.bst" or "splncs03.bst") from llncs2e folder to typeinst.
If the paper has some references generated by XXXX.bib file, then at the end of the paper, add:
\bibliographystyle{splncs}
\bibliography{XXXX}
After finish the editing, we just follow the previous tutorial (http://itantenna.blogspot.com.au/2013/08/compile-latex-file-with-eps-figures.html) to compile the latex file.
Aug 13, 2013
Compile the latex file with eps figures
Sometimes we are required to use eps figures instead of pdf ones in the latex file. Here we show a method to compile your latex file by command line. Before this, please make sure you have installed latex editor.
1) Go to the directory which includes XXX.tex
2) type "latex XXX.tex" and we will see a XXX.dvi file is generated
3) then, type "dvips XXX.dvi" and a XXX.ps file is created
4) type "ps2pdf XXX.ps" and the PDF file is created
This pdf file will display the eps figures properly.
1) Go to the directory which includes XXX.tex
2) type "latex XXX.tex" and we will see a XXX.dvi file is generated
3) then, type "dvips XXX.dvi" and a XXX.ps file is created
4) type "ps2pdf XXX.ps" and the PDF file is created
This pdf file will display the eps figures properly.
Jul 18, 2013
Add a new MAC protocol in NS2
I just install the NS2 in my machine. If you are not sure, please read:
http://itantenna.blogspot.com.au/2012/01/install-ns234-on-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2011/11/install-ns21b9a-tens-in-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2010/10/ns2macintosh.html;
Now let`s add a new MAC protocol.
1) Put your new MAC program files (newMAC.cc and newMAC.h) to ns-2.34/mac
2) Modify common/packet.h
#define HDR_NEWMAC(p) ((hdr_newmac *)hdr_mac::access(p)) // add newmac here
Find "enum packet_t{}" and add PT_NEWMAC. Notice that it must be added before PT_NTYPE.
Find "class p_info{}" and add name_[PT_NEWMAC] = "newmac". It must be before name_[PT_NTYPE] = "undefined".
3) Modify tcl/lib/ns-default.tcl
Add Mac/NEWMAC set syncFlag_ 1
Add Mac/NEWMAC set selfConfigFlag_ 1
Add Mac/NEWMAC set dutyCycle_ 10
……
In the later line,
Add Mac/NEWMAC set syncFlag_ 0
4) Modify tcl/lib/ns-packet.tcl
Find "foreach prot{}" and add NEWmac
5) Modify ns2.34/Makefile
Add mac/newmac.o \
6) Now a new MAC protocol has been added to NS2. We will modify some trace files in the next.
7) Modify trace/cmu-trace.h
Add void format_newmac(Packet *p, int offset);
8) Modify trace/cmu-trace.cc
Find "void CMUTrace::format_mac_common(Packet *p, const char *why, int offset)"
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_mac802_11 *mh;
struct hdr_smac *sh;
struct hdr_newmac *ph; // add newmac pointer
char mactype[SMALL_LEN];
strcpy(mactype, Simulator::instance().macType());
if (strcmp (mactype, "Mac/SMAC") == 0)
sh = HDR_SMAC(p);
else if (strcmp (mactype,"Mac/NEWMAC") == 0)
ph = HDR_LMAC(p);
else
mh = HDR_MAC802_11(p);
……
if (strcmp (mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp (mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
return;
Find "if(newtrace)"
offset = strlen(pt_->buffer());
if (strcmp(mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp(mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
(ch->ptype() == PT_SMAC) ? (
(sh->type == RTS_PKT) ? "RTS" :
(sh->type == CTS_PKT) ? "CTS" :
(sh->type == ACK_PKT) ? "ACK" :
(sh->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
(ch->ptype() == PT_NEWMAC) ? (
(ph->type == RTS_PKT) ? "RTS" :
(ph->type == CTS_PKT) ? "CTS" :
(ph->type == ACK_PKT) ? "ACK" :
(ph->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
packet_info.name(ch->ptype())),
ch->size());
……
if (strncmp (mactype, "Mac/SMAC", 8) == 0) {
format_smac(p, offset);
}
else if (strncmp (mactype, "Mac/NEWMAC", 8) == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
Add a new function
void CMUTrace::format_newmac(Packet *p, int offset)
{
struct hdr_newmac *ph = HDR_NEWMAC(p);
sprintf(pt_->buffer() + offset,
" [%.2f %d %d] ",
ph->duration,
ph->dstAddr,
ph->srcAddr);
}
9) Find "void CMUTrace::format(Packet* p, const char *why)"
Add
switch(ch->ptype()) {
case PT_MAC:
case PT_SMAC:
case PT_NEWMAC:
break;
case PT_ARP:
format_arp(p, offset);
break;
10) Finally, add the header files #include
http://itantenna.blogspot.com.au/2012/01/install-ns234-on-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2011/11/install-ns21b9a-tens-in-ubuntu-1004.html;
http://itantenna.blogspot.com.au/2010/10/ns2macintosh.html;
Now let`s add a new MAC protocol.
1) Put your new MAC program files (newMAC.cc and newMAC.h) to ns-2.34/mac
2) Modify common/packet.h
#define HDR_NEWMAC(p) ((hdr_newmac *)hdr_mac::access(p)) // add newmac here
Find "enum packet_t{}" and add PT_NEWMAC. Notice that it must be added before PT_NTYPE.
Find "class p_info{}" and add name_[PT_NEWMAC] = "newmac". It must be before name_[PT_NTYPE] = "undefined".
3) Modify tcl/lib/ns-default.tcl
Add Mac/NEWMAC set syncFlag_ 1
Add Mac/NEWMAC set selfConfigFlag_ 1
Add Mac/NEWMAC set dutyCycle_ 10
……
In the later line,
Add Mac/NEWMAC set syncFlag_ 0
4) Modify tcl/lib/ns-packet.tcl
Find "foreach prot{}" and add NEWmac
5) Modify ns2.34/Makefile
Add mac/newmac.o \
6) Now a new MAC protocol has been added to NS2. We will modify some trace files in the next.
7) Modify trace/cmu-trace.h
Add void format_newmac(Packet *p, int offset);
8) Modify trace/cmu-trace.cc
Find "void CMUTrace::format_mac_common(Packet *p, const char *why, int offset)"
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_mac802_11 *mh;
struct hdr_smac *sh;
struct hdr_newmac *ph; // add newmac pointer
char mactype[SMALL_LEN];
strcpy(mactype, Simulator::instance().macType());
if (strcmp (mactype, "Mac/SMAC") == 0)
sh = HDR_SMAC(p);
else if (strcmp (mactype,"Mac/NEWMAC") == 0)
ph = HDR_LMAC(p);
else
mh = HDR_MAC802_11(p);
……
if (strcmp (mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp (mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
return;
Find "if(newtrace)"
offset = strlen(pt_->buffer());
if (strcmp(mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
}
else if (strcmp(mactype, "Mac/NEWMAC") == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
(ch->ptype() == PT_SMAC) ? (
(sh->type == RTS_PKT) ? "RTS" :
(sh->type == CTS_PKT) ? "CTS" :
(sh->type == ACK_PKT) ? "ACK" :
(sh->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
(ch->ptype() == PT_NEWMAC) ? (
(ph->type == RTS_PKT) ? "RTS" :
(ph->type == CTS_PKT) ? "CTS" :
(ph->type == ACK_PKT) ? "ACK" :
(ph->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
packet_info.name(ch->ptype())),
ch->size());
……
if (strncmp (mactype, "Mac/SMAC", 8) == 0) {
format_smac(p, offset);
}
else if (strncmp (mactype, "Mac/NEWMAC", 8) == 0) {
format_newmac(p, offset);
}
else {
format_mac(p, offset);
}
……
Add a new function
void CMUTrace::format_newmac(Packet *p, int offset)
{
struct hdr_newmac *ph = HDR_NEWMAC(p);
sprintf(pt_->buffer() + offset,
" [%.2f %d %d] ",
ph->duration,
ph->dstAddr,
ph->srcAddr);
}
9) Find "void CMUTrace::format(Packet* p, const char *why)"
Add
switch(ch->ptype()) {
case PT_MAC:
case PT_SMAC:
case PT_NEWMAC:
break;
case PT_ARP:
format_arp(p, offset);
break;
10) Finally, add the header files #include
Jun 24, 2013
A book about Knapsack problem
You can download this ebook for free.
Knapsack Problems: Algorithms and computer Implementations
Download link: http://www.or.deis.unibo.it/knapsack.html
Knapsack Problems: Algorithms and computer Implementations
Download link: http://www.or.deis.unibo.it/knapsack.html
Jun 23, 2013
STUDY MATERIALS FOR ENGINEERING STUDENTS WITH SOME MATLAB PROJECT: MATLAB CODE FOR ZIGBEE
STUDY MATERIALS FOR ENGINEERING STUDENTS WITH SOME MATLAB PROJECT: MATLAB CODE FOR ZIGBEE: THIS PROGRAM FOR ZIGBEE IS IN 3 PART SAVE ALL THREE PART IN DIFFERENT EDITOR FILE AND THEN RUN %>>>>>>>>PROGRAM 1...
May 15, 2013
How to install NS3 on Mac OS Lion
1) Install XCode
You will find XCode in the App Store. Alternatively, you can download the most recent version of XCode from the Apple Developer Connection website (http://developer.apple.com/mac/). The XCode development environment includes the gcc compiler and critical libraries required to build applications to be run in Mac OS X. Mac OS X Lion, requires XCode 4.1+.
2) Install MacPorts
2.1) Download MacPorts package installer for Lion release version 2.02 from https://distfiles.macports.org/MacPorts/MacPorts-2.0.2-10.7-Lion.dmg
2.2) Click on the downloaded "pkg" file, to install MacPorts.
2.3) This will place a fully-functioning MacPorts installation on your system
3) Install Required packages for ns-3
3.1) Open a Terminal window and run each command to install the required package
3.2) Install Mercurial and Python:
>> sudo port install mercurial python26
3.3) Install Bzr
>> sudo port install bzr
3.4) Install LibXML
>> sudo port install libxml2
3.5) Install GDB
>> sudo port install gdbm
4) Download ns3 source code
>> hg clone http://code.nsnam.org/ns-3-allinone
>> cd ns-3-allinone
>> ./download.py
5) Build the local repository
>> ./build.py
6) Test the installation
>> cd ns-3-dev
>> ./test.py
You will find XCode in the App Store. Alternatively, you can download the most recent version of XCode from the Apple Developer Connection website (http://developer.apple.com/mac/). The XCode development environment includes the gcc compiler and critical libraries required to build applications to be run in Mac OS X. Mac OS X Lion, requires XCode 4.1+.
2) Install MacPorts
2.1) Download MacPorts package installer for Lion release version 2.02 from https://distfiles.macports.org/MacPorts/MacPorts-2.0.2-10.7-Lion.dmg
2.2) Click on the downloaded "pkg" file, to install MacPorts.
2.3) This will place a fully-functioning MacPorts installation on your system
3) Install Required packages for ns-3
3.1) Open a Terminal window and run each command to install the required package
3.2) Install Mercurial and Python:
>> sudo port install mercurial python26
3.3) Install Bzr
>> sudo port install bzr
3.4) Install LibXML
>> sudo port install libxml2
3.5) Install GDB
>> sudo port install gdbm
4) Download ns3 source code
>> hg clone http://code.nsnam.org/ns-3-allinone
>> cd ns-3-allinone
>> ./download.py
5) Build the local repository
>> ./build.py
6) Test the installation
>> cd ns-3-dev
>> ./test.py
Mar 31, 2013
Batch operation in AMPL
To speed up the operations, you may put the commands into a file, and run them all automatically by typing include and the filename. The following is an example batch file (routing.run):
reset;
model network.mod;
data network.dat;
option solver cplex;
solve;
display N;
display x;
So you run the optimization in AMPL command line:
ampl: include routing.run;
reset;
model network.mod;
data network.dat;
option solver cplex;
solve;
display N;
display x;
So you run the optimization in AMPL command line:
ampl: include routing.run;
Mar 13, 2013
Feb 27, 2013
AMPL optimization tool on Mac OS
AMPL is a mathematical programming language. It can be downloaded from http://www.ampl.com/DOWNLOADS/index.html. There are some useful solvers as well. http://www.ampl.com/DOWNLOADS/details.html. Most of them require student ident.
After you download or install AMPL and those solvers, you need to use command "chmod +x ..." to convert them to executable program on Mac.
Then, you must edit environment variables (in ~/.bashrc file) to add ampl and related libraries/licenses.
export PATH=...:/your/AMPL/path/ampl
export DYLD_LIBRARY_PATH=/your/knitro/path/lib
export ZIENA_LICENSE=/your/knitro/license/path
For the testing of AMPL, we create a file named as myprog.mod and write a simple model,
var XB;
var XC;
maximize Profit: 25 * XB + 30 * XC;
subject to Time: (1/200) * XB + (1/140) * XC <= 40;
subject to B_limit: 0 <= XB <= 6000;
subject to C_limit: 0 <= XC <= 4000;
Then, change directory to the myprog.mod file. type ampl on the command prompt and we can try to solve it by different solvers. (the default solver of AMPL is MINOS)
1) ampl: model myprog.mod;
ampl:option solver knitroample;
ampl:solve;
2) ampl: model myprog.mod;
ampl:option solver gurobi;
ampl:solve;
3) ampl: model myprog.mod;
ampl:solve;
4) ampl: model myprog.mod;
ampl:option solver lpSolve;
ampl:solve;
5) ampl: model myprog.mod;
ampl:option solver snopt;
ampl:solve;
Feb 22, 2013
Download and install IBM Cplex solver (Academic version) for your AMPL
By default, AMPL uses MINOS as an optimization solver. However, Cplex which was developed by IBM is the most useful solver. The official website of IBM is not so friendly and they do not remove some web pages which are out of date.
To download Cplex, you have to register a academic membership at first.
1) Go to http://www-03.ibm.com/ibm/university/academic/pub/page/software and find the link "Join now - at no charge"(if the first time) or "Renew your membership"
2) Then, step 1: you will be asked to Register for a universal IBM ID and password (use your academic email address to do it). step 2: Complete the Academic Initiative program membership process (click "apply as a faculty member"). http://www-03.ibm.com/ibm/university/academic/pub/page/mem_join
3) After that, you will receive a confirmation email saying the application has been approved.
4) Visit the page http://www-03.ibm.com/ibm/university/academic/pub/page/sof_all_software, and click the link where is at bottom Search the Academic Initiative Software Download Catalog (This is pretty tricky)
5) After submitting your request, you will go to "IBM Academic Initiative Software Downloads" page.
6) Type "cplex" on "Find by search text" and you will see a list of cplex version choose one and you will see the software list.
7) Since the download needs java applet, you have to enable it for your browser.
8) After the download is finished, you will have a .bin file like "cplex_studio125.macos.bin"(here I download cplex12.5). DO NOT put it to your Application folder as it is not an application which can be run by your Mac.
9) Put it to some other directory. Open a terminal and find that directory. This bin file is a shell script, so you have to run it by bash. type and run this command
"/bin/bash ~/your/path/cplex_studio125.macos.bin"
10) Follow the instruction and you will install it successfully.
11) Finally, do not forget configure the environment variable for the license: export ILOG_LICENSE_FILE=/your/license/path/access.lim
12) The access.lim is generated from your IBM Academic Initiative.
Jan 29, 2013
Compile threshold.cc in NS2
In ns2, if you want to calculate the receiving power threshold of a node, you may want to use threshold tool which has been integrated in ns2 source code.
I don`t know why the threshold.cc is not compiled in the new version of ns2 like ns-allinone-2.35. So we have to do it by ourselves. In ubuntu, if you try to do "gcc threshold.cc", you will get an error message of "<iostream.h>".
So, we replace this line "#include<iostream.h>" by
#include<iostream>
#include<cstring>
using namespace std;
Then, compile it with g++,
g++ threshold.cc -o threshold
Jan 15, 2013
Generate random number in old version Matlab
If you want to have different a sequence of random numbers when the program is run for multiple times, a seed has to be set. The function "rand('state', int)" can not do it.
The old version Matlab which is lower than v7.7 has no some common random number generators. You can not use RandStream or rng() to set the random seeds. So I use an extended random number generator which can be downloaded from http://people.sc.fsu.edu/~jburkardt/m_src/asa183/asa183.html (r8_random.m).
s1 = mod ( 171 * s1, 30269 );
s2 = mod ( 172 * s2, 30307 );
s3 = mod ( 170 * s3, 30323 );
r = mod ( s1 / 30269.0 ...
+ s2 / 30307.0 ...
+ s3 / 30323.0, 1.0 );
return
We just need to set different seed s1,s2,s3 at the beginning of your program each time when you run it and it will generate different random sequences.
Subscribe to:
Posts (Atom)