top of page
Search

# CS 1181 Project 3: Data Science (Package Delivery Simulation) - Solution

Updated: Aug 16

PURPOSE: This assignment explores simulation of a real-world situation which leads to meaningful actions to solve a problem. A very common use of computers is to run simulations to answer practical questions with no easy closed-form mathematical solution. A simulation is a program designed to model a real system of interest. By setting parameters and selecting an appropriate model, results are produced that model the behavior of the real system. If the model is a valid representation of the real system, then the simulation can even predict the future performance of the real system.

PROBLEM: For this project, you will be simulating a package delivery system involving drones and trucks. A delivery company is interested in decreasing the time it takes them to deliver packages. Currently, the company only uses trucks to deliver packages, but a railroad crossing has been causing costly delays for their trucks. Thus, the company recently purchased a large number of drones capable of delivering packages without the delays of the crossing. Now, the company is looking to optimize their delivery system but is unsure how many packages should be delivered by the new drones. Your goal is to determine what percent of packages should be delivered via drones (vs trucks) to result in the shortest delivery time of all packages.

CONSTANTS: The company has provided you with the following information:

• Each day the company delivers 1,500 total packages.

• The distance to the train crossing is 3,000 units.

• The distance from the train crossing is 27,000 units. (The total distance is 30,000 units.)

• Drones and trucks will follow the exact same path (same distance).

• The daily train schedule (see below for more information)

• Each drone travels at a speed of 500 units/min.

• Each drone has a max load capacity of one package.

• One drone may take off every three minutes.

• Each truck travels at a speed of 30 units/min.

• Each truck has a max load capacity of ten packages.

• One truck may depart every 15 minutes.

• The percent of packages that will be delivered via drone (PERCENT_BY_DRONE)

Train: The train schedule will be provided to you in a text file called “train_schedule.txt”. This file contains a list of start times and durations that the train will be blocking the track in minutes. For example, the first line of the file reads “94 77”. This means that a train begins blocking the crossing at 94 minutes and continues to block the crossing for 77 minutes. To find the time that the train is no longer blocking the crossing, you can add the duration to the start time (i.e. 94 + 77 = 171).

Number of Drones and Trucks: One of the first questions that must be answered is how many drones and how many trucks are needed. You should have a variable called PERCENT_BY_DRONE that indicates what percent of the packages will be delivered via drone. Using this value, you need to determine how many drones and how many trucks are needed. Remember that each drone can carry one package and each truck can carry ten packages. Therefore, if you need to deliver 100 packages, 50% by drone and 50% by truck, then you would need 50 drones (100 * .5 = 50) and five trucks ((100 * .5) / 10 = 5). If the number of packages to be delivered by truck does not divide by ten evenly, you will need to round up as an additional truck will be necessary.

Next, it is important to note that there are two distinct problems that need to be addressed: the total time it takes for all the drones to deliver their packages and the total time it takes for all the trucks to finish delivering their packages. Since the drones do not have any obstacles, simple algebra can be used to determine the total time. However, because the trucks may be interrupted by the train, discrete event simulation must be used to simulate each of the trucks’ journey.

Drones: You need to calculate the time it takes for one drone to complete its trip and the total time it takes for all drones to complete their trip. The first drone should take off at time 0.0. Keep in mind that multiple drones may be flying at the same time, so the total time is not the sum of each drone’s trip time. Again, since the drones do not have any obstacles, event simulation is not necessary to determine the total time it takes for all drones to deliver their packages.

DISCRETE EVENT SIMULATION: To simulate the truck portion of this project, discrete event simulation will be used. This means time is managed by using a simulation clock that is advanced whenever an interesting event occurs. For example, if the simulation time is 0.0 minutes and a truck begins its route at a time 10.0 minutes, we mark the passage of time by advancing the simulation clock to 10.0 minutes (current time = 0.0 + time of truck starting event = 10.0). If a truck reaches the crossing 35.0 minutes later, we advance the simulation clock to 45.0 (10.0 + 35.0). Our assumption is no interesting activities occur between events (i.e. nothing significant happens in the intervals (0.0, 10.0) or (10.0, 35.0) so we can record the passage of time by moving the simulation clock forward to the time when the next important event occurs).

For this project there are several different events of interest. These consist of train events and truck events. Below is a brief description of the significant events a truck may experience. Keep in mind that all the trucks are traveling at the exact same speed on a one-lane road, so under no circumstances may one truck pass another.

- TRUCK_START: The first truck may start at time 0.0. Due to the required offset between truck departures, the second truck will start at 15.0. Since the truck speed and distance to the tracks have been provided to you, a simple calculation can be used to determine when the truck will arrive at the crossing.

- TRUCK _AT_CROSSING: Here two outcomes may occur. First, if there is no train blocking the crossing, the truck may cross immediately and continue its journey. The other possibility is that the truck must wait. There are two possible conditions that cause a truck to wait. If a train is blocking the crossing the truck must wait. Additionally, if there is no train, but there is a line of trucks waiting to cross, then the truck must wait. Therefore, it is possible that a truck may have to wait even if the train is already gone. Each truck must also take one minute to start up from a stop and cross. For example, if a train leaves the crossing at time 35.0, then the first truck waiting will cross at 36.0, followed by the next truck at 37.0, and so on until all the trucks have crossed.

- TRUCK_CROSS: The truck crosses the tracks. Again, since the truck speed and distance from the tracks have been provided to you, simple algebra can be used to determine when the truck will complete its delivery.

- TRUCK_END: Lastly, once the truck has crossed the crossing, the truck can end its journey.

In addition to keeping track of truck events, it will be useful to keep track of the significant train events. These include when a train begins to block the crossing and when it is no longer blocking the crossing.

Event Sorting: To process the events, they should be stored in a data structure that can allow them to be sorted by event time. Additionally, some sorting rules must be implemented in case multiple events occur at the same time. First, a train event should always take priority over a truck event. Second, a truck arriving at the crossing should be handled before a truck that is crossing at the same time. This will ensure that two trucks do not cross at the same time.

Real-Time Tracking: For each significant event, a description should be printed to the console for tracking. Event tracking should be printed in correct time order. Reminder: only the trucks and trains use discrete event simulation, and therefore, only truck and train events need to be tracked. Below is a list of every event type that should be printed to the console:

• Truck beginning its journey

• Truck crossing the crossing

• Truck waiting at the crossing (if necessary)

• Truck completing its delivery

• Train beginning to block the crossing

• Train no longer blocking the crossing.

Each event print statement must include the time that the event is occurring, the type of vehicle (truck or train), the id (if a truck), and a brief description of the event. For example, if the second truck is waiting at the crossing, “76.0: TRUCK #2 waits at crossing” could be printed to the console.

Special Considerations: Via proper implementation of the discrete event simulation and real-time event tracking, your solution should demonstrate that no truck is able to cross the crossing when a train is present. Additionally, it should be clear that your solution properly queues trucks that cannot cross and dequeues them when the train is gone. This includes ensuring that a new truck arriving to the crossing does not cut to the front of a pre-existing line of trucks.

Statistics: After every event has been processed for the truck simulation and the drone calculations have been performed, the following should be printed to the console.

• The number of drones and trucks for the simulation

• The full train schedule

• The total trip time for each truck ID (time from each truck departure to time it reaches the destination)

• The average trip time for all trucks

• The total time for all the trucks to deliver their packages

• The trip time for one drone (the same for every drone)

• The total time for the drones to deliver all their packages

• The total time for all packages to be delivered

Remember that the total times for both the drones and the trucks are not the sum of all drone trip times and truck times respectively. This is because multiple drones and trucks are traveling at the same time.

End Goal: Once your simulation is running properly and your statistics are being calculated correctly, you should run your simulation several times with different values for PERCENT_BY_DRONE. In a comment at the top of your main file, indicate what PERCENT_BY_DRONE you found produces the lowest total time for all packages to be delivered. Please round your value to the nearest percent.

GRADING

(75 pts) Base Functionality

[10] “train_schedule.txt” is correctly read and parsed

[5] The number of drones and trucks is calculated correctly given a certain PERCENT_BY_DRONE

[10] Drone calculations are correct (individual drone trip, total drone trip time)

[5] Data structure holding all events sorts them properly

[10] Real-time tracking information is printed to the console

[10] Truck calculations are correct (total trip time per truck, total and average trip time for all trucks)

[10] Trucks properly queue, do not cross the tracks when a train is present, and dequeue when the train is gone

[10] Truck and drone statistics are printed to the console

[5] Final best value for PERCENT_BY_DRONE is correct

(25 pts) Style

[10] Object-oriented principles such as encapsulation, inheritance, and polymorphism, are used appropriately

[10] The coding is meaningfully commented, and there is not commented out junk code

[5] Standard coding conventions are followed, including variable names and indentation

NOTE: There is no valid excuse for turning in a program which does not compile. A program will receive no credit if it does not compile and execute.

Sample output:

With 25.0% drones and 1500 packages,

There will be:

-375 drones

-113 trucks

TRAIN SCHEDULE

--------------

94-171

213-302

376-412

438-564

627-695

764-828

862-1004

1019-1089

1146-1242

1325-1380

1382-1412

1448-1492

0.0: TRUCK #0 begins journey

15.0: TRUCK #1 begins journey

