

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The steps to find the shortest route between two points in a graph using linear programming. The problem involves setting optimization variables, defining the objective function, and setting constraints to ensure a connected path. Two methods to solve the problem using mathematica: 'minimize' and 'linearprogramming'. The solution includes the shortest route and the total cost.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Start
End
15
13
11
9
16
12
4
17
14
p
P
P
P
P
P
In[1]:= vars = 8 x12, x13, x23, x32, x24, x25, x35, x54, x46, x56<;
In[2]:= f = 15 * x12 + 13 * x13 + 9 * x23 + 9 * x32 +
11 * x24 + 12 * x25 + 16 * x35 + 4 * x54 + 17 * x46 + 14 * x56;
In[3]:= g2 = x12 + x32 ä x24 + x25 + x23;
g3 = x13 + x23 ä x32 + x35;
g4 = x24 + x54 ä x46;
g5 = x35 + x25 ä x54 + x56;
In[7]:= g1 = x12 + x13 ä 1;
In[8]:= g6 = x46 + x56 ä 1;
In[9]:= NonNegativeness = And ûû Thread@vars ≥ 0 D
Out[9]= x12 ≥ 0 && x13 ≥ 0 && x23 ≥ 0 && x32 ≥ 0 && x24 ≥ 0 && x25 ≥ 0 && x35 ≥ 0 && x54 ≥ 0 && x46 ≥ 0 && x56 ≥ 0
4. Solve the problem
In[10]:= Minimize@8f, g1 && g2 && g3 && g4 && g5 && g6 && NonNegativeness<, varsD
Out[10]= 8 41, 8 x12 Æ 1, x13 Æ 0, x23 Æ 0, x32 Æ 0, x24 Æ 0, x25 Æ 1, x35 Æ 0, x54 Æ 0, x46 Æ 0, x56 Æ 1 <<
t
i
1
2
k
In[11]:= c = Normal@CoefficientArrays@f, varsD D @@ 2 DD
Out[11]= 8 15, 13, 9, 9, 11, 12, 16, 4, 17, 14<
2 shortestroute.nb