set_state()

Action to change the acting agent’s state in another condition.

Synopsis

set_state(<condition_name>, <state_name1>, <state_name2>)
set_state(<condition_name>, <state_name>)

Description

set_state(<condition_name>, <state_name1>, <state_name2>)

If the agent is currently in <condition_name>.<state_name1>, then the agent’s current state in <condition_name> becomes <state_name2>.

set_state(<condition_name>, <state_name>)

The agent’s current state in <condition_name> becomes <state_name>, regardless of the previous state of the agent in <condition_name>.

Effects of set_state()

A concurrent event may arise as the result of the set_state() action, which immediately chamges the state of an agent in a different condition. The affected agent may also immediately performs any actions associated with the new state.

Parameters

<condition_name> :

Name of the condition being targeted.

<state_name1> :

Name of state being conditionally tested.

<state_name2> :

Name of the state the agent is set to in the conditional syntax.

<state_name> :

Name of the state the agent is set to in the unconditional syntax.

Examples

Consider the following example:

condition COND1 {

    ...

    state A {
      set_state(COND2,B,C)
      x = 1
      wait()
      next()
    }

    ...

}

condition COND2 {

    ...

    state B {
        wait()
        next()
    }

    state C {
        x = 2
        wait()
        next()
    }

    ...

}

If an agent enters state COND1.A, the final value of x is 1. The order of events for this agent is:

  • Agent enters COND1.A

  • Agent runs set_state() action, which:

  • Causes the agent to enter COND2.C

  • Agent sets x = 2

  • Agent waits in state COND2.C

  • Agent continues to execute actions in state COND1.A and sets x = 1

As this example show, the set_state() action is not queued. The new state takes effect immediately, and the actions in the new state are performed before returning to the calling state.

It is considered good modeling practice to avoid assumptions about the order of agents who perform concurrent state transitions.

See Also

next(), default()