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
db8306ed
Commit
db8306ed
authored
Sep 10, 2019
by
Julian Zobel
Browse files
Merge branch 'jz/bachelor-thesis-louis-neumann' into jz/master
parents
a886bf18
bcf79843
Changes
40
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/AttractionPointMonitor.java
0 → 100644
View file @
db8306ed
/*
* 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.movement.modularosm.attraction
;
import
de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.Analyzer
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
public
interface
AttractionPointMonitor
extends
Analyzer
{
public
void
addedAttractionPoint
(
AttractionPoint
ap
);
public
void
removedAttractionPoint
(
AttractionPoint
ap
);
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/BasicAttractionPoint.java
View file @
db8306ed
...
...
@@ -2,6 +2,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
* A basic attraction point, as simple as it can get. Really just a named location
...
...
@@ -18,7 +19,11 @@ public class BasicAttractionPoint extends PositionVector implements AttractionPo
this
.
name
=
name
;
}
@XMLConfigurableConstructor
({
"name"
,
"x"
,
"y"
})
public
BasicAttractionPoint
(
String
name
,
double
x
,
double
y
)
{
this
(
name
,
new
PositionVector
(
x
,
y
));
}
@Override
public
String
getName
()
{
return
name
;
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/ConfigAttractionGenerator.java
View file @
db8306ed
...
...
@@ -19,10 +19,7 @@
*/
package
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction
;
import
java.util.LinkedList
;
import
java.util.List
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
/**
...
...
@@ -33,15 +30,14 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
*/
public
class
ConfigAttractionGenerator
implements
IAttractionGenerator
{
private
final
List
<
AttractionPoint
>
points
=
new
LinkedList
<>();
@Override
public
List
<
AttractionPoint
>
getAttractionPoints
()
{
return
p
oints
;
return
attractionP
oints
;
}
public
void
setAttractionPoint
(
AttractionPoint
point
)
{
this
.
p
oints
.
add
(
point
);
attractionP
oints
.
add
(
point
);
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/ConfigDynamicAttractionGenerator.java
0 → 100644
View file @
db8306ed
/*
* 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.movement.modularosm.attraction
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Random
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
* Implementation of the interface {@link AttractionGenerator}.
*
* @author Julian Zobel
* @version 1.0, April 2019
*/
public
class
ConfigDynamicAttractionGenerator
implements
IAttractionGenerator
{
private
LinkedList
<
TemporalAttractionPoint
>
allAPs
=
new
LinkedList
<>();
@Override
public
List
<
AttractionPoint
>
getAttractionPoints
()
{
return
attractionPoints
;
}
public
void
setAttractionPoint
(
TemporalAttractionPoint
ap
)
{
allAPs
.
add
(
ap
);
Event
.
scheduleWithDelay
(
ap
.
getPlacementTime
(),
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
placeAP
(
ap
);
}
},
null
,
0
);
}
private
void
placeAP
(
TemporalAttractionPoint
ap
)
{
attractionPoints
.
add
(
ap
);
Event
.
scheduleWithDelay
(
ap
.
getRemovalTime
(),
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
removeAP
(
ap
);
}
},
null
,
0
);
}
private
void
removeAP
(
TemporalAttractionPoint
ap
)
{
attractionPoints
.
remove
(
ap
);
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/CsvAttractionGenerator.java
View file @
db8306ed
...
...
@@ -47,7 +47,7 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
private
final
String
SEP
=
";"
;
private
List
<
AttractionPoint
>
attractionPoints
;
private
double
radius
=
0
;
/**
*
...
...
@@ -58,12 +58,17 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
this
.
worldDimensions
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
this
.
file
=
placementFile
;
readData
();
}
public
void
setRadius
(
double
radius
)
{
this
.
radius
=
radius
;
}
@Override
public
List
<
AttractionPoint
>
getAttractionPoints
()
{
if
(
attractionPoints
==
null
)
{
attractionPoints
=
new
LinkedList
<>();
if
(
attractionPoints
==
null
)
{
readData
();
}
return
attractionPoints
;
...
...
@@ -93,8 +98,37 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
+
y
);
continue
;
}
attractionPoints
.
add
(
new
AttractionPointImpl
(
"AP"
+
i
,
new
PositionVector
(
x
,
y
)));
AttractionPoint
ap
=
new
AttractionPointImpl
(
"AP"
+
i
,
new
PositionVector
(
x
,
y
));
ap
.
setRadius
(
radius
);
addAttractionPoint
(
ap
);
i
++;
entrySuccessfullyRead
=
true
;
}
catch
(
NumberFormatException
e
)
{
// Ignore leading comments
if
(
entrySuccessfullyRead
)
{
// System.err.println("CSV ParseError " + line);
}
}
}
else
if
(
parts
.
length
==
3
)
{
try
{
Double
x
=
Double
.
parseDouble
(
parts
[
0
]);
Double
y
=
Double
.
parseDouble
(
parts
[
1
]);
Double
r
=
Double
.
parseDouble
(
parts
[
2
]);
if
(
x
>
worldDimensions
.
getX
()
||
y
>
worldDimensions
.
getY
()
||
x
<
0
||
y
<
0
)
{
System
.
err
.
println
(
"Skipped entry "
+
x
+
";"
+
y
);
continue
;
}
AttractionPoint
ap
=
new
AttractionPointImpl
(
"AP"
+
i
,
new
PositionVector
(
x
,
y
));
ap
.
setRadius
(
r
);
addAttractionPoint
(
ap
);
i
++;
entrySuccessfullyRead
=
true
;
}
catch
(
NumberFormatException
e
)
{
...
...
@@ -104,6 +138,7 @@ public class CsvAttractionGenerator implements IAttractionGenerator {
}
}
}
}
else
{
throw
new
AssertionError
(
"To many columns in CSV."
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/EquidistantSquareAttractionGenerator.java
View file @
db8306ed
...
...
@@ -25,6 +25,7 @@ import de.tud.kom.p2psim.api.topology.Topology;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
* Implementation of the interface {@link AttractionGenerator}.
...
...
@@ -38,12 +39,15 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
public
class
EquidistantSquareAttractionGenerator
implements
IAttractionGenerator
{
private
PositionVector
worldDimension
;
private
double
squareSize
;
public
EquidistantSquareAttractionGenerator
()
{
@XMLConfigurableConstructor
({
"squareSize"
})
public
EquidistantSquareAttractionGenerator
(
double
squareSize
)
{
this
.
worldDimension
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
this
.
squareSize
=
squareSize
;
createAttractionPoints
();
}
...
...
@@ -56,23 +60,23 @@ public class EquidistantSquareAttractionGenerator implements IAttractionGenerato
}
private
void
createAttractionPoints
()
{
double
x
=
worldDimension
.
getX
()
/
2
;
double
y
=
worldDimension
.
getY
()
/
2
;
double
x
=
worldDimension
.
getX
();
double
y
=
worldDimension
.
getY
();
PositionVector
p1
=
new
PositionVector
(
x
/
4
,
y
/
4
);
PositionVector
p1
=
new
PositionVector
(
x
-
squareSize
,
y
-
squareSize
);
AttractionPoint
ap1
=
new
AttractionPointImpl
(
"AP1"
,
p1
);
attractionPoints
.
add
(
ap1
);
PositionVector
p2
=
new
PositionVector
(
x
/
4
+
x
/
2
,
y
/
4
);
PositionVector
p2
=
new
PositionVector
(
x
-
squareSize
,
y
+
squareSize
);
AttractionPoint
ap2
=
new
AttractionPointImpl
(
"AP2"
,
p2
);
attractionPoints
.
add
(
ap2
);
PositionVector
p3
=
new
PositionVector
(
x
/
4
+
x
/
2
,
y
/
4
+
y
/
2
);
PositionVector
p3
=
new
PositionVector
(
x
+
squareSize
,
y
-
squareSize
);
AttractionPoint
ap3
=
new
AttractionPointImpl
(
"AP3"
,
p3
);
attractionPoints
.
add
(
ap3
);
PositionVector
p4
=
new
PositionVector
(
x
/
4
,
y
/
4
+
y
/
2
);
PositionVector
p4
=
new
PositionVector
(
x
+
squareSize
,
y
+
squareSize
);
AttractionPoint
ap4
=
new
AttractionPointImpl
(
"AP4"
,
p4
);
attractionPoints
.
add
(
ap4
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/IAttractionGenerator.java
View file @
db8306ed
...
...
@@ -22,7 +22,8 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import
java.util.LinkedList
;
import
java.util.List
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
/**
...
...
@@ -33,8 +34,40 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
*/
public
interface
IAttractionGenerator
{
public
static
LinkedList
<
AttractionPoint
>
attractionPoints
=
new
LinkedList
<>();
// TODO make this private in JAVA >= 9
static
LinkedList
<
AttractionPoint
>
attractionPoints
=
new
LinkedList
<>();
public
List
<
AttractionPoint
>
getAttractionPoints
();
/**
* Remove an {@link AttractionPoint} from the list
* @param ap
*/
default
void
removeAttractionPoint
(
AttractionPoint
ap
)
{
if
(
Monitor
.
hasAnalyzer
(
AttractionPointMonitor
.
class
))
{
Monitor
.
getOrNull
(
AttractionPointMonitor
.
class
).
removedAttractionPoint
(
ap
);
}
attractionPoints
.
remove
(
ap
);
}
/**
* Add an {@link AttractionPoint} to the list
* @param ap
*/
default
void
addAttractionPoint
(
AttractionPoint
ap
)
{
if
(
ap
==
null
)
{
Monitor
.
log
(
IAttractionGenerator
.
class
,
Level
.
ERROR
,
"IAttractionGenerator: Tried to add NULL as Attraction Point"
);
return
;
}
if
(
Monitor
.
hasAnalyzer
(
AttractionPointMonitor
.
class
))
{
Monitor
.
getOrNull
(
AttractionPointMonitor
.
class
).
addedAttractionPoint
(
ap
);
}
attractionPoints
.
add
(
ap
);
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomAttractionGenerator.java
View file @
db8306ed
...
...
@@ -103,13 +103,19 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
if
(
c
<
20
)
{
// if not within the world dimensions, directly go back to calculation
if
(
posVec
.
getX
()
+
radius
>
worldDimension
.
getX
()
||
posVec
.
getY
()
+
radius
>
worldDimension
.
getY
()
||
posVec
.
getX
()
-
radius
<
0
||
posVec
.
getY
()
-
radius
<
0
)
{
i
--;
c
++;
continue
create
;
}
for
(
AttractionPoint
ap
:
result
)
{
// if this point is closer than the given minimum distance to another point, or the radii of the points would overlap,
// or if the radius would exceed the simulation area
// then discard this attraction point and create a new one
if
(
posVec
.
distanceTo
(
ap
)
<
minimumDistance
||
(
posVec
.
distanceTo
(
ap
)
-
radius
-
ap
.
getRadius
())
<
0
||
posVec
.
getX
()
+
radius
>
worldDimension
.
getX
()
||
posVec
.
getY
()
+
radius
>
worldDimension
.
getY
()
||
posVec
.
getX
()
-
radius
<
0
||
posVec
.
getY
()
-
radius
<
0
)
{
if
(
posVec
.
distanceTo
(
ap
)
<
minimumDistance
||
(
posVec
.
distanceTo
(
ap
)
-
radius
-
ap
.
getRadius
())
<
0
)
{
i
--;
c
++;
continue
create
;
...
...
@@ -118,7 +124,7 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
}
else
{
radius
=
10
;
radius
=
minimumRadius
;
}
AttractionPoint
aPoint
=
new
AttractionPointImpl
(
"AP-"
+
i
,
posVec
);
...
...
@@ -128,7 +134,10 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
}
attractionPoints
.
clear
();
attractionPoints
.
addAll
(
result
);
for
(
AttractionPoint
ap
:
result
)
{
addAttractionPoint
(
ap
);
}
}
private
PositionVector
createPosVec
()
{
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomDynamicAttractionGenerator.java
0 → 100644
View file @
db8306ed
/*
* 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.movement.modularosm.attraction
;
import
java.util.List
;
import
java.util.Random
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
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.Monitor
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor.Level
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
* Implementation of the interface {@link AttractionGenerator}.
*
* Generates a random number (out of a given interval) of attraction points. The radius is chosen randomly from a given interval.
* Generated attraction points will most likely not overlay and be completely within the world dimensions.
* With a certain lifetime chosen from a given lifetime interval, attraction points are removed after time and the number of
* attraction points that will be in the area are recalculated. If necessary, attraction points are either removed
* or added.
*
* @author Julian Zobel
* @version 1.0, March 2019
*/
public
class
RandomDynamicAttractionGenerator
implements
IAttractionGenerator
{
private
Random
rand
;
private
PositionVector
worldDimension
;
private
int
minNumberOfAttractionPoints
;
private
int
maxNumberOfAttractionPoints
;
private
long
minDynamicIntervall
;
private
long
maxDynamicIntervall
;
private
double
minimumDistance
=
100
;
private
double
maximumRadius
=
100
;
private
double
minimumRadius
=
10
;
@XMLConfigurableConstructor
({
"minNumberOfAttractionPoints"
,
"maxNumberOfAttractionPoints"
,
"minimumRadius"
,
"maximumRadius"
,
"minDynamicIntervall"
,
"maxDynamicIntervall"
,
"minimumDistance"
})
public
RandomDynamicAttractionGenerator
(
int
minNumberOfAttractionPoints
,
int
maxNumberOfAttractionPoints
,
double
minimumRadius
,
double
maximumRadius
,
long
minDynamicIntervall
,
long
maxDynamicIntervall
,
double
minimumDistance
)
{
this
.
rand
=
Randoms
.
getRandom
(
RandomDynamicAttractionGenerator
.
class
);
this
.
worldDimension
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
if
(
minNumberOfAttractionPoints
<=
0
)
{
throw
new
ConfigurationException
(
"NumberOfAttractionPoints should be at least 1!"
);
}
if
(
minNumberOfAttractionPoints
>
maxNumberOfAttractionPoints
)
{
throw
new
ConfigurationException
(
"Minimum and maximum numbers of attraction points not correctly set!"
);
}
this
.
minNumberOfAttractionPoints
=
minNumberOfAttractionPoints
;
this
.
maxNumberOfAttractionPoints
=
maxNumberOfAttractionPoints
;
this
.
minimumRadius
=
minimumRadius
;
this
.
maximumRadius
=
maximumRadius
;
this
.
minimumDistance
=
minimumDistance
;
this
.
minDynamicIntervall
=
minDynamicIntervall
;
this
.
maxDynamicIntervall
=
maxDynamicIntervall
;
attractionPoints
.
clear
();
updateAttractionPoints
();
}
@Override
public
List
<
AttractionPoint
>
getAttractionPoints
()
{
return
attractionPoints
;
}
/**
*
* @return an integer representing a randomly chosen number of attraction points within the allowed range of numbers
*/
private
int
randomNumberOfAttractionPoints
()
{
return
minNumberOfAttractionPoints
+
rand
.
nextInt
((
maxNumberOfAttractionPoints
-
minNumberOfAttractionPoints
)
+
1
);
}
private
void
scheduleDynamicEvent
(
AttractionPoint
attractionPoint
)
{
long
r
=
(
long
)
(
rand
.
nextDouble
()
*
(
maxDynamicIntervall
-
minDynamicIntervall
))
+
minDynamicIntervall
;
Event
.
scheduleWithDelay
(
r
,
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
// maybe was already removed...
if
(
attractionPoints
.
contains
(
attractionPoint
))
{
removeAttractionPoint
(
attractionPoint
);
updateAttractionPoints
();
}
}
},
null
,
0
);
}
protected
void
updateAttractionPoints
()
{
int
numberOfAttractionPoints
=
randomNumberOfAttractionPoints
();
// do nothing if this is the required amount of attraction points
if
(
numberOfAttractionPoints
==
attractionPoints
.
size
())
{
return
;
}
// remove until this number fits
else
if
(
numberOfAttractionPoints
<
attractionPoints
.
size
())
{
int
deltaAP
=
attractionPoints
.
size
()
-
numberOfAttractionPoints
;
for
(
int
i
=
0
;
i
<
deltaAP
;
i
++)
{
int
random
=
rand
.
nextInt
(
attractionPoints
.
size
());
removeAttractionPoint
(
attractionPoints
.
get
(
random
));
}
return
;
}
// add more attraction points until it fits
else
{
int
deltaAP
=
numberOfAttractionPoints
-
attractionPoints
.
size
();
for
(
int
i
=
0
;
i
<
deltaAP
;
i
++)
{
AttractionPoint
newAP
=
createAttractionPoint
();
scheduleDynamicEvent
(
newAP
);
addAttractionPoint
(
newAP
);
}
}
}
/**
* Create an attraction point that is conform to all other currently saved attraction points.
*
* @return
*/
private
AttractionPoint
createAttractionPoint
()
{
// make a break counter to prevent more than 100 iterations and an infinity loop in general.
int
c
=
100
;
create:
for
(
int
i
=
0
;
i
<
c
;
i
++)
{
PositionVector
posVec
=
createPosVec
();
// set the radius of this attraction point
// minimum radius is 10 meters
double
radius
=
Math
.
max
(
minimumRadius
,
rand
.
nextDouble
()
*
maximumRadius
);
if
(
i
<
c
)
{
// check if the attraction points would be completely within world dimensions (including radius!)
if
((
posVec
.
getX
()
+
radius
)
>=
worldDimension
.
getX
()
||
(
posVec
.
getY
()
+
radius
)
>=
worldDimension
.
getY
()
||
(
posVec
.
getX
()
-
radius
)
<=
0
||
(
posVec
.
getY
()
-
radius
)
<=
0
)
{
continue
create
;
}
// if within world dimensions, continue checking against other attraction points
for
(
AttractionPoint
ap
:
attractionPoints
)
{
// if this point is closer than the given minimum distance to another point, or the radii of the points would overlap,
// or if the radius would exceed the simulation area
// then discard this attraction point and create a new one
if
(
posVec
.
distanceTo
(
ap
)
<
minimumDistance
||
(
posVec
.
distanceTo
(
ap
)
-
radius
-
ap
.
getRadius
())
<
0
)
{
continue
create
;
}
}
}
else
{
radius
=
0
;
}
AttractionPoint
aPoint
=
new
AttractionPointImpl
(
"AP-"
+
rand
.
nextInt
(),
posVec
);
aPoint
.
setRadius
(
radius
);
return
aPoint
;
}
AttractionPoint
ap
=
new
AttractionPointImpl
(
"AP-ERROR"
,
new
PositionVector
(
worldDimension
.
getX
()
/
2
,
worldDimension
.
getY
()
/
2
));
ap
.
setRadius
(
0
);
ap
.
setWeight
(
0
);
Monitor
.
log
(
RandomDynamicAttractionGenerator
.
class
,
Level
.
WARN
,
"RandomDynamicAttractionGenerator could not find a suitable location for a new attraction point within 100 iterations."
);
return
ap
;
}
private
PositionVector
createPosVec
()
{
double
x
=
rand
.
nextDouble
()
*
worldDimension
.
getX
();
double
y
=
rand
.
nextDouble
()
*
worldDimension
.
getY
();
return
new
PositionVector
(
x
,
y
);
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/TemporalAttractionPoint.java
0 → 100644
View file @
db8306ed
/*
* 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.movement.modularosm.attraction
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
public
class
TemporalAttractionPoint
extends
BasicAttractionPoint
{
private
long
placementTime
;
private
long
removalTime
;
@XMLConfigurableConstructor
({
"name"
,
"x"
,
"y"
,
"radius"
,
"weight"
,
"placementTime"
,
"removalTime"
})
public
TemporalAttractionPoint
(
String
name
,
double
x
,
double
y
,
double
radius
,
double
weight
,
long
placementTime
,
long
removalTime
)
{
this
(
name
,
new
PositionVector
(
x
,
y
),
radius
,
weight
,
placementTime
,
removalTime
);
}
public
TemporalAttractionPoint
(
String
name
,
PositionVector
pos
,
double
radius
,
double
weight
,
long
placementTime
,
long
removalTime
)
{
super
(
name
,
pos
);
setWeight
(
weight
);
setRadius
(
radius
);
this
.
placementTime
=
placementTime
;
this
.
removalTime
=
removalTime
;
}
public
long
getPlacementTime
()
{
return
placementTime
;
}
public
long
getRemovalTime
()
{
return
removalTime
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/TwoPointFixedAttractionGenerator.java
View file @
db8306ed
...
...
@@ -25,6 +25,7 @@ import de.tud.kom.p2psim.api.topology.Topology;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
* Implementation of the interface {@link AttractionGenerator}.
...
...
@@ -39,11 +40,19 @@ public class TwoPointFixedAttractionGenerator implements IAttractionGenerator {
private
PositionVector
worldDimension
;
public
TwoPointFixedAttractionGenerator
()
{
private
double
x1
,
x2
,
y1
,
y2
;
@XMLConfigurableConstructor
({
"x1"
,
"y1"
,
"x2"
,
"y2"
})
public
TwoPointFixedAttractionGenerator
(
double
x1
,
double
y1
,
double
x2
,
double
y2
)
{
this
.
worldDimension
=
Binder
.
getComponentOrNull
(
Topology
.
class
)
.
getWorldDimensions
();
this
.
x1
=
x1
;
this
.
y1
=
y1
;
this
.
x2
=
x2
;
this
.
y2
=
y2
;
createAttractionPoints
();
}
...
...
@@ -56,16 +65,16 @@ public class TwoPointFixedAttractionGenerator implements IAttractionGenerator {
}
private
void
createAttractionPoints
()
{
double
x
=
worldDimension
.
getX
();
double
y
=
worldDimension
.
getY
();
PositionVector
p1
=
new
PositionVector
(
0
+
0.1
*
x
,
y
/
2
);
PositionVector
p1
=
new
PositionVector
(
x1
,
y1
);
AttractionPoint
ap1
=
new
AttractionPointImpl
(
"AP1"
,
p1
);
ap1
.
setRadius
(
100
);
attractionPoints
.
add
(
ap1
);
PositionVector
p2
=
new
PositionVector
(
0.9
*
x
,
y
/
2
);
PositionVector
p2
=
new
PositionVector
(
x2
,
y2
);
AttractionPoint
ap2
=
new
AttractionPointImpl
(
"AP2"
,
p2
);
ap2
.
setRadius
(
100
);
attractionPoints
.
add
(
ap2
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/AbstractAttractionBasedTransitionStrategy.java
View file @
db8306ed
...
...
@@ -44,9 +44,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
public
abstract
class
AbstractAttractionBasedTransitionStrategy
implements
ITransitionStrategy
{
protected
Random
rnd
=
Randoms
.
getRandom
(
AbstractAttractionBasedTransitionStrategy
.
class
);
protected
Set
<
AttractionPoint
>
attractionPoints
=
new
LinkedHashSet
<>();
protected
Map
<
SimLocationActuator
,
AttractionPoint
>
assignments
=
new
LinkedHashMap
<>();
protected
Map
<
SimLocationActuator
,
AttractionPoint
>
lastAssignments
=
new
LinkedHashMap
<>();
...
...
@@ -76,18 +74,6 @@ public abstract class AbstractAttractionBasedTransitionStrategy implements ITran
listeners
.
remove
(
listener
);
}
@Override
public
void
setAttractionPoints
(
Collection
<
AttractionPoint
>
attractionPoints
)
{
this
.
attractionPoints
.
clear
();
this
.
attractionPoints
.
addAll
(
attractionPoints
);
}
@Override
public
Set
<
AttractionPoint
>
getAllAttractionPoints
()
{
return
Collections
.
unmodifiableSet
(
attractionPoints
);
}
/**
* Notify all listeners of an updated attraction point assignment for the given component
*
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/FixedAssignmentStrategy.java
View file @
db8306ed
...
...
@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.common.SimHost;
import
de.tud.kom.p2psim.api.common.SimHostComponent
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
/**
...
...
@@ -57,14 +58,14 @@ public class FixedAssignmentStrategy extends AbstractAttractionBasedTransitionSt
// No assignments been done before.
if
(
assignments
.
isEmpty
())
{
AttractionPoint
aPoint
=
attractionPoints
.
iterator
().
next
();
AttractionPoint
aPoint
=
IAttractionGenerator
.
attractionPoints
.
iterator
().
next
();
assignments
.
put
(
ms
,
aPoint
);
mappingGroupId
(
ms
,
aPoint
);
}
// GroupId is not mapped.
else
if
(!
mappingGroupIdAP
.
containsKey
(
mappingMSHost
.
get
(
ms
)
.
getProperties
().
getGroupID
()))
{
for
(
AttractionPoint
actAP
:
attractionPoints
)
{
for
(
AttractionPoint
actAP
:
IAttractionGenerator
.
attractionPoints
)
{
if
(!
mappingAPGroupId
.
containsKey
(
actAP
))
{
assignments
.
put
(
ms
,
actAP
);
mappingGroupId
(
ms
,
actAP
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/ITransitionStrategy.java
View file @
db8306ed
...
...
@@ -46,21 +46,6 @@ public interface ITransitionStrategy {
public
void
removeAttractionAssignmentListener
(
AttractionAssignmentListener
listener
);
/**
* Should be called first, to add the Attraction Points for the assignment!
*
* @param attractionPoints
*/
public
void
setAttractionPoints
(
Collection
<
AttractionPoint
>
attractionPoints
);
/**
* Return a set of all attraction points
*
* @return
*/
public
Set
<
AttractionPoint
>
getAllAttractionPoints
();
/**
* Add the object and assign the MS to an {@link AttractionPoint}.
*
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java
View file @
db8306ed
...
...
@@ -26,6 +26,7 @@ import java.util.List;
import
java.util.Map
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
...
...
@@ -53,7 +54,7 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
@Override
public
void
addComponent
(
SimLocationActuator
comp
)
{
this
.
roamingStates
.
put
(
comp
,
roamingTransitionState
.
TRANSITION
);
AttractionPoint
nextAP
=
get
NewAttractionPoint
(
comp
);
AttractionPoint
nextAP
=
pick
NewAttractionPoint
(
comp
);
updateTargetAttractionPoint
(
comp
,
nextAP
);
}
...
...
@@ -94,32 +95,52 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
if
(
type
==
EVENT_PAUSE_ENDED
)
{
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
this
.
addComponent
(
comp
);
if
(
type
==
EVENT_PAUSE_ENDED
)
{
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
// if the transit was triggered beforehand (e.g., attraction point moved), then do nothing.
if
(
roamingStates
.
get
(
comp
)
!=
roamingTransitionState
.
TRANSITION
)
{
this
.
addComponent
(
comp
);
}
}
else
if
(
type
==
EVENT_ROAMING_PAUSE_ENDED
)
{
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
this
.
roamAroundAttractionPoint
(
comp
);
AttractionPoint
currentAttractionPoint
=
this
.
assignments
.
get
(
comp
);
// if the attraction point was removed in the meantime, go directly to transit state
if
(
currentAttractionPoint
==
null
||
!
IAttractionGenerator
.
attractionPoints
.
contains
(
currentAttractionPoint
))
{
this
.
addComponent
(
comp
);
}
else
{
this
.
roamAroundAttractionPoint
(
comp
);
}
}
}
private
AttractionPoint
get
NewAttractionPoint
(
SimLocationActuator
component
)
{
double
score
=
rnd
.
nextDouble
();
private
AttractionPoint
pick
NewAttractionPoint
(
SimLocationActuator
component
)
{
double
score
=
rnd
.
nextDouble
();
List
<
AttractionPoint
>
candidates
=
new
LinkedList
<>();
for
(
AttractionPoint
ap
:
attractionPoints
)
{
for
(
AttractionPoint
ap
:
IAttractionGenerator
.
attractionPoints
)
{
if
(
ap
==
null
)
{
continue
;
}
if
(
ap
.
getWeight
()
>=
score
)
{
if
(
lastAssignments
.
get
(
component
)
==
null
||
!
ap
.
equals
(
lastAssignments
.
get
(
component
)))
{
candidates
.
add
(
ap
);
}
}
}
if
(
candidates
.
isEmpty
())
{
candidates
.
addAll
(
attractionPoints
);
candidates
.
addAll
(
IAttractionGenerator
.
attractionPoints
);
}
AttractionPoint
assignment
=
candidates
.
get
(
rnd
.
nextInt
(
candidates
.
size
()));
return
assignment
;
return
assignment
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/ManualAssignmentStrategy.java
View file @
db8306ed
...
...
@@ -40,12 +40,10 @@ public class ManualAssignmentStrategy implements ITransitionStrategy
listeners
.
remove
(
listener
);
}
@Override
public
void
setAttractionPoints
(
Collection
<
AttractionPoint
>
attractionPoints
)
{
aPoints
.
addAll
(
attractionPoints
);
}
@Override
public
Set
<
AttractionPoint
>
getAllAttractionPoints
()
{
return
aPoints
;
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/RandomInAreaTransitionStrategy.java
View file @
db8306ed
...
...
@@ -5,6 +5,7 @@ import java.util.Map;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.BasicAttractionPoint
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.Monitor
;
...
...
@@ -48,7 +49,7 @@ public class RandomInAreaTransitionStrategy extends AbstractAttractionBasedTrans
if
(!
assignments
.
containsKey
(
ms
))
{
AttractionPoint
aPoint
=
attractionPoints
.
iterator
().
next
();
AttractionPoint
aPoint
=
IAttractionGenerator
.
attractionPoints
.
iterator
().
next
();
assignments
.
put
(
ms
,
aPoint
);
currentTarget
.
put
(
ms
,
nextRandomPosition
(
aPoint
,
defaultRadius
));
currentSearchRadius
.
put
(
ms
,
defaultRadius
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/SocialTransitionStrategy.java
View file @
db8306ed
...
...
@@ -38,6 +38,7 @@ import de.tud.kom.p2psim.api.topology.Topology;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.api.topology.social.SocialView
;
import
de.tud.kom.p2psim.impl.simengine.Simulator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Binder
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
...
...
@@ -131,12 +132,6 @@ public class SocialTransitionStrategy extends AbstractAttractionBasedTransitionS
public
void
setSocialId
(
String
socialId
)
{
this
.
socialId
=
socialId
;
}
@Override
public
void
setAttractionPoints
(
Collection
<
AttractionPoint
>
attractionPoints
)
{
init
();
super
.
setAttractionPoints
(
attractionPoints
);
}
@Override
public
void
addComponent
(
SimLocationActuator
ms
)
{
...
...
@@ -146,8 +141,8 @@ public class SocialTransitionStrategy extends AbstractAttractionBasedTransitionS
// position.
// TODO: needed? We do Transition as next, and this will delete the
// assignment..
AttractionPoint
nearest
=
attractionPoints
.
iterator
().
next
();
for
(
AttractionPoint
aPoint
:
attractionPoints
)
{
AttractionPoint
nearest
=
IAttractionGenerator
.
attractionPoints
.
iterator
().
next
();
for
(
AttractionPoint
aPoint
:
IAttractionGenerator
.
attractionPoints
)
{
if
(
nearest
.
distanceTo
(
ms
.
getRealPosition
())
>
aPoint
.
distanceTo
(
ms
.
getRealPosition
()))
{
nearest
=
aPoint
;
...
...
@@ -181,7 +176,7 @@ public class SocialTransitionStrategy extends AbstractAttractionBasedTransitionS
List
<
AttractionPoint
>
apFriends
=
getFriendsPlaces
(
ms
);
List
<
AttractionPoint
>
apClusters
=
getClusterPlaces
(
ms
);
List
<
AttractionPoint
>
apRandom
=
getRandomPlaces
(
ms
,
(
int
)
Math
.
max
(
attractionPoints
.
size
()
*
0.2
,
5
));
(
int
)
Math
.
max
(
IAttractionGenerator
.
attractionPoints
.
size
()
*
0.2
,
5
));
AttractionPoint
ap
=
null
;
if
(
rnd
.
nextDouble
()
<
socialFactor
)
{
...
...
@@ -299,7 +294,7 @@ public class SocialTransitionStrategy extends AbstractAttractionBasedTransitionS
private
List
<
AttractionPoint
>
getRandomPlaces
(
SimLocationActuator
ms
,
int
number
)
{
List
<
AttractionPoint
>
result
=
new
Vector
<
AttractionPoint
>(
attractionPoints
);
List
<
AttractionPoint
>
result
=
new
Vector
<
AttractionPoint
>(
IAttractionGenerator
.
attractionPoints
);
Collections
.
shuffle
(
result
,
rnd
);
return
result
.
subList
(
0
,
Math
.
min
(
result
.
size
(),
number
));
}
...
...
@@ -339,7 +334,7 @@ public class SocialTransitionStrategy extends AbstractAttractionBasedTransitionS
private
void
assignFavoritePlaces
(
SimLocationActuator
ms
)
{
Set
<
AttractionPoint
>
msFavoritePlaces
=
new
LinkedHashSet
<
AttractionPoint
>();
LinkedList
<
AttractionPoint
>
temp
=
new
LinkedList
<
AttractionPoint
>(
attractionPoints
);
IAttractionGenerator
.
attractionPoints
);
Collections
.
shuffle
(
temp
,
rnd
);
for
(
int
i
=
0
;
i
<
numberOfFavoritePlaces
;
i
++)
{
if
(!
temp
.
isEmpty
())
{
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/WeightedTransitionStrategy.java
View file @
db8306ed
...
...
@@ -23,6 +23,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import
java.util.LinkedList
;
import
java.util.List
;
import
de.tud.kom.p2psim.api.topology.movement.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
...
...
@@ -50,13 +51,13 @@ public class WeightedTransitionStrategy extends AbstractAttractionBasedTransitio
private
AttractionPoint
getNewAssignment
(
SimLocationActuator
component
)
{
double
score
=
rnd
.
nextDouble
();
List
<
AttractionPoint
>
candidates
=
new
LinkedList
<>();
for
(
AttractionPoint
ap
:
attractionPoints
)
{
for
(
AttractionPoint
ap
:
IAttractionGenerator
.
attractionPoints
)
{
if
(
ap
.
getWeight
()
>=
score
)
{
candidates
.
add
(
ap
);
}
}
if
(
candidates
.
isEmpty
())
{
candidates
.
addAll
(
attractionPoints
);
candidates
.
addAll
(
IAttractionGenerator
.
attractionPoints
);
}
AttractionPoint
assignment
=
candidates
.
get
(
rnd
.
nextInt
(
candidates
.
size
()));
notifyListenersOfAssignmentUpdate
(
component
,
assignment
);
...
...
src/de/tud/kom/p2psim/impl/topology/util/PositionVector.java
View file @
db8306ed
...
...
@@ -25,6 +25,7 @@ import java.util.Arrays;
import
com.vividsolutions.jts.geom.Coordinate
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
/**
...
...
@@ -53,7 +54,11 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
* assertions. Replace does now fully replace the position vector entries. PVs are now
* always at least 3D (with 0 altitude)
*
* @author Bjoern Richerzhagen, Julian Zobel
* - 14.03.2019 Louis Neumann: Added timestamp when creating a PositionVector and adjusted ageOfLocation()
*
* - 04.06.2019 Julian Zobel: Clone function also clones the timestamp from the cloned position.
*
* @author Bjoern Richerzhagen, Julian Zobel, Louis Neumann
* @version 1.2, 10.09.2018
*/
public
class
PositionVector
implements
Location
{
...
...
@@ -67,6 +72,10 @@ public class PositionVector implements Location {
private
double
[]
values
;
private
double
accuracy
=
-
1
;
/**
* Timestamp with time when created
*/
private
long
created
;
/**
* Create a new Position Vector
...
...
@@ -84,6 +93,7 @@ public class PositionVector implements Location {
this
.
dimensions
=
dimensions
;
this
.
values
=
new
double
[
dimensions
];
this
.
created
=
Time
.
getCurrentTime
();
}
/**
...
...
@@ -97,6 +107,8 @@ public class PositionVector implements Location {
for
(
int
i
=
0
;
i
<
vec
.
getDimensions
();
i
++)
{
setEntry
(
i
,
vec
.
getEntry
(
i
));
}
this
.
created
=
Time
.
getCurrentTime
();
}
public
PositionVector
(
double
longitudeOrX
,
double
latitudeOrY
)
{
...
...
@@ -104,6 +116,7 @@ public class PositionVector implements Location {
this
.
setLatitudeOrY
(
latitudeOrY
);
this
.
setLongitudeOrX
(
longitudeOrX
);
this
.
setAltitude
(
0
);
this
.
created
=
Time
.
getCurrentTime
();
}
public
PositionVector
(
double
longitudeOrX
,
double
latitudeOrY
,
double
altitude
)
{
...
...
@@ -111,6 +124,7 @@ public class PositionVector implements Location {
this
.
setLatitudeOrY
(
latitudeOrY
);
this
.
setLongitudeOrX
(
longitudeOrX
);
this
.
setAltitude
(
altitude
);
this
.
created
=
Time
.
getCurrentTime
();
}
public
PositionVector
(
Location
location
)
{
...
...
@@ -126,6 +140,7 @@ public class PositionVector implements Location {
this
.
setLatitudeOrY
(
location
.
getLatitudeOrY
());
this
.
setLongitudeOrX
(
location
.
getLongitudeOrX
());
this
.
created
=
Time
.
getCurrentTime
();
}
/**
...
...
@@ -139,6 +154,7 @@ public class PositionVector implements Location {
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
setEntry
(
i
,
values
[
i
]);
}
this
.
created
=
Time
.
getCurrentTime
();
}
@Override
...
...
@@ -146,7 +162,9 @@ public class PositionVector implements Location {
/*
* If you extend Position Vector, make sure to overwrite this method!
*/
return
new
PositionVector
(
this
);
// use clone constructor
PositionVector
clone
=
new
PositionVector
(
this
);
// use clone constructor
clone
.
setTimestamp
(
this
.
created
);
return
clone
;
}
...
...
@@ -539,7 +557,11 @@ public class PositionVector implements Location {
@Override
public
long
getAgeOfLocation
()
{
return
0
;
// always a fresh location
return
Time
.
getCurrentTime
()
-
created
;
}
private
void
setTimestamp
(
long
locationTimestamp
)
{
this
.
created
=
locationTimestamp
;
}
@Override
...
...
@@ -584,4 +606,6 @@ public class PositionVector implements Location {
}
}
Prev
1
2
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