This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.h
73 lines (66 loc) · 1.54 KB
/
graph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include <iostream>
using namespace std;
/**
* Used to capture an edge with a weight
*/
struct weightedEdge
{
string subject;
string object;
int weight;
};
/**
* Used (when we already have the subject nodes)
* to capture an object node and the associated
* weight
*/
struct weightedNode
{
string object;
int weight;
};
// Creating our generic Id type
template <typename Id = int>
struct _weightedEdge
{
Id subject;
Id object;
int weight;
};
template <typename Id = int>
struct _weightedNode
{
Id object;
int weight;
};
/**
* The abstract data strucuture with which we
*/
template <class NodeKind = string>
class Graph
{
public:
virtual ~Graph();
virtual int nodeCount();
virtual int edgeCount();
virtual void addEdge(NodeKind subject, NodeKind object, int weight);
virtual vector<_weightedEdge<NodeKind>> weightedEdges(NodeKind subject);
virtual _weightedEdge<NodeKind> lightestEdge(NodeKind subject);
};
// Algorithms such as djikstras are more efficient
// to implement on the *id* rather than doing conversions
// between the id rather than the more abstract graph
// so we create this struct with internals that we
// can use to create djikstras algoritm
template <typename Id = int>
struct GraphWithIdInternals
{
int nodeCount();
int edgeCount();
Id toId(string subject);
string fromId(Id id);
vector<_weightedEdge<Id>> weightedEdges(Id subject);
_weightedEdge<Id> lightestEdge(Id suject);
void addEdge(string subject, string object, int weight);
};