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

Optimized just slower than Default approach #13

Open
YJack0000 opened this issue Jun 9, 2024 · 3 comments
Open

Optimized just slower than Default approach #13

YJack0000 opened this issue Jun 9, 2024 · 3 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@YJack0000
Copy link
Owner

Screenshot 2024-06-09 at 10 17 53 PM

As I demonstrated in the presentation, the post iteration phase is excessively time-consuming, making the quadtree solution slower than the brute force approach. To resolve this issue, additional profiling is needed. Currently, using the optimized solution does not make sense due to its inefficiency.

@YJack0000 YJack0000 added the invalid This doesn't seem right label Jun 9, 2024
@YJack0000
Copy link
Owner Author

In OptimizedSpatialIndex.cpp

/**
 * @brief Updates the position of an object in the spatial index.
 *
 * @param object The object to update.
 * @param newX The new x-coordinate of the object.
 * @param newY The new y-coordinate of the object.
 */
template <typename T>
void OptimizedSpatialIndex<T>::update(const T& object, float newX, float newY) {
    if (!inBounds(std::make_pair(newX, newY))) {
        std::stringstream ss;
        ss << "Update coordinates (" << newX << ", " << newY << ") out of bounds. ";
        ss << "Size: " << size;
        throw std::out_of_range(ss.str());

        return;
    }

    remove(object);
    insert(object, newX, newY);
}

The remove and insert cost a lot of time
Screenshot 2024-07-22 at 4 06 41 PM

Comparing to the DefaultSpatialIndex.cpp
Screenshot 2024-07-22 at 4 07 22 PM

@YJack0000
Copy link
Owner Author

For n Organism,
Default approach can cost O(n) for update all of the organism
QuadTree approach can cost O(n) * (O(log n) + O (logn)) => O(n logn)

But the total time consumption can be O(n^3) for Default approach
And O(nlogn) for QuadTree approach

@YJack0000
Copy link
Owner Author

YJack0000 commented Jul 22, 2024

It's weird that the postIteration in OptimizedSpatialIndex cost more time than the time DefaultSpatialIndex spend on query.
However, when the amount of organism is large enough, we can observer extreme lower query time reduction by using quadtree.

@YJack0000 YJack0000 self-assigned this Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant