Open jeremyojf opened 3 years ago
Your error seems more like a comparator issue as of right now, what test case is this?
If you do not want to generate one by one, you can do it like what I did: which is generate arrays for all of them in the constructor and have the program iterate through them.
As for arrival time, I generated it like this:
For service time, I just generated an array of it and increase the count for it every time a served event occurs:
For rest time, I did something similar with service time:
Oops forgot about the tc. It's 5_1.
I don't think it's a comparator issue, I mean it worked for level 1-4. Here's how I compared it using Comparable\<Event>
@Override
public int compareTo(Event another) {
//Sort by time -> customerID -> eventRank
if (getStartTime() < another.getStartTime()) {
return -1;
} else if (getStartTime() > another.getStartTime()) {
return 1;
} else if (customer.getCustomerID() != another.customer.getCustomerID()) {
return customer.getCustomerID() - another.customer.getCustomerID();
} else {
return eventRank() - another.eventRank();
}
}
Order of events are Arrive -> Wait -> Serve -> Done -> Leave
Here's how I did the random generation:
int customerCount = 1;
boolean isGreedy;
//First Customer
double timeNow = 0;
isGreedy = gen.genCustomerType() < greedyProbability;
Event firstEvent = new ArriveEvent(new Customer(customerCount, timeNow, isGreedy), servers);
for (int i = 1; i < n; i++) {
double arrTime = timeNow + gen.genInterArrivalTime();
isGreedy = gen.genCustomerType() < greedyProbability;
customerCount++;
Event newEvent = new ArriveEvent(new Customer(customerCount, arrTime, isGreedy), servers);
pq.add(newEvent);
}
LinkedList<Double> restTimes = new LinkedList<>();
for (int i = 0; i < n; i++) {
double restTime;
if (gen.genRandomRest() < restingProbability) {
restTime = gen.genRestPeriod();
} else {
restTime = 0;
}
restTimes.add(restTime);
}
you need to update your timeNow variable in your loop else its will always be 0, thats why your customer timing is off
Specifically @random689 is talking about this line: double arrTime = timeNow + gen.genInterArrivalTime();
It should be timeNow += gen.genInterArrivalTime();
Then make your customers via new Customer(customerCount, timeNow, isGreedy) inside the loop.
i generate the arrival time first and generate 9 times since the first arrival time is given as 0. For the rest service time and resttime, you need to generate the time on the spot. for instance, although customer 8 arrive before customer 9, but they may queue in different position due to greedy/not greedy thus there Is chance that customer 9 is served before customer 8. Same for the resttime, as some need to rest while others do not, if you generate all the time at the start, it is not possible to match them to the correct customer.
Summary
Does the order of generating the random numbers matter? Do they need to be in a specific order, or can I bulk create 10x genA, then 10x genB, vs 1x genA, 1x genB, 1x genA, 1x genB, ...
Edit: This is for tc 5_1
Description
I know the description says this: It is also worth noting that the service time cannot be generated together with the arrival time as each customer is created before the simulation starts, since the nth customer to arrive might not be the nth customer to be served! But this doesn't really mention if the order for each type of generation is separate or are they all combined.
Screenshots: