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
0c80da45
Commit
0c80da45
authored
Nov 06, 2015
by
Björn Richerzhagen
Browse files
Removed deprecated `Position`-Interface
parent
db566de9
Changes
64
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modular/ModularMovementModel.java
View file @
0c80da45
...
...
@@ -20,8 +20,6 @@
package
de.tud.kom.p2psim.impl.topology.movement.modular
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
...
...
@@ -32,13 +30,13 @@ import java.util.Set;
import
java.util.Vector
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.movement.MovementListener
;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.movement.MovementSupported
;
import
de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy
;
import
de.tud.kom.p2psim.impl.simengine.Simulator
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel
;
import
de.tud.kom.p2psim.impl.topology.movement.CsvMovement
;
import
de.tud.kom.p2psim.impl.topology.movement.NoMovement
;
...
...
@@ -49,6 +47,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modular.transition.FixedAssignme
import
de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector
;
import
de.tud.kom.p2psim.impl.util.Either
;
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
;
...
...
@@ -118,7 +117,8 @@ public class ModularMovementModel implements MovementModel, EventHandler {
private
Random
rand
;
public
ModularMovementModel
()
{
this
.
worldDimensions
=
Topology
.
getWorldDimension
();
this
.
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
this
.
rand
=
Randoms
.
getRandom
(
ModularMovementModel
.
class
);
// scheduling initalization!
...
...
@@ -146,14 +146,15 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
// setWayPointModel
localMovementStrategy
.
setObstacleModel
(
Topology
.
getTopology
()
.
getObstacleModel
());
localMovementStrategy
.
setWaypointModel
(
Topology
.
getTopology
()
.
getWaypointModel
());
localMovementStrategy
.
setObstacleModel
(
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getObstacleModel
());
localMovementStrategy
.
setWaypointModel
(
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWaypointModel
());
if
(
movementModel
instanceof
AbstractWaypointMovementModel
)
{
AbstractWaypointMovementModel
awmm
=
(
AbstractWaypointMovementModel
)
movementModel
;
awmm
.
setWaypointModel
(
Topology
.
getTopology
().
getWaypointModel
());
awmm
.
setWaypointModel
(
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWaypointModel
());
}
List
<
AttractionPoint
>
attractionPoints
=
attractionGenerator
...
...
@@ -194,7 +195,8 @@ public class ModularMovementModel implements MovementModel, EventHandler {
"AttractionGenerator is missing in ModularMovementModel!"
);
}
if
(
movementModel
instanceof
AbstractWaypointMovementModel
&&
Topology
.
getTopology
().
getWaypointModel
()
==
null
)
{
&&
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWaypointModel
()
==
null
)
{
throw
new
ConfigurationException
(
"Missing WaypointModel for the ModuloarMovementModel.movementModel"
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modular/attraction/CsvAttractionGenerator.java
View file @
0c80da45
...
...
@@ -26,8 +26,9 @@ import java.io.IOException;
import
java.util.LinkedList
;
import
java.util.List
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud
.kom.p2psim.impl.topology.Topology
;
import
de.tud
armstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
...
...
@@ -57,7 +58,8 @@ public class CsvAttractionGenerator implements AttractionGenerator {
*/
@XMLConfigurableConstructor
({
"placementFile"
})
public
CsvAttractionGenerator
(
String
placementFile
)
{
this
.
worldDimensions
=
Topology
.
getWorldDimension
();
this
.
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
attractionPointsPositions
=
new
LinkedList
<
PositionVector
>();
this
.
file
=
placementFile
;
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modular/attraction/RandomAttractionGenerator.java
View file @
0c80da45
...
...
@@ -25,8 +25,9 @@ import java.util.Random;
import
java.util.Vector
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud
.kom.p2psim.impl.topology.Topology
;
import
de.tud
armstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
/**
...
...
@@ -54,7 +55,8 @@ public class RandomAttractionGenerator implements AttractionGenerator {
public
RandomAttractionGenerator
()
{
this
.
rand
=
Randoms
.
getRandom
(
RandomAttractionGenerator
.
class
);
this
.
worldDimension
=
Topology
.
getWorldDimension
();
this
.
worldDimension
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
}
@Override
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modular/transition/SocialTransitionStrategy.java
View file @
0c80da45
...
...
@@ -36,12 +36,13 @@ import java.util.Vector;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.common.SimHostComponent
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.movement.MovementSupported
;
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.Topology
;
import
de.tud.kom.p2psim.impl.topology.movement.modular.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
;
...
...
@@ -121,7 +122,8 @@ public class SocialTransitionStrategy implements TransitionStrategy,
"SocialId is not set, to find the needed SocialView!"
);
}
socialView
=
Topology
.
getTopology
().
getSocialView
(
socialId
);
socialView
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getSocialView
(
socialId
);
if
(
socialView
==
null
)
{
throw
new
ConfigurationException
(
...
...
@@ -133,7 +135,8 @@ public class SocialTransitionStrategy implements TransitionStrategy,
"MinPauseTime should be smaller then maxPauseTime."
);
}
worldDimension
=
Topology
.
getWorldDimension
();
worldDimension
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
init
=
true
;
}
}
...
...
@@ -163,8 +166,9 @@ public class SocialTransitionStrategy implements TransitionStrategy,
// assignment..
AttractionPoint
nearest
=
aPoints
.
iterator
().
next
();
for
(
AttractionPoint
aPoint
:
aPoints
)
{
if
(
nearest
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
()))
{
if
(
nearest
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
()))
{
nearest
=
aPoint
;
}
}
...
...
@@ -242,7 +246,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
List
<
AttractionPoint
>
apFavorites
,
List
<
AttractionPoint
>
apFriends
,
List
<
AttractionPoint
>
apClusters
,
List
<
AttractionPoint
>
apRandom
)
{
double
distance
=
ms
.
getRealPosition
()
.
getD
istance
(
ap
.
getRealPosition
());
.
d
istance
To
(
ap
.
getRealPosition
());
double
distanceScore
=
1
-
(
distance
/
worldDimension
.
getLength
());
double
clusterScore
=
0
;
...
...
@@ -354,8 +358,9 @@ public class SocialTransitionStrategy implements TransitionStrategy,
AttractionPoint
nearest
=
aps
.
iterator
().
next
();
for
(
AttractionPoint
aPoint
:
aps
)
{
if
(
nearest
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
())
if
(
nearest
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
())
&&
!
assignments
.
get
(
ms
).
equals
(
aPoint
))
{
nearest
=
aPoint
;
}
...
...
@@ -368,8 +373,9 @@ public class SocialTransitionStrategy implements TransitionStrategy,
AttractionPoint
nearest
=
fps
.
iterator
().
next
();
for
(
AttractionPoint
aPoint
:
fps
)
{
if
(
nearest
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
())
if
(
nearest
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
())
&&
!
assignments
.
get
(
ms
).
equals
(
aPoint
))
{
nearest
=
aPoint
;
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/GPSCalculation.java
View file @
0c80da45
...
...
@@ -20,8 +20,9 @@
package
de.tud.kom.p2psim.impl.topology.movement.modularosm
;
import
de.tud.kom.p2psim.
impl
.topology.Topology
;
import
de.tud.kom.p2psim.
api
.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
/**
*
...
...
@@ -29,17 +30,20 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
* @version 1.0, Nov 3, 2015
*/
public
class
GPSCalculation
{
private
static
double
latCenter
;
private
static
double
lonCenter
;
private
static
int
zoom
;
private
static
double
scaleFactor
;
public
GPSCalculation
()
{
}
private
void
setScaleFactor
()
{
//this.scaleFactor = Math.pow(2.0d, (13 - zoom));
//
this.scaleFactor = Math.pow(2.0d, (13 - zoom));
/*
* BR: set scaleFactor to fixed zoom level 15 ==> 0.125 (as in this
* case, 1px == 1m) - this way, the world-size specified in the configs
...
...
@@ -49,47 +53,51 @@ public class GPSCalculation {
// 17: 2, 16: 1, 15: 0.5, 14: 0.25
VisualizationInjector
.
setScale
(
Math
.
pow
(
2.0d
,
(
zoom
-
16
)));
}
public
static
double
getLatCenter
()
{
return
latCenter
;
}
public
static
double
getLonCenter
()
{
return
lonCenter
;
}
public
static
int
getZoom
()
{
return
zoom
;
}
public
static
double
getLatUpper
()
{
return
latCenter
+
scaleFactor
*
0.027613
*
Topology
.
getWorldDimension
().
getX
()
/
1000
;
return
latCenter
+
scaleFactor
*
0.027613
*
Binder
.
getComponentOrNull
(
Topology
.
class
).
getWorldDimensions
().
getX
()
/
1000
;
}
public
static
double
getLatLower
()
{
return
latCenter
-
scaleFactor
*
0.027613
*
Topology
.
getWorldDimension
().
getX
()
/
1000
;
return
latCenter
-
scaleFactor
*
0.027613
*
Binder
.
getComponentOrNull
(
Topology
.
class
).
getWorldDimensions
().
getX
()
/
1000
;
}
public
static
double
getLonLeft
()
{
return
lonCenter
-
scaleFactor
*
0.0419232
*
Topology
.
getWorldDimension
().
getY
()
/
1000
;
return
lonCenter
-
scaleFactor
*
0.0419232
*
Binder
.
getComponentOrNull
(
Topology
.
class
).
getWorldDimensions
().
getY
()
/
1000
;
}
public
static
double
getLonRight
()
{
return
lonCenter
+
scaleFactor
*
0.0419232
*
Topology
.
getWorldDimension
().
getY
()
/
1000
;
return
lonCenter
+
scaleFactor
*
0.0419232
*
Binder
.
getComponentOrNull
(
Topology
.
class
).
getWorldDimensions
().
getY
()
/
1000
;
}
public
void
setLatCenter
(
double
latCenter
)
{
this
.
latCenter
=
latCenter
;
}
public
void
setLonCenter
(
double
lonCenter
)
{
this
.
lonCenter
=
lonCenter
;
}
public
void
setZoom
(
int
zoom
)
{
this
.
zoom
=
zoom
;
setScaleFactor
();
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java
View file @
0c80da45
...
...
@@ -32,19 +32,21 @@ import java.util.Vector;
import
javax.swing.JComponent
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.movement.MovementListener
;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.movement.MovementSupported
;
import
de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy
;
import
de.tud.kom.p2psim.impl.simengine.Simulator
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint
;
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.ITransitionStrategy
;
import
de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector
;
import
de.tud.kom.p2psim.impl.util.Either
;
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
;
...
...
@@ -113,7 +115,8 @@ public class ModularMovementModel implements MovementModel, EventHandler {
private
Random
rand
;
public
ModularMovementModel
()
{
this
.
worldDimensions
=
Topology
.
getWorldDimension
();
this
.
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
this
.
rand
=
Randoms
.
getRandom
(
ModularMovementModel
.
class
);
// scheduling initalization!
...
...
@@ -136,10 +139,10 @@ public class ModularMovementModel implements MovementModel, EventHandler {
checkConfiguration
();
// setWayPointModel
localMovementStrategy
.
setObstacleModel
(
Topology
.
getTopology
()
.
getObstacleModel
());
localMovementStrategy
.
setWaypointModel
(
Topology
.
getTopology
()
.
getWaypointModel
());
localMovementStrategy
.
setObstacleModel
(
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getObstacleModel
());
localMovementStrategy
.
setWaypointModel
(
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWaypointModel
());
List
<
AttractionPoint
>
attractionPoints
=
attractionGenerator
.
getAttractionPoints
();
transition
.
setAttractionPoints
(
attractionPoints
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/JSONAttractionGenerator.java
View file @
0c80da45
...
...
@@ -31,9 +31,10 @@ import org.json.JSONArray;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
/**
* Generates attraction points out of real data from osm
...
...
@@ -62,7 +63,8 @@ public class JSONAttractionGenerator implements IAttractionGenerator {
http://overpass-api.de/api/interpreter?data=%5Bout:json%5D;node%5Bamenity=bar%5D%2849%2E4813%2C8%2E5590%2C49%2E9088%2C8%2E7736%29%3Bout%3B
*/
public
JSONAttractionGenerator
()
{
this
.
worldDimensions
=
Topology
.
getWorldDimension
();
this
.
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
attractionPoints
=
new
LinkedList
<
AttractionPoint
>();
latLeft
=
GPSCalculation
.
getLatLower
();
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/OnlineJSONAttractionGenerator.java
View file @
0c80da45
...
...
@@ -36,9 +36,10 @@ import org.json.JSONArray;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
/**
* Generates attraction points out of real data from osm
...
...
@@ -65,7 +66,8 @@ public class OnlineJSONAttractionGenerator implements IAttractionGenerator {
private
double
lonRight
;
//Values from -180 to 180
public
OnlineJSONAttractionGenerator
()
{
this
.
worldDimensions
=
Topology
.
getWorldDimension
();
this
.
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
attractionPoints
=
new
LinkedList
<
AttractionPoint
>();
latLeft
=
GPSCalculation
.
getLatLower
();
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/SocialTransitionStrategy.java
View file @
0c80da45
...
...
@@ -36,12 +36,14 @@ import java.util.Vector;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.common.SimHostComponent
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.movement.MovementSupported
;
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.
Topolo
gy
;
import
de.tud.kom.p2psim.impl.topology.
movement.modular.transition.TransitionStrate
gy
;
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
;
...
...
@@ -121,7 +123,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
"SocialId is not set, to find the needed SocialView!"
);
}
socialView
=
Topology
.
getTopology
().
getSocialView
(
socialId
);
socialView
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getSocialView
(
socialId
);
if
(
socialView
==
null
)
{
throw
new
ConfigurationException
(
...
...
@@ -133,7 +136,8 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
"MinPauseTime should be smaller then maxPauseTime."
);
}
worldDimension
=
Topology
.
getWorldDimension
();
worldDimension
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
init
=
true
;
}
}
...
...
@@ -165,8 +169,9 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
// assignment..
AttractionPoint
nearest
=
aPoints
.
iterator
().
next
();
for
(
AttractionPoint
aPoint
:
aPoints
)
{
if
(
nearest
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
().
getDistance
(
ms
.
getRealPosition
()))
{
if
(
nearest
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
())
>
aPoint
.
getRealPosition
()
.
distanceTo
(
ms
.
getRealPosition
()))
{
nearest
=
aPoint
;
}
}
...
...
@@ -243,8 +248,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private
double
score
(
MovementSupported
ms
,
AttractionPoint
ap
,
List
<
AttractionPoint
>
apFavorites
,
List
<
AttractionPoint
>
apFriends
,
List
<
AttractionPoint
>
apClusters
,
List
<
AttractionPoint
>
apRandom
)
{
double
distance
=
ms
.
getRealPosition
()
.
getDistance
(
ap
.
getRealPosition
());
double
distance
=
ms
.
getRealPosition
().
distanceTo
(
ap
.
getRealPosition
());
double
distanceScore
=
1
-
(
distance
/
worldDimension
.
getLength
());
double
clusterScore
=
0
;
...
...
src/de/tud/kom/p2psim/impl/topology/obstacles/PolygonObstacle.java
View file @
0c80da45
...
...
@@ -150,7 +150,7 @@ public class PolygonObstacle extends AbstractObstacle {
/*
* Adding a bit of greedy decisions, to not always use the poly-methods
*/
double
dist
=
a
.
getD
istance
(
b
);
double
dist
=
a
.
d
istance
To
(
b
);
if
(
a
.
getX
()
+
dist
<
minX
||
a
.
getX
()
-
dist
>
maxX
||
a
.
getY
()
+
dist
<
minY
||
a
.
getY
()
-
dist
>
maxY
)
{
return
false
;
...
...
src/de/tud/kom/p2psim/impl/topology/views/AbstractTopologyView.java
View file @
0c80da45
...
...
@@ -27,7 +27,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.linklayer.LinkLayer
;
import
de.tud.kom.p2psim.api.linklayer.mac.Link
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
...
...
@@ -43,6 +42,7 @@ import de.tud.kom.p2psim.api.topology.views.TopologyView;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* To ease implementation of new {@link TopologyView}s, this class provides
...
...
@@ -475,13 +475,13 @@ public abstract class AbstractTopologyView<L extends DefaultLink> implements
}
@Override
public
Posi
tion
getPosition
(
MacAddress
address
)
{
public
Loca
tion
getPosition
(
MacAddress
address
)
{
return
getCachedPosition
(
address
);
}
@Override
public
double
getDistance
(
MacAddress
addressA
,
MacAddress
addressB
)
{
return
getCachedPosition
(
addressA
)
.
getDistance
(
getCachedPosition
(
addressB
));
return
getCachedPosition
(
addressA
)
.
distanceTo
(
getCachedPosition
(
addressB
));
}
}
src/de/tud/kom/p2psim/impl/topology/views/RangedTopologyView.java
View file @
0c80da45
...
...
@@ -231,7 +231,7 @@ public class RangedTopologyView extends AbstractTopologyView<RangedLink> {
@Override
protected
void
updateOutdatedLink
(
RangedLink
link
)
{
link
.
updateNodeDistance
(
getCachedPosition
(
link
.
getSource
())
.
getD
istance
(
getCachedPosition
(
link
.
getDestination
())));
.
d
istance
To
(
getCachedPosition
(
link
.
getDestination
())));
/*
* Update latency and drop rate - note: it depends on the actual
...
...
src/de/tud/kom/p2psim/impl/topology/views/VisualizationTopologyView.java
View file @
0c80da45
...
...
@@ -55,18 +55,17 @@ import javax.swing.Timer;
import
com.google.common.collect.Maps
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.linklayer.mac.Link
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacLayer
;
import
de.tud.kom.p2psim.api.linklayer.mac.PhyType
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.TopologyComponent
;
import
de.tud.kom.p2psim.api.topology.movement.MovementSupported
;
import
de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel
;
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.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager
;
import
de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo
;
import
de.tud.kom.p2psim.impl.topology.views.visualization.ui.ComponentToggler
;
...
...
@@ -78,7 +77,9 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.world.StrongWaypointC
import
de.tud.kom.p2psim.impl.topology.views.visualization.world.TopologyComponentVis
;
import
de.tud.kom.p2psim.impl.topology.views.visualization.world.WeakWaypointComponentVis
;
import
de.tud.kom.p2psim.impl.util.NotSupportedException
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* A very basic visualization of a Topology (ie. positioning and movement), just
...
...
@@ -126,8 +127,10 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
*
*/
public
VisualizationTopologyView
()
{
WORLD_X
=
(
int
)
Topology
.
getWorldDimension
().
getX
();
WORLD_Y
=
(
int
)
Topology
.
getWorldDimension
().
getY
();
WORLD_X
=
(
int
)
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
().
getX
();
WORLD_Y
=
(
int
)
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
().
getY
();
worldPanel
=
new
WorldPanel
();
visManager
=
new
ComponentVisManager
(
worldPanel
);
...
...
@@ -668,7 +671,7 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
}
@Override
public
Posi
tion
getPosition
(
MacAddress
address
)
{
public
Loca
tion
getPosition
(
MacAddress
address
)
{
throw
new
NotSupportedException
();
}
...
...
src/de/tud/kom/p2psim/impl/topology/views/visualization/world/SocialViewComponentVis.java
View file @
0c80da45
...
...
@@ -179,7 +179,7 @@ public class SocialViewComponentVis extends JComponent implements
public
void
mouseClicked
(
int
x
,
int
y
)
{
List
<
SimHost
>
inNear
=
new
Vector
<
SimHost
>();
for
(
Entry
<
SimHost
,
PositionVector
>
e
:
posVecs
.
entrySet
())
{
if
(
e
.
getValue
().
getD
istance
(
new
PositionVector
(
x
,
y
))
<
4
)
{
if
(
e
.
getValue
().
d
istance
To
(
new
PositionVector
(
x
,
y
))
<
4
)
{
inNear
.
add
(
e
.
getKey
());
}
}
...
...
src/de/tud/kom/p2psim/impl/topology/views/wifi/WifiTopologyView.java
View file @
0c80da45
...
...
@@ -26,7 +26,6 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacLayer
;
...
...
@@ -43,6 +42,9 @@ import de.tud.kom.p2psim.impl.topology.views.RangedLink;
import
de.tud.kom.p2psim.impl.topology.views.RangedTopologyView
;
import
de.tud.kom.p2psim.impl.topology.views.wifi.phy.InterferenceHelper
;
import
de.tudarmstadt.maki.simonstrator.api.Message
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
...
...
@@ -266,7 +268,7 @@ public class WifiTopologyView extends RangedTopologyView {
* The {@link MacAddress} of the source, which stats this
* transfer
*/
public
void
addTransfer
(
long
start
,
long
end
,
Posi
tion
sourcePosition
,
public
void
addTransfer
(
long
start
,
long
end
,
Loca
tion
sourcePosition
,
double
txPowerDbm
,
Message
id
,
WifiMode
dataMode
,
WifiPreamble
preamble
,
SimHost
host
,
MacAddress
sourceAddress
)
{
interferenceHelper
.
addTransfer
(
start
,
end
,
sourcePosition
,
txPowerDbm
,
...
...
@@ -293,7 +295,7 @@ public class WifiTopologyView extends RangedTopologyView {
* The sourceAddress of this interference (It will be used the
* neighborhood of this peer, to inform about carrier sensing).
*/
public
void
addInterference
(
long
start
,
long
end
,
Posi
tion
sourcePosition
,
public
void
addInterference
(
long
start
,
long
end
,
Loca
tion
sourcePosition
,
double
txPowerDbm
,
WifiMode
dataMode
,
MacAddress
sourceAddress
)
{
interferenceHelper
.
addInterference
(
start
,
end
,
sourcePosition
,
txPowerDbm
,
dataMode
,
sourceAddress
);
...
...
@@ -306,7 +308,7 @@ public class WifiTopologyView extends RangedTopologyView {
* @param msg
* The message which was added as interference (or rather as ID)
* with
* {@link WifiTopologyView#addInterference(long, long,
Posi
tion, double, WifiMode, MacAddress)}
* {@link WifiTopologyView#addInterference(long, long,
Loca
tion, double, WifiMode, MacAddress)}
* to the {@link InterferenceHelper}.
* @param pos
* The position for that the PER should be calculated for this
...
...
@@ -314,7 +316,7 @@ public class WifiTopologyView extends RangedTopologyView {
* @return The Packet Error Rate (PER) for the message at the given
* Position.
*/
public
double
calculatePer
(
Message
msg
,
Posi
tion
pos
)
{
public
double
calculatePer
(
Message
msg
,
Loca
tion
pos
)
{
return
interferenceHelper
.
calculatePer
(
msg
,
pos
);
}
...
...
@@ -375,8 +377,11 @@ public class WifiTopologyView extends RangedTopologyView {
rxSensitivityDbm
);
double
satRange
=
interferenceHelper
.
calculateMaximalRadius
(
maxTxPowerDbm
,
satDbm
);
// System.out.println("satRange: " + satRange + " csRange: " + csRange
// + " range: " + range);
System
.
out
.
println
(
"satRange: "
+
satRange
+
" csRange: "
+
csRange
+
" range: "
+
range
);
Monitor
.
log
(
WifiTopologyView
.
class
,
Level
.
INFO
,
"WiFi underlay ranges: satRange: "
+
satRange
+
" csRange: "
+
csRange
+
" range: "
+
range
);
setRange
(
range
);
setCSRange
(
csRange
);
...
...
src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/InterferenceHelper.java
View file @
0c80da45
...
...
@@ -28,7 +28,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Vector
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.common.SimHost
;
import
de.tud.kom.p2psim.api.linklayer.mac.MacAddress
;
import
de.tud.kom.p2psim.api.topology.views.wifi.phy.ErrorRateModel
;
...
...
@@ -46,6 +45,7 @@ import de.tudarmstadt.maki.simonstrator.api.Message;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* This class is the Interference Helper, which process for one
...
...
@@ -176,13 +176,13 @@ public class InterferenceHelper implements EventHandler {
* @param end
* The end time of this interference in microseconds
* @param sourcePosition
* The {@link
Posi
tion} of the source of this interference
* The {@link
Loca
tion} of the source of this interference
* @param txPowerDbm
* The signal power of this interference in dBm.
*/
@Deprecated
// because sourceAddress should be not null!
public
void
addInterference
(
long
start
,
long
end
,
Posi
tion
sourcePosition
,
public
void
addInterference
(
long
start
,
long
end
,
Loca
tion
sourcePosition
,
double
txPowerDbm
)
{
addInterference
(
start
,
end
,
sourcePosition
,
txPowerDbm
,
null
,
null
);
}
...
...
@@ -199,7 +199,7 @@ public class InterferenceHelper implements EventHandler {
* @param end
* The end time of this interference in microseconds
* @param sourcePosition
* The {@link
Posi
tion} of the source of this interference
* The {@link
Loca
tion} of the source of this interference
* @param txPowerDbm
* The signal power of this interference in dBm.
* @param dataMode
...
...
@@ -208,7 +208,7 @@ public class InterferenceHelper implements EventHandler {
* The {@link MacAddress} of the node, which are the originator
* of this interference.
*/
public
void
addInterference
(
long
start
,
long
end
,
Posi
tion
sourcePosition
,
public
void
addInterference
(
long
start
,
long
end
,
Loca
tion
sourcePosition
,
double
txPowerDbm
,
WifiMode
dataMode
,
MacAddress
sourceAddress
)
{
addTransfer
(
start
,
end
,
sourcePosition
,
txPowerDbm
,
null
,
dataMode
,
null
,
null
,
sourceAddress
);
...
...
@@ -225,7 +225,7 @@ public class InterferenceHelper implements EventHandler {
* @param end
* The end time of this transfer in microseconds
* @param sourcePosition
* The {@link
Posi
tion} of the source of this transfer
* The {@link
Loca
tion} of the source of this transfer
* @param txPowerDbm
* The signal power of this transfer in dBm.
* @param id
...
...
@@ -241,7 +241,7 @@ public class InterferenceHelper implements EventHandler {
* The {@link MacAddress} of the node, which are the originator
* of this transfer.
*/
public
void
addTransfer
(
long
start
,
long
end
,
Posi
tion
sourcePosition
,
public
void
addTransfer
(
long
start
,
long
end
,
Loca
tion
sourcePosition
,
double
txPowerDbm
,
Message
id
,
WifiMode
dataMode
,
WifiPreamble
preamble
,
SimHost
host
,
MacAddress
sourceAddress
)
{
if
(
start
<
Time
.
getCurrentTime
())
{
...
...
@@ -252,8 +252,8 @@ public class InterferenceHelper implements EventHandler {
throw
new
IllegalArgumentException
(
"The start time is equal or greater than the end time!"
);
}
Interference
interference
=
new
Interference
(
start
,
end
,
sourcePosition
.
clone
(),
txPowerDbm
,
id
,
dataMode
,
preamble
,
Interference
interference
=
new
Interference
(
start
,
end
,
sourcePosition
,
txPowerDbm
,
id
,
dataMode
,
preamble
,
host
,
sourceAddress
);
addInterference
(
interference
);
...
...
@@ -336,7 +336,7 @@ public class InterferenceHelper implements EventHandler {
/**
* Calculates the Packet Error Rate for this ID (the Message) and the given
* {@link
Posi
tion}. The position is used to calculate the receive power and
* {@link
Loca
tion}. The position is used to calculate the receive power and
* the resulting SNR (Signal to noise Ratio).<br>
* The transfer information will be got with the message. In this
* information will be stored all interferences, which has influence for the
...
...
@@ -354,7 +354,7 @@ public class InterferenceHelper implements EventHandler {
* @return The Packet Error Rate for this Message at the given
* {@link Position}.
*/
public
double
calculatePer
(
Message
id
,
Posi
tion
rxPos
)
{
public
double
calculatePer
(
Message
id
,
Loca
tion
rxPos
)
{
Interference
transfer
=
transfers
.
get
(
id
);
if
(
transfer
==
null
)
{
Monitor
.
log
(
...
...
@@ -520,7 +520,7 @@ public class InterferenceHelper implements EventHandler {
/**
* Calculates the actually Interference noise in Watt for a host. The host
* will be used, to use his {@link
Posi
tion}, and to ignore interferences
* will be used, to use his {@link
Loca
tion}, and to ignore interferences
* from him.
*
* @param host
...
...
@@ -536,15 +536,15 @@ public class InterferenceHelper implements EventHandler {
/**
* Calculates the actually interference noise in Watt at the given
* {@link
Posi
tion}. The output of can be different to the method
* {@link InterferenceHelper#calculateNoiseInterferenceW(SimHost)}, because
no
* interference will be leave out.
* {@link
Loca
tion}. The output of can be different to the method
* {@link InterferenceHelper#calculateNoiseInterferenceW(SimHost)}, because
*
no
interference will be leave out.
*
* @param point
* The position for that the interference noise is requested
* @return The actually interference noise in Watt at the given Position.
*/
public
double
calculateNoiseInterferenceW
(
Posi
tion
point
)
{
public
double
calculateNoiseInterferenceW
(
Loca
tion
point
)
{
return
calculateNoiseInterferenceW
(
null
,
point
);
}
...
...
@@ -562,7 +562,7 @@ public class InterferenceHelper implements EventHandler {
* @return The actually interference noise in Watt at the given Position
* without the interferences of the host.
*/
public
double
calculateNoiseInterferenceW
(
SimHost
host
,
Posi
tion
point
)
{
public
double
calculateNoiseInterferenceW
(
SimHost
host
,
Loca
tion
point
)
{
double
noiseInterferenceW
=
0
;
for
(
Interference
i
:
interferences
)
{
if
(
i
.
getStartTime
()
<=
Time
.
getCurrentTime
()
...
...
@@ -680,7 +680,7 @@ public class InterferenceHelper implements EventHandler {
private
final
NIChangeTime
niChangeEnd
;
private
final
Posi
tion
sourcePosition
;
private
final
Loca
tion
sourcePosition
;
private
final
double
txPowerDbm
;
...
...
@@ -701,7 +701,7 @@ public class InterferenceHelper implements EventHandler {
private
List
<
InterferenceHelper
.
NIChangeTime
>
niChangeList
=
new
Vector
<
InterferenceHelper
.
NIChangeTime
>();
public
Interference
(
long
startTime
,
long
endTime
,
Posi
tion
sourcePosition
,
double
txPowerDbm
,
Message
id
,
Loca
tion
sourcePosition
,
double
txPowerDbm
,
Message
id
,
WifiMode
dataMode
,
WifiPreamble
preamble
,
SimHost
host
,
MacAddress
sourceAddress
)
{
this
.
niChangeStart
=
new
NIChangeTime
(
startTime
,
false
,
this
);
...
...
@@ -733,7 +733,7 @@ public class InterferenceHelper implements EventHandler {
return
niChangeEnd
.
getTime
();
}
public
Posi
tion
getSourcePosition
()
{
public
Loca
tion
getSourcePosition
()
{
return
sourcePosition
;
}
...
...
@@ -757,20 +757,21 @@ public class InterferenceHelper implements EventHandler {
return
host
;
}
public
double
getRxPowerDbm
(
Posi
tion
pos
)
{
public
double
getRxPowerDbm
(
Loca
tion
pos
)
{
return
getLossModel
().
getRxPowerDbm
(
getTxPowerDbm
(),
sourcePosition
.
getD
istance
(
pos
))
sourcePosition
.
d
istance
To
(
pos
))
+
getRxGainDbm
();
}
public
double
getRxPowerW
(
Posi
tion
pos
)
{
public
double
getRxPowerW
(
Loca
tion
pos
)
{
double
rxPowerdbm
=
getRxPowerDbm
(
pos
);
return
PropagationLossModel
.
dbmToW
(
rxPowerdbm
);
}
public
void
addInterference
(
Interference
interference
)
{
if
(!
isUnknown
())
{
double
distance
=
this
.
sourcePosition
.
getDistance
(
interference
double
distance
=
this
.
sourcePosition
.
distanceTo
(
interference
.
getSourcePosition
());
double
maxRadius
=
calculateMaximalSatRadius
(
interference
.
getTxPowerDbm
());
...
...
@@ -874,7 +875,7 @@ public class InterferenceHelper implements EventHandler {
* @return It is positive, if an interference start, and negative if the
* interference ends.
*/
public
double
getRxPowerWChange
(
Posi
tion
rxPos
)
{
public
double
getRxPowerWChange
(
Loca
tion
rxPos
)
{
double
change
=
this
.
getInterference
().
getRxPowerW
(
rxPos
);
if
(
this
.
isEndOfTransmission
())
{
change
*=
-
1
;
...
...
src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/propagation/loss/FriisPropagationLossModel.java
View file @
0c80da45
...
...
@@ -20,8 +20,8 @@
package
de.tud.kom.p2psim.impl.topology.views.wifi.phy.propagation.loss
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
* The Friis Propagation Loss Model:
...
...
@@ -81,8 +81,8 @@ public class FriisPropagationLossModel extends PropagationLossModel {
private
double
minDistance
=
0.5d
;
@Override
public
double
getRxPowerDbm
(
double
txPowerDbm
,
Posi
tion
a
,
Posi
tion
b
)
{
double
distance
=
a
.
getD
istance
(
b
);
public
double
getRxPowerDbm
(
double
txPowerDbm
,
Loca
tion
a
,
Loca
tion
b
)
{
double
distance
=
a
.
d
istance
To
(
b
);
return
getRxPowerDbm
(
txPowerDbm
,
distance
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/views/wifi/phy/propagation/loss/LogDistancePropagationLossModel.java
View file @
0c80da45
...
...
@@ -20,8 +20,8 @@
package
de.tud.kom.p2psim.impl.topology.views.wifi.phy.propagation.loss
;
import
de.tud.kom.p2psim.api.common.Position
;
import
de.tud.kom.p2psim.api.topology.views.wifi.phy.PropagationLossModel
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
*
...
...
@@ -78,8 +78,8 @@ public class LogDistancePropagationLossModel extends PropagationLossModel {
*
referenceDistance
/
lambda
);
@Override
public
double
getRxPowerDbm
(
double
txPowerDbm
,
Posi
tion
a
,
Posi
tion
b
)
{
double
distance
=
a
.
getD
istance
(
b
);
public
double
getRxPowerDbm
(
double
txPowerDbm
,
Loca
tion
a
,
Loca
tion
b
)
{
double
distance
=
a
.
d
istance
To
(
b
);
return
getRxPowerDbm
(
txPowerDbm
,
distance
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/waypoints/AbstractWaypointModel.java
View file @
0c80da45
/*
* Copyright (c) 2005-2010 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.waypoints
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
import
org.jgrapht.alg.DijkstraShortestPath
;
import
com.google.common.collect.Sets
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.scenario.Configurator
;
import
de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel
;
import
de.tud.kom.p2psim.api.topology.waypoints.WaypointModel
;
import
de.tud.kom.p2psim.api.topology.waypoints.WaypointModelListener
;
import
de.tud.kom.p2psim.api.util.geo.maps.Map
;
import
de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After
;
import
de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph
;
import
de.tud.kom.p2psim.impl.topology.waypoints.graph.Path
;
import
de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint
;
import
de.tud.kom.p2psim.impl.util.Tuple
;
import
de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener
;
import
de.tud.kom.p2psim.impl.util.geo.maps.MapLoader
;
import
de.tud.kom.p2psim.impl.util.structures.KdTree
;
import
de.tud.kom.p2psim.impl.util.structures.KdTree.Entry
;
import
de.tud.kom.p2psim.impl.util.structures.WaypointKdTree
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
/**
* The abstract way point model manages a graph for the map data and holds
* additional information for the fast retrieval of way points.
*
* @author Fabio Zöllner
* @version 1.0, 09.04.2012
*/
public
abstract
class
AbstractWaypointModel
implements
WaypointModel
{
private
PositionVector
worldDimensions
;
private
Map
map
;
// private DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> graph;
private
ArrayList
<
WaypointModelListener
>
listeners
=
new
ArrayList
<
WaypointModelListener
>();
// k-d tree for fast retrieval of nearby waypoints
private
KdTree
<
Waypoint
>
kdTree
=
new
WaypointKdTree
(
2
);
private
ObstacleModel
obstacleModel
=
null
;
// Determines if the loaded model should be scaled or truncated to fit the given world size
private
boolean
scaleModel
=
true
;
private
String
mapName
=
""
;
public
AbstractWaypointModel
()
{
//
}
@Configure
()
@After
(
optional
={
ObstacleModel
.
class
})
public
void
_configure
(
Configurator
configurator
)
{
MapLoader
mapLoader
=
(
MapLoader
)
configurator
.
getConfigurable
(
MapLoader
.
class
.
getSimpleName
());
if
(
mapLoader
==
null
)
{
throw
new
ConfigurationException
(
"No MapLoader was configured. Unable to retrieve the map '"
+
mapName
+
"'."
);
}
Map
map
=
mapLoader
.
getMap
(
mapName
);
if
(
map
==
null
)
{
throw
new
ConfigurationException
(
"Couldn't retrieve the map '"
+
mapName
+
"' from the MapLoader. Make sure the map is configured."
);
}
this
.
map
=
map
;
map
.
addMapChangeListener
(
new
MapChangeListener
()
{
@Override
public
void
mapChanged
(
MapEvent
event
)
{
if
(
event
instanceof
PathEvent
)
{
notifyAddedPath
(((
PathEvent
)
event
).
getPath
());
}
else
if
(
event
instanceof
WaypointEvent
)
{
notifyAddedWaypoint
(((
WaypointEvent
)
event
).
getWaypoint
());
}
else
{
notifyModifiedWaypoints
();
}
}
});
Monitor
.
log
(
AbstractWaypointModel
.
class
,
Level
.
INFO
,
"The '"
+
map
.
getName
()
+
"' "
+
map
.
getClass
().
getSimpleName
()
+
" has dimensions of "
+
map
.
getDimensions
().
getX
()
+
"x"
+
map
.
getDimensions
().
getY
()
+
"."
);
PositionVector
mapBorder
=
map
.
getDimensions
().
clone
();
mapBorder
.
divide
(
getWorldDimensions
());
if
(
mapBorder
.
getEntry
(
0
)
!=
1
||
mapBorder
.
getEntry
(
1
)
!=
1
)
{
Monitor
.
log
(
AbstractWaypointModel
.
class
,
Level
.
WARN
,
"You specified WORLD to be "
+
getWorldDimensions
().
toString
()
+
" and used an OSM Map with "
+
map
.
getDimensions
()
+
", resulting in wrong scaling."
);
}
init
();
}
public
abstract
void
init
();
public
Map
getMap
()
{
return
map
;
}
public
void
setMap
(
String
mapName
)
{
this
.
mapName
=
mapName
;
}
public
void
setScale
(
boolean
shouldScale
)
{
this
.
scaleModel
=
shouldScale
;
}
public
boolean
isScaled
()
{
return
scaleModel
;
}
@Override
public
double
getScaleFactor
()
{
if
(!
this
.
scaleModel
)
{
return
1
;
}
double
mapX
=
getMap
().
getDimensions
().
getX
();
double
mapY
=
getMap
().
getDimensions
().
getY
();
double
worldX
=
getWorldDimensions
().
getX
();
double
worldY
=
getWorldDimensions
().
getY
();
double
factor
=
Math
.
abs
((
worldX
+
worldY
)
/
(
mapX
+
mapY
));
return
factor
;
}
@Override
public
void
setObstacleModel
(
ObstacleModel
model
)
{
obstacleModel
=
model
;
}
public
PositionVector
getWorldDimensions
()
{
return
worldDimensions
;
}
@Override
public
void
setWorldDimensions
(
PositionVector
worldDimensions
)
{
this
.
worldDimensions
=
worldDimensions
;
}
@Override
public
Collection
<
Waypoint
>
getWaypoints
(
Class
type
)
{
return
map
.
getWaypoints
(
type
);
}
@Override
public
Waypoint
getClosestWaypoint
(
PositionVector
position
)
{
return
getClosestWaypoint
(
position
,
Waypoint
.
class
);
}
@Override
public
Waypoint
getClosestWaypoint
(
PositionVector
position
,
Class
type
)
{
double
distance
=
-
1
;
Waypoint
waypoint
=
null
;
for
(
Waypoint
w
:
map
.
getGraph
().
vertexSet
())
{
if
(!
w
.
getClass
().
equals
(
type
))
continue
;
double
d
=
position
.
getD
istance
(
w
.
getPosition
());
if
(
distance
>
d
||
distance
==
-
1
)
{
distance
=
d
;
waypoint
=
w
;
}
}
return
waypoint
;
}
public
Waypoint
getClosestWaypointKd
(
PositionVector
position
,
Class
type
)
{
List
<
Entry
<
Waypoint
>>
waypoints
=
kdTree
.
nearestNeighbor
(
position
.
asDoubleArray
(),
1
,
false
);
if
(
waypoints
.
isEmpty
())
return
null
;
return
waypoints
.
get
(
0
).
value
;
}
@Override
public
List
<
Tuple
<
Waypoint
,
Path
>>
getConnectedWaypoints
(
Waypoint
waypoint
)
{
return
getConnectedWaypoints
(
waypoint
,
Waypoint
.
class
);
}
@Override
public
List
<
Tuple
<
Waypoint
,
Path
>>
getConnectedWaypoints
(
Waypoint
waypoint
,
Class
type
)
{
Set
<
Path
>
paths
=
map
.
getGraph
().
edgesOf
(
waypoint
);
ArrayList
<
Tuple
<
Waypoint
,
Path
>>
waypointsAndPaths
=
new
ArrayList
<
Tuple
<
Waypoint
,
Path
>>();
for
(
Path
p
:
paths
)
{
Waypoint
destinationWaypoint
=
null
;
if
(
p
.
getSource
().
equals
(
waypoint
))
destinationWaypoint
=
p
.
getTarget
();
else
if
(
p
.
getTarget
().
equals
(
waypoint
))
destinationWaypoint
=
p
.
getSource
();
if
(
destinationWaypoint
.
getClass
().
equals
(
type
))
waypointsAndPaths
.
add
(
new
Tuple
<
Waypoint
,
Path
>(
destinationWaypoint
,
p
));
}
return
waypointsAndPaths
;
}
@Override
public
int
getNumberOfWaypoints
(
Class
type
)
{
Collection
<
Waypoint
>
wpList
=
map
.
getWaypoints
(
type
);
if
(
wpList
==
null
)
return
-
1
;
return
wpList
.
size
();
}
@Override
public
void
addListener
(
WaypointModelListener
listener
)
{
this
.
listeners
.
add
(
listener
);
}
@Override
public
void
removeListener
(
WaypointModelListener
listener
)
{
this
.
listeners
.
remove
(
listener
);
}
private
void
notifyAddedWaypoint
(
Waypoint
waypoint
)
{
for
(
WaypointModelListener
l
:
listeners
)
{
l
.
addedWaypoint
(
waypoint
);
}
}
private
void
notifyModifiedWaypoints
()
{
for
(
WaypointModelListener
l
:
listeners
)
{
l
.
modifiedWaypoints
();
}
}
private
void
notifyAddedPath
(
Path
path
)
{
for
(
WaypointModelListener
l
:
listeners
)
{
l
.
addedPath
(
path
);
}
}
@Override
public
PositionVector
getMetricDimensions
()
{
return
worldDimensions
;
}
@Override
public
abstract
void
generateWaypoints
();
@Override
public
Set
<
Waypoint
>
getWaypoints
()
{
if
(
map
!=
null
)
{
return
map
.
getGraph
().
vertexSet
();
}
else
{
return
Sets
.
newHashSet
();
}
}
@Override
public
Set
<
Path
>
getPaths
()
{
return
map
.
getGraph
().
getAllEdges
();
}
@Override
public
List
<
Path
>
getShortestPath
(
Waypoint
start
,
Waypoint
end
)
{
DijkstraShortestPath
<
Waypoint
,
Path
>
dijkstrashortestpath
=
new
DijkstraShortestPath
<
Waypoint
,
Path
>(
map
.
getGraph
(),
start
,
end
);
List
<
Path
>
paths
=
dijkstrashortestpath
.
getPathEdgeList
();
return
dijkstrashortestpath
.
getPathEdgeList
();
}
@Override
public
int
getNumberOfWaypoints
()
{
return
map
.
getGraph
().
vertexSet
().
size
();
}
@Override
public
DefaultWeightedEdgeRetrievableGraph
<
Waypoint
,
Path
>
getGraph
()
{
if
(
map
==
null
)
return
null
;
return
map
.
getGraph
();
}
public
void
addWaypoint
(
Waypoint
wp
)
{
map
.
addWaypoint
(
wp
);
}
}
/*
* Copyright (c) 2005-2010 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.waypoints
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
import
org.jgrapht.alg.DijkstraShortestPath
;
import
com.google.common.collect.Sets
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.scenario.Configurator
;
import
de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel
;
import
de.tud.kom.p2psim.api.topology.waypoints.WaypointModel
;
import
de.tud.kom.p2psim.api.topology.waypoints.WaypointModelListener
;
import
de.tud.kom.p2psim.api.util.geo.maps.Map
;
import
de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.After
;
import
de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.waypoints.graph.DefaultWeightedEdgeRetrievableGraph
;
import
de.tud.kom.p2psim.impl.topology.waypoints.graph.Path
;
import
de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint
;
import
de.tud.kom.p2psim.impl.util.Tuple
;
import
de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener
;
import
de.tud.kom.p2psim.impl.util.geo.maps.MapLoader
;
import
de.tud.kom.p2psim.impl.util.structures.KdTree
;
import
de.tud.kom.p2psim.impl.util.structures.KdTree.Entry
;
import
de.tud.kom.p2psim.impl.util.structures.WaypointKdTree
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
/**
* The abstract way point model manages a graph for the map data and holds
* additional information for the fast retrieval of way points.
*
* @author Fabio Zöllner
* @version 1.0, 09.04.2012
*/
public
abstract
class
AbstractWaypointModel
implements
WaypointModel
{
private
PositionVector
worldDimensions
;
private
Map
map
;
// private DefaultWeightedEdgeRetrievableGraph<Waypoint, Path> graph;
private
ArrayList
<
WaypointModelListener
>
listeners
=
new
ArrayList
<
WaypointModelListener
>();
// k-d tree for fast retrieval of nearby waypoints
private
KdTree
<
Waypoint
>
kdTree
=
new
WaypointKdTree
(
2
);
private
ObstacleModel
obstacleModel
=
null
;
// Determines if the loaded model should be scaled or truncated to fit the given world size
private
boolean
scaleModel
=
true
;
private
String
mapName
=
""
;
public
AbstractWaypointModel
()
{
//
}
@Configure
()
@After
(
optional
={
ObstacleModel
.
class
})
public
void
_configure
(
Configurator
configurator
)
{
MapLoader
mapLoader
=
(
MapLoader
)
configurator
.
getConfigurable
(
MapLoader
.
class
.
getSimpleName
());
if
(
mapLoader
==
null
)
{
throw
new
ConfigurationException
(
"No MapLoader was configured. Unable to retrieve the map '"
+
mapName
+
"'."
);
}
Map
map
=
mapLoader
.
getMap
(
mapName
);
if
(
map
==
null
)
{
throw
new
ConfigurationException
(
"Couldn't retrieve the map '"
+
mapName
+
"' from the MapLoader. Make sure the map is configured."
);
}
this
.
map
=
map
;
map
.
addMapChangeListener
(
new
MapChangeListener
()
{
@Override
public
void
mapChanged
(
MapEvent
event
)
{
if
(
event
instanceof
PathEvent
)
{
notifyAddedPath
(((
PathEvent
)
event
).
getPath
());
}
else
if
(
event
instanceof
WaypointEvent
)
{
notifyAddedWaypoint
(((
WaypointEvent
)
event
).
getWaypoint
());
}
else
{
notifyModifiedWaypoints
();
}
}
});
Monitor
.
log
(
AbstractWaypointModel
.
class
,
Level
.
INFO
,
"The '"
+
map
.
getName
()
+
"' "
+
map
.
getClass
().
getSimpleName
()
+
" has dimensions of "
+
map
.
getDimensions
().
getX
()
+
"x"
+
map
.
getDimensions
().
getY
()
+
"."
);
PositionVector
mapBorder
=
map
.
getDimensions
().
clone
();
mapBorder
.
divide
(
getWorldDimensions
());
if
(
mapBorder
.
getEntry
(
0
)
!=
1
||
mapBorder
.
getEntry
(
1
)
!=
1
)
{
Monitor
.
log
(
AbstractWaypointModel
.
class
,
Level
.
WARN
,
"You specified WORLD to be "
+
getWorldDimensions
().
toString
()
+
" and used an OSM Map with "
+
map
.
getDimensions
()
+
", resulting in wrong scaling."
);
}
init
();
}
public
abstract
void
init
();
public
Map
getMap
()
{
return
map
;
}
public
void
setMap
(
String
mapName
)
{
this
.
mapName
=
mapName
;
}
public
void
setScale
(
boolean
shouldScale
)
{
this
.
scaleModel
=
shouldScale
;
}
public
boolean
isScaled
()
{
return
scaleModel
;
}
@Override
public
double
getScaleFactor
()
{
if
(!
this
.
scaleModel
)
{
return
1
;
}
double
mapX
=
getMap
().
getDimensions
().
getX
();
double
mapY
=
getMap
().
getDimensions
().
getY
();
double
worldX
=
getWorldDimensions
().
getX
();
double
worldY
=
getWorldDimensions
().
getY
();
double
factor
=
Math
.
abs
((
worldX
+
worldY
)
/
(
mapX
+
mapY
));
return
factor
;
}
@Override
public
void
setObstacleModel
(
ObstacleModel
model
)
{
obstacleModel
=
model
;
}
public
PositionVector
getWorldDimensions
()
{
return
worldDimensions
;
}
@Override
public
void
setWorldDimensions
(
PositionVector
worldDimensions
)
{
this
.
worldDimensions
=
worldDimensions
;
}
@Override
public
Collection
<
Waypoint
>
getWaypoints
(
Class
type
)
{
return
map
.
getWaypoints
(
type
);
}
@Override
public
Waypoint
getClosestWaypoint
(
PositionVector
position
)
{
return
getClosestWaypoint
(
position
,
Waypoint
.
class
);
}
@Override
public
Waypoint
getClosestWaypoint
(
PositionVector
position
,
Class
type
)
{
double
distance
=
-
1
;
Waypoint
waypoint
=
null
;
for
(
Waypoint
w
:
map
.
getGraph
().
vertexSet
())
{
if
(!
w
.
getClass
().
equals
(
type
))
continue
;
double
d
=
position
.
d
istance
To
(
w
.
getPosition
());
if
(
distance
>
d
||
distance
==
-
1
)
{
distance
=
d
;
waypoint
=
w
;
}
}
return
waypoint
;
}
public
Waypoint
getClosestWaypointKd
(
PositionVector
position
,
Class
type
)
{
List
<
Entry
<
Waypoint
>>
waypoints
=
kdTree
.
nearestNeighbor
(
position
.
asDoubleArray
(),
1
,
false
);
if
(
waypoints
.
isEmpty
())
return
null
;
return
waypoints
.
get
(
0
).
value
;
}
@Override
public
List
<
Tuple
<
Waypoint
,
Path
>>
getConnectedWaypoints
(
Waypoint
waypoint
)
{
return
getConnectedWaypoints
(
waypoint
,
Waypoint
.
class
);
}
@Override
public
List
<
Tuple
<
Waypoint
,
Path
>>
getConnectedWaypoints
(
Waypoint
waypoint
,
Class
type
)
{
Set
<
Path
>
paths
=
map
.
getGraph
().
edgesOf
(
waypoint
);
ArrayList
<
Tuple
<
Waypoint
,
Path
>>
waypointsAndPaths
=
new
ArrayList
<
Tuple
<
Waypoint
,
Path
>>();
for
(
Path
p
:
paths
)
{
Waypoint
destinationWaypoint
=
null
;
if
(
p
.
getSource
().
equals
(
waypoint
))
destinationWaypoint
=
p
.
getTarget
();
else
if
(
p
.
getTarget
().
equals
(
waypoint
))
destinationWaypoint
=
p
.
getSource
();
if
(
destinationWaypoint
.
getClass
().
equals
(
type
))
waypointsAndPaths
.
add
(
new
Tuple
<
Waypoint
,
Path
>(
destinationWaypoint
,
p
));
}
return
waypointsAndPaths
;
}
@Override
public
int
getNumberOfWaypoints
(
Class
type
)
{
Collection
<
Waypoint
>
wpList
=
map
.
getWaypoints
(
type
);
if
(
wpList
==
null
)
return
-
1
;
return
wpList
.
size
();
}
@Override
public
void
addListener
(
WaypointModelListener
listener
)
{
this
.
listeners
.
add
(
listener
);
}
@Override
public
void
removeListener
(
WaypointModelListener
listener
)
{
this
.
listeners
.
remove
(
listener
);
}
private
void
notifyAddedWaypoint
(
Waypoint
waypoint
)
{
for
(
WaypointModelListener
l
:
listeners
)
{
l
.
addedWaypoint
(
waypoint
);
}
}
private
void
notifyModifiedWaypoints
()
{
for
(
WaypointModelListener
l
:
listeners
)
{
l
.
modifiedWaypoints
();
}
}
private
void
notifyAddedPath
(
Path
path
)
{
for
(
WaypointModelListener
l
:
listeners
)
{
l
.
addedPath
(
path
);
}
}
@Override
public
PositionVector
getMetricDimensions
()
{
return
worldDimensions
;
}
@Override
public
abstract
void
generateWaypoints
();
@Override
public
Set
<
Waypoint
>
getWaypoints
()
{
if
(
map
!=
null
)
{
return
map
.
getGraph
().
vertexSet
();
}
else
{
return
Sets
.
newHashSet
();
}
}
@Override
public
Set
<
Path
>
getPaths
()
{
return
map
.
getGraph
().
getAllEdges
();
}
@Override
public
List
<
Path
>
getShortestPath
(
Waypoint
start
,
Waypoint
end
)
{
DijkstraShortestPath
<
Waypoint
,
Path
>
dijkstrashortestpath
=
new
DijkstraShortestPath
<
Waypoint
,
Path
>(
map
.
getGraph
(),
start
,
end
);
List
<
Path
>
paths
=
dijkstrashortestpath
.
getPathEdgeList
();
return
dijkstrashortestpath
.
getPathEdgeList
();
}
@Override
public
int
getNumberOfWaypoints
()
{
return
map
.
getGraph
().
vertexSet
().
size
();
}
@Override
public
DefaultWeightedEdgeRetrievableGraph
<
Waypoint
,
Path
>
getGraph
()
{
if
(
map
==
null
)
return
null
;
return
map
.
getGraph
();
}
public
void
addWaypoint
(
Waypoint
wp
)
{
map
.
addWaypoint
(
wp
);
}
}
src/de/tud/kom/p2psim/impl/topology/waypoints/graph/Path.java
View file @
0c80da45
/*
* Copyright (c) 2005-2010 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.waypoints.graph
;
import
org.jgrapht.graph.DefaultWeightedEdge
;
/**
* Represents a simple weighted path between
* two way points.
*
* @author Fabio Zöllner
* @version 1.0, 27.03.2012
*/
public
class
Path
extends
DefaultWeightedEdge
{
private
Waypoint
source
;
private
Waypoint
target
;
private
double
weight
=
1
;
public
Path
(
Waypoint
source
,
Waypoint
target
)
{
this
.
source
=
source
;
this
.
target
=
target
;
double
d
=
source
.
getPosition
().
getD
istance
(
target
.
getPosition
());
weight
=
Math
.
abs
(
1
-
(
1
/
d
));
}
@Override
protected
double
getWeight
()
{
return
weight
;
}
public
Waypoint
getSource
()
{
return
source
;
}
public
Waypoint
getTarget
()
{
return
target
;
}
public
Waypoint
getOtherEnd
(
Waypoint
wp
)
{
if
(
source
.
equals
(
wp
))
return
target
;
return
source
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
Path
other
=
(
Path
)
obj
;
if
(
getWeight
()
!=
other
.
getWeight
()
||
!
source
.
equals
(
other
.
getSource
())
||
!
target
.
equals
(
other
.
getTarget
()))
return
false
;
return
true
;
}
@Override
public
String
toString
()
{
return
"Path[From: "
+
source
+
", To: "
+
target
+
", Weight: "
+
weight
+
"]"
;
}
}
/*
* Copyright (c) 2005-2010 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.waypoints.graph
;
import
org.jgrapht.graph.DefaultWeightedEdge
;
/**
* Represents a simple weighted path between
* two way points.
*
* @author Fabio Zöllner
* @version 1.0, 27.03.2012
*/
public
class
Path
extends
DefaultWeightedEdge
{
private
Waypoint
source
;
private
Waypoint
target
;
private
double
weight
=
1
;
public
Path
(
Waypoint
source
,
Waypoint
target
)
{
this
.
source
=
source
;
this
.
target
=
target
;
double
d
=
source
.
getPosition
().
d
istance
To
(
target
.
getPosition
());
weight
=
Math
.
abs
(
1
-
(
1
/
d
));
}
@Override
protected
double
getWeight
()
{
return
weight
;
}
public
Waypoint
getSource
()
{
return
source
;
}
public
Waypoint
getTarget
()
{
return
target
;
}
public
Waypoint
getOtherEnd
(
Waypoint
wp
)
{
if
(
source
.
equals
(
wp
))
return
target
;
return
source
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
Path
other
=
(
Path
)
obj
;
if
(
getWeight
()
!=
other
.
getWeight
()
||
!
source
.
equals
(
other
.
getSource
())
||
!
target
.
equals
(
other
.
getTarget
()))
return
false
;
return
true
;
}
@Override
public
String
toString
()
{
return
"Path[From: "
+
source
+
", To: "
+
target
+
", Weight: "
+
weight
+
"]"
;
}
}
Prev
1
2
3
4
Next
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