整數線性規劃模型建立. 使用二元變數 the use of binary variables in constraints...

41
整整整整整整整整整整

Post on 20-Dec-2015

287 views

Category:

Documents


0 download

TRANSCRIPT

整數線性規劃模型建立

使用二元變數The use of binary variables in constraints

X 10 If a new health care plan is adopted If it is not

X 1 If a new police station is built downtown0 If it is not

X 1 If a particular constraint must hold0 If it is not

• 一個變數之決策結果分為 “ yes”/“no”, “good”/“bad” 等 . 皆為二元分類

• 說明

• 許多現實模型中至少一個決策變數為整數值– 整數模型之分類

• 純整數線性模型 Pure integer (AILP) :所有決策變數皆為整數

• 二元整數線性模型 Binary (BILP) :所有決策變數皆為二元數 (0 或 1)

• 混合整數線性模型 Mixed integer (MILP) :有些變數非整數或二元值

典型範例 (Prototype Example)

• Decision Variables

• Objective Function Z=Total Net Present Values

of these decisions

4,3,2,1no"" isdecision if 0,

yes"" isjdecision if ,1

jj

X j

Max Z= 9X1 + 5X2 + 6 X3 + 4X4

Decision No

“Yes” or “No”

Decision Variable

Net Present Value

Capital Cost

(million)

1 LA 建工廠? X1 $9 $6

2 SF 建工廠? X2 $5 $3

3 LA 建倉庫? X3 $6 $5

4 SF 建倉庫? X4 $4 $2

可用資金 : $10(million)

Constraint Descriptions

1. 4 項設備之總資金最多為$ 10

2. 該公司最多建造一間倉庫 ( 互斥決策 , Mutually Exculsive )

3. 公司僅考慮在建廠的城市增設新倉庫

( 附屬方案 , Contigent Decision )

Constraint Models

6X1+3X2+5X3 +2X4 10

X3 + X4 1

X3 X1

X4 X2

Math Model

Max Z= 9X1+5X2+ 6X3 + 4X4

S.T.

6X1+3X2+ 5X3 + 2X4 10

X3 + X4 1

- X1 + X3

- X2 + X4

Xj

X j X1 , X2 , X3 , X4 integers

X1 , X2 , X3 , X4 binary

• 範例說明– 二元變數 Yi 表示某家工廠是否要建 (Yi = 1) 或不建

(Yi = 0)

需求 Requirement 二元 Binary 表示法 1. 三家工廠中至少兩家 工廠要被建立 Y1 + Y2 + Y3 2

2. 若工廠 1 要建,則工廠 2 不能建 Y1 + Y2 1

3. 若工廠 1 要建,則工廠 2 也要建 Y1 – Y2

4. 一間工廠要建, 但不可以兩間工廠同時建 Y1+ Y2 = 1

5. 兩者都要或都不要建 Y1 – Y2 =0

6. 工廠建設不可超過 $17 百萬 其中個別成本為 $5, $8, $10 百萬 5Y1+8Y2+10Y3 17

• 工廠 1 生產鋼材可以製造兩種產品:

– 產品 1 需要 6 磅重鋼材,產品 2 需要 9 磅重鋼材 – 若工廠 1 被建後,將有 2000 磅重鋼材可以利用– 此產品是否生產取決於工廠 1 是否建立,表示式如下

6X1 + 9X2 2000Y1

補充範例一 ( 見講義 )

若工廠 1 建立則 Y1 = 1.限制式變為6x1 + 9X2 2000

若工廠 1 不建則 Y1 = 0限制式變為6x1 + 9X2 0, 且X1 = 0 , X2 = 0

補充範例二:固定費用模型 ( 見講義 )(Fixed-Charge Model)

某工廠製造三種類型衣服: Shirts, Shorts, Pants 。該廠必須租用機器來製造不同類型之衣服,- 機器租金分別如下: Shirts 用機器每週租金為 $200 , Shorts 用機器每週租金為 $150 , Pants 用機器每週租金為 $100

- 製造衣服所需要勞力與布料的資料,以及其單位售價與單位製造成本分別如下表所示:

勞力 (每小時 )

布料 (每單位 )

單位售價 單位製造成本

Shirts 3 4 $12 $6

Shorts 2 3 $8 $4

Pants 6 4 $15 $8

• Decision Variables

not isit if 0

produced pantsany if 1

not isit if 0

produced shortsany if 1

not isit if 0

produced shirtsany if 1

3

2

1

y

y

yX1= number of shirts produced per week

X2= number of shorts produced per week

X3= number of pants produced per week

Z = (12X1 + 8X2 + 15X3)- (6X1 + 4X2 + 8X3)- (200y1 + 150y2 + 100y3)

= 6X1+4X2+ 7X3 - 200y1- 150y2 -100y3

• Weekly Profits

= Weekly Sales Revenue- Weekly Production Cost - Weekly Renting (Setup) Cost

• Objective Function

• Math ModelMax Z= 6X1+4X2+ 7X3 -200y1-150y2-100y3

S.T. 3X1 + 2X2 + 6X3 150

4X1 + 3X2 + 4X3 160

X1 , X2 , X3 integers

y1 , y2 , y3 binary

• Constraints:

C1: At most 150 hours of labors can be used per week

6X1 + 2X2 + 6X3 <= 150

C2: At most 160 units of cloth can be used per week

4X1 + 3X2 + 4X3 <= 160

以 LP 求解得到:

X1 = 30

X2 = 0

X3 = 10

y1 = 0

y2 = 0

y3 = 0

• Math ModelMax Z= 6X1+4X2+ 7X3 -200y1-150y2-100y3

S.T. 3X1 + 2X2 + 6X3 150

4X1 + 3X2 + 4X3 160

X1 y1

X2 y2

X3 y3

X1 , X2 , X3 integers

y1 , y2 , y3 binary

• Constraints:

加入:

If Xi>0, then yi=1

We have

X1 <= M*y1

X2 <= M*y2

X3 <= M*y2

以 LP 求解得到:

X1* = 0

X2*= 0

X3* = 25

y1 = 0

y2 = 0

y3 = 1

With Z*=75

補充範例三:集合覆蓋模型 ( 見講義 )(Set Covering Model)

某縣有六個重要鄉鎮,該縣政府計畫興建消防隊,因此希望決定建立最少的消防隊數以確保每個城市至少有一對消防隊伍能在 15 分鐘的車程內。各鄉鎮間與其他鄉鎮的車程時間以下表所示,試建立 IP 最佳化模式使得消防隊數為最小。

車程時間To

City 1 City 2 City 3 City 4 City 5 City 6

From City 1 0 10 20 30 30 20

City 2 10 0 25 35 20 10

City 3 20 25 0 15 30 20

City 4 30 35 15 0 15 25

City 5 30 20 30 15 0 14

City 6 20 10 20 25 14 0

• Decision Variables

• Objective Function

6,..,1

not isit if 0,

icity in built isstation fire a if1,

i

xi

Min Z = X1 + X2 + X3 + X4 + X5 + X6

Cities within 15 mins of given city Constraints

City 1 City 1, City 2 X1 + X2 >=1

City 2 City 1, City 2, City 6 X1 + X2 + X6 >=1

City 3 City 3, City 4 X3 + X4 >=1

City 4 City 3, City 4, City 5 X3 + X4 + X5 >=1

City 5 City 4, City 5, City 6 X4 + X5 + X6 >=1

City 6 City 2, City 5, City 6 X2 + X5 + X6 >=1

• Math Model

Min Z= X1+X2+ X3 +X4 + X5 +X6

S.T. X1+X2

X1+X2 +X6

X3 +X4

X3 +X4 + X5

X4 + X5 +X6

X2 + X5 +X6

X1 , X2 , X3 , X4 , X5 , X6 binary

以 LP 求解得到:

X1* = 0

X2*= 1

X3* = 0

X4* = 1

