The stochastic distribution 02--of graph theory based on logit Stoch distribution method-an improved dial algorithm

Source: Internet
Author: User

function Dialsuanfaxishujuzhen (T)
% Program Description
Clc
Disp (' ====================================================================================== ');
Disp (' Logit-based Stoch distribution Method-improved dial algorithm ');
DISP (' Operating environment: MATLAB 8.3.0.532 ');
Disp (' Producer: Lanzhou Jiaotong University Liu Zhixiang ');
Disp (' Q q:531548824 ');
fprintf (' Description: This program is used for static distribution, on the basis of the classical dial algorithm to modify, to redefine the effective path, so that in the tolerance of \ n the bypass range of more than the original H-fold road (under normal circumstances 0Disp (' ====================================================================================== ');
Disp (' Press any key to continue ... ');
Pause

% data acquisition, man-machine interaction
DISP (' * * * * Please follow the prompts to enter the following parameters * * *);
Q=input (' total demand: ');
Thita=input (' parameter thita: ');
H=input (' Tolerance Detour Multiple: ');
R=input (' starting point: ');
S=input (' End point: ');
N=size (t,1);

% initialization
L=zeros (N,n);
W=zeros (N,n);
X=zeros (N,n);

To find the shortest distance matrix and shortest path
Disp (' Step1->: Seeking the shortest distance, where ');
Disp ('---------------------------------------------------------------------------------------');
Disp (' R-start R to the shortest distance from other points ');
Disp (the shortest distance ' s from other points to the end point ');
Disp (' Press any key to continue ... ');
Pause
For I=1:n
For J=1:n
If T (i,j) ==inf
T (I,J) = 0;
End
End
End
T=sparse (T);
Tmin=graphallshortestpaths (T);
[Dist,path]=graphshortestpath (T,r,s);
Disp (' ________________________________________________________________ ');
R=tmin (R,:)
S=tmin (:, s) '% note because of directionality, here for transpose processing
Disp (' ________________________________________________________________ ');


% draw initial diagram and shortest path, edge right is impedance value T
Disp (' initial graph and shortest path (red): ');
Chushitu=view (Biograph (t,[], ' showw ', ' on '));
Set (Chushitu. Nodes (path), ' Color ', [1 0 0]);
Edges=getedgesbynodeid (Chushitu,get (Chushitu. Nodes (path), ' ID ');
Set (edges, ' linecolor ', [1 0 0]);
Disp (' Shortest path: ');
Path
Disp (' Shortest distance: ');
Dist

% upstream and downstream nodes are found (obviously both up and down are transpose-symmetric, because if J is the downstream node of I, then I must be the upstream node of J)
For I=1:n
For J=1:n
If T (i,j) >0
Down (i,j) = 1;
Up (j,i) = 1;
Else
Down (i,j) = 0;
Up (J,i) = 0;
End
End
End
Down=sparse (down);
Up=sparse (UP);

% Compute edge Rights
Disp (' Step2->: Calculate edge-weighted likelihood value (any key continuation) ');
Disp ('---------------------------------------------------------------------------------------');
Pause
For I=1:n
For J=1:n
If Down (i,j)
If R (i) +t (i,j)-R (J) < (1+H) *t (I,j) &&s (j) +t (I,j)-S (i) < (1+h) *t (I,J)
P=1;
Else
P=0;
End
L (i,j) =p*exp (thita* (R (j)-R (i)-t (i,j));
End
End
End
L=sparse (L)
Disp (' Side right: ');
Bianquantu=view (Biograph (l,[], ' showw ', ' on '));

% Calculation of road rights
Disp (' Step3->: Calculation of road rights (any key continuation) ');
Disp ('---------------------------------------------------------------------------------------');
Pause
For I=1:n
For J=1:n
If Down (i,j) ~=0
If R (i) +t (i,j)-R (J) < (1+H) *t (I,j) &&s (j) +t (I,j)-S (i) < (1+h) *t (I,J)
If I==r
W (i,j) =l (I,J);
Else
W (i,j) =l (i,j) * (Up (i,:) *w (:, i));
% this is the core sentence, first find the upstream node, and then write out the upstream node to the W value of I (if not yet, then recursion until it can be calculated), please carefully consult the algorithm of the road right to understand well.
End
End
End
End
End
W=sparse (W)
Disp (' Road right: ');
Luquantu=view (Biograph (w,[], ' showw ', ' on '));

% Distribution Flow
Disp (' Step4->: distribution (any key continuation) ');
Disp ('------------------------------------------------------------------------------------------');
Pause
For I=n:-1:1
For J=n:-1:1
If Down (i,j) ==1
If R (i) +t (i,j)-R (J) < (1+H) *t (I,j) &&s (j) +t (I,j)-S (i) < (1+h) *t (I,J)
If J==s
X (i,j) =q*w (i,j)/(Up (J,:) *w (:, j)));
Else
X (I,j) =x (J,:) *down (J,:) ' *w (i,j)/(Up (J,:) *w (:, j));
% Note X (j,:) is a 1*n line vector, down (j,:) is 1*n line vector, so the down vector is to be converted to 1*n column vectors to multiply.
End
End
End
End
End
X=sparse (X)
Disp (' Matching flow result: ');
Peiliutu=view (Biograph (x,[], ' showw ', ' on '));
Disp (' ====================================================================================== ');

Disp (' < program run complete > ');


Example: A road network, impedance has been marked on the edge (the impedance is represented by distance value), the demand is 1000, the starting point is V1, the end point is v9,θ=1, the user can tolerate a detour of 0.5. Please use an improved ial algorithm for the distribution of the flow.


Solution: (1) Write Weights matrix

quanzhijuzhen=[
0 2 INF 2 inf inf INF
INF 0 2 INF 2 inf inf INF
INF INF 0 INF INF 2 inf INF
INF INF 0 1 INF 2 inf INF
INF inf INF 0 1 INF 2 inf
INF INF INF INF 0 inf INF 2
INF inf inf INF 0 2 INF
INF inf inf inf INF 0 2
INF inf inf INF 0];

(2) Bring in the program (after the format of the output as follows)

>> Dialsuanfaxishujuzhen (Quanzhijuzhen)

======================================================================================
Stoch distribution method based on Logit--Improved dial algorithm
Operating Environment: MATLAB 8.3.0.532
Producer: Lanzhou Jiaotong University Liu Zhixiang
Q q:531548824
Description: This program is used for static distribution, modified on the basis of the classical dial algorithm, redefining the effective path, making the
The user's tolerance bypass range is more than the original H-Times road (generally 0H=0 is equivalent to the classical algorithm. The dial algorithm is divided into four steps: one is to find the shortest way, the other is to seek the right of Edge, the third is to seek the right to the road, and four is the distribution
======================================================================================
Press any key to continue ...
Please follow the prompts to enter the following parameters * * *
Total demand: 1000
Parameter thita:1
Tolerance Detour Multiple: 0.5
Starting point: 1
End point: 9
Step1->: To find the shortest distance, where
---------------------------------------------------------------------------------------
The shortest distance from R-start to other points
The shortest distance from the s other point to the end point
Press any key to continue ...
________________________________________________________________
R =
0 2 4 2 3 4 4 5 6
S =
6 5 4 4 3 2 4 2 0
________________________________________________________________
Initial diagram and Shortest path (red):


Shortest path:
Path =
1 4 5) 6 9
Shortest distance:
Dist =
6
Step2-&gt: Calculating edge-weighted likelihood value (any key continuation)
---------------------------------------------------------------------------------------
L =
(1.0000)
(2,3) 1.0000
(1,4) 1.0000
(2,5) 0.3679
(4,5) 1.0000
(3,6) 0.1353
(5,6) 1.0000
(4,7) 1.0000
(5,8) 1.0000
(7,8) 0.3679
(6,9) 1.0000
(8,9) 0.3679
Benquan:


step3->: Calculating the road right (any key continuation)
---------------------------------------------------------------------------------------
W =
(1.0000)
(2,3) 1.0000
(1,4) 1.0000
(2,5) 0.3679
(4,5) 1.0000
(3,6) 0.1353
(5,6) 1.3679
(4,7) 1.0000
(5,8) 1.3679
(7,8) 0.3679
(6,9) 1.5032
(8,9) 0.6386
right of way:


Step4->: Distribution (any key continuation)
------------------------------------------------------------------------------------------
X =
(298.1420)
(2,3) 63.1887
(1,4) 701.8580
(2,5) 234.9533
(4,5) 638.6693
(3,6) 63.1887
(5,6) 638.6693
(4,7) 63.1887
(5,8) 234.9533
(7,8) 63.1887
(6,9) 701.8580
(8,9) 298.1420
Distribution Results:


======================================================================================

< program run Complete >

Description: Obviously the improved algorithm is more realistic, because people usually don't wait long time because they need to go around a little bit.

Copyright Notice: Bo Main article can be reproduced non-commercial, but please be sure to indicate the source, because the level is limited, inevitably error, in this disclaimer.

The stochastic distribution 02--of graph theory based on logit Stoch distribution method-an improved dial algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.