How to model a simple scheduling problem with MS Solver Foundation?

I have the following simple problem that I would like to use to experiment with MS Solver Foundation :

I have a schedule where I need to have 2 workers a day for 30 days. I need to respect the following restrictions:

  • Nobody has to work two days in a row.
  • Unless a special exception applies, people are only required to work once a week.
  • Some people can only work on weekends.
  • Some people can only work on weekdays.

I am planning to use C # to populate the model, but I need help getting started with modeling. I am not sure how to tweak the solutions, options and limitations to resolve this issue.

Update: While ire-and-curses has a good start, I must imagine that there is a more declarative way of expressing these constraints using a framework, rather than individually coding them for each person, Anyone more familiar with MSF. who can help with this design?

+2


source to share


1 answer


If you have n

people, you will need to define binary integer parameters 30n

, each indicating whether the person is working on a particular day or not.

P<xx>D<yy> == 1 => Person <xx> works on day <yy>
P<xx>D<yy> == 0 => Person <xx> does not work on day <yy>

      

Then you need restrictions to prevent you from working for two days in a row. These will be restrictions 29n

.

P<xx>D<yy> + P<xx>D<yy+1> <= 1

      

Then you only need restrictions to work once a week. It will be next for the first week and similar for the next three weeks.

P<xx>D00 + P<xx>D01 + P<xx>D02 + P<xx>D03 + P<xx>D04 + P<xx>D05 + P<xx>D06 <= 1

      

The last week will be as follows:



P<xx>D28 + P<xx>D29 <= 1

      

This will give other restrictions 5n

. Then add restrictions for weekdays only

P<xx>D05 + P<xx>D06 == 0
P<xx>D12 + P<xx>D13 == 0
P<xx>D19 + P<xx>D20 == 0
P<xx>D26 + P<xx>D27 == 0

      

and only weekends

P<xx>D00 + P<xx>D01 + P<xx>D02 + P<xx>D03 + P<xx>D04 == 0
P<xx>D07 + P<xx>D08 + P<xx>D09 + P<xx>D10 + P<xx>D11 == 0
P<xx>D14 + P<xx>D15 + P<xx>D16 + P<xx>D17 + P<xx>D18 == 0
P<xx>D21 + P<xx>D22 + P<xx>D23 + P<xx>D24 + P<xx>D25 == 0
P<xx>D28 + P<xx>D29 == 0

      

and finally add the target function.

+1


source







All Articles