如何在适当的地方合并时间间隔?

发布于 2025-01-22 00:09:55 字数 1564 浏览 0 评论 0原文

我正在制作共享费用管理软件,以计算在同一房子内租用房间的人之间的债务。该软件可在 https://github.com/quirinpa/sem 中获得。当某人支付账单时,它发现了谁在场以及在账单期内的时间间隔,然后从中计算出该人的费用,以及他们必须支付多少支付账单的费用。我在这些间隔中使用了两组数据库,一个包括临时叶子,另一组没有。我想确保,当每个人暂时离开时,所有这些时间之间的价格都在所有这些时间之间共享。基本上,它归结为以下问题:

示例1:

      l
o------------o - - - - - - - - - - - - -o
      el                         el
o------------o - - - - - - o------------o
      q                          q
o------------o - - - - - - o------------o

o------------o-------------o------------o
x            w             z            y

L1 = [(x, w, { l, el, q }), (z, y, { el, q })]
L2 = [(x, y, { l, el, q })]
Target = [(x, z, { l, el, q }), (z, y, { el, q })]

示例2:

      l
o------------o
      el                         el
o------------o - - - - - - o------------o
      q                          q
o------------o - - - - - - o------------o

o------------o-------------o------------o
x            w             z            y

L1 = [(x, w, { l, el, q }), (z, y, { el, q })]
L2 = [(x, w, { l, el, q }), (w, y, { el, q })]
Target = [(x, w, { l, el, q }), (w, y, { el, q })]

L1是临时叶子的列表。 L2是不在乎这一点的清单,就在他们开始并停止租房时。 目标是我想要获得的。 每个元素是(min,max,list_of_participant)。 实线是存在有关人员的时期。虚线是它们暂时不存在的时期。没有线路表明该人当时没有租房。

您能帮我找到算法吗? 在代码中使用以找到L1和L2。

I'm making a shared expenses management software to calculate debt between people renting a room within the same house. This software is available at https://github.com/quirinpa/sem. When someone pays a bill, it finds out who is present and during which intervals of time within the billing period, from which it then calculates the cost for that person, and how much they have to pay to who payed the bill. I use two sets of databases for these intervals, one that includes temporary leaves, and another that doesn't. I want to make sure that, when everybody has left temporarily, the price for that amount of time is shared between all of them. Basically it boils down to the following problem:

Example 1:

      l
o------------o - - - - - - - - - - - - -o
      el                         el
o------------o - - - - - - o------------o
      q                          q
o------------o - - - - - - o------------o

o------------o-------------o------------o
x            w             z            y

L1 = [(x, w, { l, el, q }), (z, y, { el, q })]
L2 = [(x, y, { l, el, q })]
Target = [(x, z, { l, el, q }), (z, y, { el, q })]

Example 2:

      l
o------------o
      el                         el
o------------o - - - - - - o------------o
      q                          q
o------------o - - - - - - o------------o

o------------o-------------o------------o
x            w             z            y

L1 = [(x, w, { l, el, q }), (z, y, { el, q })]
L2 = [(x, w, { l, el, q }), (w, y, { el, q })]
Target = [(x, w, { l, el, q }), (w, y, { el, q })]

L1 is the list accounting for temporary leaves.
L2 is the list that doesn't care about that, just when they started and stopped renting a room.
Target is what I want to obtain.
The elements of each is (min, max, list_of_participants).
The solid lines are periods where the person in question is present. The dashed lines are periods where they are temporarily absent. The absence of a line indicates the person is not renting a room at that time.

Can you please help me find the algorithm?
This is related in the sense that it was used in the code, to find L1 and L2.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2025-01-29 00:09:55

我最终是通过查询没有暂停的数据库上的空间隔来解决的。这会产生一些额外的结果,但是很好。请参阅

I ended up fixing this by querying the empty intervals on the databases that do not account for pauses. This produces a few extra results, but it is fine. See here for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文