Commit 6aed8748 authored by Julian Zobel's avatar Julian Zobel
Browse files

Allow group split in small scenarios

parent d1a39dbc
......@@ -49,6 +49,7 @@ import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.*;
public class ProgrammableSmallScenarioMovement extends ModularMovementModel {
......@@ -101,11 +102,9 @@ public class ProgrammableSmallScenarioMovement extends ModularMovementModel {
parseActionsFile();
// This adds the mobile hosts (smartphones/users) to the transition
// strategy
// This adds the mobile hosts to the transition strategy
for (SimLocationActuator ms : moveableHosts) {
// TODO select hosts for APs and group
// TODO place hosts appopriately
attractionAssigment.addComponent(ms);
......@@ -294,23 +293,76 @@ public class ProgrammableSmallScenarioMovement extends ModularMovementModel {
groups.put(name, group);
}
else {
String name = tokens[0];
long time = DefaultConfigurator.parseNumber(tokens[1], Long.class);
int x = Integer.parseInt(tokens[2]);
int y = Integer.parseInt(tokens[3]);
BasicAttractionPoint target = new BasicAttractionPoint("Group"+name+"-"+Time.getFormattedTime(time), new PositionVector(x, y));
System.out.println("Group " + name + " to " + x + " / " + y + " at " + Time.getFormattedTime(time));
if(tokens[0].equals("split")) {
long time = DefaultConfigurator.parseNumber(tokens[1], Long.class);
String name = tokens[2];
String name2 = tokens[3];
double val = DefaultConfigurator.parseNumber(tokens[4], Double.class);
Event.scheduleWithDelay(time, new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
SocialMovementGroup group = groups.get(name);
// split group
SocialMovementGroup group2 = new SocialMovementGroup();
LinkedHashSet<SimLocationActuator> allHosts = group.getMembers();
int n = (int) (allHosts.size() * val);
int target = allHosts.size() - n;
System.out.println("splitting group " + name + "("+allHosts.size()+") into " + n + " and " + (allHosts.size()-n));
LinkedList<SimLocationActuator> hosts2 = new LinkedList<>();
while(hosts2.size() < target) {
SimLocationActuator member = group.getRandomMember();
if(group.getLeader() == member)
continue;
hosts2.add(member);
group.removeHostFromGroup(member);
}
group2.setMembers(new LinkedHashSet<>(hosts2));
// pick leader
SimLocationActuator leader = group2.getLeader();
// set location around leader
for (SimLocationActuator host : group2.getMembers()) {
followLeader(leader, host);
}
Location lp = leader.getRealPosition();
// new group stays where it is
leader.setTargetAttractionPoint(new BasicAttractionPoint("Group"+name2+ "stay", new PositionVector(leader.getRealPosition())));
groups.put(name2, group2);
}
}, name, 0);
}
else {
String name = tokens[0];
long time = DefaultConfigurator.parseNumber(tokens[1], Long.class);
int x = Integer.parseInt(tokens[2]);
int y = Integer.parseInt(tokens[3]);
BasicAttractionPoint target = new BasicAttractionPoint("Group"+name+"-"+Time.getFormattedTime(time), new PositionVector(x, y));
System.out.println("Group " + name + " to " + x + " / " + y + " at " + Time.getFormattedTime(time));
Event.scheduleWithDelay(time, new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
groups.get(name).getLeader().setTargetAttractionPoint(target);
System.out.println(name + " moving towards " + target);
}
}, target, 0);
}
Event.scheduleWithDelay(time, new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
groups.get(name).getLeader().setTargetAttractionPoint(target);
System.out.println(name + " moving towards " + target);
}
}, target, 0);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment