メインコンテンツへスキップ

modelling error

回答済み

コメント

5件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • Simranjit Kaur
    • Gurobi Staff

    Hi,

    Are you trying to model 

    \[\sum_{m \in months} R_m/2 = \sum_{s \in skills, m \in months}y_{s,m}b_{s,m}\]
    or
    \[R_m/2 = \sum_{s \in skills}y_{s,m}b_{s,m} \qquad \forall \  m \in months \ ?\]

    Option 1 can be modelled as:

    F = m.addConstr( gp.quicksum(R[month]/2 for month in months) == gp.quicksum(y[skill, month]*b[skill, month] for skill in skills for month in months), name ="R")

    Option 2 can be modelled as:

    F = m.addConstrs( (R[month]/2 == gp.quicksum(y[skill, month]*b[skill, month] for skill in skills)  for month in months), name="R")
    I hope this helps.
     
    Best regards,
    Simran
    0
  • Ege ö
    • Gurobi-versary
    • First Comment
    • First Question

    I was trying to write 2nd funtion, now it works, thank you for your support Simranjit :)

    0
  • Ege ö
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Simranjit,

    I would be very happy if you make some comment s about below error too:

    Total_rev = m.addVars(months, vtype=GRB.CONTINUOUS, name="totalrevenue")
    Total_revenue= m.addConstr( (Total_rev[month] for month in months) == gp.quicksum( p[skill,product,month]*r[product]*x[skill, month] + k[skill,product,month]*r[product]*y[skill, month] for skill in skills for month in months for product in products), name= "rev") 

    KeyError: (1, 1, 1)


     

    0
  • Simranjit Kaur
    • Gurobi Staff

    Hi Ege,

    A KeyError is raised when you try to access an element before it is created. Please check if p[1,1,1] and k[1,1,1] exist.

    Also, please consider re-writing the Total_revenue constraint. In its current form, it will throw the same error as you had in the first constraint we discussed in this post. 

    Best regards,
    Simran

    0

投稿コメントは受け付けていません。