Uploaded by Inara Zahin Hassan ,160041055

Fariha-Ishrat-Rahman-160041069-AE Sep29-1 - Copy

advertisement
Fariha Ishrat Rahman, 160041069, Group 2B
Travelling from A to B
Approach 1: Greedy
One of the approaches to solve this problem is through a greedy algorithm. Let us assume the
limiting factor is the financial cost. So, for every point, we choose the next location such as to
minimise this cost. However, we only account for the next successive point instead of
considering all future points.
We start at A, the next possible locations are C,D,E with cost 10,2,15 respectively. So, we pick
the path with the minimum cost, i.e D. This step is repeated until we reach the destination. The
resulting path is A -> D -> F -> B with a cost of 26.
Advantage:
● Computation is very fast since we do not traverse through all possible paths.
Disadvantage:
● Does not produce the optimal solution.
● Only takes the financial cost into account and not other factors
Adjusting cost for better representation
In real-life scenarios, the financial cost isn’t the only factor that needs to be taken into
consideration. Other factors such as time, convenience of travel, accommodation etc also need
to be considered. So, a better representation of the cost can be given by the weighted sum of
these factors, where f denotes the factors and w denotes the weight coefficients.
Approach 2: Dijkstra
Previously, when we had applied the greedy algorithm, we had only considered the next
successive points, instead of taking all the nodes into account. This resulted in a non-optimal
solution. Hence, we choose to apply dijkstra to traverse through all the nodes to find the optimal
solution. Here, ​the weight of the edges is considered to be the weighted sum of factors.
The algorithm is as follows:
● Let's create an array dist[] where for each vertex v we store the current length of the
shortest path from A to v in d[v]. Initially dist[s]=0, and for all other vertices this length
equals infinity.
dist[v] = ∞, v ≠ A
● In addition, we maintain a Boolean array u[] which stores for each vertex v whether it's
marked. Initially all vertices are unmarked:
u[v]=false
● The graph is iterated for the next n nodes, choosing the node with the smallest dist in
each step
● dist[] values are updated of adjacent nodes of the current node v as follows: for each
new adjacent node u
● if dist(v) + weight(u,v) < dist(u), there is a new minimal distance found for u, so update
dist(u) to the new minimal distance value
● otherwise, no updates are made to dist(u)
Using the dijkstra algorithm, we find the optimal path from A to B, which is A -> C -> F -> B.
Advantage:
● All nodes are traversed, so gives the optimal solution.
Disadvantage:
● Computationally very expensive since the entire graph is traversed.
Approach 3: A* ( Dijkstra + heuristics)
One of the major issues with dijkstra was that it was computationally expensive since it had to
traverse the entire graph. One of the ways to improve on this is through the A* algorithm. The
algorithm is an informed search algorithm that considers heuristics while making decisions.
Heuristics is an approximation of the cost from that specific node, so the cost function is given
by ​f(n) = g(n) + h(n) where h(n) is the heuristic measure and g(n) is the weight of the edge. In
this algorithm, if we encounter a path with an A* score that is greater, the path is ignored.
Hence, we do not have to traverse through all possible paths
Advantage:
● Faster than the Dijkstra since it does not traverse all possible paths
● Gives the optimal solution if the heuristics aren’t overestimated
Disadvantage:
● The weight of the edges are an estimation and may not accurately represent real world
value
Approach 4: Recommendation with collaborative filtering
A more applicable approach that caters to real world situations is to use previous user data to
give recommendation using collaborative filtering. Users can be classified into groups according
to their criteria. To make future recommendations, we use previous data from similar users. For
example, user X shows similarity to U3. From our data we see that U3 has travelled through C,D
and G, therefore, we can also suggest that user X takes the path CDG.
Download