void DrawMinimalSpanningTree(const map<string,infoT> &point,const set<arcT> &arc){ set<string> include; cout<<"start drawing the SpanningTree......"<<endl; include.insert(point.begin()->first); while(true){ set<string>::iterator itr=include.begin(); double min=100000; string start,end; while(itr!=include.end()){ cout<<"start point:"<<*itr<<endl; set<laborT>::iterator itr_labor=point.find(*itr)->second.labor.begin(); while(itr_labor!=point.find(*itr)->second.labor.end()){ string target=(*itr_labor).name; cout<<" labor:"<<target<<endl; if(include.count(target)==0){ double distance=(*itr_labor).distance; if(distance<min){ min=distance; start=*itr; end=target; cout<<"short line:"<<start<<":"<<end<<endl; } } itr_labor++; } itr++; } if(min==100000) break; include.insert(end); cout<<"include.insert:"<<end<<endl; cout<<"Draw line:"<<start<<"-----------------"<<end<<endl; DrawLineBetween(point.find(start)->second.location, point.find(end)->second.location,"red"); } }
void drawEdges(Graph &graph, Map<coordT> &m) { Set<Arc *>::Iterator edgeIt = graph.getArcSet().iterator(); while (edgeIt.hasNext()) { Arc *arc = edgeIt.next(); DrawLineBetween(m[arc->start->name], m[arc->finish->name], "Black"); } }
void drawLine(const vector<laborT> &path,const map<string,infoT> &point,const string sp){ vector<laborT>::const_iterator itr=path.begin(); cout<<"drawing the path"<<endl; while((itr+1)!=path.end()){ cout<<(*itr).name<<"-----"<<(*(itr+1)).name<<endl; DrawLineBetween(point.find((*itr).name)->second.location,point.find((*(itr+1)).name)->second.location,"red"); itr++; } }
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 displayMST(Graph &graph, Map<coordT> &m) { Vector<Arc *> MST = graph.findMST(); double netLength = 0; for (int i = 0; i < MST.size(); i++) { Arc *arc = MST[i]; netLength += arc->cost; DrawLineBetween(m[arc->start->name], m[arc->finish->name], "Red"); // Pause(0.05); } cout << endl << "MST now displayed." << endl << "Total network length is " << netLength << " miles." << endl << "Hit return to continue: "; GetLine(); drawEdges(graph, m); }
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"); } } }
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++; } }