#include "util.hh"


using namespace Gecode;


bool file_exists (const char* file_name) 
{
  struct stat buf;
  if (!stat (file_name, &buf)) {
    return true;
  }
  switch (errno) {
  case ENOENT:
    return false;
  default:
    perror ("stat error");
    exit (1);
  }
}


void clear_file (const char* file_name) 
{
  if (file_exists (file_name)) {
    if (remove (file_name)) {
      perror ("remove error");
      exit (1);
    }
  }
}


void showIntVarRanges (IntVar x)
{
  for (IntVarRanges i (x); i (); ++i) {
    std::cout << "[" << i.min () << "..." << i.max () << "], ";
  }
  std::cout << std::endl;
}


void showIntSetRanges (IntSet x)
{
  for (IntSetRanges i (x); i (); ++i) {
    std::cout << "[" << i.min () << "..." << i.max () << "], ";
  }
  std::cout << std::endl;
}


void print_statistics (std::ostream& os, const Search::Statistics& stat)
{
  os << "fail = " << stat.fail << std::endl;
  os << "node = " << stat.node << std::endl;
  os << "depth = " << stat.depth << std::endl;
  os << "memory = " << stat.memory << std::endl;
}
