Commit 5a4723c7 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

Refactoring due to Location/Attraction API changes

- removed obsolete and duplicate modular movement classes (check your
config-files, you might need to replace "modular" with "modularosm" in
some cases
parent 0d0f5448
...@@ -22,6 +22,8 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction; ...@@ -22,6 +22,8 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List; import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/** /**
* This is the interface for the generator of the {@link AttractionPoint}s. It * This is the interface for the generator of the {@link AttractionPoint}s. It
* gets the set number of AttractionPoints back. This mean, it will be generate * gets the set number of AttractionPoints back. This mean, it will be generate
......
...@@ -35,6 +35,7 @@ import de.tud.kom.p2psim.api.topology.Topology; ...@@ -35,6 +35,7 @@ import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/** /**
* Generates attraction points out of real data from osm * Generates attraction points out of real data from osm
...@@ -110,7 +111,7 @@ public class JSONAttractionGenerator implements IAttractionGenerator { ...@@ -110,7 +111,7 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
double lat = allPOI.getJSONObject(i).getDouble("lat"); double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon"); double lon = allPOI.getJSONObject(i).getDouble("lon");
if(lat > latLeft && lat < latRight && if(lat > latLeft && lat < latRight &&
lon > lonLeft && lon < lonRight) attractionPoints.add(new AttractionPoint(transformGPSWindowToOwnWorld(lat, lon), barname)); lon > lonLeft && lon < lonRight) attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
} }
catch (JSONException e) { catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad //This bar had no name defined, so there was an error. Not so bad
......
...@@ -40,6 +40,7 @@ import de.tud.kom.p2psim.api.topology.Topology; ...@@ -40,6 +40,7 @@ import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/** /**
* Generates attraction points out of real data from osm * Generates attraction points out of real data from osm
...@@ -136,7 +137,7 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator { ...@@ -136,7 +137,7 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
double lon = allPOI.getJSONObject(i).getDouble("lon"); double lon = allPOI.getJSONObject(i).getDouble("lon");
if(lat > latLeft && lat < latRight && if(lat > latLeft && lat < latRight &&
lon > lonLeft && lon < lonRight) { lon > lonLeft && lon < lonRight) {
attractionPoints.add(new AttractionPoint(transformGPSWindowToOwnWorld(lat, lon), barname)); attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
} }
} }
catch (JSONException e) { catch (JSONException e) {
...@@ -169,7 +170,7 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator { ...@@ -169,7 +170,7 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name"); String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat"); double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon"); double lon = allPOI.getJSONObject(i).getDouble("lon");
attractionPoints.add(new AttractionPoint(transformGPSWindowToOwnWorld(lat, lon), barname)); attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
} }
catch (JSONException e) { catch (JSONException e) {
//This bar had no name defined, so there was an error. Not so bad //This bar had no name defined, so there was an error. Not so bad
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
*/ */
package de.tud.kom.p2psim.impl.topology.movement.modular.attraction; package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
...@@ -29,6 +29,8 @@ import de.tud.kom.p2psim.api.topology.Topology; ...@@ -29,6 +29,8 @@ import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
* Implementation of the interface {@link AttractionGenerator}. * Implementation of the interface {@link AttractionGenerator}.
...@@ -39,7 +41,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms; ...@@ -39,7 +41,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* @author Christoph Muenker * @author Christoph Muenker
* @version 1.0, 02.07.2013 * @version 1.0, 02.07.2013
*/ */
public class RandomAttractionGenerator implements AttractionGenerator { public class RandomAttractionGenerator implements IAttractionGenerator {
private Random rand; private Random rand;
...@@ -49,14 +51,17 @@ public class RandomAttractionGenerator implements AttractionGenerator { ...@@ -49,14 +51,17 @@ public class RandomAttractionGenerator implements AttractionGenerator {
private boolean numberOfAPsSet = false; private boolean numberOfAPsSet = false;
private double minSpeed = 2; @XMLConfigurableConstructor({"numberOfAttractionPoints"})
public RandomAttractionGenerator(int numberOfAttractionPoints) {
private double maxSpeed = 2;
public RandomAttractionGenerator() {
this.rand = Randoms.getRandom(RandomAttractionGenerator.class); this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
this.worldDimension = Binder.getComponentOrNull(Topology.class) this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions(); .getWorldDimensions();
if (numberOfAttractionPoints <= 0) {
throw new ConfigurationException(
"NumberOfAttractionPoints should be at least 1!");
}
this.numberOfAPsSet = true;
this.numberOfAttractionPoints = numberOfAttractionPoints;
} }
@Override @Override
...@@ -69,8 +74,7 @@ public class RandomAttractionGenerator implements AttractionGenerator { ...@@ -69,8 +74,7 @@ public class RandomAttractionGenerator implements AttractionGenerator {
List<AttractionPoint> result = new Vector<AttractionPoint>(); List<AttractionPoint> result = new Vector<AttractionPoint>();
for (int i = 0; i < numberOfAttractionPoints; i++) { for (int i = 0; i < numberOfAttractionPoints; i++) {
PositionVector posVec = createPosVec(); PositionVector posVec = createPosVec();
AttractionPoint aPoint = new AttractionPoint(posVec, minSpeed, AttractionPoint aPoint = new AttractionPointImpl("AP"+i,posVec);
maxSpeed);
result.add(aPoint); result.add(aPoint);
} }
return result; return result;
...@@ -82,15 +86,4 @@ public class RandomAttractionGenerator implements AttractionGenerator { ...@@ -82,15 +86,4 @@ public class RandomAttractionGenerator implements AttractionGenerator {
return new PositionVector(x, y); return new PositionVector(x, y);
} }
@Override
public void setNumberOfAttractionPoints(int numberOfAttractionPoints) {
if (numberOfAttractionPoints <= 0) {
throw new ConfigurationException(
"NumberOfAttractionPoints should be at least 1!");
}
this.numberOfAPsSet = true;
this.numberOfAttractionPoints = numberOfAttractionPoints;
}
} }
...@@ -23,9 +23,16 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization; ...@@ -23,9 +23,16 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
public interface IMapVisualization{ import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent;
public interface IMapVisualization extends VisualizationComponent {
public void paint(Graphics g); public void paint(Graphics g);
@Override
default int getPriority() {
return -10;
}
/** /**
* Retreives the current map as image. * Retreives the current map as image.
......
...@@ -35,6 +35,7 @@ import java.io.OutputStream; ...@@ -35,6 +35,7 @@ import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JMenu;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
...@@ -130,4 +131,24 @@ public class ShowGoogleMapsMapViz extends JComponent implements IMapVisualizatio ...@@ -130,4 +131,24 @@ public class ShowGoogleMapsMapViz extends JComponent implements IMapVisualizatio
g.dispose(); g.dispose();
return resizedImage; return resizedImage;
} }
@Override
public String getDisplayName() {
return "Google Map";
}
@Override
public JComponent getComponent() {
return this;
}
@Override
public JMenu getCustomMenu() {
return null;
}
@Override
public boolean isHidden() {
return false;
}
} }
...@@ -36,6 +36,7 @@ import java.io.OutputStream; ...@@ -36,6 +36,7 @@ import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JMenu;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
...@@ -190,4 +191,24 @@ public class ShowMapQuestMapViz extends JComponent ...@@ -190,4 +191,24 @@ public class ShowMapQuestMapViz extends JComponent
} }
return storedImage; return storedImage;
} }
@Override
public String getDisplayName() {
return "MapQuest Map";
}
@Override
public JComponent getComponent() {
return this;
}
@Override
public JMenu getCustomMenu() {
return null;
}
@Override
public boolean isHidden() {
return false;
}
} }
...@@ -29,9 +29,8 @@ import java.util.Map; ...@@ -29,9 +29,8 @@ import java.util.Map;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent; import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel; import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/** /**
* A {@link TransitionStrategy} for a case in which nodes are affiliated to an {@link AttractionPoint} only * A {@link TransitionStrategy} for a case in which nodes are affiliated to an {@link AttractionPoint} only
......
...@@ -24,7 +24,7 @@ import java.util.List; ...@@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/** /**
* This is the interface for the Transition Strategy.<br> * This is the interface for the Transition Strategy.<br>
......
...@@ -41,19 +41,18 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; ...@@ -41,19 +41,18 @@ import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.social.SocialView; import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/** /**
* This is a {@link TransitionStrategy} for the Social Case. It will be try to * This is a {@link TransitionStrategy} for the Social Case. It will be try to
* build groups based on the {@link SocialView} information. For this, it tries * build groups based on the {@link SocialView} information. For this, it tries
* to assignment the given objects to the given * to assignment the given objects to the given {@link AttractionPoint}s. For
* {@link AttractionPoint}s. For the {@link SocialView}, it is required a * the {@link SocialView}, it is required a {@link #socialId}, to find the right
* {@link #socialId}, to find the right {@link SocialView}. * {@link SocialView}.
* *
* <br> * <br>
* *
...@@ -65,8 +64,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms; ...@@ -65,8 +64,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* {@link AttractionPoint}. For that, it will be used only the AttractionPoints, * {@link AttractionPoint}. For that, it will be used only the AttractionPoints,
* of the hosts, which are in the same SocialCluster or are SocialNeighbors. For * of the hosts, which are in the same SocialCluster or are SocialNeighbors. For
* this AttractionPoints it will be find the highest scoring, which is to found * this AttractionPoints it will be find the highest scoring, which is to found
* in score. * in score. .
* .
* *
* <br> * <br>
* *
...@@ -79,8 +77,8 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms; ...@@ -79,8 +77,8 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* @author Christoph Muenker * @author Christoph Muenker
* @version 1.0, 02.07.2013 * @version 1.0, 02.07.2013
*/ */
public class SocialTransitionStrategy implements ITransitionStrategy, public class SocialTransitionStrategy
EventHandler { implements ITransitionStrategy, EventHandler {
private String socialId = null; private String socialId = null;
...@@ -91,7 +89,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -91,7 +89,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private List<AttractionPoint> aPoints = new Vector<AttractionPoint>(); private List<AttractionPoint> aPoints = new Vector<AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<SimLocationActuator, AttractionPoint>(); private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<SimLocationActuator, AttractionPoint>();
private Set<SimLocationActuator> arrivedAtAttractionPoint = new LinkedHashSet<>(); private Set<SimLocationActuator> arrivedAtAttractionPoint = new LinkedHashSet<>();
private Map<SimLocationActuator, Set<AttractionPoint>> favoritePlaces = new HashMap<SimLocationActuator, Set<AttractionPoint>>(); private Map<SimLocationActuator, Set<AttractionPoint>> favoritePlaces = new HashMap<SimLocationActuator, Set<AttractionPoint>>();
...@@ -160,7 +158,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -160,7 +158,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
init(); init();
aPoints.addAll(attractionPoints); aPoints.addAll(attractionPoints);
} }
@Override @Override
public List<AttractionPoint> getAllAttractionPoints() { public List<AttractionPoint> getAllAttractionPoints() {
return aPoints; return aPoints;
...@@ -176,9 +174,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -176,9 +174,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
// assignment.. // assignment..
AttractionPoint nearest = aPoints.iterator().next(); AttractionPoint nearest = aPoints.iterator().next();
for (AttractionPoint aPoint : aPoints) { for (AttractionPoint aPoint : aPoints) {
if (nearest.getRealPosition() if (nearest.distanceTo(ms.getRealPosition()) > aPoint
.distanceTo(ms.getRealPosition()) > aPoint.getRealPosition() .distanceTo(ms.getRealPosition())) {
.distanceTo(ms.getRealPosition())) {
nearest = aPoint; nearest = aPoint;
} }
} }
...@@ -188,14 +185,14 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -188,14 +185,14 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
doTransition(ms); doTransition(ms);
} }
@Override @Override
public void updateTargetAttractionPoint(SimLocationActuator comp, public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint) { AttractionPoint attractionPoint) {
arrivedAtAttractionPoint.remove(comp); arrivedAtAttractionPoint.remove(comp);
assignments.put(comp, attractionPoint); assignments.put(comp, attractionPoint);
} }
@Override @Override
public void reachedAttractionPoint(SimLocationActuator ms) { public void reachedAttractionPoint(SimLocationActuator ms) {
if (!arrivedAtAttractionPoint.contains(ms)) { if (!arrivedAtAttractionPoint.contains(ms)) {
...@@ -269,7 +266,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -269,7 +266,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private double score(SimLocationActuator ms, AttractionPoint ap, private double score(SimLocationActuator ms, AttractionPoint ap,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends, List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) { List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) {
double distance = ms.getRealPosition().distanceTo(ap.getRealPosition()); double distance = ms.getRealPosition().distanceTo(ap);
double distanceScore = 1 - (distance / worldDimension.getLength()); double distanceScore = 1 - (distance / worldDimension.getLength());
double clusterScore = 0; double clusterScore = 0;
...@@ -296,8 +293,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -296,8 +293,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
penalty = -1; penalty = -1;
} }
return (clusterScore / assignedToAp(ap) + friendsScore + 1.0 / assignedToAp(ap)) return (clusterScore / assignedToAp(ap) + friendsScore
* socialFactor + 1.0 / assignedToAp(ap)) * socialFactor
+ (distanceScore + penalty) * (1 - socialFactor); + (distanceScore + penalty) * (1 - socialFactor);
} }
...@@ -392,7 +389,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy, ...@@ -392,7 +389,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
} }
protected long getPauseTime() { protected long getPauseTime() {
return (long) ((rand.nextDouble() * (maxPauseTime - minPauseTime)) + minPauseTime); return (long) ((rand.nextDouble() * (maxPauseTime - minPauseTime))
+ minPauseTime);
} }
public void setMinPauseTime(long minPauseTime) { public void setMinPauseTime(long minPauseTime) {
......
...@@ -299,6 +299,7 @@ public class ComponentVisManager { ...@@ -299,6 +299,7 @@ public class ComponentVisManager {
this.activeByDefault = !comp.isHidden(); this.activeByDefault = !comp.isHidden();
this.showInList = true; this.showInList = true;
this.components.add(comp.getComponent()); this.components.add(comp.getComponent());
this.priority = comp.getPriority();
} }
public String getName() { public String getName() {
......
...@@ -61,4 +61,13 @@ public interface VisualizationComponent { ...@@ -61,4 +61,13 @@ public interface VisualizationComponent {
*/ */
public boolean isHidden(); public boolean isHidden();
/**
* Layer
*
* @return
*/
default public int getPriority() {
return 1;
}
} }
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