예제 #1
0
void adjustByIMUData(sensor_msgs::PointCloud& cloud) {
	for(int i = 0; i < cloud.points.size(); ++i) {
		geometry_msgs::Point32 curPoint = cloud.points[i];
		Eigen::Vector3f curVec(curPoint.x, curPoint.y, curPoint.z);
		curVec = set_pitch(imu_pitch) * set_roll(imu_roll) * curVec;
		cloud.points[i].x = curVec[0];
		cloud.points[i].y = curVec[1];
		cloud.points[i].z = curVec[2];
	}
}
mat AdultParser::getInstances() {
    ifstream infile(this->instancePath);
    string line;
    vector<vec> instances;
    while (getline(infile, line))
    {
        vector<string> splitLine = split(line, ',');
        vec curVec(123);
        for(int i=0;i<splitLine.size(); i++){
            curVec(i) = stof(splitLine[i]);
        }
        instances.push_back(curVec);
    }
    mat X(instances.size(), instances[0].n_rows);
    for (int i = 0; i < instances.size(); i++) {
        for (int j = 0; j < instances[0].n_rows; j++) {
            X(i, j) = instances[i][j];
        }
    }
    return X;
}
예제 #3
0
void GLWidget::CalculateNarrowPath()
{
    for(int b = 0; b < _actualGridSize.height() - 1; b++)
    {
        for(int a = 0; a < _actualGridSize.width() - 1; a++)
        {
            AVector curVec(_gridSpacing *  a,      _gridSpacing * b);
            AVector rVec  (_gridSpacing * (a + 1), _gridSpacing *  b    );
            AVector dVec  (_gridSpacing *  a     , _gridSpacing * (b + 1));
            AVector drVec (_gridSpacing * (a + 1), _gridSpacing * (b + 1));

            // horizontal
            if(IntersectHorizontalLine(curVec) &&
               IntersectHorizontalLine(rVec)   &&
               IntersectHorizontalLine(dVec) &&
               IntersectHorizontalLine(drVec)   )
            {
                _cells[a][b]._straightness = Straightness::ST_HORIZONTAL;
                std::cout << "-";
            }
            // vertical
            else if(IntersectVerticalLine(curVec) &&
                    IntersectVerticalLine(rVec) &&
                    IntersectVerticalLine(dVec) &&
                    IntersectVerticalLine(drVec))
            {
                _cells[a][b]._straightness = Straightness::ST_VERTICAL;
                std::cout << "|";
            }
            else
            {
                _cells[a][b]._straightness = Straightness::ST_DIAGONAL;
                std::cout << ".";
            }
        }
        std::cout << "\n";
    }

    std::cout << "\n";
    std::cout << "\n";
}
예제 #4
0
/**************************************************************
 * *  This main function creates a vector of randomly generated integers
 * *  for use in testing the implementations of Algorithms 1-4. The first part measures
 * *  the running time in ms for each Algorithm for display. The second part tests
 * *  input output by reading input from a specified text file, running each Algorithm
 * *  on this input, and writing the results to another specified text file.
 * ***************************************************************/
