SlideShare a Scribd company logo
1 of 12
Download to read offline
ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularDistribution.java (add
exception handling only)
Simulator.java
/**
* @author Mehrdad Sabetzadeh, University of Ottawa
*
*/
public class Simulator {
/**
* Length of car plate numbers
*/
public static final int PLATE_NUM_LENGTH = 3;
/**
* Number of seconds in one hour
*/
public static final int NUM_SECONDS_IN_1H = 3600;
/**
* Maximum duration a car can be parked in the lot
*/
public static final int MAX_PARKING_DURATION = 8 * NUM_SECONDS_IN_1H;
/**
* Total duration of the simulation in (simulated) seconds
*/
public static final int SIMULATION_DURATION = 24 * NUM_SECONDS_IN_1H;
/**
* The probability distribution for a car leaving the lot based on the duration
* that the car has been parked in the lot
*/
public static final TriangularDistribution departurePDF = new TriangularDistribution(0,
MAX_PARKING_DURATION / 2,
MAX_PARKING_DURATION);
/**
* The probability that a car would arrive at any given (simulated) second
*/
private Rational probabilityOfArrivalPerSec;
/**
* The simulation clock. Initially the clock should be set to zero; the clock
* should then be incremented by one unit after each (simulated) second
*/
private int clock;
/**
* Total number of steps (simulated seconds) that the simulation should run for.
* This value is fixed at the start of the simulation. The simulation loop
* should be executed for as long as clock < steps. When clock == steps, the
* simulation is finished.
*/
private int steps;
/**
* Instance of the parking lot being simulated.
*/
private ParkingLot lot;
/**
* Queue for the cars wanting to enter the parking lot
*/
private Queue incomingQueue;
/**
* Queue for the cars wanting to leave the parking lot
*/
private Queue outgoingQueue;
/**
* @param lot is the parking lot to be simulated
* @param steps is the total number of steps for simulation
*/
public Simulator(ParkingLot lot, int perHourArrivalRate, int steps) {
throw new UnsupportedOperationException("This method has not been implemented yet!");
}
/**
* Simulate the parking lot for the number of steps specified by the steps
* instance variable
* NOTE: Make sure your implementation of simulate() uses peek() from the Queue interface.
*/
public void simulate() {
throw new UnsupportedOperationException("This method has not been implemented yet!");
}
public int getIncomingQueueSize() {
throw new UnsupportedOperationException("This method has not been implemented yet!");
}
}
CapacityOptimizer.java
public class CapacityOptimizer {
private static final int NUM_RUNS = 10;
private static final double THRESHOLD = 5.0d;
public static int getOptimalNumberOfSpots(int hourlyRate) {
throw new UnsupportedOperationException("This method has not been implemented yet!");
}
public static void main(String args[]) {
StudentInfo.display();
long mainStart = System.currentTimeMillis();
if (args.length < 1) {
System.out.println("Usage: java CapacityOptimizer ");
System.out.println("Example: java CapacityOptimizer 11");
return;
}
if (!args[0].matches("d+")) {
System.out.println("The hourly rate of arrival should be a positive integer!");
return;
}
int hourlyRate = Integer.parseInt(args[0]);
int lotSize = getOptimalNumberOfSpots(hourlyRate);
System.out.println();
System.out.println("SIMULATION IS COMPLETE!");
System.out.println("The smallest number of parking spots required: " + lotSize);
long mainEnd = System.currentTimeMillis();
System.out.println("Total execution time: " + ((mainEnd - mainStart) / 1000f) + " seconds");
}
}
TriangularDistribution.java
/**
* This class provides an implementation of a triangular probabilistic
* distribution. A simple mathematical explanation of this probability
* distribution is available on Wikipedia at:
* https://en.wikipedia.org/wiki/Triangular_distribution
*
* @author Mehrdad Sabetzadeh, University of Ottawa
*
*/
public class TriangularDistribution {
/**
* a, c, b are the three parameters on the x axis of
* https://en.wikipedia.org/wiki/File:Triangular_distribution_PMF.png
*/
int a, c, b;
/**
* Constructor for TriangularDistribution. You need to verify that the following
* condition holds: a >= 0 AND a < c AND c < b
*
* @param a is the lower limit of the distribution
* @param c is the mode
* @param b is the upper limit of the distribution
*/
public TriangularDistribution(int a, int c, int b) {
if (a < c && c < b) {
this.a = a;
this.c = c;
this.b = b;
} else {
// Hint: throw an appropriate exception here!
}
}
/**
* @param x is a point on the x axis
* @return the probability density at point x
*/
public Rational pdf(int x) {
if (x < a)
return Rational.zero;
if (x >= a && x <= c)
return new Rational(2 * (x - a), (b - a) * (c - a));
if (x > c && x <= b)
return new Rational(2 * (b - x), (b - a) * (b - c));
return Rational.zero;
}
}
Car.java
/**
* @author Mehrdad Sabetzadeh, University of Ottawa
*
* The implementation of this class is complete. You do *not* need to
* change this class in this assignment.
*
*/
public class Car {
/**
* Instance variable for storing the car plate number
*/
private String plateNum;
/**
* @return the plate number
*/
public String getPlateNum() {
return plateNum;
}
/**
* Sets the car plate number
*
* @param plateNum is the car plate number
*/
public void setPlateNum(String plateNum) {
this.plateNum = plateNum;
}
/**
* Constructor for Car
*
* @param type is the type of the car
* @param plateNum is the car plate number
*/
public Car(String plateNum) {
this.plateNum = plateNum;
}
/**
* Returns a string representation of the car
*/
public String toString() {
return "Plate: " + plateNum;
}
}
List.java
// lots of missing methods and missing implementations
public interface List {
abstract void add(E elem);
abstract E remove(int index);
abstract boolean remove(E o);
abstract E get(int index);
abstract int size();
abstract boolean isEmpty();
}
Queue.java
/**
* @author Marcel Turcotte, Guy-Vincent Jourdan and Mehrdad Sabetzadeh
* (University of Ottawa)
*
* The declaration of this interface is complete. You do *not* need to
* change this interface in this assignment.
*
*/
public interface Queue {
boolean isEmpty();
void enqueue(E newElement);
E dequeue();
E peek();
int size();
}
RandomGenerator.java
import java.util.Random;
/**
* @author Mehrdad Sabetzadeh, University of Ottawa
*
* The implementation of this class is complete. You do *not* need to
* change this class in this assignment.
*
*/
public class RandomGenerator {
/**
* Array of admissible characters in randomly generated strings (for car plates)
*/
private static final char[] ALPHANUM = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
/**
* Instance of Random class; all random quantities in this assignment will be
* generated through this single instance of Random
*/
private static Random rand = new Random();
/**
* @param probability is the probability of the event of interest occurring
* within a SINGLE simulated time unit. The simulated time
* unit in this assignment is a second. For example, if this
* method is called with probability being 1/100, that means
* that the event of interest has a 1% probability of
* occurring in that second. This probability would translate
* to a (probabilistic) arrival rate of 3600 * 1% = 36 cars
* per hour.
* @return true if the event of interest occurred within the current single time
* unit, false otherwise
*/
public static boolean eventOccurred(Rational probability) {
if (probability.numerator() <= 0 || probability.denominator() < probability.numerator()) {
return false;
}
int number = rand.nextInt(probability.denominator());
if (number < probability.numerator())
return true;
return false;
}
/**
* @param length is the length of the random string to generate
* @return a random string with the specified length
*/
public static String generateRandomString(int length) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
buffer.append(ALPHANUM[rand.nextInt(ALPHANUM.length)]);
}
return buffer.toString();
}
} In this assignment, we continue with the parking-simulator theme established in Assignments
1 and 2. Our goal in Assignment 3 (A3) is as follows: knowing a priori the car arrival rate and
how long cars stay in the lot, we would like to determine the minimum number of spots that the
parking lot should have to avoid excessive queue buildup at the entrance. What we do in A3
represents a real-world application for simulation: when a real parking lot is being designed, an
informed decision needs to be made about how many spots are needed. If there are too few spots,
the parking lot will be overwhelmed; in our simulation, such a situation manifests itself as an
unacceptably large queue buildup at the parking entrance. Just as having too few spots is
problematic, having too many is problematic too! If the capacity of the parking lot exceeds
demand by a large margin, the lot will be under-utilized. If this happens, the operational costs of
the lot may exceed the revenue that the lot generates, potentially making the lot financially
unviable. Finding a balance between supply and demand is therefore essential. What we aim to
calculate in A3 is "just the right number of spots", given an hourly car arrival rate and the
probability distribution for how long a car stays parked once it has entered the lot. For simplicity,
like in A2, we assume that the probability distribution for departures is fixed. The code that you
develop in A 3 therefore has only one user-defined parameter: the hourly car arrival rate.
Provided with this parameter, your implementation should simulate the parking lot for different
numbers of spots and determine the lowest number of spots that meets demand (we discuss what
we mean by "meeting demand" a bit later). Like in A2, a simulation run spans 24 (simulated)
hours. However, in contrast to A2, we need to run the simulation numerous times rather than just
once. Specifically, we need to progressively try larger numbers of spots 1,2,, all the way to the
number of spots that would meet demand. For example, suppose we set the hourly rate to 3 cars
per hour. To determine how large our lot should be for this level of demand, we start by
simulating a lot that has only one spot, then a lot that has only two spots, then a lot that has only
three spots, and so on. Let us assume that, through this process, we determine that our lot needs
15 spots to meet demand. This means that we will have simulated the parking lot 15 times, each
time for 24 (simulated) hours. The question that now arises is whether we can trust a single
simulation run? For example, if we run the simulation only once with 15 spots and somehow we
see that there is no queue buildup at the entrance, can we have reasonable confidence that 15
spots would be sufficient? The answer is No! Why? Because our simulation is probabilistic. Like
in every probabilistic process, we need to mitigate random variation, that is, the chances of being
too lucky or too unlucky in a single run. And, how do we mitigate random variation? By
repeating the simulation process several times. A common strategy is to have 10 repetitions and
consider the average results. Going back to our example in the previous paragraph, to account for
random variation, we need to run the simulation 10 times for a lot that has one spot, 10 times for
a lot that has two spots, and so on. This means that we will have simulated the parking lot 150
times (as opposed to merely 15 times) in the scenario described earlier where we found 15 spots
would meet demand. In A3, what we want to obtain from an individual simulation run is the
number of cars left in the entrance queue after 24 (simulated) hours. To accept a number n of
spots as meeting demand, we repeat for 10 times the simulation with n spots. If the average
queue size (across 10 runs) is below a given threshold, we can be reasonably confident that
having n spots is sufficient. For this assignment, we define "meeting demand" as yielding an
average entrance queue length of 5 across 10 simulation runs. In other words, if we repeat the
simulation with n spots for 10
1. Initialize lot size (n) to 1; 2. Repeat { 3. Do 10 times { 4. Simulate the lot for 24 hours at the
(user-provided) car arrival rate; 5. 3 6. Take the average of incoming queue sizes across the 10
simulation runs; 7. if (average <=5 ) { II The lot is large enough to meet demand 8. break out of
the Repeat loop; 9. else { I/ The lot is still not large enough to meet demand 10. n=n+1 11. }
12. } Figure 1: Algorithm (pseudo-code) for determining the number n of spots to meet parking
demand times, take the average of the queue length at the entrance (after 24 simulated hours),
and this average is 5, then we are done and return n as meeting demand. Figure 1 provides the
pseudo-code for finding the smallest number of spots n that meets demand. You get to
implement this algorithm in Task 4 , below. To simplify the implementation and further to give
you more exposure to the new concepts we will see in class (particularly lists), various tweaks
need to be made to the code you previously wrote in A2 before you can adapt that code for A3.
To assist you with the implementation, this assignment is broken down into five tasks, numbered
1 to 5, as discussed below. Please keep in mind that the tasks are not of equal sizes. For A3, you
can reuse the code you wrote in A2 as well as the reference A2 solution provided to you.
Task 3. Update the Simula tor class. Modify the simulate() method in the Simulator class to work
with the revised interface of ParkingLot and the new peek () method in Queue. In addition,
implement the get IncomingQueueSize () method of Simulator using the size() method of Queue.
The get IncomingQueueSize() is going to be used in the Capacity0ptimizer class (next task) to
determine the size of the incoming queue after a simulation run. IMPORTANT!: To complete
Tasks 1 and 3, please start with the starter code provided for A3 and bring what you need from
A2 one method at a time. Do not start with your A2 implementation. Several small changes have
been made since A2; you would not want to get stuck due to these changes potentially going
unnoticed. Task 4. Complete the Capacity0ptimizer class. Implement the algorithm of Figure 1.
Your implementation will go into the get0ptimalNumber0fSpots (...) method of
Capacity0ptimizer. This method writes out statistics to the standard output. The format of the
reported statistics is straightforward and illustrated below. Note that in our illustration, the results
for lot sizes between 2 and 13 have been removed due to space. $ java Capacity0ptimizer 3 ===
Setting lot capacity to: 1==== Simulation run 1 (23ms); Queue length at the end of simulation
run: 68 Simulation run 2 (11ms); Queue length at the end of simulation run: 66 Simulation run 3
(11ms); Queue length at the end of simulation run: 73 Simulation run 4 (10ms); Queue length at
the end of simulation run: 61 Simulation run 5 (10ms); Queue length at the end of simulation
run: 82 Simulation run 6 (9ms); Queue length at the end of simulation run: 61 Simulation run 7
(10ms); Queue length at the end of simulation run: 76 Simulation run 8 (9ms); Queue length at
the end of simulation run: 63 Simulation run 9 (8ms); Queue length at the end of simulation run:
61 Simulation run 10 (9ms); Queue length at the end of simulation run: 64 [... RESULTS FOR
LOT SIZES 2 to 13 NOT SHOWN DUE TO SPACE ...] === Setting lot capacity to: 14====
Simulation run 1 (92ms); Queue length at the end of simulation run: 1 Simulation run 2(82ms);
Queue length at the end of simulation run: 7 Simulation run 3 (103ms); Queue length at the end
of simulation run: 4 Simulation run 4 (97ms); Queue length at the end of simulation run: 18
Simulation run 5 (95ms); Queue length at the end of simulation run: 14 Simulation run 6 (94ms);
Queue length at the end of simulation run: 1 Simulation run 7 (98ms); Queue length at the end of
simulation run: 4 Simulation run 8 (81ms); Queue length at the end of simulation run: 2
Simulation run 9 (102ms); Queue length at the end of simulation run: 8 Simulation run 10
(97ms); Queue length at the end of simulation run: 19 === Setting lot capacity to: 15====
Simulation run 1 (95ms); Queue length at the end of simulation run: 4 Simulation run 2 (105ms);
Queue length at the end of simulation run: 11 Simulation run 3 (95ms); Queue length at the end
of simulation run: 0 Simulation run 4 (103ms); Queue length at the end of simulation run: 11
Simulation run 5 (92ms); Queue length at the end of simulation run: 10 Simulation run 6 (96ms);
Queue length at the end of simulation run: 7 Simulation run 7 (90ms); Queue length at the end of
simulation run: 0 Simulation run 8 (95ms); Queue length at the end of simulation run: 0
Simulation run 9 (99ms); Queue length at the end of simulation run: 2 Simulation run 10 (94ms);
Queue length at the end of simulation run: 0 SIMULATION IS COMPLETE! The smallest
number of parking spots required: 15 Total execution time: 8.603 seconds $
Alongside the A3 starter code, you will find several examples of output; see the outputs
directory. Note that due to the probabilistic nature of the simulation, you should not expect the
same output when you simulate the same hourly rate a number of times. What you will find to be
more robust than individual simulation runs is the average across 10 runs. For example, if you set
the arrival rate to 3 cars per hour, you are very likely to converge on 152 as the required number
of spots for the parking lot. Task 5. Enhance Your Code with Exception Handling. Implement
exception handling for the methods in the following there classes: ParkingLot, Simulator and
TriangularDistribution. Specifically, and for the purposes of this assignment, you are asked to
check the validity of the arguments provided to the public methods for these three classes and
throw suitable exceptions when invalid arguments are provided, e.g., an out-of-bound index or a
null argument when a non-null argument is expected. Implementation We are now ready to
program our solution. Just like in A2, you need to follow the patterns provided to you in the
template code. To ensure you follow the rules on what is allowed and what is not, please consult
post @25 on Piazza. For A3, you are strongly discouraged from introducing any new (private)
instance variables. Introducing such variables can potentially take you away from the intended
solution strategy and result in lost marks. Notably, the occupancy information in ParkingLot
must be implemented through lists and not arrays. You can complete the tasks in any order you
like. However, I encourage you to follow the order in which the tasks appear (that is, Task 1,
then Task 2, and so on). Like in A2, guidance is provided through comments in the starter code.
The locations where you need to write your code are clearly indicated with an inline comment
which reads as follows:

More Related Content

Similar to ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf

(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_iiNico Ludwig
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfarjunhassan8
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfezonesolutions
 
#include iostream #include string #include fstream std.docx
#include iostream #include string #include fstream  std.docx#include iostream #include string #include fstream  std.docx
#include iostream #include string #include fstream std.docxajoy21
 
#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docx#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docxajoy21
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxalanfhall8953
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAndrey Karpov
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfnewfaransportsfitnes
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and ThreadsMathias Seguy
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfaquadreammail
 
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...Akaks
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfarchgeetsenterprises
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfabdulrahamanbags
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docxaryan532920
 

Similar to ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf (20)

(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii(7) cpp abstractions inheritance_part_ii
(7) cpp abstractions inheritance_part_ii
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdf
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
 
#include iostream #include string #include fstream std.docx
#include iostream #include string #include fstream  std.docx#include iostream #include string #include fstream  std.docx
#include iostream #include string #include fstream std.docx
 
#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docx#include iostream #include string#includeiomanip using.docx
#include iostream #include string#includeiomanip using.docx
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
 
Asterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up TelephonyAsterisk: PVS-Studio Takes Up Telephony
Asterisk: PVS-Studio Takes Up Telephony
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
 
Base de-datos
Base de-datosBase de-datos
Base de-datos
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and Threads
 
operating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdfoperating system linux,ubuntu,Mac Geometri.pdf
operating system linux,ubuntu,Mac Geometri.pdf
 
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
 
Functions
FunctionsFunctions
Functions
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdf
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
 
Wien15 java8
Wien15 java8Wien15 java8
Wien15 java8
 
PSI 3 Integration
PSI 3 IntegrationPSI 3 Integration
PSI 3 Integration
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 

More from vinodagrawal6699

Please answer it as soon as possible Chapter 2- Part 2 Link Stat.pdf
Please answer it as soon as possible  Chapter 2- Part 2 Link Stat.pdfPlease answer it as soon as possible  Chapter 2- Part 2 Link Stat.pdf
Please answer it as soon as possible Chapter 2- Part 2 Link Stat.pdfvinodagrawal6699
 
Please answer in Arm assembly language The file palindrome.s conta.pdf
Please answer in Arm assembly language The file palindrome.s conta.pdfPlease answer in Arm assembly language The file palindrome.s conta.pdf
Please answer in Arm assembly language The file palindrome.s conta.pdfvinodagrawal6699
 
Please answer in Arm assembly languageThe file palindrome.s contai.pdf
Please answer in Arm assembly languageThe file palindrome.s contai.pdfPlease answer in Arm assembly languageThe file palindrome.s contai.pdf
Please answer in Arm assembly languageThe file palindrome.s contai.pdfvinodagrawal6699
 
please answer detail thank you 5 .Deontology and consequentialism .pdf
please answer detail thank you 5 .Deontology and consequentialism .pdfplease answer detail thank you 5 .Deontology and consequentialism .pdf
please answer detail thank you 5 .Deontology and consequentialism .pdfvinodagrawal6699
 
Please answer based on the requirements written in the photo.Pro.pdf
Please answer based on the requirements written in the photo.Pro.pdfPlease answer based on the requirements written in the photo.Pro.pdf
Please answer based on the requirements written in the photo.Pro.pdfvinodagrawal6699
 
Please answer based on the requirements written in the photo.Prepa.pdf
Please answer based on the requirements written in the photo.Prepa.pdfPlease answer based on the requirements written in the photo.Prepa.pdf
Please answer based on the requirements written in the photo.Prepa.pdfvinodagrawal6699
 
Playground Project PlanYou have been asked to create a project pla.pdf
Playground Project PlanYou have been asked to create a project pla.pdfPlayground Project PlanYou have been asked to create a project pla.pdf
Playground Project PlanYou have been asked to create a project pla.pdfvinodagrawal6699
 
Pleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdfPleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdfvinodagrawal6699
 
Pleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdfPleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdfvinodagrawal6699
 
Plasmids do all of the following EXCEPTO have their own initiation.pdf
Plasmids do all of the following EXCEPTO have their own initiation.pdfPlasmids do all of the following EXCEPTO have their own initiation.pdf
Plasmids do all of the following EXCEPTO have their own initiation.pdfvinodagrawal6699
 
plan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdf
plan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdfplan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdf
plan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdfvinodagrawal6699
 
Physicians� Hospital has the following balances on December 31, 2024.pdf
Physicians� Hospital has the following balances on December 31, 2024.pdfPhysicians� Hospital has the following balances on December 31, 2024.pdf
Physicians� Hospital has the following balances on December 31, 2024.pdfvinodagrawal6699
 
Peter arrend� un espacio de oficina comercial al arrendador sobre la.pdf
Peter arrend� un espacio de oficina comercial al arrendador sobre la.pdfPeter arrend� un espacio de oficina comercial al arrendador sobre la.pdf
Peter arrend� un espacio de oficina comercial al arrendador sobre la.pdfvinodagrawal6699
 
Philip Brickell, a forty-three-year-old employee of the London Under.pdf
Philip Brickell, a forty-three-year-old employee of the London Under.pdfPhilip Brickell, a forty-three-year-old employee of the London Under.pdf
Philip Brickell, a forty-three-year-old employee of the London Under.pdfvinodagrawal6699
 
Periferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdf
Periferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdfPeriferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdf
Periferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdfvinodagrawal6699
 
paypal i�in sorular Paypaln profili nedir Kullanm nasl.pdf
paypal i�in sorular Paypaln profili nedir Kullanm nasl.pdfpaypal i�in sorular Paypaln profili nedir Kullanm nasl.pdf
paypal i�in sorular Paypaln profili nedir Kullanm nasl.pdfvinodagrawal6699
 
Paul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdf
Paul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdfPaul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdf
Paul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdfvinodagrawal6699
 
Party Supply Inc. a calender year corporation, took a physical inven.pdf
Party Supply Inc. a calender year corporation, took a physical inven.pdfParty Supply Inc. a calender year corporation, took a physical inven.pdf
Party Supply Inc. a calender year corporation, took a physical inven.pdfvinodagrawal6699
 
Parte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdf
Parte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdfParte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdf
Parte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdfvinodagrawal6699
 
PART I Think about the best and worst companies you know. What is e.pdf
PART I Think about the best and worst companies you know. What is e.pdfPART I Think about the best and worst companies you know. What is e.pdf
PART I Think about the best and worst companies you know. What is e.pdfvinodagrawal6699
 

More from vinodagrawal6699 (20)

Please answer it as soon as possible Chapter 2- Part 2 Link Stat.pdf
Please answer it as soon as possible  Chapter 2- Part 2 Link Stat.pdfPlease answer it as soon as possible  Chapter 2- Part 2 Link Stat.pdf
Please answer it as soon as possible Chapter 2- Part 2 Link Stat.pdf
 
Please answer in Arm assembly language The file palindrome.s conta.pdf
Please answer in Arm assembly language The file palindrome.s conta.pdfPlease answer in Arm assembly language The file palindrome.s conta.pdf
Please answer in Arm assembly language The file palindrome.s conta.pdf
 
Please answer in Arm assembly languageThe file palindrome.s contai.pdf
Please answer in Arm assembly languageThe file palindrome.s contai.pdfPlease answer in Arm assembly languageThe file palindrome.s contai.pdf
Please answer in Arm assembly languageThe file palindrome.s contai.pdf
 
please answer detail thank you 5 .Deontology and consequentialism .pdf
please answer detail thank you 5 .Deontology and consequentialism .pdfplease answer detail thank you 5 .Deontology and consequentialism .pdf
please answer detail thank you 5 .Deontology and consequentialism .pdf
 
Please answer based on the requirements written in the photo.Pro.pdf
Please answer based on the requirements written in the photo.Pro.pdfPlease answer based on the requirements written in the photo.Pro.pdf
Please answer based on the requirements written in the photo.Pro.pdf
 
Please answer based on the requirements written in the photo.Prepa.pdf
Please answer based on the requirements written in the photo.Prepa.pdfPlease answer based on the requirements written in the photo.Prepa.pdf
Please answer based on the requirements written in the photo.Prepa.pdf
 
Playground Project PlanYou have been asked to create a project pla.pdf
Playground Project PlanYou have been asked to create a project pla.pdfPlayground Project PlanYou have been asked to create a project pla.pdf
Playground Project PlanYou have been asked to create a project pla.pdf
 
Pleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdfPleae help me with this C++ question, ill upvote thanks.Write the .pdf
Pleae help me with this C++ question, ill upvote thanks.Write the .pdf
 
Pleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdfPleae help me with this C++ task to the required result by edit or f.pdf
Pleae help me with this C++ task to the required result by edit or f.pdf
 
Plasmids do all of the following EXCEPTO have their own initiation.pdf
Plasmids do all of the following EXCEPTO have their own initiation.pdfPlasmids do all of the following EXCEPTO have their own initiation.pdf
Plasmids do all of the following EXCEPTO have their own initiation.pdf
 
plan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdf
plan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdfplan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdf
plan de atenci�n de enfermer�a para Linda Pittmon, una paciente de 7.pdf
 
Physicians� Hospital has the following balances on December 31, 2024.pdf
Physicians� Hospital has the following balances on December 31, 2024.pdfPhysicians� Hospital has the following balances on December 31, 2024.pdf
Physicians� Hospital has the following balances on December 31, 2024.pdf
 
Peter arrend� un espacio de oficina comercial al arrendador sobre la.pdf
Peter arrend� un espacio de oficina comercial al arrendador sobre la.pdfPeter arrend� un espacio de oficina comercial al arrendador sobre la.pdf
Peter arrend� un espacio de oficina comercial al arrendador sobre la.pdf
 
Philip Brickell, a forty-three-year-old employee of the London Under.pdf
Philip Brickell, a forty-three-year-old employee of the London Under.pdfPhilip Brickell, a forty-three-year-old employee of the London Under.pdf
Philip Brickell, a forty-three-year-old employee of the London Under.pdf
 
Periferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdf
Periferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdfPeriferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdf
Periferik tolerans, bariyer bakl i�in neden kritiktir A) Uygun .pdf
 
paypal i�in sorular Paypaln profili nedir Kullanm nasl.pdf
paypal i�in sorular Paypaln profili nedir Kullanm nasl.pdfpaypal i�in sorular Paypaln profili nedir Kullanm nasl.pdf
paypal i�in sorular Paypaln profili nedir Kullanm nasl.pdf
 
Paul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdf
Paul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdfPaul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdf
Paul Casey se retir� de la Marina de los EE. UU. en 2013. Recibe una.pdf
 
Party Supply Inc. a calender year corporation, took a physical inven.pdf
Party Supply Inc. a calender year corporation, took a physical inven.pdfParty Supply Inc. a calender year corporation, took a physical inven.pdf
Party Supply Inc. a calender year corporation, took a physical inven.pdf
 
Parte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdf
Parte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdfParte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdf
Parte 1 �Cu�l es el capital contable total de la Entidad A con bas.pdf
 
PART I Think about the best and worst companies you know. What is e.pdf
PART I Think about the best and worst companies you know. What is e.pdfPART I Think about the best and worst companies you know. What is e.pdf
PART I Think about the best and worst companies you know. What is e.pdf
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 

ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf

  • 1. ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularDistribution.java (add exception handling only) Simulator.java /** * @author Mehrdad Sabetzadeh, University of Ottawa * */ public class Simulator { /** * Length of car plate numbers */ public static final int PLATE_NUM_LENGTH = 3; /** * Number of seconds in one hour */ public static final int NUM_SECONDS_IN_1H = 3600; /** * Maximum duration a car can be parked in the lot */ public static final int MAX_PARKING_DURATION = 8 * NUM_SECONDS_IN_1H; /** * Total duration of the simulation in (simulated) seconds */ public static final int SIMULATION_DURATION = 24 * NUM_SECONDS_IN_1H; /** * The probability distribution for a car leaving the lot based on the duration * that the car has been parked in the lot */ public static final TriangularDistribution departurePDF = new TriangularDistribution(0, MAX_PARKING_DURATION / 2, MAX_PARKING_DURATION); /** * The probability that a car would arrive at any given (simulated) second
  • 2. */ private Rational probabilityOfArrivalPerSec; /** * The simulation clock. Initially the clock should be set to zero; the clock * should then be incremented by one unit after each (simulated) second */ private int clock; /** * Total number of steps (simulated seconds) that the simulation should run for. * This value is fixed at the start of the simulation. The simulation loop * should be executed for as long as clock < steps. When clock == steps, the * simulation is finished. */ private int steps; /** * Instance of the parking lot being simulated. */ private ParkingLot lot; /** * Queue for the cars wanting to enter the parking lot */ private Queue incomingQueue; /** * Queue for the cars wanting to leave the parking lot */ private Queue outgoingQueue; /** * @param lot is the parking lot to be simulated * @param steps is the total number of steps for simulation */ public Simulator(ParkingLot lot, int perHourArrivalRate, int steps) { throw new UnsupportedOperationException("This method has not been implemented yet!"); } /**
  • 3. * Simulate the parking lot for the number of steps specified by the steps * instance variable * NOTE: Make sure your implementation of simulate() uses peek() from the Queue interface. */ public void simulate() { throw new UnsupportedOperationException("This method has not been implemented yet!"); } public int getIncomingQueueSize() { throw new UnsupportedOperationException("This method has not been implemented yet!"); } } CapacityOptimizer.java public class CapacityOptimizer { private static final int NUM_RUNS = 10; private static final double THRESHOLD = 5.0d; public static int getOptimalNumberOfSpots(int hourlyRate) { throw new UnsupportedOperationException("This method has not been implemented yet!"); } public static void main(String args[]) { StudentInfo.display(); long mainStart = System.currentTimeMillis(); if (args.length < 1) { System.out.println("Usage: java CapacityOptimizer "); System.out.println("Example: java CapacityOptimizer 11"); return; } if (!args[0].matches("d+")) { System.out.println("The hourly rate of arrival should be a positive integer!"); return;
  • 4. } int hourlyRate = Integer.parseInt(args[0]); int lotSize = getOptimalNumberOfSpots(hourlyRate); System.out.println(); System.out.println("SIMULATION IS COMPLETE!"); System.out.println("The smallest number of parking spots required: " + lotSize); long mainEnd = System.currentTimeMillis(); System.out.println("Total execution time: " + ((mainEnd - mainStart) / 1000f) + " seconds"); } } TriangularDistribution.java /** * This class provides an implementation of a triangular probabilistic * distribution. A simple mathematical explanation of this probability * distribution is available on Wikipedia at: * https://en.wikipedia.org/wiki/Triangular_distribution * * @author Mehrdad Sabetzadeh, University of Ottawa * */ public class TriangularDistribution { /** * a, c, b are the three parameters on the x axis of * https://en.wikipedia.org/wiki/File:Triangular_distribution_PMF.png */ int a, c, b; /** * Constructor for TriangularDistribution. You need to verify that the following * condition holds: a >= 0 AND a < c AND c < b * * @param a is the lower limit of the distribution * @param c is the mode * @param b is the upper limit of the distribution */ public TriangularDistribution(int a, int c, int b) { if (a < c && c < b) {
  • 5. this.a = a; this.c = c; this.b = b; } else { // Hint: throw an appropriate exception here! } } /** * @param x is a point on the x axis * @return the probability density at point x */ public Rational pdf(int x) { if (x < a) return Rational.zero; if (x >= a && x <= c) return new Rational(2 * (x - a), (b - a) * (c - a)); if (x > c && x <= b) return new Rational(2 * (b - x), (b - a) * (b - c)); return Rational.zero; } } Car.java /** * @author Mehrdad Sabetzadeh, University of Ottawa * * The implementation of this class is complete. You do *not* need to * change this class in this assignment. * */ public class Car { /** * Instance variable for storing the car plate number */ private String plateNum;
  • 6. /** * @return the plate number */ public String getPlateNum() { return plateNum; } /** * Sets the car plate number * * @param plateNum is the car plate number */ public void setPlateNum(String plateNum) { this.plateNum = plateNum; } /** * Constructor for Car * * @param type is the type of the car * @param plateNum is the car plate number */ public Car(String plateNum) { this.plateNum = plateNum; } /** * Returns a string representation of the car */ public String toString() { return "Plate: " + plateNum; } } List.java // lots of missing methods and missing implementations public interface List { abstract void add(E elem); abstract E remove(int index); abstract boolean remove(E o);
  • 7. abstract E get(int index); abstract int size(); abstract boolean isEmpty(); } Queue.java /** * @author Marcel Turcotte, Guy-Vincent Jourdan and Mehrdad Sabetzadeh * (University of Ottawa) * * The declaration of this interface is complete. You do *not* need to * change this interface in this assignment. * */ public interface Queue { boolean isEmpty(); void enqueue(E newElement); E dequeue(); E peek(); int size(); } RandomGenerator.java import java.util.Random; /** * @author Mehrdad Sabetzadeh, University of Ottawa * * The implementation of this class is complete. You do *not* need to * change this class in this assignment. * */ public class RandomGenerator { /** * Array of admissible characters in randomly generated strings (for car plates) */ private static final char[] ALPHANUM = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
  • 8. /** * Instance of Random class; all random quantities in this assignment will be * generated through this single instance of Random */ private static Random rand = new Random(); /** * @param probability is the probability of the event of interest occurring * within a SINGLE simulated time unit. The simulated time * unit in this assignment is a second. For example, if this * method is called with probability being 1/100, that means * that the event of interest has a 1% probability of * occurring in that second. This probability would translate * to a (probabilistic) arrival rate of 3600 * 1% = 36 cars * per hour. * @return true if the event of interest occurred within the current single time * unit, false otherwise */ public static boolean eventOccurred(Rational probability) { if (probability.numerator() <= 0 || probability.denominator() < probability.numerator()) { return false; } int number = rand.nextInt(probability.denominator()); if (number < probability.numerator()) return true; return false; } /** * @param length is the length of the random string to generate * @return a random string with the specified length */ public static String generateRandomString(int length) { StringBuffer buffer = new StringBuffer(); for (int i = 0; i < length; i++) { buffer.append(ALPHANUM[rand.nextInt(ALPHANUM.length)]); } return buffer.toString();
  • 9. } } In this assignment, we continue with the parking-simulator theme established in Assignments 1 and 2. Our goal in Assignment 3 (A3) is as follows: knowing a priori the car arrival rate and how long cars stay in the lot, we would like to determine the minimum number of spots that the parking lot should have to avoid excessive queue buildup at the entrance. What we do in A3 represents a real-world application for simulation: when a real parking lot is being designed, an informed decision needs to be made about how many spots are needed. If there are too few spots, the parking lot will be overwhelmed; in our simulation, such a situation manifests itself as an unacceptably large queue buildup at the parking entrance. Just as having too few spots is problematic, having too many is problematic too! If the capacity of the parking lot exceeds demand by a large margin, the lot will be under-utilized. If this happens, the operational costs of the lot may exceed the revenue that the lot generates, potentially making the lot financially unviable. Finding a balance between supply and demand is therefore essential. What we aim to calculate in A3 is "just the right number of spots", given an hourly car arrival rate and the probability distribution for how long a car stays parked once it has entered the lot. For simplicity, like in A2, we assume that the probability distribution for departures is fixed. The code that you develop in A 3 therefore has only one user-defined parameter: the hourly car arrival rate. Provided with this parameter, your implementation should simulate the parking lot for different numbers of spots and determine the lowest number of spots that meets demand (we discuss what we mean by "meeting demand" a bit later). Like in A2, a simulation run spans 24 (simulated) hours. However, in contrast to A2, we need to run the simulation numerous times rather than just once. Specifically, we need to progressively try larger numbers of spots 1,2,, all the way to the number of spots that would meet demand. For example, suppose we set the hourly rate to 3 cars per hour. To determine how large our lot should be for this level of demand, we start by simulating a lot that has only one spot, then a lot that has only two spots, then a lot that has only three spots, and so on. Let us assume that, through this process, we determine that our lot needs 15 spots to meet demand. This means that we will have simulated the parking lot 15 times, each time for 24 (simulated) hours. The question that now arises is whether we can trust a single simulation run? For example, if we run the simulation only once with 15 spots and somehow we see that there is no queue buildup at the entrance, can we have reasonable confidence that 15 spots would be sufficient? The answer is No! Why? Because our simulation is probabilistic. Like in every probabilistic process, we need to mitigate random variation, that is, the chances of being too lucky or too unlucky in a single run. And, how do we mitigate random variation? By repeating the simulation process several times. A common strategy is to have 10 repetitions and consider the average results. Going back to our example in the previous paragraph, to account for random variation, we need to run the simulation 10 times for a lot that has one spot, 10 times for
  • 10. a lot that has two spots, and so on. This means that we will have simulated the parking lot 150 times (as opposed to merely 15 times) in the scenario described earlier where we found 15 spots would meet demand. In A3, what we want to obtain from an individual simulation run is the number of cars left in the entrance queue after 24 (simulated) hours. To accept a number n of spots as meeting demand, we repeat for 10 times the simulation with n spots. If the average queue size (across 10 runs) is below a given threshold, we can be reasonably confident that having n spots is sufficient. For this assignment, we define "meeting demand" as yielding an average entrance queue length of 5 across 10 simulation runs. In other words, if we repeat the simulation with n spots for 10 1. Initialize lot size (n) to 1; 2. Repeat { 3. Do 10 times { 4. Simulate the lot for 24 hours at the (user-provided) car arrival rate; 5. 3 6. Take the average of incoming queue sizes across the 10 simulation runs; 7. if (average <=5 ) { II The lot is large enough to meet demand 8. break out of the Repeat loop; 9. else { I/ The lot is still not large enough to meet demand 10. n=n+1 11. } 12. } Figure 1: Algorithm (pseudo-code) for determining the number n of spots to meet parking demand times, take the average of the queue length at the entrance (after 24 simulated hours), and this average is 5, then we are done and return n as meeting demand. Figure 1 provides the pseudo-code for finding the smallest number of spots n that meets demand. You get to implement this algorithm in Task 4 , below. To simplify the implementation and further to give you more exposure to the new concepts we will see in class (particularly lists), various tweaks need to be made to the code you previously wrote in A2 before you can adapt that code for A3. To assist you with the implementation, this assignment is broken down into five tasks, numbered 1 to 5, as discussed below. Please keep in mind that the tasks are not of equal sizes. For A3, you can reuse the code you wrote in A2 as well as the reference A2 solution provided to you. Task 3. Update the Simula tor class. Modify the simulate() method in the Simulator class to work with the revised interface of ParkingLot and the new peek () method in Queue. In addition, implement the get IncomingQueueSize () method of Simulator using the size() method of Queue. The get IncomingQueueSize() is going to be used in the Capacity0ptimizer class (next task) to determine the size of the incoming queue after a simulation run. IMPORTANT!: To complete Tasks 1 and 3, please start with the starter code provided for A3 and bring what you need from A2 one method at a time. Do not start with your A2 implementation. Several small changes have been made since A2; you would not want to get stuck due to these changes potentially going unnoticed. Task 4. Complete the Capacity0ptimizer class. Implement the algorithm of Figure 1. Your implementation will go into the get0ptimalNumber0fSpots (...) method of Capacity0ptimizer. This method writes out statistics to the standard output. The format of the
  • 11. reported statistics is straightforward and illustrated below. Note that in our illustration, the results for lot sizes between 2 and 13 have been removed due to space. $ java Capacity0ptimizer 3 === Setting lot capacity to: 1==== Simulation run 1 (23ms); Queue length at the end of simulation run: 68 Simulation run 2 (11ms); Queue length at the end of simulation run: 66 Simulation run 3 (11ms); Queue length at the end of simulation run: 73 Simulation run 4 (10ms); Queue length at the end of simulation run: 61 Simulation run 5 (10ms); Queue length at the end of simulation run: 82 Simulation run 6 (9ms); Queue length at the end of simulation run: 61 Simulation run 7 (10ms); Queue length at the end of simulation run: 76 Simulation run 8 (9ms); Queue length at the end of simulation run: 63 Simulation run 9 (8ms); Queue length at the end of simulation run: 61 Simulation run 10 (9ms); Queue length at the end of simulation run: 64 [... RESULTS FOR LOT SIZES 2 to 13 NOT SHOWN DUE TO SPACE ...] === Setting lot capacity to: 14==== Simulation run 1 (92ms); Queue length at the end of simulation run: 1 Simulation run 2(82ms); Queue length at the end of simulation run: 7 Simulation run 3 (103ms); Queue length at the end of simulation run: 4 Simulation run 4 (97ms); Queue length at the end of simulation run: 18 Simulation run 5 (95ms); Queue length at the end of simulation run: 14 Simulation run 6 (94ms); Queue length at the end of simulation run: 1 Simulation run 7 (98ms); Queue length at the end of simulation run: 4 Simulation run 8 (81ms); Queue length at the end of simulation run: 2 Simulation run 9 (102ms); Queue length at the end of simulation run: 8 Simulation run 10 (97ms); Queue length at the end of simulation run: 19 === Setting lot capacity to: 15==== Simulation run 1 (95ms); Queue length at the end of simulation run: 4 Simulation run 2 (105ms); Queue length at the end of simulation run: 11 Simulation run 3 (95ms); Queue length at the end of simulation run: 0 Simulation run 4 (103ms); Queue length at the end of simulation run: 11 Simulation run 5 (92ms); Queue length at the end of simulation run: 10 Simulation run 6 (96ms); Queue length at the end of simulation run: 7 Simulation run 7 (90ms); Queue length at the end of simulation run: 0 Simulation run 8 (95ms); Queue length at the end of simulation run: 0 Simulation run 9 (99ms); Queue length at the end of simulation run: 2 Simulation run 10 (94ms); Queue length at the end of simulation run: 0 SIMULATION IS COMPLETE! The smallest number of parking spots required: 15 Total execution time: 8.603 seconds $ Alongside the A3 starter code, you will find several examples of output; see the outputs directory. Note that due to the probabilistic nature of the simulation, you should not expect the same output when you simulate the same hourly rate a number of times. What you will find to be more robust than individual simulation runs is the average across 10 runs. For example, if you set the arrival rate to 3 cars per hour, you are very likely to converge on 152 as the required number of spots for the parking lot. Task 5. Enhance Your Code with Exception Handling. Implement exception handling for the methods in the following there classes: ParkingLot, Simulator and
  • 12. TriangularDistribution. Specifically, and for the purposes of this assignment, you are asked to check the validity of the arguments provided to the public methods for these three classes and throw suitable exceptions when invalid arguments are provided, e.g., an out-of-bound index or a null argument when a non-null argument is expected. Implementation We are now ready to program our solution. Just like in A2, you need to follow the patterns provided to you in the template code. To ensure you follow the rules on what is allowed and what is not, please consult post @25 on Piazza. For A3, you are strongly discouraged from introducing any new (private) instance variables. Introducing such variables can potentially take you away from the intended solution strategy and result in lost marks. Notably, the occupancy information in ParkingLot must be implemented through lists and not arrays. You can complete the tasks in any order you like. However, I encourage you to follow the order in which the tasks appear (that is, Task 1, then Task 2, and so on). Like in A2, guidance is provided through comments in the starter code. The locations where you need to write your code are clearly indicated with an inline comment which reads as follows: