// cmainProject.cc  A correctness checking main to help debug cliques().  
// -bds 9Nov99  
// Note: this does a limited check.  A more thorough correctness checker
// will be provided later.
#include <stdlib.h>
#include <iostream.h>
#include <cliques.h>

///////////// io tools for RelationList //////////////////
istream& operator>>(istream& in, RelationList& R)
{ int x;
  R.clear();
  in >> x;
  while (x != 0)
  { R.push_back(x); 
    in >> x; 
  }
  return in;
}

ostream& operator<<(ostream& out, const RelationList& R)
{ copy(R.begin(), R.end(), ostream_iterator<int>(out, " "));
  return out;
}

///////////// io tools for DataSet //////////////////
istream& operator>>(istream& in, DataSet& D)
{ RelationList r;
  D.clear();
  while (in >> r) D.push_back(r); 
  return in;
}

ostream& operator<<(ostream& out, const DataSet& D)
{ copy(D.begin(), D.end(), ostream_iterator<RelationList>(out, "0\n"));
  return out;
}

///////////// output tools for SetDescriptor, SDL /////////////////
ostream& operator<<(ostream& out, SetDescriptor& s)
{  return out << s.size() << " " << s.rep() << " ";} 

ostream& operator<<(ostream& out, SDL& S)
{ for (SDL::iterator p = S.begin(); p != S.end(); ++p)
    out << *p << endl;
  return out << endl;
}
  
RelationList relation(ID i, int k)// make a relation of i, i+1 .. i + k - 1.
{ RelationList R;
  for (ID j = i; j < i + k; j++)
    R.push_back(j);
  return R;
}


int main(int argc, char* argv[])
{ if ( argc < 2 || argc > 3 )
  { cerr << "Usage: " << argv[0] << " n k" << endl <<
"- where n is the number of ids and k is the size of input relations." 
    << endl <<
" The constructed data set will have two cliques of size n/2 " << endl;
    return 0;
  }
  DataSet D;
  int n = atoi(argv[1]);
  int k = (argc == 3) ? atoi(argv[2]) : 2;
  int half1 = n/2;
  int half2 = n - half1;
  int start = 100;
  int goal = start + half1 - k + 1;
  for (int i = start; i < goal; i++)
    D.push_back(relation(i,k));
  start = goal + 100 + k;
  goal = start + half2 - k + 1;
  for (int i = start; i < goal; i++)
    D.push_back(relation(i,k));

  cout << D;
  SDL S;
  S = cliques(D);

  int sum = 0;
  for (SDL::iterator p = S.begin(); p != S.end(); ++p)
    sum += p->size();

  cout << endl << "Cmain sez: ";
  if ( sum == n)
    cout << "Good: The set sizes add up correctly" << endl;
  else 
    cout << "Oops: The set sizes sum to " << sum 
    << ", but the number of ID's is " << n << endl;
  cout << S;
}

