-
Notifications
You must be signed in to change notification settings - Fork 7
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
decrease-key #4
Comments
cc @krlmlr |
Hey, no, it is not yet there, because I never really found use for it. I'll implement it asap. Shouldn't take too long, since I am only interfacing the Boost methods anyways. However, I think I recently submitted to CRAN which recommends submitting only every 2 months afaik. If you are fine with installing from GitHub directly, this isn't an issue though. Cheers, |
Awesome! That would be fantastic! I think I can get by with a GitHub dependency for awhile. The CRAN policies say 1-2 months, and in the past, I have submitted monthly updates with no complaints from CRAN. But how often you submit is up to you. |
Hey, the latest release adds a decrease-key method. If you have a look at the vignette, you can see how the method is used. Let me know if this works out for you, then I'd submit to CRAN. |
Fantastic, @dirmeier! I will look at it ASAP this week. |
Thanks! I forgot to mention that drake could benefit from a priority queue with integer keys, I believe they can be implemented with |
Hey, in the amortized complexity table you can see the data structures that |
I forgot about that paper, but it does look useful. Maybe elsewhere in the huge boost universe? |
So, from a quick look into the stl and Boost data structures I couldn't find something that would suit you. However, my plan in the beginning was anyway to implement most of these into one large package and enforce a class hierarchy similar to Java's (on the R side). So maybe something useful will turn up in future Boost releases. For now, I don't want to implement these data structures myself. |
@dirmeier Thanks for your prompt work! I looked at the vignette, and the usage of |
Hey, yeah that works. If you call
For example, to decrease the key-value pair However, if you have any suggestions to simplify this process, I'd be glad to hear them :) |
Is it possible to look up a handle using a value rather than a key? That's really what I'm after. handle(fheap, value = "a") or even vectorize this somehow? keys <- handle(fheap, values = c("a", "b", "c", "d")) %>%
purrr::map_int(f = function(x) x$key)
decrease_key(fheap, from = keys, to = keys - 1) |
Sure, good idea, I'll add this. Thanks for the feedback. |
Hey, I've added this feature preliminarily with v0.2.3. I'll further optimize/modularize the code on the weekend, currently I am rather busy... Hope that works. From the vignette: h <- handle(fheap, value="V-10")
h
## [[1]]
## [[1]]$handle
## [1] "cac83f38-7a5d-4082-8fd3-0484b4858a98"
##
## [[1]]$key
## [1] 10
##
##
## [[2]]
## [[2]]$handle
## [1] "e066ef06-b0fd-462e-8ca3-c24d48614a15"
##
## [[2]]$key
## [1] 10
decrease_key(fheap, 10, -100, h[[1]]$handle) Note: CXX_STD = CXX14 now, that's why travis complains.. |
Ill submit this to CRAN once I've added some more methods for all the classes. Shouldn't take too long though.. |
Looks great! All I would ask is for |
Forgot to ask for one last thing: how do I list all the values in an Fibonacci heap? Turns out I will need this too if I am going to use |
Usually, this is not a function common for Fibonacci heaps, because it somewhat hurts the purpose of a priority queue, but if helps, I'll add it. Thanks for all the feedback, this is really valueable. :) |
Glad all this is helping you too. How do you suppose we can fix the |
Hey, this shouldn't be an issue. I think if we choose a compiler version that supports C++14 for travis, it will be fine. If travis does not have, returning to C++11 is also not a problem. Sorry for the delay, I am currently quite busy.. |
Hey, Furthermore, in order to make the package suitable to randy3k's question #5 I needed to modify the h <- handle(fheap, value="V-10") This operation before ran in constant time, but required storing the values in an additional map, next to the actual heap data structure. Now it iterates over all nodes in the heap to get to a specific value. Is the value found the handle is returned. For your scenario this is not too optimal, but I find it more reasonable that way. Upon re-reading I am not sure if it got clear what I meant. :D Please let me know if that helped. Cheers, |
Thanks, Simon. I hope to dive back into this soon. I am planning a |
Cool, glad to hear the package has use to someone. I'll put v0.2.5 on CRAN the in the meantime until I have time to work on issue #5 |
Dear @wlandau, in order to be able to use arbitrary R objects with heaps, I think we need to drop the
method. Reason being that, while I can easily compare vectors for equality, this doesn't work if I use SEXPs. Are you still making use of this? |
Thanks for letting me know, Simon. Unfortunately, this probably means I will not be able to use |
The work around I've implemented so far is to get all values from the heap and then keep only the relevant items, e.g. using values(heap) %>%
purrr::keep(~ .x$value == whatever you want) %>%
purrr::map_chr(~.x$"handle") That puts more burden on the user, but will should solve the problem. Once I am done implementing this, I come back to you. |
Hi Will, just forget about my last post. Turns out the C API has a function for comparison of
I still advise to use this cautiously, for non-primitive values, for instance data frames or matrices. |
I am really glad to hear it. I was only planning on using primitive values anyway, and I know the struggle of different users pulling in different directions. Thanks for accommodating. |
I am interested in using a priority queue for ropensci/drake#227, and I am really happy to have found this package. Is there a decrease-key method available? I could not find one in the documentation, and I will need it to modify the priorities in the queue as jobs complete at unpredictable times in a custom scheduler.
The text was updated successfully, but these errors were encountered: