//--------------------------------------------------------------------
void drawht(apvector<int> &yhand,apvector<int> &ytabel,const apvector<apstring> &ydeck)
{
	cout<<"\nhand\n-------\n";
	for(int k=0;k<yhand.length();k++)
	{
		cout<<k+1<<","<<ydeck[yhand[k]]<<endl;
	}
	cout<<"\nTabel\n-------\n";
	for(int z=0;z<ytabel.length();z++)
	{
		cout<<z+1<<","<<ydeck[ytabel[z]]<<endl;
	}
}
Exemple #2
0
void dataset::get_act_bins(apvector<UNSIGNED_4B_TYPE> &abins, UNSIGNED_4B_TYPE nbins, bool ifbsame)
{
	//abins.resize(0);
	if (nbins < 2) return;

	abins.resize(nbins);
	UNSIGNED_4B_TYPE i, N = act.length(), r = N / nbins;
	if (ifbsame)
	{
		for (i = 0; i < nbins; i++) abins[i] = r;
	}
	else
	{
		REALNUM_TYPE aBin, aRange; 
		aRange = get_MaxAct() - get_MinAct();
		aBin = aRange / nbins;
		REALNUM_TYPE aPrev = get_MinAct() - aRange, aNext = get_MinAct() + aBin;
		for (i = 0; i < nbins; i++)
		{
			aNext = (i == nbins-1) ? (get_MaxAct() + aRange) : (get_MinAct() + aBin*(i+1));
			abins[i] = get_ActPoints(aPrev, aNext).Size();
			aPrev = aNext;
		}		
	}

	//check abins
	for (r = i = 0; i < nbins; i++) r += abins[i];
	for (i = 0; i < nbins; i++)
	{
		if (r == N) break;
		if (r < N) { abins[i]++; r++; };
		if (r > N) { abins[i]--; r--; };
	}
}
// Show closest X stops to a given ID
apvector <ID> closestXtoID(apvector <apstring> & id, apmatrix <int> & dist, int x, apstring stopID) //absolute value? divide by 100?
																	//which is the starting point? (r or c?)
{
//	apstring stopID;

//	stopID = "453933W        ";

//	int x;	// the variable which will hold how many data points are to be found
//	cout<<"Please enter x (between 1 and 446, inclusive): ";
//	cin>>x;

	int n = id.length();

	int r=0;
	while(id[r]!=stopID)	//locate the corresponding row of distances in the matrix
		r++;
		
	apvector <ID> rowOfInterest(n + 1);

//	int n=447;
	for(int c=0; c<n; c++)	//copy the row of distances as well as the vector of stopIDs correspondingly
	{
		rowOfInterest[c].distance=dist[r][c];
		rowOfInterest[c].stopID=id[c];
	}

	quicksort(rowOfInterest, 0, 447);

	for(int b=1; b<=x; b++)	//starts from 1 because rowOfInterest[0] contains 0
	{
		rowOfInterest[b].distance = convertDistance(rowOfInterest[b].distance);
	}

	return rowOfInterest;
}
Exemple #4
0
int howMany (apvector<int> vec, int value) {
  int count = 0;
  for (int i=0; i< vec.length(); i++) {
    if (vec[i] == value) count++;
  }
  return count;
}
Exemple #5
0
apvector<itemType>::apvector(const apvector<itemType> & vec)
// postcondition: vector is a copy of vec
    : mySize(vec.length()),
      myList(new itemType[mySize])
{
    int k;
        // copy elements
    for(k = 0; k < mySize; k++){
        myList[k] = vec.myList[k];
    }
}
//--------------------------------------------------------------------
char drawtwo(apvector<int> &hand,apvector<int> &num)
{
	char two;
	int leng=hand.length();
	hand.resize(leng+2);
		for(int i=leng;i<hand.length();i++)
		{
			while(hand[i]<=0)
			{
				int temp=rand()%numofcards;
				if(num[temp]>0)
				{
					hand[i]=temp;
					num[temp]--;
				}
			}
		}
		cout<<"Continue again(y or n)==> \n";
		cin>>two;
		return two;
}
void carddown(apvector<int> &hand,int cr,apvector<int> &tabl)
{
	int you=cr-1,len,temp,tmp;
	if(tabl[0]==-1)
		tabl[0]=hand[you];
	else
	{
		len=tabl.length();
		tabl.resize(len+1);
		tabl[len]=hand[you];
	}
		for(int c=0;c<hand.length();c++)
		{
			tmp=hand.length();
			if(c>=you)
			{
				if(c<tmp-1)
				{
					temp=hand[c+1];
					hand[c]=temp;
				}
			}
		}
		len=hand.length();
		hand.resize(len-1);
	
}
// Show all stops inside a certain radius
apvector <ID> withinOneRadius(apvector <apstring> & id, apmatrix <int> & dist, double rad, apstring theid)
{

	int n = id.length();

//	double rad;

//	cout << "Enter the desired radius to be searched in: "; // ?? should radius be *100 or not??
//	cin >> rad;

//	apstring theid;

//	we hate getline
//	cout << "Enter the stop ID for which you would like the radii: ";
//	getline(cin, theid);

//	theid = "2051051WB007   ";

	// now should search the stopID file for the value of the node in id
	int row = 0;
	while ( theid != id[row] ) // assumes that id1 was entered correctly
	{
//		cout << id[row];
		row++;
	}

	apvector <ID> withinRad(n + 1);

	ID temp;

	int col, count = 0;
	for ( col = 0; col < dist.numcols(); col++)
	{
		if ( convertDistance(dist[row][col]) <= rad )
		{
			temp.stopID = id[col];
			temp.distance = convertDistance(dist[row][col]);
			// the distance is dist[row][col], will eventually be added to a data structure?
//			cout << id[col] << " is within the radius with distance of " << convertDistance(dist[row][col]) << endl;
			
			withinRad[count] = temp;
			count ++;
		}
	}

	withinRad.resize(count + 1); // resize the array to be smaller and not wasteful
	return withinRad;
} 
Exemple #9
0
apvector<itemType>::apvector(const apvector<itemType> & vec)
// postcondition: vector is a copy of vec
    : mySize(vec.length()),
      myList(0)
{
	if (mySize == 0)
		return;

	myList = new itemType[mySize];
    
        // copy elements
    for(int k = 0; k < mySize; k++)
	{
        myList[k] = vec.myList[k];
    }
}
void inputData(apvector <apstring> & firstCutraStopId, apmatrix <int> & dist)
{
	// must be changed
	int N = 447;
	// must be changed


	firstCutraStopId.resize(N); // a vector of the stop ID names
	char temp[15];

	ifstream stopIdFile; // stream for the IdFile
	stopIdFile.open("CR0923.id"); // opening the stopID file
	int c = 0; // counter for the loop
	while ( ! stopIdFile.eof() ) // loop reads in every element from the file and puts it in the array
	{
		stopIdFile.getline(temp, 17, '\n'); // get the next line and store it to the temporary char array
		firstCutraStopId[c] = temp; // put the char array into the vector of strings
		c++; // incriment
	}

	int oriDestcount = N; // number of stopIDs
	int *inrecord=0; // pointer for an array of ints (i think)
	inrecord= new int[oriDestcount]; // point the pointer to a new array

	ifstream inMatrix; // stream for reading in the matrix data
	inMatrix.open("CR0923.mt2", ios::binary); // open the matrix file for binary reading

	// matrix //
	dist.resize(447, 447); // create an apmatrix for storing all the distances

	for (int kkn=0; kkn < N; kkn++) // a loop that will go through each line of the file
	{
		inMatrix.seekg(kkn*(oriDestcount)*sizeof(int)); // not sure what this does

		inMatrix.read(reinterpret_cast<char *> (inrecord), oriDestcount*sizeof(int)); // not sure what this does

		for (int nnk=0; nnk<oriDestcount; nnk++) // nested loop which reads in each data point from the line
		{
			dist[kkn][nnk] = inrecord[nnk]; // puts numbers into matrix
		}
	}
	inMatrix.close(); // close the strean
	delete [] inrecord; // delete the temporary array
}
Exemple #11
0
const apvector<itemType> &
apvector<itemType>::operator = (const apvector<itemType> & rhs)
// postcondition: normal assignment via copying has been performed;
//                if vector and rhs were different sizes, vector
//                has been resized to  match the size of rhs
{
    if (this != &rhs)                           // don't assign to self!
    {
        delete [] myList;                       // get rid of old storage
        mySize = rhs.length();
        myList = new itemType [mySize];         // allocate new storage

            // copy rhs
        int k;
        for(k=0; k < mySize; k++)
        {
            myList[k] = rhs.myList[k];
        }
    }
    return *this;                               // permit a = b = c = d
}
// Show all stops inside a certain radius for all stops
apvector <apvector <ID> > withinAllRadius(apvector <apstring> & id, apmatrix <int> & dist, double rad)
{

	int n = id.length();

//	double rad;

//	cout << "Enter the desired radius to be searched in: "; // ?? should radius be *100 or not??
//	cin >> rad;

	int row = 0;
	int col;
	int count = 0;

	apvector <ID> withinRad(n + 1);
	ID temp;
	apvector <apvector <ID> > allRadii(n + 1);

	for ( row = 0; row < dist.numrows(); row++)
	{
		for ( col = 0; col < dist.numcols(); col++)
		{
			if ( convertDistance(dist[row][col]) <= rad && row != col)
			{
				temp.stopID = id[col];
				temp.distance = convertDistance(dist[row][col]);
				// the distance is dist[row][col], will eventually be added to a data structure?
//				cout << convertDistance(dist[row][col]) << '\t';
				withinRad[count] = temp;
				count ++;
			}
		}
		allRadii[row] = withinRad;
//		cout << endl << "--------------------------------------------" << endl;
	}

	return allRadii;
}
//Show closest X stops and their distance to all stops
apvector <apvector <ID> > closestXtoALL(apvector <apstring> & id, apmatrix <int> & dist, int x)
{

	int n = id.length();

//	int x; // again, the number of data points needed
//	cout<<"please enter x (between 1 and 446, inclusive): ";
//	cin>>x;
	apvector <ID> rowOfInterest(n + 1); // will be changed each iteration of k, old one will be added to allrows

	apvector <apvector <ID> > allrows(n + 1); // work on being able to return all the different vectors to the GUI


	for (int k=0; k<447; k++)	//each iteration of the loop shows closest X stopIDs to 1 ID
								//unfortunately the function closestXtoID cannot be called here
								//because apvector <ID> cannot be passed as a parameter
	{
//		int n=447;
		double cdist;
		for(int c=0; c<n; c++)
		{
			rowOfInterest[c].distance=dist[k][c];
			rowOfInterest[c].stopID=id[c];
		}

		quicksort(rowOfInterest, 0, n);

		for(int b=1; b<=x; b++)	
		{
			rowOfInterest[b].distance = convertDistance(rowOfInterest[b].distance);
		}

		allrows[k] = rowOfInterest;

	}

	return allrows;
}
Exemple #14
0
void Deck::print () const {
    for (int i = 0; i < cards.length(); i++) {
        cards[i].print ();
    }
}
Exemple #15
0
void printVector (apvector<int> vec) {
  for (int i = 0; i<vec.length(); i++) {
    cout << vec[i];
  }
}