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

Problem formulation for to satisfy the demand for a list of products

回答済み

コメント

5件のコメント

  • 正式なコメント
    Juan Orozco
    • Gurobi Staff

    You can use the method model.setPWLObj(), so I suggest to read the associated documentation, as well as the section Objectives of our reference manual.

  • 正式なコメント
    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.
  • Krzysztof Suwada
    • Gurobi-versary
    • First Comment
    • First Question

    Ok, and what if I want it to be a part of a variable?
    something like this code

    for loc_a in locations:
            for loc_b in locations:
                if loc_a != loc_b:
                    m.addConstr(total_value[loc_a, loc_b] == quicksum(x[loc_a, loc_b, p]*price[p] for p in products))
                   if total_value[loc_a, loc_b] < 1500 and total_value[loc_a, loc_b] > 1000:
                         m.addConstr(value_penalty[loc_a, loc_b] = 1500 - total_value[loc_a, loc_b])
                   else:
                        m.addConstr(value_penalty[loc_a, loc_b] = 2*(1500 - total_value[loc_a, loc_b])) 

     

    0
  • Krzysztof Suwada
    • Gurobi-versary
    • First Comment
    • First Question

    And then I want to sum-up all the penalties and add it to a objective function.

     

    0
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    Hi Krzysztof,

    I would suggest that you proceed in the way suggested by Juan.

    Perhaps the following code snippet will be an inspiration for you:

    for loc_a in locations:
            for loc_b in locations:
                if loc_a != loc_b:
    m.setPWLObj(total_value[loc_a, loc_b], [0, 15, 20, 30], [0, 10, 50, 1000000])

    It should generally do everything you are after: define a piecewise-linear penalty for your variables and include them in your objective function.

    Hope this helps.

    Best regards
    Jonasz

    0

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