Skip to main content

Rostering problem with column generation

Answered

Comments

14 comments

  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Hi Carl,

    My suggestion would be to try and implement this step-by-step. Looking at your code, I get the impression some parts are not yet valid Python (some syntax errors, and variables referenced without creating them) while there's already a lot of complexity... start small, test, then iterate. I would start with the RMP (only!) and a trivial solution as initial column(s). First make sure that part is solved correctly before working on the subproblems.

    Kind regards,
    Ronald

    0
  • Carl Baier
    Thought Leader
    First Question

    Ronald van der Velden Sorry, i accidentally added some code with errors. I fixed some of them; some of them still remain, however. What exactly do you mean by solving the RMP only? Just initially solving the objective with the demand constraint? The problem is, i dont really know how to create a trivial (initial) solution. Excuse me, but I am a real beginner, but I have to solve this problem somehow. I am therefore grateful for any help.

    0
  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Exactly, without "real" rosters produced by a subproblem. I believe since you have slack variables, there is always a solution to the master problem right? So you could generate the obvious empty roster (no shifts) for each nurse and include that in your initial master problem. Or any heuristic approach where you fill a roster left-to-right using a few shifts.

    0
  • Carl Baier
    Thought Leader
    First Question

    Ronald van der Velden I see. How would the code look to implement this?

    0
  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Hi Carl,

    Please give it a try yourself and feel free to ask a more specific question once you need help with a particular step.

    Kind regards,
    Ronald

    0
  • Carl Baier
    Thought Leader
    First Question

    Ronald van der Velden I have just updated my code and adapted the structure. Unfortunately, I still can't manage to link the dynamic index r in the master problem with the variable \(motivation_{its}\) and to add the columns from the individual subproblems. Are the individual subproblems called correctly?

    I would be infinitely grateful if you could help me solve these problems.

    0
  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Just to be sure - I think the current issue is that you solve the relaxed model, but then request "Pi" for the original model (which has not been solved, hence Pi is not available there). Are you observing the same on your side?

    0
  • Carl Baier
    Thought Leader
    First Question

    Ronald van der Velden Yes, i updated the code, the error is now gone, but now the Constr cant be found.

    0
  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Please have a look at (the end of) this question about the same problem.

    0
  • Carl Baier
    Thought Leader
    First Question

    Ronald van der Velden Thanks, that did help. I also fixed a few other errors, but now i run into this error 

        self.model.setObjective(-gu.quicksum(self.motivation[t,s]*self.duals_ts[t,s] for t in self.days for s in self.shifts)-self.duals_i[i], sense = gu.GRB.MINIMIZE)
                                                                  ~~~~~~~~~~~~~^^^^^
    KeyError: (1, 1)

    I guess the problem is, that the duals are not available yet? However, at this point, i dont really know where i should look at into the code, to fix this problem. I also updated my current problems and where i still need help!

    0
  • Carl Baier
    Thought Leader
    First Question

    Ronald van der Velden And i also guess that the column added is the wrong on, as i am "giving" over the whole solution matrix, but obvioulsy i only want to hand over the \(motivation_{ts}\) values for all nurses \(i\) to the suproblem and assign the index \(r\). Maybe replace 

    def getNewSchedule(self):
            return self.model.getAttr("X", self.model.getVars())

    with 

    def getNewSchedule(self):
    sol = self.motivation_i.values()
    sol_dict = dict((var.VarName, var.X) for var in sol)
    return sol_dict
    0
  • Ronald van der Velden
    Gurobi Staff Gurobi Staff

    Hi Carl,

    Unfortunately I can't help you debug this step-by-step. I don't believe the error you see is optimization-specific: you should be able to add breakpoints to your code and inspect variable values, see where you set and retrieve duals_ts etcetera and this will help you solve the problem.

    Kind regards,
    Ronald

    0
  • Carl Baier
    Thought Leader
    First Question

    Ronald van der Velden Of course it just was a stupid double return in the variable function. Now the optimization runs through but obviously there is now optimal solution. Unfortunately, I'm at my wit's end now, as I'm really not good at programming (see this post) and don't know how the individual functions in Gruobi work. Should I create a new post for the sake of clarity?

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    don't know how the individual functions in Gruobi work

    Could this help?

    0

Please sign in to leave a comment.