Esempio n. 1
0
int				recur_list(t_file **file, t_file **dir, t_env *e)
{
	t_file		*tmp;
	t_file		*tmp2;
	struct stat info_file;
	t_file		*dirtmp;

	dirtmp = NULL;
	tmp = *file;
	tmp2 = *dir;
	while (tmp)
	{
		if (!good_file(tmp->str, e))
		{
			if (lstat(tmp->total, &info_file) != 0)
				error_dir(tmp->str, e);
			if (S_ISDIR(info_file.st_mode & S_IFMT))
				add_link(tmp->total, ".", &dirtmp);
		}
		tmp = tmp->next;
	}
	if (dirtmp)
		return (merge_list(dir, &dirtmp));
	else
		return (0);
}
Esempio n. 2
0
// read perms from the "good" log files and try back_dfs on them
void test_good_perm(int n) {
  ifstream ifs(good_file(n).c_str());
  string line;
  int count = 0;
  while (getline(ifs, line)) {
    perm_ptr p(convert_to_perm(n, line));
    cout << "\n[n=" << n << ";" << count << "]" << endl;
    back_dfs(*p, 50);
    ++count;
  }
  cout << count << " good permutations read\n";
}
Esempio n. 3
0
// Assumes perm[0] == 1 and that the 
// no depth limit if cutoff_score == -1
perm_score dfs(const perm& root, int cutoff_score) {
  assert(perm[0] == 1);
  set<perm> good_perms;
  int prev_good_perms_size = 0;
  const int n = root.size();
  int overall_best_score_for_n = get_current_score(n, dbname);
  vector<perm_score> stack;
  perm_score best(root);
  stack.push_back(best);
  int count = 0;
  while (!stack.empty()) {
    ++count;
    perm_score ps = stack.back();
    stack.pop_back();
    const perm p = ps.get_perm();
    const int ps_score = ps.get_score();
    const int new_score = ps_score + 1;
    if (ps_score > best.get_score()) {
      best = ps;
      const int best_score = best.get_score();
      if (show_n)
        cout << "n=" << n << ", best (" << best_score
             <<  "/" << overall_best_score_for_n << "): " 
             << best.get_perm() 
             << endl;
      if (best_score > overall_best_score_for_n) {
        set_current_perm(n, best.get_perm());
        overall_best_score_for_n = best_score;
      } 
    } else if (good_logging && good_pct * overall_best_score_for_n <= ps_score) {
      //      good_perms.insert(good_perms.begin(), ps.get_perm());
      //      if (good_perms.size() > prev_good_perms_size) {
      prev_good_perms_size = good_perms.size();
      ofstream fout(good_file(n).c_str(), ios::app);
      fout << ps.get_perm() << '\n';
      ping('=');
    }
    
    // add p's children to the stack
    if (new_score < cutoff_score || cutoff_score == -1) {
      for(int i = 1; i < n; ++i) {
        const int pi = p[i];
        if (pi == i + 1) { // does p[i] holds its home value?
          perm cpy(p);
          reverse(cpy.begin(), cpy.begin() + pi);
          stack.push_back(perm_score(cpy, new_score));
        } // if
      } // for
    } // if
  } // while
  return best;
}
Esempio n. 4
0
// read perms from the "good" log files and try back_dfs on them
void test8() {
  const int n = 97;
  ifstream ifs(good_file(n).c_str());
  string line;
  int count = 0;
  while (getline(ifs, line)) {
    perm_ptr p(convert_to_perm(n, line));
    cout << "\n[" << count << "]" << endl;
    back_dfs(*p, 100);
    ++count;
  }
  cout << count << " good permutations read\n";
}