この投稿で説明するように、テニスのスケジューリング問題をモデル化しようとしています。問題を説明する方程式で答えを得られたのは幸運でした。これにより、Choco でそれを実装することができました。それは十分に機能しているようです。
だから私が説明しようとしているのは、前の投稿の回答の実装の製品についてです。
基本的に、次のように 2 つの 3 次元マトリックスと 1 つの 2 次元マトリックスを持つことになります。
// Matches schedule
// i -> players, j-> courts, k -> timeslots
// x[i][j][k] holds a value 0..1 where 0 means the player doesn't play in court_j in the timeslot_k, and 1 the opposite
IntVar[][][] x;
// Beginning of all matches
// i -> players, j-> courts, k -> timeslots
// g[i][j][k] holds a value 0..1 where 0 means the player doesn't play in court_j in the timeslot_k, and 1 the opposite
// Basically the same matrix as the previous one but it only holds the first timeslot of a match
IntVar[][][] g;
// Occupied courts
// i-> courts, j-> timeslots
// crt[i][j] holds a value 0..1 where 0 means the court_i is occupied in the timeslot_j, and 1 means the opposite
IntVar[][] crt;
このアプローチでは、スケジュール マトリックスをゲーム開始マトリックスにマップする制約は次のようになります。
for (int p = 0; p < nPlayers; p++) {
for (int c = 0; c < nCourts; c++) {
for (int t = 0; t < nTimeslots - nTimeslotsPerMatch; t++) {
if (nTimeslotsPerMatch == 1)
solver.post(IntConstraintFactory.arithm(g[p][c][t], "=", x[p][c][t]));
else
solver.post(IntConstraintFactory.times(x[p][c][t], x[p][c][t + 1], g[p][c][t]));
}
if (nTimeslotsPerMatch == 1)
solver.post(IntConstraintFactory.arithm(g[p][c][nTimeslots - 1], "=", x[p][c][nTimeslots - 1]));
else
for (int i = 0; i < nTimeslotsPerMatch - 1; i++)
solver.post(IntConstraintFactory.arithm(g[p][c][nTimeslots - i - 1], "=", 0));
}
}
これは、times
制約トリックを使用して と をマッピングx[p][c][t]
しx[p][c][t + 1]
ますg[p][c][t]
。
ただし、その定義では、各試合には 2 つのタイムスロットの固定期間があると見なされます。期間が可変になるように変更したい。
しかし、一致期間を可変にしたい場合はx
、 で値を定義するためにで 2 つ以上の値をマップする必要がありますg
。たとえば、試合時間が 3 スロットの場合、するmap g[p][c][t]
必要がありますが、現在行われている方法で、または同様の方法でそれx[p][c][t] * x[p][c][t + 1] * x[p][c][t + 2]
を行うことはできません。times
sum
だから私の質問は、一連の値の合計が値に等しいことを保証できるChocoと呼ばれる制約があるので、この一連の値の積を定義するものはありますか? そうでない場合、どうすればこれを行うことができますか?
基本的に私が達成することは次のとおりです。
g[i][j][k] = x[i][j][k] + x[i][j][k + 1] * x[i][j][k + 2] * x[i][j][k + 3] * ... * x[i][j][nTimeslotsPerMatch - 1]