Global variables or access to modules

560 views
Skip to first unread message

Thomas Ridremont

unread,
Dec 13, 2013, 9:55:11 AM12/13/13
to omn...@googlegroups.com
Hello everybody,

I am trying at the moment to implement a network showing how Dijkstra's algorithm work.

I am new with omnet++ (I have only done the tictoc tutorial) and C++ (but I have good knowledges in Java so it helps) so at the moment I am a bit struggling.

For my work, I need to have a global array. I have tried a lot before understanding that array defined in my class dijkstra : public cSimpleModule is different for every module, which is logical and obvious in fact. So I have searched how to implement global arrays but I didn't manage to do it and I have seen on every site or posts that global variables are bad.

So I had another idea but I need to access all the modules of my ned files. So here is my question : is there a way to access all those modules?

Here is my Ned file (strongly inspired from a tictoc ned file) :



simple dijkstra
{
    parameters:
        @display("i=block/routing");
    gates:
        inout gate[];
}


network Dijkstra
{
     submodules:
        node[10]: dijkstra;
    connections:
        node[0].gate++ <--> {  delay = 100ms; } <--> node[1].gate++;
        node[0].gate++ <--> {  delay = 150ms; } <--> node[2].gate++;
        node[1].gate++ <--> {  delay = 200ms; } <--> node[2].gate++;
        node[1].gate++ <--> {  delay = 250ms; } <--> node[3].gate++;
        node[1].gate++ <--> {  delay = 300ms; } <--> node[5].gate++;
        node[2].gate++ <--> {  delay = 350ms; } <--> node[3].gate++;
        node[2].gate++ <--> {  delay = 400ms; } <--> node[4].gate++;
        node[3].gate++ <--> {  delay = 450ms; } <--> node[4].gate++;
        node[3].gate++ <--> {  delay = 500ms; } <--> node[5].gate++;
        node[3].gate++ <--> {  delay = 550ms; } <--> node[6].gate++;
        node[4].gate++ <--> {  delay = 600ms; } <--> node[6].gate++;
        node[5].gate++ <--> {  delay = 650ms; } <--> node[6].gate++;
        node[5].gate++ <--> {  delay = 700ms; } <--> node[7].gate++;
        node[6].gate++ <--> {  delay = 750ms; } <--> node[7].gate++;
        node[6].gate++ <--> {  delay = 800ms; } <--> node[8].gate++;
        node[7].gate++ <--> {  delay = 850ms; } <--> node[8].gate++;
        node[7].gate++ <--> {  delay = 900ms; } <--> node[9].gate++;
        node[8].gate++ <--> {  delay = 950ms; } <--> node[9].gate++;
}



I am French so excuse my English !

Thanking you in advance,

Thomas.

Erik Becker

unread,
Dec 13, 2013, 11:08:58 AM12/13/13
to omn...@googlegroups.com
Thomas,

I implemented a global array (actually, vector) three years ago. I
cannot tell if everything still works, especially with respect to what
you need, but here are some snippets:

In the .h-file:
static std::vector<someStruct> allNodes

Where the struct contains some data, in my case positions.

In the .cc-file, right under Define_Module:
#include<vector>
std::vector<someStruct> myClassName::allNodes;

And accessing it:
std::vector<someStruct>::iterator it;
for (it=allNodes.begin();it<allNodes.end();it++){
// do something with it.
}

I hope I didn't forget anything. Maybe this helps.

Kind regards,
Erik Becker

Am 13.12.2013 15:55, schrieb Thomas Ridremont:
> Hello everybody,
>
> I am trying at the moment to implement a network showing how
> *Dijkstra's algorithm* work.
> --
> You received this message because you are subscribed to the Google
> Groups "omnetpp" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to omnetpp+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Thomas Ridremont

unread,
Dec 16, 2013, 6:56:47 AM12/16/13
to omn...@googlegroups.com
Thank you very much Erik,

I will try this way,

Kind regards,

Thomas.

Thorben I.

unread,
Dec 16, 2013, 8:11:22 AM12/16/13
to omn...@googlegroups.com
Maybe you could implement a Singleton Class for your simulation. In that case you could hold you data global accessible by all classes if they got a reference to the instance of the singleton class.
Reply all
Reply to author
Forward
0 new messages