Jump to content

help for simulation code

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
DeSiGneR

DeSiGneR

    Newbie

  • Members
  • Pip
  • 5 posts
Hi there...

I try to write a program to simulate a wireless network WLAN

Let us suppose that the network consists of 5 nodes (A to E) and the simulation time is 300 seconds.

Also, let us assume the algorithm used as follow: when a node intents to send, it checks the receiver status. If it is a free which means it does not receive or send data from another node, the node starts transmission. If not it delay for a while then try a gain.

let's take the simple scenario:

at T=2 (second no. 2) node A starts sending to B.

at T=3, node C want to send to B. It will check the receiver status and then find the node B is busy. So, it will defer the transmission for a period of time then start a gain.

My question is: I want a way to pick up a transmitter and receiver randomly during simulation time.

for example, at t=4 A sends to C
at t=4.5 D sends to B and so on.

Thank you very much in advance.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It sounds like you'll need a random number generator.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
DeSiGneR

DeSiGneR

    Newbie

  • Members
  • Pip
  • 5 posts
Not exact..

I have one... but I don't know how can I use it?!!

#4
Steve.L

Steve.L

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 444 posts
Then you need to RTFM.

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Are you asking how to use a random number generator, or how to use it to solve your problem?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
DeSiGneR

DeSiGneR

    Newbie

  • Members
  • Pip
  • 5 posts
I am asking how to use it to solve your problem?!!

#7
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You will need a list of inactive nodes. Count those nodes and generate a random number between 1 and n (the number of inactive nodes). That node becomes the new transmitter.

Next you will need a list of all the nodes except the transmitter. Generate another random number between 1 and m (the number of other nodes). That node becomes the new desired receiver.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You will need a list of inactive nodes. Count those nodes and generate a random number between 1 and n (the number of inactive nodes). That node becomes the new transmitter.

Next you will need a list of all the nodes except the transmitter. Generate another random number between 1 and m (the number of other nodes). That node becomes the new desired receiver.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
DeSiGneR

DeSiGneR

    Newbie

  • Members
  • Pip
  • 5 posts
Ok ... but that means I simulate one transmission (between one transmitter and one receiver) .

what about the others nodes? Are they still inactive ?!!

I want simulate a number of transmitter and receivers at the same time

#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
How many are going to be starting at any given second? You will need to model which ones are busy, of course.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
DeSiGneR

DeSiGneR

    Newbie

  • Members
  • Pip
  • 5 posts
at any given second, there is a random number of nodes will transmit or receive. maybe there are 3, 4 or maybe just 1

this is my problem, how can i do this?

think for your helping

#12
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I think you need a clearer specification of the desired behavior then. It was not clear to me that multiple nodes could start sending at the same time.

For any second, there are several possibilities that I can imagine:
1) a node is busy (sending or receiving data)
2) a node is doing nothing
3) a node wants to initiate a new send activity
4) a node wants to send but is waiting for the desired recipient to be free

In case 2, we can simply have each node randomly switch state to 3.
After processing those that switched to state 3, for each node we can randomly select a desired target node and set remaining wait time to 0
After processing those in state 3, we can look at all those waiting with wait time 0 and attempt to initiate a send. On failure, set the wait time to some positive value.

The key to getting ANY program to work is moving from a general description of behavior, "I want a simulator where nodes can try to contact other nodes to send data," to more precise descriptions of behavior, "I want a simulator with n nodes, where each non-busy node has an n% chance if initiating a transmission and will wait a-b seconds if the initiationg fails before re-initiating the transmission".
Usually, a precise description will resolve many of your questions about how to implement the program, because the description reduces the number of options down to something very simple.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog