metrumresearchgroup / mrgsolve

Simulate from ODE-based population PK/PD and QSP models in R
https://mrgsolve.org
129 stars 36 forks source link

Intelligent insertion of records for lagged doses and infusion stop events #1187

Closed kylebaron closed 4 months ago

kylebaron commented 4 months ago

Summary

Every time we start an infusion, we need to figure out when it ends and insert a record for that to happen. This is complicated by the fact that we aren't guaranteed to know the infusion duration for any given dose until we actually give that dose.

Current behavior is to push this dose record on the back of the vector / deque and then re-sort the records. This is fine when the data set is set up to dose in bulk, but really slows down when doses are explicit in the data set and have to be processed one at a time.

By controlled or intelligent insert, I mean we know when the infusion end record happens, so we iterate through the next records until we find the correct insertion point and insert there. With this approach, there is no need to sort. This, along with the deque speeds things up a lot in specific circumstances.

It's a similar story with doses involving lag time: once we know the lag time, we have to insert a record a the time of the original dose plus the lag time. So it's the same problem.