Processing math: 0%
跳到主要內容

Why Integer Programming Is Important In Real Life

混整數規劃(Mixed Integer Programming) 是線性規劃(Linear Programming),加了整數的決策變數。其化簡標準形式可以寫成
 \begin{array}{l}\text{ min } c_{\mathcal{I}}x_\mathcal{I} + c_{\mathcal{R}}x_\mathcal{R} \\ \text{s.t } Ax = b  \\ x  := (x_\mathcal{I} , x_\mathcal{R}) \geq 0  \\ \end{array}
其中 \mathcal{I} 為整數決策變數集 ,\mathcal{R} 為實數決策變數集,A 為已知係數
此模型已經有很多演算法可以求解詳細可以查關鍵字 branch & cut algorithm
理論上可以找到最佳決策 !! 但實務上整數規劃是 NP-Hard 問題,求解效率是議題!!,所以數學建模上我們希望 |\mathcal{I}| 越小越好!!

而現實問題為何可使用整數規劃來數學建模那麼重要原因有二:
========================================
1. 現實問題物品的數量為整數個 !!
2. 邏輯的 True , False 可以用 0 - 1 決策變數表示!!
========================================
本文介紹一些筆者經驗常見邏輯限制式代表的意義,幫助大家更能理解如何數學建模。而對於有興趣的讀者,可以去閱讀 "Paul Williams : Model Building in Mathematical Programming" 這本書,有詳細的介紹。

+++++++++++++++++++++++++++++++++++
(A) \text{ 從集合裡面挑選元素 }
+++++++++++++++++++++++++++++++++++
Let i \in I , |I| < \infty  , x_i \in \{0,1\} , cost : I \longrightarrow \mathbb{R} , denote cost_i \in \mathbb{R}
x_i = 1  \Longleftrightarrow \text{ you select element in } i  \in I

(A1) 從集合 I 裡面挑選恰好一個元素
\sum_{i \in I} x_i  = 1  
========================================
註 : 學術上我們稱   \displaystyle{\sum_{i\in I} x_i =1 } Special Ordered Sets of type 1 constraint ,記做 SOS1(I) ,或寫作 x(I) = 1
========================================
(A2) 從集合 I 裡面挑選至少一個元素
\sum_{i\in I} x_i \geq 1
(A3) 從集合 I 裡面至多挑選 U 個,至少挑選 L個  (L,U\in \mathbb{Z})
 L \leq \sum_{i\in I} x_i \leq U