30.0: TRUCK #2 begins journey

45.0: TRUCK #3 begins journey

60.0: TRUCK #4 begins journey

75.0: TRUCK #5 begins journey

90.0: TRUCK #6 begins journey

94.0: TRAIN arrives at crossing

100.0: TRUCK #0 waits at crossing

105.0: TRUCK #7 begins journey

115.0: TRUCK #1 waits at crossing

120.0: TRUCK #8 begins journey

130.0: TRUCK #2 waits at crossing

135.0: TRUCK #9 begins journey

145.0: TRUCK #3 waits at crossing

150.0: TRUCK #10 begins journey

160.0: TRUCK #4 waits at crossing

165.0: TRUCK #11 begins journey

171.0: TRAIN leaves crossing

172.0: TRUCK #0 crosses crossing

173.0: TRUCK #1 crosses crossing

174.0: TRUCK #2 crosses crossing

175.0: TRUCK #5 waits at crossing

175.0: TRUCK #3 crosses crossing

176.0: TRUCK #4 crosses crossing

177.0: TRUCK #5 crosses crossing

180.0: TRUCK #12 begins journey

190.0: TRUCK #6 crosses crossing

195.0: TRUCK #13 begins journey

205.0: TRUCK #7 crosses crossing

210.0: TRUCK #14 begins journey

213.0: TRAIN arrives at crossing

220.0: TRUCK #8 waits at crossing

225.0: TRUCK #15 begins journey

235.0: TRUCK #9 waits at crossing

240.0: TRUCK #16 begins journey

250.0: TRUCK #10 waits at crossing

255.0: TRUCK #17 begins journey

265.0: TRUCK #11 waits at crossing

270.0: TRUCK #18 begins journey

280.0: TRUCK #12 waits at crossing

285.0: TRUCK #19 begins journey

295.0: TRUCK #13 waits at crossing

300.0: TRUCK #20 begins journey

302.0: TRAIN leaves crossing

303.0: TRUCK #8 crosses crossing

304.0: TRUCK #9 crosses crossing

305.0: TRUCK #10 crosses crossing

306.0: TRUCK #11 crosses crossing

307.0: TRUCK #12 crosses crossing

308.0: TRUCK #13 crosses crossing

310.0: TRUCK #14 crosses crossing

315.0: TRUCK #21 begins journey

325.0: TRUCK #15 crosses crossing

330.0: TRUCK #22 begins journey

340.0: TRUCK #16 crosses crossing

345.0: TRUCK #23 begins journey

355.0: TRUCK #17 crosses crossing

360.0: TRUCK #24 begins journey

370.0: TRUCK #18 crosses crossing

375.0: TRUCK #25 begins journey

376.0: TRAIN arrives at crossing

385.0: TRUCK #19 waits at crossing

390.0: TRUCK #26 begins journey

400.0: TRUCK #20 waits at crossing

405.0: TRUCK #27 begins journey

412.0: TRAIN leaves crossing

413.0: TRUCK #19 crosses crossing

414.0: TRUCK #20 crosses crossing

415.0: TRUCK #21 crosses crossing

420.0: TRUCK #28 begins journey

430.0: TRUCK #22 crosses crossing

435.0: TRUCK #29 begins journey

438.0: TRAIN arrives at crossing

445.0: TRUCK #23 waits at crossing

450.0: TRUCK #30 begins journey

460.0: TRUCK #24 waits at crossing

465.0: TRUCK #31 begins journey

475.0: TRUCK #25 waits at crossing

480.0: TRUCK #32 begins journey

490.0: TRUCK #26 waits at crossing

495.0: TRUCK #33 begins journey

505.0: TRUCK #27 waits at crossing

510.0: TRUCK #34 begins journey

520.0: TRUCK #28 waits at crossing

525.0: TRUCK #35 begins journey

535.0: TRUCK #29 waits at crossing

540.0: TRUCK #36 begins journey

550.0: TRUCK #30 waits at crossing

555.0: TRUCK #37 begins journey

564.0: TRAIN leaves crossing

565.0: TRUCK #31 waits at crossing

565.0: TRUCK #23 crosses crossing

566.0: TRUCK #24 crosses crossing

567.0: TRUCK #25 crosses crossing

568.0: TRUCK #26 crosses crossing

569.0: TRUCK #27 crosses crossing

570.0: TRUCK #38 begins journey

570.0: TRUCK #28 crosses crossing

571.0: TRUCK #29 crosses crossing

572.0: TRUCK #30 crosses crossing

573.0: TRUCK #31 crosses crossing

580.0: TRUCK #32 crosses crossing

585.0: TRUCK #39 begins journey

595.0: TRUCK #33 crosses crossing

