Code cleanup and updating comments

This commit is contained in:
Noah L. Schrick 2022-03-08 10:46:14 -06:00
parent 31e585280d
commit 99f427bea4
5 changed files with 30 additions and 9 deletions

Binary file not shown.

Binary file not shown.

View File

@ -11,6 +11,7 @@
HL::HL()
{
//Read from CSV and construct the problem from the given lines
lines = construct_HWprob();
}
@ -19,10 +20,12 @@ void HL::print_sol()
std::cout << "Not yet implemented" << std::endl;
}
//Divide and Conquer Strategy using recursive call to divide ls and merge using merge()
std::set<Line> HL::gen_sol(std::set<Line>& ls){
if (ls.size() > 2){
HL inst = *this;
//Create left and right half sets
int split = ceil(ls.size()/2);
std::set<Line> lh;
std::set<Line> rh;
@ -39,33 +42,45 @@ std::set<Line> HL::gen_sol(std::set<Line>& ls){
rh.insert(*itr);
}
//Recursive call
return merge(inst.gen_sol(lh), inst.gen_sol(rh));
}
//Set with 2 lines is a base case: both are visible at +-inf respectively, and intersection is where they change
//visibility
else if (ls.size() == 2){
auto l1 = *(ls.begin());
auto l2 = *(ls.end());
double isec = (l2.get_ycept() - l1.get_ycept())/(l1.get_slope() - l2.get_slope());
l1.set_vis_start(-std::numeric_limits<double>::infinity());
l1.set_vis_end(isec);
l2.set_vis_start(isec);
l2.set_vis_end(std::numeric_limits<double>::infinity());
//Smaller Slope: vis from isec to inf
l1.set_vis_start(isec);
l1.set_vis_end(std::numeric_limits<double>::infinity());
//Greater Slope: vis from -inf to isec
l2.set_vis_start(-std::numeric_limits<double>::infinity());
l2.set_vis_end(isec);
return ls;
}
//Set with 1 line: vis at +-inf
else{
auto l1 = *(ls.begin());
l1.set_vis_start(-std::numeric_limits<double>::infinity());
l1.set_vis_end(std::numeric_limits<double>::infinity());
return ls;
}
return sol;
}
std::set<Line> HL::construct_HWprob(){
//Vector to hold all our Lines
//Set to hold all our Lines
std::set<Line> lines;
//Hold our doubles from each line
std::vector<double> tmp_data;
@ -81,7 +96,7 @@ std::set<Line> HL::construct_HWprob(){
}
}
}
//Close file
data.close();
while(!tmp_data.empty()){
@ -113,6 +128,15 @@ std::set<Line> merge(std::set<Line> lh, std::set<Line> rh){
while(litr != lh.end() && ritr != rh.end()){
Line l1 = *litr;
Line l2 = *ritr;
if(l1.get_slope() < l2.get_slope()){
litr++;
continue;
}
else{
}
}
}

View File

@ -16,13 +16,10 @@ class HL
std::set<Line> get_lines();
std::set<Line> get_sol();
private:
std::set<Line> sol;
std::set<Line> lines;
std::set<std::pair<Line, double>> isec;
};
std::set<Line> merge(std::set<Line> lh, std::set<Line> rh);