3.1.1. Initialization Phase

The first phase of the algorithm concerns the initialization of data and it is divided into two parts. In the first part, the algorithm, by knowing the city map, creates the initial graphs of the city tourist attractions: a tourist attraction is associated with a node and all the nodes are connected to each other through indirect arcs. For each pair of nodes the time needed to go from one attraction to another is specified, on the basis of the transport means, with a weight associated with the arc that connects the nodes. In addition, the times to reach each attraction starting from the origin PoI and vice versa are also provided. In particular, two weighted graphs are initially considered, respectively named *Gi*,<sup>1</sup> and *Gi*,2, composed by the same nodes and arcs, i.e., *Vi*,<sup>1</sup> = *Vi*,<sup>2</sup> and *Ei*,<sup>1</sup> = *Ei*,2, where each node represents a PoI of the city, each arc indicates the connection between two nodes and the arc weight represent respectively the travel times by foot in *Gi*,<sup>1</sup> and by bus/metro in *Gi*,2. Considering two nodes *a* and *b* of *Gi*,2, here we assume that the trip from *a* to *b* is performed mainly by bus and/or metro, with the possibility that a short segmen<sup>t</sup> of this trip must be traveled by foot. Moreover, for each node of *Gi*,<sup>1</sup> and *Gi*,<sup>2</sup> we are assuming that the travel time to go from the origin PoI to the node is equal to the travel time to go from the node to the origin PoI. After that, the graph *Gi* = {*Vi*, *Ei*} is defined composed by the same nodes and arcs of *Gi*,<sup>1</sup> and *Gi*,2. On each arc of *Gi* the weight is set among the following three possibilities, based on the user preferences:


In addition, the resulting graph *Gi* also keeps track of the transport means used on each trip segment, i.e., by foot or by bus/metro.

In the second part of the initialization phase, the tourist sets the following preferences:



#### 3.1.2. Itinerary Planning Phase

On the basis of the input from the initialization phase, the Algorithm 1 proceeds with the construction of two separate graphs *Go* and *Gr* to determine the *outward* and *return* paths, respectively. The graph *Go* and *Gr* are composed by the nodes *v* ∈ *Vo* and *v* ∈ *Vr*, respectively. Moreover, the graphs *Go* and *Gr* are of order *No* (cardinality of *Vo*) and *Nr* (cardinality of *Vr*), respectively, and are implemented through the adjacency matrices. Since the graphs are not oriented, connected and complete, the adjacency matrices are symmetric with a null diagonal. We solve the TSP (2) for the graphs *Go* and *Gr*, respectively, in order to find the minimum path *Po* and *Pr* and the associated travel time cost *t*1 and *t*2. Now, let us define the following integer linear programming problem ILP1 in order to maximize the available travel times for the outward and return paths:

$$F(\lambda) = \max \lambda$$

*λ*

$$s.t.$$

$$\begin{cases} \lambda \le t' = t\_1' - t\_o & \text{(3a)}\\ \lambda \le t'' = t\_1'' - t\_r & \text{(3b)}\\ t\_1' = t\_1 + t\_{stop}(P\_o) + y\_1 \ast t\_{stop,s} + y\_2 \ast t\_{stop,c} + t\_p & \text{(3c)}\\ t\_2'' = t\_2 + t\_{stop}(P\_r) + y\_3 \ast t\_{stop,s} + y\_4 \ast t\_{stop,c} + t\_p & \text{(3d)}\\ y\_1 + y\_3 = 1 & \text{(3e)}\\ y\_2 + y\_4 = 1 & \text{(3f)}\\ \lambda \in \mathcal{R} \\ y\_1, y\_2, y\_3, y\_4 \in \{0, 1\} \end{cases} \tag{3g}$$

$$
\lambda \le \mathfrak{t}'' = \mathfrak{t}''\_1 - \mathfrak{t}\_1 \tag{3b}
$$

$$\left| t\_1' = t\_1 + t\_{stop}(P\_o) + \mathcal{y}\_1 \* t\_{stop,s} + \mathcal{y}\_2 \* t\_{stop,c} + t\_p \right| \tag{3c}$$

$$\left|t\right|\_{2}^{''} = t\_{2} + t\_{stop}(P\_{r}) + y\_{3} \* t\_{stop,\*} + y\_{4} \* t\_{stop,\*} + t\_{p} \tag{3d}$$

$$\left[y\_1 + y\_3 = 1\right] \tag{3e}$$

$$y\_2 + y\_4 = 1\tag{3f}$$

$$
\mathbf{g} \in \mathcal{R} \tag{3g}
$$

$$\{y\_1, y\_2, y\_3, y\_4 \in \{0, 1\}\}\tag{3h}$$

where *λ* is the real decision variable that has to be maximized in order to maximize the difference between the effective travel times *t*1 and *t*2 and the respective available times *to* and *tr*. Let us specify that for the outward path *Po*, the source PoI is set as the initial node while the destination PoI as the final node. On the contrary, for the return journey *Pr* the destination PoI is set as the initial node and the source PoI as the final node. Moreover, with constraints (3c) and (3d) ILP1 takes into account the following variables: the sum of the stop time period at each PoI of *Po* and *Pr*, respectively called *tstop*(*Po*) and *tstop*(*Pr*); the time period *tp* to reach the origin PoI from the final point; the stop time period for visiting the source and destination nodes denoted respectively by *tstop*,*<sup>s</sup>* and *tstop*,*e*. In particular, constraints, (3c), (3d), (3e) and (3f) are introduced to ensure that the source and end PoI can be visited only one time respectively on the outward or on the return journey. More

precisely, constraint (3e) states that if the tourist stops for visiting the source PoI on the outward path, he/she will not repeat the visit on the return path: on the return path, the tourist will just pass through the source PoI without stopping there. The same statement of (3e) is done for the end/destination PoI by applying constraint (3f).

The resulting paths *Po* and *Pr* are not definitive and a further analysis is required to satisfy the tourist preferences.

The travel times *t*1 and *t*2, must not exceed the time available for visiting *to* and *tr*, respectively. Consequently, the following algorithms will manage the itinerary by adding and/or removing none, one or more PoI (nodes) from the path *Po* and/or *Pr* so that the time constraints are respected. Now, considering that *to* and *tr* are the available travel times to complete the outward and return journeys, respectively, two cases which needs to be managed can arise:


In particular, the managemen<sup>t</sup> of case 1 is performed by Algorithm 1.1 and Algorithm 1.2, respectively described by the UML diagrams in Figures 3 and 4, while case 2 is managed through Algorithm 1.3 described by the UML diagram of Figure 5 in the following. At the end of Algorithm 1.1 and Algorithm 1.3, Algorithm 1 displays the final itinerary to the tourist.

#### Algorithm 1.1: PoI Exchange Procedure

In case 1, it is necessary to manipulate the outward and return paths, *Po* and *Pr*, in order to respect the time constraints, to avoid delay in the origin PoI. An attempt is made to keep all the PoI of high priority by exchanging nodes between those selected for the outward and the return journeys. To this aim, a node belonging to the outward graph *Go* is exchanged with a node belonging to the return graph *Gr*. Once the exchange has been made, the Algorithm 1.1 determines the new paths *Po* and *Pr* and the travel time *t*1 and *t*2 by applying ILP1. Afterwards, it checks if the times *t* and *t* are positive or negative and one of the two cases can occur, as highlighted in Figure 3.

If case 1 occurs, Algorithm 1.1 updates the table *FS* of feasible solutions, i.e., records the paths *Po* and *Pr* obtained by feasible nodes exchange. Afterwards, all the possible nodes exchange are tried between the two graphs (see Figure 3) and all the feasible solutions are recorded in Table *FS*. If case 2 occurs the Algorithm 1.1 ignores the obtained solution beacuse it is not feasible and proceeds with the node exchange procedure until other combinations are no longer possible.

After all possible nodes exchange have been made, the Algorithm 1.1 checks if suitable solutions have been found. If table *FS* is not empty, Algorithm 1.1 asks the tourist to indicate one of the solution in table *FS* and Algorithm 1.1 goes to Algorithm 1.3. On the contrary, if table *FS* is empty, i.e., no feasible node exchange are possible, Algorithm 1.1 goes to Algorithm 1.2 to start the node deleting procedure.

