You are on page 1of 16

Introduction to Optimization:

Selection of Optimal Nodes in a Network

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

Consider a network defined by a graph G=(N,A).


• Nodes of set N are identified as i = 1, 2, …, |N|
• Arcs of set A are identified as (i,j)

𝑁 ={1,2,3,4,5,6,7,8}
|𝑁| = 8

𝐴 ={(1,2), (2,1), (1,5), (5,1),


(2,3), (3,2), (3,4), (4,3),
(3,5), (5,3), (3,6), (6,3),
(4,6), (6,4), (4,8), (8,4),
(5,7), (7,5), (6,7), (7,6),
(6,8), (8,6)}
Arc lengths lij |𝐴| = 22

2
Challenges

Consider a network defined by a graph G=(N,A).


• Nodes of set N are identified as i = 1, 2, …, |N|
• Arcs of set A are identified as (i,j)

On both challenges, for a given number n, we need to select a set S of


|S| = n nodes optimizing a given objective.
• Each combination of n out of |N| defines one possible solution
𝑁!
• There are 𝑛!× solutions
𝑁 −𝑛 !

If |N| = 100 nodes, the number of solutions is:


• 1.861011, for n = 8
• 1.731013, for n = 10

Two challenges are described in the next 2 slides.

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: 15 Length: 12
Node 2: 215 Length: 17
Node 3: 3 Length: 0
Node 4: 43 Length: 16
Node 5: 5 Length: 0
Node 6: 63 Length: 14
One possible solution for n = 2: Node 7: 75 Length: 11
Node 8: 843 Length: 33

Average shortest path length of S = {3,5}:


(12+17+0+16+0+14+11+33)/8 = 12.875
|𝑆| = 2
𝑆 ={3,5} 4
Challenge 2

The aim is to minimize the number of pairs of nodes that can


communicate when the nodes in set S are eliminated.

Link lengths are irrelevant

Connected node pairs:


{1,2},{1,5}{2,5},{4,6},{4,8},{6,8}

One possible solution for n = 2: Number of connected


nodes pairs of S = {3,7} is 6

|𝑆| = 2
𝑆 ={3,7} 5
Network
challenge

6
Network challenge

Topology characteristics: - 100 nodes


- 115 links (230 arcs)

Link length characterization:

Node degree – number of links connected to the node

Node degree
characterization:

7
Input files and MATLAB supporting codes

Input files:

Nodes.txt – a matrix of 100 rows and 2 columns with the (x,y)


coordinates of each node
Links.txt – a matrix of 115 rows and 2 columns with the node pairs
of each link
L.txt – a square matrix of 100x100 with the link length lij value
for existing links (i,j) or 0 otherwise

Loading files, computing no. of nodes and links, creating graph:

Nodes= load('Nodes.txt');  Creates Nodes with data from Nodes.txt


Links= load('Links.txt');  Creates Links with data from Links.txt
L= load('L.txt');  Creates L with data from L.txt
nNodes= size(Nodes,1);  Creates nNodes as the no. of rows of Nodes
nLinks= size(Links,1);  Creates nLinks as the no. of rows of Links
G= graph(L);  Creates G as a graph based on matrix L 8
MATLAB supporting codes

Provided MATLAB functions:

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);

% Plot the network:


figure(1)
plotTopology(Nodes,Links,[]);

% Plot the network with MATLAB plot function:


figure(2)
plot(G)

% Plot the network with server nodes:


figure(3)
servers= [11 27 66 87];
10
plotTopology(Nodes,Links,servers);
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);

servers= [11 27 66 87];

% Computing the average shortest path length from each


% node to its closest server node:
AvSP= AverageSP(G,servers)

% Computing the number of connected nodes pairs when


% server nodes are eliminated:
ConNP= ConnectedNP(G,servers)

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
----------------------------------------------------------------------------------------------

Challenge 1 (minimizing the shortest path length):

Best result:
Result value:

Challenge 2 (minimizing the number of connected node pairs):

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

function [s p] = stat(a,b)  syntax of a function


s = a+b;
p = [a b]; 13
end
Second assignment
• Develop a function for each challenge that generates multiple
random solutions for a given amount of time and outputs the best
one.
• The function must be in the form:
function [result result_nodes] = xxx(G,n,time)
% Input: G - graph of the network
% n - number of nodes of set S
% time - number of seconds to run the method

• Develop a script to run your function for n = 8 and n = 10 nodes and


for time = 5 and time = 30 seconds. Register your results.
• Compare the results for n = 8 nodes with the ones of the first
assignment.

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

A random neighbor solution can be computed as:


N = numnodes(G); % no. of nodes of graph G
n = 8; % no. of nodes of set S
best= [27 4 13 2 59 56 89 5]; % current best set S
% Compute the nodes that are not in best:
others= setdiff(1:N,best);
% Compute the neighbor with n-1 random nodes in best plus
% one random node that is not in best:
neighbor= [best(randperm(n,n-1)) others(randperm(N-n,1))]; 15
Third assignment
• Develop a function for each challenge that generates multiple
random solutions with the alternative method and for a given
amount of time, and outputs the best one.
• The function must be in the same form as in the previous second
assignment.
• Develop a script to run your function for n = 8 and n = 10 nodes and
for time = 5 and time = 30 seconds. Register your results.
• Compare the results with the ones of the second assignment.

16

You might also like