define a new nedfunction in omnet++

118 views
Skip to first unread message

Kortas Manel

unread,
Mar 22, 2015, 2:26:19 PM3/22/15
to omn...@googlegroups.com
Hi, I have to implement a random bidirectional topologie , I tried to follow this : http://www.khyber.org/tech/a/Random_Generation_of_bi-direct.shtml
But I didn't know how to define a new nedfunction , help please !!!

Pedro Yébenes Segura

unread,
Mar 23, 2015, 4:10:19 AM3/23/15
to omn...@googlegroups.com

Kortas Manel

unread,
Mar 23, 2015, 8:04:05 AM3/23/15
to omn...@googlegroups.com
Hi again,
I saw omnett++ tutorial yesterday, but there are some points that I did not understand, the first is where shoud I define the ned function, shoud I create a new source file (.cc) ?? 
the second is when I put this code in a new source file :
#include <cnedvalue.h>
#include<essai3.h>

double runiform(double rng) {
  static int r = 0;
  static double l = 0;
  if(r%2 == 0) l = uniform(0,1);
  r++;
  return l;
}
static cNEDValue runiform(cComponent *context, cNEDValue argv[], int argc)
{
 double rng = argc==2 ? (int)argv[1] : 0;
 return cNEDValue(runiform(rng), argv[0].getUnit());
}
Define_NED_Function(runiform, "quantity runiform(int rng?)", "random/continuous", "Retains the value generated from a previous call to uniform()");

it generate a syntax error , I didn't know what to do , sorry but I have just one week with omnet++ so I'm beginner.

Pedro Yébenes Segura

unread,
Mar 23, 2015, 10:10:57 AM3/23/15
to omn...@googlegroups.com
A separate source file for ned funcions is a good choice.

I think that the problem with your code is to have two functions called "runiform". Try to rename one of them and compile again.

Regards,

Kortas Manel

unread,
Mar 23, 2015, 5:31:52 PM3/23/15
to omn...@googlegroups.com
I deleted the other function and my nedfunction.cc file become like this :


double runiform(double rng) {
  static int r = 0;
  static double l = 0;
  if(r%2 == 0) l = uniform(0,1);
  r++;
  return l;
}
Define_NED_Function2(runiform, "quantity runiform(double rng?)", "random/continuous", "Retains the value generated from a previous call to uniform()");

the project generate an error and propose to add runiform and rng to dictionary , shoud I add them or not ??
Tnx Pedro for your responses.


--
You received this message because you are subscribed to a topic in the Google Groups "OMNeT++ Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omnetpp/LEJikrih_9I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to omnetpp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pedro Yébenes Segura

unread,
Mar 24, 2015, 5:25:00 AM3/24/15
to omn...@googlegroups.com
I have copied your code and the compiler didn't complain in my computer (Ubuntu 14.04 and omnet++ 4.6) changing the include declaration as I don't have <essay3.h>.
Sorry, I don't know what is happening.

#include <omnetpp.h>


double runiform(double rng) {
  static int r = 0;
  static double l = 0;
  if(r%2 == 0) l = uniform(0,1);
  r++;
  return l;
}
static cNEDValue runiform(cComponent *context, cNEDValue argv[], int argc)
{
 double rng = argc==2 ? (int)argv[1] : 0;
 return cNEDValue(runiform(rng), argv[0].getUnit());
}

Define_NED_Function2(runiform, "quantity runiform(double rng?)", "random/continuous", "Retains the value generated from a previous call to uniform()");

Sultan Mahmud Tusher

unread,
Feb 17, 2017, 11:51:26 PM2/17/17
to OMNeT++ Users
I am trying to put a bimodal gaussian distribution with two different mean and two different variances. I saw in the manual that you can define your own function. I do not know where to write this function and where i have to put in order to use it in the .ini file. I would really appreciate your help in doing that. This is  for .interarrivaltime in queueing system.

Thanks
Tusher
Reply all
Reply to author
Forward
0 new messages