Question

Write a program in a mall that will enable customers to reach the store they want to go to in the shortest way.

WhatsApp Image 2021-06-15 at 19.33.33.jpeg

Part A (70 points) :

Write a program in a mall that will enable customers to reach the store they want to go to in the

shortest way. The coordinates of the some important stores in the mall are given below :

 Cinema: (256.6, 92.3)

 Sport Center: (120.5, 5.5)

 Restaurant: (350.0, 165.5)

 Cafe: (102.3, 10.26)

 Bowling: (40.8, 72.35)

 Clothes Store: (92.5, 86.4)

 Toy Store: (90.5, 302.1)

Roads connect these locations as below:

Program stores the road network as an adjacency matrix. Locations will be seen as numbers when

the program is opened. The user enters the starting position and the arrival position. And the

program calculates the shortest path and displays visited places to the user with total distance.

- Use adjacency matrix

- Use an algorithm for shortest path and explain it (part b)

- Display visited places

- Display the distance

Part B (30 points) :

 Explain which algorithm you use to calculate shortest path and how its work. You can use

text document or write as a comment at least one paragraph.

Note : As long as you do what is asked, you are free in the general structure, architecture and

which algorithm used. You explained it with comments or in a text file.


0 0

> Bro first of all, thank you for your help. It gives errors because there are missing parts in the source code. Screenshots are not clear, so I couldn't fix it. Any chance you can share the source code again?

LeyAks Mon, Jun 21, 2021 12:43 PM

Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

The snapshots of the program source code and the output is provided below. The source code is provided at the end.

Note:-

1. To find the shortest path from the source node to the destination node, the dijkstra's algorithm has been used. In the Dijkstra's algorithm the program continuously updates the shortest path from the source node to the every node of the graph , until no more updations are possible. The "dijkstras()" function provided in the solution below , first determines the shortest distance and the shortest path from the source node to the destination node, and displays it in the console.

2. In the main function , the program prompts the user to enter the source and destination node, then the graph of the mall is created (in the form of adjacency matrix representation), and finally the "dijkstras()" function is called on this graph.

3. In the graph , the different locations in the mall are denoted by numbers from 0 to 6 and the order is similar to list of locations that is provided in the problem statement.

4. The distance between two nodes is calculated as the eucledian distance between the two nodes.

In case any problem is encountered while executing the program , inform in the comments.

1 2 3 4. 5 #include<bits/stdc++.h> using namespace std; // 0. Cinema: (256.6,92.3) // 1. Sport Center: (120.5,5.5) // 2. Rest

