Skip to content

Commit

Permalink
add step for distributed demon
Browse files Browse the repository at this point in the history
  • Loading branch information
josef-widder committed Jan 28, 2025
1 parent fa99056 commit 23d3c9a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion examples/classic/distributed/ewd426/ewd426.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ module self_stabilization {
system' = initial
}

/// Update a single non-deterministic active node
/// Pick a single active node non-deterministically and update its state
action step = {
nondet node = 0.to(N).filter(i => has_token(system, i)).oneOf()
system' = system.set(node, state_transition(system, node))
}

/// Pick several active nodes non-deterministically and update their state.
/// Closer to the distributed demon is discussed in EWD 391. We are not
/// considering interleaving in the execution of state_transition here
action distributed_step = {
nondet nodes = 0.to(N).filter(i => has_token(system, i)).powerset().exclude(Set()).oneOf()
system' = nodes.fold(system, (s, x) => s.set(x, state_transition(system, x)))
}

// Pure function to count how many tokens exist
pure def count_tokens(nodes: int -> int): int = {
0.to(N).filter(i => has_token(nodes, i)).size()
Expand Down
10 changes: 9 additions & 1 deletion examples/classic/distributed/ewd426/ewd426_3.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,20 @@ module self_stabilization_three_state {
system' = initial
}

/// Action for the three-state machine
/// Pick a single active node non-deterministically and update its state
action step = {
nondet node = 0.to(N).filter(i => has_token(system, i)).oneOf()
system' = system.set(node, state_transition(system, node))
}

/// Pick several active nodes non-deterministically and update their state.
/// Closer to the distributed demon is discussed in EWD 391. We are not
/// considering interleaving in the execution of state_transition here
action distributed_step = {
nondet nodes = 0.to(N).filter(i => has_token(system, i)).powerset().exclude(Set()).oneOf()
system' = nodes.fold(system, (s, x) => s.set(x, state_transition(system, x)))
}

// Pure function to count how many tokens exist
pure def count_tokens(nodes: int -> int): int = {
to(0, N).filter(i => has_token(nodes, i)).size()
Expand Down
10 changes: 9 additions & 1 deletion examples/classic/distributed/ewd426/ewd426_4.qnt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ module self_stabilization_four_state {
.setBy(top, s => { ...s, up: false })
}

/// Action for the four-state machine
/// Pick a single active node non-deterministically and update its state
action step = {
nondet node = 0.to(N).filter(i => has_token(system, i)).oneOf()
system' = system.set(node, state_transition(system, node))
}

/// Pick several active nodes non-deterministically and update their state.
/// Closer to the distributed demon is discussed in EWD 391. We are not
/// considering interleaving in the execution of state_transition here
action distributed_step = {
nondet nodes = 0.to(N).filter(i => has_token(system, i)).powerset().exclude(Set()).oneOf()
system' = nodes.fold(system, (s, x) => s.set(x, state_transition(system, x)))
}

// Pure function to count how many tokens exist
pure def count_tokens(nodes: int -> State): int = {
0.to(N).filter(i => has_token(nodes, i)).size()
Expand Down

0 comments on commit 23d3c9a

Please sign in to comment.