Vector functions and setting most negative and most postive slope visible ranges
This commit is contained in:
parent
7b00f0fd3b
commit
928d02d947
Binary file not shown.
Binary file not shown.
BIN
build/libHLlib.a
BIN
build/libHLlib.a
Binary file not shown.
BIN
build/main
BIN
build/main
Binary file not shown.
@ -37,6 +37,8 @@ void HL::print_sol()
|
||||
if(stop_range == std::numeric_limits<double>::max())
|
||||
stop_print = "inf";
|
||||
|
||||
if (start_range == stop_range)
|
||||
continue;
|
||||
std::cout << "Line ID " << std::get<0>(*itr) << " visible from x=" <<
|
||||
start_print << " to x=" << stop_print << std::endl;
|
||||
}
|
||||
@ -196,42 +198,35 @@ std::vector<Line> HL::construct_HWprob(){
|
||||
Line newline = Line(slope, ycept);
|
||||
newline.set_id();
|
||||
sorted_lines.insert(newline);
|
||||
lines.push_back(newline);
|
||||
|
||||
auto line_holder = get_map();
|
||||
//line_holder[newline.get_id()] = newline;
|
||||
line_holder.insert(std::pair<int, Line> (newline.get_id(), newline));
|
||||
}
|
||||
|
||||
//Set most neg slope to start range of -inf, and most pos to stop of inf
|
||||
Line lend = *lines.end();
|
||||
Line lbegin = *lines.begin();
|
||||
lend.set_vis_end(std::numeric_limits<double>::max());
|
||||
lbegin.set_vis_start(std::numeric_limits<double>::lowest());
|
||||
|
||||
std::string lend_stop = std::to_string(lend.get_vis_end());
|
||||
std::string lbegin_start = std::to_string(lbegin.get_vis_start());
|
||||
if(lend.get_vis_end() == std::numeric_limits<double>::max())
|
||||
lend_stop = "inf";
|
||||
if(lbegin.get_vis_start() == std::numeric_limits<double>::lowest())
|
||||
lbegin_start = "-inf";
|
||||
//Copy set to vector
|
||||
std::copy(sorted_lines.begin(), sorted_lines.end(), std::back_inserter(lines));
|
||||
|
||||
//Display Sorted Vector
|
||||
std::cout << "---------------Sorted Lines by slope:---------------" << std::endl;
|
||||
for(Line line : sorted_lines)
|
||||
for(std::vector<Line>::iterator it = lines.begin(); it != lines.end(); it++)
|
||||
{
|
||||
Line line = *it;
|
||||
std::cout << "Line " << line.get_id() << " has slope " << line.get_slope()
|
||||
<< " and a y-intercept of " << line.get_ycept() << std::endl;
|
||||
std::cout << "Line " << line.get_id() << " visible from x=" << line.get_vis_start() << " to x=" <<line.get_vis_end() << std::endl;
|
||||
|
||||
if (it == lines.begin()){
|
||||
line.set_vis_start(std::numeric_limits<double>::lowest());
|
||||
std::cout << "Changed Line " << line.get_id() << " start vis to " << line.get_vis_start() << std::endl;
|
||||
*it = line;
|
||||
}
|
||||
if (it == (std::prev(lines.end()))){
|
||||
line.set_vis_end(std::numeric_limits<double>::max());
|
||||
std::cout << "Changed Line " << line.get_id() << " stop vis to " << line.get_vis_end() << std::endl;
|
||||
*it = line;
|
||||
}
|
||||
}
|
||||
std::cout << "-----------------------------------------------------" << std::endl;
|
||||
|
||||
std::cout << "From the sorted lines, we can derive that Line " << lend.get_id() << " is visible from x=" << lend.get_vis_start() <<
|
||||
" to x=" << lend_stop << std::endl;
|
||||
|
||||
std::cout << "From the sorted lines, we can derive that Line " << lbegin.get_id() << " is visible from x=" << lbegin.get_vis_start() <<
|
||||
" to x=" << lbegin.get_vis_end() << std::endl;
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
@ -13,9 +13,6 @@ int main(int argc, char *argv[])
|
||||
HL inst = HL();
|
||||
std::cout << std::endl;
|
||||
|
||||
Line tmp = *inst.get_lines().end();
|
||||
std::cout << "Line "<< tmp.get_id() << " vis from x=" << tmp.get_vis_start() << " to x=" << tmp.get_vis_end() << std::endl;
|
||||
|
||||
std::cout << "Generating Solution.\n" << std::endl;
|
||||
auto lines = inst.get_lines();
|
||||
inst.gen_sol(lines);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user