Hi,
I am a beginner in programming! I work part time on C++ projects in
University. Currently, i am developing a barber shop simulation model.
The current model is--> Each time when the client arrives, he checks
for a free barber. if a barber is free, he is serviced. Else he waits
in a queue (Common queue for all clients).
After barber is done with his work, he checks if the queue is empty, if
not, the 1st client in the queue is served by the barber.
Now i need to change it as follows--> The client has a preference for
barber ( i am done with this)! and each barber has HIS SEPARATE queue!
the client checks if this barber is free! if not he waits in the
corresponding queue of the barber! I wish to know how to implement this
qeueue for each barber. I am just pasting the source code of barber,
where i have generated the number of barbers and has set his chair
number, and also the intialisation of the clientqueue.
queue<client*> barber::clientQueue; // this is a common queue
barber::barber( int numberOfBarbers ) : currentClient( 0 ), name( 0 ) {
for( int i = 1; i <= numberOfBarbers; i++ ) {
barber* b = dynamic_cast<barber*>( this->clone( ) );
b->setChairNumber( i );
barbers.push_back( b );
b->name = new char[255];
sprintf( b->name, "%s - %i", this->getClassName( ), i );
}
} 11 3741
<ha*************@gmail.com> wrote: I am a beginner in programming! I work part time on C++ projects in University. Currently, i am developing a barber shop simulation model.
The current model is--> Each time when the client arrives, he checks for a free barber. if a barber is free, he is serviced. Else he waits in a queue (Common queue for all clients).
After barber is done with his work, he checks if the queue is empty, if not, the 1st client in the queue is served by the barber.
Now i need to change it as follows--> The client has a preference for barber ( i am done with this)! and each barber has HIS SEPARATE queue! the client checks if this barber is free! if not he waits in the corresponding queue of the barber! I wish to know how to implement this qeueue for each barber. I am just pasting the source code of barber, where i have generated the number of barbers and has set his chair number, and also the intialisation of the clientqueue.
<snip>
I guess I would make a queue for each barber and also a common queue. Each
client gets a time stamp when he enters the system, no ties permitted. When
a barber becomes free he checks the time stamp of the leading contender in
his private queue with the time stamp of the leading contender in the common
queue. He takes whoever has the oldest time stamp.
Well, thank you! do u have any idea on how to declare the queue for
each barber? syntax?
osmium wrote: <ha*************@gmail.com> wrote:
I am a beginner in programming! I work part time on C++ projects in University. Currently, i am developing a barber shop simulation model.
The current model is--> Each time when the client arrives, he checks for a free barber. if a barber is free, he is serviced. Else he waits in a queue (Common queue for all clients).
After barber is done with his work, he checks if the queue is empty, if not, the 1st client in the queue is served by the barber.
Now i need to change it as follows--> The client has a preference for barber ( i am done with this)! and each barber has HIS SEPARATE queue! the client checks if this barber is free! if not he waits in the corresponding queue of the barber! I wish to know how to implement this qeueue for each barber. I am just pasting the source code of barber, where i have generated the number of barbers and has set his chair number, and also the intialisation of the clientqueue. <snip>
I guess I would make a queue for each barber and also a common queue. Each client gets a time stamp when he enters the system, no ties permitted. When a barber becomes free he checks the time stamp of the leading contender in his private queue with the time stamp of the leading contender in the common queue. He takes whoever has the oldest time stamp.
<ha*************@gmail.com> wrote: Well, thank you! do u have any idea on how to declare the queue for each barber? syntax?
Something like this for a first cut. It compiles.
#include <iostream>
#include <deque>
#include <vector>
// in a real program, this would be in a header file
struct Client
{
int id;
double time_stamp;
};
//----------------
typedef std::deque<Client> QT; // queue type
// end header
using namespace std;
int main()
{
vector<QT> vq; // index 0 - collective queue,
// else one for each barber
// stuff
}
> Something like this for a first cut. It compiles.
#include <iostream> #include <deque> #include <vector>
// in a real program, this would be in a header file struct Client { int id; double time_stamp; }; //---------------- typedef std::deque<Client> QT; // queue type
You could use double or a counter for the time stamp, and then you
would have one queue for each barber and one generic queue. At the time
when a barber becomes available, you must compare the timestamps in
each queue, i.e. the one for the generic queue and the one for the
barber-specific queue.
osmium wrote: <ha*************@gmail.com> wrote:
I am a beginner in programming! I work part time on C++ projects in University. Currently, i am developing a barber shop simulation model.
The current model is--> Each time when the client arrives, he checks for a free barber. if a barber is free, he is serviced. Else he waits in a queue (Common queue for all clients).
After barber is done with his work, he checks if the queue is empty, if not, the 1st client in the queue is served by the barber.
Now i need to change it as follows--> The client has a preference for barber ( i am done with this)! and each barber has HIS SEPARATE queue! the client checks if this barber is free! if not he waits in the corresponding queue of the barber! I wish to know how to implement this qeueue for each barber. I am just pasting the source code of barber, where i have generated the number of barbers and has set his chair number, and also the intialisation of the clientqueue. <snip>
I guess I would make a queue for each barber and also a common queue. Each client gets a time stamp when he enters the system, no ties permitted. When a barber becomes free he checks the time stamp of the leading contender in his private queue with the time stamp of the leading contender in the common queue. He takes whoever has the oldest time stamp.
You don't need to mess around with time stamps.
You have a queue for each barber and a common queue. When a barber
needs a customer he checks his queue, if empty then the common queue.
When a customer arrives he always joins the common queue. When he gets
to the front of the common queue, if the first free barber is not the
one he wants, he goes to the end of that barbers queue. Done.
Geo wrote: You don't need to mess around with time stamps.
You have a queue for each barber and a common queue. When a barber needs a customer he checks his queue, if empty then the common queue. When a customer arrives he always joins the common queue. When he gets to the front of the common queue, if the first free barber is not the one he wants, he goes to the end of that barbers queue. Done.
Seems a good solution. In the implementation:
- You would signal the common queue when a barber is available (which
means nobody in his own personal queue too).
- If after signalling, the customer at the front did not go to the free
barber but joined a different queue, you must signal again.
On 6 Jun 2006 09:31:14 -0700, "Earl Purple" <ea********@gmail.com>
wrote: Geo wrote: You don't need to mess around with time stamps.
You have a queue for each barber and a common queue. When a barber needs a customer he checks his queue, if empty then the common queue. When a customer arrives he always joins the common queue. When he gets to the front of the common queue, if the first free barber is not the one he wants, he goes to the end of that barbers queue. Done.
Seems a good solution. In the implementation:
- You would signal the common queue when a barber is available (which means nobody in his own personal queue too).
- If after signalling, the customer at the front did not go to the free barber but joined a different queue, you must signal again.
Sorry if I'm not much help here, but I remember having a similar
problem a long, long time ago. An old crusty engineer dug up some
really old literature about Railroad Yard Scheduling. Apparently back
when railroads were huge, this was a big engineering problem. Getting
all those trains queued up correctly at the right time on the various
tracks was a real science.
For clarity: Here is a link that shows a picture of a railroad yard.
Though the article is not about them. http://en.wikipedia.org/wiki/Classification_yard
"Geo" writes: You don't need to mess around with time stamps.
Any simulator worth it's salt already *has* a time stamp on when the client
entered the system. You don't write simulators simply to burn up excess CPU
cycles. One of the products of the simulator has to the time spent waiting,
presented in various forms. Mean, worst case, as a histogram of all
clients. So nothing is accomplished by getting rid of the time stamp. I
don't object to a revised method, but don't implicitly attribute
non-existent benefits to the change.
"osmium" writes: Any simulator worth it's salt already *has* a time stamp on when the client entered the system. You don't write simulators simply to burn up excess CPU cycles. One of the products of the simulator has to the time spent waiting, presented in various forms. Mean, worst case, as a histogram of all clients. So nothing is accomplished by getting rid of the time stamp. I don't object to a revised method, but don't implicitly attribute non-existent benefits to the change.
A point I forgot to make. I think it is far better to fully parameterize
objects as they enter the system, If you do it in bits and pieces here and
there it gets terribly confusing. So some of the proposed changes (I didn't
try to fully absorb what all was proposed) will require a new field to tell
whether the client is a wait kind of guy - and has favorite barber and that
barber's id - or he takes pot luck. The way I had it that information was
used and discarded when he joined a queue.
On Tue, 06 Jun 2006 09:59:58 -0700, JustBoo <Ju*****@BooWho.com>
wrote: For clarity: Here is a link that shows a picture of a railroad yard. Though the article is not about them. http://en.wikipedia.org/wiki/Classification_yard
I was wrong. The article is about train yards. Even better. :-)
osmium wrote: "Geo" writes:
You don't need to mess around with time stamps.
Any simulator worth it's salt already *has* a time stamp on when the client entered the system. You don't write simulators simply to burn up excess CPU cycles. One of the products of the simulator has to the time spent waiting, presented in various forms. Mean, worst case, as a histogram of all clients. So nothing is accomplished by getting rid of the time stamp. I don't object to a revised method, but don't implicitly attribute non-existent benefits to the change.
The OP made no mention of tracking time, but you may well be correct. I
was just highlighting an alternative solution that did not require
tracking time differences. The benefit of not doing time comaprisons is
IMO far from 'non-existant' but the fun in programming is that there is
seldom 'one' solution. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Flare |
last post by:
Hi
I tring to implement a model 2 architecture in a new test JSP site for my
own training. I read this article...
|
by: pysim |
last post by:
Hi, I have a couple of general requests for pointers to python
examples and design advice.
I'm looking for examples of MVC-based GUI controls done in python
(model-view-controller).
Also,...
|
by: yensao |
last post by:
Hi,
I have a hard time to understand difference and similarities between
Relational database model and the Object-Oriented model. Can somebody
help me with this?
Thank you in advance.
...
|
by: Michael Strorm |
last post by:
Hi!
I've been having problems with a DTD. Having had the Sun XML validator
reject a document, I put it through 'xmllint' for more information.
'Xmllint' noted a problem with the DTD itself;...
|
by: Robert W. |
last post by:
I'm building my first major C# program and am try to use best practices
everywhere. So I've implemented the "Document/View Model" whereby:
- There's a Windows Form, which we'll call "formView"
-...
|
by: Earl Teigrob |
last post by:
Background:
When I create a ASP.NET control (User or custom), it often requires security to be set for certain functionality with the control. For example, a news release user control that is...
|
by: Edward Diener No Spam |
last post by:
The definition of a component model I use below is a class which allows
properties, methods, and events in a structured way which can be
recognized, usually through some form of introspection...
|
by: Doug |
last post by:
Hi,
I learned a little about the model view presenter pattern at a
conference this last week and am experimenting with it. It's working
pretty well but I have a question.
I am trying to use...
|
by: tonytech08 |
last post by:
What I like about the C++ object model: that the data portion of the
class
IS the object (dereferencing an object gets you the data of a POD
object).
What I don't like about the C++ object...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |