A subway ticket record storage and indexing method based on distributed secondary index

Through distributed secondary index technology, subway ticket card data is partitioned and partially indexed, and spatio-temporal attributes are used to organize data, which solves the problem of low storage and query efficiency of NoSQL databases, realizes trajectory similarity search and data scalability, and meets the needs of Massive data storage requirements.

CN118626497BActive Publication Date: 2024-10-11YUNNAN NORMAL UNIV
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411111262.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-14
Publication Date
2024-10-11
Estimated Expiration
2044-08-14

AI Technical Summary

Technical Problem

Existing NoSQL databases fail to make full use of spatiotemporal characteristics when storing and indexing subway ticket card data, resulting in low query efficiency and inability to effectively support trajectory similarity searches. Moreover, the single-node storage scale is limited and cannot meet long-term data storage needs. .

Method used

A storage and indexing method based on distributed secondary indexes is used to partition the track ticket records through global indexes, and build local indexes in each partition, using spatiotemporal attributes to organize data and support trajectory similarity searches. Specific steps include collecting ticket records, forming passenger trajectories, dividing them into OD sequences, building global indexes and local indexes, calculating data distribution characteristics, finding optimal search solutions, performing parallel searches and merging data, and finally filtering and returning results.

Benefits of technology

It achieves efficient storage of massive ticket card data and trajectory similarity search, has good scalability, can manage large-scale subway passenger ticket card records, and improves indexing efficiency and data processing capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626497B_ABST
    Figure CN118626497B_ABST
Patent Text Reader

Abstract

The present invention relates to a subway ticket record storage and indexing method based on distributed secondary indexing, and the technical field of data storage and indexing. The present invention partitions the track ticket record through a global index, then maps each partition to a different storage node, and then organizes the ticket record in the partition by spatiotemporal attributes through a local index, and stores a large amount of ticket records in this distributed secondary index to complete storage and indexing. The present invention can process ultra-large-scale subway ticket data sets and support track similarity search.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a subway ticket record storage and indexing method based on distributed secondary indexing, and belongs to the technical field of data storage and indexing. Background Art

[0002] Modern urban rail transit systems have become an important part of urban public transportation systems. Rail transit systems usually provide fast and punctual services, which can effectively alleviate urban traffic congestion. Compared with other modes of transportation, such as cars or buses, rail transit systems can usually carry a large number of passengers faster during peak hours. The rail transit system operates at high speed every day, serving a large number of urban residents, and generates millions of ticket data every day. These ticket data not only contain the travel trajectories of individual passengers, but also contain the travel patterns of urban residents. Operators have tried to store these billions of ticket records and try to develop some data-driven smart applications to better support the operation of the subway. In terms of shuttle bus settings, the mining of passenger trajectory patterns determines the starting and ending points of shuttle buses. In terms of smart policing, based on the suspect's ticket, his accomplices are located through trajectory similarity calculation.

[0003] Taking a first-tier city as an example, there are currently 12 lines with a total of 400 stations, and the number of active bus cards is more than 10 million. It serves an average of 5 million passengers every day, and each passenger generates an average of 4 card-swiping records every day. Each card-swiping record contains multiple fields such as card number, timestamp, station name, entry and exit mark, and fare. The entire subway system generates 20 million card-swiping records every day, with a total of 600 million card-swiping records per month and 3.6 billion card-swiping records every six months. Practitioners have explored how to store massive amounts of ticket data. In the era when the road network was small, the data scale was also small, and common database technologies including relational databases (such as MySQL, PostgreSQL, and Oracle) were used to store ticket data. Now, with the continuous increase in ticket data, NoSQL databases (such as HBase, MongoDB, Cassandra, and TiDB) are beginning to be used for storage.

[0004] Although these NOSQL databases can also meet the storage needs of massive ticket data and establish some indexes such as card number and timestamp to speed up queries, there are still two shortcomings:

[0005] (1) Efficiency. The ticket data is stored in a NOSQL database, and the temporal and spatial characteristics of the ticket data are not considered when designing the index, which makes it inefficient in supporting various queries.

[0006] (2) Functionality: The ticket data is stored in a NOSQL database, which does not support similarity search and query of trajectories.

[0007] The patent "CN115344795 B, a method for searching similarity of subway track passengers based on multi-way merging" has made a preliminary exploration of the storage and indexing of ticket data. This method takes into account the spatiotemporal characteristics of ticket records, designs a stand-alone storage and indexing system, and designs a trajectory similarity search algorithm for a single machine. Although certain results have been achieved, the data storage scale of a single node is limited. It can only store data for 1 month, which cannot meet long-term storage requirements (for example, more than 4 months). As the ticket data generated by the subway system continues to increase, there is an urgent need for a new solution that not only takes into account spatiotemporal characteristics but also has good scalability. Summary of the invention

[0008] The present invention aims to solve the problem of efficient storage and indexing of massive subway passenger ticket data, so as to support similarity search of trajectories and some data-driven intelligent applications in rail transit scenarios.

[0009] The present invention analyzes the characteristics of passenger ticket records in rail transit scenarios. Specifically, passenger ticket records have two unique characteristics:

[0010] 1. Trajectory attributes;

[0011] All the ticket records of passengers in the subway system over a period of time (for example, one month) are arranged in chronological order to form the passenger's trajectory. The trajectory contains the passenger's travel time and space rules, such as where they live, where they work; whether they are commuting, going to school, relaxing or shopping; and what time period they usually travel.

[0012] 2. Special space-time attributes;

[0013] (1) Highly sparse in time and highly deterministic in space. A subway passenger’s trip may take tens of minutes, but only generates two points: the starting point and the end point. The corresponding ground vehicle GPS trajectory may generate hundreds of points. Although millions of ticket records are generated every day, the locations where the tickets are generated are all in subway stations.

[0014] (2) Travel mode. Travel mode has three meanings. First, a passenger's trip must have an entry and an exit. For example, if a passenger enters from station O and exits from station D, OD can be understood as a set of OD (original destination). Second, a passenger's trip may be round trip. For example, in the morning, a passenger starts at station A and gets off at station B; in the evening, a passenger gets off from station B and gets off at station A. Therefore, the ABBA travel mode accounts for the largest proportion of passenger trajectories.

[0015] The technical solution of the present invention is: Based on the above analysis, the present invention provides a subway ticket record storage and indexing method based on distributed secondary index, which partitions the track ticket record through the global index, and then maps each partition to a different storage node. Then, the ticket record in the partition is organized by the time and space attributes through the local index. In this way, a large number of ticket records are efficiently stored in this distributed secondary index. In addition, this distributed secondary index can well support track similarity search.

[0016] The method specifically comprises:

[0017] Step 1: Collect all smart card tapping records generated by all rail transit ticket collection systems;

[0018] The smart card tapping record refers to the ticket record generated by passengers tapping their cards at the subway station gate;

[0019] Step 2: Group all ticket records by card number, sort the ticket records in each group by time to form passenger trajectories, and save the passenger trajectories in the form of OD sequence;

[0020] The OD refers to treating the information contained in the OD of a passenger's trip in a subway station as a tuple, including the following information: "starting station, entry time, entry", "terminal station, exit time, exit";

[0021] Step 3: Divide all passenger trajectories into OD granularity, build a global index in the distributed secondary index, traverse each trajectory, obtain the OD in the trajectory, and the OD in all trajectories constitute an OD set;

[0022] Divide the OD set into multiple partitions, each partition contains an OD subset, and each partition is mapped to a unique storage node;

[0023] Among them, the mapping from OD to partition number and the mapping from partition number to storage node constitute the global index;

[0024] The global index is stored in the control node. In the global index, partition positioning is performed in units of OD;

[0025] The hash signature is a function that takes OD as input and outputs an integer number. The maximum value of the integer number corresponds to the number of storage nodes in the cluster.

[0026] Step 4: Build a local index for the OD subset in the partition on each storage node, split each OD into two points, O and D, to form a point set;

[0027] The point set is divided into finer granularity levels according to the subway station name, card tapping time, and entry and exit marks in the point, as follows:

[0028] First, the point set is divided according to the site name to form a site name subset;

[0029] Secondly, the site name subset is divided into time interval subsets to form time period subsets;

[0030] Finally, the time period subsets are divided into two groups according to direction, namely the inbound group and the outbound group;

[0031] Step 5: Given the target trajectory saved in the form of OD sequence, calculate the data distribution characteristics of the target trajectory in the cluster;

[0032] According to the data distribution characteristics, local computing costs, network transmission costs and distributed synchronization costs, find the optimal search solution with the shortest time consumption among all search solutions;

[0033] Step 6: Specify the query trajectory, similarity measurement function, similarity threshold and filtering strategy, and call the query interface;

[0034] Step 7: Calculate the distribution characteristics of the passenger trajectory in the cluster based on the query trajectory, and calculate the optimal search solution based on the distribution characteristics;

[0035] The optimal search solution refers to the search solution that consumes the least time among all search solutions;

[0036] Step 8: Execute the optimal search solution in a distributed environment, specifically:

[0037] To perform the first round of search, a set of tasks executed in parallel in a distributed environment extract data from the local local index and merge them into OD, and then transmit the data to the corresponding nodes through the network;

[0038] To perform the second round of search, a set of tasks that are executed in parallel in a distributed environment are executed simultaneously, and each task has the same processing logic;

[0039] Each task first obtains the data sent to the local node by other nodes, merges it with the local data, forms a candidate trajectory segment, and transmits the candidate trajectory segment to the corresponding node through the network;

[0040] The subsequent rounds of searches were all the same as the second round of searches;

[0041] After the last round, a set of candidate trajectories is formed;

[0042] The candidate trajectory set refers to each trajectory in the set that may satisfy the similarity query condition;

[0043] Step 9: Execute the filtering strategy on the candidate trajectory set. The trajectories that do not meet the filtering conditions are deleted, and the trajectories that meet the filtering conditions are retained to form the result trajectory set;

[0044] Step 10: Return the result trajectory set in Step 9.

[0045] Furthermore, the global index of the distributed secondary index is constructed in Step 3, and the specific process is as follows:

[0046] Step 3.1: Given a trajectory set TRSet, a given number of partitions p, and a given number of nodes m, the trajectory set is in the following form:

[0047] TRSet={TR1,TR2,TR3,…,TRn}(5)

[0048] In formula (5), TR is the specific trajectory, and n represents the number of trajectories in the set;

[0049] Initialize the key-value structure ODMap(index,ODSet) for the result of OD set partitioning;

[0050] Initialize the key-value structure GIndexMap(OD,(index,node)) to save the global index;

[0051] Step 3.2: Initialize variable i to 1, traverse each trajectory in the trajectory set; determine the size relationship between i and TRSet.len;

[0052] If i is less than or equal to TRSet.len, select the current track currTR, currTR=TRSet(i);

[0053] Otherwise, execute Step 3.8;

[0054] Step 3.3: Initialize the variable j to 1, traverse each OD in currTR, and determine the size relationship between j and currTR.len;

[0055] If j is less than or equal to currTR.len, select the current currOD=currTR(j);

[0056] Otherwise, execute Step 3.2;

[0057] Step 3.4: Calculate the partition number corresponding to OD, as shown in the following formula:

[0058] index=(hash(OD) mod p)+1(6)

[0059] In formula (6), hash(OD) represents the hash signature of OD, p is the number of partitions, and the value of index is between 1 and p;

[0060] Step 3.5: Save OD into a key-value pair data structure. The specific format is as follows:

[0061] ODMap = {(index1,ODSet1),(index2,ODSet2)...,(index p ,ODSet p )}(7)

[0062] In formula (7), ODMap is a key-value storage structure, index represents the partition number, ODSet represents the set of ODs, and in the same key-value structure (index, ODSet), each OD in the ODSet set has the same partition number index;

[0063] Step 3.6: The value of variable j increases by 1, j=j+1, pointing to the next OD of the current trajectory, and go to Step 3.3;

[0064] Step 3.7: The value of variable i increases by 1, i=i+1, pointing to the next trajectory of the current trajectory set, and go to Step 3.2;

[0065] Step 3.8: Initialize the variable k to 1, traverse ODMap, and compare the relationship between k and ODMap.len;

[0066] If k is less than ODMap.len, get the current index and ODSet through function call, (index, ODSet) = ODMap(k);

[0067] Otherwise, go to Step 3.11;

[0068] Step 3.9: Calculate the storage node number corresponding to the partition number, node = (index mod m) + 1, the node number value range is [1 ~ m];

[0069] Traverse each element OD in ODSet, and insert the partition and storage node corresponding to the OD into the global index, GIndexMap.insert(OD,(index,node));

[0070] Step 3.10: k=k+1, pointing to the next element in ODMap, go to Step 3.8;

[0071] Step3.11: Return the global index GIndexMap and OD partition ODMap.

[0072] Furthermore, the local index described in Step 4 is to build the local index in parallel on each storage node at the same time. The specific process is as follows:

[0073] Step 4.1: Input OD set ODSet, subway station name set StationSet and time interval t;

[0074] Step 4.2: Traverse each OD in ODSet and split each OD into two points, O and D. After the traversal is completed, all points form a point set PointSet;

[0075] Step 4.3: Traverse each point in the point set PointSet, divide the points with the same site name into the same group, and save the divided point set in the following data structure:

[0076] StationMap={(ID1,station1,Set1),( ID2,station2,Set2),…, ( ID N ,station N ,Set N )}(8)

[0077] In formula (8), StationMap is the storage method after the point set is divided, IDi represents the number of the subway station, stationi represents the name of the subway station, and Seti represents the set of all ticket records generated by the subway station;

[0078] Step 4.4: Initialize the variable i to 1, traverse each member in StationMap, and compare the size relationship between i and StationMap.len;

[0079] If i is less than StationMap.len, select the current station and its corresponding point set currStation, currStation=StationMap (i);

[0080] Otherwise, go to Step 4.11;

[0081] Step 4.5: Get the point set Set corresponding to the current station currStation, and further divide the points in Set into segments according to the time interval t. The point set Set and the space-time points after segmentation are stored in a data structure as shown in formula (9):

[0082] timeLMap = {(I1,tSeg1,n1,sSet1), (I2,tSeg2,n2,sSet2),…, (IM ,tSeg M ,n M ,sSet M )}(9)

[0083] In formula (9), I represents the time period number, tSeg represents the time period name, n represents the number of ticket records generated within the time period, and sSet represents the set of all ticket records generated within the time period, which is a subset of Set.

[0084] Step 4.6: Initialize the variable j to 1, traverse each member in timeLMap, and determine the size relationship between j and timeLMap.len;

[0085] If j is less than or equal to timeLMap.len, select the current time segment currSeg, currSeg=timeLMap(j);

[0086] Otherwise, go to Step 4.11;

[0087] Step 4.7: Further divide the sSet in the current currSeg into OSet and DSet, where OSet represents the entry set and DSet represents the battle set;

[0088] Step 4.8: Sort the points in OSet and DSet by time respectively;

[0089] Step 4.9: The value of variable j increases by 1, j=j+1, pointing to the next member of the current currSeg, and go to Step 4.6;

[0090] Step 4.10: The value of variable i increases by 1, i=i+1, pointing to the next member of the current currStation, and go to Step 4.4;

[0091] Step 4.11: Return to StationMap. At this time, the StationMap divided layer by layer is the local index.

[0092] Furthermore, the distribution characteristics of the passenger trajectory in the cluster are calculated according to the query trajectory as described in Step 7. The specific process is as follows:

[0093] Assume the query trajectory TR = (OD1, OD2, OD3, …, ODn), there are common repeated ODs in the OD sequence corresponding to this trajectory;

[0094] The distribution characteristic calculation process is as follows:

[0095] Step7.1.1: Given the query trajectory TR=(OD1, OD2, OD3, …, ODn);

[0096] Step 7.1.2: Traverse the OD sequence in TR, count the number of each OD, sort in descending order by the number of times OD appears, and save the results in the following data structure:

[0097] countMap={(OD1, N1),(OD2, N2)),…,(ODk,Nh)}(10)

[0098] In formula (10), OD1~ODh are all different ODs without repetition, Ni represents the number of occurrences of ODi, and the cumulative sum of the number is n, where N1 is the largest and Nh is the smallest;

[0099] Step 7.1.3: Traverse countMap, count the percentage of each OD in the trajectory length, and save the result in the following data structure:

[0100] percentMap={(OD1, W1),(OD2, W2)),…,(ODk,Wh)}(11)

[0101] In formula (11), Wi represents the percentage of the number of ODi occurrences in the trajectory length, and the calculation formula is Wi = (Ni / n), with a value between 0 and 1; the cumulative sum of W1~Wh is 1;

[0102] Step 7.1.4: Traverse percentMap, use the global index to calculate the storage node corresponding to each OD, and save the result in the following data structure:

[0103] NodeMap={(Node1, W1),(Node2, W2)),…,(Nodek,Wh)}(12)

[0104] In formula (12), Nodei represents the node stored by Odi, and the calculation formula is Wi = (Ni / n), which takes a value between 0 and 1; the sum of W1~Wh is 1;

[0105] The calculation function that defines the distribution characteristics is:

[0106] distVector=getVectorByTR(TR)(13)

[0107] In formula (13), TR is the query trajectory, distVector is the distribution feature, and the type of distVector is the data structure described in formula (12).

[0108] Furthermore, the optimal search solution described in Step 7 has the following specific process:

[0109] Step7.2.1: Given the query trajectory distribution feature distVector;

[0110] distVector={(Node1, W1),(Node2, W2)),…,(Nodek,Wh)}

[0111] Initialize the key-value structure kvMap(solution,cost) to store the search solution and its corresponding time cost;

[0112] Step7.2.2: Traverse the distribution features and obtain the node set NodeSet={Node1, Node2, … ,Nodeh};

[0113] Step 7.2.3: Based on NodeSet, use the exhaustive method to list each search solution. All search solutions are stored in the following data structure:

[0114] solSet=(sol1, sol2, sol3, … ,soln) (18)

[0115] In formula (18), solSet is a search solution set, each element is a search solution, and there are n different search solutions in the search solution set;

[0116] Step7.2.4: Initialize variable i to 1 and traverse the search solution set solSet;

[0117] Step 7.2.5: Compare the size relationship between i and solSet.len;

[0118] If i is less than or equal to solSet.len, get the current search solution currSol, currSol=solSet(i);

[0119] Otherwise, go to Step 7.2.9;

[0120] Step 7.2.6: Calculate the time cost corresponding to the current search solution and save it in the variable currCost, currCost = getCost (distVector, currSol, C1, C2, C3);

[0121] Step7.2.7: Insert the current search scheme and the corresponding time into kvMap;

[0122] kvMap.insert(currSol, currCost)

[0123] Step7.2.8: Increase the variable i by 1, i=i+1, and go to Step7.2.5;

[0124] Step 7.2.9: Find the minimum time cost in kvMap: minCost = kvMap.getMinValue();

[0125] Step7.2.10: Use the minimum time cost to obtain the optimal search solution: optSol = kvMap.get(minCost);

[0126] Step7.2.11: Return the optimal search solution optSol.

[0127] Furthermore, the query interface in Step 6 is specifically as follows:

[0128] resList=distributedSearch (oTR, simfunc, threshold, filterfun,N) (20)

[0129] In formula (20), oTR is a trajectory, which consists of a set of OD sequences, specifically (id, OD1, OD2, ..., OD n ) ;

[0130] simfunc is a trajectory similarity measurement function used to calculate the similarity between the candidate trajectory and oTR;

[0131] threshold is a similarity threshold, ranging from 0 to 1;

[0132] filterfun is a filter function used to filter the trajectories that do not meet the query conditions in the candidate trajectory set;

[0133] N is a positive integer that determines the number of return trajectories;

[0134] resList is used to save the results of function execution and is a collection of trajectories.

[0135] Furthermore, the optimal search scheme is executed in a distributed environment as described in Step 8. The specific process is as follows:

[0136] Step8.1: Given the target trajectory oTR, the number of ODs in oTR is n;

[0137] Given a similarity measurement function simfunc, a similarity threshold threshold, a filter function filterfun and a return quantity N;

[0138] Step 8.2: Based on oTR as input, obtain the distribution characteristics of the trajectory:

[0139] disVector = getVectorByTR(oTR)

[0140] Step 8.3: Get the optimal search solution:

[0141] optSol=getOptimalSolution(disVector)

[0142] Step 8.4: Initialize the distributed task queue distributedTaskQueue and the distributed synchronization tool distributedBarrier;

[0143] The distributed task queue distributedTaskQueue is used to store tasks to be calculated;

[0144] The distributed synchronization tool distributedBarrier is used to provide task synchronization function in a distributed environment and control rounds to be executed in sequence;

[0145] Step8.5: Serialize the optimal search strategy optSol, target trajectory oTR, similarity measurement function simfunc, similarity threshold threshold, filter function filterfun and return quantity N into a message solMessage;

[0146] Step 8.6: Submit the message solMessage to the distributed queue:

[0147] distributedTaskQueue.submit(solMessage)

[0148] Step8.7: Initialize the variable loop to 1 to control the execution of the optimal search strategy optSol;

[0149] Step 8.8: Compare the size relationship between loop and optSol.len;

[0150] If loop is less than or equal to optSol.len, get the current round currRound=optSol(i);

[0151] Otherwise, go to Step 8.14;

[0152] Step 8.9: Get all participating nodes in currRound, save them in NodeList, and notify all nodes in NodeList to get the currRound of the current round;

[0153] Step8.10: Determine the value of loop. If loop is equal to 1, execute step 8.11.1; otherwise, execute step 8.11.2;

[0154] Step 8.11.1: Each node obtains currRound information, parses the computing tasks involved in this node, extracts and merges data from the local index, saves the result to the candidate trajectory segment canSegSet, and sends the result to the successor node through the network;

[0155] Step 8.11.2: Each node obtains currRound information, parses the computing tasks involved in this node, receives canSegSet sent by other nodes, merges them locally, and forms a new canSegSet;

[0156] Step8.12: Global synchronization waits for all tasks in the same round to finish, distributedBarrier.wait();

[0157] Step8.13: Increase the variable loop by 1, loop=loop+1, go to Step8.8;

[0158] Step8.14: Receive canSegSet sent by all nodes at the aggregation node and generate the candidate trajectory set canTRSet;

[0159] Step8.15: Return the candidate trajectory set canTRSet.

[0160] Furthermore, the execution process of the filtering strategy described in Step 9 is as follows:

[0161] The filter function runs after the last round. The form of the filter function is as follows:

[0162] resTRSet=filterfunc (canTRSet, simfunc, N) (21)

[0163] In formula (21), canTRSet is the candidate trajectory set generated in the last round, simfunc is the trajectory similarity measurement function, and N is the number of trajectories that should be returned;

[0164] The specific implementation process is as follows:

[0165] Step9.1: Input the candidate trajectory set canTRSet, the similarity measurement function simfunc and the number of trajectories N;

[0166] Step 9.2: Initialize the key-value pair data structure kvMap<TR,score> , used to save the similarity scores of candidate trajectories;

[0167] Step 9.3: Initialize variable i to 1 and traverse each member in canTRSet;

[0168] Step 9.4: Determine the relationship between i and canTRSet.len. If i is less than canTRSet.len, select the current trajectory currTR=canTRSet(i); otherwise, go to Step 9.7;

[0169] Step 9.5: Calculate the similarity between currTR and oTR: socre = simfunc (oTR, currTR);

[0170] Save the calculation results to kvMap, kvMap.insert(currTR, score);

[0171] Step 9.6: Increase the variable i by 1, i=i+1, and go to Step 9.4;

[0172] Step 9.7: Sort kvMap by similarity score and save the sorted results, sortedTRList = kvMap.sortByScore;

[0173] Step 9.8: Select the first N trajectories and save them in the result set resTRSet, resTRSet = sortedTRList(5);

[0174] Step E: Return resTRSet, end.

[0175] The beneficial effects of the present invention are:

[0176] (1) The present invention uses a secondary index to store subway passenger ticket data in a distributed environment, divides the ticket data into track modes, and maps them to different storage nodes. By simply adding storage nodes, a larger scale of ticket data can be stored, and the scalability is strong.

[0177] (2) This invention makes full use of the spatiotemporal attributes of ticket data and designs a local index based on station-time-direction, providing a more efficient indexing method.

[0178] (3) The present invention can manage large-scale subway passenger ticket records, complete data partition mapping through distributed secondary indexing, and design local indexes based on trajectory spatiotemporal features. Compared with existing methods, the present invention has stronger data processing capabilities, higher indexing efficiency, and greater scalability. BRIEF DESCRIPTION OF THE DRAWINGS

[0179] Figure 1 It is a schematic diagram of ticket card data partition mapping in the present invention;

[0180] Figure 2 Schematic diagram of the local index inside the storage node;

[0181] Figure 3 Schematic diagram of trajectory similarity search execution. DETAILED DESCRIPTION

[0182] The present invention will be further described below in conjunction with the accompanying drawings and specific implementation methods.

[0183] Embodiment 1: A method for storing and indexing subway ticket records based on distributed secondary indexes, characterized in that the method comprises:

[0184] Step 1: Collect all smart card tapping records generated by all rail transit ticket collection systems;

[0185] The smart card tapping record refers to the ticket record generated by passengers tapping their cards at the subway station gate;

[0186] The ticket record includes fields such as card number, timestamp, subway station, entry and exit identification, amount information, etc. The time, subway station, and entry and exit identification in a ticket record can be converted into a point containing time and space attributes;

[0187] Step 2: Group all ticket records by card number, sort the ticket records in each group by time to form passenger trajectories, and save the passenger trajectories in the form of OD sequence;

[0188] The OD refers to treating the information contained in the OD of a passenger's trip in a subway station as a tuple, including the following information: "starting station, entry time, entry", "terminal station, exit time, exit";

[0189] Step 3: Figure 1 As shown, all passenger trajectories are divided into OD granularity, a global index in the distributed secondary index is constructed, each trajectory is traversed, the OD in the trajectory is obtained, and the OD in all trajectories constitutes an OD set;

[0190] Divide the OD set into multiple partitions, each partition contains an OD subset, and each partition is mapped to a unique storage node;

[0191] Figure 1The partitioning process of ticket track data is described in . First, the OD in the ticket track is hashed and signed. The hash signature is modulo the number of nodes m to obtain an integer number from 0 to (m-1), which is used as the partition number of the OD, and also the number of the storage node. The OD is aggregated by the partition number to form an OD subset. Each subset is mapped to a storage node, laying a good foundation for the local index inside the node.

[0192] Specifically:

[0193] First, use the hash signature to sign each OD in the passenger trajectory and obtain the partition number corresponding to each OD.

[0194] Secondly, ODs with the same partition number are grouped and aggregated, and then the OD mapping corresponding to each partition is saved to different storage nodes.

[0195] Among them, the mapping from OD to partition number and the mapping from partition number to storage node constitute the global index;

[0196] The global index is stored in the control node. In the global index, partition positioning is performed in units of OD;

[0197] The hash signature is a function that takes OD as input and outputs an integer number. The maximum value of the integer number corresponds to the number of storage nodes in the cluster.

[0198] The cluster is a collection of computer nodes. In the present invention, multiple computer nodes are used to store OD data.

[0199] Step 4: Figure 2 As shown, a local index is constructed for the OD subset in the partition on each storage node, and each OD is split into two points, O and D, to form a point set;

[0200] The point set is divided into finer granularity levels according to the subway station name, card tapping time, and entry and exit marks in the point, as follows:

[0201] First, the point set is divided according to the site name to form a site name subset;

[0202] Secondly, the site name subset is divided into time interval subsets to form time period subsets;

[0203] Finally, the time period subsets are divided into two groups according to direction, namely the inbound group and the outbound group;

[0204] After a series of divisions, a three-layer index of "site name-time period-direction" is formed. This three-layer index is the local index, which is stored on each storage node.

[0205] Step 5: Given the target trajectory saved in the form of OD sequence, calculate the data distribution characteristics of the target trajectory in the cluster;

[0206] According to the data distribution characteristics, local computing costs, network transmission costs and distributed synchronization costs, find the optimal search solution with the shortest time consumption among all search solutions;

[0207] Step 6: Specify the query trajectory, similarity measurement function, similarity threshold and filtering strategy, and call the query interface;

[0208] The similarity metric function is used to quantify the similarity between two different trajectories. The similarity value is between 0 and 1, where 0 means that the two trajectories have no temporal and spatial intersection, and 1 means that the two trajectories are exactly the same.

[0209] The similarity threshold is a floating point number between 0 and 1. When the similarity between the candidate trajectory and the input trajectory is greater than the threshold, the candidate trajectory will be returned;

[0210] The filtering strategy is an optimization measure that can quickly determine whether the similarity between the candidate trajectory and the input trajectory is greater than a threshold based on the characteristics of the candidate trajectory and the input trajectory, thus avoiding time-consuming trajectory similarity comparison.

[0211] Step 7: Calculate the distribution characteristics of the passenger trajectory in the cluster based on the query trajectory, and calculate the optimal search solution based on the distribution characteristics;

[0212] The distribution characteristics of the passenger trajectory describe the distribution of OD in different storage nodes in the trajectory. The characteristic distribution is calculated by querying the trajectory and the global index.

[0213] The similarity search of trajectories involves multiple nodes in the cluster. There are many ways to aggregate data between nodes in a distributed environment. Assuming that the search involves N nodes in the cluster, two typical data aggregation methods are given here. For example, N-1 nodes are aggregated to the Nth node; N nodes are aggregated in pairs for multiple rounds of aggregation. After the first round, there are (0.5*N) nodes left to participate in the second round of aggregation. After the second round, there are (0.5*0.5*N) nodes left, and they are aggregated to 1 node in the last round.

[0214] The convergence method is the search scheme. Multiple possible convergence methods represent multiple different search schemes. Each search scheme consists of multiple rounds of search, and each round of search consists of a set of tasks executed in parallel. The tasks may be local calculations or network data transmissions. Different convergence methods will result in different local calculation costs, network transmission costs, and distributed synchronization costs during execution, which will lead to different total time consumption.

[0215] The optimal search solution refers to the search solution that consumes the least time among all search solutions;

[0216] Step 8: Execute the optimal search solution in a distributed environment, such as Figure 3 As shown in the figure, in a distributed environment, the process of trajectory similarity search is a multi-round parallel execution process. In each round, a group of parallel tasks are executed. After the tasks are completed, the intermediate results are merged. The intermediate results of the previous round are used as the input of the next round of calculation. Use distributed synchronization tools to wait for the completion of a group of tasks and control the execution of rounds according to the scheduling plan. Generally speaking, the number of tasks in the current round is half of that in the previous round.

[0217] Specifically:

[0218] To perform the first round of search, a set of tasks executed in parallel in a distributed environment extract data from the local local index and merge them into OD, and then transmit the data to the corresponding nodes through the network;

[0219] To perform the second round of search, a set of tasks that are executed in parallel in a distributed environment are executed simultaneously, and each task has the same processing logic;

[0220] Each task first obtains the data sent to the local node by other nodes, merges it with the local data, forms a candidate trajectory segment, and transmits the candidate trajectory segment to the corresponding node through the network;

[0221] The subsequent rounds of searches were all the same as the second round of searches;

[0222] After the last round, a set of candidate trajectories is formed;

[0223] The candidate trajectory set refers to each trajectory in the set that may satisfy the similarity query condition;

[0224] Step 9: Execute the filtering strategy on the candidate trajectory set. The trajectories that do not meet the filtering conditions are deleted, and the trajectories that meet the filtering conditions are retained to form the result trajectory set;

[0225] Step 10: Return the result trajectory set in Step 9.

[0226] Each ticket record of a passenger can be converted into a point containing space-time information. A space-time point is represented by three attributes.

[0227] Definition of spacetime point:

[0228] Point = (t,s,d)(1)

[0229] In formula (1), t represents the card swiping time, s represents the station name, and d represents the entry or exit mark.

[0230] A passenger's journey in the subway system includes two time and space points, the starting point and the end point. A journey can be represented by an OD. The definition of OD is:

[0231] OD = (P o ,P d )(2)

[0232] In formula (2), Po represents the starting point of the trip, and Pd represents the end point of the trip. Each point records the passenger's card number, card tapping time, and entry and exit marks.

[0233] All the trips of passengers in the subway system within a period of time constitute the passenger's trajectory. Definition of trajectory:

[0234] Trajectory = (id, OD1, OD2, ... , OD m )(3)

[0235] In formula (3), id represents the smart card number, OD represents one-time formation, and OD is arranged from small to large in terms of time.

[0236] The trajectories generated by all passengers in the rail transit system constitute the trajectory set. Trajectory set and definition:

[0237] TRSet=(TR, TR, TR,…TR) (4)

[0238] In formula (4), each TR represents the trajectory of a passenger, and the number of trajectories is equal to the number of smart cards.

[0239] Trajectory similarity search means, given a query trajectory Q, a similarity measure function F, and a similarity threshold threshold, finding a subset in the trajectory set, in which the similarity between each trajectory and Q is greater than the threshold threshold.

[0240] The global index of the distributed secondary index is constructed in Step 3. The specific process is as follows:

[0241] Step 3.1: Given a trajectory set TRSet, a given number of partitions p, and a given number of nodes m, the trajectory set is in the following form:

[0242] TRSet={TR1,TR2,TR3,…,TRn}(5)

[0243] In formula (5), TR is the specific trajectory, and n represents the number of trajectories in the set;

[0244] Initialize the key-value structure ODMap(index,ODSet) for the result of OD set partitioning;

[0245] Initialize the key-value structure GIndexMap(OD,(index,node)) to save the global index;

[0246] Step 3.2: Initialize variable i to 1, traverse each trajectory in the trajectory set; determine the size relationship between i and TRSet.len;

[0247] If i is less than or equal to TRSet.len, select the current track currTR, currTR=TRSet(i);

[0248] Otherwise, execute Step 3.8;

[0249] The i is an index used to traverse different trajectories in the trajectory set; j is also an index used to traverse the OD in the trajectory; this is essentially a double for loop, which is to take out each OD in the trajectory set.

[0250] Step 3.3: Initialize the variable j to 1, traverse each OD in currTR, and determine the size relationship between j and currTR.len;

[0251] If j is less than or equal to currTR.len, select the current currOD=currTR(j);

[0252] Otherwise, execute Step 3.2;

[0253] If j is greater than currTR.len, it means that every OD of the current trajectory has been processed. It is necessary to jump out of the inner loop and process the next trajectory in the trajectory set.

[0254] Step 3.4: Calculate the partition number corresponding to OD, as shown in the following formula:

[0255] index=(hash(OD) mod p)+1(6)

[0256] In formula (6), hash(OD) represents the hash signature of OD, p is the number of partitions, and the value of index is between 1 and p;

[0257] Step 3.5: Save OD into a key-value pair data structure. The specific format is as follows:

[0258] ODMap = {(index1,ODSet1),(index2,ODSet2)...,(index p ,ODSet p )}(7)

[0259] In formula (7), ODMap is a key-value storage structure, index represents the partition number, ODSet represents the set of ODs, and in the same key-value structure (index, ODSet), each OD in the ODSet set has the same partition number index;

[0260] Step 3.6: The value of variable j increases by 1, j=j+1, pointing to the next OD of the current trajectory, and go to Step 3.3;

[0261] Step 3.7: The value of variable i increases by 1, i=i+1, pointing to the next trajectory of the current trajectory set, and go to Step 3.2;

[0262] Here is a double for loop. Take j as an example. j points to the current OD. After the current OD is executed, the next OD needs to be processed. At this time, j needs to be increased by 1 to get the next OD. After the double for loop ends, 3.8 starts to execute.

[0263] Step 3.8: Initialize the variable k to 1, traverse ODMap, and compare the relationship between k and ODMap.len;

[0264] If k is less than ODMap.len, get the current index and ODSet through function call, (index, ODSet) = ODMap(k);

[0265] Otherwise, go to Step 3.11;

[0266] The ODMap is a key-value structure, and k is used to traverse each key-value pair in the ODMAp. The three different variables i, j, and k are all used to control the loop.

[0267] The (index, ODSet)=ODMap(k) is a commonly used function of the key-value pair data structure.

