80 lines
1.9 KiB
C++
80 lines
1.9 KiB
C++
//Homework 4 for the University of Tulsa's CS-7353 Analysis of Algorithms Course
|
|
//C++ code for solving the Hidden Lines Problem with a Divide and Conquer strategy in O(nlogn)
|
|
//Professor: Dr. Schoenefeld, Spring 2022
|
|
//Noah Schrick - 1492657
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
|
|
#include "Line.h"
|
|
|
|
//Line data for this problem is stored in a CSV file
|
|
std::vector<Line> construct_HWprob()
|
|
{
|
|
//Vector to hold all our Lines
|
|
std::vector<Line> lines;
|
|
//Hold our doubles from each line
|
|
std::vector<double> tmp_data;
|
|
|
|
std::ifstream data("../data/data.csv");
|
|
if(data.is_open())
|
|
{
|
|
std::string csvline;
|
|
|
|
//Throw header row away
|
|
std::getline(data, csvline);
|
|
while(std::getline(data, csvline, ',')){
|
|
if(!csvline.empty()){
|
|
tmp_data.emplace_back(std::stod(csvline));
|
|
}
|
|
}
|
|
}
|
|
|
|
data.close();
|
|
|
|
while(!tmp_data.empty()){
|
|
double slope = *tmp_data.begin();
|
|
tmp_data.erase(tmp_data.begin());
|
|
|
|
if(tmp_data.empty()){
|
|
std::cout << "Error in CSV file: Number of slope entries does not match the number of y-intercept entries. ";
|
|
std::cout << "Please correct the CSV file and try again." << std::endl;
|
|
exit(-1);
|
|
}
|
|
double ycept = *tmp_data.begin();
|
|
tmp_data.erase(tmp_data.begin());
|
|
|
|
Line newline = Line(slope, ycept);
|
|
lines.push_back(newline);
|
|
}
|
|
|
|
return lines;
|
|
}
|
|
|
|
std::vector<Line> visible_lines(std::vector<Line> lines)
|
|
{
|
|
std::vector<Line> line_sol;
|
|
|
|
return line_sol;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
std::cout << "Constructing Problem..." << std::endl;
|
|
std::vector<Line> lines = construct_HWprob();
|
|
|
|
int i = 0;
|
|
for(Line line : lines)
|
|
{
|
|
std::cout << "Line " << i << " has slope " << line.get_slope() << " and a y-intercept of " << line.get_ycept() << std::endl;
|
|
i++;
|
|
}
|
|
|
|
std::vector<Line> line_sol = visible_lines(lines);
|
|
}
|
|
|