-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource: Movie_Vertex.cpp
More file actions
58 lines (49 loc) · 1.57 KB
/
Source: Movie_Vertex.cpp
File metadata and controls
58 lines (49 loc) · 1.57 KB
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
//Movie_Vertex.cpp
//Implementation of Movie_Vertex class
//Intention is to provide an infrastructure for storing data about movies in a "node" referred to as a vertex
//The vertex can be connected to other verticies using edges, thus creating a graph
//The Graph class is required as a handler for the movie vertex objects
//A single graph object is made and multiple verticies/edges are added to it
#include "Movie_Vertex.h"
#include <iostream>
using namespace std;
// Constructor for Movie_Vertex, stores all information relating to the movie dataset
Movie_Vertex::Movie_Vertex(string title, string genre, double rating)
{
this->title = title;
this->genre = genre;
this->rating = rating;
}
//Adds adjVert to a list of connected verticies, adjVerts
void Movie_Vertex::addEdge(Movie_Vertex& adjVert)
{
//Prevent duplicates
for (int i = 0; i < adjVerts.size(); i++)
{
if (adjVerts[i].second->getTitle().compare(adjVert.getTitle()) == 0)
{
return;
}
}
//Edge weight determined by sum of ratings
//Higher ratings will have lower weights
//Maximum rating is 10+10 -> weight of 0.05
adjVerts.push_back(make_pair(1 / (getRating() + adjVert.getRating()), &adjVert));
}
// Return all connections of this vertex
vector<pair<double, Movie_Vertex*>>* Movie_Vertex::getEdges()
{
return &adjVerts;
}
string Movie_Vertex::getTitle()
{
return title;
}
string Movie_Vertex::getGenre()
{
return genre;
}
double Movie_Vertex::getRating()
{
return rating;
}