X5*= 0

X6* = 0

With Z*=2

• 專案選擇模型由一群二元變數表示” “ go/no-go” 的決定

• 模型中包含元件有 :– 預算 Budget– 空間 Space– 優先順序 Priority conditions

補充範例四:專案選擇模型 ( 見講義 )(Project Selection Model)

• A 市議會的目標是最大化選民之支持度下合理分派預算

• 資料中包含成本 costs, 可利用資源 , 計畫優順序 .

A 市議會─專案選擇

計畫 成本($1000) 工作 記點僱請七名新警官 400.00$ 7 4176警察總部現代化 350.00$ 0 1774購買新警車 50.00$ 1 2513巡邏警察恤金 100.00$ 0 1928購買新消防車與支援設備 500.00$ 2 3607雇用消防局助理 90.00$ 1 962恢復被刪體育計畫 220.00$ 8 2829恢復被刪音樂計畫 150.00$ 3 1708高中新購新電腦 140.00$ 2 3003

民調之結果

X1

X2

X3

X4

X5

X6

X7

X8

X9

A 市議會─專案選擇

• 決策變數 : Xj- 一組二元決策變數; if a project j is selected (Xj=1) or not (Xj=0) for j=1,2,..,9

• 目標函數 :使經費之計畫總點數最大化

• 限制式 :See the mathematical model.

A 市議會─專案選擇

互斥性:警車與消防車購其一

體育與音樂須在電腦設備購買前通過

共同必要性:體育與音樂同時恢復或不恢復

最大預算不能超過 $900,000

4 個警察計畫中至多 3 個限制式通過

工作創造限制式:至少十個工作數量

The Mathematical Model

(Xi = 0,1 for i=1, 2…, 9)

Max 4176X1+1774X2+ 2513X3+1928X4+3607X5+962X6+2829X7+1708X8+3003X9

S.T. 400X1+350X2+ 50X3+ 100X4+500X5+90X6+ 220X7+ 150X8+ 140X9

900

7X1+ X3+ 2X5+ X6+ 8X7+ 3X8+ 2x9

10

X1+ X2+ X3+ X4 3

X3+ X5 = 1

X7 - X8 = 0

X7 - X9 0

x8 - x9

整數規劃模式彙整1. 二選一限制式 (Either-Or Constraints)

Either 6X1 + 2X2 + 6X3 <= 150

or X1 + 3X2 + 4X3 <= 100

6X1 + 2X2 + 6X3 <= 150

X1 + 3X2 + 4X3 <= 100 +M

6X1 + 2X2 + 6X3 <= 150 + My

X1 + 3X2 + 4X3 <= 100 +M(1-y)

y = 0 or 1 (y is called Auxiliary Variable)

6X1 + 2X2 + 6X3 <= 150+M

X1 + 3X2 + 4X3 <= 100or

整數規劃模式彙整2. N 個限制式滿足 k 個 (k out of N Constraints)

F1 (X1 ,X2 , ……,Xn ) = d1

F2 (X1 ,X2 , ……,Xn ) = d2

F3 (X1 ,X2 , ……,Xn ) = d3

….

Fn (X1 ,X2 , ……,Xn ) = dn

F1 (X1 ,X2 , ……,Xn ) = d1 + M(1-y1)

F2 (X1 ,X2 , ……,Xn ) = d2 + M(1-y2 )

F3 (X1 ,X2 , ……,Xn ) = d3 + M(1-y3 )

….

Fn (X1 ,X2 , ……,Xn ) = dn + M(1-yn )

binaryykywhere i

N

ii ,

1

課堂練習: (p.11-77) 習題 11.3-3

(1) 下列兩不等式最少有一成立 :

X1 + X2 + X3 + X4 4

3X1 - X2 - X3 + X4 3

X1 + X2 + X3 + X4 4 + M(1-y1)

3X1 - X2 - X3 + X4 3 + M(1-y2)

y1 + y2 1 ,

y1 , y2 binary

(2) 下列四項不等式至少兩項成立 :

