Forum Replies Created
@CharlesPandian wrote:
You need not do everything in god.cc itself.
You may handle the values inside your new agent code (if any) or pass them to a tcl variable as follows. Here AddNeighborToList will add the neighbors to a tcl list. After that You can use that variable from the simulation script itself.
The c++ part
void MyAgent::FillNeighborList()
{
Tcl& tcl = Tcl::instance();
int TotalNodes=God::instance()->nodes();
for(int i=0;i{
if(God::instance()->IsNeighbor(i , here_.addr_))
{
tcl.evalf("%s AddNeighborToList %d ",name(), i);
}
}
}
the tcl part
Agent/MyAgent instproc AddNeighborToList {nn} {
$self instvar NeighborList_
lappend NeighborList_ $nn
}
I am a novice ns2 user and a dummy in object-oriented programming so I am lost in how to proceed your steps. Do I need to create new files, say myagent.cc and myagent.h to contain this new agent? After that, will I add your Tcl code into the existing file ns-agent.tcl?
If possible please help me once more. At the same time, I will try my best to figure it out.
Ah, and one more thing is, after getting the NeighborList_, I can write its length to a file by this command, is it right?
puts $file [llength NeighborList_]
Thank you very much for your help.
I just want to thank you as soon as possible!!!!! I will try your approach now.