[0268] Step 3.9: Calculate the storage node number corresponding to the partition number, node = (index mod m) + 1, the node number value range is [1 ~ m];

[0269] Traverse each element OD in ODSet, and insert the partition and storage node corresponding to the OD into the global index, GIndexMap.insert(OD,(index,node));

[0270] Step 3.10: k=k+1, pointing to the next element in ODMap, go to Step 3.8;

[0271] Step3.11: Return the global index GIndexMap and OD partition ODMap.

[0272] The local index described in Step 4 is to build the local index in parallel on each storage node at the same time. The specific process is as follows:

[0273] Step 4.1: Input OD set ODSet, subway station name set StationSet and time interval t;

[0274] ODSet comes from the ODMap returned in Step 3.11;

[0275] The subway station name set is {(station1,station2,…,station N}, where each element is a subway station name;

[0276] The time interval t is in minutes and can be any integer value between 5 and 60;

[0277] Step 4.2: Traverse each OD in ODSet and split each OD into two points, O and D (refer to formula (1) point). After the traversal, all points form a point set PointSet;

[0278] The OD is a trip, including the starting point and the end point. The passenger trajectory is composed of a series of ODs. The global index is located by OD, and the local index is managed by point.

[0279] Step 4.3: Traverse each point in the point set PointSet, divide the points with the same site name into the same group, and save the divided point set in the following data structure:

[0280] StationMap={(ID1,station1,Set1),( ID2,station2,Set2),…, ( ID N ,station N ,Set N )}(8)

[0281] In formula (8), StationMap is the storage method after the point set is divided, IDi represents the number of the subway station, stationi represents the name of the subway station, and Seti represents the set of all ticket records generated by the subway station;

[0282] Step 4.4: Initialize the variable i to 1, traverse each member in StationMap, and compare the size relationship between i and StationMap.len;

[0283] If i is less than StationMap.len, select the current station and its corresponding point set currStation, currStation=StationMap (i);

[0284] Otherwise, go to Step 4.11;

[0285] This is a process of layer-by-layer processing to establish a local index, and the local index also has a multi-layer structure. Step 4.3 divides the point set by station name, and the result is saved in StationMap in formula (8). Then traverse each member of StationMap to continue the division.

[0286] Step 4.5: Get the point set Set corresponding to the current station currStation, and further divide the points in Set into segments according to the time interval t. The point set Set and the space-time points after segmentation are stored in a data structure as shown in formula (9):

[0287] timeLMap = {(I1,tSeg1,n1,sSet1), (I2,tSeg2,n2,sSet2),…, (I M ,tSeg M ,n M ,sSet M )}(9)

[0288] In formula (9), I represents the time period number, tSeg represents the time period name, n represents the number of ticket records generated within the time period, and sSet represents the set of all ticket records generated within the time period, which is a subset of Set.

[0289] Step 4.6: Initialize the variable j to 1, traverse each member in timeLMap, and determine the size relationship between j and timeLMap.len;

[0290] If j is less than or equal to timeLMap.len, select the current time segment currSeg, currSeg=timeLMap(j);

[0291] Otherwise, go to Step 4.11;

[0292] Step 4.7: Further divide the sSet in the current currSeg into OSet and DSet, where OSet represents the entry set and DSet represents the battle set;

[0293] Step 4.8: Sort the points in OSet and DSet by time respectively;

[0294] Step 4.9: The value of variable j increases by 1, j=j+1, pointing to the next member of the current currSeg, and go to Step 4.6;

[0295] Step 4.10: The value of variable i increases by 1, i=i+1, pointing to the next member of the current currStation, and go to Step 4.4;

[0296] Step 4.11: Return to StationMap. At this time, the StationMap divided layer by layer is the local index.

[0297] In Step 7, the distribution characteristics of the passenger trajectory in the cluster are calculated according to the query trajectory. The specific process is as follows:

[0298] Assume the query trajectory TR = (OD1, OD2, OD3, …, ODn), there are common repeated ODs in the OD sequence corresponding to this trajectory;

[0299] The distribution characteristic calculation process is as follows:

[0300] Step7.1.1: Given the query trajectory TR=(OD1, OD2, OD3, …, ODn);

[0301] Step 7.1.2: Traverse the OD sequence in TR, count the number of each OD, sort in descending order by the number of times OD appears, and save the results in the following data structure:

[0302] countMap={(OD1, N1),(OD2, N2)),…,(ODk,Nh)}(10)

[0303] In formula (10), OD1~ODh are all different ODs without repetition, Ni represents the number of occurrences of ODi, and the cumulative sum of the number is n, where N1 is the largest and Nh is the smallest;

[0304] Step 7.1.3: Traverse countMap, count the percentage of each OD in the trajectory length, and save the result in the following data structure:

[0305] percentMap={(OD1, W1),(OD2, W2)),…,(ODk,Wh)}(11)

[0306] In formula (11), Wi represents the percentage of the number of ODi occurrences in the trajectory length, and the calculation formula is Wi = (Ni / n), with a value between 0 and 1; the cumulative sum of W1~Wh is 1;

[0307] Step 7.1.4: Traverse percentMap, use the global index to calculate the storage node corresponding to each OD, and save the result in the following data structure:

[0308] NodeMap={(Node1, W1),(Node2, W2)),…,(Nodek,Wh)}(12)

[0309] In formula (12), Nodei represents the node stored by Odi, and the calculation formula is Wi = (Ni / n), which takes a value between 0 and 1; the sum of W1~Wh is 1;

[0310] The calculation function that defines the distribution characteristics is:

[0311] distVector=getVectorByTR(TR)(13)

[0312] In formula (13), TR is the query trajectory, distVector is the distribution feature, and the type of distVector is the data structure described in formula (12).

[0313] The specific process of the optimal search solution in Step 7 is as follows:

[0314] Given a query trajectory TR, calculate the distribution characteristics corresponding to the trajectory:

[0315] distVector ={(Node1, W1),(Node2, W2)),…,(Nodek,Wh)}

[0316] The distribution characteristics describe the nodes involved in the search process, and the node set is:

[0317] NodeSet={Node1, Node2, … , Nodeh}

[0318] Since each search scheme is equivalent to a data aggregation method in a distributed environment, there are many different aggregation methods for this node set;

[0319] The search scheme consists of multiple rounds of convergence, each of which consists of multiple parallel tasks in a distributed environment. The tasks are defined as:

[0320] Task=(Node1, Node2)(14)

[0321] In formula (14), Node1 and Node2 are both storage nodes, and the order represents that Node1 stores the local aggregation results to Node2 through the network;

[0322] Define rounds as:

[0323] Round={Task1,Task2,…,Taskh}(15)

[0324] In formula (15), represents h tasks executed simultaneously, each task has the same function;

[0325] Define the search scheme as:

[0326] Solution={Round1,Round2,…,Roundk}(16)

[0327] In formula (16), each member is a round, and k represents the number of rounds to be searched.

[0328] Different search schemes have different local execution costs, network data transmission costs, and distributed synchronization costs. The present invention defines the total time cost calculation method of the search scheme as follows:

[0329] cost=getCost (distVector, Solution, C1, C2, C3) (17)

[0330] In formula (17), distVector represents the distribution characteristics of the trajectory, Solution represents a search solution, C1 represents the local computing cost, C2 represents the data transmission cost in the network, C3 represents the cost of multi-node synchronization (barrier) in a distributed environment, getCost is a nonlinear calculation function with the above four parameters as input, and cost is the time cost corresponding to a given search solution, marked in seconds (s) or milliseconds (ms);

[0331] Step7.2.1: Given the query trajectory distribution feature distVector;

[0332] distVector={(Node1, W1),(Node2, W2)),…,(Nodek,Wh)}

[0333] Initialize the key-value structure kvMap(solution,cost) to store the search solution and its corresponding time cost;

[0334] Step7.2.2: Traverse the distribution features and obtain the node set NodeSet={Node1, Node2, … ,Nodeh};

[0335] Step 7.2.3: Based on NodeSet, use the exhaustive method to list each search solution. All search solutions are stored in the following data structure:

[0336] solSet=(sol1, sol2, sol3, … ,soln) (18)

[0337] In formula (18), solSet is a search solution set, each element is a search solution, and there are n different search solutions in the search solution set;

[0338] Step7.2.4: Initialize variable i to 1 and traverse the search solution set solSet;

[0339] Step 7.2.5: Compare the size relationship between i and solSet.len;

[0340] If i is less than or equal to solSet.len, get the current search solution currSol, currSol=solSet(i);

[0341] Otherwise, go to Step 7.2.9;

[0342] Step 7.2.6: Calculate the time cost corresponding to the current search solution and save it in the variable currCost, currCost = getCost (distVector, currSol, C1, C2, C3);

[0343] Step7.2.7: Insert the current search scheme and the corresponding time into kvMap;

[0344] kvMap.insert(currSol, currCost)

[0345] Step7.2.8: Increase the variable i by 1, i=i+1, and go to Step7.2.5;

[0346] Step 7.2.9: Find the minimum time cost in kvMap: minCost = kvMap.getMinValue();

[0347] Step7.2.10: Use the minimum time cost to obtain the optimal search solution: optSol = kvMap.get(minCost);

