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
0d921e5e
Commit
0d921e5e
authored
Nov 22, 2017
by
Tobias Meuser
Committed by
Jose Ignacio Monreal Bailey
Aug 20, 2019
Browse files
Fist evaluation version for geographical relevance
parent
4b8c82a8
Changes
6
Show whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/VehicleMovementModel.java
View file @
0d921e5e
...
@@ -26,6 +26,7 @@ import java.util.LinkedList;
...
@@ -26,6 +26,7 @@ import java.util.LinkedList;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Queue
;
import
java.util.Queue
;
import
java.util.Random
;
import
de.tud.kom.p2psim.api.network.SimNetInterface
;
import
de.tud.kom.p2psim.api.network.SimNetInterface
;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
...
@@ -38,6 +39,7 @@ import de.tud.kom.p2psim.impl.vehicular.DefaultVehicleInformationComponent;
...
@@ -38,6 +39,7 @@ import de.tud.kom.p2psim.impl.vehicular.DefaultVehicleInformationComponent;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID
;
import
de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
...
@@ -50,6 +52,8 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
...
@@ -50,6 +52,8 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public
class
VehicleMovementModel
implements
MovementModel
,
EventHandler
{
public
class
VehicleMovementModel
implements
MovementModel
,
EventHandler
{
private
Random
_knownRoutesRandom
=
Randoms
.
getRandom
(
getClass
());
private
static
final
Location
DEFAULT_LOCATION
=
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
);
private
static
final
Location
DEFAULT_LOCATION
=
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
);
private
boolean
_reuseComponents
=
false
;
private
boolean
_reuseComponents
=
false
;
...
@@ -88,6 +92,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -88,6 +92,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
private
List
<
Location
>
intersections
;
private
List
<
Location
>
intersections
;
private
double
_percentageOfKnownRoutes
=
1
;
/**
/**
* Constructor for the movement model using the sumo TraCI API
* Constructor for the movement model using the sumo TraCI API
* @param timeBetweenMoveOperations The time between two movement operations.
* @param timeBetweenMoveOperations The time between two movement operations.
...
@@ -143,6 +149,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -143,6 +149,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
this
.
height
=
height
;
this
.
height
=
height
;
}
}
/**
* @param pPercentageOfKnownRoutes the percentageOfKnownRoutes to set
*/
public
void
setPercentageOfKnownRoutes
(
double
pPercentageOfKnownRoutes
)
{
_percentageOfKnownRoutes
=
pPercentageOfKnownRoutes
;
}
public
void
setReuseComponents
(
boolean
pReuseComponents
)
{
public
void
setReuseComponents
(
boolean
pReuseComponents
)
{
_reuseComponents
=
pReuseComponents
;
_reuseComponents
=
pReuseComponents
;
...
@@ -358,7 +371,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -358,7 +371,13 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
vehicularHostComponent
=
simLocationActuator
.
getHost
().
getComponent
(
VehicleInformationComponent
.
class
);
vehicularHostComponent
=
simLocationActuator
.
getHost
().
getComponent
(
VehicleInformationComponent
.
class
);
}
catch
(
ComponentNotAvailableException
e
)
{
}
catch
(
ComponentNotAvailableException
e
)
{
Host
host
=
simLocationActuator
.
getHost
();
Host
host
=
simLocationActuator
.
getHost
();
vehicularHostComponent
=
new
DefaultVehicleInformationComponent
(
host
,
_controller
,
_extractor
);
boolean
routeKnown
;
if
(
_knownRoutesRandom
.
nextDouble
()
<
_percentageOfKnownRoutes
)
{
routeKnown
=
true
;
}
else
{
routeKnown
=
false
;
}
vehicularHostComponent
=
new
DefaultVehicleInformationComponent
(
host
,
_controller
,
_extractor
,
routeKnown
);
host
.
registerComponent
(
vehicularHostComponent
);
host
.
registerComponent
(
vehicularHostComponent
);
}
}
vehicularHostComponent
.
setVehicleID
(
vehicle
);
vehicularHostComponent
.
setVehicleID
(
vehicle
);
...
...
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/VehicleInformationContainer.java
View file @
0d921e5e
...
@@ -21,17 +21,20 @@
...
@@ -21,17 +21,20 @@
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller
;
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute
;
public
class
VehicleInformationContainer
{
public
class
VehicleInformationContainer
{
private
Location
_position
;
private
Location
_position
;
private
double
_heading
;
private
double
_heading
;
private
double
_speed
;
private
double
_speed
;
private
RoadNetworkRoute
_route
;
public
VehicleInformationContainer
(
Location
pPosition
,
double
pHeading
,
public
VehicleInformationContainer
(
Location
pPosition
,
double
pHeading
,
double
pSpeed
)
{
double
pSpeed
,
RoadNetworkRoute
pRoute
)
{
_position
=
pPosition
;
_position
=
pPosition
;
_heading
=
pHeading
;
_heading
=
pHeading
;
_speed
=
pSpeed
;
_speed
=
pSpeed
;
_route
=
pRoute
;
}
}
public
Location
getPosition
()
{
public
Location
getPosition
()
{
...
@@ -45,4 +48,8 @@ public class VehicleInformationContainer {
...
@@ -45,4 +48,8 @@ public class VehicleInformationContainer {
public
double
getSpeed
()
{
public
double
getSpeed
()
{
return
_speed
;
return
_speed
;
}
}
public
RoadNetworkRoute
getRoute
()
{
return
_route
;
}
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java
View file @
0d921e5e
...
@@ -7,7 +7,6 @@ import java.io.IOException;
...
@@ -7,7 +7,6 @@ import java.io.IOException;
import
java.io.ObjectInputStream
;
import
java.io.ObjectInputStream
;
import
java.io.ObjectOutputStream
;
import
java.io.ObjectOutputStream
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -75,9 +74,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -75,9 +74,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
private
double
_endX
;
private
double
_endX
;
private
double
_endY
;
private
double
_endY
;
private
Map
<
Double
,
Map
<
String
,
VehicleInformationContainer
>>
_positonsByTimestamp
=
new
HashMap
<>();
private
Map
<
String
,
VehicleInformationContainer
>
_positons
=
new
HashMap
<>();
private
int
_futureInformation
=
0
;
private
boolean
_initalized
=
false
;
private
boolean
_initalized
=
false
;
...
@@ -120,10 +117,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -120,10 +117,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
try
{
try
{
_connection
.
runServer
();
_connection
.
runServer
();
for
(
int
i
=
0
;
i
<
_futureInformation
;
i
++)
{
nextStep
();
}
}
catch
(
RuntimeException
e
)
{
}
catch
(
RuntimeException
e
)
{
throw
e
;
throw
e
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -149,14 +142,15 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -149,14 +142,15 @@ public class TraciSimulationController implements VehicleController, SimulationS
@Override
@Override
public
Location
getVehiclePosition
(
String
pVehicleID
)
{
public
Location
getVehiclePosition
(
String
pVehicleID
)
{
return
getVehiclePosition
(
_step
,
pVehicleID
);
return
_positons
.
get
(
p
Vehicle
ID
).
get
Position
();
}
}
@Override
@Override
public
Location
getVehiclePosition
(
double
pStep
,
String
pVehicleID
)
{
public
Location
getVehiclePosition
(
double
pStep
,
String
pVehicleID
)
{
Map
<
String
,
VehicleInformationContainer
>
map
=
_positonsByTimestamp
.
get
(
pStep
);
if
(
pStep
==
_step
)
{
return
getVehiclePosition
(
pVehicleID
);
return
map
.
get
(
pVehicleID
).
getPosition
();
}
throw
new
UnsupportedOperationException
(
"Future locations is not supported anymore!"
);
}
}
@Override
@Override
...
@@ -214,18 +208,18 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -214,18 +208,18 @@ public class TraciSimulationController implements VehicleController, SimulationS
_connection
.
do_timestep
();
_connection
.
do_timestep
();
try
{
try
{
synchronized
(
_positons
)
{
_positons
.
clear
();
int
temp
=
(
Integer
)
_connection
.
do_job_get
(
Simulation
.
getCurrentTime
());
int
temp
=
(
Integer
)
_connection
.
do_job_get
(
Simulation
.
getCurrentTime
());
_step
=
temp
/
1000.0
-
_futureInformation
;
_step
=
temp
/
1000.0
;
if
(
_start
==
-
1
)
{
if
(
_start
==
-
1
)
{
_start
=
_step
+
_futureInformation
;
_start
=
_step
;
}
}
double
newStep
=
_step
+
_futureInformation
;
if
(!
_positonsByTimestamp
.
containsKey
(
newStep
))
{
Map
<
String
,
VehicleInformationContainer
>
vehiclePositions
=
new
HashMap
<>();
Map
<
String
,
VehicleInformationContainer
>
vehiclePositions
=
new
HashMap
<>();
_positonsByTimestamp
.
put
(
newStep
,
vehiclePositions
);
List
<
String
>
allVehicles
=
requestAllVehicles
();
List
<
String
>
allVehicles
=
requestAllVehicles
();
for
(
String
vehicle
:
allVehicles
)
{
for
(
String
vehicle
:
allVehicles
)
{
...
@@ -233,16 +227,14 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -233,16 +227,14 @@ public class TraciSimulationController implements VehicleController, SimulationS
if
(
position
!=
null
)
{
if
(
position
!=
null
)
{
double
heading
=
requestVehicleHeading
(
vehicle
);
double
heading
=
requestVehicleHeading
(
vehicle
);
double
speed
=
requestVehicleSpeed
(
vehicle
);
double
speed
=
requestVehicleSpeed
(
vehicle
);
RoadNetworkRoute
route
=
requestVehicleRoute
(
vehicle
);
VehicleInformationContainer
informationContainer
=
new
VehicleInformationContainer
(
position
,
heading
,
speed
);
VehicleInformationContainer
informationContainer
=
new
VehicleInformationContainer
(
position
,
heading
,
speed
,
route
);
vehiclePositions
.
put
(
vehicle
,
informationContainer
);
vehiclePositions
.
put
(
vehicle
,
informationContainer
);
}
}
}
}
}
_positons
=
vehiclePositions
;
if
(
_positonsByTimestamp
.
containsKey
(
_step
-
1
))
{
_positonsByTimestamp
.
remove
(
_step
-
1
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -364,9 +356,10 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -364,9 +356,10 @@ public class TraciSimulationController implements VehicleController, SimulationS
@Override
@Override
public
List
<
String
>
getAllVehicles
(
double
pStep
)
{
public
List
<
String
>
getAllVehicles
(
double
pStep
)
{
Map
<
String
,
VehicleInformationContainer
>
map
=
_positonsByTimestamp
.
get
(
pStep
);
if
(
pStep
==
_step
)
{
return
new
ArrayList
<>(
_positons
.
keySet
());
return
new
ArrayList
<>(
map
.
keySet
());
}
throw
new
UnsupportedOperationException
(
"Future locations is not supported anymore!"
);
}
}
public
RoadNetworkEdge
getCurrentEdge
(
String
pVehicleID
)
{
public
RoadNetworkEdge
getCurrentEdge
(
String
pVehicleID
)
{
...
@@ -387,10 +380,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -387,10 +380,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
return
edge
;
return
edge
;
}
}
@Override
public
RoadNetworkRoute
requestVehicleRoute
(
String
pVehicleID
)
{
public
RoadNetworkRoute
getCurrentRoute
(
String
pVehicleID
)
{
obtainRoadNetwork
();
obtainRoadNetwork
();
synchronized
(
_positons
)
{
List
<
RoadNetworkEdge
>
streets
=
new
ArrayList
<>();
SumoCommand
routeCommand
=
Vehicle
.
getRoute
(
pVehicleID
);
SumoCommand
routeCommand
=
Vehicle
.
getRoute
(
pVehicleID
);
Object
object
=
requestObject
(
routeCommand
);
Object
object
=
requestObject
(
routeCommand
);
SumoStringList
streetList
=
(
SumoStringList
)
object
;
SumoStringList
streetList
=
(
SumoStringList
)
object
;
...
@@ -401,7 +396,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -401,7 +396,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
return
null
;
return
null
;
}
}
List
<
RoadNetworkEdge
>
streets
=
new
ArrayList
<>();
boolean
add
=
false
;
boolean
add
=
false
;
for
(
String
street
:
streetList
)
{
for
(
String
street
:
streetList
)
{
if
(
street
.
equals
(
currentEdge
.
getEdgeID
()))
{
if
(
street
.
equals
(
currentEdge
.
getEdgeID
()))
{
...
@@ -419,6 +413,15 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -419,6 +413,15 @@ public class TraciSimulationController implements VehicleController, SimulationS
return
new
RoadNetworkRoute
(
streets
);
return
new
RoadNetworkRoute
(
streets
);
}
}
}
@Override
public
RoadNetworkRoute
getCurrentRoute
(
String
pVehicleID
)
{
if
(
_positons
.
containsKey
(
pVehicleID
))
{
return
_positons
.
get
(
pVehicleID
).
getRoute
();
}
return
null
;
}
public
Object
requestObject
(
SumoCommand
routeCommand
)
{
public
Object
requestObject
(
SumoCommand
routeCommand
)
{
Object
object
=
null
;
Object
object
=
null
;
...
@@ -454,9 +457,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -454,9 +457,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
@Override
@Override
public
double
getMaximumAvailablePrediction
()
{
public
double
getMaximumAvailablePrediction
()
{
double
max
=
Collections
.
max
(
_positonsByTimestamp
.
keySet
());
return
getStep
();
return
max
;
}
}
@Override
@Override
...
@@ -801,6 +802,20 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -801,6 +802,20 @@ public class TraciSimulationController implements VehicleController, SimulationS
edge
.
setMaxSpeed
(
pMaxSpeed
);
edge
.
setMaxSpeed
(
pMaxSpeed
);
}
}
@Override
public
boolean
isEdgeUsable
(
String
pEdgeID
)
{
if
(
_observedAreaSet
)
{
List
<
Location
>
laneShape
=
getLaneShape
(
_roadNetwork
.
getEdge
(
pEdgeID
).
getLanes
().
get
(
0
).
getLaneID
());
for
(
Location
location
:
laneShape
)
{
if
(
_startX
<=
location
.
getLongitude
()
&&
location
.
getLongitude
()
<=
_endX
&&
_startY
<=
location
.
getLatitude
()
&&
location
.
getLatitude
()
<=
_endY
)
{
return
true
;
}
}
return
false
;
}
return
true
;
}
/**
/**
* @return the startX
* @return the startX
*/
*/
...
...
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/xml/VehicleDataInformationHandler.java
View file @
0d921e5e
...
@@ -58,10 +58,10 @@ public class VehicleDataInformationHandler extends DefaultHandler {
...
@@ -58,10 +58,10 @@ public class VehicleDataInformationHandler extends DefaultHandler {
if
(
_observedAreaSet
)
{
if
(
_observedAreaSet
)
{
if
(
_startX
<=
lon
&&
lon
<=
_endX
&&
_startY
<=
lat
&&
lat
<=
_endY
)
{
if
(
_startX
<=
lon
&&
lon
<=
_endX
&&
_startY
<=
lat
&&
lat
<=
_endY
)
{
_nextVehiclePositions
.
put
(
id
,
new
VehicleInformationContainer
(
new
PositionVector
(
lon
-
_startX
,
lat
-
_startY
,
0
),
heading
,
speed
));
_nextVehiclePositions
.
put
(
id
,
new
VehicleInformationContainer
(
new
PositionVector
(
lon
-
_startX
,
lat
-
_startY
,
0
),
heading
,
speed
,
null
));
}
}
}
else
{
}
else
{
_nextVehiclePositions
.
put
(
id
,
new
VehicleInformationContainer
(
new
PositionVector
(
lon
,
lat
,
0
),
heading
,
speed
));
_nextVehiclePositions
.
put
(
id
,
new
VehicleInformationContainer
(
new
PositionVector
(
lon
,
lat
,
0
),
heading
,
speed
,
null
));
}
}
}
}
}
}
...
...
src/de/tud/kom/p2psim/impl/vehicular/DefaultVehicleInformationComponent.java
View file @
0d921e5e
...
@@ -50,7 +50,7 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
...
@@ -50,7 +50,7 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
private
String
vehicleID
;
private
String
vehicleID
;
public
DefaultVehicleInformationComponent
(
Host
host
,
VehicleController
controller
,
SimulationSetupExtractor
extractor
)
{
public
DefaultVehicleInformationComponent
(
Host
host
,
VehicleController
controller
,
SimulationSetupExtractor
extractor
,
boolean
pRouteKnown
)
{
this
.
host
=
host
;
this
.
host
=
host
;
this
.
controller
=
controller
;
this
.
controller
=
controller
;
...
@@ -66,7 +66,10 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
...
@@ -66,7 +66,10 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
throws
InformationNotAvailableException
{
throws
InformationNotAvailableException
{
if
(
pNodeID
==
getHost
().
getId
())
{
if
(
pNodeID
==
getHost
().
getId
())
{
if
(
isValid
())
{
if
(
isValid
())
{
return
getCurrentRoute
().
getStart
();
RoadNetworkRoute
route
=
getCurrentRoute
();
if
(
route
!=
null
)
{
return
route
.
getStart
();
}
}
}
}
}
return
null
;
return
null
;
...
@@ -83,6 +86,34 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
...
@@ -83,6 +86,34 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
}
}
});
});
if
(
pRouteKnown
)
{
siSComponent
.
provide
().
nodeState
(
SiSTypes
.
ROUTE
,
new
SiSDataCallback
<
RoadNetworkRoute
>()
{
@Override
public
RoadNetworkRoute
getValue
(
INodeID
pNodeID
,
SiSProviderHandle
pProviderHandle
)
throws
InformationNotAvailableException
{
if
(
pNodeID
==
getHost
().
getId
())
{
if
(
isValid
())
{
return
getCurrentRoute
();
}
}
return
null
;
}
@Override
public
Set
<
INodeID
>
getObservedNodes
()
{
return
INodeID
.
getSingleIDSet
(
getHost
().
getId
());
}
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
new
SiSInfoProperties
();
}
});
}
}
catch
(
ComponentNotAvailableException
e
)
{
}
catch
(
ComponentNotAvailableException
e
)
{
// Nothing to do!
// Nothing to do!
}
}
...
...
src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java
View file @
0d921e5e
...
@@ -26,29 +26,46 @@ import java.util.List;
...
@@ -26,29 +26,46 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetInterface
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName
;
import
de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName
;
import
de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener
;
import
de.tudarmstadt.maki.simonstrator.api.component.transport.ConnectivityListener
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CachingComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CachingComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.invalidation.CacheInvalidationStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.invalidation.CacheInvalidationStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.replacement.CacheReplacementStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.replacement.CacheReplacementStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.JamInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute
;
public
class
DefaultCachingComponent
implements
CachingComponent
,
ConnectivityListener
{
public
class
DefaultCachingComponent
implements
CachingComponent
,
ConnectivityListener
{
private
Map
<
Class
<?
extends
Object
>,
List
<
PointInformation
>>
_cache
=
new
HashMap
<>();
private
Map
<
Class
<?
extends
Object
>,
List
<
PointInformation
>>
_cache
=
new
HashMap
<>();
private
Map
<
Integer
,
Integer
>
_lastColorValues
=
new
HashMap
<>();
private
Host
_host
;
private
Host
_host
;
private
CacheInvalidationStrategy
_invalidationStrategy
;
private
CacheInvalidationStrategy
_invalidationStrategy
;
private
CacheReplacementStrategy
_replacementStrategy
;
private
CacheReplacementStrategy
_replacementStrategy
;
private
CacheDecisionStrategy
_decisionStrategy
;
private
CacheDecisionStrategy
_decisionStrategy
;
public
DefaultCachingComponent
(
Host
pHost
,
CacheInvalidationStrategy
pInvalidationStrategy
,
CacheReplacementStrategy
pReplacementStrategy
,
CacheDecisionStrategy
pDecisionStrategy
)
{
private
double
[]
informationRatios
=
new
double
[]
{
1
,
0.75
,
0.5
,
0.25
,
0
};
public
DefaultCachingComponent
(
Host
pHost
,
CacheInvalidationStrategy
pInvalidationStrategy
,
CacheReplacementStrategy
pReplacementStrategy
,
CacheDecisionStrategy
pDecisionStrategy
)
{
_host
=
pHost
;
_host
=
pHost
;
if
(
_host
!=
null
)
{
if
(
_host
!=
null
)
{
_host
.
getNetworkComponent
().
getByName
(
NetInterfaceName
.
WIFI
).
addConnectivityListener
(
this
);
_host
.
getNetworkComponent
().
getByName
(
NetInterfaceName
.
WIFI
)
.
addConnectivityListener
(
this
);
}
}
_invalidationStrategy
=
pInvalidationStrategy
;
_invalidationStrategy
=
pInvalidationStrategy
;
...
@@ -57,7 +74,8 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -57,7 +74,8 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
}
}
@Override
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
)
{
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
)
{
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
if
(
cacheEntries
==
null
)
{
if
(
cacheEntries
==
null
)
{
...
@@ -75,8 +93,10 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -75,8 +93,10 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
}
}
List
<
T
>
decidedInformation
=
new
ArrayList
<>();
List
<
T
>
decidedInformation
=
new
ArrayList
<>();
for
(
List
<
PointInformation
>
similarEntries
:
similarCacheEntries
.
values
())
{
for
(
List
<
PointInformation
>
similarEntries
:
similarCacheEntries
PointInformation
correctInformation
=
_decisionStrategy
.
decideOnCorrectInformation
(
similarEntries
);
.
values
())
{
PointInformation
correctInformation
=
_decisionStrategy
.
decideOnCorrectInformation
(
similarEntries
);
decidedInformation
.
add
((
T
)
correctInformation
);
decidedInformation
.
add
((
T
)
correctInformation
);
}
}
...
@@ -85,9 +105,11 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -85,9 +105,11 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
}
}
@Override
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getCacheEntries
(
Class
<
T
>
pCacheEntryClass
)
{
public
<
T
extends
PointInformation
>
List
<
T
>
getCacheEntries
(
Class
<
T
>
pCacheEntryClass
)
{
if
(
_cache
.
containsKey
(
pCacheEntryClass
))
{
if
(
_cache
.
containsKey
(
pCacheEntryClass
))
{
List
<?
extends
PointInformation
>
cacheEntries
=
_cache
.
get
(
pCacheEntryClass
);
List
<?
extends
PointInformation
>
cacheEntries
=
_cache
.
get
(
pCacheEntryClass
);
List
<
T
>
results
=
new
ArrayList
<>();
List
<
T
>
results
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
cacheEntries
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
cacheEntries
.
size
();
i
++)
{
...
@@ -153,7 +175,8 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -153,7 +175,8 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
public
Object
getEdgeOrPosition
(
PointInformation
information
)
{
public
Object
getEdgeOrPosition
(
PointInformation
information
)
{
if
(
information
.
hasAttribute
(
AvailableInformationAttributes
.
EDGE
))
{
if
(
information
.
hasAttribute
(
AvailableInformationAttributes
.
EDGE
))
{
return
information
.
getAttribute
(
AvailableInformationAttributes
.
EDGE
);
return
information
.
getAttribute
(
AvailableInformationAttributes
.
EDGE
);
}
else
{
}
else
{
return
information
.
getLocation
();
return
information
.
getLocation
();
}
}
...
@@ -163,4 +186,99 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -163,4 +186,99 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
return
_decisionStrategy
;
return
_decisionStrategy
;
}
}
@Override
public
String
getNodeDescription
()
{
return
""
;
}
@Override
public
int
getNodeColorDimensions
()
{
return
2
;
}
@Override
public
String
[]
getNodeColorDimensionDescriptions
()
{
return
new
String
[]
{
"Route Information"
,
"Number of jam information"
};
}
@Override
public
String
[]
getNodeColorDescriptions
(
int
pDimension
)
{
if
(
pDimension
==
0
)
{
String
[]
labels
=
new
String
[
informationRatios
.
length
];
for
(
int
i
=
0
;
i
<
informationRatios
.
length
;
i
++)
{
labels
[
i
]
=
informationRatios
[
i
]
*
100
+
"%"
;
}
return
labels
;
}
else
if
(
pDimension
==
1
)
{
String
[]
numbers
=
new
String
[
10
];
for
(
int
i
=
0
;
i
<
numbers
.
length
;
i
++)
{
numbers
[
i
]
=
String
.
valueOf
(
i
);
}
return
numbers
;
}
return
new
String
[
0
];
}
@Override
public
int
getNodeColor
(
int
pDimension
)
{
if
(
pDimension
==
0
)
{
List
<
JamInformation
>
decidedCacheEntries
=
getDecidedCacheEntries
(
JamInformation
.
class
);
try
{
VehicleInformationComponent
vehicleInformationComponent
=
getHost
().
getComponent
(
VehicleInformationComponent
.
class
);
if
(
vehicleInformationComponent
.
isValid
())
{
RoadNetworkRoute
currentRoute
=
vehicleInformationComponent
.
getCurrentRoute
();
if
(
currentRoute
!=
null
)
{
int
count
=
0
;
int
active
=
0
;
for
(
RoadNetworkEdge
edge
:
currentRoute
.
getRoute
())
{
if
(
edge
.
isActive
())
{
if
(
decidedCacheEntries
!=
null
)
{
for
(
JamInformation
jamInformation
:
decidedCacheEntries
)
{
if
(
jamInformation
.
getEdge
().
equals
(
edge
)
&&
jamInformation
.
getValue
())
{
count
++;
break
;
}
}
}
active
++;
}
}
if
(
active
!=
0
)
{
double
ratio
=
count
/
((
double
)
active
);
for
(
int
i
=
0
;
i
<
informationRatios
.
length
;
i
++)
{
if
(
informationRatios
[
i
]
<=
ratio
)
{
_lastColorValues
.
put
(
pDimension
,
i
);
break
;
}
}
}
else
{
_lastColorValues
.
put
(
pDimension
,
0
);
}
}
}
}
catch
(
ComponentNotAvailableException
e
)
{
}
if
(
_lastColorValues
.
containsKey
(
pDimension
))
{
return
_lastColorValues
.
get
(
pDimension
);
}
return
0
;
}
if
(
pDimension
==
1
)
{
List
<
JamInformation
>
decidedCacheEntries
=
getDecidedCacheEntries
(
JamInformation
.
class
);
if
(
decidedCacheEntries
!=
null
)
{
_lastColorValues
.
put
(
pDimension
,
decidedCacheEntries
.
size
());
}
if
(
_lastColorValues
.
containsKey
(
pDimension
))
{
return
Math
.
min
(
9
,
_lastColorValues
.
get
(
pDimension
));
}
return
0
;
}
return
0
;
}
@Override
public
boolean
isActive
()
{
return
getHost
().
getNetworkComponent
().
getByName
(
NetInterfaceName
.
MOBILE
).
isUp
()
||
getHost
().
getNetworkComponent
().
getByName
(
NetInterfaceName
.
WIFI
).
isUp
();
}
}
}
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