按 Alloy 中的日期获取物品

发布于 2024-09-29 21:23:39 字数 745 浏览 0 评论 0原文

我被这个正式方法作业问题困住了,我不确定我哪里做错了。

我有两个签名,Item 和 ToDo,它们的定义如下:

sig Item {
    due : Date lone -> Step,
    category : Category lone -> Step
}

one sig ToDo {
    list : (seq Item) -> Step,
    current : Item lone -> Step,
    completed : Item -> Step
}

我必须定义一个函数,将具有给定日期和类别的 Item 插入 ToDo 的列表集中。诀窍是列表集应该按项目的到期日期排序。步骤和日期都有顺序。

我的问题是:如何获取 ToDo.list 中具有特定日期的项目集?我已经有了这个功能:

fun tasksWithDate[d : Date, st : Step, t : set Item]: set Item

我尝试使用以下代码(及其变体)来获取 Item 集:

t.due.st.d

这不起作用,我明白为什么,因为 t.due.st 留下了一组日期。然而,从那时起的其他尝试并没有让我到达那里。我尝试使用括号让它在到达 t 之前评估“due.st”和“d”之间的连接,但这不起作用,我尝试使用方括号来更改顺序,但是那不起作用。我知道我在这里做错了什么,但我不知道是什么。

I'm stuck on this formal methods homework problem and I'm not sure what I'm not getting right.

I have two signatures, Item and ToDo which are defined as so:

sig Item {
    due : Date lone -> Step,
    category : Category lone -> Step
}

one sig ToDo {
    list : (seq Item) -> Step,
    current : Item lone -> Step,
    completed : Item -> Step
}

I have to define a function which inserts an Item with a given date and category into the list set of ToDo. The trick is that the list set is supposed to be ordered by the due date of the items. There is ordering on both Step and Date.

My question is: How do I get the set of Items in ToDo.list with a specific date? I've got the function:

fun tasksWithDate[d : Date, st : Step, t : set Item]: set Item

And I've tried using the following code (and variations thereof) to get the set of Item:

t.due.st.d

This doesn't work, and I understand why because t.due.st leaves a set of dates. However other attempts from that point don't get me there. I've tried using parentheses to get it to evaluate the join between "due.st" and "d" before getting to the t, but that doesn't work and I've tried using square brackets to change the order, but that doesn't work. I know I'm doing something wrong here, but I can't figure out what.

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

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

发布评论

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

评论(1

甜妞爱困 2024-10-06 21:23:39

我提出的解决方案如下:

let r = t -> t.due.st {
    r.d
}

它所做的是创建一组 t 与 t 的到期日期的关系。然后,它与所需日期执行连接,返回包含该日期的所有 t。

The solution that I came up with is the following:

let r = t -> t.due.st {
    r.d
}

What this is doing is creating a set of relations of t to the due date of t. It then performs a join with the desired date returning all t with that date.

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