#include #include #include #include #include using namespace std; #include "graph.h" void main () { graph g(70000, 3600); //there are 70000 actors in the list. and 3600 movies ifstream ifs("//Engr_asu/Ece352/allmovies.list"); g.readGraph (ifs, 2000); //this takes a long time and memory, //change the 2000 to 4000 to make it faster g.calculateShortestPaths("Bacon, Kevin"); g.printShortestPath("Pfeiffer, Michelle"); g.printShortestPath("Smith, Will"); g.printShortestPath("Banderas, Antonio"); g.printShortestPath("Goldblum, Jeff"); g.printShortestPath("Madonna"); g.printShortestPath("Hopkins, Anthony"); } // Ignore the stuff below this point. (you can cut it out from your main.cpp). void formatData() { //my ugly code to turn IMDB files into something more useful. // map movieNumber; string movieNames[5000]; double ratings[5000]; int votes[5000]; list actorsInMovie[5000]; string word, dist; int vote; double rating; ifstream ifs("//Engr_asu/Ece352/ratings.list"); int counter = 0, i; int currentMovie = 1; int totalNumberMovies = 0; string name = ""; ifs >> dist; //distribution ifs >> vote; //number of votes ifs >> rating; //rating cout << "Reading movies..." << endl; while (ifs >> word) { if (word[0] == '(' && word[1] >= '0' && word[1] <= '9'){ name += " " + word; // cout << name << endl; if (vote >= 100) { movieNames[currentMovie] = name; movieNumber[movieNames[currentMovie]] = currentMovie; ratings[currentMovie] = rating; votes[currentMovie] = vote; currentMovie++; }; name = ""; ifs >> dist; //distribution while (dist == "(TV)" || dist == "(V)" || dist == "(mini)" || dist == "(VG)") ifs >> dist; ifs >> vote; //number of votes ifs >> rating; //rating continue; } if (name == "") name += word; else name += " " + word; // if (counter++ > 20) break; }; totalNumberMovies = currentMovie; cout << "There were " << totalNumberMovies << " movies" << endl; // for (i = 0 ; i < 10; i++){ // cout << movieNames[i] << " " << ratings[i] << endl; // }; /* ifstream act1("//Engr_asu/Ece352/actors-c.list"); ofstream out1("//Engr_asu/Ece352/actors-short.list"); cout << "Reading Actors..." << endl; act1 >> word; while (word == "A:") { // if (counter++ > 50) break; name = ""; if (word == "A:"){ int first=1; while (1) { act1 >> word; if (word == "M:") break; if (first){ name = word; first = 0; } else name += " " + word; } // if (name[0] =='F') // cout << "a=" << name << "=" << endl; int firstmovie = 1; while (word == "M:"){ string movie = ""; first = 1; while (act1 >> word) { if (word == "M:" || word == "A:") break; if (first){ movie = word; first = 0; } else movie += " " + word; }; // if (name[0] == 'F') // cout << "m=" << movie << endl; if (movieNumber[movie]) { if (firstmovie){ out1 << "A:\t" << name << endl; firstmovie = 0; } out1 << "M:\t" << movie << endl; } } } } out1.close(); ifstream act2("//Engr_asu/Ece352/actresses-c.list"); ofstream out2("//Engr_asu/Ece352/actresses-short.list"); cout << "Reading Actresses..." << endl; act2 >> word; while (word == "A:") { // if (counter++ > 50) break; name = ""; if (word == "A:"){ int first=1; while (1) { act2 >> word; if (word == "M:") break; if (first){ name = word; first = 0; } else name += " " + word; } // cout << "a=" << name << endl; int firstmovie = 1; while (word == "M:"){ string movie = ""; first = 1; while (act2 >> word) { if (word == "M:" || word == "A:") break; if (first){ movie = word; first = 0; } else movie += " " + word; }; // cout << "m=" << movie << endl; if (movieNumber[movie]) { if (firstmovie){ out2 << "A:\t" << name << endl; firstmovie = 0; } out2 << "M:\t" << movie << endl; } } } } out2.close(); return; */ string *actorNames; actorNames = new string[70000]; int currentActor = 1; map actorNumber; ifstream act("//Engr_asu/Ece352/allactors.list"); cout << "Reading Actors..." << endl; act >> word; while (word == "A:") { name = ""; int first=1; while (1) { act >> word; if (word == "M:") break; if (first){ name = word; first = 0; } else name += " " + word; } actorNames[currentActor] = name; // cout << "a=" << name << endl; int firstmovie = 1; int currentMovieNumber; while (word == "M:"){ string movie = ""; first = 1; while (act >> word) { if (word == "M:" || word == "A:") break; if (first){ movie = word; first = 0; } else movie += " " + word; }; currentMovieNumber = movieNumber[movie]; if (!(currentMovieNumber)) cout << "ERROR: " << movie << " is not in" << endl; else{ actorsInMovie[currentMovieNumber].push_front(currentActor); } } currentActor++; } cout << "Writing movies..." << endl; ofstream ofs("//Engr_asu/Ece352/allmovies.list"); int j; for (i =1; i ::const_iterator LI; for (LI j = actorsInMovie[i].begin(); j != actorsInMovie[i].end(); ++j){ currentActor = *j; ofs << "A:\t" << actorNames[currentActor] << endl; } } } /* //this code should be run on the original actor.list and actresses.list first. ifstream act("//Engr_asu/Ece352/actresses.list"); char c, oldc;; int newactor=1; int print = 1; counter = 0; ofstream out("//Engr_asu/Ece352/actresses-c.list"); out << "A:\t"; while ((c = act.get()) != EOF){ if (c == '[' || c == '<') print = 0; if (c == ']' || c == '>') { print = 1; continue; }; if (c == '\n' && oldc == '\n'){ out << "A:\t"; continue; } if (c == '\t' && oldc == '\t' ) continue; if (c == '\t' && oldc == '\n') { out << "M:\t"; oldc = c; continue; } if (c == '\t'){ out << endl; out << "M:\t"; oldc = c; continue; } if (print) out.put(c); oldc = c; // if (counter++ > 800) break; } */