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
5a7c6b8c
Commit
5a7c6b8c
authored
Mar 04, 2020
by
Julian Zobel
Browse files
Checks for GPS and x/y coordinates to check if within the simulation boundaries.
parent
a18638c5
Changes
20
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/DefaultTopology.java
View file @
5a7c6b8c
...
...
@@ -32,10 +32,8 @@ import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import
de.tud.kom.p2psim.api.topology.social.SocialView
;
import
de.tud.kom.p2psim.api.topology.views.TopologyView
;
import
de.tud.kom.p2psim.api.topology.waypoints.WaypointModel
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector
;
import
de.tud.kom.p2psim.impl.topology.views.visualization.world.SocialViewComponentVis
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* Very basic Topology
...
...
@@ -59,7 +57,7 @@ public class DefaultTopology implements Topology {
private
List
<
SocialView
>
socialViews
;
private
PositionVector
worldDimensions
;
private
static
PositionVector
worldDimensions
;
private
boolean
initializedSocial
=
false
;
...
...
@@ -186,5 +184,20 @@ public class DefaultTopology implements Topology {
}
}
public
static
boolean
isWithinWorldBoundaries
(
double
x
,
double
y
)
{
if
(
x
>=
0
&&
y
>=
0
&&
x
<=
worldDimensions
.
getX
()
&&
y
<=
worldDimensions
.
getY
())
{
return
true
;
}
else
{
return
false
;
}
}
public
static
boolean
isWithinWorldBoundaries
(
Location
location
)
{
return
isWithinWorldBoundaries
(
location
.
getLongitudeOrX
(),
location
.
getLatitudeOrY
());
}
}
src/de/tud/kom/p2psim/impl/topology/movement/SmarterMovementModelNew.java
View file @
5a7c6b8c
...
...
@@ -27,7 +27,6 @@ import java.util.Set;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization
;
import
de.tud.kom.p2psim.impl.topology.movement.smarter.dataanalyzer.Analyzer
;
import
de.tud.kom.p2psim.impl.topology.movement.smarter.dataanalyzer.Statistics
;
import
de.tud.kom.p2psim.impl.topology.movement.smarter.host.SmarterHost
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
...
...
@@ -68,9 +67,7 @@ public class SmarterMovementModelNew implements MovementModel, EventHandler {
}
private
void
initialize
()
{
// TODO get bool from xml to decide whether to analyze data or not
if
(!
dataAnalyzed
)
analyzeData
();
if
(
mapVisualization
!=
null
)
{
VisualizationInjector
.
injectComponent
(
mapVisualization
);
...
...
@@ -85,29 +82,7 @@ public class SmarterMovementModelNew implements MovementModel, EventHandler {
return
movement
;
}
/**
* Calculates statistics of the If files and stores them within a line for each host with the following format:
* id;distance;avgSpeed;idleTime;movingTime;phoneOutTime
*/
private
void
analyzeData
()
{
// Check if If files have been created in previous simulations. If not, create them.
if
(!
filesAlreadyExist
())
{
// System.out.println("FILES DO NOT EXIST, CREATE NEW FILES.");
Analyzer
analyzer
=
new
Analyzer
();
analyzer
.
analyzeTraces
();
}
else
// System.out.println("FILES ALREADY EXIST, SKIP FILE CREATION STEP.");
// Calculate statistics using the If files.
Statistics
.
clearFile
();
for
(
int
index
=
1
;
index
<=
125
;
index
++)
{
String
filePath
=
"smarter/traces-mv/mobilityTraceFile-File-Modified-"
+
index
+
".if"
;
Statistics
stats
=
new
Statistics
(
filePath
);
stats
.
calcStatistics
();
}
dataAnalyzed
=
true
;
}
/**
* Checks if all 94 If files have already been created.
* @return true if files have been created, else false
...
...
src/de/tud/kom/p2psim/impl/topology/movement/TracefileMovementModel.java
View file @
5a7c6b8c
...
...
@@ -26,10 +26,14 @@ import java.util.LinkedHashMap;
import
java.util.LinkedList
;
import
java.util.Scanner
;
import
de.tud.kom.p2psim.api.network.SimNetInterface
;
import
de.tud.kom.p2psim.api.network.SimNetworkComponent
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.DefaultTopology
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.IAttractionBasedMovementAnalyzer
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointViz
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
...
...
@@ -43,13 +47,17 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
public
static
String
tracefileFolder
=
"smarter/tracefiles/"
;
public
static
String
tracefilePrefix
=
"smarterTraceFile-"
;
public
static
long
GPS_MISSING_TRACE_THRESHOLD
=
120
;
protected
final
int
EVENT_MOVE
=
1
;
protected
final
PositionVector
DEFAULT_POSITION
=
new
PositionVector
(-
1000
,
-
1000
);
protected
long
timeBetweenMoveOperations
;
protected
IMapVisualization
mapVisualization
;
protected
IAttractionGenerator
attractionGenerator
;
protected
AttractionPointViz
attractionpointVisualization
;
protected
boolean
initialized
=
false
;
...
...
@@ -83,6 +91,10 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
VisualizationInjector
.
injectComponent
(
mapVisualization
);
}
if
(
attractionpointVisualization
!=
null
)
{
VisualizationInjector
.
injectComponent
(
attractionpointVisualization
);
}
initialized
=
true
;
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
,
this
,
null
,
EVENT_MOVE
);
...
...
@@ -99,10 +111,9 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
if
(
first
)
{
components
.
forEach
((
component
,
steps
)
->
{
component
.
updateCurrentLocation
(
new
PositionVector
(-
1
,
-
1
));
shutdownComponent
(
component
);
});
}
}
// as the files contain the timestamp in seconds, the current time needs to be converted in seconds
long
currentTime
=
Time
.
getCurrentTime
()
/
Time
.
SECOND
;
...
...
@@ -115,30 +126,46 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
if
(
step
!=
null
)
{
if
(
currentTime
<
step
.
timestamp
)
{
//component.updateCurrentLocation(new PositionVector(-1, -1));
if
(
DefaultTopology
.
isWithinWorldBoundaries
(
component
.
getRealPosition
()))
{
if
(
currentTime
+
GPS_MISSING_TRACE_THRESHOLD
>=
step
.
timestamp
)
{
if
(
component
.
getRealPosition
().
distanceTo
(
new
PositionVector
(
step
.
x
,
step
.
y
))
>
GPS_MISSING_TRACE_THRESHOLD
*
2
)
{
shutdownComponent
(
component
);
}
// do nothing for smoothing?
}
else
{
if
(
DefaultTopology
.
isWithinWorldBoundaries
(
component
.
getRealPosition
()))
{
shutdownComponent
(
component
);
}
}
}
}
else
{
else
{
if
(!
DefaultTopology
.
isWithinWorldBoundaries
(
component
.
getRealPosition
()))
{
startupComponent
(
component
);
}
step
=
steps
.
pop
();
component
.
updateCurrentLocation
(
new
PositionVector
(
step
.
x
,
step
.
y
));
}
}
else
{
System
.
out
.
println
(
"Component "
+
component
.
getHost
().
getId
()+
" left the area at "
+
Time
.
getFormattedTime
());
component
.
updateCurrentLocation
(
new
PositionVector
(-
1
,
-
1
));
else
{
toRemove
.
add
(
component
);
}
});
for
(
SimLocationActuator
simLocationActuator
:
toRemove
)
{
components
.
remove
(
simLocationActuator
);
shutdownComponent
(
simLocationActuator
);
}
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
,
this
,
null
,
EVENT_MOVE
);
if
(
first
)
{
System
.
out
.
println
(
"first with "
+
components
.
keySet
().
size
()
+
" hosts"
);
// Inform analyzer of resolved movement
if
(
Monitor
.
hasAnalyzer
(
IAttractionBasedMovementAnalyzer
.
class
))
{
Monitor
.
getOrNull
(
IAttractionBasedMovementAnalyzer
.
class
).
onAllNodeInitializationCompleted
(
components
.
keySet
());
...
...
@@ -148,6 +175,28 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
}
}
private
void
shutdownComponent
(
SimLocationActuator
node
)
{
node
.
updateCurrentLocation
(
new
PositionVector
(
DEFAULT_POSITION
));
SimNetworkComponent
net
=
(
SimNetworkComponent
)
node
.
getHost
().
getNetworkComponent
();
for
(
SimNetInterface
netI
:
net
.
getSimNetworkInterfaces
())
{
if
(
netI
.
isOnline
())
{
netI
.
goOffline
();
}
}
}
private
void
startupComponent
(
SimLocationActuator
node
)
{
SimNetworkComponent
net
=
(
SimNetworkComponent
)
node
.
getHost
().
getNetworkComponent
();
for
(
SimNetInterface
netI
:
net
.
getSimNetworkInterfaces
())
{
if
(
netI
.
isOffline
())
{
netI
.
goOnline
();
}
}
}
@Override
public
void
addComponent
(
SimLocationActuator
actuator
)
{
if
(!
initialized
)
{
...
...
@@ -204,7 +253,7 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
@Override
public
void
placeComponent
(
SimLocationActuator
actuator
)
{
// Initial placement
actuator
.
updateCurrentLocation
(
new
PositionVector
(
-
1
,
-
1
));
actuator
.
updateCurrentLocation
(
new
PositionVector
(
DEFAULT_POSITION
));
}
@Override
...
...
@@ -216,6 +265,10 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
this
.
mapVisualization
=
mapVisualization
;
}
public
void
setAttractionPointViz
(
AttractionPointViz
viz
)
{
this
.
attractionpointVisualization
=
viz
;
}
public
void
setIAttractionGenerator
(
IAttractionGenerator
attractionGenerator
)
{
if
(
attractionGenerator
==
null
)
{
throw
new
ConfigurationException
(
...
...
@@ -238,6 +291,11 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
this
.
y
=
y
;
this
.
timestamp
=
timestamp
;
}
@Override
public
String
toString
()
{
return
"Step @ "
+
timestamp
+
"s -> ("
+
x
+
", "
+
y
+
")"
;
}
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/GPSCalculation.java
View file @
5a7c6b8c
...
...
@@ -150,15 +150,21 @@ public class GPSCalculation {
return
new
PositionVector
(
x
,
y
);
}
public
static
boolean
isWithinSimulationBoundaries
(
double
lat
,
double
lon
)
{
/**
* Checks if the given latitute and longitude is within the simulated GPS area.
*
* @param lat
* @param lon
* @return True if within the GPS area, false otherwise.
*/
public
static
boolean
isWithinGPSBoundaries
(
double
lat
,
double
lon
)
{
if
(
lat
>
getLatLower
()
&&
lat
<
getLatUpper
()
&&
lon
>
getLonLeft
()
&&
lon
<
getLonRight
())
{
return
true
;
}
else
return
false
;
}
/**
* Formula http://wiki.openstreetmap.org/wiki/Zoom_levels
*
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java
View file @
5a7c6b8c
...
...
@@ -36,6 +36,7 @@ import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import
de.tud.kom.p2psim.api.topology.placement.PlacementModel
;
import
de.tud.kom.p2psim.impl.simengine.Simulator
;
import
de.tud.kom.p2psim.impl.topology.TopologyFactory
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointViz
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.mapvisualization.IMapVisualization
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.IAttractionAssigmentStrategy
;
...
...
@@ -109,6 +110,8 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
protected
IMapVisualization
mapVisualization
;
protected
ModularMovementModelViz
modelVisualisation
;
protected
AttractionPointViz
attractionPointViz
;
protected
Set
<
SimLocationActuator
>
moveableHosts
=
new
LinkedHashSet
<
SimLocationActuator
>();
...
...
@@ -145,6 +148,10 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
if
(
mapVisualization
!=
null
)
{
VisualizationInjector
.
injectComponent
(
mapVisualization
);
}
if
(
attractionPointViz
!=
null
)
{
System
.
out
.
println
(
"insert AP viz"
);
VisualizationInjector
.
injectComponent
(
attractionPointViz
);
}
checkConfiguration
();
...
...
@@ -388,4 +395,8 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
public
List
<
IAttractionPoint
>
getAttractionPoints
()
{
return
new
Vector
<
IAttractionPoint
>(
IAttractionGenerator
.
attractionPoints
);
}
public
void
setAttractionPointViz
(
AttractionPointViz
viz
)
{
this
.
attractionPointViz
=
viz
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/SocialGroupMovementModel.java
View file @
5a7c6b8c
...
...
@@ -90,6 +90,10 @@ public class SocialGroupMovementModel extends ModularMovementModel {
if
(
mapVisualization
!=
null
)
{
VisualizationInjector
.
injectComponent
(
mapVisualization
);
}
if
(
attractionPointViz
!=
null
)
{
System
.
out
.
println
(
"insert AP viz"
);
VisualizationInjector
.
injectComponent
(
attractionPointViz
);
}
checkConfiguration
();
...
...
@@ -115,27 +119,25 @@ public class SocialGroupMovementModel extends ModularMovementModel {
IAttractionPoint
assignment
=
attractionAssigment
.
getAssignment
(
ms
);
double
apRadius
=
(
assignment
.
hasRadius
()
?
Math
.
max
(
assignment
.
getRadius
(),
25.0
)
:
25.0
);
ms
.
updateCurrentLocation
(
this
.
addGaussianOffsetToPosition
(
new
PositionVector
(
assignment
),
apRadius
/
3
));
ms
.
updateCurrentLocation
(
this
.
addGaussianOffsetToPosition
(
new
PositionVector
(
assignment
),
apRadius
/
3
));
attractionAssigment
.
updateTargetAttractionPoint
(
ms
,
assignment
);
}
}
setTimeBetweenMoveOperations
(
timeBetweenMoveOperation
);
// initial move
move
();
initialized
=
true
;
// Inform analyzer of resolved movement
if
(
Monitor
.
hasAnalyzer
(
IAttractionBasedMovementAnalyzer
.
class
))
{
Monitor
.
getOrNull
(
IAttractionBasedMovementAnalyzer
.
class
).
onAllNodeInitializationCompleted
(
moveableHosts
);
}
// initial move
move
();
initialized
=
true
;
}
}
/**
* Returns a random SimLocationActuator component from the set of moveable hosts.
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/AttractionPointImpl.java
View file @
5a7c6b8c
...
...
@@ -178,6 +178,6 @@ public class AttractionPointImpl extends BasicAttractionPoint {
@Override
public
String
toString
()
{
return
getName
();
return
getName
()
+
" ("
+
getX
()
+
", "
+
getY
()
+
")"
+
" <"
+
getRadius
()
+
"> "
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/AttractionPointViz.java
0 → 100644
View file @
5a7c6b8c
/*
* Copyright (c) 2005-2015 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction
;
import
java.awt.Color
;
import
java.awt.Composite
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.Point
;
import
java.awt.RenderingHints
;
import
java.util.LinkedList
;
import
javax.swing.JCheckBoxMenuItem
;
import
javax.swing.JComponent
;
import
javax.swing.JMenu
;
import
javax.swing.event.ChangeEvent
;
import
javax.swing.event.ChangeListener
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector
;
import
de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint
;
public
class
AttractionPointViz
extends
JComponent
implements
VisualizationComponent
{
protected
boolean
showAttractionPoints
=
true
;
private
JMenu
menu
;
private
final
static
int
ATTR_SIZE
=
5
;
private
static
Color
COLOR_ATTR_POINT
=
Color
.
decode
(
"#4A7B9D"
);
public
static
LinkedList
<
LinkedList
<
SimHost
>>
clusters
=
new
LinkedList
<
LinkedList
<
SimHost
>>();
public
static
LinkedList
<
Color
>
colors
=
new
LinkedList
<
Color
>();
public
AttractionPointViz
()
{
init
();
}
protected
void
init
()
{
setBounds
(
0
,
0
,
VisualizationInjector
.
getWorldX
(),
VisualizationInjector
.
getWorldY
());
setOpaque
(
true
);
setVisible
(
true
);
menu
=
new
JMenu
(
"Attraction Points"
);
menu
.
add
(
createCheckboxAp
());
}
private
JCheckBoxMenuItem
createCheckboxAp
()
{
final
JCheckBoxMenuItem
checkBox
=
new
JCheckBoxMenuItem
(
"show attraction points"
,
showAttractionPoints
);
checkBox
.
addChangeListener
(
new
ChangeListener
()
{
@Override
public
void
stateChanged
(
ChangeEvent
e
)
{
showAttractionPoints
=
checkBox
.
isSelected
();
VisualizationInjector
.
invalidate
();
}
});
return
checkBox
;
}
@Override
public
void
paint
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
Graphics2D
g2
=
(
Graphics2D
)
g
;
g2
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
if
(
showAttractionPoints
)
{
drawAttractionPoints
(
g2
);
}
}
/**
* Provides access super.paintComponent() for extending classes.
* @param g the Graphics object for painting.
*/
protected
void
paintSuper
(
Graphics
g
)
{
super
.
paintComponent
(
g
);
}
protected
void
drawClusters
(
Graphics2D
g2
)
{
// Composite gc = g2.getComposite();
if
(
colors
.
isEmpty
())
{
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
colors
.
add
(
new
Color
(
new
java
.
util
.
Random
().
nextInt
()));
}
}
for
(
LinkedList
<
SimHost
>
group
:
clusters
)
{
g2
.
setColor
(
colors
.
get
(
clusters
.
indexOf
(
group
)));
for
(
SimHost
member
:
group
)
{
PositionVector
p
=
member
.
getTopologyComponent
().
getRealPosition
();
g2
.
fillOval
(
VisualizationInjector
.
scaleValue
(
p
.
getX
())
-
10
,
VisualizationInjector
.
scaleValue
(
p
.
getY
())
-
10
,
20
,
20
);
}
}
}
/**
* Draws the attraction points. This method has been extracted from paint()
* to make it possible for extending class to override only this bit while leaving everything
* else untouched.
* @param g2 the Graphics2D object for painting.
*/
protected
void
drawAttractionPoints
(
Graphics2D
g2
)
{
Composite
gc
=
g2
.
getComposite
();
for
(
IAttractionPoint
aPoint
:
IAttractionGenerator
.
attractionPoints
)
{
Point
point
=
((
PositionVector
)
aPoint
).
asPoint
();
// draw border
g2
.
setColor
(
Color
.
BLACK
);
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_SIZE
);
// g2.setColor(COLOR_ATTR_POINT);
// float alpha = 0.25f + (float) (aPoint.getWeight() / 2);
// g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
// g2.fillOval(
// VisualizationInjector.scaleValue(point.x) - ATTR_PAD,
// 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_SIZE
;
g2
.
drawOval
(
VisualizationInjector
.
scaleValue
(
point
.
x
)
-
radius
,
VisualizationInjector
.
scaleValue
(
point
.
y
)
-
radius
,
radius
*
2
+
1
,
radius
*
2
+
1
);
g2
.
setComposite
(
gc
);
}
}
@Override
public
String
getDisplayName
()
{
return
"Attraction Points"
;
}
@Override
public
JComponent
getComponent
()
{
return
this
;
}
@Override
public
JMenu
getCustomMenu
()
{
return
menu
;
}
@Override
public
boolean
isHidden
()
{
return
false
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/JSONAttractionGenerator.java
View file @
5a7c6b8c
...
...
@@ -106,7 +106,7 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
AttractionPointImpl
ap
;
// check that the point is within the simulation boundaries
if
(
GPSCalculation
.
isWithin
Simulation
Boundaries
(
lat
,
lon
))
{
if
(
GPSCalculation
.
isWithin
GPS
Boundaries
(
lat
,
lon
))
{
// initialize the attraction point with basic information, will be filled now...
ap
=
new
AttractionPointImpl
(
barname
,
GPSCalculation
.
transformGPSWindowToOwnWorld
(
lat
,
lon
));
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/SocialMovementGroup.java
View file @
5a7c6b8c
...
...
@@ -33,8 +33,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* This class handles the instance of a group. Each group instance has a leader which sets the behavior. All other
* participants follow the behavior of the leader in terms of speed, velocity, heading etc.
*
* @author Marcel Verst
* @version 1.0, 22.11.2018
* @author Julian Zobel
*/
public
class
SocialMovementGroup
{
...
...
@@ -46,6 +45,22 @@ public class SocialMovementGroup {
private
PositionVector
destination
;
private
PositionVector
meetingPoint
;
/**
* Initializes the group with a given leader.
*
* @param SimLocationActuator New leader of the group
* @param int The ID of the group.
*/
public
SocialMovementGroup
(
SimLocationActuator
leader
)
{
this
.
groupID
=
UUID
.
randomUUID
();
this
.
leader
=
leader
;
this
.
members
=
new
LinkedHashSet
<
SimLocationActuator
>();
this
.
members
.
add
(
leader
);
}
/**
* Initializes the group, sets the participants and groupId, finally chooses a random leader.
*
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/AbstractGroupForming.java
View file @
5a7c6b8c
...
...
@@ -70,11 +70,14 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
protected
long
groupRejoinWaitTime
;
protected
long
groupFormationSetupDelay
;
private
long
groupFormationDelay
;
public
static
AbstractGroupForming
instance
;
@XMLConfigurableConstructor
({
"enableGroups"
,
"maxNumberOfGroups"
,
"minGroupSize"
,
"maxGroupSize"
,
"probabilityToJoin"
,
"groupFormationSetupDelay"
,
"groupFormationDelay"
,
"groupRejoinWaitTime"
})
public
AbstractGroupForming
(
boolean
enableGroups
,
int
maxNumberOfGroups
,
int
minGroupSize
,
int
maxGroupSize
,
double
probabilityToJoin
,
long
groupFormationSetupDelay
,
long
groupFormationDelay
,
long
groupRejoinWaitTime
)
{
instance
=
this
;
this
.
enableGroups
=
enableGroups
;
if
(
enableGroups
)
{
...
...
@@ -135,13 +138,31 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
stayDuration
.
put
(
host
.
getHost
().
getId
(),
new
Tuple
<
Long
,
Long
>(
0L
,
Time
.
getCurrentTime
()));
}
Event
.
scheduleWithDelay
(
groupFormationSetupDelay
,
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
triggerGroupFormation
();
for
(
int
g
=
0
;
g
<
20
;
g
++)
{
// FIXME random Gauß distribution?
long
std
=
(
long
)
(
4.3
*
Time
.
MINUTE
);
long
mean
=
(
long
)
(
7.38
*
Time
.
MINUTE
);
long
delay
=
(
long
)
(
rand
.
nextGaussian
()
*
std
+
mean
);
delay
=
(
long
)
((
rand
.
nextDouble
()
*
(
Time
.
MINUTE
*
45
)
+
Time
.
MINUTE
));
if
(
delay
<
Time
.
MINUTE
)
{
delay
=
Time
.
MINUTE
;
}
},
null
,
0
);
System
.
out
.
println
(
Time
.
getFormattedTime
(
delay
)
);
Event
.
scheduleWithDelay
(
delay
,
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
assembleGroup
();
}
},
null
,
0
);
}
}
/**
* Returns a time delay between removal and creation of a group. A random part of up to half of the
...
...
@@ -171,12 +192,15 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
protected
int
rndGroupSize
()
{
if
(
maxGroupSize
==
minGroupSize
)
return
minGroupSize
;
else
return
rand
.
nextInt
(
maxGroupSize
-
minGroupSize
)
+
minGroupSize
;
else
{
// int groupsize = (int) Math.max(1, rand.nextGaussian() * 0.93 + 2.76);
int
groupsize
=
rand
.
nextInt
(
5
)
+
1
;
System
.
out
.
println
(
groupsize
);
return
groupsize
;
}
//return rand.nextInt(maxGroupSize - minGroupSize) + minGroupSize;
}
protected
abstract
void
triggerGroupFormation
();
/**
* Creates a group with the given set of members.
*
...
...
@@ -263,6 +287,10 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
}
},
null
,
0
);
}
public
static
void
nodeready
()
{
instance
.
assembleGroup
();
}
protected
abstract
void
assembleGroup
();
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/DefaultGroupForming.java
View file @
5a7c6b8c
...
...
@@ -89,21 +89,9 @@ public class DefaultGroupForming extends AbstractGroupForming {
* === GROUP BUILDING PROCESS
* =====================================================================================================
*/
protected
void
triggerGroupFormation
()
{
updateStayDuration
();
int
groupsToCreate
=
maxNumberOfGroups
-
groupCon
.
getGroups
().
size
();
System
.
out
.
println
(
Time
.
getFormattedTime
()
+
" | group trigger "
+
groupsToCreate
);
for
(
int
g
=
0
;
g
<
groupsToCreate
;
g
++)
{
assembleGroup
();
}
}
@Override
protected
void
assembleGroup
()
{
protected
void
assembleGroup
()
{
IAttractionPoint
apCandidate
=
IAttractionGenerator
.
attractionPoints
.
get
(
rand
.
nextInt
(
IAttractionGenerator
.
attractionPoints
.
size
()));
if
(
apCandidate
==
null
)
{
return
;
...
...
@@ -122,6 +110,11 @@ public class DefaultGroupForming extends AbstractGroupForming {
for
(
SimLocationActuator
m
:
randomShuffledHostsAtAttractionPoint
)
{
// do not continue if enough group members are gathered
if
(
groupCandidates
.
size
()
==
groupSize
)
{
break
;
}
// skip already added hosts (should never happen)
if
(
groupCandidates
.
contains
(
m
))
{
continue
;
...
...
@@ -142,17 +135,11 @@ public class DefaultGroupForming extends AbstractGroupForming {
if
(!
beenInGroup
(
m
)
||
groupRejoinTimerExpired
(
m
))
{
groupCandidates
.
add
(
m
);
}
}
// do not continue if enough group members are gathered
if
(
groupCandidates
.
size
()
==
groupSize
)
{
break
;
}
}
}
// if there are no candidates, wait a minute until asking again
if
(
groupCandidates
.
isEmpty
()
||
groupCandidates
==
null
||
groupCandidates
.
size
()
<
minGroupSize
)
{
if
(
groupCandidates
.
isEmpty
()
||
groupCandidates
==
null
||
groupCandidates
.
size
()
<
minGroupSize
)
{
Event
.
scheduleWithDelay
(
Time
.
MINUTE
,
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
...
...
@@ -162,7 +149,7 @@ public class DefaultGroupForming extends AbstractGroupForming {
return
;
}
for
(
SimLocationActuator
candidate
:
groupCandidates
)
{
INodeID
id
=
candidate
.
getHost
().
getId
();
stayDuration
.
put
(
id
,
new
Tuple
<
Long
,
Long
>(
0L
,
Time
.
getCurrentTime
()));
// FIXME why?
...
...
@@ -237,9 +224,5 @@ public class DefaultGroupForming extends AbstractGroupForming {
}
}
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/IGroupFormingBehavior.java
View file @
5a7c6b8c
...
...
@@ -20,6 +20,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
;
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/AbstractAttractionBasedAssignmentStrategy.java
View file @
5a7c6b8c
...
...
@@ -31,6 +31,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.IAttractionBasedMovem
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint
;
/**
...
...
@@ -63,8 +64,13 @@ public abstract class AbstractAttractionBasedAssignmentStrategy implements IAttr
}
@Override
public
IAttractionPoint
getAssignment
(
SimLocationActuator
comp
)
{
return
assignments
.
get
(
comp
);
public
IAttractionPoint
getAssignment
(
SimLocationActuator
host
)
{
return
assignments
.
get
(
host
);
}
@Override
public
IAttractionPoint
getLastAssignment
(
SimLocationActuator
host
)
{
return
lastAssignments
.
get
(
host
);
}
@Override
...
...
@@ -117,7 +123,9 @@ public abstract class AbstractAttractionBasedAssignmentStrategy implements IAttr
}
public
long
getPauseTime
(
IAttractionPoint
attractionPoint
)
{
return
getRandomUniformDistributionPauseTime
(
attractionPoint
);
long
pause
=
getRandomUniformDistributionPauseTime
(
attractionPoint
);
//System.out.println(Time.getFormattedTime(pause));
return
pause
;
}
/**
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/AttractionPointRoamingStrategy.java
View file @
5a7c6b8c
...
...
@@ -81,19 +81,8 @@ public class AttractionPointRoamingStrategy extends AbstractAttractionBasedAssig
this
.
roamingStates
.
put
(
comp
,
roamingTransitionState
.
PAUSE
);
// schedule roaming
Event
.
scheduleWithDelay
(
Math
.
max
(
Time
.
MINUTE
,
gaussianDistributionPauseTime
(
5
*
Time
.
MINUTE
,
1
*
Time
.
MINUTE
)
),
this
,
comp
,
0
);
Event
.
scheduleWithDelay
(
getPauseTime
(
attractionPoint
),
this
,
comp
,
0
);
}
/**
* Use a gaussian distribution for the pause time interval generation, using a mean value and a standard deviation
*
* @return
*/
private
long
gaussianDistributionPauseTime
(
double
mean
,
double
std
)
{
double
x
=
rnd
.
nextGaussian
()
*
std
+
mean
;
if
(
x
<=
0
)
return
gaussianDistributionPauseTime
(
mean
,
std
*
0.9
);
return
(
long
)
x
;
}
private
void
roamAroundAttractionPoint
(
SimLocationActuator
comp
)
{
if
(
roamingStates
.
get
(
comp
)
==
roamingTransitionState
.
PAUSE
)
{
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/IAttractionAssigmentStrategy.java
View file @
5a7c6b8c
...
...
@@ -44,6 +44,8 @@ public interface IAttractionAssigmentStrategy {
*/
public
IAttractionPoint
getAssignment
(
SimLocationActuator
host
);
public
IAttractionPoint
getLastAssignment
(
SimLocationActuator
host
);
public
void
addAttractionAssignmentListener
(
AttractionAssignmentListener
listener
);
public
void
removeAttractionAssignmentListener
(
AttractionAssignmentListener
listener
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java
View file @
5a7c6b8c
...
...
@@ -124,7 +124,8 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedAssi
if
(
currentAttractionPoint
.
getRadius
()
>
0
)
{
this
.
roamingStates
.
put
(
comp
,
roamingTransitionState
.
ROAMING
);
notifyListenersOfAssignmentUpdate
(
comp
,
currentAttractionPoint
);
updateTargetAttractionPoint
(
comp
,
currentAttractionPoint
);
//notifyListenersOfAssignmentUpdate(comp, currentAttractionPoint);
}
}
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/smarter/DataConverter.java
View file @
5a7c6b8c
...
...
@@ -124,7 +124,7 @@ public class DataConverter {
double
lon
=
entry
.
getLongitude
();
// if the position in the database is within the simulated area, parse the position to a simulation position and save it
if
(
GPSCalculation
.
isWithin
Simulation
Boundaries
(
lat
,
lon
))
{
if
(
GPSCalculation
.
isWithin
GPS
Boundaries
(
lat
,
lon
))
{
PositionVector
p
=
GPSCalculation
.
transformGPSWindowToOwnWorld
(
lat
,
lon
);
if
(!
active
)
{
...
...
src/de/tud/kom/p2psim/impl/topology/views/visualization/ui/SimControlPanel.java
View file @
5a7c6b8c
...
...
@@ -167,7 +167,7 @@ public class SimControlPanel extends JMenuBar implements ActionListener, ChangeL
protected
JSlider
getSpeedSlider
()
{
if
(
speedslider
==
null
)
{
int
simskew
=
(
int
)
Simulator
.
getScheduler
().
getTimeSkew
()
+
4
;
int
simskew
=
(
(
int
)
Simulator
.
getScheduler
().
getTimeSkew
()
+
4
>
50
?
simskew
=
50
:
(
int
)
Simulator
.
getScheduler
().
getTimeSkew
()
+
4
)
;
speedslider
=
new
JSlider
(
SwingConstants
.
HORIZONTAL
,
1
,
50
,
simskew
);
speedslider
.
addChangeListener
(
this
);
}
...
...
src/de/tud/kom/p2psim/impl/util/oracle/GlobalOracle.java
View file @
5a7c6b8c
...
...
@@ -176,7 +176,7 @@ public class GlobalOracle implements OracleComponent {
/**
* @return the list with all hosts of the scenario
*/
public
static
List
<
SimHost
>
getHosts
(
String
groupID
)
{
public
static
List
<
SimHost
>
getHosts
ByGroupID
(
String
groupID
)
{
if
(
groupID
.
equals
(
""
))
{
return
getHosts
();
...
...
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