473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

developing network simulation.

1. In a network, there are a number of nodes. Each node has a queue and a
thread, performing the discrete event simulation.
class CNode
{...
queue q;
CWinThread* pthread;

void Start();//to execute the thread
....
}; where CWinThread is the thread class in MFC.
In the main program,
void main()
{
CNode node[10];
for (i=0;i<10;i++)
node[i].Start();
.....
}

2. but, I can not find a way to transmit the events between the nodes. For
example, in the thread of node[0], triggered by an action, it will send a
message MSG to node[1] and insert this event to node[1]'s queue. It seems
impossible to achieve this based on this design.

Can you please give some comments on this problem, the class design and the
program architecuter as well as the design pattern? Any comments are greatly
appreaciated.

--
Yan ZHANG
http://www.nict.com.sg/zhang/
Jul 22 '05 #1
3 5047
Yan ZHANG wrote:
1. In a network, there are a number of nodes. Each node has a queue and a
thread, performing the discrete event simulation.
class CNode
{...
queue q;
CWinThread* pthread;

void Start();//to execute the thread
...
}; where CWinThread is the thread class in MFC.
In the main program,
void main()
{
CNode node[10];
for (i=0;i<10;i++)
node[i].Start();
....
}

2. but, I can not find a way to transmit the events between the nodes. For
example, in the thread of node[0], triggered by an action, it will send a
message MSG to node[1] and insert this event to node[1]'s queue. It seems
impossible to achieve this based on this design.

Can you please give some comments on this problem, the class design and
the program architecuter as well as the design pattern? Any comments are
greatly appreaciated.

--
Yan ZHANG
http://www.nict.com.sg/zhang/


I have developed an Artificial Chemistry simulator. At the heart of the
simulator is a network of nodes and links between the nodes. In the
Reactor, each node corresponds to a Realised_Molecute_Type. The system
maintains a list of Realisable_Interaction_Types. The main simulation works
on this list of Realisable_Interaction_Types, creating and removing
Realised_Molecute_Type. I make a lot of use of STL lists, eg to maintain a
list of Realisable_Interaction_Types associated with a particular
Realised_Molecute_Type.

The UML diagrams for the Chemistry and Reactor subsystems are at

http://graffiti.virgin.net/c.gordon-...SimSoup/Design
Chemistry_Subsystem.html

The code is open source and can also be downloaded fom the same site.

--
Chris Gordon-Smith
London
Homepage: http://graffiti.virgin.net/c.gordon-smith/
Jul 22 '05 #2
All node threads in your program would be blocked, waiting for an
event.
A "check mailbox" event can be raised when a thread adds a message
to the queue of another thread.

When the receiving thread gets the "check mailbox" event, it checks the
message queue.

Deepa
--
http://www.EventHelix.com/EventStudio
EventStudio 2.5 - Automate Sequence Diagram Generation

Jul 22 '05 #3
Responding to ZHANG...
1. In a network, there are a number of nodes. Each node has a queue and a
thread, performing the discrete event simulation.
class CNode
{...
queue q;
CWinThread* pthread;

void Start();//to execute the thread
...
}; where CWinThread is the thread class in MFC.
In the main program,
void main()
{
CNode node[10];
for (i=0;i<10;i++)
node[i].Start();
....
}

2. but, I can not find a way to transmit the events between the nodes. For
example, in the thread of node[0], triggered by an action, it will send a
message MSG to node[1] and insert this event to node[1]'s queue. It seems
impossible to achieve this based on this design.


Separate out the queue as a standalone object associated with CNode so
that it is accessible directly.

1 triggers 1
[Queue] ----------------- [Node]
| * | *
| pushes events on |
| |
+-----------------------+
|
[Network]

[Network] keeps track of what Queues a particular Node can talk to.

Use a semaphore to determine whether the thread is paused. When an
event is pushed, queue the event and then check if the thread is paused.
If so, invoke pop(). Pop() sets the semaphore, starts the thread, and
invokes the Node method (e.g., Start) for the next event in the queue.
When Node is finished its synchronous processing (i.e., control is
returned to pop()), check the queue for additional events and continue
to pop them. When the queue is empty, pause the thread and unset the
semaphore. During its processing Node places the events on the relevant
Queues using push().

Now anyone (e.g., any CNode) can push an event asynchronously with the
thread because push() isn't in the execution thread. The semaphore
ensures that only one event at a time is processed. Now you can also
eliminate the loop in main(); all you need is for main() to provide a
single "seed" event and the nodes will talk to one another.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.

H. S. Lahman
hs*@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
blog (under constr): http://pathfinderpeople.blogs.com/hslahman
(888)-OOA-PATH

Jul 22 '05 #4

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

Similar topics

1
by: Steaming Balturd | last post by:
are there any php based economic simulations out there - not trading games per se, but more like simulating an economy, be it running a business or running a government? All i've been able to...
2
by: Samir Patel | last post by:
For last couple of weeks, I was doing lot of research on various simulation libraries. Only one I find in python is http://simpy.sourceforge.net. It is very powerful, but it seems that it does not...
19
by: Nicolas Pernetty | last post by:
Hello, I'm looking for any work/paper/ressource about continuous system simulation using Python or any similar object oriented languages (or even UML theory !). I'm aware of SimPy for...
1
by: Daryl Shanley | last post by:
I have some c code that writes results directly to a file as they're produced during a simulation. I want to modify the code to write directly to a postgres database using libpq. I think I could...
1
by: Tim Silva | last post by:
SDX Modeling, Simulation and Numerical Computing Environment for science and engineering has now been released. Major features include: * A unified simulation environment for modeling virtually...
4
by: Richard Blackwood | last post by:
Hello all. I have a few questions about simulation programming. One, do all programmers know to how to code a simulation? By simulation I mean a model of real world relationships (i.e. like...
1
by: diffuser78 | last post by:
I have to create a small and simple GUI app in Python which is similar to a netwrok game. Let me expalain you. I need some suggestions. I might use wxPython for GUI because that is the only GUI...
3
by: DanielJohnson | last post by:
I was wondering if anyblody can suggest me a network simulator written in python in which I can add on my own code and extend its functionality. I am looking for a simulator which will simualte...
1
by: itcoll | last post by:
i just want to create a simulation of LAN using java. i got the code for the client and serversocket programs - although i could make connection between 3 clients and a server socket , iam not able...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.