void TrafficMap::print(list<int> &path){
	for(int i = 0; i < weight_map_.size(); i++){
		if(i % width_ == 0) cout<<"\n";
		if(onPath(path,i))
			cout<<"["<<weight_map_[i]<<"]";
		else
			cout<<" "<<weight_map_[i]<<" ";
	}
	cout<<endl;
}
void TrafficMap::print(list<int> &path,ofstream &file){
	for(int i = 0; i < weight_map_.size(); i++){
		if(i % width_ == 0) file<<"\n";
		if(onPath(path,i))
			file<<"["<<weight_map_[i]<<"]";
		else
			file<<" "<<weight_map_[i]<<" ";
	}
	file<<endl;
}
Example #3
0
void EditDistanceTable_draw (EditDistanceTable me, Graphics graphics, int iformat, int precision, double angle) {
    long rowmin = 1, rowmax = my numberOfRows;
    Graphics_setInner (graphics);
    Graphics_setWindow (graphics, 0.5, my numberOfColumns + 0.5, 0, 1);
    double leftMargin = getLeftMargin (graphics);   // not earlier!
    double lineSpacing = getLineSpacing (graphics);   // not earlier!
    double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax);
    double y = 1 + 0.1 * lineSpacing;
    autoNUMmatrix<bool> onPath (1, my numberOfRows, 1, my numberOfColumns);
    for (long i = 1; i <= my warpingPath -> pathLength; i++) {
        structPairOfInteger poi = my warpingPath -> path[i];
        onPath[poi.y] [poi.x] = true;
    }

    for (long irow = my numberOfRows; irow > 0; irow --) {
        Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF);
        if (my rowLabels && my rowLabels [irow] && my rowLabels [irow] [0])
            Graphics_text (graphics, 0.5 - leftMargin, y, my rowLabels [irow]);
        Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_HALF);
        for (long icol = 1; icol <= my numberOfColumns; icol ++) {
            char text [40];
            print4 (text, my data [irow] [icol], iformat, 0, precision);
            Graphics_setBold (graphics, onPath[irow][icol]);
            Graphics_text (graphics, icol, y, Melder_peek8to32 (text));
            if (onPath[irow][icol]) {
                Graphics_rectangle (graphics, icol-0.5, icol+0.5, y - 0.5*lineSpacing, y + 0.5*lineSpacing);
            }
        }
        y -= lineSpacing;
        Graphics_setBold (graphics, false);
    }

    double left = 0.5;
    if (maxTextWidth > 0.0) left -= maxTextWidth + 2 * leftMargin;
    Graphics_line (graphics, left, y, my numberOfColumns + 0.5, y);

    Graphics_setTextRotation (graphics, angle);
    if (angle < 0) {
        y -= 0.3*lineSpacing;
        Graphics_setTextAlignment (graphics, Graphics_LEFT, Graphics_HALF);
    } else if (angle > 0) {
        Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF);
        y -= 0.3*lineSpacing;
    } else {
        Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_TOP);
    }
    for (long icol = 1; icol <= my numberOfColumns; icol ++) {
        if (my columnLabels && my columnLabels [icol] && my columnLabels [icol] [0])
            Graphics_text (graphics, icol, y, my columnLabels [icol]);
    }
    Graphics_setTextRotation (graphics, 0);
    y -= lineSpacing;
    Graphics_line (graphics, 0.5, y, 0.5, 1 + 0.5 * lineSpacing);
    Graphics_unsetInner (graphics);
}
 vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) {
     if(numCourses <= 0) return {};
     
     vector<unordered_set<int>> graph(numCourses);
     for(auto pre: prerequisites){
         graph[pre.second].insert(pre.first);
     }
     vector<bool> onPath(numCourses, false), visited(numCourses, false);
     stack<int> s;
     for(int i = 0; i < numCourses; ++i){
         if(!dfs(i, onPath, visited, graph, s))
             return {};
     }
     vector<int> order;
     while(!s.empty()){
         order.push_back(s.top());
         s.pop();
     }
     return order;
 }