コード例 #1
0
ファイル: planner.cpp プロジェクト: gnunoe/Cf_ROS
void planner_t::get_max_cost(tree_node_t* node)
{
	sorted_nodes.push_back(node);
	if(node->cost > max_cost)
		max_cost = node->cost;
	for (std::list<tree_node_t*>::iterator i = node->children.begin(); i != node->children.end(); ++i)
	{
		get_max_cost(*i);
	}
}
コード例 #2
0
ファイル: planner.cpp プロジェクト: gnunoe/Cf_ROS
void planner_t::visualize_nodes(int image_counter)
{
    /*
    char buff[PATH_MAX];
    //getcwd( buff, PATH_MAX );
    
    ssize_t len = ::readlink(-d "sparseRRT", buff, sizeof(buff)-1);
    if (len != -1) 
    {	
      buff[len] = '\0';
    }
    
    std::cout << buff;    
    */
    //system("beep");
    //std::stringstream s;
    //std::cout <<"Path: " <<s.str();
    //params::path_file<<"/nodes_"<<image_counter<<".svg";
    std::string dir;
    if (params::planner == "rrt")
    {
      dir = params::path_file + "/nodes_rrt.svg";
    }
    else
    {
      dir = params::path_file + "/nodes_sst.svg";
    }
    //std::cout <<"Path: " <<dir;
    svg::Dimensions dimensions(params::image_width, params::image_height);
    svg::Document doc(dir, svg::Layout(dimensions, svg::Layout::BottomLeft));

    //-------------------
    sorted_nodes.clear();
    get_max_cost();
    sort(sorted_nodes);

    
    for(unsigned i=sorted_nodes.size()-1;i!=0;i--)
    {
	    visualize_node(sorted_nodes[i],doc,dimensions);
    }
    //------------------


	svg::Circle circle(system->visualize_point(start_state,dimensions),params::solution_node_diameter,svg::Fill( svg::Color(255,0,0) ));
	doc<<circle;
	svg::Circle circle2(system->visualize_point(goal_state,dimensions),params::solution_node_diameter,svg::Fill( svg::Color(0,255,0) ));
	doc<<circle2;

	visualize_solution_nodes(doc,dimensions);
    system->visualize_obstacles(doc,dimensions);

    doc.save();
}
コード例 #3
0
/*
 * This function is called from two paths.
 * One is garbage collection and the other is SSR segment selection.
 * When it is called during GC, it just gets a victim segment
 * and it does not remove it from dirty seglist.
 * When it is called from SSR segment selection, it finds a segment
 * which has minimum valid blocks and removes it from dirty seglist.
 */
static int get_victim_by_default(struct f2fs_sb_info *sbi,
                                 unsigned int *result, int gc_type, int type, char alloc_mode)
{
    struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
    struct victim_sel_policy p;
    unsigned int secno, max_cost;
    int nsearched = 0;

    p.alloc_mode = alloc_mode;
    select_policy(sbi, gc_type, type, &p);

    p.min_segno = NULL_SEGNO;
    p.min_cost = max_cost = get_max_cost(sbi, &p);

    mutex_lock(&dirty_i->seglist_lock);

    if (p.alloc_mode == LFS && gc_type == FG_GC) {
        p.min_segno = check_bg_victims(sbi);
        if (p.min_segno != NULL_SEGNO)
            goto got_it;
    }

    while (1) {
        unsigned long cost;
        unsigned int segno;

        segno = find_next_bit(p.dirty_segmap,
                              TOTAL_SEGS(sbi), p.offset);
        if (segno >= TOTAL_SEGS(sbi)) {
            if (sbi->last_victim[p.gc_mode]) {
                sbi->last_victim[p.gc_mode] = 0;
                p.offset = 0;
                continue;
            }
            break;
        }
        p.offset = ((segno / p.ofs_unit) * p.ofs_unit) + p.ofs_unit;
        secno = GET_SECNO(sbi, segno);

        if (sec_usage_check(sbi, secno))
            continue;
        if (gc_type == BG_GC && test_bit(secno, dirty_i->victim_secmap))
            continue;

        cost = get_gc_cost(sbi, segno, &p);

        if (p.min_cost > cost) {
            p.min_segno = segno;
            p.min_cost = cost;
        }

        if (cost == max_cost)
            continue;

        if (nsearched++ >= MAX_VICTIM_SEARCH) {
            sbi->last_victim[p.gc_mode] = segno;
            break;
        }
    }
    if (p.min_segno != NULL_SEGNO) {
got_it:
        if (p.alloc_mode == LFS) {
            secno = GET_SECNO(sbi, p.min_segno);
            if (gc_type == FG_GC)
                sbi->cur_victim_sec = secno;
            else
                set_bit(secno, dirty_i->victim_secmap);
        }
        *result = (p.min_segno / p.ofs_unit) * p.ofs_unit;

        trace_f2fs_get_victim(sbi->sb, type, gc_type, &p,
                              sbi->cur_victim_sec,
                              prefree_segments(sbi), free_segments(sbi));
    }
    mutex_unlock(&dirty_i->seglist_lock);

    return (p.min_segno == NULL_SEGNO) ? 0 : 1;
}
コード例 #4
0
ファイル: planner.cpp プロジェクト: gnunoe/Cf_ROS
void planner_t::get_max_cost()
{
	max_cost = 0;
	get_max_cost(root);
}