Train ticket query method

By using unsigned integers to represent seat information in the ticketing system, the problem of high-speed railway ticketing system being under great pressure during peak periods is solved, and rapid query and maintenance are achieved, improving user experience.

CN119127930APending Publication Date: 2024-12-13程会艳
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410740178.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

High-speed railway ticketing systems are susceptible to pressure during peak periods, which may lead to system downtime, and existing technologies are difficult to effectively handle huge ticketing data and fast query requirements.

Method used

By storing date, train number, car number and seat number in a dictionary, and using unsigned integers to represent seat information, representing ticket status from low to high, use simple assignment and operations to query and update ticket information.

Benefits of technology

It reduces the memory and computing complexity of the ticketing system, improves the speed of ticket purchases, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127930A_ABST
    Figure CN119127930A_ABST
Patent Text Reader

Abstract

The invention discloses a method for querying train tickets, which comprises the following steps of: S1, respectively storing dates, train numbers, compartment numbers and seat numbers in corresponding dictionaries, and nesting the dictionaries according to hierarchies; s2, a plurality of unsigned integers are set in the seat number dictionary, each unsigned integer represents one seat, and each unsigned integer represents ticket information of the seat from a starting station to a terminal station in sequence from a low position to a high position; and S3, querying whether there is a ticket between the mth station and the nth station of a certain seat, wherein the specific method is as follows: judging whether an unsigned integer where the seat is located is 0; and S4, after a ticket from the mth station to the nth station of the seat is sold, the ticket business information of the seat is updated. Ticket retrieval can be completed through simple assignment and operation, the internal memory and calculation complexity of a ticketing system are greatly reduced, maintenance of the ticketing system is facilitated, the ticket buying speed is increased, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of train ticketing, and in particular to a method for querying train tickets. Background Art

[0002] In recent years, high-speed railways have developed rapidly. As the public's demand for travel has become increasingly strong, the pressure on the ticketing system has also increased. Especially during the Spring Festival or holidays, based on the relatively complex backend computing system, the huge amount of ticketing data can easily cause an impact on the server, and may even cause the ticketing system to crash. Therefore, the existing technology needs to be improved. Summary of the invention

[0003] In view of the problems existing in the prior art, the present invention provides a method for querying train tickets.

[0004] To achieve the above object, the specific scheme of the present invention is as follows:

[0005] A method for querying train tickets, characterized in that it comprises the following steps:

[0006] S1: Store the date, train number, carriage number, and seat number in the corresponding dictionaries respectively, and nest the dictionaries in a hierarchical manner;

[0007] S2: Set a number of unsigned integers in the seat number dictionary, each of which represents a seat, and each of which represents the ticket information of the seat from the departure station to the destination station from the low digit to the high digit, 0 means unsold, and 1 means sold;

[0008] S3: Check whether there are any tickets for a certain seat between the mth station and the nth station. The specific method is: determine whether the unsigned integer where the seat is located is 0. If the unsigned integer where the seat is located is 0, then there are tickets for the seat between the mth station and the nth station, otherwise there are no tickets, wherein m and n are both natural numbers, and n>m>=0;

[0009] S4: After the ticket for the seat between the mth station and the nth station is sold, the ticket information of the seat is updated.

[0010] Preferably, in step S1, the seat number dictionary is placed in the innermost layer.

[0011] Preferably, in step S2, the number of bits of the unsigned integer is not less than the number of stations. When the number of bits of the unsigned integer is greater than the number of stations, the value of the bits higher than the number of stations is 0.

[0012] Preferably, in step S3, the method for determining whether the unsigned integer where the seat is located is 0 comprises the following steps:

[0013] S301: Set an unsigned integer p;

[0014] S302: Set the mth to n-1th bits of p to 1, and set the other bits to 0;

[0015] S303: performing an AND operation on p and the unsigned integer where the seat is located, and obtaining an unsigned integer v;

[0016] S304: Determine whether v is 0.

[0017] Preferably, in step S302, the method of setting the mth to n-1th bits of p to 1 and the other bits to 0 comprises the following steps:

[0018] S3021: P = 2^(n-m+1)-2;

