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
protected boolean showNodePositions = true;
protected boolean showTrajectories = false;
protected boolean showTrajectories = true;
protected boolean setupCalculatesTrajectories = false;
......@@ -78,9 +78,9 @@ public class ModularMovementModelViz extends JComponent
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");
......@@ -276,7 +276,7 @@ public class ModularMovementModelViz extends JComponent
g2.setFont(VisualizationTopologyView.FONT_MEDIUM);
g2.drawString(aPoint.getName(),
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);
// float alpha = 0.25f + (float) (aPoint.getWeight() / 2);
// g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
......@@ -285,7 +285,7 @@ public class ModularMovementModelViz extends JComponent
// VisualizationInjector.scaleValue(point.y) - ATTR_PAD,
// ATTR_PAD * 2 + 1, ATTR_PAD * 2 + 1);
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,
VisualizationInjector.scaleValue(point.y) - radius,
radius * 2 + 1, radius * 2 + 1);
......@@ -305,9 +305,9 @@ public class ModularMovementModelViz extends JComponent
{
Point2D pt = comp.getRealPosition().asPoint();
g2.setColor(Color.GRAY);
g2.fillOval(VisualizationInjector.scaleValue(pt.getX()) - NODE_PAD,
VisualizationInjector.scaleValue(pt.getY()) - NODE_PAD, NODE_PAD * 2 + 1,
NODE_PAD * 2 + 1);
g2.fillOval(VisualizationInjector.scaleValue(pt.getX()) - NODE_SIZE,
VisualizationInjector.scaleValue(pt.getY()) - NODE_SIZE, NODE_SIZE * 2,
NODE_SIZE * 2);
}
protected void setMovementModel(ModularMovementModel model)
......
......@@ -172,18 +172,6 @@ public class SocialGroupMovementModel extends ModularMovementModel {
*/
for (SimLocationActuator component : moveableHosts) {
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));
}
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, EVENT_MOVE);
......
......@@ -259,8 +259,6 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
*/
protected SocialMovementGroup mergeGroupsFully(SocialMovementGroup group1, SocialMovementGroup group2) {
groupCon.updateMergeVars(group1, group2);
System.out.println("merge groups | " + group1 + "| " + group2 );
SocialMovementGroup large = getLargerGroup(group1, group2);
SocialMovementGroup small = getSmallerGroup(group1, group2);
......@@ -309,48 +307,21 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior
}
protected void wait(SocialMovementGroup group, long timeToWait) {
// Do not apply waiting process if one of both groups is already waiting
if(!groupCon.waitingGroups.containsKey(group)) {
// long timer = groupCon.waitingGroups.get(group).getA();
// long delta = Time.getCurrentTime() - groupCon.waitingGroups.get(group).getB();
// 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() {
// only start the waiting process if not already waiting (duh!)
if(!groupCon.waitingGroups.containsKey(group)) {
groupCon.waitingGroups.put(group, new Tuple<Long, Long>(timeToWait, Time.getCurrentTime()));
Event.scheduleWithDelay(timeToWait, new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
SocialMovementGroup g = (SocialMovementGroup) content;
if(!groupCon.hasGroup(g)) {
System.out.println("group NULL");
public void eventOccurred(Object content, int type) {
SocialMovementGroup g = (SocialMovementGroup) content;
// if group was deleted in the meantime (e.g., by dissolving/merging), just do nothing
if(!groupCon.hasGroup(g)) {
return;
}
System.out.println(" Timer expired for " + g);
groupCon.updateMergeVars(g);
groupCon.waitingGroups.remove(g);
}
}, group, 0);
}, group, 0);
}
}
......
......@@ -46,38 +46,27 @@ public class WaitSmartMerge extends Wait{
long pauseTime = getRandomWaitTime();
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)) {
pauseTime =getRemainingGroupWaitTime(group2);
pauseTime = getRemainingGroupWaitTime(group2);
}
if(group1.getLeader().getCurrentTargetAttractionPoint() == group2.getLeader().getCurrentTargetAttractionPoint()) {
SocialMovementGroup merged = mergeGroupsFully(group1, group2);
wait(merged, getRandomWaitTime());
wait(merged, pauseTime);
}
else if(rand.nextDouble() <= probabilityToWait) {
long time = getRandomWaitTime();
wait(group1, time);
wait(group2, time);
else if(rand.nextDouble() <= probabilityToWait) {
wait(group1, pauseTime);
wait(group2, pauseTime);
}
}
private long getRemainingGroupWaitTime(SocialMovementGroup group) {
long pausetime = groupCon.waitingGroups.get(group).getA();
private long getRemainingGroupWaitTime(SocialMovementGroup group) {
long pausetime = groupCon.waitingGroups.get(group).getA();
long issueTime = groupCon.waitingGroups.get(group).getB();
long remaining = issueTime + pausetime - Time.getCurrentTime();
System.out.println(Time.getFormattedTime(remaining) + " remaining of " + group);
return remaining;
return issueTime + pausetime - Time.getCurrentTime();
}
}
......
......@@ -231,7 +231,17 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
else {
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() {
@Override
public void eventOccurred(Object content, int type) {
......
......@@ -510,7 +510,7 @@ public class VisualizationTopologyView extends JFrame
return plottingViews.get(name);
}
protected static void notifyInteractionListenersOnClick(long hostid,
public static void notifyInteractionListenersOnClick(long hostid,
boolean isActive) {
for (NodeVisInteractionListener listener : VisualizationInjector.interactionListeners) {
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