nus-cs2030 / 2223-s1

MIT License
1 stars 0 forks source link

Struggling with Test Case 8 for Lab 5 #194

Open yanqiyqh opened 1 year ago

yanqiyqh commented 1 year ago

Summary

I'm having trouble with test case 8 and not sure how to debug or find where my code logic is not appropriate.

Description:

From the screenshot I attached, the inputTimes seem to be getting jumbled up as expected output service time is different from my output. Am I calling for serviceTime too many times?

For context, I am currently running Simulator with a helper class ServerManager to manage the queues at each server and update the servers with customer done time when necessary. Simulator takes care of the events and flow (whether customer is immediately served, has to wait to be served, or has to leave) and calls for an available server from ServerManager to create the events.

Code Snippets

Attach code snippets (if any)

Screenshots

Screenshot 2022-10-13 at 4 52 15 PM
wilsonwid commented 1 year ago

Potential issues might include:

lanqinggg commented 1 year ago

Hello! I had the same issue and it was due to calling get() to get the service time before serve event occurs

ziyi105 commented 1 year ago

@wilsonwid do you mind sharing how you implement it such that serviceTime is only retrieved when serveEvent is executed? As for my implementation, the serviceTime is called in wait event to update the expecetedServeTime and busyUntil. If i getServiceTime only when serveEvent is executed, i will get the error shown above

yanqiyqh commented 1 year ago

Served served = new Served(customer, manager.getServer(freeQueueIndex), nextFreeTime); customer = customer.setServedTime(served.getOccurrence()); Done done = new Done(customer, manager.getServer(freeQueueIndex), customer.getServedTime() + customer.getServiceTime()); manager = manager.addServerQueue(freeQueueIndex, served.getOccurrence(), done.getOccurrence()); double waitTime = served.getOccurrence() - customer.getArrival(); Wait wait = new Wait(customer, manager.getServer(freeQueueIndex));

code snippet of calling get when a customer has to wait to be served. i'm not sure whether i'm calling service time before the serve event as i only call it in my Done event

keefetok commented 1 year ago

@wilsonwid do you mind sharing how you implement it such that serviceTime is only retrieved when serveEvent is executed? As for my implementation, the serviceTime is called in wait event to update the expecetedServeTime and busyUntil. If i getServiceTime only when serveEvent is executed, i will get the error shown above

my implementation includes just having serviceTime in serve event. other times, i just use super of the previous event time. if you would like this implementation of serviceTime being only retrieved when serveEvent is executed, then you simply supply the customer with a supplier attribute now rather than a double serviceTime attribute, and use a .get() to obtain the serviceTime from the supplier within the customer.

acekhoon commented 1 year ago

I got exactly same error. There are possible reasons:

  1. Maybe you retrieved service time too early even before the customer is served. It should be retrieved when you execute your method within serve method.
  2. Multiple serving can happen together. For instance, if customer 1 is waiting and customer 2 arrives. Even though customer 1 should be served, since the time where customer 1 arrives and actually serves are not updated accordingly (which means supplier function is not initialized yet), customer 2 might get served ahead of customer 1.
  3. Alternatively even though waiting customer is not time to be served, since the time of serving is not updated accordingly, it might serve customer waiting haphazardly. This was my problem and I resolved it by creating separate waiting class where it checks whether waiting customer can be served or not, and if its serving time stipulated/retrieved from server attribute in the class is too fast (earlier than the desired time), I pass them to new waiting class in order for them to wait in the queue further.
YEETTTTTTT commented 1 year ago

Hi, I came across this error as well. U have to retrieve the service time only when customer is served. u cant retrieve it in wait either

dartyr commented 1 year ago

Got the same issue as well, solved it once i removed retrieving the service time from the wait event

siqirua commented 1 year ago

If u only use the supplier.get() once in ServeEvent and still face this issue, maybe u wanna check whether it is called within the constructor? If it is used in constructor, the supplier is also called in the classes that make a new Serve even though it is only called in ServeEvent

yanqiyqh commented 1 year ago

hi all thanks for your help! ive resolved this by modifying the way i process the queue (i was calling service time before the customer was served) however ive encountered a new issue... do let me know if anyone has gotten this error before and how to resolve it.

image_2022-10-17_11-39-54

all subsequent service times seem to be correct, so i don't think calling service time is an issue anymore, but im not sure why customer 18 and 14 is having problems with their done time being slightly off causing everything else to spiral out of control

YEETTTTTTT commented 1 year ago

Hi, given that the done time for 18 is late by 1sec while the done time for 14 is earlier by 1sec, could be possible that their service times were assigned wrongly i.e. service time for 18 is assigned to 14 and vice versa. You might want to check through ur logic for assigning service times and see if there's anything you missed out