[0348] Step7.2.11: Return the optimal search solution optSol.

[0349] The calculation formula for defining the optimal search solution is as follows:

[0350] optSol=getOptimalSolution(distVector)(19)

[0351] In formula (19), distVector is the distribution feature and optSol is the optimal search solution.

[0352] The query interface in Step 6 is specifically:

[0353] resList=distributedSearch (oTR, simfunc, threshold, filterfun,N) (20)

[0354] In formula (20), oTR is a trajectory, which consists of a set of OD sequences, specifically (id, OD1, OD2, ..., OD n ) ;

[0355] simfunc is a trajectory similarity measurement function, which is used to calculate the similarity between the candidate trajectory and oTR; its input is two trajectories, and its output is a floating point number between 0 and 1, where 0 means that the two trajectories have no temporal and spatial intersection, and 1 means that the two trajectories are exactly the same. This similarity measurement function can be one of the four common trajectory similarity measurement methods: LCSS, DTW, JC, and ED;

[0356] threshold is a similarity threshold, ranging from 0 to 1, usually above 0.5. When the similarity between the candidate trajectory and the oTR is greater than the threshold, the candidate trajectory will be retained and participate in the subsequent calculation.

[0357] filterfun is a filter function used to filter the trajectories that do not meet the query conditions in the candidate trajectory set;

[0358] N is a small positive integer that determines the number of return trajectories;

[0359] resList is used to save the results of function execution and is a collection of trajectories.

[0360] In Step 8, the optimal search solution is executed in a distributed environment. The specific process is as follows:

[0361] Step8.1: Given the target trajectory oTR, the number of ODs in oTR is n;

[0362] Given a similarity measurement function simfunc, a similarity threshold threshold, a filter function filterfun and a return quantity N;

[0363] Step 8.2: Based on oTR as input, obtain the distribution characteristics of the trajectory:

[0364] disVector = getVectorByTR(oTR)

[0365] Step 8.3: Get the optimal search solution:

[0366] optSol=getOptimalSolution(disVector)

[0367] Step 8.4: Initialize the distributed task queue distributedTaskQueue and the distributed synchronization tool distributedBarrier;

[0368] The distributed task queue distributedTaskQueue is used to store tasks to be calculated;

[0369] The distributed synchronization tool distributedBarrier is used to provide task synchronization function in a distributed environment and control rounds to be executed in sequence;

[0370] Step 8.5: Serialize the optimal search strategy optSol, target trajectory oTR, similarity measurement function simfunc, similarity threshold threshold, filter function filterfun and return quantity N into a message solMessage;

[0371] Step 8.6: Submit the message solMessage to the distributed queue:

[0372] distributedTaskQueue.submit(solMessage)

[0373] Step8.7: Initialize the variable loop to 1 to control the execution of the optimal search strategy optSol;

[0374] Step 8.8: Compare the size relationship between loop and optSol.len;

[0375] If loop is less than or equal to optSol.len, get the current round currRound=optSol(i);

[0376] Otherwise, go to Step 8.14;

[0377] Step 8.9: Get all participating nodes in currRound, save them in NodeList, and notify all nodes in NodeList to get the currRound of the current round;

[0378] Step8.10: Determine the value of loop. If loop is equal to 1, execute step 8.11.1; otherwise, execute step 8.11.2;

[0379] Step 8.11.1: Each node obtains currRound information, parses the computing tasks involved in this node, extracts and merges data from the local index, saves the result to the candidate trajectory segment canSegSet, and sends the result to the successor node through the network;

[0380] Step 8.11.2: Each node obtains currRound information, parses the computing tasks involved in this node, receives canSegSet sent by other nodes, merges them locally, and forms a new canSegSet;

[0381] Step8.12: Global synchronization waits for all tasks in the same round to finish, distributedBarrier.wait();

[0382] Step8.13: Increase the variable loop by 1, loop=loop+1, go to Step8.8;

[0383] Step8.14: Receive canSegSet sent by all nodes at the aggregation node and generate the candidate trajectory set canTRSet;

[0384] Step8.15: Return the candidate trajectory set canTRSet.

[0385] The execution process of the filtering strategy in Step 9 is as follows:

[0386] The filter function runs after the last round. The form of the filter function is as follows:

[0387] resTRSet=filterfunc (canTRSet, simfunc, N) (21)

[0388] In formula (21), canTRSet is the candidate trajectory set generated in the last round, simfunc is the trajectory similarity measurement function, and N is the number of trajectories that should be returned;

[0389] The specific implementation process is as follows:

[0390] Step9.1: Input the candidate trajectory set canTRSet, the similarity measurement function simfunc and the number of trajectories N;

[0391] Step 9.2: Initialize the key-value pair data structure kvMap<TR,score> , used to save the similarity scores of candidate trajectories;

[0392] Step 9.3: Initialize variable i to 1 and traverse each member in canTRSet;

[0393] Step 9.4: Determine the relationship between i and canTRSet.len. If i is less than canTRSet.len, select the current trajectory currTR=canTRSet(i); otherwise, go to Step 9.7;

[0394] Step 9.5: Calculate the similarity between currTR and oTR: socre = simfunc (oTR, currTR);

[0395] Save the calculation results to kvMap, kvMap.insert(currTR, score);

[0396] Step 9.6: Increase the variable i by 1, i=i+1, and go to Step 9.4;

[0397] Step 9.7: Sort kvMap by similarity score and save the sorted results, sortedTRList = kvMap.sortByScore;

[0398] Step 9.8: Select the first N trajectories and save them in the result set resTRSet, resTRSet = sortedTRList(5);

[0399] Step E: Return resTRSet and end. For example, suppose there are 10 results that meet the similarity search condition, but only 5 (determined by parameter N) trajectories need to be returned. Therefore, sort the 10 trajectories and select 5 of them to return as the results.

[0400] Example 2: In order to better demonstrate the present invention, based on Example 1, when implementing the scheme of the present invention, the implementation process of the present invention can also be divided into three parts, namely: data preprocessing, index construction and serialization, service deployment and testing.

[0401] The data preprocessing process is as follows:

[0402] Plan a six-node cluster to install Spark and HDFS cluster. One node is used as the master node, four nodes are used as slave nodes, and one node is used to run the program. The Spark cluster is used to complete data preprocessing and index construction.

[0403] Install and configure HDFS and Spark clusters in a hybrid deployment mode, with HMaster and NameNode deployed on the same node and Worker and DataNode deployed on other nodes.

[0404] Collect six months of bus card swiping records from a city's rail transit system and upload them to the distributed file system HDFS cluster;

[0405] Use Spark program to read ticket data and preprocess the data, including: field extraction, grouping by card number, sorting by time, generating passenger trajectories, and saving the trajectories in OD sequence format. The processed data is saved in HDFS.

[0406] Extract sample trajectories: Randomly collect 100 trajectories in the OD sequence in the previous step as test samples, and download the test samples from HDFS to the local disk of the master node.

[0407] The specific process of index construction and serialization is as follows:

[0408] Use the Spark program to read the OD sequence stored on HDFS, call the flatMap operator, traverse each OD sequence, and use (hash(OD) mod m, where m is 4) to calculate the partition number corresponding to each OD in the sequence to form an (OD, index) tuple;

[0409] Group and aggregate OD by partition: Group and aggregate the (OD, index) tuples formed in the previous step by partition number index, call the GroupBy operator, and form (index, (OD1, OD2, …, ODn)).

[0410] Divide by station: Perform OD decomposition on the (index, (OD1, OD2, …, ODn)) formed in the previous step to form a point sequence (index, (O1, D1, O2, D2, …, On, Dn)), and group the point sequence by station to form (station, {p1, p2, …pm}).

[0411] Divide by time period: The (station,{p1,p2,…pm}) formed in the previous step is further divided by time period, which can be set to 30 minutes here, to form ((station,tindex),{p1,p2,…pk}).

[0412] Divide by entry and exit station: The ((station,tindex), {p1,p2,…pk}) formed in the previous step is further divided according to the entry and exit flags to form a three-level index ((station,tindex,flag), {p1,p2,…ph}), and the internal points are sorted by time size.

[0413] Index file serialization: Serialize the index ((station,tindex,flag), {p1,p2,…ph}) formed in the previous step and save it as a binary file. Four serialized files are formed here.

[0414] The service deployment and performance testing process is as follows:

[0415] Index file download: The four serialized files generated in the previous stage are downloaded from HDFS on four nodes respectively and saved in the local disk.

[0416] Service deployment: Before deploying the service of the present invention, shut down the HDFS and Spark clusters. Deploy the control node program on the master node, the user maintains the global index, and submits the trajectory similarity search program; deploy storage and computing services on the slave nodes to maintain the local index and perform the search function.

[0417] Service support service: Deploy the zookeeper service on the four master nodes to provide distributed queues and distributed synchronization tools, and start zookeeper.

[0418] Service startup: Start the guard of the present invention in the command line to complete the service deployment.

[0419] Index file deserialization: The service deployed on the slave node reads the serialized file into memory, deserializes it, and regenerates the (site-time period-reverse) three-level index in memory.

[0420] Performance test: read 100 sample trajectories from the local disk of the master node, call the function interface, submit the 100 sample data in sequence, perform trajectory similarity search, and record the time taken for each function call.

