473,765 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

discrete event simulation question

Hi guys,
I am working on a project which requires an implementation of discrete
event simulation in C using linked lists. I would greatly appreciate if
someone could provide with some sources on how to approach DES. Please
help me out.

Thanks,
Jack

Feb 9 '06 #1
10 5261
jack wrote:
Hi guys,
I am working on a project which requires an implementation of discrete
event simulation in C using linked lists. I would greatly appreciate if
someone could provide with some sources on how to approach DES. Please
help me out.


You don't have a C question (yet -- once you start on
the implementation, you may have C questions), but a question
about algorithms and/or data structures.

<off-topic>

The fundamental form of a discrete-event simulation is that
there's a queue of events scheduled for various times in the
simulated future. You remove the earliest of those events from
the queue, advance the global "clock" to the scheduled time
of that event, and do whatever event-specific processing the
event requires. This processing may add new events to the
queue (scheduled for times no earlier than the clock, of
course), may cancel scheduled events that have not yet happened,
and may change the scheduled time of some future events (which
can be regarded as a cancellation plus adding a new event, if
that's convenient). The event processing also modifies the
state of the simulated system in whatever ways are appropriate,
and may even cause the simulation to terminate.

So: The central data structure for the simulation framework
is a priority queue, ordered by the events' scheduled times.
Other data structures are usually problem-specific, keeping
track of the automobiles or mesons or whatever knick-knacks
circulate in the simulated system. There are *many* data
structures that implement such things; you need to choose a
few and then (if puzzled) come back here with the problems
you've encountered in writing the code for them.

(In my brief and inglorious career as "Lecturer in
Mathematics," I used to teach this stuff. At the time, it
went for 0.5 semester-hours' credit; nowadays, I understand
that merely learning a programming language or learning how
to operate a spreadsheet earns more. O tempora! O mores!)

</off-topic>

--
Eric Sosman
es*****@acm-dot-org.invalid
Feb 9 '06 #2
Thanks a lot Eric for your effort. I shall start working on the
algorithm and get back to you with some C questions.

Jack

Feb 10 '06 #3
Hi,

I've been working on an Discrete event simulation problem using linked
lists(LL). The algorithm looks as follows:

struct linkedlist
{
int event;
int queue; //FIFO on which the event acts
double timer; // time value embedded in each node in the LL on
which the LL is sorted.
};

The timer field has the time based on which, the time for a particular
node is set. The timer value for a node indicates when the node is to
be read and the corresponding event executed. The event loop looks
something like this:

struct linkedlist *ptr;
ptr = (struct linkedlist *)head; (points to the beginning of LL)
while(1)
{
ptr = ptr->next ( advance the linked list)
execute ptr->event on ptr->queue
get time from gettimeval (global_time)
add the time taken for execution of one event to the global time
create new node with another event, the queue on which the event
acts and the time value.
Add the new node to the linked list based on time (The list is
ordered based on increasing time)
get time from gettimeval (global_time)
sleep(ptr->time - global_time)
}

Now, is this the way we schedule time in a event scheduling algorithm?
If not how do we do it? I would be more than glad if you can provide me
with some documentation.. ...on this stuff i.e., time scheduling..I am
asking this coz...I am getting -ve vlaues of (ptr->time - global_time)
.. This means that the event is taking more time than its required to
take. But, then..how do we set the time for that event before hand and
store it in the node? Any info on this...is welcome.

Jack

Feb 25 '06 #4
"jack" writes:
I've been working on an Discrete event simulation problem using linked
lists(LL). The algorithm looks as follows:
I think this is too complicated a problem to be of much help without a
blackboard. There are likely terminology problems and simple
misunderstandin gs of what is meant. But I will give it a brief try. First
of all, this may be helpful;

http://www.cis.temple.edu/~ingargio/...ks/hints1.html
struct linkedlist
{
int event;
int queue; //FIFO on which the event acts
double timer; // time value embedded in each node in the LL on
which the LL is sorted.
};

The timer field has the time based on which, the time for a particular
node is set. The timer value for a node indicates when the node is to
be read and the corresponding event executed. The event loop looks
something like this:

struct linkedlist *ptr;
ptr = (struct linkedlist *)head; (points to the beginning of LL)
while(1)
{
ptr = ptr->next ( advance the linked list)
execute ptr->event on ptr->queue
get time from gettimeval (global_time)
add the time taken for execution of one event to the global time
No. Global time should only be advanced as needed to accommodate the due
time of the next item. But my guess is you probably did not mean what I
understood you to say. The change in state of the 'gadget' takes place in,
conceptually, zero time.
create new node with another event, the queue on which the event
acts and the time value.
Add the new node to the linked list based on time (The list is
ordered based on increasing time)
get time from gettimeval (global_time)
sleep(ptr->time - global_time)
}

Now, is this the way we schedule time in a event scheduling algorithm?
If not how do we do it?
Before an event releases control back to the main program, it computes the
time during which the event will be dormant. IOW, it says "Reactivate me at
time x" ( or time now + y).

I would be more than glad if you can provide me with some documentation.. ...on this stuff i.e., time scheduling..I am
asking this coz...I am getting -ve vlaues of (ptr->time - global_time)
. This means that the event is taking more time than its required to
take. But, then..how do we set the time for that event before hand and
store it in the node? Any info on this...is welcome.

Jack

Feb 25 '06 #5
Osmium,

Thanks for your answer. The link which you provide partly
explained/addressed my problem . But ,I still dont get a picture of
what I should do. As I mentioned above:

I am alloting the 'due time' for each event in the following manner

due_time = global_time + (time one_data_transf er (That's the event
here) requires ) ------ 1

Now, I place the node in the linked list sorted on the order of
increasing due_time. And once I start to execute the event, If I happen
to finish the event before the designated due_time for that event, I
sleep for the remaining time. But THE MAIN PROBLEM is the time taken
for one event is exceeding the due_time sometimes(which it
shouldn't??)(I guess this is because,with equation---1, often it's so
happening that the difference between the due_times of two consecutive
nodes is less than the time one _data_transfer requires).

so I begun to question my the basic allocation of due_time which I did
in equation--1. Is that correct?

Jack

Feb 25 '06 #6

"jack" <vi*********@gm ail.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
Osmium,

Thanks for your answer. The link which you provide partly
explained/addressed my problem . But ,I still dont get a picture of
what I should do. As I mentioned above:

I am alloting the 'due time' for each event in the following manner

due_time = global_time + (time one_data_transf er (That's the event
here) requires ) ------ 1

Now, I place the node in the linked list sorted on the order of
increasing due_time. And once I start to execute the event, If I happen
to finish the event before the designated due_time for that event, I
sleep for the remaining time. But THE MAIN PROBLEM is the time taken
for one event is exceeding the due_time sometimes(which it
shouldn't??)


When the event is scheduled to be finished it damn well *has* to be
finished. There is no looking back, you can only look forward. For
example, if a read might result in error handling, the first estimate is the
scheduled time with no error, if an error occurs this is a new job, so to
speak. If necessary, change the initial estimate to the minimum time, when
it expires see what the situation is and reschedule another event if needed.

..
Feb 26 '06 #7
You remove the earliest of those events from
the queue, advance the global "clock" to the scheduled time
of that event, and do whatever event-specific processing the
event requires. This processing may add new events to the
queue (scheduled for times no earlier than the clock, of
course), may cancel scheduled events that have not yet happened,
and may change the scheduled time of some future events (which
can be regarded as a cancellation plus adding a new event, if
that's convenient). The event processing also modifies the
state of the simulated system in whatever ways are appropriate,
and may even cause the simulation to terminate.
What exactly do you mean by global "clock" here? Is it the system
clock? If its system clock, how do we use it to set the due_time in
each node? If its not system clock , then how exactly do we manage the
global time?

The reason why I ask this is I am using system clock as the global time
and assigning the due_time to each node in the Linkedlist based on the
following value:

due_time_for_ev ent => current_system_ clock_time +
time_taken_for_ one_event.

( In my case, the event is consumption of data by a FIFO. Hence the
time_taken_for_ one_event i.e., consumption would be
(1/Consumption_rat e_of_FIFO)).

But, because of this, some times(infact many times) its so happening
that the due_times of 2 adjacent nodes are overlapping. Because of this
, the event's execution is still going on when the next event's
due_time has already elapsed and its due. How do I deal with this in a
sequential program? How do I maintain global time? What is its relation
to system clock time? How to I use to set the due_time in each node so
that each event gets its due_time as atleast greater than the previous
event's due_time by "time_taken_for _one_event"?

Thanks,
Jack

Feb 27 '06 #8
On 26 Feb 2006 18:02:34 -0800, "jack" <vi*********@gm ail.com> wrote:
You remove the earliest of those events from
the queue, advance the global "clock" to the scheduled time


I think it's time to repeat Eric's original reply:

" You don't have a C question (yet -- once you start on
the implementation, you may have C questions), but a question
about algorithms and/or data structures."

You'd probably get more and better answers in comp.programmin g or some
other group where this is on-topic.

--
Al Balmer
Sun City, AZ
Feb 27 '06 #9

Al Balmer wrote:
On 26 Feb 2006 18:02:34 -0800, "jack" <vi*********@gm ail.com> wrote:
You remove the earliest of those events from
the queue, advance the global "clock" to the scheduled time


I think it's time to repeat Eric's original reply:

" You don't have a C question (yet -- once you start on
the implementation, you may have C questions), but a question
about algorithms and/or data structures."

You'd probably get more and better answers in comp.programmin g or some
other group where this is on-topic.

--
Al Balmer
Sun City, AZ


Thanks Al.

Feb 27 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5038
by: jva02 | last post by:
Hi, I'm confused why I can capture an event fired by an ActiveX object when it's loaded via an <object> tag, but not when loaded using "new ActiveXObject". Here's a basic example: vb ActiveX object: Private Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
2
3374
by: Marinos Christoforou | last post by:
Sorry if this has been asked before but as an inexperienced wanna-be C# programmer I wondering how to code classes to help build a standard Windows UI. For example to build a common toolbar. I would call a method from the class in the load event of my varioius windows forms, to create the toolbar, add buttons to it and set various properties as required. This is fine but I am at a loss as to how to expose the toolbar's various events...
2
1568
by: Pat Richey | last post by:
i'm writing some events that need to be NonSerialized and to get it to work i ended up doing something like: public event OnEventHandler myEvent; because public event OnEventHandler myEvent;
2
1254
by: Colin McGuire | last post by:
If I have a routine that handles event A of class B coded in VB.Net like: Private Sub handleEventA Handles B.eventA Debug.WriteLine("eventA handler for class B") End sub and then I perform the following three steps
5
1570
by: Charles Law | last post by:
I think I asked the wrong question last time, so I am starting a separate post to distinguish them. Take five classes: ClassA and ClassW...Z ClassA raises five events: Event1...5 ClassW...Z handle some combination of these events. For example ClassW handles Event1, 2 and 5
2
2153
by: Affan | last post by:
Hi, I am writing a discrete event simulator and want to simplify the analysis of multipath by trigging an arrival of multipath based on a the receiver distance from sender- say 'd'- and a simulation parameter, say mpParam which gives the fraction of maximum range within which the reflecting surface is located (I know gross simplifications!). Note that for fraction beyond 1, there is no need for any event to be triggered as it will not be...
8
1619
by: Louis | last post by:
I was trying to display a custom context menu in javascript. I wanted to capture a right mouse click. I added an eventListener to a "div" like this.. element,addEventListener ("click", myfunc, true); When I tried to debug it, it seems to react fine to a left mouse click, but it totally ignores the right mouse click.
0
1983
by: info | last post by:
Hi I would like to introduce Discrete-event simulation system Delsi 2.0 The system is implemented as a set of components for .NET 2.0 Framework. It is designed for simulation of queuing systems with complex logic and topology. Delsi 2.0 allows you to utilize all the power of C#, Microsoft .NET Framework 2.0 and its development environment, such as Microsoft
7
3510
by: gordon | last post by:
is it possible to send a message to the gui instance while the Tk event loop is running?I mean after i create a gui object like root=Tk() mygui=SomeUI(root) and call root.mainloop() can i send message to mygui without quitting the ui or closing the
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.