Designing a Ticket Booking System with Priority Queues. Presentation with Slides, including: Objective of the project Data structures utilized Algorithms employed, if any Applications of the project Modules or features incorporated Working principle, along with graphical visualization (using any suitable animated tool) Sample output screenshots Objective of the project: The objective of the project is to develop a flight Tickect optimization system that helps users find the most efficient flight routes between airports, considering factors like distance and layovers. The project aims to provide a user-friendly tool that assists travelers in planning their trips, whether for business or leisure, by identifying the shortest and most convenient routes based on their preferences and constraints. This system should take into account the following objectives: Efficiency: Find the most time-efficient or distance-efficient flight routes, as per the user's preference. Layover Management: Consider the number of layovers or stopovers according to the user's specified limit. User-Friendly Interface: Provide an intuitive and user-friendly interface for users to input their departure and destination airports, preferences, and constraints. Realistic Data: Utilize real airport and flight data to provide accurate and up-to-date information for route planning. Scalability: Handle a potentially large number of airports and flight routes to accommodate global travel needs. Robustness: Ensure the system can handle unexpected issues, such as airport closures or flight cancellations. Optimization Algorithms: Implement efficient routing algorithms to find optimal routes within the specified constraints. Customization: Allow users to specify their preferences, including flight class, airlines, and other factors affecting route selection. Visualization: Provide clear visualization of selected routes, including layovers, distances, and estimated travel times. Integration: Consider integration with external services, such as airline reservation systems, to allow users to book flights directly. Cost Considerations: Optionally, incorporate cost considerations for budget-conscious travelers. Ultimately, the project aims to provide a valuable tool for travelers, travel agencies, and businesses to streamline the flight planning process and make informed decisions about their journeys. It should offer flexibility in route selection while ensuring that all routes presented are practical and efficient within the specified constraints. Data structures utilized: In the flight route optimization project, several data structures are utilized to represent and manage the data efficiently. These data structures play a critical role in the program's functionality and optimization. Here are the key data structures used in the project. Graph: Graphs are a fundamental data structure for representing airport networks and flight routes. The graph consists of nodes (airports) and edges (flight routes) and is typically implemented using adjacency lists or adjacency matrices. It allows for efficient traversal and path-finding algorithms. Priority Queue (Min-Heap): A priority queue is used to efficiently select the next airport to explore during path-finding. Min-heaps ensure that the airport with the shortest distance is always considered first. This data structure is crucial for Dijkstra's algorithm and similar path-finding algorithms. Unordered Map: Unordered maps are used to store airport data efficiently. Each airport is associated with information like its name, geographical coordinates, and other details. Unordered maps provide fast access to this information based on the airport code. Vector or List: Vectors or lists are used to store flight data, which includes details like the source airport, destination airport, and the distance or other relevant information. These data structures allow for easy iteration through the flight data. Structs or Classes: Custom data structures (e.g., structs or classes) can be used to represent flight nodes, which contain information about an airport, its distance, and any other relevant attributes. This can make the code more organized and maintainable. String: String data types are used to store airport codes, airport names, and other textual information. They are essential for matching airports and displaying results to the user. These data structures help manage and process the airport and flight data efficiently, allowing for route optimization and user-friendly presentation of the results. The choice of data structures can impact the program's performance, so it's essential to select the appropriate data structures for the specific requirements of the project. Algorithms employed, if any: For the flight route optimization program described earlier, Dijkstra's algorithm is a suitable choice for finding the shortest path while considering factors like distance and layovers. Below is a summary of how Dijkstra's algorithm can be employed for this program: Data Representation: Use a directed graph to represent the airports as nodes and flight routes as edges. Each edge should be associated with a weight (e.g., distance) that represents the cost of traveling between airports. Initialization: Initialize a priority queue (min-heap) to keep track of airports to explore. Create a data structure to store the distance from the starting airport to all other airports. Initialize the distance to the starting airport as 0 and all other distances as infinity. Main Algorithm: Repeat the following steps until the priority queue is empty: Pop the airport with the shortest distance from the priority queue. For each neighboring airport that can be reached from the current airport, calculate the distance from the starting airport through the current airport to the neighboring airport. If this calculated distance is less than the previously recorded distance for the neighboring airport, update the distance and add the neighboring airport to the priority queue. Backtracking: After running Dijkstra's algorithm to find the shortest path, you can backtrack to retrieve the path from the starting airport to the destination airport. Layover Management: You can introduce a constraint to limit the number of layovers. During path exploration, you can keep track of the number of layovers and only consider paths that meet the layover constraint. User Input: Implement a user-friendly interface to allow users to input their departure and destination airports, preferences (e.g., distance or time efficiency), and constraints (e.g., maximum layovers). Visualization and Display: Provide a clear visualization of the selected route, including details such as the airports, distances, estimated travel times, and layovers. Dijkstra's algorithm is a suitable choice for finding the most efficient routes while considering factors like distance and layovers. It can be implemented in C++ as shown in the C++ code example provided earlier. Additionally, you may want to consider using a data structure like an unordered_map to efficiently store airport data and distances and a priority queue to manage the exploration of airports during the algorithm execution. Applications of the project: A flight route optimization project has a wide range of applications across the travel and aviation industry, benefiting both travelers and businesses. Here are some of the key applications of such a project: Travel Planning for Individuals: Travelers can use the system to find the most efficient flight routes for their vacations, family visits, or business trips. They can select routes that minimize travel time, distance, or layovers based on their preferences. Business Travel Management: Corporations can use the system to optimize travel for their employees, reducing travel costs and time. This is especially useful for companies with frequent business travelers. Travel Agencies and Tour Operators: Travel agencies can offer better itinerary planning services to their clients. They can also create more competitive and attractive travel packages. Airlines and Airports: Airlines can use the optimization system to offer suggested routes to customers or improve their own route planning. Airports can provide real-time information about optimal routes to passengers. Air Cargo and Logistics: Companies involved in air cargo and logistics can use the system to optimize the movement of goods by air, considering factors like time, cost, and cargo volume. Emergency and Medical Evacuations: In emergency situations, such as medical evacuations or natural disasters, the system can help find the fastest routes to transport personnel, equipment, or medical supplies. Military and Government Operations: Military and government organizations can use the system for mission planning and transportation logistics. Academic and Research Use: Researchers in aviation and transportation can use the project to study and analyze flight route optimization algorithms and their real-world applications. Air Traffic Control and Monitoring: Air traffic controllers can benefit from the system to track and optimize the movement of aircraft for efficient use of airspace. Tourism and Regional Development: Local governments and tourism boards can use the project to attract tourists by providing efficient routes to popular destinations. Charter and Private Jet Services: Charter and private jet companies can enhance their services by offering optimal routes to clients for private or business travel. Flight Simulation and Training: Flight training programs and simulators can use the system to replicate real-world scenarios and provide realistic training for pilots and air traffic controllers. Environmental Impact Reduction: By finding shorter and more efficient flight routes, airlines can reduce their carbon footprint and contribute to environmental sustainability. The flight route optimization project offers numerous opportunities for enhancing travel experiences, increasing efficiency in aviation operations, and reducing costs. Its applications extend across various sectors, making it a valuable tool in today's interconnected world. Modules or features incorporated: To create a comprehensive flight route optimization program, various modules or features can be incorporated to provide a well-rounded solution for travelers and the aviation industry. Here are some key modules and features that can be included: User Interface (UI): User-friendly interface for travelers to input their departure and destination airports, preferences, and constraints. Data Management: Module to manage airport and flight data, including real-time updates, ensuring data accuracy and integrity. Route Optimization: Core module implementing algorithms like Dijkstra's algorithm to find the most efficient routes while considering factors like distance, layovers, and other user preferences. Layover Management: Feature to allow users to set layover limits and find routes that meet these constraints. Route Visualization: Module for visually displaying the selected route, including the airports involved, distances, estimated travel times, and layovers. User Preferences: Option to estimate the cost of travel based on flight routes, allowing budget-conscious travelers to make informed decisions. Real-time Data Integration: Integration with external services to provide real-time information, such as flight availability, pricing, and schedule updates. Airport Information: Module to display detailed information about airports, including their facilities, services, and local transportation options. Multi-Stop Routes: Capability to find routes with multiple layovers for travelers who are open to exploring multiple destinations on a single trip. Flight Booking Integration: Integration with airline reservation systems to allow users to book flights directly through the program. Constraints Handling: Robust handling of constraints such as limited airport access or temporary flight disruptions. Historical Data Analysis: Feature to provide insights based on historical flight data, helping travelers choose routes with good ontime performance. Working principle, along with graphical visualization. The working principle of a flight route optimization program involves a series of steps and algorithms to find the most efficient flight routes between airports. Here's a high-level overview of the working principle : Data Collection: The program starts by collecting and maintaining a database of airport information, including their geographical coordinates, services, and facilities. It also gathers data on flight routes, including distances, layovers, and other relevant details. This data can be obtained from reliable sources, such as airlines, airports, and aviation authorities. User Input: Travelers provide input to the program, specifying their departure and destination airports, preferences (e.g., distance or time efficiency), and constraints (e.g., maximum layovers or specific airlines). Route Optimization: The program ensures that the routes generated adhere to the specified constraints. For example, if a traveler wants a maximum of one layover, the program will only consider routes with one or fewer layovers. Visualization: The selected route is visually displayed to the traveler, including the airports involved, distances, estimated travel times, and the number of layovers. This helps travelers make informed decisions. User Interaction: Travelers can review the suggested route, make adjustments to their preferences, and book flights if a booking feature is available. Security and Privacy: Robust security measures are in place to protect user data and privacy, ensuring that sensitive information is kept confidential. The working principle of the flight route optimization program focuses on taking user input, leveraging algorithms to find optimal routes, and providing a user-friendly interface to help travelers plan their trips. It aims to consider user preferences, constraints, and real-time data to generate routes that meet their specific needs and make the travel experience more efficient and enjoyable. Graphical Visualization Programming Code: #include <bits/stdc++.h> #include <string> #include<time.h> using namespace std; typedef tuple<int,int,int> ftuple; typedef pair<int, int> fpair; class Flight { public: string OACode,DACode,OCity,Dcity; int passengers,seats,flightnumer,distance,seats_reserved; }; map<string, int> flightMap; vector< ftuple > flightGraph[500]; bool installed=false; Flight flight[2501]; bool check_key( string key) { // Key is not present if (flightMap.find(key) == flightMap.end()) return false; return true; } bool checkCityExists(string city) { if(check_key(city))return true; return false; } void notInstalledError() { cout<<"Critical Error : Flight Data Not Installed"<<endl; return; } string trimalpha(string s) { for(string::iterator i = s.begin(); i != s.end(); i++) { if(!isalpha(s.at(i - s.begin()))) { s.erase(i); i--; } } return s; } void read_record() { ifstream fp; fp.open("out.csv"); int i=0; string oac,dac,pa,sea,dist,dc,oc; getline(fp,oac,','); getline(fp,dac,','); getline(fp,pa,','); getline(fp,sea,','); getline(fp,dist,','); getline(fp,dc,','); getline(fp,oc,'\n'); int ind=1; while(fp.good()) { getline(fp,oac,','); getline(fp,dac,','); getline(fp,pa,','); getline(fp,sea,','); getline(fp,dist,','); getline(fp,dc,','); getline(fp,oc,'\n'); oc=trimalpha(oc); dc=trimalpha(dc); flight[i].OACode=oac; flight[i].DACode=dac; flight[i].passengers=stoi(pa); flight[i].seats=stoi(sea); flight[i].distance=stoi(dist); flight[i].Dcity=dc; flight[i].OCity=oc; flight[i].flightnumer=i; flight[i].seats_reserved=stoi(pa); if(!check_key(oc)) { flightMap[oc]=ind++; } if(!check_key(dc)) { flightMap[dc]=ind++; } cout<<i<<" Reading Data : "<<endl; cout<<"Origin City Code: "<<oac<<" "; cout<<"Destination City Code: "<<dac<<" "; cout<<"Number of Passengers: "<<pa<<" "; cout<<"Number of seats: "<<sea<<" "; cout<<"Destination City: "<<dc<<" "; cout<<"Origin City: "<<oc<<"\n"; i++; } } vector<int> Dijkstra(int source,int destination) { priority_queue<fpair,vector<fpair>,greater<fpair>> pq; vector<int> dist; vector<bool> vis; int n=flightMap.size(); dist.resize(n+1,1e7); vis.resize(n+1,false); vector<int> parent; vector<int> path; parent.resize(n+5,-1); path.resize(n+5,-1); dist[source]=0; pq.push({0,source}); while(pq.size()>0) { auto[currw,currv]=pq.top(); pq.pop(); if(vis[currv])continue; vis[currv]=true; //if(dist[cv]<cw)continue; for(auto[nextw,nextv,nextfin]:flightGraph[currv]) { if(vis[nextv])continue; int newWeight=currw+nextw; if(newWeight<dist[nextv]) { dist[nextv]=newWeight; parent[nextv]=currv; path[nextv]=nextfin; pq.push({newWeight,nextv}); } } } vector<int> pathTaken; if(dist[destination]==1e7)return pathTaken; for(int i=destination;i!=source;i=parent[i]) { pathTaken.push_back(path[i]); } reverse(pathTaken.begin(), pathTaken.end()); return pathTaken; } void buildGraph() { for(int i=0;i<=2500;i++) { int originIndex=flightMap[flight[i].OCity]; int destinationIndex=flightMap[flight[i].Dcity]; flightGraph[originIndex].push_back(make_tuple(flight[i].distanc e,destinationIndex,flight[i].flightnumer)); //making the graph directed by commenting the code below //flightGraph[destinationIndex].push_back(make_tuple(flight[i] .distance,originIndex,flight[i].flightnumer)); } } int calculateCost(int distance) { int baseFair=50; int totalFair=(distance+1)/2+baseFair; return totalFair; } void install() { if(installed) { cout<<"Flight Data Already Installed"<<endl; return; } installed=true; cout<<"Installing Flight Data...."<<endl; read_record(); cout<<"Read Data Successfully! "<<endl; buildGraph(); } class Booking{ public: string booked_under; int booking_id; int num_seats; int distance; int cost; vector<int> flightsTaken; string password; string bookingTimeAndDate; }; vector<Booking> bookings; string generatepassword() { char alphanum[] = "0123456789!@#$%^&*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL MNOPQRSTUVWXYZ"; int l=sizeof(alphanum)-1; string p=""; for(int i=0;i<8;i++) { p+=(alphanum[rand() % l]); } return p; } void reseveSeats() { if(!installed) { notInstalledError(); return; } string originCity; string destinationCity; cout <<"Enter Origin City: "<<endl; cin>>originCity; for (auto & c: originCity) c = toupper(c); if(!checkCityExists(originCity)) { cout<<"Entered City doesn't exist!!"<<endl; cout << "Enter 1 to retry booking or any other key to Exit"; int cho; cin>>cho; if(cho==1)reseveSeats(); else { return; } } cout <<"Enter Destination City: "<<endl; cin>>destinationCity; for (auto & c: destinationCity) c = toupper(c); if(!checkCityExists(destinationCity)) { cout<<"Entered Destination City doesn't exist!!"<<endl; cout << "Enter 1 to retry booking or any other key to Exit"; int cho; cin>>cho; if(cho==1)reseveSeats(); else { return; } } vector<int> path; path= Dijkstra(flightMap[originCity],flightMap[destinationCity]); if(path.size()==0) { cout<<"Sorry there is no flight connecting "<<originCity<<" and "<<destinationCity<<endl; cout << "Enter 1 to retry booking seats or any other key to Exit"; int cho; cin>>cho; if(cho==1)reseveSeats(); else { return; } } cout<<"You will have to take "<<path.size()<<" flight(s) to reach your destination : "<<endl; int totalDistance=0; for(int i : path) { cout<<"From "<<flight[i].OCity<<" to "<<flight[i].Dcity<<endl; totalDistance+=flight[i].distance; cout<<"then "<<endl; } cout<<"You will reach your destination"<<endl; int costFlight=calculateCost(totalDistance); cout<<"The total sum you will have to pay is "<<costFlight<<" $ "<<endl; cout<<"You will have travelled "<<totalDistance<<" miles"<<endl; cout<<"Enter number of Required Seats\n"; int reqseats; cin>>reqseats; int counter=0; for(int i: path) { if(reqseats>flight[i].seats-flight[i].seats_reserved) { cout<<" Sorry The Flight "<<flight[i].OCity<<" to "<<flight[i].Dcity<<" has Only "<<(flight[i].seatsflight[i].seats_reserved)<<" seats available"<<endl; counter=1; } } if (counter==1) { cout << "Enter 1 to retry or any other key to Exit"; int cho; cin>>cho; if(cho==1)reseveSeats(); else { return; } } for(int i : path) { flight[i].seats_reserved+=reqseats; } Booking book; cout<<"Enter Booking Name: "; string nam; for(int i : path) { flight[i].seats_reserved+=reqseats; book.flightsTaken.push_back(i); } cin>>nam; book.booked_under=nam; int b_id=bookings.size(); book.booking_id=b_id; book.num_seats=reqseats; book.distance= totalDistance; string pword=generatepassword(); book.cost=costFlight; book.password=pword; time_t my_time = time(NULL); string time=ctime(&my_time); cout<<"Resrvation time:"<<time; book.bookingTimeAndDate=time; bookings.push_back(book); cout<<"Booking Successfull!!"<<endl; cout<<"Your booking id is: "<<b_id<<endl; cout<<"Your password is: "<<pword<<endl; cout<<"Please remember these for future reference"<<endl; } int authenticate() { int option=0; cout<<"Enter your booking id : "; int bookid; cin>>bookid; cout<<"Enter your password : "; string passwd; cin>>passwd; if (bookid>=(int)bookings.size()) { option=1; cout<<"Your Booking ID is incorrect!!"<<endl; return -1; } if(passwd!=bookings[bookid].password) { option=1; cout<<"Your Password is incorrect!!"<<endl; } else { cout<<"Succesfully Logged in!!!!"<<endl; } if(option==1) { return -1; } else { return bookid; } } void cancellation() { int authKey=authenticate(); if(authKey!=-1) { cout<<"Press 1 to confirm your cancellation "; int choiced; cin>>choiced; if (choiced==1) { cout<<"Your ticket has been cancelled and your money "<<bookings[authKey].cost-100 <<" has been added to your account after deducting cancellation amount"<<endl; for(int i : bookings[authKey].flightsTaken) { flight[i].seats_reserved=bookings[authKey].num_seats; } } } else { cout<<"Failed authentication!"<<endl; } } void showBooking() { if(!installed) { notInstalledError(); return; } int authKey=authenticate(); if(authKey!=-1) { cout<<"Your Booking Id is:"; cout<<authKey<<endl; cout<<"Your journey is booked under the name: "<<bookings[authKey].booked_under<<endl; cout<<"The number of seats you have reserved are: "<<bookings[authKey].num_seats<<endl; cout<<"The number of flights you will be taking is "<<bookings[authKey].flightsTaken.size()<<" namely:"<<endl; for(int i : bookings[authKey].flightsTaken) { cout<<"From "<<flight[i].OCity<<" to "<<flight[i].Dcity<<endl; cout<<"then "<<endl; } cout<<"You will reach your destination"<<endl; cout<<"Your Journey will be of "<<bookings[authKey].distance<<" miles"<<endl; cout<<"The total money you have paid is "<<bookings[authKey].cost<<" USD"<<endl; cout<<"Your booking was made on "<<bookings[authKey].bookingTimeAndDate<<endl; } } void seeConnectivity() { if(!installed) { notInstalledError(); return; } string originCity; string destinationCity; cout <<"Enter Origin City: "<<endl; cin>>originCity; for (auto & c: originCity) c = toupper(c); cout <<"Enter Destination City: "<<endl; cin>>destinationCity; for (auto & c: destinationCity) c = toupper(c); vector<int> path; path= Dijkstra(flightMap[originCity],flightMap[destinationCity]); if(path.size()==0) { cout<<"Entered Cities arent connected by any flights"; return; } cout<<"The entered cities are conneccted with flights:"<<endl; int d=0; int min_=INT_MAX; for(int i : path) { cout<<"From "<<flight[i].OCity<<" to "<<flight[i].Dcity<<endl; d+=flight[i].distance; min_=min(min_,(flight[i].seats-flight[i].seats_reserved)); } cout<<"number of seats available: "<<min_<<endl; cout<<"The ditance thus is "<<d<<" miles"<<endl; } int main() { system("clear"); int w; srand(time(0)); while (1) { cout<<"\n"; time_t my_time = time(NULL); printf("%s", ctime(&my_time)); //system("cls"); cout << "\n\n\n\n\n"; cout << "\t\t\t1.Install\n\t\t\t" << "2.Reservation\n\t\t\t" << "3.Show Booking\n\t\t\t" << "4.Cancellation. \n\t\t\t" << "5.See Connectivity between two cities \n\t\t\t" << "6.Exit"; cout << "\n\t\t\tEnter your choice:-> "; cin >> w; switch (w) { case 1: install(); break; case 2: reseveSeats(); break; case 3: showBooking(); break; case 4: cancellation(); break; case 5: seeConnectivity(); break; case 6: exit(0); } } return 0; } Sample output screenshots XXXXXXXXXX---------------------XXXXXXXXXX