Skip to main content

Orienteering Problem

Awaiting user input

Comments

4 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff 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?.
  • Mario Ruthmair
    Gurobi Staff Gurobi Staff

    Hi Bence,

    There is a lot of literature on modeling the orienteering problem and its variants, see for example this EJOR paper. Do you observe any problems with your model and implementation? You should always try to analyze the solution you get and see whether it satisfies all the constraints in your problem definition.

    What I can see after a quick look at your code is the following:

    • In your objective function you should also consider the scores at the nodes.
    • In the last set of constraints, the MTZ subtour elimination constraints, you might have mixed up the indices i and j in the last term on the right-hand side.
    • With your bounds on the u[i] variables (that correspond to the position in the route) you do not allow to visit all nodes.
    • In general, take care of the indices! Do you really want to end your route in node n-1?

    Best regards,
    Mario

    0
  • Bence Labant
    Gurobi-versary
    First Question
    First Comment

    Hi Mario,

    Thanks for the help. To tell the truth I am very newbie in the topic. An unexpected problem came up in my project and it led me to create route optimization code. So, I am not an optimizer, and I am sorry If I ask some lame questions.

    Well, mostly I ctrl+c and ctrl+v the code what I have found. I understand it on a high level.

    I think my most important question is: How can I consider the nodes?

    Can I do something like this? 

    objective = grb.quicksum(x_vars[i,j] * nodes[i,j]
    for i in range(1, n-1)
    for j in range(1, n))

    To be honest with you this subtour elimination part is the most confusing part for me I know what a subtour is and I know why we should have a constraint about it. I just do not understand the code. But do you mean that I should modify the code to something like this?

    for i in range(1,n):
    for j in range(1,n):
    opt_model.addConstr((u[i] - u[j] + 1 <= (n-1)*(1-x_vars[i,j])))

    Well I am nost sure where I want to end my route yet, I just copied the code but maybe I will modify it to n.

    Thanks for your help in advance!

    Sincerely,

    Bence

    0
  • Mario Ruthmair
    Gurobi Staff Gurobi Staff

    Hi Bence,

    Probably it is more intuitive to introduce binary node variables y_vars[i] that are 1 if node i is visited and 0 otherwise. Then, you can easily state your objective function as

    objective = grb.quicksum(scores[i] * y_vars[i] for i in range(1, n+1))

    Note that Python range() does not include the range end value, i.e., range(1,n) only iterates from 1 to n-1. You should be sure about which is your start node and which is your end node. So you probably need to adapt all ranges accordingly.

    Then you need to link your node variables to the edge variables as follows:

    opt_model.addConstr(grb.quicksum(x_vars[k,j] for k in range(1, n+1)) == y_vars[j] for j in range(1, n+1))

    Regarding subtour elimination, there is plenty of material available in the web, start by searching for TSP, subtour elimination, Miller-Tucker-Zemlin constraints, etc. Swapping indices i and j is correct here, but the coefficient (n-1) on the right-hand side depends on your bounds for variables u.

    The most important part is to analyze the optimal solution obtained, i.e., to output all non-zero variables and see whether this is a feasible route and if the objective value is correct. If this is not the case, you have to check which of your constraints lead to the wrong result, mostly there are issues with wrong indices, wrong ranges, wrong bounds, etc.

    Best regards,
    Mario

    0

Post is closed for comments.