Commit c7688bc1 authored by Julian Zobel's avatar Julian Zobel
Browse files

More refactoring for social group movement

parent 6aa5caf6
......@@ -29,6 +29,7 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.SocialGroupMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.MovementGroupContainer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovementGroup;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupforming.AbstractGroupForming;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
......@@ -167,7 +168,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
*
* @return Double Distance between group leaders of both groups.
*
* @author Marcel Verst
*/
public double getDistanceBetweenGroups(SocialMovementGroup group1, SocialMovementGroup group2) {
PositionVector l1Pos = group1.getLeaderPosition();
......@@ -182,7 +182,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
* @param SocialMovementGroup The second group.
* @return GroupInstance The larger group, or the first group if both are the same size.
*
* @author Marcel Verst
*/
protected SocialMovementGroup getLargerGroup(SocialMovementGroup group1, SocialMovementGroup group2) {
......@@ -201,7 +200,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
* @param SocialMovementGroup The second group.
* @return GroupInstance The smaller group, or the second group if both are the same size.
*
* @author Marcel Verst
*/
protected SocialMovementGroup getSmallerGroup(SocialMovementGroup group1, SocialMovementGroup group2) {
......@@ -220,7 +218,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
* @param int The time a host has to wait until it can merge again.
* @return boolean
*
* @author Marcel Verst
*/
protected boolean waitedLongEnoughAfterMerging(SimLocationActuator host) {
return ((Time.getCurrentTime() - groupCon.getMergedAtTime().get(host)) >= groupReencounterWaitTime);
......@@ -229,14 +226,24 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
/**
* Removes both groups on encounter.
*
* @author Marcel Verst
*/
protected void dissolveGroups(SocialMovementGroup group1, SocialMovementGroup group2) {
groupCon.updateMergeVars(group1, group2);
if(groupCon.getGroups().contains(group1) && groupCon.getGroups().contains(group2)) {
groupCon.removeGroup(group1);
groupCon.removeGroup(group2);
for(SimLocationActuator participant : group1.getMembers()) {
groupCon.addLeftGroupAtTimeEntry(participant, Time.getCurrentTime());
movementModel.getAttractionAssignmentStrategy().addComponent(participant);
}
for(SimLocationActuator participant : group2.getMembers()) {
groupCon.addLeftGroupAtTimeEntry(participant, Time.getCurrentTime());
movementModel.getAttractionAssignmentStrategy().addComponent(participant);
}
movementModel.getGroupFormingBehavior().removeGroup(group1);
movementModel.getGroupFormingBehavior().removeGroup(group2);
}
}
......@@ -246,11 +253,12 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
* @param SocialMovementGroup The first group.
* @param SocialMovementGroup The second group.
*
* @author Marcel Verst
*/
protected void mergeGroupsFully(SocialMovementGroup group1, SocialMovementGroup group2) {
groupCon.updateMergeVars(group1, group2);
System.out.println("merge groups!");
SocialMovementGroup large = getLargerGroup(group1, group2);
SocialMovementGroup small = getSmallerGroup(group1, group2);
......@@ -262,7 +270,7 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
large.addHostToGroup(participant);
}
groupCon.removeGroup(small);
movementModel.getGroupFormingBehavior().removeGroup(small);
}
/**
......@@ -271,7 +279,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
* @param SocialMovementGroup The first group.
* @param SocialMovementGroup The second group.
*
* @author Marcel Verst
*/
protected void mergeGroupsPartially(SocialMovementGroup group1, SocialMovementGroup group2, int numberOfHostsToLeave) {
......
......@@ -52,6 +52,7 @@ public class Dissolve extends AbstractGroupEncounter {
@Override
public void handleGroupEncounter(SocialMovementGroup group1, SocialMovementGroup group2) {
if(rand.nextDouble() <= probabilityToDissolve) {
System.out.println("Dissolve groups");
dissolveGroups(group1, group2);
}
}
......
......@@ -31,13 +31,13 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public class Fully extends AbstractGroupEncounter {
public class Merge extends AbstractGroupEncounter {
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private double probabilityToMergeFully;
//------------------------------------------
@XMLConfigurableConstructor({"enableGroupEncounters","groupEncounterMeetingDistance","groupReencounterWaitTime"})
public Fully(boolean enableGroupEncounters,
public Merge(boolean enableGroupEncounters,
double groupEncounterMeetingDistance,
long groupReencounterWaitTime) {
super(enableGroupEncounters, groupEncounterMeetingDistance,
......
......@@ -35,7 +35,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public class FullyPartially extends AbstractGroupEncounter {
public class MergeFullOrMergePartial extends AbstractGroupEncounter {
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private double probabilityToMergeFully;
private double probabilityToMergePartially;
......@@ -43,7 +43,7 @@ public class FullyPartially extends AbstractGroupEncounter {
//------------------------------------------
@XMLConfigurableConstructor({"enableGroupEncounters","groupEncounterMeetingDistance","groupReencounterWaitTime"})
public FullyPartially(boolean enableGroupEncounters,
public MergeFullOrMergePartial(boolean enableGroupEncounters,
double groupEncounterMeetingDistance,
long groupReencounterWaitTime) {
super(enableGroupEncounters, groupEncounterMeetingDistance,
......
......@@ -34,7 +34,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public class FullyPartiallyDissolve extends AbstractGroupEncounter {
public class MergeFullOrMergePartialOrDissolve extends AbstractGroupEncounter {
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private double probabilityToMergeFully;
private double probabilityToMergePartially;
......@@ -43,7 +43,7 @@ public class FullyPartiallyDissolve extends AbstractGroupEncounter {
//------------------------------------------
@XMLConfigurableConstructor({"enableGroupEncounters","groupEncounterMeetingDistance","groupReencounterWaitTime"})
public FullyPartiallyDissolve(boolean enableGroupEncounters,
public MergeFullOrMergePartialOrDissolve(boolean enableGroupEncounters,
double groupEncounterMeetingDistance,
long groupReencounterWaitTime) {
super(enableGroupEncounters, groupEncounterMeetingDistance,
......
......@@ -32,14 +32,14 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public class FullyDissolve extends AbstractGroupEncounter {
public class MergeOrDissolve extends AbstractGroupEncounter {
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private double probabilityToMergeFully;
private double probabilityToDissolve;
//------------------------------------------
@XMLConfigurableConstructor({"enableGroupEncounters","groupEncounterMeetingDistance","groupReencounterWaitTime"})
public FullyDissolve(boolean enableGroupEncounters,
public MergeOrDissolve(boolean enableGroupEncounters,
double groupEncounterMeetingDistance,
long groupReencounterWaitTime) {
super(enableGroupEncounters, groupEncounterMeetingDistance,
......
......@@ -31,14 +31,14 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public class Partially extends AbstractGroupEncounter {
public class MergePartial extends AbstractGroupEncounter {
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private double probabilityToMergePartially;
private int numberOfHostsToLeave;
//------------------------------------------
@XMLConfigurableConstructor({"enableGroupEncounters","groupEncounterMeetingDistance","groupReencounterWaitTime"})
public Partially(boolean enableGroupEncounters,
public MergePartial(boolean enableGroupEncounters,
double groupEncounterMeetingDistance,
long groupReencounterWaitTime) {
super(enableGroupEncounters, groupEncounterMeetingDistance,
......
......@@ -33,7 +33,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public class PartiallyDissolve extends AbstractGroupEncounter {
public class MergePartialOrDissolve extends AbstractGroupEncounter {
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private double probabilityToMergePartially;
private double probabilityToDissolve;
......@@ -41,7 +41,7 @@ public class PartiallyDissolve extends AbstractGroupEncounter {
//------------------------------------------
@XMLConfigurableConstructor({"enableGroupEncounters","groupEncounterMeetingDistance","groupReencounterWaitTime"})
public PartiallyDissolve(boolean enableGroupEncounters,
public MergePartialOrDissolve(boolean enableGroupEncounters,
double groupEncounterMeetingDistance,
long groupReencounterWaitTime) {
super(enableGroupEncounters, groupEncounterMeetingDistance,
......
......@@ -226,10 +226,17 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
*
* @param SocialMovementGroup The group to be removed.
*
* @author Marcel Verst
*/
protected void removeGroup(SocialMovementGroup group) {
@Override
public void removeGroup(SocialMovementGroup group) {
groupCon.removeGroup(group);
Event.scheduleWithDelay(rndGroupFormationDelay(), new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
triggerGroupFormation();
}
}, null, 0);
}
/**
......
......@@ -191,15 +191,6 @@ public class DefaultGroupForming extends AbstractGroupForming {
for(SocialMovementGroup group : groupsToRemove) {
removeGroup(group);
//System.out.println("Removed group, schedule new formation in " + Time.getFormattedTime(groupFormationDelay) + " @ " + Time.getFormattedTime(Time.getCurrentTime() + groupFormationDelay));
Event.scheduleWithDelay(rndGroupFormationDelay(), new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
triggerGroupFormation();
}
}, null, 0);
}
}
......
......@@ -22,6 +22,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupforming;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.SocialGroupMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovementGroup;
/**
* This interface specifies the GroupFormingStrategy, which basically handles the creation and deletion of groups.
......@@ -63,4 +64,6 @@ public interface IGroupFormingBehavior {
public int getMinGroupSize();
public int getMaxGroupSize();
public void removeGroup(SocialMovementGroup group);
}
\ No newline at end of file
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