Write a computer program in Python, C, another language you know, or with Excel
ID: 3734234 • Letter: W
Question
Write a computer program in Python, C, another language you know, or with Excel to solve the general version of the parking space problem, described below. Your program should take as input the mean time it takes to shop, the mean inter-arrival time (or the average rate) of potential customers, the mean sales profit gained from a shopper, the monthly cost per parking space, and the amount of time per month the store is open. Your program output should be the expected net profit per month and the expected fraction of potential customers who shop, for k = 1, 2, . . . , n parking spaces, as well as an echo of the input data. Your program chooses an appropriate value of n, which had better depend on the input data. Besides providing numerical output, display your results visually in a way that would be helpful to the store manager. Put yourself in the manager’s shoes as you design your visual displays.
A store pays a monthly fee for each of its parking spaces. Potential customers arrive at the storefront as a Poisson Process with a known rate. If there is an empty parking space when a customer arrives, the customer parks, shops, and drives away. If all parking spaces are occupied, the customer leaves without shopping. Shoppers take an exponentially distributed amount of time with known mean. The average store profit per shopper (not counting the cost of parking spaces) is known. The store manager needs to decide how many parking spaces to pay for. The net profit in a month is the total store profit from shoppers minus the parking space fees.
Submit a copy of your code and the output from some representative sets of runs. For example, one of your sets could vary the cost per parking space while keeping the other data fixed, another could vary the shopping time while keeping the other data fixed, etc. Also, answer the following questions. You should think of at least two valid answers to each question.
Why might the manager decide to get more parking spaces than the number that is optimal in your model? Why would it be advantageous for the store to pool its parking spaces with the store next door?
Explanation / Answer
// Vehicle and its inherited classes.
public enum VehicleSize { Motorcycle, Compact,Large }
Solution: For our purposes right now, we’ll make the following assumptions. We made these specific assumptions to add a bit of complexity to the problem without adding too much. If you made different assumptions, that’s totally fine.
1) The parking lot has multiple levels. Each level has multiple rows of spots.
2) The parking lot can park motorcycles, cars, and buses.
3) The parking lot has motorcycle spots, compact spots, and large spots.
4) A motorcycle can park in any spot.
5) A car can park in either a single compact spot or a single large spot.
6) A bus can park in five large spots that are consecutive and within the same row. It cannot park in small spots.
In the below implementation, we have created an abstract class Vehicle, from which Car, Bus, and Motorcycle inherit. To handle the different parking spot sizes, we have just one class ParkingSpot which has a member variable indicating the size.
Main Logic in Java given below
public abstract class Vehicle
{
protected ArrayList<ParkingSpot> parkingSpots =
new ArrayList<ParkingSpot>();
protected String licensePlate;
protected int spotsNeeded;
protected VehicleSize size;
public int getSpotsNeeded()
{
return spotsNeeded;
}
public VehicleSize getSize()
{
return size;
}
/* Park vehicle in this spot (among others,
potentially) */
public void parkinSpot(ParkingSpot s)
{
parkingSpots.add(s);
}
/* Remove vehicle from spot, and notify spot
that it's gone */
public void clearSpots() { ... }
/* Checks if the spot is big enough for the
vehicle (and is available).
This * compares the SIZE only.It does not
check if it has enough spots. */
public abstract boolean canFitinSpot(ParkingSpot spot);
}
public class Bus extends Vehicle
{
public Bus()
{
spotsNeeded = 5;
size = VehicleSize.Large;
}
/* Checks if the spot is a Large. Doesn't check
num of spots */
public boolean canFitinSpot(ParkingSpot spot)
{... }
}
public class Car extends Vehicle
{
public Car()
{
spotsNeeded = 1;
size = VehicleSize.Compact;
}
/* Checks if the spot is a Compact or a Large. */
public boolean canFitinSpot(ParkingSpot spot)
{ ... }
}
public class Motorcycle extends Vehicle
{
public Motorcycle()
{
spotsNeeded = 1;
size = VehicleSize.Motorcycle;
}
public boolean canFitinSpot(ParkingSpot spot)
{ ... }
}
The ParkingSpot is implemented by having just a variable which represents the size of the spot. We could have implemented this by having classes for LargeSpot, CompactSpot, and MotorcycleSpot which inherit from ParkingSpot, but this is probably overkilled. The spots probably do not have different behaviors, other than their sizes.
public class ParkingSpot
{
private Vehicle vehicle;
private VehicleSize spotSize;
private int row;
private int spotNumber;
private Level level;
public ParkingSpot(Level lvl, int r, int n,
VehicleSize s)
{ ... }
public boolean isAvailable()
{
return vehicle == null;
}
/* Check if the spot is big enough and is available */
public boolean canFitVehicle(Vehicle vehicle) { ... }
/* Park vehicle in this spot. */
public boolean park(Vehicle v) {..}
public int getRow()
{
return row;
}
public int getSpotNumber()
{
return spotNumber;
}
/* Remove vehicle from spot, and notify
level that a new spot is available */
public void removeVehicle() { ... }
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.