Find below a discussion topic on initialization of time dependent sets with Alloy
Different behavior during initialization when using integers:
Version 1: initialization of a State to zero component with addition of an extra component
module Test
open util/ordering[Time] as T
sig Time {}
let dynamic[x] = x one-> Time
let dynamicLess[x] = x lone-> Time
let dynamicSet[x] = x -> Time
sig Farm {}
abstract sig Items extends Farm {}
one sig Farmer extends Items {}
lone sig Chicken extends Items {}
lone sig Grain extends Items {}
lone sig Fox extends Items {}
lone sig Wolf extends Items {}
one abstract sig State {
item: dynamicSet[Items],
next: one State
}
pred InitState[c:State,t:Time] { no c.item.t }
let addItem[c,itm, t1,t2]= c.item=c.item+itm->t2-itm->t1
// set all initial state to empty
// add one element to the next to initial state
// impose that the first time is the minimum time and the second time
// is its successor
// If satisfied, add an element to the state
fact{
all c:State| InitState[c,T/first]
all c:State|all t1,t2:Time| one itm:Items|
(t1=min[t1]) and
(#c.item.t1=0) and
(t2=min[t1].next) => addItem[c,itm,t1,t2]
}
pred show {}
run show for 8 but 4 Time, 1 State
Version 2 removing the state count during initialization:
module Test
open util/ordering[Time] as T
sig Time {}
let dynamic[x] = x one-> Time
let dynamicLess[x] = x lone-> Time
let dynamicSet[x] = x -> Time
sig Farm {}
abstract sig Items extends Farm {}
one sig Farmer extends Items {}
lone sig Chicken extends Items {}
lone sig Grain extends Items {}
lone sig Fox extends Items {}
lone sig Wolf extends Items {}
one abstract sig State {
item: dynamicSet[Items],
next: one State
}
pred InitState[c:State,t:Time] { no c.item.t }
let addItem[c,itm, t1,t2]= c.item=c.item+itm->t2-itm->t1
// set all initial state to empty
// add one element to the next to initial state
// impose that the first time is the minimum time and the second time
// is its successor
// If satisfied, add an element to the state
fact{
all c:State| InitState[c,T/first]
all c:State|all t1,t2:Time| one itm:Items|
(t1=min[t1]) and
// (#c.item.t1=0) and
(t2=min[t1].next) => addItem[c,itm,t1,t2]
}
pred show {}
run show for 8 but 4 Time, 1 State