Disclosure of Invention
The invention provides a multi-transit point path planning method, a multi-transit point path planning system, electronic equipment and a storage medium, aiming at overcoming the defect that an accurate solution and a quick solution of multi-transit point path planning in the prior art cannot coexist.
The invention solves the technical problems through the following technical scheme:
a path planning method for multiple transit points is characterized by comprising the following steps:
acquiring a first set, wherein the first set comprises a starting point and at least two passing points;
inquiring a passing point with the shortest route from the current starting point;
saving a sub-path from the current starting point to the current route point obtained by query;
changing the passing point obtained by the current query into a starting point;
judging whether the first set comprises a passing point or not;
if yes, continuing to execute the step of inquiring the passing point with the shortest route from the current starting point;
if not, splicing the sub-paths according to the stored sequence to generate an optimal path;
wherein the current starting point is the latest starting point in the first set.
Preferably, the step of querying the route point with the shortest route from the current starting point includes:
adding the current starting point into the second set;
selecting the point with the minimum path cost in the second set as a transit point;
adding the current transit point into a third set, and deleting the current transit point from the second set;
judging whether the neighbor points of the current transit point are included in the third set;
if the current transit point is included in the third set, continuing to judge whether another adjacent point of the current transit point is included in the third set;
if not, judging whether the current adjacent point is included in the second set;
if the current path cost is included in the second set, recalculating the path cost of the current adjacent point;
if not, adding the current adjacent point into the second set, and calculating the path cost of the current adjacent point;
judging whether other adjacent points which are not judged exist in the current transit point;
if yes, continuously judging whether another adjacent point of the current transit point is included in the third set;
if not, continuing to execute the step of selecting the point with the minimum path cost in the second set as the transit point;
and for the point P in the second set, the path cost is the sum of the minimum value of the cost from the point P to each passing point and the cost from the point P to the first current starting point.
Preferably, after the step of adding the current transit point into the third set, the step of querying a route point with the shortest route from the current starting point further includes:
judging whether the current transit point is a passing point or not;
if yes, turning to the step of saving the sub-path from the current starting point to the current route point obtained by query;
if not, continuing to execute the step of judging whether the adjacent point of the current transfer point is included in the third set.
Preferably, the step of saving the sub-path from the current starting point to the route point obtained by the current query includes:
and connecting the points in the third set according to the adding sequence to generate the sub-path.
An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements any one of the above-mentioned multi-waypoint path planning methods when executing the computer program.
A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of any of the above-mentioned methods for path planning for multiple waypoints.
A multi-transit point path planning system, the path planning system comprising:
the device comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for acquiring a first set, and the first set comprises a starting point and at least two passing points;
the query module is used for querying a passing point with the shortest route away from the current starting point;
the storage module is used for storing sub-paths from the current starting point to the route point obtained by current query;
the changing module is used for changing the passing point obtained by the current query into a starting point;
the judging module is used for judging whether the first set comprises a passing point or not;
if yes, continuing to call the query module; if not, calling the splicing module;
the splicing module is used for splicing the sub-paths according to the stored sequence to generate an optimal path;
wherein the current starting point is the latest starting point in the first set.
Preferably, the query module comprises:
a first adding unit, configured to add the current starting point into the second set;
a selecting unit, configured to select a point in the second set with the smallest path cost as a transit point;
a second adding unit, configured to add the current transit point to the third set;
a deleting unit configured to delete the current transit point from the second set;
a first judgment unit configured to judge whether or not a neighboring point of the current transit point is included in the third set;
if the current transit point is included in the third set, calling the first judging unit to continuously judge whether another adjacent point of the current transit point is included in the third set;
if the current time is not included in the third set, calling a second judgment unit;
wherein the second judging unit is configured to judge whether a current neighboring point is included in the second set;
if the first adding unit is not included in the second set, calling a third adding unit and a calculating unit;
if the current time is included in the second set, the computing unit is called again;
wherein the third adding unit is configured to add a current neighboring point to the second set;
the calculating unit is used for calculating the path cost of the current adjacent point;
the third judging unit is used for judging whether other adjacent points which are not judged exist in the current transit point;
if yes, calling the first judging unit, and continuously judging whether another adjacent point of the current transit point is included in the third set;
if not, calling the selection unit;
and for the point P in the second set, the path cost is the sum of the minimum value of the cost from the point P to each passing point and the cost from the point P to the first current starting point.
Preferably, the query module further comprises:
a fourth judging unit, configured to judge whether the current transit point is a transit point;
if yes, calling the storage module;
if not, the first judgment unit is called.
Preferably, the storage module is configured to connect the points in the third set according to a joining sequence to generate a sub-path.
The positive progress effects of the invention are as follows: the invention starts from an initial starting point, inquires a passing point closest to the current starting point to obtain a sub-path, then takes the passing point obtained by inquiry as a new starting point, continuously inquires another passing point closest to the passing point to obtain another sub-path, and continuously circulates the process until all the passing points are inquired.
Detailed Description
The invention is further illustrated by the following examples, which are not intended to limit the scope of the invention.
Example 1
The present embodiment provides a path planning method for multiple transit points, and fig. 1 shows a flowchart of the present embodiment. Referring to fig. 1, the path planning method of the present embodiment includes:
and S1, acquiring the first set.
In this embodiment, the first set includes, but is not limited to, representations of lists, where the first set includes a starting point and at least two passing points, and in this embodiment, the current starting point is the latest starting point in the first set, that is, when only one starting point is included in the first set, the only starting point is the current starting point.
And S2, inquiring the passing point with the shortest path from the current starting point.
Fig. 2 shows a flowchart of step S2, specifically, step S2 includes:
s201, adding the current starting point into a second set;
s202, selecting a point with the minimum path cost in the second set as a transit point;
s203, adding the current transfer point into a third set, and deleting the current transfer point from the second set;
s204, judging whether the current transit point is a passing point or not;
if yes, go to step S3; if not, go to step S205;
s205, judging whether the adjacent points of the current transit point are included in the third set;
if yes, another neighboring point is selected to continue to perform step S205; if not, go to step S206;
s206, judging whether the current adjacent point is included in the second set;
if yes, go to step S207; if not, go to step S208;
s207, recalculating the path cost of the current adjacent point, and turning to the step S209;
s208, adding the current adjacent point into the second set, calculating the path cost of the current adjacent point, and turning to the step S209;
s209, judging whether other adjacent points which are not judged exist in the current transit point;
if yes, another neighboring point is selected to continue to perform step S205; if not, the step S202 is continued.
In the present embodiment, when the determinations of step S205 and step S209 are yes, the execution of step S205 is continued with the aim of determining whether another neighboring point of the current transit point is included in the third set.
Specifically, in the present embodiment, referring to fig. 3, the first set includes the start point S0Passing point M1、M2At this time, the starting point S0I.e. the current starting point. The current starting point S0Adding a second set, wherein the second set only comprises the current starting point S0And then, without calculation, the current starting point S0That is, the point with the minimum path cost in the second set is selected as the current starting point S0Is the transit point. The current transit point S0Adding the third set and deleting the current transit point S from the second set0At this time, only the current transit point S is included in the third set0The second set does not include any point, and thus, step S204, step S205 and step S206 are both determined to be no. In this embodiment, the points that are not obstacles and are away from the transit point by the unit length can be made to be adjacent points, and then, for the current transit point S0Current neighbor point P ofiI can take the values 1, 2, 3, 4. The current adjacent point P1Add the second set and calculate P1The path cost of (2). Suppose that the current transit point S0Also includes neighboring points P2、P3、P4Furthermore, when step S202 is executed continuously, the second set includes neighboring points P for which the path cost has been calculated1、P2、P3、P4The third set including a starting point S0。
Continuing to step S202, assume neighboring point P2When the path cost is the minimum, P is selected2Is the transit point. The current transit point P2Adding the third set and deleting the current transit point P from the second set2At this time, the third set includes the start point S0And a neutral point P2The second set comprising P1、P3、P4. For the current transit point P2Adjacent point P of5Which are not route points and are not included in either the third set or the second set, a current neighboring point P is included5Add the second set and calculate P5The path cost of (2). The current transit point P due to the presence of an obstacle (shaded portion in the figure)2Also includes neighboring points S0、P6Returning to step S205, the determination is continued. For adjacent points S0Since the third set includes S0Returning to step S205 to continue judging neighboring point P6. For adjacent point P6Which are not route points and are not included in either the third set or the second set, a current neighboring point P is included6Add the second set and calculate P6The path cost of (2). To this end, the second set comprises neighboring points P for which the path cost has been calculated1、P3、P4、P5、P6The third set including a starting point S0And a neutral point P2。
Continue to holdStep S202, assume neighboring point P6When the path cost is the minimum, P is selected6Is the transit point. The current transit point P6Adding the third set and deleting the current transit point P from the second set6At this time, the third set includes the start point S0And a neutral point P2、P6P is included in the second set1、P3、P4、P5. For the current transit point P6Adjacent point P of3If it is not a waypoint and is not included in the third set but is included in the second set, then P is recalculated3The path cost of (2).
In this embodiment, for the point P in the second set, the path cost is the sum of the minimum value of the cost from the point P to each passing point and the cost from the point P to the first current starting point. For example, for P3The precursor of which is initially S0Then, P is estimated separately3To a passing point M1And M2Taking the minimum value of (1) and P3To the starting point S0(S0→P3) The sum of the costs of (a) is the path cost; and, P for the recomputed path cost3Its precursor is changed to P6Taking P3To a passing point M1And M2Is compared with the minimum value of the cost to the starting point S0(S0→P2→P6→P3) The sum of the costs of (a) is the path cost.
The above steps are continuously executed until step S204 determines that the current transit point is a transit point, that is, a transit point with the shortest route from the current starting point is found, and step S3 is executed.
And S3, saving the sub-path from the current starting point to the route point obtained by the current query.
Suppose that, in the present embodiment, the first query results in being the passing point M1Then save from the starting point S0To a passing point M1Is used to determine the sub-path of (1). Specifically, in this embodiment, the points in the third set are connected according to the adding sequence to generate the sub-path, that is, the sub-path is S0→P2→P6→P3→……→M1。
And S4, changing the route point obtained by the current query into a starting point.
At this time, the passing point M1Change to the starting point S1Thus, the first set includes the start point S0、S1And a passing point M2。
At the passing point M1Change to the starting point S1Previously, step S4 may further include: deleting the current starting point, and the first set comprises the starting point S1And a passing point M2At this time, the latest starting point in the first set is still S1。
S5, judging whether the first set comprises a passing point or not;
if yes, go to step S2; if not, go to step S6;
and S6, splicing the sub-paths according to the stored sequence to generate the optimal path.
When the first set includes the starting point S0、S1And a passing point M2If yes, step S5 continues to execute step S2 until the passing point M is inquired2Saving from the starting point S1To a passing point M2Is used to determine the sub-path of (1). Finally, in step S6, the sub-paths are spliced according to the stored sequence, and in this embodiment, the finally generated optimal path is S0→P2→P6→P3→……→M1→……→M2。
In this embodiment, a route point closest to the current starting point is queried from the initial starting point to obtain a sub-route, the route point obtained through the query is taken as a new starting point, another route point closest to the route point is continuously queried to obtain another sub-route, and the above process is continuously circulated until all the route points are queried.
Example 2
The present embodiment provides an electronic device, which may be represented in the form of a computing device (for example, may be a server device), and includes a memory, a processor, and a computer program stored in the memory and running on the processor, where the processor, when executing the computer program, may implement the multi-transit-point path planning method provided in embodiment 1.
Fig. 4 shows a schematic diagram of a hardware structure of the present embodiment, and as shown in fig. 4, the electronic device 9 specifically includes:
at least one processor 91, at least one memory 92, and a bus 93 for connecting the various system components (including the processor 91 and the memory 92), wherein:
the bus 93 includes a data bus, an address bus, and a control bus.
Memory 92 includes volatile memory, such as Random Access Memory (RAM)921 and/or cache memory 922, and can further include Read Only Memory (ROM) 923.
Memory 92 also includes a program/utility 925 having a set (at least one) of program modules 924, such program modules 924 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
The processor 91 executes various functional applications and data processing, such as the multi-transit point path planning method provided in embodiment 1 of the present invention, by executing the computer program stored in the memory 92.
The electronic device 9 may further communicate with one or more external devices 94 (e.g., a keyboard, a pointing device, etc.). Such communication may be through an input/output (I/O) interface 95. Also, the electronic device 9 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the Internet) via the network adapter 96. The network adapter 96 communicates with the other modules of the electronic device 9 via the bus 93. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the electronic device 9, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.
It should be noted that although in the above detailed description several units/modules or sub-units/modules of the electronic device are mentioned, such a division is merely exemplary and not mandatory. Indeed, the features and functionality of two or more of the units/modules described above may be embodied in one unit/module, according to embodiments of the application. Conversely, the features and functions of one unit/module described above may be further divided into embodiments by a plurality of units/modules.
Example 3
The present embodiment provides a computer-readable storage medium on which a computer program is stored, which when executed by a processor implements the steps of the multi-transit point path planning method provided in embodiment 1.
More specific examples, among others, that the readable storage medium may employ may include, but are not limited to: a portable disk, a hard disk, random access memory, read only memory, erasable programmable read only memory, optical storage device, magnetic storage device, or any suitable combination of the foregoing.
In a possible implementation, the present invention can also be implemented in the form of a program product including program code for causing a terminal device to perform the steps of implementing the path planning method for multi-transit points in embodiment 1 when the program product is run on the terminal device.
Where program code for carrying out the invention is written in any combination of one or more programming languages, the program code may be executed entirely on the user device, partly on the user device, as a stand-alone software package, partly on the user device and partly on a remote device or entirely on the remote device.
Example 4
The present embodiment provides a path planning system with multiple transit points, and fig. 5 shows a module diagram of the present embodiment. Referring to fig. 5, the path planning system of the present embodiment includes:
an obtaining module 1, configured to obtain the first set. In this embodiment, the first set includes, but is not limited to, representations of lists, where the first set includes a starting point and at least two passing points, and in this embodiment, the current starting point is the latest starting point in the first set, that is, when only one starting point is included in the first set, the only starting point is the current starting point.
And the query module 2 is used for querying the passing point with the shortest path from the current starting point. Referring to fig. 5, the query module 2 specifically includes:
a first adding unit 201, configured to add the current starting point to the second set.
A selecting unit 202, configured to select a point in the second set with the smallest path cost as a transit point.
A second adding unit 203, configured to add the current transit point to the third set.
A deleting unit 204, configured to delete the current transit point from the second set.
A fourth judging unit 210, configured to judge whether the current transit point is a transit point; if yes, calling a storage module 3; if not, the first determination unit 205 is invoked.
A first judging unit 205 configured to judge whether or not a neighboring point of the current transit point is included in the third set; if yes, the first determining unit 205 is invoked to continue to determine whether another neighboring point of the current transit point is included in the third set; if not, the second determination unit 206 is invoked.
The second judging unit 206 is configured to judge whether the current neighboring point is included in the second set;
if not, a third adding unit 207 and a calculating unit 208 are called; if so, the calculation unit 208 is recalled.
The third adding unit 207 is configured to add the current neighboring point to the second set.
The calculating unit 208 is configured to calculate a path cost of the current neighboring point. The computation unit 208 is called again, that is, the path cost of the current neighboring point is recalculated.
A third determining unit 209, configured to determine whether there are other neighboring points that are not determined at the current transit point; if yes, the first determining unit 205 is invoked to continue to determine whether another neighboring point of the current transit point is included in the third set; if not, the selection unit 202 is invoked.
In this embodiment, a schematic diagram of the query module 2 querying a passing point with the shortest route from the current starting point is also shown in fig. 3, and specifically, the first set obtained by the obtaining module 1 includes the starting point S0Passing point M1、M2At this time, the starting point S0I.e. the current starting point. The first joining unit 201 joins the current start point S0Adding a second set, wherein the second set only comprises the current starting point S0And then, without calculation, the current starting point S0That is, the point with the minimum path cost in the second set, the selection unit 202 selects the current starting point S0Is the transit point. The second adding unit 203 adds the current transfer point S0The third set is added and the deletion unit 204 deletes the current transit point S from the second set0At this time, only the current transit point S is included in the third set0The second set does not include any point, and thus the fourth judging unit 210, the first judging unit 205, and the second judging unit 206 judge no. In this embodiment, the points that are not obstacles and are away from the transit point by the unit length can be made to be adjacent points, and then, for the current transit point S0Current neighbor point P ofiI can take the values 1, 2, 3, 4. The third adding unit 207 adds the current neighboring point P1Join the second set and the calculation unit 208 calculates P1The path cost of (2). Suppose that the current transit point S0Also includes neighboring points P2、P3、P4Furthermore, when the selection unit 202 is continuously invoked, the second set includes neighboring points P for which the path cost has been calculated1、P2、P3、P4The third set including a starting point S0。
The selection unit 202 is invoked continuously, assuming the neighboring point P2Has the smallest path cost, the selection unit 202 selects P2Is the transit point. The second adding unit 203 will beFront middle turning point P2The third set is added and the deletion unit 204 deletes the current transit point P from the second set2At this time, the third set includes the start point S0And a neutral point P2The second set comprising P1、P3、P4. For the current transit point P2Adjacent point P of5Which is not a route point and is included in neither the third nor the second set, the third adding unit 207 adds the current neighboring point P to the second set5Join the second set and the calculation unit 208 calculates P5The path cost of (2). The current transit point P due to the presence of an obstacle (shaded portion in the figure)2Also includes neighboring points S0、P6The first judgment unit 205 is invoked to continue the judgment. For adjacent points S0Since the third set includes S0Invoking the first determining unit 205 to continue determining the neighboring point P6. For adjacent point P6Which is not a route point and is included in neither the third nor the second set, the third adding unit 207 adds the current neighboring point P to the second set6Join the second set and the calculation unit 208 calculates P6The path cost of (2). To this end, the second set comprises neighboring points P for which the path cost has been calculated1、P3、P4、P5、P6The third set including a starting point S0And a neutral point P2。
The selection unit 202 is invoked continuously, assuming the neighboring point P6Has the smallest path cost, the selection unit 202 selects P6Is the transit point. The second adding unit 203 adds the current transit point P6The third set is added and the deletion unit 204 deletes the current transit point P from the second set6At this time, the third set includes the start point S0And a neutral point P2、P6P is included in the second set1、P3、P4、P5. For the current transit point P6Adjacent point P of3If it is not a passing point and is not included in the third set but is included in the second set, the calculation unit 208 recalculates P3The path cost of (2).
In this embodiment, for the point P in the second set, the path cost is the sum of the minimum value of the cost from the point P to each passing point and the cost from the point P to the first current starting point. For example, for P3The precursor of which is initially S0Then, P is estimated separately3To a passing point M1And M2Taking the minimum value of (1) and P3To the starting point S0(S0→P3) The sum of the costs of (a) is the path cost; and, P for the recomputed path cost3Its precursor is changed to P6Taking P3To a passing point M1And M2Is compared with the minimum value of the cost to the starting point S0(S0→P2→P6→P3) The sum of the costs of (a) is the path cost.
The above units are continuously called until the fourth judging unit 210 judges that the current transit point is a passing point, that is, a passing point with the shortest route from the current starting point is found, and the saving module 3 is called.
And the storage module 3 is used for storing the sub-path from the current starting point to the route point obtained by the current query. Suppose that, in the present embodiment, the first query results in being the passing point M1Then save from the starting point S0To a passing point M1Is used to determine the sub-path of (1). Specifically, in this embodiment, the points in the third set are connected according to the adding sequence to generate the sub-path, that is, the sub-path is S0→P2→P6→P3→……→M1。
And the changing module 4 is used for changing the passing point obtained by the current query into a starting point. At this time, the passing point M1Change to the starting point S1Thus, the first set includes the start point S0、S1And a passing point M2。
At the passing point M1Change to the starting point S1Before, the changing module 4 may be further configured to delete the current starting point, and the first set includes the starting point S1And a passing point M2At this time, the latest starting point in the first set is still S1。
A judging module 5, configured to judge whether the first set includes a passing point; if yes, continuing to call the query module 2; if not, the splicing module 6 is called.
And the splicing module 6 is used for splicing the sub-paths according to the stored sequence to generate an optimal path. When the first set includes the starting point S0、S1And a passing point M2If yes, the judging module 5 continues to call the query module 2 until the passing point M is queried2Saving from the starting point S1To a passing point M2Is used to determine the sub-path of (1). Finally, the splicing module 6 splices the sub-paths according to the stored sequence, in this embodiment, the finally generated optimal path is S0→P2→P6→P3→……→M1→……→M2。
In this embodiment, a route point closest to the current starting point is queried from the initial starting point to obtain a sub-route, the route point obtained through the query is taken as a new starting point, another route point closest to the route point is continuously queried to obtain another sub-route, and the above process is continuously circulated until all the route points are queried.
While specific embodiments of the invention have been described above, it will be appreciated by those skilled in the art that this is by way of example only, and that the scope of the invention is defined by the appended claims. Various changes and modifications to these embodiments may be made by those skilled in the art without departing from the spirit and scope of the invention, and these changes and modifications are within the scope of the invention.