[0019] S3022: Convert P to an unsigned integer in binary representation;

[0020] S3023: When m=0, P is shifted right by 1 bit to obtain p; when m>0, P is shifted left by m-1 bits to obtain p.

[0021] Preferably, in step S4, the method for updating the seat information is: performing an OR operation on p and an unsigned integer where the seat is located to obtain an unsigned integer w, where w is the updated information of the seat.

[0022] The technical solution of the present invention has the following beneficial effects:

[0023] The present invention can complete ticket retrieval through simple assignment and calculation, greatly reducing the memory and calculation complexity of the ticketing system, which is beneficial to the maintenance of the ticketing system, increasing the ticket purchase speed and improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is the overall flow chart of the present invention;

[0025] Figure 2 is a flow chart of step S1 of the present invention;

[0026] Figure 3 This is a flow chart of step S302 of the present invention. DETAILED DESCRIPTION

[0027] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments.

[0028] Reference Figure 1 The present invention provides a method for querying train tickets, comprising the following steps:

[0029] S1: Store the date, train number, car number, and seat number in the corresponding dictionaries respectively, and nest the above dictionaries in a hierarchical manner.

[0030] In this step, the seat number dictionary is placed in the innermost layer, and there is no special requirement for the order of other dictionaries. This embodiment will be described in the order of date-train number-car number-seat number.

[0031] S2: A plurality of unsigned integers are set in the seat number dictionary, each of which represents a seat, and each of which represents the ticket information of the seat from the departure station to the destination station in order from the low digit to the high digit.

[0032] In this step, the number of digits of the unsigned integer is not less than the number of stations. When the number of digits of the unsigned integer is greater than the number of stations, the value of the digits above the number of stations is 0. For example, a train named K00 is sent from the departure station (station 0) to the terminal station (station 6), with a total of 7 stations, and has 2 carriages, each with 4 seats, then the train dictionary is:

[0033] Dic[“K00”]={“1”:{“01”:0b00000000, “02”:0b00000000, “03”:0b00000000, “04”:0b00000000}, “2”:{“01”:0b00000000, “02”:0b00000000, “03”:0b00000000, “04”:0b00000000}}, where “K00” is the value of the Dic[“K00”]. "00" is the train number, "1" and "2" are the two carriages of the train, "01" "02" "03" and "04" are the four seat numbers in each carriage, "0b00000000" represents the ticket status of the seat, and "0b" is a binary representation, and "00000000" represents the ticket status of the seat from the 0th to the 6th station from low to high. 0 means unsold, and 1 means sold. Since the highest digit has no corresponding station, it is represented by 0.

[0034] S3: Check whether there are any tickets for a certain seat between the mth station and the nth station. The specific method is: determine whether the unsigned integer where the seat is located is 0. If the unsigned integer where the seat is located is 0, then the seat has no tickets between the mth station and the nth station, otherwise, there are no tickets, where m and n are both natural numbers, and n>m>=0;

[0035] In this step, the method for determining whether the unsigned integer where the seat is located is 0 is as follows: First, set an unsigned integer p; then set the m-th to the (n - 1)-th bits of p to 1 and the other bits to 0. The specific method is: P = 2^(n - m + 1) - 2. When m = 0, p = P >> 1 (shift right by one bit), and when m > 0, p = P << (m - 1) (shift left by m - 1 bits); then perform an AND operation on p and the unsigned integer 0b00000000 where the seat is located to obtain an unsigned integer v; finally, determine whether v is 0. If it is 0, it means there is a ticket, otherwise there is no ticket.

[0036] Example 1, when the information of seat No. 03 in the first carriage of the train is: 0b00010110, it means the tickets for this seat at the 0th, 1st, 2nd, and 4th stops have been sold, while the tickets at the 3rd, 5th, and 6th stops have not been sold. When the user queries whether there are still tickets from the 2nd stop to the 5th stop, the calculation method is as follows:

[0037] P = 2^(n - m + 1) - 2 = 14, which is represented in binary as P = 00001110. At this time, m > 0, p = P << (m - 1), that is, p = 00011100, v = p & 0b00010110 = 00010100. Since v is not 0, it means that there is no ticket for seat No. 03 in the first carriage of the train from the 2nd stop to the 5th stop;

