Skip to content

Commit f7174db

Browse files
authored
Merge pull request #105 from plaans/numeric-planning
Various fixes in numeric planning
2 parents 82e8292 + b1623de commit f7174db

File tree

25 files changed

+783
-315
lines changed

25 files changed

+783
-315
lines changed

doc/src/resources.md

Lines changed: 70 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The right-hand side of the operator could be either a constant or a variable.
1616
### 1.2 Effects
1717

1818
The value of a resource can be :
19+
1920
- changed with an **assignment**, the new value could be either a constant or a variable
2021
- **increased** by a constant value
2122
- **decreased** by a constant value, internally it is an increased operation with a negative constant value
@@ -24,55 +25,85 @@ The value of a resource can be :
2425

2526
### 2.1. Effects
2627

27-
Every time a resource value is updated, new conditions are created in order to check that the value can be updated and that the new value is contained in the bounded domain of the resource.
28+
Every time a resource value is updated, new constraints or conditions are created in order to check that the value can be updated and that the new value is contained in the bounded domain of the resource.
29+
30+
#### 2.1.1 Assign effects
31+
32+
For an assign effect $[t^a] R^a := z$, we will create the following constraints:
2833

29-
For an **assign effect** $[t^a] R^a := z$, we will create the following conditions:
30-
$$\begin{cases}
34+
$$
35+
\begin{cases}
3136
[t^a] z \ge l \\
3237
[t^a] z \le u \\
33-
\end{cases}$$
38+
\end{cases}
39+
$$
3440

35-
For an **increase effect** $[t^i] R^i \mathrel{+}= c$, we will create the following conditions:
36-
$$\begin{cases}
37-
[t^i] R^i \le u - c \\
38-
[t^i] R^i \ge l - c \\
39-
[t^i+\varepsilon] R^i \le u \\
40-
[t^i+\varepsilon] R^i \ge l \\
41-
\end{cases}$$
41+
#### 2.1.2 Increase effects
4242

43-
For a **decrease effect** $[t^d] R^d \mathrel{-}= c$, we convert it into the increase effect $[t^d] R^d \mathrel{+}= (-c)$ and then create the associated conditions.
43+
For an increase effect $[t^i] R^i \mathrel{+}= c$, we will create a new variable $v$ with the same domain as the resource and add a new condition $[t^i]R^i = v$.
4444

45-
Next, these conditions are converted into linear constraints as explained in the next section.
45+
This will ensure that the new value of the resource is in the correct domain after the increase.
46+
Next, this condition is converted into linear constraints as explained in the next section.
47+
48+
#### 2.1.3 Decrease effects
49+
50+
For a decrease effect $[t^d] R^d \mathrel{-}= c$, we convert it into the increase effect $[t^d] R^d \mathrel{+}= (-c)$ and then create the associated conditions.
4651

4752
### 2.2. Conditions
4853

4954
Every time a resource must be tested, a set of associated linear constraints are created.
5055

51-
For an **equality condition** $[t^c] R^c = z$, we will have the **linear constraints**
52-
$$\begin{cases}
53-
l^a_1c^a_1 + l^i_{11}c^i_1 + \dots + l^i_{1m}c^i_m - z = 0 \\
54-
\dots \\
55-
l^a_qc^a_q + l^i_{q1}c^i_1 + \dots + l^i_{qm}c^i_m - z = 0 \\
56-
\end{cases}$$
57-
58-
Where $l^a_jc^a_j$ represents an assignment to the resource and $l^i_{jk}c^i_k$ represents an increase, the $l$ variables are booleans used to know if the associated $c$ variable (which is the value of the assignment or the increase) should be used. The idea is to consider only the constraint corresponding to the latest assignment.
59-
60-
To do so, we define $\textit{SP}$ which test if the parameters of two resources are the same, $\textit{SPP}$ which test the presence and the parameters, $\textit{LA}$ which test if the assignment is the last one for the current condition:
61-
$$\begin{cases}
62-
\textit{SP}(R^1,R^2) &\Leftrightarrow \bigwedge_{b} (p^1_b=p^2_b) \\
63-
\textit{SPP}(j, b) &\Leftrightarrow \textit{SP}(R^j,R^b) \land \textit{prez}(j) \land \textit{prez}(b) \\
64-
\textit{LA}(j) &\Leftrightarrow \bigwedge_{b \ne j} (t^a_b \le t^c \land \textit{SPP}(j,b) \implies t^a_b < t^a_j) \\
65-
\end{cases}$$
66-
67-
Using these intermediate variables, we obtain
68-
$$\begin{cases}
69-
\bigvee_{b} l^a_b \\
70-
l^a_j \Leftrightarrow t^a_j \le t^c \land \textit{LA}(j) \land \textit{SPP}(j,c) \\
71-
l^i_{jk} \Leftrightarrow l^a_j \land t^a_j < t^i_k \land t^i_k < t^c \land \textit{SPP}(k,c) \\
72-
\end{cases}$$
73-
74-
For **others conditions**, we convert them into equality conditions. For example, the condition $[t^c] R^c \le z$ is converted into
75-
$$\begin{cases}
56+
#### 2.2.1 Equality conditions
57+
58+
For an equality condition $[t^c] R^c = z$, we will have the **linear constraints**
59+
60+
$$
61+
\begin{cases}
62+
l^a_1c^a_1 + l^i_{11}c^i_1 + \dots + l^i_{1n}c^i_n - l^a_1z = 0 \\
63+
\vdots \\
64+
l^a_kc^a_k + l^i_{k1}c^i_1 + \dots + l^i_{kn}c^i_n - l^a_kz = 0 \\
65+
\end{cases}
66+
$$
67+
68+
Where $l^a_jc^a_j$ represents an assignment to the resource and $l^i_{jm}c^i_m$ represents an increase, the $l$ variables are boolean literals used to know if the associated $c$ variable (which is the value of the effect) should be used.
69+
The idea is to consider only the constraint corresponding to the latest assignment.
70+
71+
To do so, we define $\textit{SP}$ which test if the parameters of two resources are the same by:
72+
73+
$$\textit{SP}(x,y) \Leftrightarrow \bigwedge_{b} (p^x_b=p^y_b)$$
74+
75+
We also define $\textit{LA}$ which test if the assignment effect is the last one before the condition.
76+
**There are two ways to define it**.
77+
The **first** one is to check that the effect is before the condition and for other compatible assignment effects, check that they are not between the considering effect and the condition:
78+
79+
$$\textit{LA}(j) \Leftrightarrow t^a_j \le t_c \land \bigwedge_{b \ne j} (\neg \textit{prez}_b \lor \neg\textit{SP}(b,c) \lor t^a_b < t^a_j \lor t^a_b > t^c)$$
80+
81+
The **second** way to define $\textit{LA}$ is to add a fourth time point to the numeric assignment effects.
82+
Currently, the effects have three time points: the start of the transition, the start of the persistence, and the end of the persistence.
83+
We add a fourth one, the **end of the assignment**, which holds while the current assignment is the last one.
84+
This time point is forced to be after or equals to the end of the persistence.
85+
This way, we just need to check that the condition is between the start of the persistence $t^a_{j,s}$ and the end of the assignment $t^a_{j,e}$:
86+
87+
$$\textit{LA}(j) \Leftrightarrow t^a_{j,s} \le t_c \land t_c \le t^a_{j,e}$$
88+
89+
At the end, the $l^a_j$ literal is true if the effect is present, is the effect before the condition, and has the same resource as the condition:
90+
91+
$$l^a_j \Leftrightarrow \textit{prez}_j \land \textit{LA}(j) \land \textit{SP}(j,c)$$
92+
93+
Moreover, we enforce to have at least one last assignment effect with the disjunction $\bigvee_{j}l^a_j$.
94+
95+
The $l^i_{jm}$ literal is true if the increase $m$ is present with the same resource as the condition, if the assignment $j$ is the last one and if the increase $m$ is between the assignment $j$ and the condition:
96+
97+
$$l^i_{jm} \Leftrightarrow \textit{prez}_m \land \textit{SP}(m,c) \land l^a_j \land t^a_j < t^i_m \land t^i_m \le t_c$$
98+
99+
#### 2.2.2 Others conditions
100+
101+
For others conditions, we convert them into equality conditions.
102+
For example, the condition $[t^c] R^c \le z$ is converted into
103+
104+
$$
105+
\begin{cases}
76106
[t^c] R^c = z' \\
77107
[t^c] z' \le z
78-
\end{cases}$$
108+
\end{cases}
109+
$$

planning/grpc/server/src/chronicles.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,18 +536,18 @@ impl<'a> ChronicleFactory<'a> {
536536
let operation = match kind {
537537
EffectKind::Assign => EffectOp::Assign(value),
538538
EffectKind::Increase => {
539-
let value = IntCst::try_from(value).context("Increase effect require a constant value.")?;
540-
EffectOp::Increase(value)
539+
let value = IAtom::try_from(value).context("Increase effect require an integer value.")?;
540+
EffectOp::Increase(LinearSum::from(value))
541541
}
542542
EffectKind::Decrease => {
543-
let value = IntCst::try_from(value).context("Decrease effect require a constant value.")?;
544-
EffectOp::Increase(-value)
543+
let value = IAtom::try_from(value).context("Decrease effect require an integer value.")?;
544+
EffectOp::Increase(-LinearSum::from(value))
545545
}
546546
};
547547
self.chronicle.effects.push(Effect {
548548
transition_start: span.start,
549-
persistence_start: span.end,
550-
min_persistence_end: Vec::new(),
549+
transition_end: span.end,
550+
min_mutex_end: Vec::new(),
551551
state_var: sv,
552552
operation,
553553
});

planning/grpc/server/src/serialize.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn serialize_plan(
127127
};
128128

129129
// If this is a scheduling problem, interpret all actions as activities
130-
// TODO: currently, parameters/variables are not supported.
130+
// TODO: currently, variables are not supported.
131131
let schedule = if _problem_request.scheduling_extension.is_some() {
132132
let mut schedule = Schedule {
133133
activities: vec![],
@@ -144,6 +144,22 @@ pub fn serialize_plan(
144144
format!("{name}.end"),
145145
a.end_time.expect("No end time in scheduling solution").into(),
146146
);
147+
if !a.parameters.is_empty() {
148+
// Search for the corresponding activity definition
149+
let act = _problem_request
150+
.scheduling_extension
151+
.as_ref()
152+
.expect("Missing scheduling extension")
153+
.activities
154+
.iter()
155+
.find(|a| a.name == name)
156+
.unwrap_or_else(|| panic!("Missing the activity `{}` definition", name));
157+
158+
// Assign the solution value to each action parameter
159+
for (v, p) in a.parameters.iter().zip(&act.parameters) {
160+
schedule.variable_assignments.insert(p.name.clone(), v.clone());
161+
}
162+
}
147163
schedule.activities.push(name);
148164
}
149165
Some(schedule)

0 commit comments

Comments
 (0)