**Figure 3.** The UML diagram for the node exchange procedure.

Algorithm 1.2: PoI Deletion Procedure

Algorithm 1.2 starts the node deleting procedure (see UML diagram of Figure 4). If *t* > 0, a node is eliminated from *Go* and, in case *t* > 0, a node is simultaneously deleted from *Gr*. After that, Algorithm 1.2 computes *Po* and *t*1, *Pr*, *t*2 and, in particular, *t* and *t* by applying ILP1. Then, the algorithm checks if the time constraints on *t* and *t* are satisfied. These steps are repeated iteratively by Algorithm 1.2 until time constraints are not respected or no more node can be deleted. The Algorithm 1.2 displays an error message in case, after all possible nodes of *Go* or *Gr* have been deleted, it still holds *t* > 0 or *t* > 0, respectively. On the contrary, if *t* ≤ 0 and *t* ≤ 0, the PoI elimination is not necessary anymore and the Algorithm 1.2 goes to Algorithm 1.3 where the possible addition of other points is evaluated.

**Figure 4.** The UML diagram for the node deletion procedure.

Algorithm 1.3: PoI Addition Procedure

In the case *t* ≤ 0 and *t* ≤ 0, it is reasonable to add one or more nodes to the paths *Po* and *Pr*. Thus, a node *v* ∈ *Vs* with secondary priority is temporarily added to *Go* and *Gr*. Note that *Ns* is the cardinality of *Vs*. At this point, if condition *t* ≤ 0 and *t* ≤ 0 is still verified the Algorithm 1.3 proceeds by adding another node *v* ∈ *Vs*, until no more nodes *v* ∈ *Vs* can be added. On the other hand, if the addition of a node does not satisfy the time constraints, the added node is removed from the relative path and the Algorithm 1.3 checks whether it is possible to insert other nodes by repeating the operation until all nodes *v* ∈ *Vs* are examined (see the UML diagram in Figure 5).

**Figure 5.** The UML diagram for the node addition procedure.

#### **4. Complexity and Performance Analysis**

In this section, the analysis of the complexity and performance of the proposed algorithms are provided. The following results describe the algorithms complexity:


We can conclude that the complexity of the heuristic approach is *O*(*N* ∗ *<sup>K</sup>*). In order to be compliant with application time constraints, the TSP has been implemented using the Lin-Kernighan algorithm that often keeps its tours within 2% of the Held-Karp lower bound [48], then *K* = *<sup>O</sup>*(*N*2.2). Therefore, our heuristic approach shows complexity *<sup>O</sup>*(*N*3.2). Let us underline that the proposed application interacts with users to find the final best solution. Therefore, the time to complete the heuristic approach application and provide the final solution strongly depends on the velocity of the user given the necessary inputs to the application.

The performance of the proposed algorithms are validated with benchmark orienteering algorithms presented in [49]. In particular, the data set used in [49] and reported in [50] is used as benchmark (see Figure 6). Since, in the considered benchmark data set the PoI importance is defined by a score, we associate the priorities to the higher score values as reported in Figure 6. Note that in Figure 6, X and Y are the cartesian coordinates of the PoI and the PoIs distance is computed using the Euclidean distance formula [49]. Moreover, for comparison purpose, we assume that (i) the PoI *Vd* is selected as to minimize the total travel time, (ii) the Euclidean distance includes the stop time for visiting in our approach, (iii) the user preferences are randomly set in the instances simulation. Now, let us report the comparison results between the proposed heuristic and the D-algorithm and S-algorithm proposed by [49]. In particular, Figures 7–9 report respectively the comparison results considering data set of problem 1, 2 and 3, where Tmax represents the total travel time. Comparing the score and time values it can be concluded that the proposed approach performs much better than D-algorithm and little worse than the S-algorithm. However, in case only addition of PoI are needed by Algorithm 1.3, the proposed approach performs better than S-algorithm too. It is also remarked that the performance of Algorithm 1.2 can be further improved when a considerable number of PoIs must be deleted.


**Figure 6.** The benchmark data set.


**Figure 7.** Algorithms comparison using data set of problem 1.


**Figure 8.** Algorithms comparison using data set of problem 2.


**Figure 9.** Algorithms comparison using data set of problem 3.
