Project-3 Report
Project-3 Report
Project:3
Network Topology Design of Nodes
by
➢ Network Description:
➢ Network topology:
Create a network topology such that it has the following properties:
1. It contains all the given nodes.
2. The degree of each vertex in the graph is at least 3, that is, each node is
connected to at least 3 other nodes.
3. The diameter of the graph is at most 4. By this we mean that any node can
be reached from any other node in at most 4 hops. (This can be checked by
any shortest path algorithm.) That is, the diameter in our case refers to the
hop-distance, not to any kind of geometric distance. Note that this diameter
bound implies that the graph must be connected.
4. The total cost of the network topology is as low as possible, where the cost
is measured by the total geometric length of all links. This means, you have
compute how long each link is geometrically (that is, how far apart are its
end-nodes), and then sum it up for all links that exist in the network. This
sum represents the total cost that we would like to minimize, under the
constraints described above in items 1,2,3.
➢ Assumptions:
Network topology is a undirected graph. We are assuming that the nodes are
always connected.
➢ Goal:
Given the coordinate location of n nodes in a plane, create a network topology
design such that it satisfies the given properties. Thus, the goal is to create and
implement two different heuristic algorithms for this network topology design
problem, and experiment with them.
➢ Heuristic Algorithms:
1. Constructive Heuristic Algorithm
2. Local Search Heuristic Algorithm
o Constructive Algorithm:
In combinatorial optimization problems, every solution x is a subset of the
ground set E.
A constructive heuristic iteratively updates a subset x (t) as follows:
1. it starts from an empty subset: x (0) = ∅ (it is a subset of the optimal solution)
2. at each iteration t, if selects an element i (t) ∈ E as “the best one” among
the “admissible” elements (one tries to make x(t) to be a subset of a feasible
and optimal solution)
3. inserts i (t) in the current subset x (t) : x (t+1) := x (t) ∪ i (t) (no backtrack is
allowed)
4. it goes back to step 2 until the solution is complete (if further enlarged, the
solution would not remain feasible)
o How it works:
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). In general, the resulting
complexity turns out to be a low order polynomial. T (n) = n (γExt (n) + γφ (n)).
2. Local Search Heuristic Algorithm: In computer science, 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.
In Step 3, the acceptance rule is usually based on values F(S) and F(S’) of the
objective function for schedules S and S’. In some algorithms only moves to
‘better’ schedules are accepted (schedule S’ is better than S if F(S’) < F(S); in
others it may be allowed to move to ‘worse’ schedules. Sometimes ‘wait and
see’ approach is adopted.
In what follows we specify Step 3 “Acceptance Test” for each type of the local
search algorithm.
➢ Program Details:
• It consists of implementation of two heuristic algorithms: Local Search &
Constructive Heuristic Algorithms.
• Run the file ExperimentAlgorithms.java. It shows analysis of both the algorithms.
• A total of 6 experiments are run which can be configured using
numberOfExamples in ExperimentAlgorithms.java
• Each experiment simulates a graph of 18 nodes in a 2d plane with x-y cords lying
between (0,0) and (100,100)
• Both the algorithms are run to find optimal cost of the total graph subject to the
following conditions:
a) Graph should be connected
b) Graph should have degree of at least 3 for each node
c) Diameter of graph should be at most 4
➢ ReadMe:
Node-Edges Connection:
Source Target
0 2
0 13
0 15
0 16
1 4
1 7
1 13
2 0
2 6
2 9
2 10
2 17
3 8
3 11
3 14
3 15
4 1
4 7
4 13
5 12
5 13
5 16
6 2
6 9
6 17
7 1
7 4
7 13
8 3
8 15
9 2
9 6
9 10
10 2
10 9
10 17
11 3
11 12
11 15
12 5
12 11
12 16
13 0
13 1
13 4
13 5
13 7
14 3
14 15
15 0
15 3
15 8
15 11
15 14
16 0
16 5
16 12
17 2
17 6
17 10
Network Topology (Graph):
❖ Experiment Run-2:
Points:
Node-Edges Connection:
Source Target
0 5
0 6
0 12
1 2
1 3
1 4
1 6
1 10
1 11
1 16
1 17
2 1
2 11
2 16
3 1
3 10
3 17
4 1
4 8
4 13
4 15
5 0
5 6
5 12
6 0
6 1
6 5
6 12
7 9
7 11
7 14
8 4
8 13
8 15
9 7
9 11
10 1
10 3
10 17
11 1
11 2
11 7
11 9
11 14
11 16
12 0
12 5
12 6
13 4
13 8
13 15
14 7
14 11
15 4
15 8
15 13
16 1
16 2
16 11
17 1
17 3
17 10
Network Topology (Graph):
❖ Experiment Run-3:
Points:
Node-Edges Connection:
Source Target
0 12
0 15
1 4
1 6
1 15
2 3
2 5
2 9
2 10
2 12
3 2
3 7
3 14
4 1
4 14
4 16
5 2
5 9
5 10
6 1
6 12
6 15
7 3
7 13
7 17
8 12
8 15
9 2
9 5
9 10
10 2
10 5
10 9
11 14
11 15
11 16
12 0
12 2
12 6
12 8
13 7
13 16
13 17
14 3
14 4
14 11
14 16
14 17
15 0
15 1
15 6
15 8
15 11
16 4
16 11
16 13
16 14
17 7
17 13
17 14
Network Topology (Graph):
❖ Experiment Run-4:
Points:
Node-Edges Connection:
Source Target
0 3
0 12
0 16
1 5
1 10
1 13
2 6
2 7
2 12
3 0
3 8
3 17
4 5
4 7
4 9
5 1
5 4
5 7
5 10
5 11
6 2
6 11
6 15
7 2
7 4
7 5
7 12
8 3
8 12
8 16
9 4
9 13
10 1
10 5
10 13
11 5
11 6
11 13
12 0
12 2
12 7
12 8
13 1
13 9
13 10
13 11
13 14
13 15
14 13
14 15
14 17
15 6
15 13
15 14
16 0
16 8
16 17
17 3
17 14
17 16
Network Topology (Graph):
❖ Experiment Run-5:
Points:
Node-Edges Connection:
Source Target
0 6
0 9
0 13
1 3
1 5
1 7
2 3
2 7
2 17
3 1
3 2
3 5
3 7
3 9
3 13
3 17
4 8
4 14
4 15
5 1
5 3
6 0
6 10
6 11
7 1
7 2
7 3
8 4
8 12
8 14
8 15
9 0
9 3
9 11
10 6
10 11
10 12
11 6
11 9
11 10
12 8
12 10
12 16
13 0
13 3
13 14
13 16
14 4
14 8
14 13
14 15
14 16
15 4
15 8
15 14
16 12
16 13
16 14
17 2
17 3
Network Topology (Graph):
❖ Experiment Run-6:
Points:
Node-Edges Connection:
Source Target
0 3
0 4
0 9
0 13
0 14
0 16
1 2
1 6
1 17
2 1
2 10
2 13
2 17
3 0
3 14
3 16
4 0
4 5
4 9
4 11
4 13
4 15
5 4
5 6
5 7
5 8
5 12
6 1
6 5
6 8
7 5
7 8
7 12
8 5
8 6
8 7
9 0
9 4
9 13
10 2
10 13
10 17
11 4
11 12
12 5
12 7
12 11
12 15
13 0
13 2
13 4
13 9
13 10
14 0
14 3
14 16
15 4
15 12
16 0
16 3
16 14
17 1
17 2
17 10
Network Topology (Graph):
➢ Observation:
Thus, observing the costs from the results, we can infer that the Constructive
Heuristic Algorithm takes less amount of time and cost to build the complete
solution. Constructive algorithm extends the empty solution until we get the
complete solution whereas Local Search algorithm takes the complete solution and
tries to improve it via local moves. Thus, it is better among the two algorithms.
➢ Conclusion:
The cost of these algorithms at first decreases and then increases. Thus, it is not
steady but if more than 25 iterations are performed then it may lead to a decrease
in the cost. 20 iterations are enough to reach a solution that does not improve
significantly in further iterations. The experimental running time of the algorithms
keeps on decreasing as we increase the iterations.
➢ References:
(1) Professor Andras Farago’s Lecture Notes
(2) www.wikipedia.com
➢ Appendix:
[Source Code:]
ExperimentAlgorithms.java
package com.bhakti.project3;
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 = 18 here*/
private static int n = 18;
public static int x,y;
public static long Algo1Time1, Algo1Time2, Algo2Time1, Algo2Time2;
public static IndexMinPQ<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();
Algorithm1_Constructive.java
package com.bhakti.project3;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import com.bhakti.project3.*;
/*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 CheckConnectedNodes(graph).isNodeConnected();
boolean isAtLeastDegreeThree = GraphProperties.isDegreeThree(graph, 3);
boolean isAtMostDiameterFour = GraphProperties.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);
//System.out.println("allThreeConditionsSatisfied:
"+allThreeConditionsSatisfied);
if(allThreeConditionsSatisfied)
{
currCost = GraphProperties.getCost(graph);
System.out.println("Constructive Current Cost [max] -> " + currCost);
break;
}
}
if(heaviestEdge==null)
{
break;
}
graph.getAdjMatrix()[heaviestEdge.getNodei()][heaviestEdge.getNodej()] = 0;
graph.getAdjMatrix()[heaviestEdge.getNodej()][heaviestEdge.getNodei()] = 0;
if(allThreeConditionsSatisfied)
{
//System.out.println("in here");
currCost = GraphProperties.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 com.bhakti.project3;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import com.bhakti.project3.*;
while(true)
{
/*Finds an edge with the largest weight and remove it else break*/
List<NodeEdge> edges = graph.edges();
double weight = 0.0;
NodeEdge heaviestEdge = null;
for (NodeEdge 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 = GraphProperties.getCost(graph);
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());
}
}
}
}
CheckConnectedNodes.java:
package com.bhakti.project3;
CalculateDijkstraShortestPath.java:
package com.bhakti.project3;
import java.util.Vector;
import java.util.stream.Collectors;
distBtwn[dt] = 0.0;
pqMin = new IndexMinPQ<Double>(gg.nVertices());
pqMin.insert(dt, distBtwn[dt]);
while (!pqMin.isEmpty())
{
int i = pqMin.delMin();
//System.out.println("Adjacent edges of" + i + " are: " +
gg.adjacentEdges(i).stream().map(NodeEdge::getNodej).collect(Collectors.toList()));
CoordinatePoints.java:
package com.bhakti.project3;
GenerateGraph.java:
package com.bhakti.project3;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import com.bhakti.project3.*;
GraphProperties.java:
package com.bhakti.project3;
import java.util.HashMap;
import com.bhakti.project3.*;
package com.bhakti.project3;
IndexMinPQ.java:
package com.bhakti.project3;
import java.util.Iterator;
import java.util.NoSuchElementException;