Skip to main content

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

Answered

Comments

4 comments

  • Official comment
    Juan Orozco
    Gurobi Staff 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.

  • Krzysztof Suwada
    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
    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 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

Please sign in to leave a comment.