600.0: TRUCK #40 begins journey

610.0: TRUCK #34 crosses crossing

615.0: TRUCK #41 begins journey

625.0: TRUCK #35 crosses crossing

627.0: TRAIN arrives at crossing

630.0: TRUCK #42 begins journey

640.0: TRUCK #36 waits at crossing

645.0: TRUCK #43 begins journey

655.0: TRUCK #37 waits at crossing

660.0: TRUCK #44 begins journey

670.0: TRUCK #38 waits at crossing

675.0: TRUCK #45 begins journey

685.0: TRUCK #39 waits at crossing

690.0: TRUCK #46 begins journey

695.0: TRAIN leaves crossing

696.0: TRUCK #36 crosses crossing

697.0: TRUCK #37 crosses crossing

698.0: TRUCK #38 crosses crossing

699.0: TRUCK #39 crosses crossing

700.0: TRUCK #40 crosses crossing

705.0: TRUCK #47 begins journey

715.0: TRUCK #41 crosses crossing

720.0: TRUCK #48 begins journey

730.0: TRUCK #42 crosses crossing

735.0: TRUCK #49 begins journey

745.0: TRUCK #43 crosses crossing

750.0: TRUCK #50 begins journey

760.0: TRUCK #44 crosses crossing

764.0: TRAIN arrives at crossing

765.0: TRUCK #51 begins journey

775.0: TRUCK #45 waits at crossing

780.0: TRUCK #52 begins journey

790.0: TRUCK #46 waits at crossing

795.0: TRUCK #53 begins journey

805.0: TRUCK #47 waits at crossing

810.0: TRUCK #54 begins journey

820.0: TRUCK #48 waits at crossing

825.0: TRUCK #55 begins journey

828.0: TRAIN leaves crossing

829.0: TRUCK #45 crosses crossing

830.0: TRUCK #46 crosses crossing

831.0: TRUCK #47 crosses crossing

832.0: TRUCK #48 crosses crossing

835.0: TRUCK #49 crosses crossing

840.0: TRUCK #56 begins journey

850.0: TRUCK #50 crosses crossing

855.0: TRUCK #57 begins journey

862.0: TRAIN arrives at crossing

865.0: TRUCK #51 waits at crossing

870.0: TRUCK #58 begins journey

880.0: TRUCK #52 waits at crossing

885.0: TRUCK #59 begins journey

895.0: TRUCK #53 waits at crossing

900.0: TRUCK #60 begins journey

910.0: TRUCK #54 waits at crossing

915.0: TRUCK #61 begins journey

925.0: TRUCK #55 waits at crossing

930.0: TRUCK #62 begins journey

940.0: TRUCK #56 waits at crossing

945.0: TRUCK #63 begins journey

955.0: TRUCK #57 waits at crossing

960.0: TRUCK #64 begins journey

970.0: TRUCK #58 waits at crossing

975.0: TRUCK #65 begins journey

985.0: TRUCK #59 waits at crossing

990.0: TRUCK #66 begins journey

1000.0: TRUCK #60 waits at crossing

1004.0: TRAIN leaves crossing

1005.0: TRUCK #67 begins journey

1005.0: TRUCK #51 crosses crossing

1006.0: TRUCK #52 crosses crossing

1007.0: TRUCK #53 crosses crossing

1008.0: TRUCK #54 crosses crossing

1009.0: TRUCK #55 crosses crossing

1010.0: TRUCK #56 crosses crossing

1011.0: TRUCK #57 crosses crossing

1012.0: TRUCK #58 crosses crossing

1013.0: TRUCK #59 crosses crossing

1014.0: TRUCK #60 crosses crossing

1015.0: TRUCK #61 crosses crossing

1019.0: TRAIN arrives at crossing

1020.0: TRUCK #68 begins journey

1030.0: TRUCK #62 waits at crossing

1035.0: TRUCK #69 begins journey

1045.0: TRUCK #63 waits at crossing

1050.0: TRUCK #70 begins journey

1060.0: TRUCK #64 waits at crossing

1065.0: TRUCK #71 begins journey

1072.0: TRUCK #0 completes journey

1073.0: TRUCK #1 completes journey

1074.0: TRUCK #2 completes journey

1075.0: TRUCK #65 waits at crossing

1075.0: TRUCK #3 completes journey

1076.0: TRUCK #4 completes journey

1077.0: TRUCK #5 completes journey

1080.0: TRUCK #72 begins journey

1089.0: TRAIN leaves crossing

......

.....

.....

Need Solution - 100% Plagiarism Free Solution only on Request will be developed: Please contact: +91-995 314 1035

Solution Includes: Plagiarism and AI report with 100% Accuracy.

3 views0 comments
bottom of page