Beispiel #1
0
// protected
void 
FileInputStreamTestCase::ctors (void)
{	
	FileInputStream fin (TEST_FILE_NAME);
	
	File file (TEST_FILE_NAME);
	
	FileInputStream fin2(TEST_FILE_NAME, READ_SHARE);
	CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, WRITE_SHARE), Exception);
	fin2.close ();
	fin.close ();
	
	FileInputStream fin3(TEST_FILE_NAME, NONE_SHARE);
	CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, READ_SHARE), Exception);
	
}
Beispiel #2
0
int main(int argc, char* argv[])
{
    std::ifstream fin1("lTall.txt"); /// all protoss matches
    std::ifstream fin2("lPall.txt"); /// all protoss matches
    std::ifstream fin3("lZall.txt"); /// all protoss matches
#ifdef GENERATE_X_VALUES
    std::vector<std::set<int> > terran = get_X_values(fin1);
    std::vector<std::set<int> > protoss = get_X_values(fin2);
    std::vector<std::set<int> > zerg = get_X_values(fin3);
#else
    std::vector<std::set<int> > terran = tech_trees(fin1).vector_X;
    std::vector<std::set<int> > protoss = tech_trees(fin2).vector_X;
    std::vector<std::set<int> > zerg = tech_trees(fin3).vector_X;
#endif
#ifdef FILE_OUTPUT
std::ofstream terran_fout("terran_possible_tech_trees.txt");
std::ofstream protoss_fout("protoss_possible_tech_trees.txt");
std::ofstream zerg_fout("zerg_possible_tech_trees.txt");
#endif

    std::set<std::set<int> > terran_verif;
    for (std::vector<std::set<int> >::const_iterator it
            = terran.begin(); it != terran.end(); ++it)
    {
#ifdef PRINTALL
#ifdef FILE_OUTPUT
        print_set<Terran_Buildings>(*it, terran_fout);
#else
        print_set<Terran_Buildings>(*it);
#endif
#endif
        terran_verif.insert(*it);
    }

    if (terran.size() != terran_verif.size()) 
        std::cout << "TEST FAIL" << std::endl;
    std::cout << "Terran, printed: " << terran.size() << " sets == tech trees" << std::endl;

    std::set<std::set<int> > protoss_verif;
    for (std::vector<std::set<int> >::const_iterator it
            = protoss.begin(); it != protoss.end(); ++it)
    {
#ifdef PRINTALL
#ifdef FILE_OUTPUT
        print_set<Protoss_Buildings>(*it, protoss_fout);
#else
        print_set<Protoss_Buildings>(*it);
#endif
#endif
        protoss_verif.insert(*it);
    }

    if (protoss.size() != protoss_verif.size()) 
        std::cout << "TEST FAIL" << std::endl;
    std::cout << "Protoss, printed: " << protoss.size() << " sets == tech trees" << std::endl;

    std::set<std::set<int> > zerg_verif;
    for (std::vector<std::set<int> >::const_iterator it
            = zerg.begin(); it != zerg.end(); ++it)
    {
#ifdef PRINTALL
#ifdef FILE_OUTPUT
        print_set<Zerg_Buildings>(*it, zerg_fout);
#else
        print_set<Zerg_Buildings>(*it);
#endif
#endif
        zerg_verif.insert(*it);
    }

    if (zerg.size() != zerg_verif.size()) 
    {
        std::cout << "TEST FAIL" << std::endl;
        std::cout << zerg.size() << " " << zerg_verif.size() << std::endl;
    }
    std::cout << "Zerg, printed: " << zerg.size() << " sets == tech trees" << std::endl;

    return 0;
}
Beispiel #3
0
void plotCmp(int eff) {
  TFile fin1("out1_EE_Jan.root","read");
  TH1D *hEff1=(TH1D*)fin1.Get("eff_postFSRcorr");
  TH1D *hAcc1=(TH1D*)fin1.Get("acc_postFSRcorr");
  hEff1->SetDirectory(0);
  hAcc1->SetDirectory(0);
  fin1.Close();
  TH1D* hAS=(eff) ? hEff1 : hAcc1;

  TString path="../root_files_reg/constants/DY_j22_19712pb/";
  TString fname2= path+ TString((!eff) ? "acceptance_1D.root" : "efficiency_1D.root");
  TString fieldName=(eff) ? "hEfficiency" : "hAcceptance";
  TString correctionName=(eff) ? "efficiency" : "acceptance";

  TFile fin2(fname2,"read");
  TH2D *h2Our=(TH2D*)fin2.Get(fieldName);
  h2Our->SetName("h2Our");
  h2Our->SetDirectory(0);
  fin2.Close();

  TH1D *hOurRaw=createProfileX(h2Our,1,fieldName + TString("Raw"));
  TH1D *hOur=removeLastBin(hOurRaw,fieldName);
  TString label1="regressed en. (20-500,500-800,800+)";
  TH1D *h2=NULL, *h3=NULL;
  TString label2,label3;

  if (0) {
    TString fname3="../root_files_reg/constants/DY_j22_19712pb_20inf/efficiency_1D.root";
    if (!eff) fname3.ReplaceAll("efficiency","acceptance");
    TFile fin3(fname3,"read");
    TH2D* h2tmp=(TH2D*)fin3.Get(fieldName);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    label2="regressed en. (20-inf)";
    h2=removeLastBin(h1tmp,fieldName+TString("regEn20inf"));
    delete h1tmp;
    delete h2tmp;
    fin3.Close();
  }

  if (0) {
    TString fname4="../root_files/constants/DY_j22_19789pb/efficiency_1D.root";
    if (!eff) fname4.ReplaceAll("efficiency","acceptance");
    TFile fin4(fname4,"read");
    TH2D* h2tmp=(TH2D*)fin4.Get(fieldName);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    h3=removeLastBin(h1tmp,fieldName+TString("summer2012"));
    label3="old n-tuples (20-500,500-800,800+)";
    delete h1tmp;
    delete h2tmp;
    fin4.Close();
  }

  if (0 && !eff) {
    TString fname3="../root_files_reg/constants/DY_j22_19712pb/acceptance_1D-PU.root";
    //if (!eff) fname4.ReplaceAll("efficiency","acceptance");
    TFile fin3(fname3,"read");
    TH2D* h2tmp=(TH2D*)fin3.Get(fieldName);
    printHisto(h2tmp);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    h2=removeLastBin(h1tmp,fieldName+TString("_wPU"));
    label3="regressed (20-500,500-800,800+); wPU";
    delete h1tmp;
    delete h2tmp;
    fin3.Close();
  }

  if (0 && !eff) {
    //TString fname4="../root_files_reg/constants/DY_j22_19712pb/acceptance_1D-PU.root";
    TString fname4="../root_files_reg/constants/DY_j22_19712pb_NoReweight/acceptance_1D___NoReweight.root";
    //if (!eff) fname4.ReplaceAll("efficiency","acceptance");
    TFile fin4(fname4,"read");
    TH2D* h2tmp=(TH2D*)fin4.Get(fieldName);
    printHisto(h2tmp);
    TH1D* h1tmp=createProfileX(h2tmp,1,"h1tmp");
    h3=removeLastBin(h1tmp,fieldName+TString("_noFEWZ"));
    label3="regressed (20-500,500-800,800+); noFEWZ";
    delete h1tmp;
    delete h2tmp;
    fin4.Close();
  }

  std::cout << "Alexey: "; printHisto(hAS);
  //std::cout << "OurRaw: "; printHisto(hOurRaw);
  std::cout << "Our   : "; printHisto(hOur);

  ComparisonPlot_t cp(ComparisonPlot_t::_ratioPlain,"cp","","#it{M}_{ee}",correctionName,"ratio");
  cp.SetLogx();
  cp.AddHist1D(hAS,"Alexey","LP",kBlack,1,0);
  cp.AddHist1D(hOur,label1,"LP",kBlue,1,0);
  if (h2) cp.AddHist1D(h2,label2,"LP",kGreen+1,1,0);
  if (h3) cp.AddHist1D(h3,label3,"LP",kRed+1,1,0);
  
  TCanvas *cx= new TCanvas("cx","cx",700,850);
  cp.Prepare2Pads(cx);
  cp.Draw(cx);
  cp.TransLegend(0,-0.6);
  if (1 || h2 || h3) {
    cp.TransLegend(-0.15,0.);
    cp.WidenLegend(0.15,0.);
  }
  cx->Update();
}
int main(int argc, char **argv) {
  PetscInitialize(&argc, &argv, "cmame.opt", help);

  int rank;
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  // The global domain size
  double gSize[3];
  gSize[0] = 1.; gSize[1] = 1.; gSize[2] = 1.;

  // Parameters for the balancing algorithm.
  // Refer to manual for details ... 
  bool incCorner = 1; // balance across corners = true  
  unsigned int maxNumPts= 1; // maximum number of points per octant
  unsigned int dim=3; // spatial dimensions 

  // unsigned int maxDepth=8; // maximum depth of the octree, has to be <= 30
  int maxDepth=8; // maximum depth of the octree, has to be <= 30

  int Ns = 32;
  unsigned int dof = 3;

  char problemName[PETSC_MAX_PATH_LEN];
  char filename[PETSC_MAX_PATH_LEN];

  double t0 = 0.0;
  double dt = 0.1;
  double t1 = 1.0;
  double beta = 0.000001;

  Vec rho;        // density - elemental scalar
  Vec lambda;     // Lame parameter - lambda - elemental scalar
  Vec mu;         // Lame parameter - mu - elemental scalar
  Vec fibers;     // Fiber orientations - nodal vector (3-dof)

  std::vector<Vec> tau;        // the scalar activation - nodal scalar

  std::vector<ot::TreeNode> linOct, balOct, newLinOct;
  std::vector<double> pts;

  // Initial conditions
  Vec initialDisplacement; 
  Vec initialVelocity;

  double nu, E;
  nu = 0.45;
  E = 1000;

  timeInfo ti;

  PetscTruth mf = PETSC_FALSE;
  bool mfree = false;

  PetscOptionsGetTruth(0, "-mfree", &mf, 0);

  if (mf == PETSC_TRUE) {
    mfree = true;
  } else
    mfree = false;

  double ctrst = 1.0;
  // get Ns
  CHKERRQ ( PetscOptionsGetInt(0,"-Ns",&Ns,0) );
  CHKERRQ ( PetscOptionsGetInt(0,"-mdepth",&maxDepth,0) );

  CHKERRQ ( PetscOptionsGetScalar(0,"-ctrst",&ctrst,0) );
  CHKERRQ ( PetscOptionsGetScalar(0,"-t0",&t0,0) );
  CHKERRQ ( PetscOptionsGetScalar(0,"-nu",&nu,0) );
  CHKERRQ ( PetscOptionsGetScalar(0,"-Youngs",&E,0) );
  CHKERRQ ( PetscOptionsGetScalar(0,"-t1",&t1,0) );
  CHKERRQ ( PetscOptionsGetScalar(0,"-dt",&dt,0) );
  CHKERRQ ( PetscOptionsGetScalar(0,"-beta",&beta,0) );
  CHKERRQ ( PetscOptionsGetString(PETSC_NULL,"-pn",problemName,PETSC_MAX_PATH_LEN-1,PETSC_NULL));

  // Time info for timestepping
  ti.start = t0;
  ti.stop  = t1;
  ti.step  = dt;

  if (!rank) {
    std::cout << "Grid size is " << Ns+1 << " and NT is " << (int)ceil(1.0/dt) << std::endl;
    std::cout << "MaxDepth is " << maxDepth << std::endl;
  }

  /*
  for (int i=0; i<3*Ns*Ns*Ns; i++) {
    double val = gaussian(); //randgauss(0., 1., 2.0, 0.);
    // std::cout << val << std::endl;
    pts.push_back(val);
  }

  MPI_Barrier(MPI_COMM_WORLD);  
*/
  /*********************************************************************** */
  // CONSTRUCT: Construct the linear octree from the points ...
  /*********************************************************************** */
  // ot::points2Octree(pts, gSize, linOct, dim, maxDepth, maxNumPts, MPI_COMM_WORLD);

  // The points are not needed anymore, and can be cleared to free memory.
  // pts.clear();

  if (!rank) {
    ot::readNodesFromFile("test.256.oct", newLinOct);
    std::cout << "Finished reading" << std::endl;
  }

  // std::sort(linOct.begin(), linOct.end());
  std::cout << rank << " Original octree size is " << newLinOct.size() << std::endl;

  /*
  par::Partition<ot::TreeNode>(linoct, newLinOct, MPI_COMM_WORLD);
  linOct.clear();
  */
  par::sampleSort<ot::TreeNode>(newLinOct, linOct, MPI_COMM_WORLD);
  newLinOct.clear();

  std::cout << rank << ": after Part octree size is " << linOct.size() << std::endl;

  /*********************************************************************** */
  // BALANCE: Balance the linear octree to enforce the 2:1 balance conditions.
  /*********************************************************************** */
  ot::balanceOctree (linOct, balOct, dim, maxDepth, incCorner, MPI_COMM_WORLD);

  std::cout << "Balanced octree size is " << balOct.size() << std::endl;

  // The linear octree (unbalanced) can be cleared to free memory.
  linOct.clear();

  // If desired the octree can be written to a file using the supplied routine ...
  ot::writeNodesToFile("filename.oct", balOct);

  /*********************************************************************** */
  // MESH : Construct the octree-based Distruted Array.
  /*********************************************************************** */
  ot::DA da(balOct,MPI_COMM_WORLD);
  balOct.clear();

  MPI_Barrier(MPI_COMM_WORLD);

  if (!rank)
    std::cout <<"Finshed Meshing" << std::endl;

  PetscFinalize();
  return 0;

  // create Matrices and Vectors
  elasMass *Mass = new elasMass(feMat::OCT); // Mass Matrix
  elasStiffness *Stiffness = new elasStiffness(feMat::OCT); // Stiffness matrix
  raleighDamping *Damping = new raleighDamping(feMat::OCT); // Damping Matrix

  cardiacForce *Force = new cardiacForce(feVec::OCT); // Force Vector

  // create vectors 

  da.createVector(rho, false, false, 1);
  da.createVector(mu, false, false, 1);
  da.createVector(lambda, false, false, 1);

  da.createVector(initialDisplacement, false, false, dof);
  da.createVector(initialVelocity, false, false, dof);

  // Set initial conditions
  CHKERRQ( VecSet ( initialDisplacement, 0.0) ); 
  CHKERRQ( VecSet ( initialVelocity, 0.0) );

  int parFac = 2;
  int numParams = 120;

  CHKERRQ ( PetscOptionsGetInt(0,"-pFac", &parFac,0) );

  numParams = parFac*parFac*parFac*5*3;
  if (!rank)
    std::cout << "Total number of unknowns is " << numParams << std::endl;

  // Generate the basis ...
  std::vector < radialBasis > spatialBasis;
  bSplineBasis temporalBasis(3, 5);	// this creates and sets up the basis ...
  // temporalBasis.knot();

  double fac = 1.0/parFac;
  double ssq = fac*fac/5.5452; // 8log(2) = 5.5452
  PetscPrintf(0, "SSQ is %f\n", ssq); 
  // Now to set up the radial bases ...
  for (int k=0; k<parFac; k++) {
    for (int j=0; j<parFac; j++) {
      for (int i=0; i<parFac; i++) {
        // std::cout << "Adding radial basis at: " << fac/2+i*fac << ", " << fac/2+j*fac << ", " << fac/2+k*fac << std::endl;
        radialBasis tmp(Point( fac/2+i*fac,fac/2+j*fac,fac/2+k*fac), Point(ssq,ssq,ssq));
        spatialBasis.push_back(tmp);
      }
    }
  }

  /*
  // Homogeneous material properties ...
  CHKERRQ( VecSet ( rho, 1.0) ); 

  nu = 0.45; E = 1000;
  double mmu = E/(2*(1+nu));
  double llam = E*nu/((1+nu)*(1-2*nu));

  CHKERRQ( VecSet ( mu, mmu) ); 
  CHKERRQ( VecSet ( lambda, llam) );
  */


  PetscScalar *muArray, *lamArray, *rhoArray;
  // Read in material properties from file ...
  unsigned int elemSize = Ns*Ns*Ns;

  unsigned char *tmp_mat = new unsigned char[elemSize];  
  double *tmp_tau = new double[elemSize];
  double *tmp_fib = new double[dof*elemSize];

  // generate filenames & read in the raw arrays first ...
  std::ifstream fin;

  sprintf(filename, "%s.%d.img", problemName, Ns); 
  fin.open(filename, std::ios::binary); fin.read((char *)tmp_mat, elemSize); fin.close();

  nu = 0.35; E = 1000;
  double mmu = E/(2*(1+nu));
  double llam = E*nu/((1+nu)*(1-2*nu));
  nu = 0.45; E = 1000*ctrst;
  double mmu2 = E/(2*(1+nu));
  double llam2 = E*nu/((1+nu)*(1-2*nu));

  da.vecGetBuffer(mu, muArray,true,true,false,1);
  da.vecGetBuffer(lambda, lamArray,true,true,false,1);
  da.vecGetBuffer(rho, rhoArray,true,true,false,1);

  for ( da.init<ot::DA::ALL>(), da.init<ot::DA::WRITABLE>(); da.curr() < da.end<ot::DA::ALL>(); da.next<ot::DA::ALL>()) {
    unsigned int i = da.curr();
    Point pt;
    pt = da.getCurrentOffset();

    int indx = pt.z()*Ns*Ns + pt.y()*Ns + pt.x();

    if ( tmp_mat[indx] ) {
      muArray[i] = mmu2;
      lamArray[i] = llam2;
      rhoArray[i] = 1.0;
    } else {
      muArray[i] = mmu;
      lamArray[i] = llam;
      rhoArray[i] = 1.0;
    }
  }

  da.vecRestoreBuffer(mu, muArray,true,true,false,1);
  da.vecRestoreBuffer(lambda, lamArray,true,true,false,1);
  da.vecRestoreBuffer(rho, rhoArray,true,true,false,1);

  delete [] tmp_mat;

  // Now set the activation ...
  unsigned int numSteps = (unsigned int)(ceil(( ti.stop - ti.start)/ti.step));

  Vec tauVec, tmpTau;

  // Create elemental vector ...
  da.createVector(tmpTau, true, true, 1);
  da.createVector(fibers, true, true, 3);
  
  PetscScalar *tauArray;

  // load the fibers ...
  da.vecGetBuffer(fibers, tauArray, true, true, 3);
    
  sprintf(filename, "%s.%d.fibers", problemName, Ns);
  std::ifstream fin3(filename, std::ios::binary); fin3.read((char *)tmp_fib, dof*elemSize*sizeof(double)); fin3.close();

  for ( da.init<ot::DA::ALL>(), da.init<ot::DA::WRITABLE>(); da.curr() < da.end<ot::DA::ALL>(); da.next<ot::DA::ALL>()) {
    unsigned int i = da.curr();
    Point pt;
    pt = da.getCurrentOffset();

    int indx = pt.z()*Ns*Ns + pt.y()*Ns + pt.x();

    for (int d=0; d<dof; d++) {
      tauArray[dof*i+d] = tmp_tau[dof*indx+d];
    }
  }

  da.vecRestoreBuffer(fibers, tauArray, true, true, 3);

  delete [] tmp_fib;


  // loop through time steps
  for (unsigned int t=0; t<numSteps+1; t++) {
    // a. Create new nodal vector ...
    da.createVector(tauVec, false, true, 1);

    VecSet( tmpTau, 0.0 );
    da.vecGetBuffer(tmpTau, tauArray, true, true, 1);

    // b. read in the activation 
    // std::cout << "Setting force vectors" << std::endl;
    sprintf(filename, "%s.%d.%.3d.fld", problemName, Ns, t);
    // std::cout << "Reading force file " << filename << std::endl;
    fin.open(filename); fin.read((char *)tmp_tau, elemSize*sizeof(double)); fin.close();

    // c. set the values ...
    for ( da.init<ot::DA::ALL>(), da.init<ot::DA::WRITABLE>(); da.curr() < da.end<ot::DA::ALL>(); da.next<ot::DA::ALL>()) {
      unsigned int i = da.curr();
      Point pt;
      pt = da.getCurrentOffset();

      int indx = pt.z()*Ns*Ns + pt.y()*Ns + pt.x();
      
      tauArray[i] = tmp_tau[indx];
    }

    // restore
    da.vecRestoreBuffer(tmpTau, tauArray, true, true, 1);
    // d. element2node
    elementToNode(da, tmpTau, tauVec, 1);

    // store in vector 
    tau.push_back(tauVec);
  }

  // Setup Matrices and Force Vector ...

  Mass->setProblemDimensions(1.0, 1.0, 1.0);
  Mass->setDA(&da);
  Mass->setDof(dof);
  Mass->setDensity(rho);

  Stiffness->setProblemDimensions(1.0, 1.0, 1.0);
  Stiffness->setDA(&da);
  Stiffness->setDof(dof);
  Stiffness->setLame(lambda, mu);

  Damping->setAlpha(0.0);
  Damping->setBeta(0.00075);
  Damping->setMassMatrix(Mass);
  Damping->setStiffnessMatrix(Stiffness);
  Damping->setDA(&da);
  Damping->setDof(dof);

  // Force Vector
  Force->setProblemDimensions(1.0,1.0,1.0);
  Force->setDA(&da);
  // Force->setFDynamic(tau);
  Force->setActivationVec(tau);
  Force->setFiberOrientations(fibers);
  Force->setTimeInfo(&ti);

  // Newmark time stepper ...
  newmark *ts = new newmark; 

  ts->setMassMatrix(Mass);
  ts->setDampingMatrix(Damping);
  ts->setStiffnessMatrix(Stiffness);
  ts->damp(false);
  ts->setTimeFrames(1);
  ts->storeVec(true);

  ts->setForceVector(Force);

  ts->setInitialDisplacement(initialDisplacement);
  ts->setInitialVelocity(initialVelocity);

  ts->setTimeInfo(&ti);
  ts->setAdjoint(false); // set if adjoint or forward
  ts->useMatrixFree(mfree);

  //if (!rank)
  //  std::cout << RED"Initializing Newmark"NRM << std::endl;
  double itime = MPI_Wtime();
  ts->init(); // initialize IMPORTANT 
  //if (!rank)
  //  std::cout << RED"Starting Newmark Solve"NRM << std::endl;
  double stime = MPI_Wtime();
  ts->solve();// solve 
  double etime = MPI_Wtime();
  
  // PetscFinalize();
Vec alpha, outvec;
  PetscScalar *avec;

  VecCreateSeq(PETSC_COMM_SELF, numParams, &alpha);

  VecGetArray(alpha, &avec);

  for (int j=0; j<numParams; j++)
    avec[j] = 0.0;

  avec[1] = 1.0;

  VecRestoreArray(alpha, &avec);

  VecDuplicate(alpha, &outvec);

  // Inverse solver set up
  parametricActivationInverse *hyperInv = new parametricActivationInverse;

  hyperInv->setBasis(spatialBasis, temporalBasis);

  hyperInv->setForwardInitialConditions(initialDisplacement, initialVelocity);

  hyperInv->setTimeStepper(ts);		 // set the timestepper

  hyperInv->setInitialGuess(alpha);// set the initial guess 

  hyperInv->setRegularizationParameter(beta);	// set the regularization paramter

  // hyperInv->setObservations(solvec); // set the data for the problem 

  hyperInv->init();	// initialize the inverse solver

  hyperInv->solve();

  Vec FinalSolution;
  hyperInv->getCurrentControl(FinalSolution);


  char fname[256];
  sprintf(fname, "%s.soln.%d.%d.raw",problemName, Ns, parFac );

  std::ofstream sol;
  if (!rank) {
    sol.open(fname, std::ios::binary);

    VecGetArray(FinalSolution, &avec);
    sol.write((char *)avec, numParams*sizeof(PetscScalar));
    VecRestoreArray(outvec, &avec);

    sol.close();
  }

  PetscFinalize();
}
Beispiel #5
0
void Query::startQuery()
{
    int count = 0;

    //before starting query we have to get the index
    buildIndex();
    cout << "Enter E to quit" << endl;
    string input = "";
    string temp = "";
    cin.ignore();

    while(input != "E" || input != "e")
    {
        count = 0;
    //cin.ignore();
    //http://www.codecogs.com/library/computing/stl/algorithms/set/set_union.php
    //good for parameters for a set
    cout << "To start a query please enter the words you would like to search for: " << endl;
    //cin.ignore();
    getline(cin, input);
    if(input == "E" || input == "e")
    {
        break;
    }
    stringstream ss(input);

    while(ss >> temp)
    {
        if(temp != "AND" && temp != "OR" && temp != "NOT")
            transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
        char* arr = new char[temp.length() + 1];
        strcpy(arr, temp.c_str());
        int x = stem(arr, 0, strlen(arr)-1);
        arr[x+1] = '\0';
        temp = arr;
        searchWords.push_back(temp);
        //try to separate the string into vector or array
        count++;
    }
    Word * word1;
    Word * word2;
    Word * word3;
    vector<int> word1Pages;
    map <int, int> freqMap;
    map <int, int> freqMap2;
    int totalFrequency = 0;
    vector<int> totalWordFrequency;
    vector <Page*> pageTitleResults;
    vector<int> pageResults;
    int testCount = 0;
    if(count  == 1)
    {
        word1 = table.returnWord(searchWords[0]);
        //word1 = tree.returnWord(searchWords[0]);
        if(word1 == NULL)
        {
            cout << searchWords[0] << " does not exist" << endl;
        }
        else
        {
            pageResults = word1->getPages();
            for(int b = 0; b < pageResults.size(); b++)
            {
                int oPage = pageResults[b];
                freqMap = word1->getInfo();
                totalFrequency = freqMap[oPage];
                totalWordFrequency.push_back(totalFrequency);
                //cout << "PAGE: " << pageResults[b] << " TOTAL FREQUENCY: " << totalFrequency << endl;
            }
            cout << endl;
            frequencySort(totalWordFrequency, pageResults);
            for(int i = 0; i < pageResults.size(); i++) {
                //cout << "FREQUENCY: " << totalWordFrequency[i] << " PAGE: " << pageResults[i] <<endl;
            }
        }

    }
    else if(searchWords[0] == "AND")
    {
        word1 = table.returnWord(searchWords[1]);
        word2 = table.returnWord(searchWords[2]);
        //word1 = tree.returnWord(searchWords[1]);
        //word2 = tree.returnWord(searchWords[2]);
        if(word1 == NULL || word2 == NULL)
        {
            cout << "word does not exist" << endl;
        }
        else
        {
        word1Pages = word1->getPages();
        vector<int> word2Pages = word2->getPages();
        pageResults = qAND(word1Pages, word2Pages);
        if(count == 5)
        {
            word3 = table.returnWord(searchWords[4]);
            //word3 = tree.returnWord(searchWords[4]);
            if(word3 == NULL)
            {
                cout << "word does not exist" << endl;
            }
            else
            {
            vector<int> word3Pages = word3->getPages();
            pageResults = qNOT(pageResults, word3Pages);
            } //end else
        }
        }

        for(int b = 0; b < pageResults.size(); b++)
        {
            int oPage = pageResults[b];
            if(oPage == 0)
                break;
            else
            {
                freqMap = word1->getInfo();
                freqMap2 = word2->getInfo();
                totalFrequency = freqMap[oPage] + freqMap2[oPage];
                totalWordFrequency.push_back(totalFrequency);
                //cout << "PAGE: " << pageResults[b] << " TOTAL FREQUENCY: " << totalFrequency << endl;
            }
        }
        frequencySort(totalWordFrequency, pageResults);
        for(int i = 0; i < pageResults.size(); i++)
        {
            if(pageResults[i] == 0)
                break;
            //cout << "FREQUENCY: " << totalWordFrequency[i] << " PAGE: " << pageResults[i] <<endl;
        }
        }//end else

    else if(searchWords[0] == "OR")
    {
        word1 = table.returnWord(searchWords[1]);
        word2 = table.returnWord(searchWords[2]);
        //word1 = tree.returnWord(searchWords[1]);
        //word2 = tree.returnWord(searchWords[2]);
        if(word1 == NULL || word2 == NULL)
        {
            cout << "word does not exist" << endl;
        }
        else
        {
        word1Pages = word1->getPages();
        vector<int> word2Pages = word2->getPages();
        pageResults = qOR(word1Pages, word2Pages);
        if(count == 5)
        {
            word3 = table.returnWord(searchWords[4]);
            //word3 = tree.returnWord(searchWords[4]);
            if(word3 == NULL)
            {
                cout << "word does not exist" << endl;
            }
            else
            {
            vector<int> word3Pages = word3->getPages();
            pageResults = qNOT(pageResults, word3Pages);
            }//end else
        }
        }

        for(int b = 0; b < pageResults.size(); b++)
        {
            int oPage = pageResults[b];
            if(oPage == 0)
                break;
            else
            {
                freqMap = word1->getInfo();
                freqMap2 = word2->getInfo();
                totalFrequency = freqMap[oPage] + freqMap2[oPage];
                totalWordFrequency.push_back(totalFrequency);
                //cout << "PAGE: " << pageResults[b] << " TOTAL FREQUENCY: " << totalFrequency << endl;
            }
        }
        frequencySort(totalWordFrequency, pageResults);
        for(int i = 0; i < pageResults.size(); i++)
        {
            if(pageResults[i] == 0)
                break;
            //cout << "FREQUENCY: " << totalWordFrequency[i] << " PAGE: " << pageResults[i] <<endl;
        }
        }
    else
    {
        word1 = table.returnWord(searchWords[0]);
        word2 = table.returnWord(searchWords[2]);
        //word1 = tree.returnWord(searchWords[0]);
        //word2 = tree.returnWord(searchWords[2]);
        if(word1 == NULL || word2 == NULL)
        {
            cout << "word does not exist" << endl;
        }
        else
        {
        word1Pages = word1->getPages();
        vector<int> word2Pages = word2->getPages();
        pageResults =  qNOT(word1Pages, word2Pages);
        }//end else


    }

        Page* x;
        //frequencySort(totalWordFrequency, pageResults);
        if(pageResults.size() <= 15)
        {
            for(int i = 0; i < pageResults.size(); i++)
            //to return the top 15 items
            //for(int i = 0; i < 15; i++)
            {
                if(pageResults[i] == 0)
                    break;
                cout << pageResults[i] << " ";
                x = pageIndex.returnObject(pageResults[i]);
                cout << x->getTitle() << endl;
                pageTitleResults.push_back(x);
            }
        }
        else
        {
        for(int i = 0; i < 15; i++)
        //to return the top 15 items
        //for(int i = 0; i < 15; i++)
        {
            if(pageResults[i] == 0)
                break;
            //cout << pageResults[i] << " ";
            x = pageIndex.returnObject(pageResults[i]);
            //cout << x->getTitle() << endl;
            pageTitleResults.push_back(x);
        }
        }
        cout << "Pages on which your search appears:" << endl << endl;
        //pageTitleResults.print3(cout);
        for(int s = 0; s < pageTitleResults.size(); s++)
        {
            cout << "Page: " << pageTitleResults[s]->getId() << " " << pageTitleResults[s]->getTitle() << endl;
        }

        cout << endl;
        Page* k;
        int pageChoice = 0;
        cout << "Please enter the page number of the page you would like to view " << endl;
        cout << "Enter -1 if you do not want to view a page" << endl;
        //cin >> pageChoice;
        string pc;
        getline(cin, pc);
        pageChoice = stoi(pc);

        if(pageChoice != -1) {
        for(int z = 0; z < pageTitleResults.size(); z++)
        {
            if(pageChoice == pageTitleResults[z]->getId())
            {
                string name = "";
                int fileNum = pageChoice % 100;
                stringstream fs;
                fs << fileNum;
                fs << ".txt";
                fs >> name;
                string text = "";
                string text1 = "";
                string cmpString = "$#**%";
                ifstream fin3(name);



                while(!fin3.eof())
                {
                    string pageTitle = "";
                    int pageId = 0;
                    fin3 >> pageTitle;
                    fin3.ignore(3);
                    fin3 >> pageId;
                    fin3.ignore();
                    getline(fin3, text1);
                    while(cmpString != text1)
                    {
                        text += text1;
                        getline(fin3, text1);
                    }

                    Page* p = new Page(pageTitle, pageId, text);
                    topPageIndex.insert2(p);
                    //cout << "PAGE TITLE: " << pageTitle << endl;
                    //cout << "PAGE NUMBER:" << pageId << endl;
                    //cout << "TEXT: " << text << endl;
                }
                fin3.close();
                break;
            }
            else
            {
                //do nothing, keep looping until you find page number
            }
        }
        //topPageIndex.print4(cout);
        k = topPageIndex.returnObject(pageChoice);
        cout << k->getText() << endl;
        //cout << k->getText() << endl;
        }//end if statement