int main(int argc, char* argv[]){	

	std::string filename;
	std::string outputfilename;


	/* The first argument (argc) is the number of elements in the array so we should have two elements the program name and file name 
	Credit: http://www.site.uottawa.ca/~lucia/courses/2131-05/labs/Lab3/CommandLineArguments.html
	*/
    if(argc != 2)
    {
        std::cout << "Please enter an input filename." << std::endl << std::endl;
        exit(1);
    }
	/* which is the second argument (argv). The second argument is always an array of char*, */
    else
    {      
        filename = std::string(argv[1]);
		std::string tempoutputfilename = std::string(argv[1]);
		//http://www.cplusplus.com/reference/string/string/length/
		int strsize = tempoutputfilename.length() - 4;
		/* http://www.cplusplus.com/reference/string/string/operator+/ 
		http://www.cplusplus.com/reference/string/string/substr/ */
		outputfilename = (tempoutputfilename.substr(0, strsize)) + "change.txt";
		std::cout << outputfilename << std::endl;
	}
	//cout << filename << endl;
	/* Stream class provided by C++ to read from files
	Credit: http://www.cplusplus.com/doc/tutorial/files/*/
	/* In order to open a file with a stream object we use its member function open
     * http://stackoverflow.com/questions/16552753/no-matching-function-ifstream-open */
        std::ifstream textfile(filename);
	/* To check if a file stream was successful opening a file, you can do it by calling to member is_open
	Credit: http://www.cplusplus.com/doc/tutorial/files/*/
    if(!textfile.is_open())
    {
        std::cout << "The file could not be opened." << std::endl;
        textfile.close();
        exit(1);
    }
	/* Call function to put first alternating lines as the coin set input and the second alternating lines as total change V */
    std::vector< std::vector<int> > coinsetinput;
    std::vector<int> changevalueV;
    getinput( textfile, coinsetinput, changevalueV );
    textfile.close();

	/* Stream class to write on files
	Credit: http://www.cplusplus.com/doc/tutorial/files/*/	
    /*http://stackoverflow.com/questions/16552753/no-matching-function-ifstream-open*/
    std::ofstream textfile2(outputfilename);

    if(!textfile2.is_open())
    {
        std::cout << "Cannot open for writing. Check the permissions of the directory." << std::endl;
        textfile2.close();
        exit(1);
    }
	 /*Display a babel for brute force algorithm time trial 
    std::cout << "Testing changeslow...." << std::endl;
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        // Run brute force algorithm on input numbers from first to last element 
		std::vector<int> coinCount;
		runtimetrial( changeslow, coinsetinput.at(i), changevalueV.at(i), coinCount );
    }
	// Display a babel for greedy algorithm time trial 
    std::cout << "Testing changegreedy...." << std::endl;
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        // Run greedy algorithm on input numbers from first to last element 
		std::vector<int> coinCount;
        runtimetrial( changegreedy, coinsetinput.at(i), changevalueV.at(i), coinCount);
    }
    // Display a babel for dynamic programming algorithm time trial 
    std::cout << "Testing changedp...." << std::endl;
    //for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
         Run greedy algorithm on input numbers from first to last element 
		
    }*/
	/* Call function to output is to be written to text file 
    textfile2 << "Brute Force \n\n";
	 // Run changeslow algorithm on input numbers
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        std::vector<int> coinCount;
        int minCoins = changeslow( coinsetinput.at(i), changevalueV.at(i), coinCount );
        writeResults( textfile2, coinCount, minCoins );
    }
	// Call function to output is to be written to text file 
    textfile2 << "Greedy\n\n";
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
        std::vector<int> coinCount;
        int minCoins = changegreedy(coinsetinput.at(i), changevalueV.at(i), coinCount);
        writeResults( textfile2, coinCount, minCoins );
    }
	// Call function to output is to be written to text file */
    textfile2 << "Dynamic Programming\n\n";
    for( unsigned int i = 0; i < coinsetinput.size(); i++ )
    {
		if(!coinsetinput.at(i).empty()){
			printf("\n\n%d Results %d\n", i, i);
			struct coinChange result; 
            std::vector<int> curVec ( coinsetinput.at(i) );            
            Changedp::dpChange(curVec, changevalueV.at(i), result);	
			for(unsigned int y = 0; y<coinsetinput.at(i).size(); ++y){
				printf("%d\t", coinsetinput.at(i).at(y));
			}
			printf("\nmin coins = %d\tSumVal = %d\tResult array\n", result.coins, changevalueV.at(i));
			for(unsigned int y = 0; y<result.resultVec.size(); ++y){
				printf("%d\t", result.resultVec.at(y));
			}		

			writeResults( textfile2, result.resultVec, result.coins );
		}
	}
    textfile2.close();	
}