合金事实不是两个属性

时间:2011-11-13 13:47:27

标签: predicate formal-methods model-driven-development fact alloy

我在合金中有一段代码我正在尝试进行餐厅预订系统,我之间有这种信号和关系。

abstract sig Table{
breakfast: one breakFast,
lunch: one Lunch,
dinner: one Dinner
}

sig Free{

}

sig Reserved{

}

sig breakFast {
breakfastfree:one Free,
breakfastReserved:one Reserved
}

sig Lunch {
Lunchfree:one Free,
LunchReserved:one Reserved

} 

sig Dinner  {
Dinnerfree:one Free,
 DinnertReserved:one Reserved
}


fact{
all t1,t2 : Table | t1 != t2 => t1.breakfast != t2.breakfast
all t1,t2 : Table | t1 != t2 => t1.lunch != t2.lunch
all t1,t2 : Table | t1 != t2 => t1.dinner != t2.dinner

 }

 pred RealismConstraints []{

 #Table = 4

 }
  run RealismConstraints for 20

我想说一个事实,早餐它可以保留或免费,并不是在午餐和晚餐中同样的想法吗?

1 个答案:

答案 0 :(得分:1)

首先,您约束breakfastfreebreakfastReserved的方式始终是两者。您需要使用lone(无对象或一个):

sig breakFast {
  breakfastfree:lone Free,
  breakfastReserved:lone Reserved
}

然后,你可以写下这样一个事实:

fact{
  all t: Table | let breakf = t.breakfast |
    #(breakf.breakfastfree+breakf.breakfastReserved) = 1
}

或更简单,只是:

sig breakFast {
  breakfastfree: lone Free,
  breakfastReserved: lone Reserved
}
{
  #(breakfastfree+breakfastReserved) = 1
}

但是,我建议您选择

之类的东西
sig breakFast {
    breakfastReserved: lone Reserved
}

并将no breakfastReserved视为“免费”。那时你不需要任何进一步的事实。