Skip to main content

Problems about general constrains

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 Liu,

    The two formulations both look okay to me. Could you post a small code snippet that has the same result (one model feasible, the other infeasible), but includes the definitions of all variables/constants? Ideally, this snippet would build a smaller version of the model, so the code is easier to look through. Maybe you can narrow down the problem to a single value of \( i \) and/or \( t \).

    It would also help if you used the "code" style to format the code so the Python indenting isn't lost.

    Thanks,

    Eli

    0
  • Liu Yanyue
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Eli,

    Thanks for your response. 

    Here is the code that includes definitions of these variables.

    U = [11, 12, 25, 26, 27, 28, 29, 30]
    maxcell = 2
    Tc = 100
    n = {}
    space = {}
    for i in U:
    for j in range(1,maxcell):
    for t in range(1, Tc+2):
    n[i,j,t] = m.addVar(lb = 0.0, ub = Kjam[i], vtype=GRB.CONTINUOUS, name='n%s_%s_%s'%(i,j,t))
    space[i,j,t] = m.addVar(vtype=GRB.BINARY, name='space%s_%s_%s'%(i,j,t))

    N = {}
    G = {}
    Sending = {}
    zx3 = {}
    zx4 = {}
    freeflow = {}

    for i in U:
    for t in range(Tc+1):
    for j in [0,1]:
    N[i,j,t] = m.addVar(lb = 0.0, vtype=GRB.CONTINUOUS, name='N%s_%s_%s'%(i,j,t))
    G[i,t] = m.addVar(lb = 0.0, vtype=GRB.CONTINUOUS, name='G%s_%s'%(i,t))
    Sending[i,t] = m.addVar(lb = 0.0, vtype=GRB.CONTINUOUS, name='S%s_%s'%(i,t))
    zx3[i,t] = m.addVar( vtype=GRB.BINARY, name='z3%s_%s'%(i,t))
    zx4[i,t] = m.addVar( vtype=GRB.BINARY, name='z4%s_%s'%(i,t))
    freeflow[i,t] = m.addVar(lb = 0.0, vtype=GRB.CONTINUOUS, name='ff%s_%s'%(i,t))

    And I have try to change Tc from 100 to 40, which is the cycle of traffic signal and it can't be lesser than 40. But there is still no feasible solution. Also, i may can't be a single value because an intersection has 4 branches of roads and 8 different directions so the minimum size of list U is 8. 

    If you need more information, you may access my github to get a runnable version of the complete code. You can find definition of these variables at line 875 to 918, and general constrains can be found at line 993 to 998. Line 1000 to 1011 is the commented code that not use general constrains, a feasible solution can be obtained with these constrains. 

    My github: https://github.com/yanyueliu/Lane_based_model

    Best regards,

    Liu

    0
  • Eli Towle
    • Gurobi Staff

    Hi Liu,

    The definition of the \( \texttt{space} \) variables doesn't look right:

    space[i,j,t] = m.addVar(vtype=GRB.BINARY, name='space%s_%s_%s'%(i,j,t))

    It looks like these should be continuous (and maybe unbounded with \( \texttt{lb=-GRB.INFINITY} \)).

    Thanks,

    Eli

    0
  • Liu Yanyue
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Eli,

    Thank you for pointing out my mistake.

    I am so careless and when I define space I just copied code above without change and check.

    The problem is solved after variable type is changed as contiuous.

    Best regards,

    Liu

    0

Post is closed for comments.