Skip to main content

adding constraint

Answered

Comments

3 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?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Farzana,

    Your code uses files to read in data. This makes it impossible for the community to reproduce the error. Moreover, your code is not properly edited, making it even harder to understand. Note that proper indenting is essential in Python.

    Please post a minimal working example of your issue if the Community shall be able to help.

    A minimal working example would consist of a code which hard codes the definition of

    n_time_horizon = 120
    road_node = [...]
    vehicle_list = [...]
    s_space_time_network = [...]
    l = {...}
    fftt = {...}

    for (i,t,j,h) in s_space_time_network:
    for v in vehicle_list:
    x[v,i,t,j,h] = m.addVar(vtype=GRB.BINARY, name ="s_space_time_network")

    #link Storage Constraint
    for (i,j) in road_node:
    for t in range(1,n_time_horizon+1):
    m.addConstr(sum([x[v,i,u,j,u+fftt[(i,j)]] for v in vehicle_list if u>=1 and u<=t]) - sum([x[v,j,u,i,u+fftt[(j,i)]] for v in vehicle_list for (j,i) in road_node if u>=1 and u<=t]) <= l[(i,j)],name = "cont_4")

    In general, it seems like you define the list \(\texttt{s_space_time_network}\) such that the last entry in the tuples is defined from 1 to \(\texttt{n_time_horizon}\) but in the link Storage Constraint, you want to access \(\texttt{x}\) at \(\texttt{u+fftt[(i,j)]}\). Thus, when \(\texttt{u=n_time_horizon}\), you get a KeyError.

    Best regards,
    Jaromił

    0
  • Jaromił Najman
    • Gurobi Staff

    This is a cross-post to Gurobi Python constraint adding.

    0

Post is closed for comments.