Skip to main content

problem in modelling constraints

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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    Your initial approach was correct except that you should use addConstr instead of addConstrs

    for d_2 in range(365):
    t3
    = d_2 * 24
    t4 = (d_2 + 1) * 24
    for p in range(num_prod):
    m.addConstr((HP.sum(p, t) for t in range(t3, t4, 1))
    == (HT.sum(d_2, p, '*')))

    For your second question, it's quite hard to help here with the limited information. Is NUM_R a constant value? It sounds like you are trying to model a conditional constraint with an equality condition, i.e., something similar to "if sum(HT) = some value then sum(Y) = some other value", is this correct?

    0
  • José Rodrigues
    • Gurobi-versary
    • Curious
    • Conversationalist

    Dear Jaromił, 

    Thank you for your fast reply. I've done exatcly as you mentioned and this error was prompted:

    TypeError: unsupported operand type(s) for *: 'int' and 'generator'

    Regarding the last question I just realised that on of the constraints I already have takes care of I what I intended, thank you anyways. 

    0
  • Jaromił Najman
    • Gurobi Staff

    Could you try

    for d_2 in range(365):
    t3
    = d_2 * 24
    t4 = (d_2 + 1) * 24
    for p in range(num_prod):
    m.
    addConstr(quicksum(HP[p, t] for t in range(t3, t4, 1)) == (HT.sum(d_2, p, '*'))

    If this does not help, could you please post a minimal working example to reproduce the TypeError?

    Best regards, 
    Jaromił

    0
  • José Rodrigues
    • Gurobi-versary
    • Curious
    • Conversationalist

    Hi, 

    Yes, it worked! Thank you.

    0

Post is closed for comments.