Commit 30bbfedd authored by Julian Zobel's avatar Julian Zobel
Browse files

More refactoring for social group movement

parent bd8eefc1
......@@ -282,12 +282,17 @@ public class MovementGroupContainer {
this.groups = groups;
}
public boolean getHostWasGroupMember(SimLocationActuator host) {
public boolean hostWasGroupMember(SimLocationActuator host) {
return this.leftGroupAtTime.containsKey(host);
}
public Map<SimLocationActuator, Long> getLeftGroupAtTime() {
return leftGroupAtTime;
public long getTimeSinceHostLeftLastGroup(SimLocationActuator host) {
if(hostWasGroupMember(host)) {
return Time.getCurrentTime() - this.leftGroupAtTime.get(host);
}
else {
return 0;
}
}
public void setLeftGroupAtTime(Map<SimLocationActuator, Long> leftGroupAtTime) {
......
......@@ -241,7 +241,7 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
for(SimLocationActuator participant : toRemove) {
small.removeHostFromGroup(participant);
groupCon.getLeftGroupAtTime().put(participant, Time.getCurrentTime());
groupCon.addLeftGroupAtTimeEntry(participant, Time.getCurrentTime());
large.addHostToGroup(participant);
}
......@@ -269,7 +269,7 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
for(int i = 0; i < numberOfHostsToLeave; i++) {
SimLocationActuator randomParticipant = large.getRandomMember();
groupCon.getLeftGroupAtTime().put(randomParticipant, Time.getCurrentTime() );
groupCon.addLeftGroupAtTimeEntry(randomParticipant, Time.getCurrentTime());
large.removeHostFromGroup(randomParticipant);
small.addHostToGroup(randomParticipant);
groupCon.updateGroupEntry(small);
......
......@@ -177,7 +177,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
for(SimLocationActuator member : group.getMembers()) {
member.setTargetAttractionPoint(poiDestination);
if(groupCon.getLeftGroupAtTime().containsKey(member)) {
if(groupCon.hostWasGroupMember(member)) {
groupCon.removeLeftGroupAtTimeEntry(member);
}
}
......@@ -332,28 +332,16 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
* @author Marcel Verst
*/
protected boolean groupRejoinTimerExpired(SimLocationActuator host) {
long t = getWaitingTime(host, Time.getCurrentTime());
long t = groupCon.getTimeSinceHostLeftLastGroup(host);
System.out.println(host.getHost().getId() + " | Wait for:" +Time.getFormattedTime(t) + ", req is " + Time.getFormattedTime(groupRejoinWaitTime) );
System.out.println(host.getHost().getId() + " | "+Time.getFormattedTime()
+" | Wait for:" +Time.getFormattedTime(t) + ", req is " + Time.getFormattedTime(groupRejoinWaitTime) );
boolean dec = t >= groupRejoinWaitTime;
return dec;
}
/**
* Returns the time a host has waited since he left a group the last time.
*
* @param SimLocacationActuator The host to be checked.
* @param Long The current time.
* @return Long
*
* @author Marcel Verst
*/
protected long getWaitingTime(SimLocationActuator host, long currentTime) {
return currentTime - groupCon.getLeftGroupAtTime().get(host);
}
/**
* Returns true, if a host has been in a group before at least once. False else.
*
......@@ -363,7 +351,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
* @author Marcel Verst
*/
protected boolean beenInGroup(SimLocationActuator host) {
return groupCon.getHostWasGroupMember(host);
return groupCon.hostWasGroupMember(host);
}
/*
......
......@@ -95,7 +95,7 @@ public class DefaultGroupForming extends AbstractGroupForming {
updateStayDuration();
int groupsToCreate = maxNumberOfGroups - groupCon.getGroups().size();
System.out.println("group trigger " + groupsToCreate);
System.out.println(Time.getFormattedTime() + " | group trigger " + groupsToCreate);
for(int g = 0; g < groupsToCreate; g++) {
// Get attractionPoint with highest amount of hosts
......@@ -147,6 +147,14 @@ public class DefaultGroupForming extends AbstractGroupForming {
if(groupCandidates.isEmpty() || groupCandidates == null) {
System.out.println("--no cands");
Event.scheduleWithDelay(Time.MINUTE, new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
triggerGroupFormation();
}
}, null, 0);
break;
}
......@@ -191,7 +199,7 @@ public class DefaultGroupForming extends AbstractGroupForming {
for(SocialMovementGroup group : groupsToRemove) {
removeGroup(group);
System.out.println("Removed group, schedule new formation in " + groupFormationDelay);
System.out.println("Removed group, schedule new formation in " + Time.getFormattedTime(groupFormationDelay) + " @ " + Time.getFormattedTime(Time.getCurrentTime() + groupFormationDelay));
Event.scheduleWithDelay(groupFormationDelay, new EventHandler() {
@Override
......@@ -220,6 +228,7 @@ public class DefaultGroupForming extends AbstractGroupForming {
Location hostLocation = component.getLastLocation();
if(ap.distanceTo(hostLocation) <= ap.getRadius()) {
isInAp = true;
break;
}
}
......
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