22 more models qap and sos
play

22. More models, QAP and SOS Quadratic assignment problems SOS1 - PowerPoint PPT Presentation

CS/ECE/ISyE 524 Introduction to Optimization Spring 201718 22. More models, QAP and SOS Quadratic assignment problems SOS1 constraints SOS2 constraints General piecewise linear functions Laurent Lessard


  1. CS/ECE/ISyE 524 Introduction to Optimization Spring 2017–18 22. More models, QAP and SOS ❼ Quadratic assignment problems ❼ SOS1 constraints ❼ SOS2 constraints ❼ General piecewise linear functions Laurent Lessard (www.laurentlessard.com)

  2. Quadratic assignment problems (QAP) Two big classes of problems seen so far: ❼ GAP: Assign jobs to machines. Each assignment has a price, each machine has a fixed cost and a max capacity. ❼ TSP: Find the optimal sequence of items (or cities). Each possible transition has an associated cost. (probably the most famous integer program) One more important class of problems: ❼ QAP: Assign facilities to fixed locations. The facilities have known communication requirements and incurred costs depend on the distances between the facilities. (second most famous integer program – harder than TSP) 22-2

  3. QAP example: shopping mall A small shopping mall has four shop locations. The walking distance, in feet, between all pairs of locations are shown below. Four shops, designated A, B, C, D, are to be assigned to the four locations in such a way that customers traveling between pairs of shops will not walk too far. We have data on the number of customers per week that travel between the shops, shown below. Distance 1 2 3 4 Flow A B C D 1 0 80 150 170 A 0 5 2 7 2 0 130 100 B 0 3 8 3 0 120 C 0 3 4 0 D 0 d ij f ij ❼ let x ij = 1 if shop i is in location j . 22-3

  4. QAP example: shopping mall ❼ Each shop can only be in one location: L � x ij = 1 for i = 1 , . . . , S j =1 ❼ Each location can only contain one shop: S � x ij = 1 for j = 1 , . . . , L i =1 ❼ Cost depends on pairs of facilities! If shop i is in location j and shop k is in location ℓ , then between them we have a flow of f ik and a distance of d j ℓ . The total cost is: S L S L 1 � � � � f ik d j ℓ x ij x k ℓ 2 i =1 j =1 k =1 ℓ =1 22-4

  5. QAP example: shopping mall S L S L 1 � � � � minimize f ik d j ℓ x ij x k ℓ 2 x i =1 j =1 k =1 ℓ =1 L � subject to: x ij = 1 for i = 1 , . . . , S j =1 S � x ij = 1 for j = 1 , . . . , L i =1 x ij ∈ { 0 , 1 } ❼ cost is quadratic in the variables! Can we linearize? ❼ define new binary variable: z ijk ℓ = x ij x k ℓ 22-5

  6. QAP example: shopping mall S L S L 1 � � � � minimize f ik d j ℓ z ijk ℓ 2 x , z i =1 j =1 k =1 ℓ =1 L � subject to: x ij = 1 for i = 1 , . . . , S j =1 S � x ij = 1 for j = 1 , . . . , L i =1 x ij ∈ { 0 , 1 } z ijk ℓ = x ij x k ℓ ❼ Equivalent to: ( z ijk ℓ = 1) ⇐ ⇒ ( x ij = 1) ∧ ( x k ℓ = 1) 22-6

  7. QAP example: shopping mall How do we model: ( z ijk ℓ = 1) ⇐ ⇒ ( x ij = 1) ∧ ( x k ℓ = 1) ? ❼ we saw this when we discussed logic constraints! ◮ ( = ⇒ ): x ij ≥ z ijk ℓ and x k ℓ ≥ z ijk ℓ ◮ ( ⇐ = ): x ij + x k ℓ ≤ z ijk ℓ + 1 22-7

  8. QAP example: shopping mall S L S L 1 � � � � minimize f ik d j ℓ z ijk ℓ 2 x , z i =1 j =1 k =1 ℓ =1 L � subject to: x ij = 1 ∀ i j =1 S � x ij = 1 ∀ j i =1 x ij ≥ z ijk ℓ and x k ℓ ≥ z ijk ℓ ∀ i , j , k , ℓ x ij + x k ℓ ≤ z ijk ℓ + 1 ∀ i , j , k , ℓ x ij , z ijk ℓ ∈ { 0 , 1 } ∀ i , j , k , ℓ ❼ Julia code: QAP.ipynb 22-8

  9. QAP example: circuit layout ❼ Place n electronic modules in n predetermined positions on a backplate. ❼ We are given a wiring specification that tells us how the various modules must be connected. ❼ Identical to the facility location problem: ◮ f ij is the number of wires between module i and module j ◮ d ij distance between positions i and j on the backplate. ◮ Minimize total length of wire used. 22-9

  10. Special ordered sets ❼ Another type of constraint that is standard among many solvers is called the special ordered set (SOS). ❼ We saw one type of SOS constraint in the context of a variable belonging to a discrete set of values. There are other types of SOS constraints (we will see them next!) ❼ All SOS constraints can be implemented using logic tricks but some solvers also allow you to specify them explicitly. Only two reasons you would ever want to do this ◮ It makes your code run faster ◮ It makes your code easier to understand ❼ Some solvers can automatically detect SOS constraints. 22-10

  11. SOS1 (type 1) constraint SOS1 constraint: The variables { x 1 , . . . , x m } satisfy an SOS1 constraint if at most one of them is nonzero . ❼ An SOS1 constraint represents a multiple-choice notion. ❼ Standard use: representing a discrete-valued function 22-11

  12. SOS1 (type 1) constraint y a 3 4 a 1 a 5 3 a 2 a 6 2 a 4 1 0 x 1 x 2 x 3 x 4 x 5 x 6 x ❼ Let ( x i , a i ), i = 1 , . . . , m be the admissible ( x , y ) pairs. ❼ write: x = � m i =1 x i λ i and y = � m i =1 a i λ i . ❼ constraint: exactly one of the λ i is equal to 1, the rest are equal to zero. 22-12

  13. SOS1 constraint Using SOS1 constraint Using algebraic forumlation m m � � y = a i λ i y = a i λ i i =1 i =1 m m � � λ i = 1 , λ i ≥ 0 λ i = 1 i =1 i =1 { λ 1 , . . . , λ m } is SOS1 λ i ∈ { 0 , 1 } ❼ The λ i are real (not binary) in the SOS1 formulation ❼ Solver will still use binary variables internally, of course ❼ IJulia example: SOS.ipynb 22-13

  14. SOS2 (type 2) constraint SOS2 constraint: The variables { x 1 , . . . , x m } satisfy an SOS2 constraint if at most two of them are nonzero . Also, nonzero elements must be consecutive. ❼ SOS2 constraints are typically used to represent piecewise-linear functions. 22-14

  15. SOS2 (type 2) constraint y a 3 4 a 1 a 5 ( x , y ) 3 y a 6 2 a 2 1 a 4 0 x 1 x 2 x 3 x x 4 x 5 x 6 x ❼ Let ( x i , a i ), i = 1 , . . . , m be the transition points. ❼ x = � m i =1 x i λ i and y = � m i =1 a i λ i with � m i =1 λ i = 1. ❼ If x i < x < x i +1 then λ i + λ i +1 = 1 and the other λ j are zero. Then, x = λ i x i + λ i +1 x i +1 and y = λ i a i + λ i +1 a i +1 22-15

  16. SOS2 (type 2) constraint How do we represent the constraint that at most two of the variables { λ 1 , . . . , λ m } are nonzero, and nonzero variables must be consecutive? ❼ Let { z 1 , . . . , z m − 1 } be binary with � m − 1 i =1 z i = 1. ❼ If z i = 1, then λ i and λ i +1 can be nonzero. ❼ In other words: if z i − 1 and z i are zero, then λ i = 0. z 1 z 2 z 3 z 4 z 5 x x 1 x 2 x 3 x 4 x 5 x 6 22-16

  17. SOS2 constraint SOS2 constraint Using algebraic forumlation m m � � y = a i λ i y = a i λ i i =1 i =1 m m � � λ i = 1 , λ i ≥ 0 λ i = 1 , λ i ≥ 0 i =1 i =1 { λ 1 , . . . , λ m } is SOS2 λ 1 ≤ z 1 λ i ≤ z i − 1 + z i , i = 2 , . . . , m − 1 λ m ≤ z m − 1 ❼ Extra binary variables m − 1 needed in algebraic � z i = 1 , z i ∈ { 0 , 1 } formulation. i =1 ❼ Solver still uses binary variables for SOS2. 22-17

  18. General piecewise linear functions y We may have: 5 4 t n e m 4 g ❼ segments overlapping s e e g s m segment 3 e 3 n t ❼ semi-infinite or 1 infinite segments 2 segment 2 ❼ holes in the space of 1 x coordinates 0 0 1 2 3 4 5 6 7 8 9 10 x x f ℓ g For each segment, record: segment 1 3 2 −∞ − 1 ❼ an endpoint ( x , f ) segment 2 2 1 4 0 ❼ the x -length ℓ segment 3 6 1 1 3 ❼ the slope g . segment 4 8 2 ∞ 1 22-18

  19. General piecewise linear functions ❼ The segment i has two variables associated with it: ◮ z i , a binary variable that selects whether segment i is active or not. Note that the { z 1 , . . . , z m } are SOS1. ◮ λ i , a nonnegative real variable that chooses how far along segment i we are situated. Note that 0 ≤ λ i ≤ | ℓ i | . ❼ The general point ( x , f ) on the function is given by: ◮ x = � m i =1 ( z i x i + sign( ℓ i ) λ i ), f = � m i =1 ( z i f i + sign( ℓ i ) g i λ i ) ❼ We also require some constraints: ◮ z i ∈ { 0 , 1 } and � m i =1 z i = 1 ◮ 0 ≤ λ i ≤ | ℓ i | . ◮ if z i = 0 then λ i = 0. (this is tricky!) 22-19

  20. General piecewise linear functions How do we impose the constraint that if z i = 0 then λ i = 0 ? ❼ If ℓ i is finite, then we have the bound 0 ≤ λ i ≤ | ℓ i | so we can use the standard fixed cost trick: λ i ≤ | ℓ i | z i ❼ If ℓ i = ±∞ then this won’t work! ❼ For the infinte case, we can use the constraint: { λ i , 1 − z i } is SOS1 There is no upper bound for λ i (and so we can’t model algebraically) but solvers can nonetheless implement this constraint efficiently. 22-20

Recommend


More recommend