Professional Documents
Culture Documents
Simulação e Otimização
Mestrado em Engenharia Informática
Mestrado em Robótica e Sistemas Inteligentes
Amaro de Sousa, Nuno Lau
DETI-UA, 2021/2022
A Network defined by a Graph
𝑁 ={1,2,3,4,5,6,7,8}
|𝑁| = 8
2
Challenges
3
Challenge 1
Each arc (i,j) has an associated length lij. The aim is to minimize the
average shortest path length from each node i N to its closest node
in set S.
Shortest paths and lengths:
Node 1: 15 Length: 12
Node 2: 215 Length: 17
Node 3: 3 Length: 0
Node 4: 43 Length: 16
Node 5: 5 Length: 0
Node 6: 63 Length: 14
One possible solution for n = 2: Node 7: 75 Length: 11
Node 8: 843 Length: 33
|𝑆| = 2
𝑆 ={3,7} 5
Network
challenge
6
Network challenge
Node degree
characterization:
7
Input files and MATLAB supporting codes
Input files:
9
MATLAB supporting codes
Use of provided MATLAB functions:
Nodes= load('Nodes.txt');
Links= load('Links.txt');
L= load('L.txt');
nNodes= size(Nodes,1);
nLinks= size(Links,1);
G=graph(L);
11
First assignment
Analyze the graph and try to identify the best set S of nodes:
• for each of the two challenges
• considering n = 8 nodes
----------------------------------------------------------------------------------------------
Best result:
Result value:
Best result:
Result value:
12
Useful MATLAB information
A= 20; S= 6;
D= randperm(A,S); D is a row vector with a random permutation of 6
values from 1 to 20
t= tic;
while toc(t)<time while cycle runs during time seconds
(...)
end
n= 20;
for i=1:n for cycle runs 20 iterations with i = 1, 2, …, 20
(...)
end
as= [2 4 5 9];
for i=as for cycle runs 4 iterations with i = 2, 4, 5 and 9
(...)
end
14
Alternative method
• First, generate the best solution with a random solution.
• Then, repeat for a given amount of time:
– generate a random neighbor of the best solution
– if the neighbor is better than the best solution, the neighbor
becomes the best solution; otherwise, the best solution remains the
same
• In its simplest form, a neighbor solution is a solution that differs from
the best solution on a single node
16