void OASpanningGraph::Check_Edge_Cost_Length() { for(int i=0;i<this->getNumEdge();i++) { SGEdge* E =this->getEdge(i); if(E->getLength()==0) { cout<<"\n--[Check edges' length and cost in OASG ?]\n"; cout<<"Catch error! length = 0\n"; PrintEdge(E); exit(0); } if(E->getCost()!=E->getLength()) { cout<<"\n--[Check edges' length and cost in OASG ?]\n"; cout<<"Catch error! cost != length\n"; PrintEdge(E); exit(0); } } }
/** * Prints edge labels of the Suffix tree */ void SSTree::PrintTree(ulong v, int depth) { for (int i=0;i< depth;i++) printf(" "); if (v != 0) { PrintEdge(v); } if(!(isleaf(v))) { PrintTree(v + 1, depth+1); } v = sibling(v); if (v != 0) PrintTree(v, depth); }
void PrintInstance(Instance *instance, Graph *graph, LabelList *labelList) { ULONG i; if (instance != NULL) { for (i = 0; i < instance->numVertices; i++) { printf(" "); PrintVertex(graph, instance->vertices[i], labelList); } for (i = 0; i < instance->numEdges; i++) { printf(" "); PrintEdge(graph, instance->edges[i], labelList); } } }
void PrintGraph(Graph *graph, LabelList *labelList) { ULONG v; ULONG e; if (graph != NULL) { printf(" Graph(%luv,%lue):\n", graph->numVertices, graph->numEdges); // print vertices for (v = 0; v < graph->numVertices; v++) { printf(" "); PrintVertex(graph, v, labelList); } // print edges for (e = 0; e < graph->numEdges; e++) { printf(" "); PrintEdge(graph, e, labelList); } } }
//check intersection of edges. build the relation of edges that intersect each other. //for more detail, refer to algorithm textbook (sweep-line implementation) void OASpanningGraph::CheckEdgeIntersection() { #ifdef DEBUG_ANALYSIS_RUN_TIME clock_t SG_check_intersection_start = clock(); #endif //(1) build the event vector // the definition of event : refer to sweep line algorithm vector<Event*> vEvent; for(int i=0;i<getNumEdge();i++) { SGEdge* E = getEdge(i); //No need to consider edges of obstacle if(E->getToNode()->getType() != _PIN && E->getFromNode()->getType() != _PIN) { continue; } Point* P1=E->getFromNode()->getPoint(); Point* P2=E->getToNode()->getPoint(); if(P1->getX() > P2->getX()) { Point* temp = P2; P2 = P1; P1 = temp; } //true for leftmost point of edge Event* ev1 = new Event(P1->getX(),P1->getY(),P1->getLayer(),true,E); Event* ev2 = new Event(P2->getX(),P2->getY(),P2->getLayer(),false,E); vEvent.push_back(ev1); vEvent.push_back(ev2); } //(2) sort event vector by increasing x-coordinate //when the line is vertical //it may come the rightmost of edge first, then leftmost of edge //so the order is reverse, In order to make sure the order, we use stable_sort() instead of sort() stable_sort(vEvent.begin(),vEvent.end(),Event_XLessThan()); //(3) sweep from left to right vector<SGEdge*> State; for(int i=0;i<vEvent.size();i++) { Event* ev=vEvent[i]; SGEdge* E=ev->getEdge(); #ifdef DEBUG_OASG_DETECT_INTERSECTION cout<<"\nEvent\n"; PrintEdge(E); #endif if(ev->LeftmostOfEdge() == true) { #ifdef DEBUG_OASG_DETECT_INTERSECTION cout<<":LeftmostOfEdge\n"; #endif //compare with the edges in state for(int j=0;j<State.size();j++) { SGEdge* detectEdge=State[j]; if(E == detectEdge) { cout<<"Error: occured in¡@OASpanningGraph::CheckEdgeIntersection().\n"; exit(0); } else if(DetectLineIntersection(E,detectEdge) == true) { #ifdef DEBUG_OASG_DETECT_INTERSECTION cout<<"Intersect this edge\n"; PrintEdge(detectEdge); #endif E->addIntersectEdge(detectEdge); detectEdge->addIntersectEdge(E); } } //add this edge into State State.push_back(E); } else { #ifdef DEBUG_OASG_DETECT_INTERSECTION cout<<":RightmostOfEdge\n"; #endif //remove edge from State int deleteIndex=-1; for(int j=0;j<State.size();j++) { SGEdge* detectEdge=State[j]; if(detectEdge == E) { deleteIndex=j; #ifdef DEBUG_OASG_DETECT_INTERSECTION cout<<"delete this edge from State\n"; PrintEdge(detectEdge); #endif break; } } if(deleteIndex==-1) { cout<<"Error: occured in¡@OASpanningGraph::CheckEdgeIntersection(). Index cannot be negative\n"; exit(0); } else { State.erase(State.begin()+deleteIndex); } } } #ifdef DEBUG_ANALYSIS_RUN_TIME clock_t SG_check_intersection_end = clock(); RunTime* RunTime = data->getRunTimeSet(); RunTime->SG_check_intersection = RunTime->SG_check_intersection + float(SG_check_intersection_end - SG_check_intersection_start)/CLK_TCK; cout<<"RunTime->SG_check_intersection = "<<RunTime->SG_check_intersection<<endl; #endif }
//from each node traces back to driving node by the value of distFromDriving //if cannot reach driving node, that's must be a error when rectilinearizing slant edges void OASpanningGraph::Check_Conn() { if(this->getNumNode()==0) { cout<<"There is no node in OASG\n"; return ; } for(int i=0;i<this->getNumNode();i++) { SGNode* N = this->getNode(i); if(N->getType()==_PIN && N->checkInTree()==true) { #ifdef DEBUG_OASG_CHECK_CONNECTION cout<<"Path starts from node :\n"; PrintNode(N); #endif #ifdef DEBUG_OASG_CHECK_CONNECTION if(N->checkedConn()==true) { cout<<"this node is checked\n"; } #endif #ifndef DEBUG_OASG_CHECK_CONNECTION_STRICTLY while(N != this->DrivingNode && N->checkedConn()!=true) #endif #ifdef DEBUG_OASG_CHECK_CONNECTION_STRICTLY while(N != this->DrivingNode) #endif { //select next internode SGNode* nextN = NULL; for(int j=0;j<N->getNumEdge();j++) { if(N->getEdge(j)->checkRouted()) { if(N->getEdge(j)->getToNode()->getDistFromDriving() == N->getDistFromDriving()) //check error { cout<<"\n--[Check Tree's Connection in OASG]\n"; cout<<"Error occured in OASpanningGraph::Check_Conn()\n"; cout<<"N->getEdge(j)->getToNode()->getDistFromDriving() is wrong\n"; cout<<"N' = "; PrintNode(N->getEdge(j)->getToNode()); cout<<"N = "; PrintNode(N); exit(0); } if(N->getEdge(j)->getToNode()->getDistFromDriving() < N->getDistFromDriving()) { if(nextN == NULL) { nextN = N->getEdge(j)->getToNode(); //because slant edge its length may be not an integer //so give it an inaccuracy range (range = 1) if( abs(int(N->getDistFromDriving() - (N->getEdge(j)->getToNode()->getDistFromDriving() + N->getEdge(j)->getLength())) ) > 1) { cout<<"\n--[Check Tree's Connection in OASG]\n"; cout<<"Error occured in OASpanningGraph::Check_Conn()\n"; cout<<"N->getEdge(j)->getToNode()->getDistFromDriving() is wrong\n"; cout<<"nextN = "; PrintNode(N->getEdge(j)->getToNode()); cout<<"N = "; PrintNode(N); cout<<"Length = "<<N->getEdge(j)->getLength()<<endl; exit(0); } } else { cout<<"\n--[Check Tree's Connection in OASG]\n"; cout<<"Error occured in OASpanningGraph::Check_Conn()\n"; cout<<"N->getEdge(j) is wrong\n"; PrintEdge(N->getEdge(j)); cout<<"nextN is wrong\n"; PrintNode(nextN); exit(0); } } } } #ifdef DEBUG_OASG_CHECK_CONNECTION PrintNode(nextN); #endif if(nextN==NULL) { cout<<"\n--[Check Tree's Connection in OASG]\n"; cout<<"Error occured in OASpanningGraph::Check_Conn()\n"; cout<<"nextN cannot be NULL\n"; cout<<"Driving Node : "; PrintNode(this->DrivingNode); cout<<"N : "; PrintNode(N); cout<<"edges of N :\n"; for(int j=0;j<N->getNumEdge();j++) { PrintEdge(N->getEdge(j)); } exit(0); } N->setCheckedConn(true); N = nextN; } #ifdef DEBUG_OASG_CHECK_CONNECTION cout<<"One path is checked!\n"; cout<<"===========================\n"; #endif } } }