Assignment3_AkshayBhat
Assignment3_AkshayBhat
TELECOMMUNICATION NETWORKS
CS 6385.0W1
PROJECT #3
NETWORK TOPOLOGY
DESIGN
Submitted by
Akshay Bhat
ID: 2021319198
Netid: axb163530
1
CONTENTS
OBJECTIVE.............................................................................................................................. 3
NETWORK TOPOLOGY......................................................................................................... 3
ALGORITHMS…………………………………..………………………………4
RESULTS .................................................................................................................................. 6
APPENDIX ................................................................................................................................ 23
README .................................................................................................................................... 38
2
OBJECTIVE
The aim of the project is to create a network topology (represented by an undirected graph),
such that it has the following properties:
The goal is to create and implement two different heuristic algorithms for this
network topology design problem, and experiment with them
NETWORK TOPOLOGY:
Graphs have some properties that are very useful when unravelling the information that they
contain. It is important to realise that the purpose of any type of network analysis is to work
with the complexity of the network to extract meaningful information that you would not
have if the individual components were examined separately.
Network properties, and particularly topological properties, can help us identify relevant sub-
structures within a network.
Topology is the way in which the nodes and edges are arranged within a network.
Topological properties can apply to the network as a whole or to individual nodes and edges.
Network topology is the arrangement of the elements of a communication network.
Network topology is the topological structure of a network and may be depicted physically or
logically. It is an application of graph theory wherein communicating devices are modeled as
nodes and the connections between the devices are modeled as links or lines between the
nodes. Distances between nodes, physical interconnections, transmission rates, or signal
types may differ between two different networks, yet their topologies may be identical.
Network topology can be used to define or describe the arrangement of various types of
telecommunication networks, including command and control radio networks, industrial
fieldbusses, and computer networks.
3
ALGORITHMS:
Local search is a heuristic method for solving computationally hard optimization problems.
Local search can be used on problems that can be formulated as finding a solution
maximizing a criterion among a number of candidate solutions. Local search algorithms
move from solution to solution in the space of candidate solutions (the search space) by
applying local changes, until a solution deemed optimal is found or a time bound is elapsed.
Local search is based on the oldest optimization method: trial and error. To systematize the
search a neighborhood structure is defined and build. The neighborhood of a given solution is
the set of feasible solutions that, somehow, are alike the given solution, i.e. com similar
elements and objective function values not very different.
A constructive heuristic is a type of heuristic method which starts with an empty solution and
repeatedly extends the current solution until a complete solution is obtained. It differs from
local search heuristics which start with a complete solution and then try to improve the
current solution further via local moves.
It is essential to know the difference between:
a. Constructive methods
Extend empty solution until get complete solution
b. Local search
4
Take complete solution and try to improve it via local moves
Pseudo-code
A constructive algorithm (for minimization) can be described as follows:
Algorithm Greedy(I)
x := ∅;
x∗:= ∅;
f∗:= +∞; { Best incumbent solution }
While Ext(x) 6= ∅ do
i := arg min
i∈Ext(x)
φ (i, x);
x := x ∪ {i};
If x ∈ X and f (x) < f∗
then x∗:= x;
f∗:= f (x);
Return (x∗, f∗);
A constructive heuristic finds the optimum when the current subset x(t) at every iteration t is
contained in an optimal solution. This property is valid for x(0) = ∅, but is usually lost in
some later iteration t.
A constructive heuristic executes at most n = |E| iterations.
The complexity of each step is affected by
1. the computation of Ext(x);
2. the evaluation of φ (i, x) for each i ∈ Ext(x);
3. the selection of the minimum value and the corresponding element;
4. the update of x (and possibly other data-structures).
Constructive heuristics
1. are intuitive;
2. are rather simple to design, analyze and implement;
3. are very efficient
4. can be very different in effectiveness according to the different problems.
• optimality is guaranteed
• approximation is guaranteed
• feasible solution is guaranteed, but unreliable quality (most cases);
• no feasible solution is guaranteed.
5
RESULTS
a) Experiment-1
The adjacency matrix denoting the node and the edges are:
6
The network topology graph is:
The result:
7
b. Experiment-2
8
Adjacency matrix is:
Graph is:
9
The result:
c. Experiment-3
Points are:
Point number 0 is: (6,77)
Point number 1 is: (89,83)
Point number 2 is: (50,56)
Point number 3 is: (58,63)
Point number 4 is: (36,35)
Point number 5 is: (12,80)
Point number 6 is: (87,30)
Point number 7 is: (18,58)
10
Point number 8 is: (83,50)
Point number 9 is: (26,98)
Point number 10 is: (91,53)
Point number 11 is: (75,98)
Point number 12 is: (71,55)
Point number 13 is: (74,2)
Point number 14 is: (36,43)
Point number 15 is: (13,55)
Point number 16 is: (58,82)
Point number 17 is: (5,12)
Point number 18 is: (32,56)
Graph is:
11
The result:
12
d. Experiment-4
Points are:
Point number 0 is: (22,56)
Point number 1 is: (89,6)
Point number 2 is: (45,97)
Point number 3 is: (96,92)
Point number 4 is: (8,11)
Point number 5 is: (23,36)
Point number 6 is: (71,24)
Point number 7 is: (95,66)
Point number 8 is: (60,12)
Point number 9 is: (97,37)
Point number 10 is: (7,64)
Point number 11 is: (19,36)
Point number 12 is: (18,19)
Point number 13 is: (41,93)
Point number 14 is: (8,65)
Point number 15 is: (9,11)
Point number 16 is: (18,61)
Point number 17 is: (52,61)
Point number 18 is: (4,38)
13
Adjacency matrix is:
Graph is:
14
The result:
15
e. Experiment-5
Points are:
Point number 0 is: (66,10)
Point number 1 is: (84,99)
Point number 2 is: (79,60)
Point number 3 is: (5,33)
Point number 4 is: (7,13)
Point number 5 is: (6,59)
Point number 6 is: (92,0)
Point number 7 is: (6,86)
Point number 8 is: (45,42)
Point number 9 is: (28,3)
Point number 10 is: (36,59)
Point number 11 is: (32,66)
Point number 12 is: (17,63)
Point number 13 is: (25,12)
Point number 14 is: (79,34)
Point number 15 is: (7,68)
Point number 16 is: (77,89)
Point number 17 is: (47,1)
Point number 18 is: (21,52)
16
Adjacency matrix is:
Graph is:
17
The result:
18
f. Experiment-6
Points are:
Point number 0 is: (62,4)
Point number 1 is: (25,34)
Point number 2 is: (56,72)
Point number 3 is: (16,9)
Point number 4 is: (86,16)
Point number 5 is: (56,43)
Point number 6 is: (95,0)
Point number 7 is: (18,54)
Point number 8 is: (99,95)
Point number 9 is: (32,96)
Point number 10 is: (49,86)
Point number 11 is: (75,66)
Point number 12 is: (4,82)
Point number 13 is: (26,66)
Point number 14 is: (2,36)
Point number 15 is: (99,73)
Point number 16 is: (44,93)
Point number 17 is: (75,78)
Point number 18 is: (84,45)
19
Adjacency matrix is:
Graph is:
20
The result:
21
OBSERVATION AND CONCLUSION:
We see that Constructive heuristic algorithm is way faster than local search and gives results
quickly. In each experiment, we see that after each iteration, the cost of both algorithm
decreases and the final value is less than the starting cost.
References:
1. www.wikipedia.com
2. Lecture notes
3. https://homes.di.unimi.it/righini/Didattica/AlgoritmiEuristici/MaterialeAE/6%20-
%20Constructive%20algorithms.pdf
4. http://www.cs.nott.ac.uk/~pszrq/files/2AIMconstruct.pdf
5. http://graphonline.ru/en/
22
APPENDIX
Algorithm1_ConstructiveHeuristics.java
package assignment3atn;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
/*Generates edges */
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i<j)
{
edge.add(new Node_Edge(i, j, Graph_Impl.getEdgeWeight(i, j,
points)));
}
}
}
/*Check the conditions (1),(2) and (3) of pdf i.e all the nodes are connected, degree is at least
3 and diameter is at most 4*/
boolean isNodeConnected = new CheckConnection_Nodes(graph).isNodeConnected();
boolean isAtLeastDegreeThree = Graph_Impl.isDegreeThree(graph, 3);
boolean isAtMostDiameterFour = Graph_Impl.isDiameterFour(graph, 4);
boolean allThreeConditionsSatisfied = isNodeConnected && isAtLeastDegreeThree &&
isAtMostDiameterFour;
double currCost = Double.POSITIVE_INFINITY;
System.out.println("Constructive Current Cost [fully disconnected]: " + currCost);
//System.out.println("isNodeConnected: "+isNodeConnected);
//System.out.println("isAtLeastDegreeThree: "+isAtLeastDegreeThree);
//System.out.println("isAtMostDiameterFour: "+isAtMostDiameterFour);
23
//System.out.println("allThreeConditionsSatisfied: "+allThreeConditionsSatisfied);
if(allThreeConditionsSatisfied)
{
currCost = Graph_Impl.getCost(graph);
System.out.println("Constructive Current Cost [max] -> " + currCost);
break;
}
}
while(true)
{
/*Find the edge that has the maximum weight else break*/
List<Node_Edge> edg = graph.edges();
double wt = 0.0;
Node_Edge heaviestEdge = null;
for (Node_Edge ed : edg)
{
if(wt < ed.getWeight() && !unremovableEdges.contains(ed.getNodei() + ""
+ ed.getNodej()) && !unremovableEdges.contains(ed.getNodej() + "" + ed.getNodei()))
{
wt = ed.getWeight();
heaviestEdge = ed;
}
}
if(heaviestEdge==null)
{
break;
}
graph.getAdjMatrix()[heaviestEdge.getNodei()][heaviestEdge.getNodej()] = 0;
graph.getAdjMatrix()[heaviestEdge.getNodej()][heaviestEdge.getNodei()] = 0;
if(allThreeConditionsSatisfied)
{
currCost = Graph_Impl.getCost(graph);
System.out.println("Constructive Current Cost -> " + currCost);
}
else
{
graph.getAdjMatrix()[heaviestEdge.getNodei()][heaviestEdge.getNodej()] = 1;
graph.getAdjMatrix()[heaviestEdge.getNodej()][heaviestEdge.getNodei()] = 1;
unremovableEdges.add(heaviestEdge.getNodei() + "" + heaviestEdge.getNodej());
unremovableEdges.add(heaviestEdge.getNodej() + "" + heaviestEdge.getNodei());
}
}
}
}
Algorithm2_LocalSearch.java
package assignment3atn;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
24
import java.util.HashSet;
import java.util.List;
while(true)
{
/*Finds an edge with the largest weight and remove it else break*/
List<Node_Edge> edges = graph.edges();
double weight = 0.0;
Node_Edge heaviestEdge = null;
for (Node_Edge edge : edges)
{
if(weight < edge.getWeight() &&
!unremovableEdges.contains(edge.getNodei() + "" + edge.getNodej()) &&
!unremovableEdges.contains(edge.getNodej() + "" + edge.getNodei()))
{
weight = edge.getWeight();
heaviestEdge = edge;
}
}
if(heaviestEdge==null)
{
break;
}
graph.getAdjMatrix()[heaviestEdge.getNodei()][heaviestEdge.getNodej()] = 0;
graph.getAdjMatrix()[heaviestEdge.getNodej()][heaviestEdge.getNodei()] = 0;
if(allThreeConditionsSatisfied)
{
currentCost = Graph_Impl.getCost(graph);
int matrix[][] = graph.getAdjMatrix();
System.out.println("Adjancey matrix");
for(int k=0;k<matrix.length;k++)
{
//System.out.println("Adjancey matrix for " +k);
for (int h=0;h<matrix.length;h++)
{
//if(matrix[k][h]==1)
//System.out.println("with edge for " +h);
System.out.print(matrix[k][h] + ",");
}
25
System.out.println();
}
System.out.println("Local Search Current Cost -> " + currentCost);
}
else
{
graph.getAdjMatrix()[heaviestEdge.getNodei()][heaviestEdge.getNodej()] = 1;
graph.getAdjMatrix()[heaviestEdge.getNodej()][heaviestEdge.getNodei()] = 1;
unremovableEdges.add(heaviestEdge.getNodei() + "" + heaviestEdge.getNodej());
unremovableEdges.add(heaviestEdge.getNodej() + "" + heaviestEdge.getNodei());
}
}
}
}
Algorithms_Impl.java
package assignment3atn;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/*Take n random points in the plane; n >= 15; lets take n = 19 here*/
private static int n = 18;
public static int x,y;
public static long Algo1Time1, Algo1Time2, Algo2Time1, Algo2Time2;
public static PQImpl<Double> pqMin;
public static void main(String[] args)
{
for(int ex=0;ex<numberOfExamples;ex++)
{
System.out.println("Experiment Number: "+(ex+1)+" starts here:");
HashMap<Integer, CoordinatePoints> points = new HashMap<Integer,
CoordinatePoints>();
NumberFormat nf = NumberFormat.getInstance();
CheckConnection_Nodes.java
package assignment3atn;
}
CoordinatesPoints.java
package assignment3atn;
DijkstraShortestPath.java
package assignment3atn;
import java.util.ArrayList;
import java.util.Vector;
import java.util.stream.Collectors;
distBtwn[dt] = 0.0;
pqMin = new PQImpl<Double>(gg.nVertices());
pqMin.insert(dt, distBtwn[dt]);
// ArrayList<Integer> node_edge = new ArrayList<Integer>();
while (!pqMin.isEmpty())
{
int i = pqMin.delMin();
// if(!node_edge.contains(i)) {
// System.out.println("Adjacent edges of" + i + " are: " +
gg.adjacentEdges(i).stream().map(NodeEdge::getNodej).collect(Collectors.toList()));
// node_edge.add(i);
// }
for (Node_Edge e : gg.adjacentEdges(i))
{
relaxAndUpdate(e, i);
}
}
}
Graph_Impl.java
package assignment3atn;
import java.util.HashMap;
29
public class Graph_Impl
{
/*Checks if the diameter of the graph is at most 4*/
Graph.java
package assignment3atn;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
Node_Edge.java
package assignment3atn;
PQImpl.java
package assignment3atn;
import java.util.Iterator;
import java.util.NoSuchElementException;
/*Compares index */
public boolean contains(int i)
{
if (i < 0 || i >= maxN)
throw new IndexOutOfBoundsException();
return qp[i] != -1;
}
34
/*Gives the number of keys */
public int size()
{
return n;
}
37
Readme
38