2/26/2021 Project 2 https://canvas.pitt.edu/courses/81202/assignments/508595?module_item_id= XXXXXXXXXX/2 Project 2 Due Mar 11 by 12pm Points 100 Submitting a file upload File Types zip Available Feb...

1 answer below »
Please, do my project.Thank you


2/26/2021 Project 2 https://canvas.pitt.edu/courses/81202/assignments/508595?module_item_id=2021935 1/2 Project 2 Due Mar 11 by 12pm Points 100 Submitting a file upload File Types zip Available Feb 25 at 12pm - Mar 11 at 12pm 14 days Submit Assignment Your project will not be graded if You do not produce outputs for all the test cases by executing your source code Your source code is not included in the required extensions (*.c, *.cpp, *.java, or *.py) Your report (PDF file) does not include results for all test cases Your report is in some other format than PDF In this project you must design and implement two programs, one for Dijkstra’s algorithm and one Floyd’s algorithm, to compute all-pair shortest paths in any given graph. Each program must be implemented with two data structures for the adjacency matrix: a two-dimensional array and a linked list. This means you will have 4 programs: 2 for Dijkstra’s algorithm (one with a two-dimensional array and one with a linked list) and 2 for Floyd’s algorithm (one with a two-dimensional array and one with a linked list). Requirements In each program you must read the data from the 10 files (see Input Files at the end of this description) to create the adjacency matrix in a two-dimensional array or in a linked list. You must report on the performance and on the memory requirements of the 2 data structures. Performance is defined as the total time taken to construct the data structure and compute all-pair shortest paths. To measure performance, you must run your programs (Dijkstra’s and Floyd’s) for all the 10 input files and plot the running time for each input file. Note that you must create a total of 4 plots: 2 different algorithms and 2 different data structures. For the memory (space) usage, you can derive the information based on the data structures you used in your algorithm or report a summary statistics provided by your programming language tools, if available. Your programs must print the the results the routes in a sequence of nodes (intersections). However, given the large number of routes that can be computed in each input file, you will need to print only the results of the test cases (see below). Test Cases Once you implement each program and before you run your program on those 10 files, you must check to ensure that your programs produce correct routes. Run the program for Dijkstra’s algorithm and the 2/26/2021 Project 2 https://canvas.pitt.edu/courses/81202/assignments/508595?module_item_id=2021935 2/2 program for Floyd’s algorithm, with both data structures, for these test cases using Project2_Input-File3 data and print the route for each test case in a sequence of nodes (intersections). The test cases are in this file: Project 2_TestCases.pdf There are three test cases in this file, each for a shortest path between a pair of nodes. In the test cases file, the requested shortest path between two nodes, along with node addresses, are at the top and the computed shortest path is the sequence of nodes in the table. Note, all you need to check is to see if your algorithm produces the same node sequence for each test case (shortest path). The intersection names and the maps are for visualization only and you do not need to prepare (print) them. Submission Items Upload to Canvas a zip file with Four programs (source codes), 2 for Dijkstra's algorithm (2 data structures) and 2 for Floyd's algorithm (2 data structures) A PDF file with The results of the test cases by running your algorithms, 4 of them (2 for each algorithm) 4 plots on time performance A discussion of memory usage for Dijkstra's algorithm (2 data structures) and for Floyd's algorithm (2 data structures) Input Files Project2_Input_Files.zip https://canvas.pitt.edu/courses/81202/files/4978605?wrap=1 https://canvas.pitt.edu/courses/81202/files/4978605?wrap=1 https://canvas.pitt.edu/courses/81202/files/4978792?wrap=1
Answered 3 days AfterMar 03, 2021

Answer To: 2/26/2021 Project 2 https://canvas.pitt.edu/courses/81202/assignments/508595?module_item_id=...