5X1 + 3X2 + 3X3 - X4 10

2X1 + 5X2 - X3 + 3X4 10

-X1 + 3X2 + 5X3 + 3X4 10

3X1 - X2 + 3X3 + 5X4 10

5X1 + 3X2 + 3X3 - X4 10 + M(1-y1)

2X1 + 5X2 - X3 + 3X4 10 + M(1-y2)

-X1 + 3X2 + 5X3 + 3X4 10 + M(1-y3)

3X1 - X2 + 3X3 + 5X4 10 + M(1-y4)

y1 + y2 + y3 + y4 2 ,

y1 , y2 , y3 , y4 binary

整數規劃模式彙整3. 函數有 N 個可能值 (Function with N Possible Va

lues)

F1 (X1 ,X2 , ……,Xn ) = d1 or F1 (X1 ,X2 , ……,Xn ) = d2

or F1 (X1 ,X2 , ……,Xn ) = d3

….

or F1 (X1 ,X2 , ……,Xn ) = dn

binaryyywhere

ydxxxF

i

N

ii

N

iiin

,1

,),..,(

1

1211

課堂練習:

6X1 + 2X2 = 5 or 10 or 15 6X1 + 2X2 = 5y1+10y2+15y3

y1+y2+y3 =1,

y1 , y2 , y3 Binary

整數規劃模式彙整  4. Fixed-Charge Problem

  若產品  j 之生產成本,包含固定成本 Kj 與變動成本 Cj ,令 Xj 為產品之生產數量,則其生產成本函數為 :

0,

0,0)(

jjjj

jjj xxCk

xxC

• Math ModelMin Z= ∑ kj yj + Cj Xj

S.T. Xj yj

X1 , X2 , ….., Xj integers

y1 , y2 , ….., yj binary

課本例題一 ( 產品混合問題 ) (p.11-22)

• Decision Variables

• Objective Function

Z=Total Profits of these decisions

Max Z= 5X1 + 7X2 + 3X3

Product 1

(hour)

Product 2(hour)

Product 3 (hour)

Time Available

(per week)

工廠 1 3 (hour) 4 (hour) 2 (hour) 30 (hours)

工廠 2 4 (hour) 6 (hour) 2 (hour) 40 (hours)

Marginal Profit

5 7 3 (千元 )

Sales Amount

7 5 9 ( 每週件數 )

X1= number of Product 1

produced per week

X2= number of Product 1

produced per week

X3= number of Product 1

produced per week

Constraint Descriptions

1. 生產工時限制

2. 可銷售件數限制

Constraint Models

3X1+4X2+2X3 30

4X1+6X2+2X3 40

X1 X2 5

X3 9

Constraint Description 3. 三種新產品最多可以生產兩 種 ( 利用輔助二元變數)

加入: If Xi>0, then yi=1

If Xi=0, then yi=0 i= 1,2,3

4. 兩工廠中只能選擇一個工廠 生產

(Either-or Constraints )

Constraint Models

X1 y1

X2 y2 X3 y3

y1 + y2 + y3 2

3X1+4X2+2X3 30 + M(1-y4)

4X1+6X2+2X3 40 + M(1-y5)

y4 + y5 = 1

Math ModelMax Z= 5X1+7X2+ 3X3

S.T.

X1

X2 5

X3 9

X1 - y1 X2 - y2 X3 - y3 y1 + y2 + y3 2

3X1 +4X2 +2X3 30 + M(1-y4)

4X1 +6X2 +2X3 40 + M(1-y5)

y4 + y5 = 1

X1 , X2 , X3 , integers

y1 , y2 , y3 , y4 , y5 binary

Two Fallacies of IP

1. Having finite number of feasible solutions ensures that the problem is solvable??

– BIP with n variables →2n solutions to be considered • Exponential Growth of the difficulty of the

problem

– Best algorithms cannot be guaranteed to solve even relatively small problems

Two Fallacies of IP

(2) Removing feasible solutions for LP will make it easier to solve???– All feasible solutions are corner-point feasible

(CPF) solutions that are optimal for the overall problem.

– CPF is the key to the remarkable efficiency of the simplex method

Computational Difficulty for IP

• Number of integer variables• Any special structure in the problem

[Definition] LP relaxation The LP problem obtained by omitting all integers or binary constraints on variables.

Pitfalls for IP• Rounding may cause infeasibility• Rounding solution will not be the optimal solution

Solution Methods for LIP

1. Enumerations (Heuristic Algorithms)– Try all possible computations– Efficient for large problems– Cannot guarantee to find an optimal solution– Meta-heuristic

• e.g. Tabu Search, Simulated Annealing, Genetic Algorithm etc. al.

Solution Methods for LIP

2. Branch & Bound (i) Observation: if the optimal solution of the LP

relaxation of a pure IP are integers, then the optimal solution for the LP relaxation is also optimal solution for the IP.

[Example 1]

Max Z= 3X1+2X2

s.t. 2X1 + X2 6

X1 , X2 ≥ 0, integers

Optimal solution for LP relaxation :

X*1 = 0

X*2 = 6

With Z = 12

Optimal solution for IP problem :

X*1 = 0

X*2 = 6

With Z = 12

Branch & Bound (Divide & Conquer)

[Example 2]

Max Z= 8X1+5X2

s.t. X1 + X2 6

9X1 + 5X2 45

X1 , X2 ≥ 0,

integers

Optimal LP solution for LP relaxation (Sub-problem 1) :

X*1 = 3.75

X*2 = 2.25

With Z = 165/4

Sub-problem 1

t=1

Sub-problem 2:

Sub-problem 1 + X1 ≥ 4

Sub-problem 3:

Sub-problem 1 + X1 ≤ 3

Optimal LP solution for LP relaxation (Sub-problem 2) :

X*1 = 4

X*2 = 9/5

With Z =41

t=2

Sub-problem 4:

Sub-problem 1 + X1 ≥ 4

+ X2 ≥ 2

Sub-problem 5:

Sub-problem 1 + X1 ≥ 4

+ X2 ≤ 1

Optimal LP solution for LP relaxation

(Sub-problem 4 is fathomed w with infeasible solution)

t=3

Optimal LP solution for LP relaxation (Sub-problem 5)

X*1 = 40/9

X*2 = 1

With Z =365/9

t=4

t=4

LIFO rules 作

分枝動作

Sub-problem 6:

Sub-problem 5 + X1 ≥ 5

Sub-problem 7:

Sub-problem 5 + X1 ≤ 4

Optimal LP solution for LP relaxation (Sub-problem 7)

X*1 = 5

X*2 = 0

With Z =40

Fathomed with

LB = 37 → 40

t=6

t =5t =6

Optimal LP solution for LP relaxation (Sub-problem 7)

X*1 = 4

X*2 = 1

With Z =37

Fathomed with

Lower Bound (LB) = 37

t=5

Candidate solution with LB=37

Candidate solution with LB =40

Sub-problem 3:

Sub-problem 1 + X1 ≤ 3Optimal LP solution for LP relaxation (Sub-problem 3)

X*1 = 3

X*2 = 3

With Z =39 < LB =40

Fathomed with Z < LB

t=7

Branch & Bound (Conclusion)

• Step 1:– If it is not necessary to branch on a sub-problem, it is

fathomed

– Fathomed Conditions: (1) Sub-problem is infeasible

(2) Sub-problem yields an optimal solution

(3) the optimal z-value for the sub-problem < current LB

• Step 2: when to eliminate a sub-problem?– The sub-problem is infeasible– The z-value for the sub-problem < current LB

[Example 3] (Knapsack Problem)

Max Z= 16X1+ 22X2 + 12X3+ 8X4

s.t. 5X1 + 7X2 + 4X3 + 3X4 14

X1 , X2 , X 3 , X4 binary

X4=0

Branching on sub-problem 9 could never yield a z-value greater than LB=42

Optimal Solution