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;
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
* 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;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
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
......@@ -110,7 +111,7 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
double lat = allPOI.getJSONObject(i).getDouble("lat");
double lon = allPOI.getJSONObject(i).getDouble("lon");
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) {
//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;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
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
......@@ -136,7 +137,7 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
double lon = allPOI.getJSONObject(i).getDouble("lon");
if(lat > latLeft && lat < latRight &&
lon > lonLeft && lon < lonRight) {
attractionPoints.add(new AttractionPoint(transformGPSWindowToOwnWorld(lat, lon), barname));
attractionPoints.add(new AttractionPointImpl(barname, transformGPSWindowToOwnWorld(lat, lon)));
}
}
catch (JSONException e) {
......@@ -169,7 +170,7 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
String barname = allPOI.getJSONObject(i).getJSONObject("tags").getString("name");
double lat = allPOI.getJSONObject(i).getDouble("lat");
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) {
//This bar had no name defined, so there was an error. Not so bad
......
......@@ -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.Random;
......@@ -29,6 +29,8 @@ import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder;
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}.
......@@ -39,7 +41,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* @author Christoph Muenker
* @version 1.0, 02.07.2013
*/
public class RandomAttractionGenerator implements AttractionGenerator {
public class RandomAttractionGenerator implements IAttractionGenerator {
private Random rand;
......@@ -49,14 +51,17 @@ public class RandomAttractionGenerator implements AttractionGenerator {
private boolean numberOfAPsSet = false;
private double minSpeed = 2;
private double maxSpeed = 2;
public RandomAttractionGenerator() {
@XMLConfigurableConstructor({"numberOfAttractionPoints"})
public RandomAttractionGenerator(int numberOfAttractionPoints) {
this.rand = Randoms.getRandom(RandomAttractionGenerator.class);
this.worldDimension = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
if (numberOfAttractionPoints <= 0) {
throw new ConfigurationException(
"NumberOfAttractionPoints should be at least 1!");
}
this.numberOfAPsSet = true;
this.numberOfAttractionPoints = numberOfAttractionPoints;
}
@Override
......@@ -69,8 +74,7 @@ public class RandomAttractionGenerator implements AttractionGenerator {
List<AttractionPoint> result = new Vector<AttractionPoint>();
for (int i = 0; i < numberOfAttractionPoints; i++) {
PositionVector posVec = createPosVec();
AttractionPoint aPoint = new AttractionPoint(posVec, minSpeed,
maxSpeed);
AttractionPoint aPoint = new AttractionPointImpl("AP"+i,posVec);
result.add(aPoint);
}
return result;
......@@ -82,15 +86,4 @@ public class RandomAttractionGenerator implements AttractionGenerator {
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;
import java.awt.Graphics;
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);
@Override
default int getPriority() {
return -10;
}
/**
* Retreives the current map as image.
......
......@@ -35,6 +35,7 @@ import java.io.OutputStream;
import java.net.URL;
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.views.VisualizationTopologyView.VisualizationInjector;
......@@ -130,4 +131,24 @@ public class ShowGoogleMapsMapViz extends JComponent implements IMapVisualizatio
g.dispose();
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;
import java.net.URL;
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.views.VisualizationTopologyView.VisualizationInjector;
......@@ -190,4 +191,24 @@ public class ShowMapQuestMapViz extends JComponent
}
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;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent;
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.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
......
......@@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map;
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>
......
......@@ -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.impl.simengine.Simulator;
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.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
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
* build groups based on the {@link SocialView} information. For this, it tries
* to assignment the given objects to the given
* {@link AttractionPoint}s. For the {@link SocialView}, it is required a
* {@link #socialId}, to find the right {@link SocialView}.
* to assignment the given objects to the given {@link AttractionPoint}s. For
* the {@link SocialView}, it is required a {@link #socialId}, to find the right
* {@link SocialView}.
*
* <br>
*
......@@ -65,8 +64,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* {@link AttractionPoint}. For that, it will be used only the AttractionPoints,
* 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
* in score.
* .
* in score. .
*
* <br>
*
......@@ -79,8 +77,8 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* @author Christoph Muenker
* @version 1.0, 02.07.2013
*/
public class SocialTransitionStrategy implements ITransitionStrategy,
EventHandler {
public class SocialTransitionStrategy
implements ITransitionStrategy, EventHandler {
private String socialId = null;
......@@ -91,7 +89,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private List<AttractionPoint> aPoints = new Vector<AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<SimLocationActuator, AttractionPoint>();
private Set<SimLocationActuator> arrivedAtAttractionPoint = new LinkedHashSet<>();
private Map<SimLocationActuator, Set<AttractionPoint>> favoritePlaces = new HashMap<SimLocationActuator, Set<AttractionPoint>>();
......@@ -160,7 +158,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
init();
aPoints.addAll(attractionPoints);
}
@Override
public List<AttractionPoint> getAllAttractionPoints() {
return aPoints;
......@@ -176,9 +174,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
// assignment..
AttractionPoint nearest = aPoints.iterator().next();
for (AttractionPoint aPoint : aPoints) {
if (nearest.getRealPosition()
.distanceTo(ms.getRealPosition()) > aPoint.getRealPosition()
.distanceTo(ms.getRealPosition())) {
if (nearest.distanceTo(ms.getRealPosition()) > aPoint
.distanceTo(ms.getRealPosition())) {
nearest = aPoint;
}
}
......@@ -188,14 +185,14 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
doTransition(ms);
}
@Override
public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint) {
arrivedAtAttractionPoint.remove(comp);
assignments.put(comp, attractionPoint);
}
@Override
public void reachedAttractionPoint(SimLocationActuator ms) {
if (!arrivedAtAttractionPoint.contains(ms)) {
......@@ -269,7 +266,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private double score(SimLocationActuator ms, AttractionPoint ap,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
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 clusterScore = 0;
......@@ -296,8 +293,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
penalty = -1;
}
return (clusterScore / assignedToAp(ap) + friendsScore + 1.0 / assignedToAp(ap))
* socialFactor
return (clusterScore / assignedToAp(ap) + friendsScore
+ 1.0 / assignedToAp(ap)) * socialFactor
+ (distanceScore + penalty) * (1 - socialFactor);
}
......@@ -392,7 +389,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
}
protected long getPauseTime() {
return (long) ((rand.nextDouble() * (maxPauseTime - minPauseTime)) + minPauseTime);
return (long) ((rand.nextDouble() * (maxPauseTime - minPauseTime))
+ minPauseTime);
}
public void setMinPauseTime(long minPauseTime) {
......
......@@ -299,6 +299,7 @@ public class ComponentVisManager {
this.activeByDefault = !comp.isHidden();
this.showInList = true;
this.components.add(comp.getComponent());
this.priority = comp.getPriority();
}
public String getName() {
......
......@@ -61,4 +61,13 @@ public interface VisualizationComponent {
*/
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