Vaishnavi R answered on Mar 05 2021
141 Votes
ass2/Assignment/.classpath

    
        
            
        
    
    
    
ass2/Assignment/.project

     Assignment
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
ass2/Assignment/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=15
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=15
ass2/Assignment/bin/analysis.class
ass2/Assignment/bin/Dijkstra.class
ass2/Assignment/bin/MinDist.class
ass2/Assignment/bin/PerformanceTest.class
ass2/Assignment/bin/Vertex.class
ass2/Assignment/src/analysis.java
ass2/Assignment/src/analysis.java
public class analysis {
    private static final long MEGABYTE = 1024L * 1024L;
      public static long bytesToMegabytes(long bytes) {
        return bytes / MEGABYTE;
      }
}
ass2/Assignment/src/Dijkstra.java
ass2/Assignment/src/Dijkstra.java
// THIS PROGRAM IS FOR DIJKSTRA ALGORITHM USING 2d array
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.Scanner;
//import jdk.javadoc.internal.doclets.toolkit.util.Utils.Pair;
public class Dijkstra 
{
    private PriorityQueue pq;
    private Vertex vertices[];

    // parent of node/vertex
    private int path[];
    // stores distance of src to all vertex
    private int dist[];

    // this method is for extracting the info from excel file
    public static ArrayList file()
    {
        ArrayList myList = new ArrayList();
         try
         {
             FileReader fr = null;
             BufferedReader br = null;
             String inputPath;
             fr = new FileReader("E:\\vaishnavi\\greynodes\\assignments\\project2inputfile3-vocie1vd.csv");
             br = new BufferedReader(fr);
             String line = null;
             line = br.readLine();
             while(line!=null)
             {
                 myList.add(line);
                 line = br.readLine();
             }  
         } //try end
         catch(IOException ioex)
         {
             System.out.print(ioex);
         }
         return myList;
    }

    // this method will take src and dest and run dijkstra algorithm
    public void dijkstraAlgo(int sourceNode, int destinatioNode)
    {
        try {
 
            // first add src to pq,
            // pass (distance, vertex)
            pq.add(new MinDist(0,sourceNode));
            dist[sourceNode]=0;
 
            while(!pq.isEmpty())
            {
                int p = pq.peek().getVertex();
                dist[p] = pq.peek().getDist();
                pq.remove();
 
 
                if(p == destinatioNode)
                {
 
                    break;
                }
                // search for adjacent elements
                for(int i=0; i<427; i++)
                {
                    if(vertices[p].matrix[i]!=Integer.MAX_VALUE)
                    {
                        if(dist[i]>dist[p]+vertices[p].matrix[i])
                        {
                            path[i] = p;
                            dist[i]  = dist[p]+vertices[p].matrix[i];
                            pq.add(new MinDist(dist[i],i));
                        } 
 
                    }
                }
            }
        }
         catch(ClassCastException c)
        {
             System.out.print(c);
        }
    }
    // recursive funtion to print the path
    public static void printPath(int path[], int i,Vertex ver[]) {

        if(path[i] == -1) {
            System.out.println(ver[i].nodeId + " "+ ver[i].name);
            return;
        }

        printPath(path,path[i],ver);
        System.out.println(ver[i].nodeId + " "+ ver[i].name);

    }

    public static void main(String[] args) 
    {  
        long startTime = System.nanoTime();
        System.out.println("DIJKSTRA ALGORITHM USING 2D ARRAY");
        ArrayList myList = file();
        Dijkstra d = new Dijkstra();
        d.dist = new int[427];
        d.vertices = new Vertex[427];
        d.path =  new int[427];
        for(int i=0; i<427; i++)
        {
            d.vertices[i]=null;
        }
        for(int i=0; i<427; i++)
        {
            d.path[i]=-1;
        }

        for(int i=0; i<427; i++)
        {
            d.dist[i]=Integer.MAX_VALUE;
        }
        int op=0;
        for(int i=1; i        {
            String name="";
            double x=0;
            double y=0;
            int nodeId = 0;
            int distance=0;
            int destination=0;
            String line = myList.get(i);
            String[] tokens = line.split(",");
            int count=0;
            for (String token : tokens)
            {
                count++;
                if(count==1)
                {
                    nodeId = Integer.parseInt(token); 
                }
                else if(count==2)
                {
                    destination = Integer.parseInt(token);
                }
                else if(count==3)
                {
                    distance = Integer.parseInt(token);
                }
                else if(count==4)
                {
                    x = Double.parseDouble(token.substring(2, token.length()));
                }
                else if(count==5)
                {
                    y  = Double.parseDouble(token.substring(0, token.length()-2));
                }
                else if(count==6)
                {
                    name =token.substring(1,token.length());
                    name.concat(",");
                }
                else if(count==7)
                {
                    name+=(token.substring(0, token.length()-1));
                }
            }
            if(d.vertices[nodeId]==null)
            {
                Vertex v = new Vertex(name,x,y,nodeId);
                v.addEdge(destination, distance);
                d.vertices[nodeId]=v;
            }
            else
            {
                d.vertices[nodeId].addEdge(destination, distance);
            }
 
        }

        // take input 
                int sourceNode;
                int destinatioNode;
                 Scanner s = new Scanner(System.in); 
                 sourceNode = s.nextInt(); 
                 destinatioNode = s.nextInt();
                 d.pq =  new PriorityQueue(427, new MinDist());
 
                 d.dijkstraAlgo(sourceNode,destinatioNode);
 
                 // total distance from source to destination
                 System.out.println(d.dist[destinatioNode]);
 
                 // print path
                 printPath(d.path,destinatioNode,d.vertices);
 
                 long endTime = System.nanoTime();
                    System.out.println("Took "+(endTime - startTime) + " ns"); 
    }
}
ass2/Assignment/src/MinDist.java
ass2/Assignment/src/MinDist.java
import java.util.*; 
public class MinDist implements Comparator {
     private int dist;
     private int ver;


     MinDist(){
         dist = 0;
         ver = 0;
     }

     // parameterised constructor
     MinDist(int dist,int ver){
         this.dist = dist;
         this.ver = ver;
     }

     // method to give distance of vertex to src node
     public int getDist() {
         return dist;
     }

     // method to give current vertex
     public int getVertex() {
         return ver;
     }


    @Override
    public int compare(MinDist o1, MinDist o2) {
        if(o1.dist < o2.dist) return -1;
        if(o1.dist > o2.dist) return 1;
        return 0;
    }
}
ass2/Assignment/src/PerformanceTest.java
ass2/Assignment/src/PerformanceTest.java

public class PerformanceTest 
{
          private static final long MEGABYTE = 1024L * 1024L;
          public static long bytesToMegabytes(long bytes) {
            return bytes / MEGABYTE;
          }
}
ass2/Assignment/src/Vertex.java
ass2/Assignment/src/Vertex.java
public class Vertex {
    String name;
    double x;
    double y;
    int nodeId;

    // every node has 1d array to store connections of a graph
    int matrix[];

    public Vertex(String name,double x,double y,int nodeId) 
    {
        this.name = name;
        this.x = x;
        this.y = y;
        this.nodeId = nodeId;
        this.matrix = new int[427];
        for (int i = 0; i < 427; i++) 
            matrix[i] = Integer.MAX_VALUE;
    }

    // creating adjaceny list
    public void addEdge(int nodeId2,int weight)
    {
        matrix[nodeId2]= weight;
    }

    public void display()
    {
         System.out.println(this.nodeId);
         System.out.println(this.name);
    }
}
ass2/dijkstra2D.png
ass2/dijkstraLinkedList.png
ass2/DijkstraLL/.classpath

    
        
            
        
    
    
    
ass2/DijkstraLL/.project

     DijkstraLL
    
    
    
    
        
             org.eclipse.jdt.core.javabuilder
            
            
        
    
    
        ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here