void displayDomSet(Graph &graph, Map<coordT> &m) { Set<Node *> domSet = graph.findSmallDomSet(); Set<Node *>::Iterator it = domSet.iterator(); while (it.hasNext()) { string name = it.next()->name; DrawFilledCircleWithLabel(m[name], "Red", name); } cout << endl << "Displaying a small dominated set, hit return to continue: "; GetLine(); it = domSet.iterator(); while (it.hasNext()) { string name = it.next()->name; DrawFilledCircleWithLabel(m[name], "Black", name); } }
nodeT * GetPoint(Set<nodeT *> graph, string message, string color) { nodeT *node; while (true) { cout << message << endl; coordT point1 = GetMouseClick(); bool pointFound = false; Set<nodeT *>::Iterator itr = graph.iterator(); while (itr.hasNext()) { // Test if click was close enough to a known location node = itr.next(); if (WithinDistance(GetCoords(node),point1)) { cout << node->name << endl; DrawFilledCircleWithLabel(GetCoords(node), color); pointFound = true; break; } } if (pointFound) break; else cout << "Try Again" << endl; } return node; }
void drawVertices(Map<coordT> &m) { Map<coordT>::Iterator locIt = m.iterator(); while (locIt.hasNext()) { string name = locIt.next(); DrawFilledCircleWithLabel(m[name], "Black", name); } }
void displayMinPath(Graph &graph, Map<coordT> &m, string &s1, string &s2) { cout << "\nFinding shortest path using Dijkstra... " << endl; int dequeueCount = 0; Vector<Arc *> path = graph.findShortestPath(s1, s2, dequeueCount); string prev = s1, curr; for (int i = 1; i < path.size(); i++) { curr = path[i]->start->name; DrawLineBetween(m[prev], m[curr], "Red"); DrawFilledCircleWithLabel(m[curr], "Red", curr); prev = curr; } DrawLineBetween(m[prev], m[s2], "Red"); double cost = getPathCost(path); displayMinResult(s1, s2, cost, dequeueCount); prev = s1; for (int i = 0; i < path.size(); i++) { curr = path[i]->finish->name; DrawLineBetween(m[prev], m[curr], "Black"); DrawFilledCircleWithLabel(m[prev], "Black", prev); prev = curr; } DrawFilledCircleWithLabel(m[prev], "Black", prev); }
void DrawNodesAndArcs(Set<nodeT *> graph) { Set<nodeT *>::Iterator itr = graph.iterator(); while (itr.hasNext()) { nodeT *n = itr.next(); coordT center = GetCoords(n); DrawFilledCircleWithLabel(center, "Black", n->name); Vector<arcT *>::Iterator itrArc = n->links.iterator(); while (itrArc.hasNext()) { arcT *arc = itrArc.next(); DrawLineBetween(GetCoords(arc->start), GetCoords(arc->end), "Black"); } } }
string getLocName(string s, Map<coordT> &m) { string name; while (true) { cout << s; coordT loc = GetMouseClick(); Map<coordT>::Iterator it = m.iterator(); while (it.hasNext()) { name = it.next(); if (WithinDistance(loc, m[name])) { cout << name << " chosen." <<endl; DrawFilledCircleWithLabel(m[name], "Red", name); return name; } } cout << "Invalid click. Please try again." << endl << endl; } }
void DrawLabeledPointAndLine(const map<string,infoT> &point,const set<arcT> &arc){ map<string,infoT>::const_iterator itrP=point.begin(); while(itrP!=point.end()){ DrawFilledCircleWithLabel(itrP->second.location, "green", itrP->first); itrP++; } set<arcT>::const_iterator itrA=arc.begin(); while(itrA!=arc.end()){ //read arc string start=(*itrA).start; string end=(*itrA).end; //draw DrawLineBetween(point.find(start)->second.location, point.find(end)->second.location,"green"); itrA++; } }