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
74c2e2f4
Commit
74c2e2f4
authored
Mar 11, 2019
by
Julian Zobel
Browse files
Random Dynamic Attraction Poins now provide full funcationality
parent
b0947a8e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomDynamicAttractionGenerator.java
View file @
74c2e2f4
...
...
@@ -20,7 +20,6 @@
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
;
...
...
@@ -30,18 +29,20 @@ 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.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName
;
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 the given number of {@link AttractionPoint}s
* 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
0
.0
* @version
1
.0
, March 2019
*/
public
class
RandomDynamicAttractionGenerator
implements
IAttractionGenerator
{
...
...
@@ -81,6 +82,9 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
this
.
minNumberOfAttractionPoints
=
minNumberOfAttractionPoints
;
this
.
maxNumberOfAttractionPoints
=
maxNumberOfAttractionPoints
;
this
.
minimumRadius
=
minimumRadius
;
this
.
maximumRadius
=
maximumRadius
;
this
.
minDynamicIntervall
=
minDynamicIntervall
;
this
.
maxDynamicIntervall
=
maxDynamicIntervall
;
...
...
@@ -163,27 +167,28 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
// set the radius of this attraction point
// minimum radius is 10 meters
double
radius
=
Math
.
max
(
minimumRadius
,
rand
.
nextDouble
()
*
maximumRadius
);
System
.
out
.
println
(
radius
);
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
;
}
// is within world dimensions, so continue checking against other attraction points
else
{
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
;
}
}
}
// 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
=
1
0
;
else
{
radius
=
0
;
}
AttractionPoint
aPoint
=
new
AttractionPointImpl
(
"AP-"
+
rand
.
nextInt
(),
posVec
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java
View file @
74c2e2f4
...
...
@@ -98,20 +98,18 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
if
(
type
==
EVENT_PAUSE_ENDED
)
{
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
if
(
roamingStates
.
get
(
comp
)
==
roamingTransitionState
.
TRANSITION
)
{
System
.
out
.
println
(
"already in transition state!"
);
}
else
{
// 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
;
SimLocationActuator
comp
=
(
SimLocationActuator
)
content
;
AttractionPoint
currentAttractionPoint
=
this
.
assignments
.
get
(
comp
);
if
(!
IAttractionGenerator
.
attraction
P
oint
s
.
contains
(
currentAttractionPoint
))
{
System
.
out
.
println
(
"Assigned AP not available!"
);
// if the
attraction
p
oint
was removed in the meantime, go directly to transit state
if
(!
IAttractionGenerator
.
attractionPoints
.
contains
(
currentAttractionPoint
))
{
this
.
addComponent
(
comp
);
}
else
{
...
...
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