Open FrederikSchaff opened 6 years ago
Thanks for the suggestion! To add this function to LSD, we would need to introduce a new category of elements to the LSD macro language, that is, pointer to functions or C++ containers. Also, it is not clear to me how useful such extension would be to a broader audience. As you know, I'm personally not very favorable to move non-essential elements to the macro language. On the other hand, it seems to me that a personal standalone macro/function to perform such kind of job can be added to LSD without any change to the core LSD code (you could start from the code of draw_rnd member function), particularly because no modification to the internal object structure is required (so no risk of messing things).
Hi,
the macro could still work the same way. I have implemented some such macros in the context of the GIS module. However, c++ structures are necessary. Let's pause this discussion, until a while after I added the GIS module as a separate branch here, as discussed with Marco.
Problem description: Currently, RNDDRAW(S) moves twice through the list of objects. Once to gather the probabilities and once more, until the position indicated by the random draw. Sometimes one may want to define the probabilities based on a conditional dummy that takes values of 0.0 or 1.0, respectively. In other words, the random draw should be a fair draw in a subset. In this case, the conditional value might even be calculated by a function inside the object of interest. It would then be good, if there would only be a single run through all the objects.
Potential solution: A temporary list of object pointers which holds the candidates. The set is divided in elements with weights < 1.0 and >= 1.0, the latter being part of the list. After the single run, one candidate of the subset can be returned randomly. In cpp11 std::deque would be good for holding such a list (random access, no memory reallocation). A macro could be something like: RNDDRAW_DUMMY(LS).