Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
c7688bc1
Commit
c7688bc1
authored
Jan 30, 2020
by
Julian Zobel
Browse files
More refactoring for social group movement
parent
6aa5caf6
Changes
11
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/AbstractGroupEncounter.java
View file @
c7688bc1
...
...
@@ -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
)
{
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/Dissolve.java
View file @
c7688bc1
...
...
@@ -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
);
}
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
Fully
.java
→
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
Merge
.java
View file @
c7688bc1
...
...
@@ -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
,
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
Fully
Partial
ly
.java
→
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
MergeFullOrMerge
Partial.java
View file @
c7688bc1
...
...
@@ -35,7 +35,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public
class
Fully
Partial
ly
extends
AbstractGroupEncounter
{
public
class
MergeFullOrMerge
Partial
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
Fully
Partial
ly
(
boolean
enableGroupEncounters
,
public
MergeFullOrMerge
Partial
(
boolean
enableGroupEncounters
,
double
groupEncounterMeetingDistance
,
long
groupReencounterWaitTime
)
{
super
(
enableGroupEncounters
,
groupEncounterMeetingDistance
,
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
Fully
Partial
ly
Dissolve.java
→
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
MergeFullOrMerge
Partial
Or
Dissolve.java
View file @
c7688bc1
...
...
@@ -34,7 +34,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public
class
Fully
Partial
ly
Dissolve
extends
AbstractGroupEncounter
{
public
class
MergeFullOrMerge
Partial
Or
Dissolve
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
Fully
Partial
ly
Dissolve
(
boolean
enableGroupEncounters
,
public
MergeFullOrMerge
Partial
Or
Dissolve
(
boolean
enableGroupEncounters
,
double
groupEncounterMeetingDistance
,
long
groupReencounterWaitTime
)
{
super
(
enableGroupEncounters
,
groupEncounterMeetingDistance
,
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
Fully
Dissolve.java
→
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
MergeOr
Dissolve.java
View file @
c7688bc1
...
...
@@ -32,14 +32,14 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public
class
Fully
Dissolve
extends
AbstractGroupEncounter
{
public
class
MergeOr
Dissolve
extends
AbstractGroupEncounter
{
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private
double
probabilityToMergeFully
;
private
double
probabilityToDissolve
;
//------------------------------------------
@XMLConfigurableConstructor
({
"enableGroupEncounters"
,
"groupEncounterMeetingDistance"
,
"groupReencounterWaitTime"
})
public
Fully
Dissolve
(
boolean
enableGroupEncounters
,
public
MergeOr
Dissolve
(
boolean
enableGroupEncounters
,
double
groupEncounterMeetingDistance
,
long
groupReencounterWaitTime
)
{
super
(
enableGroupEncounters
,
groupEncounterMeetingDistance
,
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/Partial
ly
.java
→
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
Merge
Partial.java
View file @
c7688bc1
...
...
@@ -31,14 +31,14 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public
class
Partial
ly
extends
AbstractGroupEncounter
{
public
class
Merge
Partial
extends
AbstractGroupEncounter
{
//--- VARIABLES TO BE DECLARED IN CONFIG ---
private
double
probabilityToMergePartially
;
private
int
numberOfHostsToLeave
;
//------------------------------------------
@XMLConfigurableConstructor
({
"enableGroupEncounters"
,
"groupEncounterMeetingDistance"
,
"groupReencounterWaitTime"
})
public
Partial
ly
(
boolean
enableGroupEncounters
,
public
Merge
Partial
(
boolean
enableGroupEncounters
,
double
groupEncounterMeetingDistance
,
long
groupReencounterWaitTime
)
{
super
(
enableGroupEncounters
,
groupEncounterMeetingDistance
,
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/Partial
ly
Dissolve.java
→
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/
Merge
Partial
Or
Dissolve.java
View file @
c7688bc1
...
...
@@ -33,7 +33,7 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
* @author Marcel Verst
* @version 1.0, 22.11.2018
*/
public
class
Partial
ly
Dissolve
extends
AbstractGroupEncounter
{
public
class
Merge
Partial
Or
Dissolve
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
Partial
ly
Dissolve
(
boolean
enableGroupEncounters
,
public
Merge
Partial
Or
Dissolve
(
boolean
enableGroupEncounters
,
double
groupEncounterMeetingDistance
,
long
groupReencounterWaitTime
)
{
super
(
enableGroupEncounters
,
groupEncounterMeetingDistance
,
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/AbstractGroupForming.java
View file @
c7688bc1
...
...
@@ -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
);
}
/**
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/DefaultGroupForming.java
View file @
c7688bc1
...
...
@@ -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
);
}
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/IGroupFormingBehavior.java
View file @
c7688bc1
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment