3.1. Problem Formulation
In this section, we calculate an optimal controller for G to achieve a given task. Particularly, the following two optimization objectives should be satisfied.
Deadlock-Free: We say a state is a deadlock state if we cannot arrive at a marked state from it. In other words, once we arrive at a deadlock state, we can never reach a marked state;
Efficiency: Among all the strings of G in the solution domain, efficiency requires us to execute a string with a minimal cost.
Let us first introduce the definition of a deadlock state.
Definition 1. Given a state , q is a deadlock state if there does not exist a string such that .
From a deadlock state, we can never reach a marked state. In this paper, we denote
by the set of all the deadlock states of
G [
53]. We also denote
by the set of illegal states from which we can reach a deadlock state via an uncontrollable event sequence. If we are in an illegal state, we may reach a deadlock state even if we disable all the controllable events in the future. Thus, to ensure the system is deadlock-free, all the illegal states are prohibited from reaching.
We define a cost function , where is the set of real numbers. Formally, for any and any , is the cost resulting from executing event s when the system is in state q.
Given a state and the search depth , we let be the set of strings that are defined at z and are of the length l. To save the computational resource, we require that the solution calculated at the current state is optimal for the next steps. We assume that for each state of the automaton, there is at least one event defined at this state. This is not a restriction since for any state whose active event set is empty, we can always add a dumb self-loop with a cost of 0 at it. Thus, given the current state , an optimal solution is always included in . Now, the objective function for resource allocation can be expressed as follows.
Problem 1. Given the system automaton G, the optimization for resource allocation in the current state iswhere is the fixed number of prediction steps, and the model constraints are given as follows: Condition (3) states the first event of the solution is enforceable so that it can be enforced by the controller. Condition (4) states that all the illegal states are prevented from being reached. By definition, the solution
of (
2) is an event sequence of length
l defined at the current state
q and has the minimal cost. Note that there may be several minimal solutions of (
2), i.e., the solutions of (
2) need not to be unique. We can select any one of them and then execute the first event of
t, i.e.,
. After execution, the state of the system is updated, and a new optimal solution of (
2) should be calculated. Since the first event of
t is enforceable, it can always be enforced. Meanwhile, when we enforce an event occurrence, we must disable all the remaining controllable events. Given the current state
, we next show how to compute the optimal solution
.
3.2. Solution
In this section, a set of algorithms are developed to solve Problem 1. Given a state
, we define the set of predecessor states of
q, denoted by
, as:
Algorithm 1 calculates all the nondeadlock states
of
G.
Algorithm 1: Nondeadlock States |
|
To search for all the nondeadlock states, Algorithm 1 considers all the marked states first, then all the nondeadlock states that can reach within 1 step, then all the nondeadlock states that can reach within 2 steps, and so on. Algorithm 1 does not terminate until all the nondeadlock states are considered at least once. Since Q is finite, Algorithm 1 will terminate in finite steps.
Proposition 1. The returned of Algorithm 1 collects all the nondeadlock states of G, i.e., .
Proof. We denote by the set of states returned by Line 1 and the set of states returned at the end of the ith iteration of the while-loop in Line 2.
We first prove that . The proof is by induction. Since , the base case is trivially true.
The induction hypothesis is that . In the st iteration of the while-loop, all the predecessor states of (if they are not included in ) are added into . Hence, for all , there exist a and a such that . By the induction hypothesis, . By Definition 1, there exists a sequence such that . Moreover, since , we have . Therefore, . By Line 9, .
We next prove . For an arbitrary , by Definition 1, there exists a sequence such that . Without loss of generality, we write for . By the while-loop on Line 2, for . Therefore, . □
Given the set of nondeadlock states, Algorithm 2 returns the set of all the legal states.
Algorithm 2: Legal States |
|
Algorithm 2 computes all the legal states by iteratively removing the states q from the set of nondeadlock states if we can arrive at a deadlock state from q via an uncontrollable event sequence. Since Q is finite, the algorithm will terminate in finite steps. The following proposition states that Algorithm 2 indeed returns all the legal states.
Proposition 2. The returned of Algorithm 2 collects all the legal states of G, i.e., .
Proof. We first prove that . The proof is by induction. Initially, we have . By the definitions of and , we have , which implies . Thus, is true.
The induction hypothesis is that . In the st iteration of the repeat-until loop, Line 5 of Algorithm 2 removes all the such that with . Since and , . Then, by the definition of , there exists a sequence such that . Since , all the that are removed from are illegal states, i.e., . Therefore, .
We next prove that . Given any , by the repeat-until loop, if there exists such that , then . Otherwise, it contradicts the assumption that the repeat-until loop does not terminate until . Moreover, since , for any and any , we have . By the definition of , or equivalently . Since q is arbitrarily given, . □
We let be the current state of the system G and be the prediction depth. Algorithm 3 is used to calculate .
Algorithm 3 involves a breadth-first search of a tree with a depth of
h. Each node of the tree is a pair
, where
q is a state of
G and
s is a sequence with the length no larger than
l (its length is the search depth). We say a node
is promising if
q is legal, i.e.,
. Algorithm 3 visits the root node
first, followed by all promising nodes at level 1, all promising nodes at level 2, and so on. The following theorem states that Algorithm 3 returns all possible promising nodes that can be reached from the initial node
over a sequence in
.
Algorithm 3: Computation of Feasible Sequences |
|
Theorem 1. We let be the set of pairs returned by Algorithm 3. Then, such that for if and only if .
Proof. We denote by the set of nodes obtained at the end of the ith iteration of the repeat-until loop.
(⇒) Since and , by recursively applying the while-loop on Line 3 of Algorithm 3, we have . Therefore, we have .
(⇐) For any , we prove that , , and . The proof is by induction on . The base case is trivially true since , , , and . The induction hypothesis is that for all with , we have , , and . We now prove that the same is also true for all . By the while-loop on Line 3 of Algorithm 3, there exist and such that and . Since and , we have and . Thus, for all , we have , , and . Therefore, for all , we have , , and . By definition, . □
Corollary 1. For any , it is a solution of Problem 1 if such that and there does not exist another with and .
Proof. For any , Problem 1 intends to find a having the minimum cost such that (i) and (ii) for . By Theorem 1, collects all the such that and for . Thus, s is a solution of Problem 1 if and only if and there does not exsit another such that and . That completes the proof. □
By Corollary 1, we can always obtain a solution of Problem 1 (if it exists) by selecting one with that has a minimum cost .
Flow diagrams of the algorithm for optimal resource allocation are given in
Figure 4. Specifically, we first model the resource automata and process automata as described in
Section 2.2. The overall system model
G can be obtained by paralleling all these automata as in (
1). When the state of the system is updated, we apply Algorithms 1–3 to calculate all the feasible event sequences that start from the current state. By Corollary 1, by calculating the time cost of all the feasible event sequences, we can always select one having the minimum time cost. Then, we enforce the first event of this sequence at the right time. After the execution of this event, the state of the system is updated again, and we repeat the above process.