[0038] Example 2, when the information of seat No. 04 in the second carriage of the train is: 0b01100010, it means the tickets for this seat at the 1st, 5th, and 6th stops have been sold, while the tickets at the 0th, 2nd, 3rd, and 4th stops have not been sold. When the user queries whether there are still tickets from the 0th stop to the 2nd stop, the calculation method is as follows:

[0039] P = 2^(n - m + 1) - 2 = 6, which is represented in binary as P = 00000110. At this time, m = 0, p = P >> 1, that is, p = 00000011, v = p & 0b01100010 = 00000110. Since v is not 0, it means that there is no ticket for seat No. 04 in the second carriage of the train from the 0th stop to the 2nd stop.

[0040] S4: After the tickets between the m-th and n-th stops of this seat are sold, update the ticket information of this seat. The specific method is: perform an OR operation on p and the unsigned integer where the seat is located to obtain an unsigned integer w, and w is the updated information of this seat.

[0041] The invention can quickly complete ticket retrieval through simple calculations, greatly reducing the memory and computational complexity of the ticketing system, which is conducive to maintaining the ticketing system, improving the ticket purchase speed, and improving the user experience. Take a train with 20 carriages, 200 seats in each carriage, and 32 stops as an example. Each seat is 4 bytes, that is, 32 bits, corresponding to 32 stations. A train has a total of 4*200*20=16000 bytes, about 15kb. Assuming there are 10,000 trains in the country, the daily data is 150,000kb, that is, about 150M. Assuming that the tickets are sold in advance for one month, it is 150*30=450M, about 4.5G of data.

[0042] The above description is only a preferred embodiment of the present invention, and does not limit the patent scope of the present invention. All equivalent structural changes made by using the contents of the present invention specification and drawings under the inventive concept of the present invention, or directly / indirectly applied in other related technical fields are included in the protection scope of the present invention.

Claims

1. A method for querying train tickets, characterized in that: The following steps are involved: S1: Store the date, train number, carriage number, and seat number in the corresponding dictionaries respectively, and nest the dictionaries in a hierarchical manner; S2: Set a number of unsigned integers in the seat number dictionary, each of which represents a seat, and each of which represents the ticket information of the seat from the departure station to the destination station from the low digit to the high digit, 0 means unsold, and 1 means sold; S3: Check whether there are any tickets for a certain seat between the mth station and the nth station. The specific method is: determine whether the unsigned integer where the seat is located is 0. If the unsigned integer where the seat is located is 0, then there are tickets for the seat between the mth station and the nth station, otherwise there are no tickets, wherein m and n are both natural numbers, and n>m>=0; S4: After the ticket for the seat between the mth station and the nth station is sold, the ticket information of the seat is updated.

2. The train ticket query method according to claim 1, characterized in that: In step S1, the seat number dictionary is placed in the innermost layer.

3. The train ticket query method according to claim 1, characterized in that: In step S2, the number of bits of the unsigned integer is not less than the number of stations. When the number of bits of the unsigned integer is greater than the number of stations, the value of the bits higher than the number of stations is 0.

4. The train ticket query method according to claim 1, characterized in that: In step S3, the method for determining whether the unsigned integer of the seat is 0 comprises the following steps: S301: Set an unsigned integer p; S302: Set the mth to n-1th bits of p to 1, and set the other bits to 0; S303: performing an AND operation on p and the unsigned integer where the seat is located, and obtaining an unsigned integer v; S304: Determine whether v is 0.

5. The train ticket query method according to claim 4, characterized in that: In step S302, the method of setting the mth to n-1th bits of p to 1 and the other bits to 0 includes the following steps: S3021: P = 2^(n-m+1)-2; S3022: Convert P to an unsigned integer in binary representation; S3023: When m=0, P is shifted right by 1 bit to obtain p; when m>0, P is shifted left by m-1 bits to obtain p.

6. The train ticket query method according to claim 4, characterized in that: In step S4, the method for updating the seat information is: perform an OR operation on p and the unsigned integer where the seat is located to obtain an unsigned integer w, where w is the updated information of the seat.