37 38 TERLER 39 40 . 41 pq.push({0,0}); int flag=0; while(!pq.empty()) { pair<double, int> p = pq.top(); pq.pop(); int n = p.

73 reverse(path.begin(),patn.end()); 74 76 cout<<The shortest path is : \n; cout<<pl[u]; for(auto x: path) {cout<<-><<p1[

110 111 adj_mat[3][5] = calc_dist(arr[3].first, arr[3].second, arr[5].first, arr[5].second); adj_mat[3][6] = calc_dist(arr[3]

Output:-

enter the source and destination node 05 The shortest distance to the destination node is equal to : 247.244 The shortest pat

Source code:-

#include
using namespace std;
// 0. Cinema: (256.6,92.3)
// 1. Sport Center: (120.5,5.5)
// 2. Restaurant: (350.0, 165.5)
// 3. Cafe: (102.3,10.26)
// 4. Bowling: (40.8,72.35)
// 5. Clothes Store: (92.5,86.4)
// 6. Toy Store: (90.5,302.1)

// function to calculate the eucledian distance between two nodes
string pl[7] = {"Cinema","Sport Center","Restaurant","Cafe","Bowling","Clothes Store","Toy Store"};
double calc_dist(double x,double y,double x1,double y1)
{
    return sqrt(pow(x1-x,2)+pow(y1-y,2));
}

// applying dijkstras algorithm to find the shortest path from source to destination node
void dijkstras(vector > adj,int u,int v) // u is source and v is destination 
{
    double dist[7]; // this array will store the shortest distance to any node i , from the source node
    int par[7]; // this array will store the parent to a node i 
    int vis[7]; // this array will be used to check if a node has been visited or not
    
    for(int i=0;i<7;i++)
    {
        dist[i] = INT_MAX;
        vis[i] = 0;
        par[i] = i;
    }
    priority_queue, vector > > pq;

    vis[u] = 0;
    dist[u] = 0;
    par[u] = u;

    pq.push({0,0});
    int flag=0;
    while(!pq.empty())
    {
        pair p = pq.top();
        pq.pop();
        int n = p.second;
        double d = p.first;
        flag =0;

        vis[n] =1;
        for(int i=0;i<7;i++)
        {
            if(adj[n][i]!=0.0)
            {
            double temp = (d+adj[n][i]);
            if((vis[i]==0 && dist[i]>temp))
            {
                dist[i]=(d+adj[n][i]);
                pq.push({dist[i],i});

                par[i] = n;
                flag=1;
            }
            }
        }
        if(flag==0)
        break;
    }

    cout<<"The shortest distance to the destination node is equal to : "< path; // vector to store the shortest path from source to destination

    while(v!=par[v])
    {path.push_back(v);v=par[v];}
    reverse(path.begin(),path.end());

    cout<<"The shortest path is : \n";
    cout<"< > adj_mat(7,vector(7,0.0)); //adjacency matrix representation of the graph

    vector > arr(7);
    arr[0] = {256.6,92.3};
    arr[1] = {120.5,5.5};
    arr[2] = {350.0,165.5};
    arr[3] = {120.3,10.26};
    arr[4] = {40.8,72.35};
    arr[5] = {92.5,86.4};
    arr[6] = {90.5,302.1};

    int u,v;
    cout<<"enter the source and destination node\n";
    cin>>u>>v;
    // adding the neighbours of node 0 to the graph
    adj_mat[0][1] = calc_dist(arr[0].first,arr[0].second,arr[1].first,arr[1].second);
    adj_mat[0][2] = calc_dist(arr[0].first,arr[0].second,arr[2].first,arr[2].second);

    // adding the neighbours of node 1 to the graph
    adj_mat[1][3] = calc_dist(arr[1].first,arr[1].second,arr[3].first,arr[3].second);
    adj_mat[1][0] = calc_dist(arr[1].first,arr[1].second,arr[0].first,arr[0].second);

    // adding the neighbours of node 2 to the graph
    adj_mat[2][3] = calc_dist(arr[2].first,arr[2].second,arr[3].first,arr[3].second);
    adj_mat[2][0] = calc_dist(arr[2].first,arr[2].second,arr[0].first,arr[0].second);

    // adding the neighbours of node 3 to the graph
    adj_mat[3][4] = calc_dist(arr[3].first,arr[3].second,arr[4].first,arr[4].second);
    adj_mat[3][5] = calc_dist(arr[3].first,arr[3].second,arr[5].first,arr[5].second);
    adj_mat[3][6] = calc_dist(arr[3].first,arr[3].second,arr[6].first,arr[6].second);
    adj_mat[3][1] = calc_dist(arr[3].first,arr[3].second,arr[1].first,arr[1].second);
    adj_mat[3][2] = calc_dist(arr[3].first,arr[3].second,arr[2].first,arr[2].second);

    // adding the neighbours of node 4 to the graph
    adj_mat[4][3] = calc_dist(arr[4].first,arr[4].second,arr[3].first,arr[3].second);
    adj_mat[4][5] = calc_dist(arr[4].first,arr[4].second,arr[5].first,arr[5].second);

    // adding the neighbours of node 5 to the graph
    adj_mat[5][4] = calc_dist(arr[5].first,arr[5].second,arr[4].first,arr[4].second);
    adj_mat[5][3] = calc_dist(arr[5].first,arr[5].second,arr[3].first,arr[3].second);
    adj_mat[5][6] = calc_dist(arr[5].first,arr[5].second,arr[6].first,arr[6].second);

    // adding the neighbours of node 6 to the graph

    adj_mat[6][5] = calc_dist(arr[6].first,arr[6].second,arr[5].first,arr[5].second);
    adj_mat[6][3] = calc_dist(arr[6].first,arr[6].second,arr[3].first,arr[3].second);
    dijkstras(adj_mat,u,v);
}

> Bro first of all, thank you for your help. It gives errors because there are missing parts in the source code. Screenshots are not clear, so I couldn't fix it. Any chance you can share the source code again?

LeyAks Mon, Jun 21, 2021 12:45 PM

Add a comment
Know the answer?
Add Answer to:
Write a program in a mall that will enable customers to reach the store they want to go to in the shortest way.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Help. I need to write a small program that executes the following graph algorithms in any language: 1. All-Pairs Shortest Path (Floyd-Warshall). It must ask for the vertices and edges for the user to...

    Help. I need to write a small program that executes the following graph algorithms in any language: 1. All-Pairs Shortest Path (Floyd-Warshall). It must ask for the vertices and edges for the user to enter them. As an output, deploy the resulting matrix. This will be done only for directed graphs. 2. Kruskal or Prim algorithm whatever you want to do. It must ask for a graph and present it at the end. The minimum coating tree that results from...

  • In this question, we will think about how to answer shortest path problems where we have more than just a single sourc...

    In this question, we will think about how to answer shortest path problems where we have more than just a single source and destination. Answer each of the following in English (not code or pseudocode). Each subpart requires at most a few sentences to answer. Answers significantly longer than required will not receive full credit You are in charge of routing ambulances to emergency calls. You have k ambulances in your fleet that are parked at different locations, and you...

  • Instructions Write a program in Java that implements the A* algorithm to find a path from...

    Instructions Write a program in Java that implements the A* algorithm to find a path from any two given nodes. Problem Overview & Algorithm Description In a fully-observable environment where there are both pathable and blocked nodes, an agent must find a good path from their starting node to the goal node. The agent must use the A* algorithm to determine its path. For this program, you must use the Manhattan method for calculating the heuristic. Remember: your heuristic function...

  • Need a program in python. Asterix and Obelix want to store and process information about movies...

    Need a program in python. Asterix and Obelix want to store and process information about movies they are interested in. So, you have been commissioned to write a program in Python to automate this. Since they are not very computer literate, your program must be easy for them to use. They want to store the information in a comma separated text file. Using this they would need to generate a report – see all items AND show a bar chart...

  • Write a Java program which will store, manipulate, and print student registration information. As part of...

    Write a Java program which will store, manipulate, and print student registration information. As part of the solution, identify the following classes: Student Admissions. The class Student must have the following fields – Name, Address, Id number, Courses, and Date, where: Name is a user defined class comprising of at minimum first name and last name. Address is a user defined class comprising of fields - street, city, state, and zip code. Date is a predefined class in the java.util...

  • Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sale...

    Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sales people (SalesPerson.java) The information needed are: D Number integer Month 1 Sales Amount-Double Month 2 Sales Amount-Double Month 3 Sales Amount-Double Write a Java program that allows you to store the information of any salesperson up to 20 While the user...

  • Problem: Write a short C++ program that gets the side of a cube and the radius...

    Problem: Write a short C++ program that gets the side of a cube and the radius of a sphere from the keyboard and writes to a file the surfaces of these shapes.             ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79 points) Algorithm solution (in pseudocode): To accomplish this task, your program will have to take the following steps: 1. Declare a variable named outFile that represents an output stream. 2. Declare a...

  • This program will store a roster of most popular videos with kittens. The roster can include...

    This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...

  • Please write it in Java language 2. (Myinterface.java) The program description below was found waaaaay back...

    Please write it in Java language 2. (Myinterface.java) The program description below was found waaaaay back in the archives of the Equinox history database. It is the specification for a simply "computer store storefront". Even though computer stores are now extinct, you find the idea charming and decide to use the specification as inspiration to write an interface for one of the Equinox systems. Read carefully: write your own GUI for one of the Equinox systems, drawing inspiration from the...

  • ***** running late, mere 3 hours left for due time, please help ** #needed in c++...

    ***** running late, mere 3 hours left for due time, please help ** #needed in c++ #inputfile MinPath2.txt 0   SF 1   LA 2   DALLAS 3   CONCORD 4   PHOENIX 5   CHICAGO 6   ST LOUIS 7   BOSTON 8   NY 9   LONDON 10   PARIS 11   TOKYO 12   BANGKOK 13   MEXICO CITY 14   MONTREAL -1   0   1   40 0   2   100 0   4   130 0   8   200 0   9   800 0   10   900 1   2   50 1   3   80 1   4   70 1   8  ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT