交通調(diào)度-網(wǎng)絡(luò)流最大流問(wèn)題
行業(yè)背景
交通調(diào)度是指對(duì)交通資源進(jìn)行合理的調(diào)度和管理,以實(shí)現(xiàn)交通系統(tǒng)的高效運(yùn)行和流量控制。如何安排調(diào)度,以幫助提高交通運(yùn)輸?shù)男剩档统杀尽?/span>這個(gè)優(yōu)化問(wèn)題也可以運(yùn)用數(shù)學(xué)規(guī)劃的方法來(lái)建模和求解。
例如:已知有七個(gè)站點(diǎn),每個(gè)站點(diǎn)都有若干條進(jìn)站道路與出站道路,道路旁的數(shù)字表示單位時(shí)間內(nèi)此路所能承載的最大車輛數(shù),如何分配車輛使得單位時(shí)間從a站點(diǎn)出發(fā),最后到達(dá)g站點(diǎn)的車輛最多?
業(yè)務(wù)調(diào)研、數(shù)據(jù)量化、數(shù)學(xué)建模
在使用優(yōu)化技術(shù)的時(shí)候,需要更詳細(xì)的調(diào)研業(yè)務(wù)的需求,整理相關(guān)的業(yè)務(wù)邏輯和數(shù)據(jù),并量化表示它。然后采用數(shù)學(xué)規(guī)劃的方法進(jìn)行數(shù)學(xué)建模。
此部分細(xì)節(jié)較多,可在案例交通調(diào)度中查閱細(xì)節(jié),此處我們僅列出數(shù)學(xué)公式如下,參數(shù)部分請(qǐng)點(diǎn)擊案例鏈接查看:
其中i代表每段通道的起點(diǎn),j代表通道的抵達(dá)點(diǎn),e代表車輛的初始點(diǎn),k代表每個(gè)中間的站點(diǎn),r代表可以通過(guò)的車輛數(shù)
以上公式對(duì)應(yīng)的約束有:
進(jìn)入中間站點(diǎn)的車輛數(shù)等于該站點(diǎn)出去的車輛數(shù)
每條通道通過(guò)的車輛數(shù)有限制
源代碼
MindOpt支持多種編程語(yǔ)言或者建模語(yǔ)言來(lái)調(diào)用。此處僅列出一種供參考:
MindOpt APL建模語(yǔ)言調(diào)用
MindOpt APL建模語(yǔ)言的源代碼(可在交通調(diào)度上試運(yùn)行):
##====MindOpt APL 建模語(yǔ)言版本代碼====
clear model;
# 建模
# net1.mapl
set Station :={"a","b","c","d","e","f","g"};
set Middle := {"b","c","d","e","f"};
set Roads :={<"a","b">,<"b","d">,<"c","d">,<"d","e">,<"e","g">,<"a","c">,<"b","e">,<"c","f">,<"d","f">,<"f","g">};
param entr := "a";
param lb := 0;
param ub[Roads] := <"a","b"> 50, <"b","d"> 40, <"c","d"> 60, <"d","e"> 50, <"e","g"> 70, <"a","c"> 100, <"b","e"> 20, <"c","f"> 20, <"d","f"> 60, <"f","g"> 70;
var x[<i,j> in Roads] >= lb <= ub[i,j];
maximize Total : sum {<entr,j> in Roads } x[entr,j]; #起點(diǎn)進(jìn)入的最大流量
#流量均衡
subto Balance:
forall <k> in Middle do
sum {<i,k> in Roads} x[i,k] == sum {<k,j> in Roads } x[k,j];
print "-----------------用MindOpt求解---------------";
option solver mindopt; # (可選)指定求解用的求解器,默認(rèn)是MindOpt
#option mindopt_options 'print=0'; #設(shè)置求解器輸出級(jí)別,減少過(guò)程打印
solve; # 求解
print "-----------------結(jié)果---------------";
display; # 展示結(jié)果
print "經(jīng)過(guò)優(yōu)化后,最大流量=" ,sum {<entr,j> in Roads } x[entr,j];
結(jié)果和結(jié)果用法
不同代碼日志打印不一樣。部分結(jié)果日志打印如下所示:
...
Model summary.
- Num. variables : 10
- Num. constraints : 5
- Num. nonzeros : 16
- Bound range : [2.0e+01,1.0e+02]
- Objective range : [1.0e+00,1.0e+00]
- Matrix range : [1.0e+00,1.0e+00]
...
Simplex method terminated. Time : 0.002s
OPTIMAL; objective 130.00
...
-----------------結(jié)果---------------
經(jīng)過(guò)優(yōu)化后,最大流量=130
目標(biāo)的最優(yōu)解是:130。更多解的細(xì)節(jié),如決策變量的取值、驗(yàn)證約束是否正確,可以通過(guò)print命令打印來(lái)顯示,變量的取值也可以從程序運(yùn)行寫的.sol文件里面獲取,還可以調(diào)用display
獲取所有變量的。
如運(yùn)行如下指令,驗(yàn)證“進(jìn)入中間站點(diǎn)的車輛數(shù)等于該站點(diǎn)出去的車輛數(shù)”這個(gè)約束:
forall <k> in Middle do
print '進(jìn)入{}站點(diǎn)的車輛數(shù):{}'%k, sum {<i,k> in Roads} x[i,k];
print "-------------";
forall <k> in Middle do
print '離開(kāi){}站點(diǎn)的車輛數(shù):{}'%k, sum {<k,j> in Roads} x[k,j];
輸出結(jié)果是對(duì)等的:
進(jìn)入b站點(diǎn)的車輛數(shù):50
進(jìn)入c站點(diǎn)的車輛數(shù):80
進(jìn)入d站點(diǎn)的車輛數(shù):90
進(jìn)入e站點(diǎn)的車輛數(shù):70
進(jìn)入f站點(diǎn)的車輛數(shù):60
-------------
離開(kāi)b站點(diǎn)的車輛數(shù):50
離開(kāi)c站點(diǎn)的車輛數(shù):80
離開(kāi)d站點(diǎn)的車輛數(shù):90
離開(kāi)e站點(diǎn)的車輛數(shù):70
離開(kāi)f站點(diǎn)的車輛數(shù):60
運(yùn)行如下代碼,將輸出打印為csv格式,作為交通調(diào)度問(wèn)題的解決方案:
print "{},{},{} "% "起點(diǎn)","途徑點(diǎn)","車輛數(shù)" : "Results.csv";
close "Results.csv";
forall {<i,j> in Roads}
print "{},{},{}" % i,j,x[i,j] >> "Results.csv";
close "Results.csv";
輸出結(jié)果如下:
即,從a站最多可出發(fā)130輛車。并且分流的流量為,如下圖
a到b是50,到c是80;
b到d是30,到e是20
c到d是60,到f是20
d匯總了90的流量,分流到e是50,到f是40
e匯總了70的流量
f匯總了60的流量 -它們都匯總到出口g,總共是130