0

I have a piece of code in ALLOY I am trying to do a restaurant reservation system and I have this sig and relation between them.

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

I want to put a fact that for breakfast it can be reserved or free NOT BOTH and in lunch and dinner the same thing any ideas?

Rüdiger Hanke
  • 6,215
  • 2
  • 38
  • 45
dori naji
  • 980
  • 1
  • 16
  • 41

1 Answers1

1

First, the way you've constrained breakfastfree and breakfastReserved it will always be both. You need to use lone (no object or one):

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

Then, you could write the fact:

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

or, simpler, just:

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

However, I'd suggest that you just go with something like

sig breakFast {
    breakfastReserved: lone Reserved
}

and treat no breakfastReserved as "free". You don't need any further facts then.

Rüdiger Hanke
  • 6,215
  • 2
  • 38
  • 45
  • in the last section you mean i should take out the free signature and keep only reserved and if it is not pointing on the reserved it is free? – dori naji Nov 14 '11 at 10:11
  • if i do the last section as you mentioned i got some dinner alone without a relation with a table its like i lose my table proprites – dori naji Nov 14 '11 at 10:53
  • 1
    If I understand you correctly, then I find the same behaviour in the original model (maybe you have to enumerate some solutions). If you wish all breakfasts etc. connected to a table you should use additional facts like "Table.breakfast = breakFast", "Table.lunch = Lunch" etc. – Rüdiger Hanke Nov 14 '11 at 11:09
  • no what i mean is if i take out the free sig or sig breakFast { breakfastfree: lone Free, breakfastReserved: lone Reserved } { #(breakfastfree+breakfastReserved) = 1 } in the model some breakfasts or dinner or lunch without a table pointing to them – dori naji Nov 14 '11 at 11:32
  • I think we mean the same. Try adding the facts I've given in my previous comment. If they don't help, you'd have to clarify your problem a bit. – Rüdiger Hanke Nov 14 '11 at 11:45
  • perfect it works great thank you for your help and fast replies – dori naji Nov 14 '11 at 11:51