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

Removed a bug where node trajectory would not update in the real world street...

Removed a bug where node trajectory would not update in the real world street movement when dissolving the group in social movement. Now, the reached attraction point is explicitly set as the current attraction point for all nodes leaving the group.
parent 3f83db48
...@@ -70,7 +70,7 @@ public class ModularMovementModelViz extends JComponent ...@@ -70,7 +70,7 @@ public class ModularMovementModelViz extends JComponent
protected boolean showNodePositions = true; protected boolean showNodePositions = true;
protected boolean showTrajectories = false; protected boolean showTrajectories = true;
protected boolean setupCalculatesTrajectories = false; protected boolean setupCalculatesTrajectories = false;
...@@ -78,9 +78,9 @@ public class ModularMovementModelViz extends JComponent ...@@ -78,9 +78,9 @@ public class ModularMovementModelViz extends JComponent
private Map<Long, TrajectoryVis> trajectoryVisualizations = new LinkedHashMap<>(); private Map<Long, TrajectoryVis> trajectoryVisualizations = new LinkedHashMap<>();
private final static int NODE_PAD = 2; private final static int NODE_SIZE = 2;
private final static int ATTR_PAD = 5; private final static int ATTR_SIZE = 5;
private static Color COLOR_ATTR_POINT = Color.decode("#4A7B9D"); private static Color COLOR_ATTR_POINT = Color.decode("#4A7B9D");
...@@ -276,7 +276,7 @@ public class ModularMovementModelViz extends JComponent ...@@ -276,7 +276,7 @@ public class ModularMovementModelViz extends JComponent
g2.setFont(VisualizationTopologyView.FONT_MEDIUM); g2.setFont(VisualizationTopologyView.FONT_MEDIUM);
g2.drawString(aPoint.getName(), g2.drawString(aPoint.getName(),
VisualizationInjector.scaleValue(point.x) - g2.getFontMetrics().stringWidth(aPoint.getName()) / 2, VisualizationInjector.scaleValue(point.x) - g2.getFontMetrics().stringWidth(aPoint.getName()) / 2,
VisualizationInjector.scaleValue(point.y - aPoint.getRadius() - 5) - ATTR_PAD); VisualizationInjector.scaleValue(point.y - aPoint.getRadius() - 5) - ATTR_SIZE);
// g2.setColor(COLOR_ATTR_POINT); // g2.setColor(COLOR_ATTR_POINT);
// float alpha = 0.25f + (float) (aPoint.getWeight() / 2); // float alpha = 0.25f + (float) (aPoint.getWeight() / 2);
// g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); // g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
...@@ -285,7 +285,7 @@ public class ModularMovementModelViz extends JComponent ...@@ -285,7 +285,7 @@ public class ModularMovementModelViz extends JComponent
// VisualizationInjector.scaleValue(point.y) - ATTR_PAD, // VisualizationInjector.scaleValue(point.y) - ATTR_PAD,
// ATTR_PAD * 2 + 1, ATTR_PAD * 2 + 1); // ATTR_PAD * 2 + 1, ATTR_PAD * 2 + 1);
g2.setColor(COLOR_ATTR_POINT); g2.setColor(COLOR_ATTR_POINT);
int radius = VisualizationInjector.scaleValue(aPoint.getRadius()) + ATTR_PAD; int radius = VisualizationInjector.scaleValue(aPoint.getRadius()) + ATTR_SIZE;
g2.drawOval(VisualizationInjector.scaleValue(point.x) - radius, g2.drawOval(VisualizationInjector.scaleValue(point.x) - radius,
VisualizationInjector.scaleValue(point.y) - radius, VisualizationInjector.scaleValue(point.y) - radius,
radius * 2 + 1, radius * 2 + 1); radius * 2 + 1, radius * 2 + 1);
...@@ -305,9 +305,9 @@ public class ModularMovementModelViz extends JComponent ...@@ -305,9 +305,9 @@ public class ModularMovementModelViz extends JComponent
{ {
Point2D pt = comp.getRealPosition().asPoint(); Point2D pt = comp.getRealPosition().asPoint();
g2.setColor(Color.GRAY); g2.setColor(Color.GRAY);
g2.fillOval(VisualizationInjector.scaleValue(pt.getX()) - NODE_PAD, g2.fillOval(VisualizationInjector.scaleValue(pt.getX()) - NODE_SIZE,
VisualizationInjector.scaleValue(pt.getY()) - NODE_PAD, NODE_PAD * 2 + 1, VisualizationInjector.scaleValue(pt.getY()) - NODE_SIZE, NODE_SIZE * 2,
NODE_PAD * 2 + 1); NODE_SIZE * 2);
} }
protected void setMovementModel(ModularMovementModel model) protected void setMovementModel(ModularMovementModel model)
......
...@@ -172,18 +172,6 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -172,18 +172,6 @@ public class SocialGroupMovementModel extends ModularMovementModel {
*/ */
for (SimLocationActuator component : moveableHosts) { for (SimLocationActuator component : moveableHosts) {
assert currentTargets.containsKey(component); assert currentTargets.containsKey(component);
if(component.getHost().getId().value() == 74) {
if(component.getCurrentTargetAttractionPoint().distanceTo(component.getRealPosition())
> component.getCurrentTargetAttractionPoint().getRadius()) {
System.out.println(currentTargets.get(component));
System.out.println(component.getRealPosition());
System.out.println(component.getCurrentTargetAttractionPoint());
System.out.println(component.getCurrentTargetAttractionPoint().distanceTo(component.getRealPosition()));
System.out.println("==");
}
}
doGroupMovement(component, currentTargets.get(component)); doGroupMovement(component, currentTargets.get(component));
} }
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, EVENT_MOVE); Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, EVENT_MOVE);
......
...@@ -259,8 +259,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior ...@@ -259,8 +259,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
*/ */
protected SocialMovementGroup mergeGroupsFully(SocialMovementGroup group1, SocialMovementGroup group2) { protected SocialMovementGroup mergeGroupsFully(SocialMovementGroup group1, SocialMovementGroup group2) {
groupCon.updateMergeVars(group1, group2); groupCon.updateMergeVars(group1, group2);
System.out.println("merge groups | " + group1 + "| " + group2 );
SocialMovementGroup large = getLargerGroup(group1, group2); SocialMovementGroup large = getLargerGroup(group1, group2);
SocialMovementGroup small = getSmallerGroup(group1, group2); SocialMovementGroup small = getSmallerGroup(group1, group2);
...@@ -309,48 +307,21 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior ...@@ -309,48 +307,21 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
} }
protected void wait(SocialMovementGroup group, long timeToWait) { protected void wait(SocialMovementGroup group, long timeToWait) {
// Do not apply waiting process if one of both groups is already waiting // only start the waiting process if not already waiting (duh!)
if(!groupCon.waitingGroups.containsKey(group)) { if(!groupCon.waitingGroups.containsKey(group)) {
// long timer = groupCon.waitingGroups.get(group).getA(); groupCon.waitingGroups.put(group, new Tuple<Long, Long>(timeToWait, Time.getCurrentTime()));
// long delta = Time.getCurrentTime() - groupCon.waitingGroups.get(group).getB(); Event.scheduleWithDelay(timeToWait, new EventHandler() {
// System.out.println("Group " + group.getLeader().getHost().getId());
// System.out.println(Time.getFormattedTime(timer) + " TTW");
// System.out.println(Time.getFormattedTime(delta) + " delta");
//
// // Remove groups if they have waited long enough
// if(delta >= timer) {
// System.out.println(" Delta >= Timer --- remove...");
// groupCon.updateMergeVars(group);
// groupCon.waitingGroups.remove(group);
// }
// else {
// System.out.println(" wait more... ");
// }
//
// System.out.println(" == ");
// }
// else {
System.out.println("new Waiting group : " + group.getLeader().getHost().getId() );
groupCon.waitingGroups.put(group, new Tuple<Long, Long>(timeToWait, Time.getCurrentTime()));
Event.scheduleWithDelay(timeToWait, new EventHandler() {
@Override @Override
public void eventOccurred(Object content, int type) { public void eventOccurred(Object content, int type) {
SocialMovementGroup g = (SocialMovementGroup) content;
SocialMovementGroup g = (SocialMovementGroup) content; // if group was deleted in the meantime (e.g., by dissolving/merging), just do nothing
if(!groupCon.hasGroup(g)) {
if(!groupCon.hasGroup(g)) {
System.out.println("group NULL");
return; return;
} }
System.out.println(" Timer expired for " + g);
groupCon.updateMergeVars(g); groupCon.updateMergeVars(g);
groupCon.waitingGroups.remove(g); groupCon.waitingGroups.remove(g);
} }
}, group, 0); }, group, 0);
} }
} }
......
...@@ -46,38 +46,27 @@ public class WaitSmartMerge extends Wait{ ...@@ -46,38 +46,27 @@ public class WaitSmartMerge extends Wait{
long pauseTime = getRandomWaitTime(); long pauseTime = getRandomWaitTime();
if(groupCon.waitingGroups.containsKey(group1) && !groupCon.waitingGroups.containsKey(group2)) { if(groupCon.waitingGroups.containsKey(group1) && !groupCon.waitingGroups.containsKey(group2)) {
pauseTime =getRemainingGroupWaitTime(group1); pauseTime = getRemainingGroupWaitTime(group1);
} }
else if(!groupCon.waitingGroups.containsKey(group1) && groupCon.waitingGroups.containsKey(group2)) { else if(!groupCon.waitingGroups.containsKey(group1) && groupCon.waitingGroups.containsKey(group2)) {
pauseTime =getRemainingGroupWaitTime(group2); pauseTime = getRemainingGroupWaitTime(group2);
} }
if(group1.getLeader().getCurrentTargetAttractionPoint() == group2.getLeader().getCurrentTargetAttractionPoint()) { if(group1.getLeader().getCurrentTargetAttractionPoint() == group2.getLeader().getCurrentTargetAttractionPoint()) {
SocialMovementGroup merged = mergeGroupsFully(group1, group2); SocialMovementGroup merged = mergeGroupsFully(group1, group2);
wait(merged, getRandomWaitTime()); wait(merged, pauseTime);
} }
else if(rand.nextDouble() <= probabilityToWait) { else if(rand.nextDouble() <= probabilityToWait) {
long time = getRandomWaitTime(); wait(group1, pauseTime);
wait(group1, time); wait(group2, pauseTime);
wait(group2, time);
} }
} }
private long getRemainingGroupWaitTime(SocialMovementGroup group) { private long getRemainingGroupWaitTime(SocialMovementGroup group) {
long pausetime = groupCon.waitingGroups.get(group).getA();
long pausetime = groupCon.waitingGroups.get(group).getA();
long issueTime = groupCon.waitingGroups.get(group).getB(); long issueTime = groupCon.waitingGroups.get(group).getB();
return issueTime + pausetime - Time.getCurrentTime();
long remaining = issueTime + pausetime - Time.getCurrentTime();
System.out.println(Time.getFormattedTime(remaining) + " remaining of " + group);
return remaining;
} }
} }
......
...@@ -231,7 +231,17 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior { ...@@ -231,7 +231,17 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
else { else {
delay = rndGroupFormationDelay(); delay = rndGroupFormationDelay();
} }
if(group.getGroupSize() > 0 || group.getLeader() != null) {
AttractionPoint currentAP = group.getLeader().getCurrentTargetAttractionPoint();
for (SimLocationActuator host : group.getMembers()) {
movementModel.updatedAttractionAssignment(host, currentAP);
}
}
Event.scheduleWithDelay(delay, new EventHandler() { Event.scheduleWithDelay(delay, new EventHandler() {
@Override @Override
public void eventOccurred(Object content, int type) { public void eventOccurred(Object content, int type) {
......
...@@ -510,7 +510,7 @@ public class VisualizationTopologyView extends JFrame ...@@ -510,7 +510,7 @@ public class VisualizationTopologyView extends JFrame
return plottingViews.get(name); return plottingViews.get(name);
} }
protected static void notifyInteractionListenersOnClick(long hostid, public static void notifyInteractionListenersOnClick(long hostid,
boolean isActive) { boolean isActive) {
for (NodeVisInteractionListener listener : VisualizationInjector.interactionListeners) { for (NodeVisInteractionListener listener : VisualizationInjector.interactionListeners) {
listener.onHostClick(hostid, isActive); listener.onHostClick(hostid, isActive);
......
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