nus-cs2030 / 2021-s2

2 stars 2 forks source link

CS2030 project time limit exceeded #229

Open iztanpy opened 3 years ago

iztanpy commented 3 years ago

Summary

Unsure why my code exceeds the time limit for hidden test case

Tried running it with 200 customers and it seems to work in my terminal

Screenshot 2021-04-16 at 10 42 32 PM

Description

[

Screenshot 2021-04-16 at 10 41 34 PM

](url)

Screenshots (if any):

Insert Images here if necessary

eryuanren commented 3 years ago

if there is no input and it stops due to an infinite loop, it is probably due to the additional event that you added to check for serving time (i called mine Waiting event but idk what your naming is). Since your additional even does not have an output, it is probably stuck in a loop somewhere

hewtungyuen commented 3 years ago

i experienced the same issue as well, but managed to solve it by adjusting my event comparator to prevent recursive calls.

iztanpy commented 3 years ago

hi what do you mean changing the comparator to prevent recursive calls?

if (e1.getTiming() - e2.getTiming() > 0) { 8 return 1; 9 } else if (e1.getTiming() - e2.getTiming() < 0) { 10 return -1; 11 } else if (e1.getTiming() - e2.getTiming() == 0){ 12 return e2.order() - e1.order();

mine is something like this right now? I don't think it should be creating a loop though

hewtungyuen commented 3 years ago

arrive -> wait -> waiting -> serve -> done is my order of events, if lets say the customer cannot be served on arrival. all my events have a customer. my waiting event will check if the customer can be served by the server. if it can be served, a serve event will be returned. else, a waiting event is returned.

so my waiting event can return another waiting event, that was the source of my recursive call. thus i had to change my event comparator to check the customer ID as well, so that the correct order of events is polled from the priority queue. but i think this solution is quite tailored to my implementation haha not sure if it will work for urs too

markwty commented 3 years ago

Try to simulate a 0 server rest time i.e Pr=1 and ρ=0 to try to replicate the issue on your terminal and debug from there.

marcuslim835 commented 3 years ago

if you had implemented the checking sequence with service end time lists, then maybe you could check if your code deals with repeated service end times?

iztanpy commented 3 years ago

ahhh ok I think I got it thank you everyone!