Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW6 #7

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
585 changes: 585 additions & 0 deletions homework/HW1.ipynb

Large diffs are not rendered by default.

419 changes: 419 additions & 0 deletions homework/HW3-DJ.ipynb

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions homework/HW6-DJ.ipynb

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions homework/hw7/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import matplotlib.pyplot as plt

time_quad_search = [70592,33250,35424,18072,15555,16509,32368,12693,11016,20349,52016,33128,11111,41022,35417,12469,38529,31943,12439,10874,38309,35429,11781,10704,13960,14161,29970,34661,31576,13384,11129,15665,47686,34592,11914,14982,36714,12914,18757,12917]

res = range(1,41)

plt.scatter(time_quad_search,res,marker='o')

plt.xlabel('Computation time in ns')
plt.ylabel('Resolution')

plt.title('Plot of Computation time in ns vs Resolution')
plt.show()
49 changes: 42 additions & 7 deletions homework/hw7/quadtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,36 @@ class QuadTree
std::list<Landmark> search(const Position &position, double radius)
{
std::list<Landmark> close_landmarks;
// just fill in your logic here

double dx = m_center.x-position.x;
double dy = m_center.y-position.y;
bool overlap = (sqrt(dx*dx+dy*dy) < (radius+m_size*sqrt(2)));

if(m_landmarks.size() > 0)
{
return m_landmarks;
}

if(m_NE.get() && overlap )
{
close_landmarks.splice(close_landmarks.end(),m_NE->search(position,radius));
}

if(m_SE.get() && overlap)
{
close_landmarks.splice(close_landmarks.end(),m_SE->search(position,radius));
}

if(m_NW.get() && overlap)
{
close_landmarks.splice(close_landmarks.end(),m_NW->search(position,radius));
}

if(m_SW.get() && overlap)
{
close_landmarks.splice(close_landmarks.end(),m_SW->search(position,radius));
}

return close_landmarks;
}

Expand All @@ -146,6 +175,9 @@ class QuadTree

int main(int argc, char const *argv[])
{
int i;
double elap_quad_t[40];

srand(1234); // seed random number generator

Position center{0, 0}; // center of space
Expand Down Expand Up @@ -190,7 +222,7 @@ int main(int argc, char const *argv[])
std::chrono::high_resolution_clock::now() - start)
.count();
std::cout << "search landmarks brute force,\telapsed time "
<< elapsed_brute_force_search << " ns" << std::endl;
<< elapsed_brute_force_search << " ns" << std::endl;
// output close landmarks
for (auto &lm : close_landmarks_brute_force)
{
Expand All @@ -205,23 +237,26 @@ int main(int argc, char const *argv[])
tree.insert(lm);
}
double elapsed_quadtree_insert = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now() - start)
.count();
std::chrono::high_resolution_clock::now() - start)
.count();
std::cout << ",\telapsed time " << elapsed_quadtree_insert << " ns" << std::endl;

// quadtree search
std::cout << "quadtree searching";
start = std::chrono::high_resolution_clock::now();
std::list<Landmark> close_landmarks_quadtree = tree.search(vehicle_position, search_radius);
double elapsed_quadtree_search = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now() - start)
.count();
std::chrono::high_resolution_clock::now() - start)
.count();
std::cout << ",\t\telapsed time " << elapsed_quadtree_search << " ns" << std::endl;

for (auto &lm : close_landmarks_quadtree)
{
std::cout << "id: " << lm.id << " x: " << lm.pos.x << " y: " << lm.pos.y << std::endl;
}

std::cout << "quadtree speed up: " << elapsed_brute_force_search/elapsed_quadtree_search << std::endl;


return 0;
}
}
419 changes: 419 additions & 0 deletions lectures/HW3-DJ.ipynb

Large diffs are not rendered by default.