0

The following problem arose, I wrote a restriction that some shift must be scheduled twice during the week, And this is not entirely correct, I need the shifts to go in a row, and only the last day on which the train operates is issued. That is, if the train travels for 5 days, then only the state on its last day is recorded in the solution

        Dictionary<Tuple<int, int, int>, IntVar> shifts = new Dictionary<Tuple<int, int, int>, IntVar>();
        foreach (int t in allTrains)
        {
            foreach (int d in allDays)
            {
                foreach (int s in allShifts)
                {
                    shifts.Add(Tuple.Create(t, d, s), model.NewBoolVar($"shifts_t{t}d{d}s{s}"));
                }
            }
        }
        foreach (int t in allTrains)
        {
            IntVar[] x = new IntVar[numDays];
            foreach (int s in allShifts)
            {
                foreach (int d in allDays)
                {
                    var key = Tuple.Create(t, d, s);
                    x[d] = shifts[key];
                }
                model.Add(LinearExpr.Sum(x) == 2);
            }
        }

The end result should be something like. Result for 3 shifts in a row and 10 days. The problem itself is that some shift is assigned for a certain number of days, something like intervals. In a real task, the planning horizon can grow up to a month, and the number of shifts up to 20

Valid Solution:

example

Invalid decision №1

  1. Train 1
    • Days 1 going to the shift 1
    • Days 2 going to the shift 2
    • Days 3 going to the shift 0
    • Days 4 going to the shift 2
    • Days 5 going to the shift 1
    • Days 6 going to the shift 0

Invalid decision №2

  1. Train 1
    • Days 2 going to the shift 2
    • Days 3 going to the shift 3
    • Days 5 going to the shift 1
    • Days 6 going to the shift 0

Only, please, without links to the github :) It is still too complicated for me, because I have only recently begun to study this tool. Thanks in advance

Laurent Perron
  • 8,594
  • 1
  • 8
  • 22
Rnisa
  • 1
  • 1
  • I think you'll need to attach more code and information to be able to get help. Where is ``shifts[]`` defined, for example? Are the "trains" the workers? Is your planning horizon one week or more? Do you want that "some" shift is assigned twice during the week, or all shifts worked to be assigned twice? Do the shifts assigned twice have to be on consecutive days or just sometime during the week? (i.e. is 1, 2, 1, 2 an acceptable solution?). – Christopher Hamkins Nov 21 '22 at 14:51
  • Added more information, my main task now is to do this so that some shift is assigned sequentially in accordance with the given value of n, in the example n is 2 – Rnisa Nov 21 '22 at 15:33
  • Its still pretty sketchy to be able to help. Is this homework or a real problem? What I understand is that sometime during the planning horizon, there must be at least two consecutive days working on the same shift for each train. Also give an example of an unacceptable solution. – Christopher Hamkins Nov 22 '22 at 14:38
  • The teacher slightly changed the task, and now some shift s should be assigned for n number of days in a row, but only the last day on which the train works on shift s should be recorded in the solution. – Rnisa Nov 23 '22 at 21:39

0 Answers0