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

problem in modeling constraint

回答済み

コメント

12件のコメント

  • 正式なコメント
    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?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmed,

    One possible way would be to introduce additional binary variables, 1 integer variable, and make use of the indicator constraints feature.

    \[\begin{align}
    \sum_{p \in P} S_r^p &= z\\
    b_i = 1 &\Rightarrow z = i \quad\forall i \in \{0,\dots,7\} \text{ // these are 8 indicator constraints}\\
    b_0 = 1 &\Rightarrow x_r = \gamma_r \cdot 0 \text{ // indicator constraints to model the multiplication with 0}\\
    b_0 = 1 &\Rightarrow  \gamma_r = 0\\
    b_i = 1 &\Rightarrow x_r = \gamma_r \cdot (1-(i-1)\cdot 0.05) \quad \forall i \in \{1,\dots,7\} \text{ // indicator constraints to model the remaining multiplications}\\
    \sum_i b_i &= 1 \\
    \sum_s \sum_p X_{prsu}& \leq x_r \quad \forall u \in U\quad r\in R\\
    z &\in \{0,\dots,7\}\\
    b_i &\in \{0,1\} \quad i \in \{0,\dots,7\}\\
    x &\in \mathbb{R}_{\geq 0}
    \end{align}\]

    Please note that the above formulation is not guaranteed to be the best or the most compact one.

    Best regards,
    Jaromił

    0
  • ahmed hachem bouguerra
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi,
    thank you for responding 

    i had another idea wich is is  to have 2 constraints : the first one will work for the case of sum(S_r_p)=1 to 7 and the secod one will enforce that the facility will not accept any flow of product if the product is not allowed to be treated in that facility

    what do you think?
     is there a possibility to have a for loop inside addGenConstrIndicator ?

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmed,

    This might work. However, I see two possible difficulties in this formulation. There is no guarantee that

    \[\sum_p S_r^p\]

    will be an integer value between \(0 \leq \dots \leq 7\) (unless you have more information which was not shared here).

    Moreover, the first constraint is now a nonconvex quadratic constraint, because it holds the bilinear multiplications

    \[\gamma_r \cdot S_r^p \]

    I think that in the second constraint the \(\sum\) sign is missing.

    I think that the best and only way to say which formulation works well would be to test both.

    Best regards,
    Jaromił

    0
  • ahmed hachem bouguerra
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi
    in fact S_r_p is binary variable and the products that the model uses are 7 (1,2,...,7) so in maximum the total products that a facility could treat is 7 and the minimum is 0

    γr is constant for all the facilities so it is not a deicision variable
    the ∑ is not missed. that constraint is developed only for the case of 0 products treated in a faicility because the first cosntraint face a problem when it comes to ∑pSpr =0 so the second constraint will work if S_rp is different to 0 but when the facility do not treat a product there will not be a flow that comes to that facility

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmed,

    Thank you for clarifying. With the information that \(S_r^p\) are binaries and \(\gamma_r\) is a constant parameter, your formulation seems way more promising than the one I proposed.

    Best regards,
    Jaromił

    0
  • ahmed hachem bouguerra
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi,
    i'm facing now a modeling problem.

    let's say that i have a facilities that treat many type of products. and each facility has the possibility to treat one or more products and it depends on their speciality. it means that faiclity 1 can  treat p1 and p2 , facility 2 can treat p4 , p5 and p6 ..
    what i mean by can is that theortically they can treat these type od products but it is not ncesseraly that they treat them all. so model choose with a decision varaible wether the facility 1 treat p1 or p2 or both or even not open the facility

    so i'm looking for two thnigs :

    parameter : that describe wether each facility could treat this product or not in the begining
    decision varaible : that can determine finally after executing the model wich from  the list of possible products each facility treated

    and i have to link between them so that i can use the decision variable to obtain the capacity of each facility wich depend on the number of products treated

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmed,

    In this case, you could introduce binary variables for each pair of facility and which product can it treat. So for example for facility 1 you could introduce 2 binary variables \(fp_{11},fp_{12}\). I suppose that in the end, you probably have to check whether every product is treated by at least one facility or something similar. You can achieve that by summing over all these binary for each product so

    \[\sum_i fp_{ij} \geq 1 \quad \forall j \]

    and i have to link between them so that i can use the decision variable to obtain the capacity of each facility wich depend on the number of products treated

    You could use the binary variables to determine the capacity of each facility. For example the constraint

    \[200 fp_{11} + 300 fp_{12} \leq 400\]

    states that facility one can only produce either product 1 or product 2 because if it would produce both, its capacity would be exceeded.

    Best regards,
    Jaromił

    0
  • ahmed hachem bouguerra
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi,
    the thing is my problem is much more complicated than this. I have a logistic network in wich facilities send wastes to other facilities in the next level ( collecting facilities( called c1,c2..),sorting facilities( called S1,S2..) , recycling facilities(Called R1,R2...)

    each one of the recyclling facilities had n types of products that could treat. R1 can treat maximum 3  types of products , R2 can treat maximum 5 products, R3 can treat maximum 1 type of product.let's call Srp binary variables that is equal to 1 if Rn treat product p  and 0 else 

    depends of the number of products that the model chooses to treat for every recycling center their capacity changes. for example :

    every recyling center has his own relation between number of products treated and resulting capacity . and after obtaining the resulting capacity i must put the capacity constraint of each recyling center 
    so i'm having a big problem in connecting this in the same model

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi,

    Do I understand correctly that the only difference to your previous problem is actually hidden in the values of the resulting capacity which cannot be expressed in a linear fashion? You can circumvent this by computing the resulting capacity as described in my first post, i.e., with the usage of indicator constraints. Then, instead of setting

    \[b_i = 1 \Rightarrow x_r = \gamma_r \]
    where \(\gamma_r\) is the resulting capacity for the specific number of products equaling \(i\). You would have to introduce binaries \(b_{ir}\) and the corresponding indicator variables for each facility.

    Best regards,
    Jaromił

    0
  • ahmed hachem bouguerra
    • Gurobi-versary
    • Conversationalist
    • First Question

    Hi
    i have a  decision variable called Q_r_p[r,p] : quantity of product p treated in facility R
    how can i obtain number of  products treated in each facility ? 

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Ahmed,

    When \(b_i\) are the binaries referring to the number of products treated as discussed in the messages above, you can set \(Q_{rp} = \sum_i i\cdot b_i\). Since exactly only \(1\) \(b_i\) can equal \(1\) at a time, the \(\sum_i i\cdot b_i\) term provides you the exact quantity of treated product.

    Best regards,
    Jaromił

    0

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