package org.lucci.madhoc.network;
import java.util.Random;
import org.lucci.madhoc.network.net.NetworkingTechnology;
import org.lucci.math.Utilities;
import org.lucci.util.Collections;
public class RandomNetworkAlterer extends NetworkAlterer
{
public void operate(Network network)
{
NetworkingTechnology techno = network.getNetworkTypes().get("umts");
Random random = network.getSimulation().getRandomNumberGenerator().getRandom();
for (Connection link : network.findConnections(techno))
{
if (Utilities.getRandomBetween(0, 1, random) < 0.1)
{
link.remove();
}
}
int numberOfLinks = network.getStations().size() / 50;
while (network.findConnections(techno).size() < numberOfLinks)
{
Station s1 = (Station) Collections.getRandomObject(network
.getStations(), random);
Station s2 = (Station) Collections.getRandomObject(network
.getStations(), random);
while (s2 == s1)
{
s2 = (Station) Collections.getRandomObject(network
.getStations(), random);
}
network.createBidirectionalConnection(s1, s2, "umts");
}
}
}