12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import java.util.Collection;
- import java.util.Iterator;
- import java.util.Random;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.NetworkManipulationAlgorithm;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
- public class RandomWiggle implements NetworkManipulationAlgorithm {
-
- private Random rand = new Random();
-
- @Override
- public void runAlgorithm(Controller controller, long currentTimeStep) {
-
- Collection<SmartDevice> devices = controller.getNetworkController().getVisibleSmartDevices();
-
- Iterator<SmartDevice> it = devices.iterator();
-
- SmartDevice move = null;
-
- int deviceNumber = rand.nextInt(devices.size());
- for(int i = 0; i <= deviceNumber && it.hasNext(); i++){
- move = it.next();
- }
-
- if(move != null){
- controller.getNetworkController().moveSmartDevice(move,(int)(move.getX()+rand.nextInt(11)-5), (int)(move.getY()+rand.nextInt(11)-5), move.getZ());
- controller.getNetworkController().validateDevicePosition();
- }
-
- controller.notifyObservers();
- }
- }
|