@Override
	public WeightedGraph<Sensor, Link> createNetwork(float sensorRange) {

		resetStatistics();
		WeightedGraph<Sensor, Link> network = new WeightedGraph<Sensor, Link>();

		// Add all vertices in the logical network to the new network.
		Iterator<Sensor> vertsIter = logicalNetwork.vertices().iterator();

		while (vertsIter.hasNext()) {
			network.insertVertex(vertsIter.next());
		}

		// Add edges which have the proper sensor range to the network.
		Iterator<Sensor> vertsUIter = logicalNetwork.vertices().iterator();
		Iterator<Sensor> vertsVIter;

		// For every pair of vertices, if their distance is less than or equal
		// to the new distance we want to create an edge between them. Only do
		// this if the vertices are not the same.
		while (vertsUIter.hasNext()) {

			Sensor u = vertsUIter.next();

			u.setAntennaType(AntennaType.DIRECTIONAL);
			u.setAntennaRange(sensorRange);

			vertsVIter = logicalNetwork.vertices().iterator();

			while (vertsVIter.hasNext()) {
				Sensor v = vertsVIter.next();

				// If the distance is less than the range then we add an edge.
				if (u.getDistance(v) <= sensorRange && v != u) {

					Link newEdge = new Link(u.getName() + v.getName());
					network.insertEdge(u, v, newEdge);
				}
			}
		}

		// Set the antenna ranges & angles.
		vertsIter = network.vertices().iterator();

		while (vertsIter.hasNext()) {

			Sensor sensor = vertsIter.next();

			// First get the connected edges. Then filter them by using only
			// outgoing edges. According to the edges we can then find the
			// correct angle and distance.
			Iterator<Link> edgeIter = network.incidentEdges(sensor).iterator();
			HashSet<Sensor> connectedVertices = new HashSet<Sensor>();

			while (edgeIter.hasNext()) {
				Link link = edgeIter.next();

				// Only use outgoing edges.
				if (network.endVertices(link).iterator().next().equals(sensor)) {

					Sensor s = network.opposite(sensor, link);
					connectedVertices.add(s);
				}
			}

			setSensorProps(sensor, connectedVertices, sensorRange);
		}

		return network;
	}