[0421] The experimental test cluster contains five nodes, each with the same configuration of 64 cores, 128 GB memory, and 20 TB disk. The dataset contains 2 billion ticket records, belonging to 10 million passenger trajectories. 100 trajectory similarity searches are performed, with a time cost ranging from 0.1 seconds to 0.3 seconds.

[0422] The above data show that the index construction and serialization of the present invention are at the minute level, which is much faster than the existing methods, and can perform fast index updates and service redeployment.

[0423] The present invention uses cluster and big data technologies to design a distributed secondary index for storing and indexing massive amounts of subway passenger ticket data to support trajectory similarity search. Its processing capability far exceeds that of a single-node-based solution. Compared with a distributed database, the present invention stores record-type ticket data from the perspective of trajectory, which can efficiently support trajectory similarity search.

[0424] The specific implementation modes of the present invention are described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above implementation modes, and various changes can be made within the knowledge scope of ordinary technicians in this field without departing from the purpose of the present invention.

Claims

1. A subway ticket record storage and indexing method based on distributed secondary index, characterized in that: The method comprises: Step 1: Collect all smart card tapping records generated by all rail transit ticket collection systems; The smart card tapping record refers to the ticket record generated by passengers tapping their cards at the subway station gate; Step 2: Group all ticket records by card number, sort the ticket records in each group by time to form passenger trajectories, and save the passenger trajectories in the form of OD sequence; The OD refers to treating the information contained in a passenger's trip OD in a subway station as a tuple, including the following information: "starting station, entry time, entry", "terminal station, exit time, exit"; Step 3: Divide all passenger trajectories into OD granularity, build a global index in the distributed secondary index, traverse each trajectory, obtain the OD in the trajectory, and the OD in all trajectories constitute an OD set; Divide the OD set into multiple partitions, each partition contains an OD subset, and each partition is mapped to a unique storage node; Among them, the mapping from OD to partition number and the mapping from partition number to storage node constitute the global index; The global index is stored in the control node. In the global index, partition positioning is performed in units of OD; The hash signature is a function that takes OD as input and outputs an integer number. The maximum value of the integer number corresponds to the number of storage nodes in the cluster. Step 4: Build a local index for the OD subset in the partition on each storage node, split each OD into two points, O and D, to form a point set; The point set is divided into finer granularity levels according to the subway station name, card tapping time, and entry and exit marks in the point, as follows: First, the point set is divided according to the site name to form a site name subset; Secondly, the site name subset is divided into time interval subsets to form time period subsets; Finally, the time period subsets are divided into two groups according to direction, namely the inbound group and the outbound group; Step 5: Given the target trajectory saved in the form of OD sequence, calculate the data distribution characteristics of the target trajectory in the cluster; According to the data distribution characteristics, local computing costs, network transmission costs and distributed synchronization costs, find the optimal search solution with the shortest time consumption among all search solutions; Step 6: Specify the query trajectory, similarity measurement function, similarity threshold and filtering strategy, and call the query interface; Step 7: Calculate the distribution characteristics of the passenger trajectory in the cluster based on the query trajectory, and calculate the optimal search solution based on the distribution characteristics; The optimal search solution refers to the search solution that consumes the least time among all search solutions; Step 8: Execute the optimal search solution in a distributed environment, specifically: To perform the first round of search, a set of tasks executed in parallel in a distributed environment extract data from the local local index and merge them into OD, and then transmit the data to the corresponding nodes through the network; To perform the second round of search, a set of tasks that are executed in parallel in a distributed environment are executed simultaneously, and each task has the same processing logic; Each task first obtains the data sent to the local node by other nodes, merges it with the local data, forms a candidate trajectory segment, and transmits the candidate trajectory segment to the corresponding node through the network; The subsequent rounds of searches were all the same as the second round of searches; After the last round, a set of candidate trajectories is formed; The candidate trajectory set refers to each trajectory in the set that may satisfy the similarity query condition; Step 9: Execute the filtering strategy on the candidate trajectory set. The trajectories that do not meet the filtering conditions are deleted, and the trajectories that meet the filtering conditions are retained to form the result trajectory set; Step 10: Return the result trajectory set in Step 9.

2. The subway ticket record storage and indexing method based on distributed secondary index according to claim 1 is characterized in that: The global index of the distributed secondary index is constructed in Step 3. The specific process is as follows: Step 3.1: Given a trajectory set TRSet, a given number of partitions p, and a given number of nodes m, the trajectory set is in the following form: TRSet={TR1,TR2,TR3,…,TRn}(5); In formula (5), TR is the specific trajectory, and n represents the number of trajectories in the set; Initialize the key-value structure ODMap(index,ODSet) for the result of OD set partitioning; Initialize the key-value structure GIndexMap(OD,(index,node)) to save the global index; Step 3.2: Initialize variable i to 1, traverse each trajectory in the trajectory set; determine the size relationship between i and TRSet.len; If i is less than or equal to TRSet.len, select the current track currTR, currTR=TRSet(i); Otherwise, execute Step 3.8; Step 3.3: Initialize the variable j to 1, traverse each OD in currTR, and determine the size relationship between j and currTR.len; If j is less than or equal to currTR.len, select the current currOD=currTR(j); Otherwise, execute Step 3.2; Step 3.4: Calculate the partition number corresponding to OD, as shown in the following formula: index=(hash(OD) mod p)+1(6); In formula (6), hash(OD) represents the hash signature of OD, p is the number of partitions, and the value of index is between 1 and p; Step 3.5: Save OD into a key-value pair data structure. The specific format is as follows: ODMap = {(index1,ODSet1),(index2,ODSet2)...,(index p ,ODSet p )}(7); In formula (7), ODMap is a key-value storage structure, index represents the partition number, ODSet represents the set of ODs, and in the same key-value structure (index, ODSet), each OD in the ODSet set has the same partition number index; Step 3.6: The value of variable j increases by 1, j=j+1, pointing to the next OD of the current trajectory, and go to Step 3.3; Step 3.7: The value of variable i increases by 1, i=i+1, pointing to the next trajectory of the current trajectory set, and go to Step 3.2; Step 3.8: Initialize the variable k to 1, traverse ODMap, and compare the relationship between k and ODMap.len; If k is less than ODMap.len, get the current index and ODSet through function call, (index, ODSet) = ODMap(k); Otherwise, go to Step 3.11; Step 3.9: Calculate the storage node number corresponding to the partition number, node = (index mod m) + 1, the node number value range is [1 ~ m]; Traverse each element OD in ODSet, and insert the partition and storage node corresponding to the OD into the global index, GIndexMap.insert(OD,(index,node)); Step 3.10: k=k+1, pointing to the next element in ODMap, go to Step 3.8; Step3.11: Return the global index GIndexMap and OD partition ODMap.

3. The subway ticket record storage and indexing method based on distributed secondary index according to claim 1 is characterized in that: The local index described in Step 4 is to build the local index in parallel on each storage node at the same time. The specific process is as follows: Step 4.1: Input OD set ODSet, subway station name set StationSet and time interval t; Step 4.2: Traverse each OD in ODSet and split each OD into two points, O and D. After the traversal is completed, all points form a point set PointSet; Step 4.3: Traverse each point in the point set PointSet, divide the points with the same site name into the same group, and save the divided point set in the following data structure: StationMap={(ID1,station1,Set1),( ID2,station2,Set2),…, ( ID N ,station N ,Set N )} (8); In formula (8), StationMap is the storage method after the point set is divided, ID i Indicates the number of the subway station, station i Indicates the name of the subway station, Set i Represents the set of all ticket records generated by the subway station; Step 4.4: Initialize the variable i to 1, traverse each member in StationMap, and compare the size relationship between i and StationMap.len; If i is less than StationMap.len, select the current station and its corresponding point set currStation, currStation=StationMap (i); Otherwise, go to Step 4.11; Step 4.5: Get the point set Set corresponding to the current station currStation, and further divide the points in Set into segments according to the time interval t. The point set Set and the space-time points after segmentation are stored in a data structure as shown in formula (9): <h2 style=";text-align:left;direction:ltr">timeLMap = {(I1,tSeg1,n1,sSet1), (I2,tSeg2,n2,sSet2),…, (I<h2 style=";text-align:left;direction:ltr"> M <h2 style=";text-align:left;direction:ltr"> ,tSeg<h2 style=";text-align:left;direction:ltr"> M <h2 style=";text-align:left;direction:ltr"> ,n<h2 style=";text-align:left;direction:ltr"> M <h2 style=";text-align:left;direction:ltr"> sSet<h2 style=";text-align:left;direction:ltr"> M <h2 style=";text-align:left;direction:ltr"> )}(9)); In formula (9), I represents the time period number, tSeg represents the time period name, n represents the number of ticket records generated within the time period, and sSet represents the set of all ticket records generated within the time period, which is a subset of Set. Step 4.6: Initialize the variable j to 1, traverse each member in timeLMap, and determine the size relationship between j and timeLMap.len; If j is less than or equal to timeLMap.len, select the current time segment currSeg, currSeg=timeLMap(j); Otherwise, go to Step 4.11; Step 4.7: Further divide the sSet in the current currSeg into OSet and DSet, where OSet represents the entry set and DSet represents the battle set; Step 4.8: Sort the points in OSet and DSet by time respectively; Step 4.9: The value of variable j increases by 1, j=j+1, pointing to the next member of the current currSeg, and go to Step 4.6; Step 4.10: The value of variable i increases by 1, i=i+1, pointing to the next member of the current currStation, and go to Step 4.4; Step 4.11: Return to StationMap. At this time, the StationMap divided layer by layer is the local index.

