Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How can I implement the following in my application?
We have a room and is available in 3 types. First there is the food that is fed into the room. The second current is fed from the first. The third eat from frist current fed. They can control each other.
It needs to be concurrent.
They must use the same algorithm without the knowledge of each other!
they life relate to another!
Posted
Comments
moosa il 16-May-12 17:01pm    
i just help me to simulate it!
Sergey Alexandrovich Kryukov 16-May-12 17:14pm    
What kind of help are you looking for? I already explained that there is nothing which said it needs to be concurrent.
So, simulate what? The purpose?
--SA
moosa il 16-May-12 17:23pm    
i want simulate this for example in database or network!
three current live whit together.current frist eat form food and same tim current third eat that and same time current second eat from current frist .
current second whit eat current frist contorol them.
Sergey Alexandrovich Kryukov 16-May-12 17:35pm    
If you keep being so "descriptive", you cannot hope for help. And please stop re-posting.
You need to describe things in detail, starting from the goal of the project (important). Is it a research/illustration in the field of concurrency? If you say anything like "they must" you should provide the convincing explanation "why". You need to explain where you see the problem.
--SA
TRK3 16-May-12 18:15pm    
You don't need a computer program to simulate something.

Get three people. Tell one of them he is room #1 and explain to him what he does. Tell the second person he is room #2 and explain to him what he deos. The the third person he is room #3 and explain to him what he does. Then tell them all to start and watch what happens.

Do this exercise first.

If you can actually explain to the three people what it is you want them to simulate and they understand it, they might be able to perform a simulation manually that is adequate to your needs.

If they can't, at least the exercise will have forced you to figure out how to clearly describe what it is you are trying to simulate. Once you've clearly described it, you might find it is now easier for you to implement it.

Or at least, you can then come back here and explain it to us. Right now I have no idea what you are trying to do, and am not sure that you even understand what it is you are trying to do.

TRK3 gave you a very good answer. If you cannot get 3 people to do the simulation then use paper. Do a state of each room on one line, then an action, then the results of that action in each room on the next line.


    Action      Room A            Room B         Room C
                 full              current=5a     ---
     C increases current
                 full              current=?      ???

and so on
 
Share this answer
 
You should probably find some books on numerical modelling, and on simulation. They may help you understand how to create simulations.

Most similations work on a 'tick' basic - i.e. each element of the simulation calcuates its next state based on its inputs - but doesn't publish its calcuated next state until the end of the tick. That way, all elements in the simulation expose a constant expression of their value 'now' (i.e. in the current tick); only at the transition from one tick to the next do the elements update their 'published' current state to be the value that they had calculated it would be.

Here's some pseudo-code:

In each tick:
    > Iterate each element in the simulation:
        * The element calculates it's pending new value based on its inputs
          (which are probably derived from the current states of other 
          elements in the simulation.
        * The element caches this value (keeps it private).
    > Iterate each element, again:
        * The element sets its publicised value to be the value it cached
          in the earlier iteration


In your example, a room is an element in the simulation. Rooms (as far as I can tell from your description) publish how much 'food' they contain. They also are aware of one or more other rooms (inputs).

Note that if one room eats from another the gain (in one room) and loss (in the other) of food are values to be accounted for in the calculated value that is cached in the two rooms; until the second iteration across all elements NO element updates its current state.

Have fun. Writing simulation systems is often very rewarding.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900