Processing math: 0%
跳到主要內容

Constraint Programming on Graph Connectedness

本文介紹在一張簡單無向圖 G(V,E^{<})上,點記做 i,j \in V
每個邊 e := \{i,j\} \in E^{<} ,Either 連通=0 or 不連通=1。今給定起訖點 o,d  \in V , o \neq d ,od-pair 記做  <o,d> ,由於可能有很多替代的路徑可以從 o 走到 d
如何描述(表達集合) <o,d> 為連通/不連通時"邊集"的情況 ??
======================================================
預備知識:
\displaystyle{ \bigwedge_{s \in S}} Equation(s)  
是邏輯大 And 或可嚴謹讀作  \forall s \in S , Equation(s) \text{ is true}   

\displaystyle{\bigvee_{s \in S} } Equation(s)  
是邏輯的大 Or   或可讀作  \exists s \in S , Equation(s) \text{ is true }
======================================================
符號定義:
1. \mathcal{P}_{<o,d>}  為起點為 o,終點為 d 所有"路徑名稱(下標 index)"的集合   
2.   E^{<}_{p}   \subseteq E^{<} 路徑 p \in \mathcal{P}_{<o,d>} 經過的無向邊集
3. 起訖點<o,d>可能會經過的所有無向邊的集合(路徑是由"邊"組成的) \displaystyle{E^{<}_{<o,d>} :=  \bigcup_{p \in \mathcal{P}_{<o,d>}} E^{<}_{p}  } \subseteq E^{<} 
4. 令向量 y \in \{0,1\}^{E^{<}_{<o,d>}} 為連通性可能情況,其中 y \equiv (y_{e})_{e\in E^{<}_{<o,d>}} \quad ,   \bigwedge_{e\in E^{<}_{<o,d>}} \bigg( y_{e} = 1 \Longleftrightarrow  e \text{ 不連通} \bigg)
5. 兩點下標表示法:  y_{e} \equiv y_{ij} 

==================================================
實作小技巧:

\mathcal{P}_{<o,d>} , E^{<}_{p} 可由 DFS 窮舉路徑演算法獲得,詳細可看~
https://www.geeksforgeeks.org/find-paths-given-source-destination/

但實作上演算法可能為"有向邊"思維,儲存時須特別注意!!
例如某路徑 p,經過的順序為 5 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 4
由於 2 \rightarrow 3  , 3 \rightarrow  2 事實上是經過同一個邊  e = \underbrace{\{2,3\} = \{3,2\}}_{  \{ \cdot , \cdot \}  \text{ 表示無向邊化}} = (2,3)

所以紀錄 E^{<}_{p} 時應該為 \{ (2,5),(2,3),(2,4)   \}   註: 給定排序 i<j 記法 ,可以定義 y_{25} , y_{23} , y_{24}  二元布林值 !!!

而非單純 bi-gram  \{ (5,2),(2,3),(3,2),(2,4)   \}
=================================================
<o,d> 不連通邊集 :

Y^{disconnected}_{<o,d>}:= \bigg\{  y \in \{0,1\}^{|E^{<}_{<o,d>}|}  :  \bigwedge_{p \in \mathcal{P}_{<o,d>}}\left(\sum_{e \in E^{<}_{p}} y_{e} \geq 1 \right)  \bigg\}


邏輯意義: 對於每條可以走的路徑 p \in \mathcal{P}_{<o,d>} ,都存在至少一個無向邊 e \in E^{<}_{p} 是不連通的 y_{e} = 1,即沒有任何一條路可以通,代表 <o,d> 不連通!!
=================================================
關於連通邊集,就是下面的集合 !!

Y^{connected}_{<o,d>}:=   \bigg\{  y \in \{0,1\}^{|E^{<}_{<o,d>}|}  : \bigvee_{p \in \mathcal{P}_{<o,d>}}\left(\sum_{e \in E^{<}_{p}} y_{e} = 0 \right)  \bigg\} 

==================================================
定義 y_{p}:
但我們希望把連通集轉換成 Big-And 形式 !!
 需要先另外新定義向量 (y_p)_{p \in \mathcal{P}_{<o,d>}} \in \{0,1\}^{|\mathcal{P}_{<o,d>}|},表示路徑 p 是否連通的布林值!! 註: y_e , y_p 是不同的定義
而且以下三個邏輯也成立:

[1]
\bigwedge_{p \in \mathcal{P}_{<o,d>}}\bigwedge_{e \in E^{<}_{p}} \bigg(y_e = 1  \Longrightarrow y_p = 1  \bigg)
邏輯白話解釋: 如果邊 e 不連通,則整條含e的路徑p就不連通


[2]
\bigwedge_{p \in \mathcal{P}_{<o,d>}}\left[y_p = 1 \not\Longrightarrow \left( \bigwedge_{e \in E^{<}_{p}}  (y_e = 1) \right) \right] 
邏輯白話解釋 : 如果路徑 p 不連通,不代表 所有在路徑上的邊 e 都不連通


[3]
\bigwedge_{p \in \mathcal{P}_{<o,d>}}\left[y_p = 1 \Longrightarrow \left( \bigvee_{e \in E^{<}_{p}}  (y_e = 1) \right) \right] 
邏輯白話解釋:  如果路徑 p 不連通,代表 存在路徑上的邊 e 不連通

可以使用之前整數規劃的技巧文章詳細如下:
http://discoverforgottenmath.blogspot.com/2017/09/why-integer-programming-is-important-in.html


[1] 可寫成:
\bigwedge_{p \in \mathcal{P}_{<o,d>}}\bigwedge_{e \in E^{<}_{p}} \left( y_e  \leq y_p \right)

[3] 可寫成:
\bigwedge_{p \in \mathcal{P}_{<o,d>}}\left( y_{p} \leq \sum_{e\in E^{<}_{p}}y_{e}  \right)

由於我們已經有 y_{e} , y_{p} 的邏輯關係,<o,d>連通性可以直接用 \exists  p \in \mathcal{P}_{<o,d>} , y_{p} = 0 表示,也就是以下 [4]
   \sum_{p\in \mathcal{P}_{<o,d>}}  y_{p} \leq  \underbrace{\left(|\mathcal{P}_{<o,d>}| - 1\right)}_{\text{不讓 $y_{p}$ 全部塞 $1$}}


重新把 y 向量定義成兩個向量 (y_{p})_{p \in \mathcal{P}_{<o,d>}},(y_{e})_{e\in E^{<}_{<o,d>}}的 concatenate,則我們有連通邊集的 Big-And 形式 (但需要增加 y 的維度 !! )
Y^{connected}_{<o,d>} \equiv \left\{  y \in \{0,1\}^{|E^{<}_{<o,d>}|+|\mathcal{P}_{<o,d>}|}  :  [4] \wedge \bigwedge_{p \in \mathcal{P}_{<o,d>}}\left\{ \begin{array}{cc}  \bigwedge_{e \in E^{<}_{p}} \left( y_e  \leq y_p \right) & [1]   \\ y_{p} \leq \sum_{e\in E^{<}_{p}}y_{e} &[3]   \\    \end{array} \right. \quad   \right\}

==================================================
[演算法相關]
關於為何我們需要 Big-And 邏輯形式是因為可以寫成"線性矩陣系統" :D

  \bigwedge_{r \in \text{rows}} \left( \sum_{c \in \text{columns} } a_{rc}y_c \leq  b_r \right)    \Longleftrightarrow \text{Create Set} Y:= \bigg\{y \in \{0,1\}^{|columns|} : Ay \leq b \bigg\} 

而線性矩陣系統如  Y 可以使用 Constraint Programming (CP) 高效率演算法窮舉出其每個元素 :) 其演算法 Google 有開源有興趣可以詳見:
https://developers.google.com/optimization/

而如果要更高速計算 |Y| 可以使用高深理論的 Barvinok algorithm :D,但因為筆者功力目前不夠深厚無法詳細解釋,但有連結:  http://www.maths.ed.ac.uk/~v1ranick/papers/barvpomm.pdf

[小結]
本文利用邏輯觀念與限制式,建構出"連通方程式/集合",連通的概念是重要的,跟系統可靠度(reliability)息息相關 !!


[以上純為學術經驗交流知識分享,如有錯誤或建議可留言~~] 
by Plus & Minus 2018.06

留言

這個網誌中的熱門文章

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)\...