#include #include #include using namespace std; #include #include "vertex.h" #include "edge.h" #include "graph.h" #define GRAPH_NODES 50 #define GRAPH_EDGES 50 //int gay; Vertex* readVertex(ifstream &inFile) { int aVertex = -1; string line; if(!inFile.eof()) { inFile >> aVertex; //cout << "Read: " << aVertex << endl; getline(inFile,line); //cout << "Read: " << line << endl; } return new Vertex(aVertex, line); } int readVertexNum(ifstream &inFile) { int vertex = -1; if(!inFile.eof()) inFile >> vertex; return vertex; } Edge* readEdge(ifstream &inFile, int nuid, Vertex* v1, Vertex* v2) { int timerCode = 0; string line, input, output; if(!inFile.eof()) { inFile >> timerCode >> input >> output; //read send input part //cout << "READ: " << input; //cout << "READ: " << output; inFile.ignore(1,'\t'); getline(inFile,line); } return new Edge(nuid, line, v1, v2, timerCode, input, output); } void processARecord(ifstream &inFile, Graph *graph, int current_record) { string line; //getline(inFile,line); cout << "\n"; Vertex *v1 = readVertex(inFile); v1->printInfo(); Vertex *v2 = readVertex(inFile); v2->printInfo(); //Graph *g = new Graph(GRAPH_NODES); Edge* e = readEdge(inFile,current_record, v1, v2); //e->printInfo(); //cout << "\n"; graph->add(e); //g->printInfo(); graph->displayMatrix(); } int loader(Graph *graph) { cout << "loader\n"; //int total_record = 0; int current_record = 0; ifstream inFile_N("nodes.txt"); ifstream inFile_E("edges.txt"); if(inFile_N.is_open() && inFile_E.is_open()) { Vertex *v[GRAPH_NODES]; int rec = 0; while(!inFile_N.eof()) { v[rec] = readVertex(inFile_N); rec++; } int id = 0; while(!inFile_E.eof()) { int a = readVertexNum(inFile_E); int b = readVertexNum(inFile_E); Edge* e = readEdge(inFile_E,id++, v[a], v[b]); //e->printInfo(); //cout << "\n"; graph->add(e); //cout << "CUR_SIZE: " << graph->getSize() << endl; } } else { cout << "Unable to open file"; return 0; } return current_record; } void printer(Graph* graph) { cout << "printer\n"; cout << "\n############################################\n"; graph->displayMatrix(); cout << "\n############################################\n"; } void searcher() { cout << "searcher\n"; } void lister(Graph* graph) { int state_num; cout << "lister\n"; cout << "Enter State Number: "; cin >> state_num; cout << "\n############################################\n"; graph->displayChild(state_num); cout << "\n############################################\n"; } void automate(Graph* graph) {//srand(100); //gay = rand()%10; //int cunt = 0; //cout << "@@@@@@@@@@()@()(@)(@)()(@(@)()@(@)(@)(@)(@(@)(@)" << cunt++ << endl; graph->graph_auto(); } int main() { Graph *graph = new Graph(GRAPH_EDGES); //int record_size = 0; // stick's integration ////receiver.setRecieverPort(7000); cout << "GRAPH READER" << endl; int choice = -1; do { cout << "\t0. EXIT\n" << "\t1. LOAD FILE\n" << "\t2. PRINT MATRIX\n" << "\t3. SEARCH MATRIX \n" << "\t4. LIST CHILD\n" << "\t5. AUTOMATE \n" << "\t6. Get message\n" << "::"; cin >> choice; if(choice == 1) //record_size = loader(graph); loader(graph); else if(choice == 2) printer(graph); else if(choice == 3) searcher(); else if(choice == 4) lister(graph); else if(choice == 7) ; //stateChange(); else if(choice == 6) ; //printMsg(); // end Albert Tam option else if(choice == 5) automate(graph); else if(choice < 0 || choice > 7) cout << "INVALID CODE ENTERED: " << choice << endl; }while(choice != 0); return 0; }