• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Moving data from one queue to another

 
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like last time please feel free to correct me in moving this to the C# part of the forum. Just that java and C# are very similar, and java usually gets the most attention. For my question I have a queue of customers arriving, and a queue for customers waiting. I want to move the customers in the arriving queue to the queue of waiting customers. I thought I had it figured, but I was told that its not going to do what I want it to do. My solution was



but I was told there is something minor that I still need to figure out
here is the full class
 
Marshal
Posts: 80281
432
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are going to have to try out that code and see what happens. Does that loop at the beginning actually compile?
 
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Cody,

is a teller a bank employee who services a customer? Google Translate was a bit vague on this point. Also, what is the reason for having an arrival list and a customer queue?

For each minute (see timeSlot, line 38), you calculate how many new customers arrive. Then, for each teller, if that teller is empty and the waiting queue is not empty, the tellers waiting time is 0, since he can service a new customer right away. If the queue is empty, the teller simply has to wait another minute, at least, until there is a customer available. So, a teller must be able to know the time it becomes empty and the time when he starts servicing a new customer.

When servicing a new customer, you can then calculate the servicing time needed for that customer (at least one minute, at most five, average probably 3 minutes). After timeSlot is 120, the bank closes and only the waiting customers will be serviced.

So a teller must be able to registrate both waiting time (since more than one customer is being serviced by a teller, you need a list for this, I would say), and servicing time. It should then be relatively easy to calculate all the requested statistics,

Admitted, I'm speculating much on what a teller is and what the method 'teller.ProcessNextCustomer(timeSlot);' involves. but this is how I read the exercise. If I'm wrong, do let me know. Can you show the Customer, Teller and CustomerGenerator classes?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, for the late reply. Had a terrible UC flare this weekend so I was in no mood to try looking at this when I felt like death. Luckily I did most of it already, so I still have till tomorrow night to figure it out. Here are the rest of the classes

Teller:


CustomerGenerator


Customer

 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Cody,

take your time. I hope you feel better for a long period.

The assignment is a bit different than I expected, but that is not so important. It is a bit confusing due to a lot of queues being used here. There is a fixed number of Customers (90, = 0.75 * 120 minutes or timeslots).
These 90 customers are divided randomly over a customer array[120]. Well, I resckon you understand the working of the program.

Then about the required statistics, Have a look at the Teller class (whatever such a teller may be). Each customer, when added tp the Customer waiting queue, gets an arrival time, a start-of-service-time and a Transaction time.
So for a customer, the waiting time is simply the difference between start-of-service-time and the arrival time. Each teller also keeps the maximum waiting time so far, the total waiting time for all customers handled by this teller and, most important, the number of Customers serviced by this teller.

Therefore, it is now an easy task to get the total waiting time per teller, the average waiting time for a customer per teller (if the total waiting time is 100, and you serviced 25 customers, what is the average waiting time per customer?), you can even calculate the average Transaction Time per customer (can you predict what that would be?), etcetera. By adding the basic data of all the tellers, you can calculate the same statistics, but now for the whole group, instead of per teller.

Did you write these classes, or where these delivered by your teacher?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The teacher provided the classes with most of the code. We had to go in and fill in some of the code in the bank and teller class.
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. Are the statistics that you must provide clear?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The statistics I think I’m good on. The real question I had was the queue moving customers. Which was

for( int i = 0; i < arrivals.Count)
               {
                   // draw out on paper
                   
                   Customer c = arrivals.Dequeue();
                   customerQueue.Enqueue(c);
               }
Sorry the code tags won’t work on my phone. But The above code doesn’t do what I want it to according to the instructor. I’m gonna look at it tomorrow, just to give me another night to rest up. But according to him I’m missing something with that code
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, stupid me. I misunderstood the problem. Sleep well and when you wake up in the morning,  do have a look at your very first line in your opening post.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I may need help with the statistics after all...I feel embarrassed. Simple calculations, and its like I have just gone blank...
So to find the maxwaitTime I have to walk through my teller list, and find the greatest time. So Something like?

 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.

That will not often be the case....

Start with an initial value for the variable overallMaxWaitTime, -infinity (or -1), and since we're talking about the maximum, watch the sign of the comparison! Can't remember if we have talked about java 8 streams, but these sure would make life a bit easier.

For the average waiting Time, have a look at a suitable variable in the Teller class. Add these values for all the tellers, and since you know the total numbers of customers, the average should be easy-piecy.

Et cetera.

By the way: in C#, if you have a for loop, like 'for (A; B) {...}' (note the syntax carefully!) do you get a compiler error? And if you do an 'arrivals.Dequeue();' what happens when 'arrivals' is empty? Do you get an Exception or a special value (say null)?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know why im so confused. its like a major set back today So

 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's it!

Edit:

Why not? Indeed you loose the teller, but you know upfront how many customers were being served! (remember: average numer of clients per minute/timeSlot and the number of timeslots are given, so how many are served?)
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I just need to find out what goes in that something area. which ive looked at the variables, and im not entirely sure about that something.
I talked to the instructor...well emailed him a little earlier this morning. His suggestion is to keep track of the customers served inside the loop. like I did with the time
like this :



so then my print would look like
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all: beware of integer division! Athough I don't think it will make much of a difference.

Your teacher is absolutely right, of course. And doing it that way is also correct. But look at the method 'initializeArrivals' in the CustomerGenerator class. Do you see what this method is about?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I was going to cast a double on them, but the code does not like that. So like below...at least thats how I saw it as an example. As far as the generator class we never really went over it he just kind of gave it to us.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I got the cast, but when I print my avgTime I get NaN in the console.....
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should get a NaN if you do 0.0 / 0.0. Ah well, never mind, forget that integer division.

Did you  have a look at your original problem?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont see it. Here is the latest hint I got "Assume that there are six things in your loop, i.e. arrivals.Count == 6.  Draw two columns, one for 'i', one for arrivals.Count.  Write down what each will be as you go throug the loop.  See when it will come out of the loop."

so I starts at 0, and arrivals at 6
Loop 1
i =1, arrivals = 5
Loop 2
i = 2 arrivals = 4
Loop 3
i = 3 arrivals = 3
Loop 4
i = 4 arrivals = 2
Loop 5
i = 5 arrivals = 1
Loop 6
i = 6 arrivals = 0

ends at loop 6..


 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the code in your opening post:

And this is your latest code above:

And this is what I wrote a couple of replies back:

Piet wrote:By the way: in C#, if you have a for loop, like 'for (A; B) {...}' (note the syntax carefully!) do you get a compiler error?

 
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The initial post I guess I was just in a hurry, and didnt finish writing everything for the for loop. The latest code with the fixed for loop is still not correct, its the code inside the loop that im after. Not sure what you mean by 'for (A; B) {...}
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With 'for (A;B)'I simply mean that there are only two statements between the parentheses. Be careful to supply correct code, since that is all a replier has to base his answer on.

Problem is I can't check the code, since I don't have Visual Studio. But I looked at this code before and it seemed ok to me. Here is what happens, and try to figure what goes wrong in this process:

1) in the CustomerCreator class, there is a method called 'initializeArrivals' and is invoked in the constructor. This method divides the 90 customers over an array customerArrivals[120]. So, some indices in this array will contain no arrivals, while other may contain one or more.

2) Also in the CustomerGenerator class, we have the method 'public Queue<Customer> GetCustomers(int timeSlot)'. The number of arrivals (see above) is equal to customerArrivals[timeSlot] and that same number of customers is added to the return value of the method: Queue<Customer> customers

3) now have a look at line 38 and further of your Bank class:

arrivals is the queue that contains the customers that arrived at the moment of timeSlot. It seems right to me that these customers are dequeued from arrivals nd enqueued in the customer waiting queue.

Now, either put some Console.Writes(<variable of interest>) at some handy places, so that you can follow if it indeed works s I think, or run with a single stepper through that part of the code, to see if something goes wrong and where that might be going wrong.
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found the (well: an) error, of the well-known type 'Ah, of course...'

Look at the continuation condition of the for loop. What happens to 'arrivals.Count' when you do: 'arrivals.Dequeue();'? For instance: if two clients arrive, how many will be added to the customerQueue?
In Java you could simply do: customerQueue.addAll(arrivals); no doubt C# has a similat method.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was actually looking at that this morning. The loop wont get past loop 3 because i will no longer be less than arrivals, it will be equal to arrivals. Unfortunately looking through the methods given to me by the queue there is no addAll. The only add method is enqueue  
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a simple solution. Just before the loop do: int newCustomers = arrivals.Count, and use that in your loop
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see what you are saying. In keeping with the same example I used with the two columns if arrivals contains 6 things, then it would loop all 6 times instead of the 3 times when arrivals is getting customers taken out.



Then for my teller maxTime I did this. Not sure if this is it.


 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks fine to me. An idea is to print out the teller list,  before doing the statistics. You can then check your calculations easily.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. Hes suppose to send us sample output of what its suppose to be or be around I guess he said. I appreciate all the help Piet! This semester has not been the best with my UC still not in check, but can not let that stop me. This is my last class until I graduate, so I have to make sure I get the most out of it that I can even if im sick
 
Piet Souris
Bartender
Posts: 5584
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I had (and still have) my (un)fair share of these horrible auto immune defiencies.  I hope you will have a long and stable period to come. Meanwhile, en,joy the study, and keep the questions coming! For your efforts, why not have a cow?
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic