Пример #1
0
void	run_sort_algorithms(t_info *info)
{
	t_algo	*best;
	t_algo	*b_sort;
	t_algo	*s_sort;
	t_algo	*d_sort;

	b_sort = new_algo(info);
	s_sort = new_algo(info);
	d_sort = new_algo(info);
	info->in_count = dumb_sort(d_sort, info);
	compress_ops(d_sort->operations, &info->in_count);
	best = d_sort;
	bubble_sort(b_sort, info);
	compress_ops(b_sort->operations, &b_sort->op_count);
	if (b_sort->op_count < best->op_count && stack_sorted(b_sort->stack_a))
		best = b_sort;
	split_sort(s_sort, info);
	print_stacks(s_sort->stack_a, s_sort->stack_b, info);
	print_steps(s_sort->operations);
	compress_ops(s_sort->operations, &s_sort->op_count);
	if (s_sort->op_count < best->op_count && stack_sorted(s_sort->stack_a))
		best = s_sort;
	run_test2(best, info);
	delete_algo(&b_sort);
	delete_algo(&s_sort);
	delete_algo(&d_sort);
}
	int main(int argc, char* argv[]){
		float a = atof(argv[1]);
		float b = atof(argv[2]);
		int steps = atoi(argv[3]);
		
		print_steps(a, b, steps);
		
		return 0;
	}
Пример #3
0
TEST_F(avl_tree, DISABLED_show)
{
    steps_t not_found=scan_steps("(-1,1:X);(0,0:X);(1,-1:X);(1,0:O);(1,1:O);(-2,2:O);(2,-2:X);(3,-3:O);(-2,0:X);(-2,3:O);(-2,1:X);(-2,4:O)");
    sort_steps(not_found);

    steps_t writed_steps=scan_steps("(-3,-2:O);(-2,0:X);(-2,2:O);(-2,4:O);(-1,1:X);(0,0:X);(0,1:X);(1,-1:X);(1,0:O);(1,1:O);(2,-2:X);(3,-3:O)");
    sort_steps(writed_steps);

    std::cout<<print_steps(not_found)<<std::endl<<print_steps(writed_steps)<<std::endl;

    data_t not_found_bin;
    points2bin(not_found,not_found_bin);

    std::string not_found_str;
    bin2hex(not_found_bin,not_found_str);

    data_t cut_bin(not_found_bin.begin()+2,not_found_bin.end());
    std::string cut_str;
    bin2hex(cut_bin,cut_str);

    std::cout<<"not_found: "<<not_found_str<<std::endl<<"cut: "<<cut_str<<std::endl;

    
/*
    bin_index_t ind("D:\\1\\w",34);
    	
	data_t key;
	data_t val;
    std::string key_str;
    std::string val_str;

    std::ofstream fs("D:\\1\\w\\key_content.txt");

    for(bool r=ind.first(key,val);r;r=ind.next(key,val))
    {
        bin2hex(key,key_str);
        bin2hex(val,val_str);

//        std::cout<<"key="<<key_str<<" val="<<val_str<<std::endl;
        fs<<key_str<<std::endl;
    }
*/
}
Пример #4
0
void	run_test2(t_algo *best, t_info *info)
{
	t_info	*w_sort;

	w_sort = weight_sort(info);
	compress_ops(w_sort->steps, &w_sort->elem_steps);
	rollback_sort(info);
	compress_ops(info->steps, &info->elem_steps);
	if (info->elem_steps < best->op_count && stack_sorted(info->a))
	{
		if (info->elem_steps < w_sort->elem_steps)
			print_steps(info->steps);
		else
			print_steps(w_sort->steps);
	}
	else
		print_steps(best->operations);
	delete_mask(w_sort);
	delete_mask(info);
}
Пример #5
0
static void update_steps() {
  int steps = (int)HealthMetricStepCount;
  APP_LOG(APP_LOG_LEVEL_DEBUG, "The step count is %u", steps);
  print_steps(steps);
}
int IterativeDeepening::dfs_search(LiteState& current, int& bound, std::stack<LiteState>& path, Timer& timer) {
	
    if(!timer.is_still_valid()){
        return current.get_g();
    }
	
	// Perform heuristic evaluation
    double startTime = omp_get_wtime();
	int h = heuristic->calc_h(std::make_shared<LiteState>(current));
    heuristic_timer += (omp_get_wtime() - startTime);
    current.set_h(h);

	// Uses stack to trace path through state space
	path.push(current);

	// Bound check
	if (current.get_f() > bound){
        // Remove this state from the back of the vector
		path.pop();
		//path.erase(path.begin() + path.size() - 1);
		nodes_rejected++;
		int f = current.get_f();
		state_space.remove(std::shared_ptr<LiteState>(new LiteState(current)));
		return f;
	}

	if (state_space.state_is_goal(current, goals)){

		timer.stop_timing_search();
		print_steps(path);
		solved = true;

        std::cout << "Nodes generated during search: " << nodes_generated << std::endl;
        std::cout << "Nodes expanded during search: " << nodes_expanded << std::endl;

        std::cout << "Sequential search took " << timer.get_search_time() << " seconds." << std::endl;
        std::cout << "Time spent calculating heuristic: " << heuristic_timer << " seconds." << std::endl;
		
		return current.get_f();
	}

	nodes_expanded++;
	int min = Search::protect_goals;

	const std::vector<Operator>& applicable_operators = get_applicable_ops(current);

	for (std::size_t i = 0; i < applicable_operators.size(); i++) {

		const Operator& op = applicable_operators[i];

		// Generate successor state, set path cost
		LiteState child = get_successor(op, current);
		int new_g = current.get_g() + op.get_cost();
		child.set_g(new_g);

		// Check if state has been visited, if it has check if we have reached it in fewer steps (lower g value)
		if (state_space.child_is_duplicate(std::shared_ptr<LiteState>(new LiteState(child)))) {
			nodes_rejected++;
			continue;
		}

		// Record operator
		int op_id = op.get_num();
		child.set_op_id(op_id);

		nodes_generated++;

        int t = 0;
 		// Explore child node
		t = dfs_search(child, bound, path, timer);
		if (t < min){
			min = t;
		}
		// Get out of recursion when done. 
		if (solved){
			break;
		}
	}
	// We have generated no children that have lead to a solution and are backtracking.
	// Erase node as we backtrack through state space
	path.pop();
	return min;
}