CS/ECE/ISyE 524 Introduction to Optimization Spring 2017–18 20. Logic constraints, integer variables ❼ If-then constraints ❼ Generalized assignment problems ❼ Logic constraints ❼ Modeling a restricted set of values ❼ Sudoku! Laurent Lessard (www.laurentlessard.com)
If-then constraints A single simple trick (with suitable adjustments) can help us model a great variety of if-then constraints The trick ❼ We’d like to model the constraint: if z = 0 then a T x ≤ b . ❼ Let M be an upper bound for a T x − b . ❼ Write: a T x − b ≤ Mz ❼ If z = 0, then a T x − b ≤ 0 as required. Otherwise, we get a T x − b ≤ M , which is always true. 20-2
If-then constraints Slight change: if z = 1 then a T x ≤ b ❼ Again, let M be an upper bound for a T x − b ❼ Write: a T x − b ≤ M (1 − z ) Reversed inequality: if z = 0 then a T x ≥ b ❼ Write constraint as − a T x + b ≤ 0 ❼ Let m be an upper bound on − a T x + b ❼ Write: − a T x + b ≤ mz . Same as: a T x − b ≥ − mz ❼ Note: − m is a lower bound on a T x − b . 20-3
If-then constraints The converse: if a T x ≤ b then z = 1 ❼ Equivalent to: if z = 0 then a T x > b (contrapositive). ❼ The strict inequality is not really enforceable. Instead, write: if z = 0 then a T x ≥ b + ε where ε is small. ❼ Let m be a lower bound for a T x − b and we obtain the equivalent constraint: a T x − b ≥ mz + ε (1 − z ) ❼ If z = 0, we get a T x ≥ b + ε , as required. Otherwise, we get: a T x − b ≥ m , which is always true. ❼ Note: If a , x , b are integer-valued, we may set ε = 1. 20-4
If-then constraints (summary) Logic statement Constraint if z = 0 then a T x ≤ b a T x − b ≤ Mz if z = 0 then a T x ≥ b a T x − b ≥ mz if z = 1 then a T x ≤ b a T x − b ≤ M (1 − z ) if z = 1 then a T x ≥ b a T x − b ≥ m (1 − z ) if a T x ≤ b then z = 1 a T x − b ≥ mz + ε (1 − z ) if a T x ≥ b then z = 1 a T x − b ≤ Mz − ε (1 − z ) if a T x ≤ b then z = 0 a T x − b ≥ m (1 − z ) + ε z if a T x ≥ b then z = 0 a T x − b ≤ M (1 − z ) − ε z Where M and m are upper and lower bounds on a T x − b . 20-5
Return to fixed costs and lower bounds ❼ Modeling a fixed cost: if x > 0 then z = 1. ◮ Use the contrapositive: if z = 0 then x ≤ 0. ◮ Apply the 1 st rule on Slide 20-5. ❼ Modeling a lower bound: either x = 0 or x ≥ m . ◮ Equivalent to: if x > 0 then x ≥ m . ◮ Equivalent to the following two logical constraints: if x > 0 then z = 1, and if z = 1 then x ≥ m . ◮ The first one is a fixed cost (see above) ◮ The second one is the 4 th rule on Slide 20-5. 20-6
Generalized assignment problems (GAP) ❼ Set of machines: M = { 1 , 2 , . . . , m } that can perform jobs. (think of these as the facilities in the facility problem) ❼ Machine i has a fixed cost of h i if we use it at all. ❼ Machine i has a capacity of b i units of work (this is new!) ❼ Set of jobs: N = { 1 , 2 , . . . , n } that must be performed. (think of these as the customers in the facility problem) ❼ Job j requires a ij units of work to be completed if it is completed on machine i . ❼ Job j will cost c ij if it is completed on machine i . ❼ Each job must be assigned to exactly one machine. 20-7
GAP model � � � minimize h i z i + (fixed cost + assignment cost) c ij x ij x , z i ∈M i ∈M j ∈N � ∀ j ∈ N subject to: x ij = 1 (one machine per job) i ∈M � a ij x ij ≤ b i ∀ i ∈ M (work budget) j ∈N x ij ≤ z i ∀ i ∈ M , j ∈ N (if x ij > 0 then z i = 1) x ij , z i ∈ { 0 , 1 } ∀ i ∈ M , j ∈ N (all binary!) ❼ z i = 1 if machine i is used, and ❼ x ij = 1 if job j is performed by machine i . ❼ Note: many choices possible for M i and aggregations. 20-8
New constraints Let’s make GAP more interesting... 1. If you use k or more machines, you must pay a penalty of λ . 2. If you operate either machine 1 or machine 2, you may not operate both machines 3 and 4 at the same time. 3. If you operate both machines 1 and 2, then machine 3 must be operated at 40% of its capacity. 4. Each job j ∈ N has a duration d j . Minimize the time we have to wait before all jobs are completed. (this is called the makespan ). 20-9
GAP 1 If you use k or more machines, you must pay a penalty of λ . ❼ Using k or more machines is equivalent to saying that z 1 + z 2 + · · · + z m ≥ k ❼ Let δ 1 = 1 if we incur the penalty. We now have the if-then constraint: if � i ∈M z i ≥ k then δ 1 = 1. ❼ Use the 6 th rule on Slide 20-5 and obtain: � i ∈M z i ≤ m δ 1 + ( k − 1)(1 − δ 1 ) ❼ add λδ 1 to the cost function. 20-10
GAP 2 If you operate either machine 1 or machine 2, you may not operate both machines 3 and 4 at the same time. ❼ Operating machine 1 or machine 2: z 1 + z 2 ≥ 1. ❼ Not operating machines 3 and 4: z 3 + z 4 ≤ 1 ❼ We must model z 1 + z 2 ≥ 1 = ⇒ z 3 + z 4 ≤ 1 ◮ Same trick as before: model this in two steps: z 1 + z 2 ≥ 1 = ⇒ δ 2 = 1 ⇒ z 3 + z 4 ≤ 1 and δ 2 = 1 = ◮ First follows from 6 th rule on Slide 20-5 ◮ Second follows from 3 rd rule on Slide 20-5 ❼ Result: z 1 + z 2 ≤ 2 δ 2 and z 3 + z 4 + δ 2 ≤ 2. 20-11
GAP 2 (cont’d) If you operate either machine 1 or machine 2, you may not operate both machines 3 and 4 at the same time. We didn’t do anything to ensure that when z i = 1, the machines are actually operating! (we didn’t explicitly disallow paying the fixed cost without using the machine). ❼ To force the converse as well, include the constraint: if z i = 1 then � j ∈N x ij ≥ 1 ❼ Use the 4 th rule on Slide 20-5. ❼ Result: � j ∈N x ij ≥ z i (for i = 1 , 2 , 3 , 4) 20-12
GAP 3 If you operate both machines 1 and 2, then machine 3 must be operated at 40% of its capacity. ❼ Operate both machines 1 and 2: z 1 + z 2 ≥ 2 ❼ Capacity of machine 3 drops: b 3 becomes 0 . 4 b 3 . ❼ Two parts to the implementation: ⇒ δ 3 = 1. (6 th rule on Slide 20-5) ◮ z 1 + z 2 ≥ 2 = j ∈N a 3 j x 3 j ≤ 0 . 4 b 3 . (3 rd rule on Slide 20-5) ◮ δ 3 = 1 = ⇒ � ❼ Equivalently, just replace b 3 by: b 3 (1 − δ 3 ) + 0 . 4 b 3 δ 3 . 20-13
GAP 4 Each job j ∈ N has a duration d j . Minimize the time we have to wait before all jobs are completed. (the makespan) ❼ Machine i completes all its jobs in time: � j ∈N x ij d j ❼ Minimax problem (no integer variables needed!) �� � ❼ Let t be the makespan; t = max i ∈M j ∈N x ij d j ❼ Model: minimize t subject to: � t ≥ for all i ∈ M x ij d j j ∈N 20-14
Logic constraints ❼ A proposition is a statement that evaluates to true or false. One example we’ve seen: a linear constraint a T x ≤ b . ❼ We’ll use binary variables δ i to represent propositions P i : � 1 if proposition P i is true δ i = 0 if proposition P i is false The term for this is that δ i is an indicator variable . How can we turn logical statements about the P i ’s into algebraic statements involving the δ i ’s? Some standard notation: ∨ means “or” = ⇒ means “implies” ∧ means “and” ⇐ ⇒ means “if and only if” ¬ means “not” ⊕ means “exclusive or” 20-15
Boolean algebra Basic definitions: P Q P ∧ Q P ∨ Q P ⊕ Q 1 1 1 1 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 Useful relationships: ❼ ¬ ( P 1 ∧ · · · ∧ P k ) = ¬ P 1 ∨ · · · ∨ ¬ P k ❼ ¬ ( P 1 ∨ · · · ∨ P k ) = ¬ P 1 ∧ · · · ∧ ¬ P k ❼ P ∧ ( Q ∨ R ) = ( P ∧ Q ) ∨ ( P ∧ R ) ❼ P ∨ ( Q ∧ R ) = ( P ∨ Q ) ∧ ( P ∨ R ) ❼ P ⊕ Q = ( P ∧ ¬ Q ) ∨ ( ¬ P ∧ Q ) 20-16
Logic to algebra Statement Constraint ¬ P 1 δ 1 = 0 P 1 ∨ P 2 δ 1 + δ 2 ≥ 1 P 1 ⊕ P 2 δ 1 + δ 2 = 1 P 1 ∧ P 2 δ 1 = 1, δ 2 = 1 ¬ ( P 1 ∨ P 2 ) δ 1 = 0, δ 2 = 0 P 1 = ⇒ P 2 δ 1 ≤ δ 2 (equivalent to: ( ¬ P 1 ) ∨ P 2 ) ⇒ ( ¬ P 2 ) δ 1 + δ 2 ≤ 1 (equivalent to: ¬ ( P 1 ∧ P 2 )) P 1 = P 1 ⇐ ⇒ P 2 δ 1 = δ 2 ⇒ ( P 2 ∧ P 3 ) δ 1 ≤ δ 2 , δ 1 ≤ δ 3 P 1 = P 1 = ⇒ ( P 2 ∨ P 3 ) δ 1 ≤ δ 2 + δ 3 ( P 1 ∧ P 2 ) = ⇒ P 3 δ 1 + δ 2 ≤ 1 + δ 3 ( P 1 ∨ P 2 ) = ⇒ P 3 δ 1 ≤ δ 3 , δ 2 ≤ δ 3 P 1 ∧ ( P 2 ∨ P 3 ) δ 1 = 1, δ 2 + δ 3 ≥ 1 P 1 ∨ ( P 2 ∧ P 3 ) δ 1 + δ 2 ≥ 1, δ 1 + δ 3 ≥ 1 20-17
More logic to algebra Statement Constraint k � P 1 ∨ P 2 ∨ · · · ∨ P k δ i ≥ 1 i =1 k n � � ( P 1 ∧ · · · ∧ P k ) = ⇒ ( P k +1 ∨ · · · ∨ P n ) (1 − δ i ) + δ i ≥ 1 i =1 i = k +1 n � at least k out of n are true δ i ≥ k i =1 n � exactly k out of n are true δ i = k i =1 n � δ i ≤ k at most k out of n are true i =1 k � P n ⇐ ⇒ ( P 1 ∨ · · · ∨ P k ) δ i ≥ δ n , δ n ≥ δ j , j = 1 , . . . , k i =1 k � P n ⇐ ⇒ ( P 1 ∧ · · · ∧ P k ) δ n + k ≥ 1 + δ i , δ j ≥ δ n , j = 1 , . . . , k i =1 20-18
Modeling a restricted set of values ❼ We may want variable x to only take on values in the set { a 1 , . . . , a m } . ❼ We introduce binary variables y 1 , . . . , y m and the constraints m m � � x = a j y j , y j = 1 , y j ∈ { 0 , 1 } j =1 j =1 ❼ y i serves to select which a i will be selected. ❼ The set of variables { y 1 , y 2 , . . . , y m } is called a special ordered set (SOS) of variables. 20-19
Recommend
More recommend