Question: Graph.h #pragma once #include #include #include #include #ifndef COP 3 5 3 0 _ PROJECT _ 3 _ GRAPH _ H #define COP 3 5
Graph.h
#pragma once
#include
#include
#include
#include
#ifndef COPPROJECTGRAPHH
#define COPPROJECTGRAPHH
using namespace std;
class AdjacencyList
private:
graph structure
unorderedmultimap graph;
store lat and long of nodes as pair
unorderedmultimap nodeLocations;
public:
void insertNodeint nodeID, double latitude, double longitude
nodeLocations.insert nodeID, latitude longitude;
void insertEdgeint fromID, int toID, double weight
graph.insert fromID, toID weight;
code referenced from Lecture Slides Mod a Graphs Terminology and Implementation slide
vector bfsint startID, int endID
create containers for bfs
set visited;
queue queue;
unorderedmap previous;
insert and push startID into visited and queue
visited.insertstartID;
queue.pushstartID;
set node previous to start id as
previousstartID;
while queue.empty
int u queue.front;
checks if u is the same as the endID, add it to the path and keep adding the previous nodes until it reaches the previousstart which is
if u endID
vector pathTrace;
for int i endID; i ; i previousi
pathTrace.pushbacki;
reverse order of path
reversepathTracebegin pathTrace.end;
return pathTrace;
queue.pop;
check if element is in the visited set, if its not, add it to vector and queue
vector neighbours;
auto it graph.equalrangeu;
for auto& i itfirst; i itsecond; i
for const auto& neighbour : isecond
int v neighbour.first;
if visitedcountv
visited.insertv;
queue.pushv;
no path found return empty
return ;
vector dijkstrasint startID, int endID;
unorderedmultimap& getAdjacencyList
return graph;
unorderedmultimap getNodeLoc
return nodeLocations;
;
#endif
Main.cpp
#include
#include "graph.h
#include
#include
#include
#include
#include
#include
#define pi
Earth Radius in Kilometers found online
const double EarthR ;
formula to calculate weights based on longitude and latitude
double Formuladouble Latitude double Longitude double Latitude double Longitude
double Longitude Latitude Latitude pi ;
double Latitude Longitude Longitude pi ;
Latitude Latitude pi ;
Latitude Latitude pi ;
double Result sinLatitude sinLatitude cosLatitude cosLatitude sinLongitude sinLongitude ;
double Result atansqrtResult sqrt Result;
double final EarthR Result;
return final;
class Drawer : public osmium::handler::Handler
public:
AdjacencyList& graph;
int NodeTotal ;
const int NodeMax ;
DrawerAdjacencyList& list : graphlist
override node function
void nodeconst osmium::Node& nodes
if NodeTotal NodeMax
graph.insertNodenodesid nodes.locationlat nodes.locationlon;
NodeTotal;
cout "Node ID: nodes.idt NodeTotal t;
override way function
void wayconst osmium::Way& Direct
const auto& DirectionofNode Direct.nodes;
for sizet x ; x DirectionofNode.size; x
auto Node DirectionofNodex ref;
auto Node DirectionofNodexref;
if graphgetNodeLoccountNode && graph.getNodeLoccountNode
auto it graph.getNodeLocequalrangeNode;
auto it graph.getNodeLocequalrangeNode;
for auto i itfirst; i itsecond; i
for auto j itfirst; j itsecond; j
double Latitude isecond.first;
double Longitude isecond.second; ;
i am getting a derefrencing error at the end two lines in the main.cpp file for some reason. Everything else works
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
