fix
This commit is contained in:
@@ -62,7 +62,7 @@ public class NurseSolutionObserver : CpSolverSolutionCallback
|
||||
}
|
||||
|
||||
private int solution_count_;
|
||||
private IntVar[,,] shifts_;
|
||||
private BoolVar[,,] shifts_;
|
||||
private int num_nurses_;
|
||||
private int num_days_;
|
||||
private int num_shifts_;
|
||||
@@ -110,12 +110,12 @@ public class NursesSat
|
||||
{
|
||||
foreach (int s in all_shifts)
|
||||
{
|
||||
IntVar[] tmp = new IntVar[num_nurses];
|
||||
List<ILiteral> nurses = new List<ILiteral>();
|
||||
foreach (int n in all_nurses)
|
||||
{
|
||||
tmp[n] = shift[n, d, s];
|
||||
nurses.Add(shift[n, d, s]);
|
||||
}
|
||||
model.Add(LinearExpr.Sum(tmp) == 1);
|
||||
model.AddExactlyOne(nurses);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,12 +124,12 @@ public class NursesSat
|
||||
{
|
||||
foreach (int d in all_days)
|
||||
{
|
||||
IntVar[] tmp = new IntVar[num_shifts];
|
||||
List<ILiteral> worked = new List<ILiteral>();
|
||||
foreach (int s in all_shifts)
|
||||
{
|
||||
tmp[s] = shift[n, d, s];
|
||||
worked.Add(shift[n, d, s]);
|
||||
}
|
||||
model.Add(LinearExpr.Sum(tmp) == 1);
|
||||
model.AddExactlyOne(worked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class NursesSat
|
||||
// That is each nurse works shift 0 at most 2 times.
|
||||
foreach (int n in all_nurses)
|
||||
{
|
||||
IntVar[] tmp = new IntVar[num_days];
|
||||
BoolVar[] tmp = new BoolVar[num_days];
|
||||
foreach (int d in all_days)
|
||||
{
|
||||
tmp[d] = shift[n, d, 0];
|
||||
@@ -147,18 +147,18 @@ public class NursesSat
|
||||
|
||||
// works_shift[(n, s)] is 1 if nurse n works shift s at least one day in
|
||||
// the week.
|
||||
IntVar[,] works_shift = new IntVar[num_nurses, num_shifts];
|
||||
BoolVar[,] works_shift = new BoolVar[num_nurses, num_shifts];
|
||||
foreach (int n in all_nurses)
|
||||
{
|
||||
foreach (int s in all_shifts)
|
||||
{
|
||||
works_shift[n, s] = model.NewBoolVar(String.Format("works_shift_n{0}s{1}", n, s));
|
||||
IntVar[] tmp = new IntVar[num_days];
|
||||
BoolVar[] worked = new BoolVar[num_days];
|
||||
foreach (int d in all_days)
|
||||
{
|
||||
tmp[d] = shift[n, d, s];
|
||||
worked[d] = shift[n, d, s];
|
||||
}
|
||||
model.AddMaxEquality(works_shift[n, s], tmp);
|
||||
model.AddMaxEquality(works_shift[n, s], worked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,12 +166,12 @@ public class NursesSat
|
||||
// during the week.
|
||||
foreach (int s in all_working_shifts)
|
||||
{
|
||||
IntVar[] tmp = new IntVar[num_nurses];
|
||||
BoolVar[] nurses = new BoolVar[num_nurses];
|
||||
foreach (int n in all_nurses)
|
||||
{
|
||||
tmp[n] = works_shift[n, s];
|
||||
nurses[n] = works_shift[n, s];
|
||||
}
|
||||
model.Add(LinearExpr.Sum(tmp) <= 2);
|
||||
model.Add(LinearExpr.Sum(nurses) <= 2);
|
||||
}
|
||||
|
||||
// If a nurse works shifts 2 or 3 on, she must also work that
|
||||
|
||||
Reference in New Issue
Block a user