Skip to main content

Examination Timetabling Problem - First steps with Gurobi

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Eli Towle
    • Gurobi Staff

    Hi Carlo,

    You can retrieve the solution value of a variable by using GRBVar.get() to query the GRB.DoubleAttr.X attribute. With binary variables, it's good practice to check if the value is actually within a small tolerance of 0 or 1, in case the value found by the solver is very slightly different (e.g., \( 10^{-8} \)).

    Does this answer your question? Thanks!

    Eli 

    0
  • Carlo Eggenschwiler
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Eli

    Thanks, that helped.

    I simplified the input data and can now log the solution.

    But what I still dont understand is why all presentations are assigned to the same room.

    GRBVar[][][] x = new GRBVar[nPresentations][nTimeslots][nRooms];
    for (int p = 0; p < nPresentations; ++p) {
    for (int t = 0; t < nTimeslots; ++t) {
    for (int r = 0; r < nRooms; ++r) {
    x[p][t][r] = model.addVar(0, 1, 1.0, GRB.BINARY, presentations[p] + "." + timeslots[t] + "." + rooms[r]);
    }
    }
    }

    // CONSTRAINT: presentation in one room and one timeslot
    for (int p = 0; p < nPresentations; ++p) {
    GRBLinExpr lhs = new GRBLinExpr();
    for (int t = 0; t < nTimeslots; ++t) {
    for (int r = 0; r < nRooms; ++r) {
    lhs.addTerm(1.0, x[p][t][r]);
    }
    }
    model.addConstr(lhs, GRB.EQUAL, 1.0, presentations[p]);
    }
    // END

     

    Optimization complete
    Solution found, objective = 7.0
    P1.T1.R1 1.0
    P2.T1.R1 1.0
    P3.T1.R1 1.0
    P4.T5.R4 1.0
    P5.T1.R1 1.0
    P6.T1.R1 1.0
    P7.T1.R1 1.0

    Is there someting wrong with my constraint modellation?

    Thanks!

     

    0
  • Thomas Opfer
    • Gurobi-versary
    • Thought Leader

    I think you need constraints that state that not more than one presentation may be in the same room at the same time. Otherwise, that would be perfectly ok.

    0
  • Carlo Eggenschwiler
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Thomas

    Thanks for the reply. You were right. I implemented this constraint and now the assignment is correct. Thanks a lot.

    Cheers.

    0

Post is closed for comments.