(A4) 如果挑選 i \in I 都需要負擔/獲得 c_i \in \mathbb{R}
則總價格可以寫成 cost(I):=  \sum_{i\in I}c_i x_i  
(A5) 當然可以考慮子集合 S \subseteq I ,則價格可以寫成
cost(S):=  \sum_{i\in S}c_i x_i  
(A6) 因為 x_i = 1 代表的是種類 i 有挑選,但如果同種類要計量可以用"整數"決策變數 z_i \in \mathbb{Z^{\geq 0 }}= \{0,1,2,3,4,....\}
qcost(S):= \sum_{i\in S}c_i z_i
當然還可以考慮集合的集合 \mathcal{F}\subseteq 2^{I}= \{S : S\subseteq I \},其中 2^{I} 為 PowerSet of I ,還可以定義 Cost : 2^{I} \longrightarrow \mathbb{R} 類比 (A4) , (A5) 限制式,可以定義
(A7) \quad Cost(\mathcal{F}) := \sum_{S \in \mathcal{F}}cost(S)
(A8) \quad QCost(\mathcal{F}) := \sum_{S \in \mathcal{F}}qcost(S)
如果  z_i \leq U 則我們還可以增加一個維度只用 0-1變數 x_{ij} 來刻劃 z_i  , x_i
(A9)  \left\{\begin{array}{c} \displaystyle{z_i := \sum^{U}_{j=0} j \cdot x_{ij} \quad \forall i \in I} \\   \displaystyle{x_i:= \sum^{U}_{j=0} x_{ij}\leq 1 \quad \forall i \in I }  \\ x_{ij} \in \{0,1\} \quad \forall (i,j) \in I \times \{0,1,2,....U\} \\ \end{array}\right.


+++++++++++++++++++++++++++++++++++
(B) \text{ if - then constraints}
+++++++++++++++++++++++++++++++++++
考慮 i \in I , y_i \in \{0,1\} ,記作 \bar{y}_i = 1-y_i

(B1) 四大基本,可用來串接邏輯 Proposition
if y_1 = 1 then y_2 = 1 :\qquad  y_1 \leq y_2  
if y_1 = 1 then y_2 = 0 :\qquad  y_1 \leq 1-y_2  \Longrightarrow  y_1 \leq  \bar{y}_2 
if y_1 = 0 then y_2 = 1 :\qquad  1-y_1 \leq y_2   \Longrightarrow  \bar{y}_1 \leq y_2
if y_1 = 0 then y_2 = 0 :\qquad 1- y_1 \leq 1- y_2  \Longrightarrow  \bar{y}_1 \leq \bar{y}_2
============================================
例如 : P \Longrightarrow  Q   ,  P\Longrightarrow R , R\Longrightarrow S , Q \Longrightarrow S   可以寫成
\left\{\begin{array}{c}  y_P \leq y_Q   \\    y_P \leq y_R  \\  y_R \leq y_S  \\   y_Q \leq y_S    \\      \end{array}\right.
事實上這可以畫成一個邏輯有向網路圖(Directed Graph) G(N,A) 邊的方向性即為 "\leq",如例子: N=\{P,Q,R,S\} , A = \{ (P,Q), (P,R), (R,S) , (Q,S)\}
=============================================
Let  a, x \in \mathbb{R}^J , b \in \mathbb{R}  ,  [a,x] := \sum_{j \in J} a_{j}x_j
===================================
註 : [a,x]\geq b   可以改寫成  -b \leq -[a,x]
===================================
再來介紹經典的"開啟"限制式 !!

(B2)  if (y = 1)  then [a,x] \leq b  , else  [a,x]  < \infty redundant !!
[a,x] \leq b + M(1-y)
註: M 是充分大常數,學術上稱為 Capital M/Big M Constraint,但不能太大(求解上不穩定),最好的 M := -b + \underset{x \in \mathbb{R}^J}{\text{sup }}[a,x] 

再來是限制式"開啟" !!
(B3)  if ( [a,x] \leq b ) then  y=1  , else :  redundant !!
   b + \epsilon \leq  [a,x] + My 
========================================
證:  等價於 y = 0  \Longrightarrow  [a,x] > b   ,右邊引入極小的數 \epsilon , 變成 [a,x] \geq b + \epsilon,根據(B2)最後可寫成  b + \epsilon \leq  [a,x] + My 
最好的 M:= b + \epsilon - \underset{x \in \mathbb{R}^J}{\text{inf }}[a,x]
========================================
註 : 如果(B2)(B3)條件是 (y = 0) 只要把 y 代換成 \bar{y} 即可 !!
========================================
結合 (B2) (B3)  概念可以有 (B4) , (B5)

(B4)  開關限制式  [a,x] \leq b   \Longleftrightarrow  y =1
\left\{\begin{array}{c} [a,x] \leq b + M(1-y)  \\ b + \epsilon \leq  [a,x] + My  \\ \end{array}\right.

(B5)  限制式開限制式   [a_1,x_1]\leq b_1 \Longrightarrow  [a_2,x_2]\leq b_2
 \left\{\begin{array}{c}   b + \epsilon \leq  [a_1,x_1] + My \\ [a_2,x_2] \leq b + M(1-y) \\  \end{array}\right.
========================================
證:  串聯 [a_1,x_1]\leq b_1 \Longrightarrow y = 1 , y = 1 \Longrightarrow [a_2,x_2]\leq b_2
========================================
+++++++++++++++++++++++++++++++++++
(C) And + Or Constraints !!
+++++++++++++++++++++++++++++++++++
(C1)   if y = 1 then  \underset{i \in I}{\bigwedge} ([a_i,x_i]\leq b_i)  (Right-And Constraints)
\left\{\begin{array}{c}  [a_1,x_1]\leq b_1 + M_1(1-y)  \\  [a_2,x_2]\leq b_2 + M_2(1-y)   \\  [a_3,x_3]\leq b_3  + M_3(1-y)  \\ ...  \\  [a_{|I|},x_{|I|}]\leq b_{|I|} +M_{|I|}(1-y) \\  \end{array}\right.

Let   \forall i \in I \quad  y_i \in \{0,1\}
(C2)   if y = 1 then  \underset{i \in I}{\bigvee}([a_i,x_i]\leq b_i)   (Right-Or Constraints)
\left\{\begin{array}{c}  [a_1,x_1]\leq b_1 + M_1(1-y_1)  \\  [a_2,x_2]\leq b_2 + M_2(1-y_2)   \\  [a_3,x_3]\leq b_3  + M_3(1-y_3)  \\ ...  \\  [a_{|I|},x_{|I|}]\leq b_{|I|} +M_{|I|}(1-y_{|I|}) \\ \displaystyle{y \leq \sum_{i\in I} y_i}  \\   \end{array}\right.
==============================================
註: 學術上稱 (C2) 叫 disjunctive constraints ,可以輕易推廣成
if y = 1 then \displaystyle{\underset{i \in I}{\bigvee}\left\{\underset{j\in J_i}{\bigwedge}([a_j,x_j]\leq b_j)\right\}}
==============================================
(C3)   if (\underset{i \in I}{\bigwedge}([a_i,x_i]\leq b_i) then y = 1  (Left-And Constraints)
\left\{\begin{array}{c}  b_1 + \epsilon_1 \leq [a_1,x_1] + M_1(1-y_1)  \\   b_2 + \epsilon_2 \leq [a_2,x_2] + M_2(1-y_2)  \\  b_3 + \epsilon_3 \leq [a_3,x_3] + M_3(1-y_3)  \\ ...  \\   b_{|I|} + \epsilon_{|I|} \leq [a_{|I|},x_{|I|}] + M_{|I|}(1-y_{|I|}) \\ \displaystyle{ (1-y)  \leq  \sum_{i\in I} y_i} \\   \end{array}\right.
========================================
證:  等價於 if y = 0 then  \underset{i \in I}{\bigvee}([a_i,x_i] > b_i) 
========================================
(C4)   if (\underset{i \in I}{\bigvee}([a_i,x_i]\leq b_i) then y = 1  (Left-Or Constraints)
\left\{\begin{array}{c}  b_1 + \epsilon_1 \leq [a_1,x_1] + M_1 \cdot y  \\   b_2 + \epsilon_2 \leq [a_2,x_2] + M_2 \cdot y  \\  b_3 + \epsilon_3 \leq [a_3,x_3] + M_3 \cdot y  \\ ...  \\   b_{|I|} + \epsilon _{|I|}\leq [a_{|I|},x_{|I|}] + M_{|I|}\cdot y \\   \end{array}\right.
========================================
證:  等價於 if y = 0 then  \underset{i \in I}{\bigwedge}([a_i,x_i] > b_i) 
========================================

(C5)  互斥或,只有 [a_i,x_i] \leq b_i 其中之一會發生  (Disjoint Or Constaints)

\left\{\begin{array}{c}  [a_1,x_1]\leq b_1 + M_1(1-y_1)  \\  [a_2,x_2]\leq b_2 + M_2(1-y_2)   \\  [a_3,x_3]\leq b_3  + M_3(1-y_3)  \\ ...  \\  [a_{|I|},x_{|I|}]\leq b_{|I|} +M_{|I|}(1-y_{|I|}) \\ \displaystyle{\sum_{i\in I} y_i = 1}  \\   \end{array}\right.

+++++++++++++++++++++++++++++++++++
(D) 離散時間狀態網路圖(Time-State-Network)
+++++++++++++++++++++++++++++++++++
考慮離散時間 t \in T := \{0,1,2,........U\}  (單位時刻點集)
考慮離散狀態向量集\displaystyle{i\in(i_1,i_2,i_3,....,i_n) \in I = \prod^{n}_{j=1} I_{j}}  
註: 狀態向量集可能隨著時間 t 不同而不同,即 I^{(t)}
考慮狀態-時間函數 \displaystyle{v :   T \times I \longrightarrow  } \{0,1\}
很明顯我們一個時間點,只會有一個狀態
(D1) \quad  \forall t \in T \quad   \sum_{i\in I} v_{it} = 1  \quad  \text{或寫成 } v_t(I) = 1  

如果我們看 i 的每個分量,很明顯每個分量也只能選一種
因為(D1)的決策變數非常多,事實上如果 State 間是獨立的,只要定義 X^{jt}_{i_j} = 1 \Longleftrightarrow \text{at time }t  , j\text{-th state is } i_j   (只需要 |T| \sum^{n}_{j = 1}|I_j| 個決策變數)
(D2) \quad \forall t\in T \quad  \forall j \in \{1,2,3,...n\} \quad \sum_{i_j \in I_j} X^{jt}_{i_j} =  1

[小結] 在整數規劃裡,邏輯 0-1 是強大數學建模的工具,但邏輯的串聯是困難的部分使用正確的限制式需要時間練習與經驗,而書本鮮少提到,故筆者以此文分享給需要的讀者,更多限制式技巧如 TakeMin , TakeMax , Absolute , Piecewise Linear 可以參考 FICO Xpress 教學文件 ,關於圖論(Graph) 限制式,如 TSPVRPShortest PathMulti-commodity Flow 等等日後會再寫一篇 !!
[以上純為學術經驗交流知識分享,如有錯誤或建議可留言~~] 
by Plus & Minus 2017.09





留言

這個網誌中的熱門文章

Nash Equilibrium & Best Responce Function (BRF) In Continuous Strategies

經濟學重要的賽局理論( Game Theory )領域,用數學描述人與人之間的理性互動,最重要的就是尋找奈許均衡( Nash equilibrium ), 本篇介紹其數學規劃與非線性方程組!!  假設有 p 名玩家(player i),i=1,2,3,4,5,....p , 正在玩一場遊戲(Game)~~,完全不合作,各自獨立作決策 每個人有決策向量 x_i \in \Omega_i \subseteq R^{n_i} (有n_i個決策變數)  定義長向量: \underbrace{x =  (x_1,x_2,x_3,....x_p)}_{\# \text{ of } \sum^{p}_{i=1}n_i \text{ variables }} \in  \prod^{p}_{i=1} \Omega_i = \Omega 對於每個 player i ,長向量可以寫成 x = (x_i , x_{-i})x_{-i} 代表其他人(不是 player i) 能做的決策向量。 所有人各自作決策後,每個人都會個自的存在報酬效用函數 f_i (x)  \in \mathbb{R}  (報酬函數皆為公開已知資訊) 假設每位玩家是理性人(會極大化自己效用) 即 \forall i = 1,2,3,4....p \qquad  \underset{x_i \in \Omega_i}{\text{max }}f_i(x)   [註: 如果為合作可視為多目標規劃問題( multiobjective ),即 x_1,x_2,...x_p 可以由領導人一起決定] [註: 如果為合作而且把效用加總,即目標式變成 \sum_{i=1}^{p} f_i(x) ,可能對集體效益有更大的幫助,但是如何分配效益給 ( player i )會是個議題,可以查關鍵字 fair optimization ] 我們可以定義每個 player i 的 Best Response Function (BRF) or Best Reponce Set S_i(x_{-i}) \subset \Omega_i $$  S_i(x...

Lattice & Multinomial Theorem

本文介紹格子點(Lattice) 幾何意義與多項式定理(Mutinomial Theorem) 的關係,並可協助我們理解計算一些機率問題。 [符號定義] 非負整數 / 非負實數:  \mathbb{Z}_{\geq 0} := \{0,1,2,3,4,......\}  \subseteq [0,\infty) =: \mathbb{R}_{\geq 0} 離散機率向量:  p_{I} := (p_{i})_{i \in I} \text{ s.t } \sum_{i\in I}p_i =1 ,|I|<\infty  發生事件 i \in I 的累積次數向量: k_{I} := (k_i)_{i \in I} \in \mathbb{Z}^{|I|}_{\geq 0} \mathbb{Z}^{|I|}_{\geq 0} 就是 |I| 維格子點 !! [格子點情境] 出發點定義為 k^{start}_{I}:= \overbrace{(0,0...,0)}^{|I|},今發生一次 p_{I} 分布隨機互斥事件,等價於"點的移動"(state transition),數學定義如下:   \text{Event } i  \text{ happens }  \Longleftrightarrow  \overbrace{(\color{red}{k_i},k_{-i})}^{k^{old}_{I}}  \underset{\text{with probability }p_{i}}{\longrightarrow}   \overbrace{(\color{red}{k_i+1},k_{-i})}^{ k^{new}_{I}}    PS1: 其中  k_{-i} := (k_{i'})_{i' \in I-\{i\}} PS2: 不管怎麼走都在第一象限,也就是只能往右,往上,往高.... 當發生 n 次獨立同分布 p_{I} (iid) 的事件後,所有可能點位置在以下的集合上 $$  S_{n}(\col...

Linear Regression By Using Linear Programming

當拿到一筆資料準備玩統計,往往會想要做線性迴歸( Linear Regression ),找出一個模型( mathematical model )來解釋變數間的關係,一般都是使用平方距離,但是如果我們採用絕對值距離呢?? 而剛好在工業工程( Industrial Engineering ),作業研究( Operation Research ) 領域,發展成熟的線性規劃( Linear Programming ) 恰好可以來解決,是一個跨領域的應用 !! 已經存在有許多商業或open source 軟體,如: Gurobi , Cplex , Xpress , Mosek , SCIP  可以輕易求解大型的線性規劃問題。而不僅如此也可以利用整數規劃( Integer Programming )來做特徵選擇 ( Feature Selection ),甚至可以偵測離群值( Detect Outlier ) !! 本文只介紹最小絕對值和,關於 Feature Selection , Detect Outlier 可以參考 Mixed-Integer Linear Programming Robust Regression with Feature Selection , Oleksii Omelchenko , 2010 的論文。 [Data Fitting Problem] 給定n筆實數型訓練資料 (training data) \{(x^{k},y^{k})\}^{n}_{k=1} = \mathcal{D} , x^{k} =(x^{k}_1,x^{k}_2, ... , x^{k}_{p})\in \mathbb{R}^{p} , y^{k} \in \mathbb{R} , 我們目標是想要找到一個函數 f_{\mathcal{D}} : \mathbb{R}^p \rightarrow \mathbb{R} 使得  \forall x \in \mathbb{R}^{p} , f_{\mathcal{D}}(x) \approx y , 精確來說: $$ \text{Find } f_{\mathcal{D}} \text{ such that } f_{\mathcal{D}}(x)\...