4. The subway ticket record storage and indexing method based on distributed secondary index according to claim 1 is characterized in that: Step 7 describes the calculation of the distribution characteristics of the passenger trajectory in the cluster based on the query trajectory. The specific process is as follows: Assume the query trajectory TR = (OD1, OD2, OD3, …, ODn), there are common repeated ODs in the OD sequence corresponding to this trajectory; The distribution characteristic calculation process is as follows: Step7.1.1: Given the query trajectory TR=(OD1, OD2, OD3, …, ODn); Step 7.1.2: Traverse the OD sequence in TR, count the number of each OD, sort in descending order by the number of times OD appears, and save the results in the following data structure: countMap={(OD1, N1),( OD2, N2)),…,( ODh,Nh)} (10); In formula (10), OD1~ODh are all different ODs without repetition, Ni represents the number of occurrences of ODi, and the cumulative sum of the number is n, where N1 is the largest and Nh is the smallest; Step 7.1.3: Traverse countMap, count the percentage of each OD in the trajectory length, and save the result in the following data structure: percentMap={(OD1, W1),( OD2, W2)),…,( ODh,Wh)} (11); In formula (11), Wi represents the percentage of the number of ODi occurrences in the trajectory length, and the calculation formula is Wi = (Ni / n), with a value between 0 and 1; the cumulative sum of W1~Wh is 1; Step 7.1.4: Traverse percentMap, use the global index to calculate the storage node corresponding to each OD, and save the result in the following data structure: NodeMap={(Node1, W1),(Node2, W2)),…,(Nodeh,Wh)} (12); In formula (12), Nodei represents the node stored in ODi, and the calculation formula is Wi = (Ni / n), which takes a value between 0 and 1; the cumulative sum of W1~Wh is 1; The calculation function that defines the distribution characteristics is: distVector=getVectorByTR(TR)(13); In formula (13), TR is the query trajectory, distVector is the distribution feature, and the type of distVector is the data structure described in formula (12).

5. The subway ticket record storage and indexing method based on distributed secondary index according to claim 4 is characterized in that: The optimal search solution described in Step 7 is as follows: Step7.2.1: Given the query trajectory distribution feature distVector; distVector={(Node1, W1),(Node2, W2)),…,(Nodeh,Wh)}; Among them, Wi represents the percentage of the number of ODi occurrences in the trajectory length, and Nodei represents the node stored in ODi; Initialize the key-value structure kvMap(solution,cost) to store the search solution and its corresponding time cost; Step7.2.2: Traverse the distribution features and obtain the node set NodeSet={Node1, Node2, … , Nodeh}; Step 7.2.3: Based on NodeSet, use the exhaustive method to list each search solution. All search solutions are stored in the following data structure: solSet=(sol1, sol2, sol3, … ,soly)(18); In formula (18), solSet is a search solution set, each element is a search solution, and there are y different search solutions in the search solution set; Step7.2.4: Initialize the variable z to 1 and traverse the search solution set solSet; Step 7.2.5: Compare the size relationship between z and solSet.len; If z is less than or equal to solSet.len, get the current search solution currSol, currSol=solSet(z); Otherwise, go to Step 7.2.9; Step 7.2.6: Calculate the time cost corresponding to the current search solution and save it in the variable currCost, currCost = getCost (distVector, currSol, C1, C2, C3); C1 represents the local computing cost, C2 represents the data transmission cost in the network, and C3 represents the cost of multi-node synchronization in a distributed environment; Step7.2.7: Insert the current search scheme and the corresponding time into kvMap; kvMap.insert(currSol, currCost); Step7.2.8: Increase the variable z by 1, z=z+1, and go to Step7.2.5; Step 7.2.9: Find the minimum time cost in kvMap: minCost = kvMap.getMinValue(); Step7.2.10: Use the minimum time cost to obtain the optimal search solution: optSol = kvMap.get(minCost); Step7.2.11: Return the optimal search solution optSol.

6. The subway ticket record storage and indexing method based on distributed secondary index according to claim 1 is characterized in that: The query interface in Step 6 is specifically: resList=distributedSearch (oTR, simfunc, threshold, filterfun,N) (20); In formula (20), oTR is a trajectory, which consists of a set of OD sequences, specifically (id, OD1, OD2, ... ,ODn); simfunc is a trajectory similarity measurement function used to calculate the similarity between the candidate trajectory and oTR; threshold is a similarity threshold, ranging from 0 to 1; filterfun is a filter function used to filter the trajectories that do not meet the query conditions in the candidate trajectory set; N is a positive integer that determines the number of return trajectories; resList is used to save the results of function execution and is a collection of trajectories.

7. The subway ticket record storage and indexing method based on distributed secondary index according to claim 5 is characterized in that: Step 8 describes the optimal search solution in a distributed environment. The specific process is as follows: Step8.1: Given the target trajectory oTR, the number of ODs in oTR is n; Given a similarity measurement function simfunc, a similarity threshold threshold, a filter function filterfun and a return quantity N; Step 8.2: Based on oTR as input, obtain the distribution characteristics of the trajectory: disVector = getVectorByTR(oTR) Step 8.3: Get the optimal search solution: optSol=getOptimalSolution(disVector) Step 8.4: Initialize the distributed task queue distributedTaskQueue and the distributed synchronization tool distributedBarrier; The distributed task queue distributedTaskQueue is used to store tasks to be calculated; The distributed synchronization tool distributedBarrier is used to provide task synchronization function in a distributed environment and control rounds to be executed in sequence; Step8.5: Serialize the optimal search strategy optSol, target trajectory oTR, similarity measurement function simfunc, similarity threshold threshold, filter function filterfun and return quantity N into a message solMessage; Step 8.6: Submit the message solMessage to the distributed queue: distributedTaskQueue.submit(solMessage) Step8.7: Initialize the variable loop to 1 to control the execution of the optimal search strategy optSol; Step 8.8: Compare the size relationship between loop and optSol.len; If loop is less than or equal to optSol.len, get the current round currRound=optSol(loop); Otherwise, go to Step 8.14; Step 8.9: Get all participating nodes in currRound, save them in NodeList, and notify all nodes in NodeList to get the currRound of the current round; Step8.10: Determine the value of loop. If loop is equal to 1, execute step Step8.11.1; Otherwise, execute Step 8.11.2; Step 8.11.1: Each node obtains currRound information, parses the computing tasks involved in this node, extracts and merges data from the local index, saves the result to the candidate trajectory segment canSegSet, and sends the result to the successor node through the network; Step 8.11.2: Each node obtains currRound information, parses the computing tasks involved in this node, receives canSegSet sent by other nodes, merges them locally, and forms a new canSegSet; Step8.12: Global synchronization waits for all tasks in the same round to finish, distributedBarrier.wait(); Step8.13: Increase the variable loop by 1, loop=loop+1, go to Step8.8; Step8.14: Receive canSegSet sent by all nodes at the aggregation node and generate the candidate trajectory set canTRSet; Step8.15: Return the candidate trajectory set canTRSet.

8. The method for storing and indexing subway ticket records based on distributed secondary indexes according to claim 1, characterized in that: The execution process of the filtering strategy described in Step 9 is as follows: The filter function runs after the last round. The form of the filter function is as follows: resTRSet=filterfunc (canTRSet, simfunc, N) (21); In formula (21), canTRSet is the candidate trajectory set generated in the last round, simfunc is the trajectory similarity measurement function, and N is the number of trajectories that should be returned; The specific implementation process is as follows: Step9.1: Input the candidate trajectory set canTRSet, the similarity measurement function simfunc and the number of trajectories N; Step 9.2: Initialize the key-value pair data structure kvMap<TR,score> , used to save the similarity scores of candidate trajectories; Step 9.3: Initialize variable i to 1 and traverse each member in canTRSet; Step 9.4: Determine the relationship between i and canTRSet.len. If i is less than canTRSet.len, select the current trajectory currTR=canTRSet(i); otherwise, go to Step 9.7; Step 9.5: Calculate the similarity between currTR and oTR: socre = simfunc (oTR, currTR); Save the calculation results to kvMap, kvMap.insert(currTR, score); Step 9.6: Increase the variable i by 1, i=i+1, and go to Step 9.4; Step 9.7: Sort kvMap by similarity score and save the sorted results, sortedTRList = kvMap.sortByScore; Step 9.8: Select the first N trajectories and save them in the result set resTRSet, resTRSet = sortedTRList(N); Step E: Return resTRSet, end.

Citation Information

Patent Citations

  • A subway passenger trajectory similarity search method based on multi-path merging

    CN115344795B

  • Subway passenger track similarity search method based on multi-path merging

    CN115344795A

  • Method and apparatus for tracking objects over a wide area using a network of stereo sensors

    US20080101652A1