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
d202296e
Commit
d202296e
authored
Jun 12, 2018
by
Tobias Meuser
Browse files
Current version
parent
44bee7a8
Changes
12
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/simengine/Scheduler.java
View file @
d202296e
...
@@ -57,7 +57,7 @@ SchedulerComponent, TimeComponent {
...
@@ -57,7 +57,7 @@ SchedulerComponent, TimeComponent {
private
long
statusInterval
=
SCHEDULER_WAKEUP_INTERVAL_IN_VIRTUALTIME
;
private
long
statusInterval
=
SCHEDULER_WAKEUP_INTERVAL_IN_VIRTUALTIME
;
private
static
final
int
INITIAL_QUEUE_CAPACITY
=
5000
;
private
static
final
int
INITIAL_QUEUE_CAPACITY
=
5000
0
;
private
long
processedEventCounter
;
private
long
processedEventCounter
;
...
...
src/de/tud/kom/p2psim/impl/topology/movement/VehicleMovementModel.java
View file @
d202296e
...
@@ -92,6 +92,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -92,6 +92,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
private
double
_percentageOfKnownRoutes
=
1
;
private
double
_percentageOfKnownRoutes
=
1
;
private
int
_startTime
;
/**
/**
* 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.
...
@@ -117,6 +119,27 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -117,6 +119,27 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
this
.
offsetY
=
Integer
.
parseInt
(
offsetY
);
this
.
offsetY
=
Integer
.
parseInt
(
offsetY
);
this
.
width
=
Integer
.
parseInt
(
width
);
this
.
width
=
Integer
.
parseInt
(
width
);
this
.
height
=
Integer
.
parseInt
(
height
);
this
.
height
=
Integer
.
parseInt
(
height
);
Thread
current
=
Thread
.
currentThread
();
Thread
thread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
while
(
true
)
{
StackTraceElement
[]
stackTrace
=
current
.
getStackTrace
();
System
.
out
.
println
();
System
.
out
.
println
();
for
(
int
i
=
0
;
i
<
stackTrace
.
length
;
i
++)
{
System
.
out
.
println
(
stackTrace
[
i
]);
}
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
}
}
}
});
// thread.start();
}
}
/**
/**
...
@@ -154,6 +177,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -154,6 +177,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
_percentageOfKnownRoutes
=
pPercentageOfKnownRoutes
;
_percentageOfKnownRoutes
=
pPercentageOfKnownRoutes
;
}
}
public
void
setStartTime
(
long
pStartTime
)
{
_startTime
=
(
int
)
(
pStartTime
/
Time
.
SECOND
);
}
public
void
setReuseComponents
(
boolean
pReuseComponents
)
{
public
void
setReuseComponents
(
boolean
pReuseComponents
)
{
_reuseComponents
=
pReuseComponents
;
_reuseComponents
=
pReuseComponents
;
...
@@ -221,6 +248,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -221,6 +248,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
TraciSimulationController
simulationController
=
TraciSimulationController
.
createSimulationController
(
sumoExe
,
sumoConfigFile
);
TraciSimulationController
simulationController
=
TraciSimulationController
.
createSimulationController
(
sumoExe
,
sumoConfigFile
);
_controller
=
simulationController
;
_controller
=
simulationController
;
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
simulationController
.
setStartTime
(
_startTime
);
_controller
.
init
();
_controller
.
init
();
_controller
.
nextStep
();
_controller
.
nextStep
();
...
@@ -262,6 +290,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
...
@@ -262,6 +290,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
*/
*/
long
currentTime
=
Time
.
getCurrentTime
()
/
timestepConversion
;
long
currentTime
=
Time
.
getCurrentTime
()
/
timestepConversion
;
System
.
out
.
println
(
"Performing movement for step "
+
currentTime
);
while
(
_controller
.
getStep
()
-
_controller
.
getStart
()
<
currentTime
)
{
while
(
_controller
.
getStep
()
-
_controller
.
getStart
()
<
currentTime
)
{
if
(!
_controller
.
nextStep
())
{
if
(!
_controller
.
nextStep
())
{
return
;
return
;
...
...
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java
View file @
d202296e
...
@@ -75,6 +75,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -75,6 +75,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
private
double
_endX
;
private
double
_endX
;
private
double
_endY
;
private
double
_endY
;
private
int
_startTime
=
0
;
private
Map
<
String
,
VehicleInformationContainer
>
_positons
=
new
HashMap
<>();
private
Map
<
String
,
VehicleInformationContainer
>
_positons
=
new
HashMap
<>();
private
boolean
_initalized
=
false
;
private
boolean
_initalized
=
false
;
...
@@ -99,6 +101,10 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -99,6 +101,10 @@ public class TraciSimulationController implements VehicleController, SimulationS
_configFile
=
pConfigFile
;
_configFile
=
pConfigFile
;
}
}
public
void
setStartTime
(
int
pStartTime
)
{
_startTime
=
pStartTime
;
}
public
static
VehicleController
getSimulationController
()
{
public
static
VehicleController
getSimulationController
()
{
return
CONTROLLER
.
values
().
iterator
().
next
();
return
CONTROLLER
.
values
().
iterator
().
next
();
}
}
...
@@ -127,6 +133,15 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -127,6 +133,15 @@ public class TraciSimulationController implements VehicleController, SimulationS
Simulator
.
getInstance
().
addObserver
(
this
);
Simulator
.
getInstance
().
addObserver
(
this
);
_initalized
=
true
;
_initalized
=
true
;
for
(
int
i
=
0
;
i
<
_startTime
;
i
++)
{
System
.
out
.
println
(
"Pre-Start Setup: "
+
i
+
" of "
+
_startTime
+
" steps done."
);
try
{
_connection
.
do_timestep
();
}
catch
(
Exception
e
)
{
throw
new
AssertionError
(
e
);
}
}
}
}
}
}
...
@@ -750,7 +765,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
...
@@ -750,7 +765,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
List
<
Location
>
positions
=
new
ArrayList
<>();
List
<
Location
>
positions
=
new
ArrayList
<>();
boolean
set
=
false
;
boolean
set
=
false
;
SumoCommand
laneShapeCommand
=
Lane
.
getShape
(
pLaneID
);
SumoCommand
laneShapeCommand
=
Lane
.
getShape
(
pLaneID
);
SumoGeometry
geometry
=
(
SumoGeometry
)
requestObject
(
laneShapeCommand
);
SumoGeometry
geometry
=
(
SumoGeometry
)
requestObject
(
laneShapeCommand
);
for
(
SumoPosition2D
location
:
geometry
.
coords
)
{
for
(
SumoPosition2D
location
:
geometry
.
coords
)
{
...
...
src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java
View file @
d202296e
...
@@ -24,15 +24,18 @@ import java.util.ArrayList;
...
@@ -24,15 +24,18 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
de.tud.kom.p2psim.impl.vehicular.caching.decision.NewestCacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
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.transition.TransitionEngine
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.TransitionEngine
;
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.VehicleInformationComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.CacheStateListener
;
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.decision.CacheSizeAwareCacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheSizeAwareCacheDecisionStrategy
;
...
@@ -43,6 +46,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.Avai
...
@@ -43,6 +46,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.Avai
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.JamInformation
;
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.information.RoadInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute
;
...
@@ -58,14 +62,17 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -58,14 +62,17 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
private
CacheReplacementStrategy
_replacementStrategy
;
private
CacheReplacementStrategy
_replacementStrategy
;
private
CacheDecisionStrategy
_decisionStrategy
;
CacheDecisionStrategy
_defaultDecisionStrategy
;
Map
<
Class
<?
extends
Object
>,
CacheDecisionStrategy
>
_decisionStrategies
=
new
HashMap
<>();
private
int
_minObservations
=
0
;
private
int
_minObservations
=
0
;
private
int
_maxCacheSize
PerEntry
=
Integer
.
MAX_VALUE
;
private
int
_maxCacheSize
=
Integer
.
MAX_VALUE
;
private
double
[]
informationRatios
=
new
double
[]
{
1
,
0.75
,
0.5
,
0.25
,
0
};
private
double
[]
informationRatios
=
new
double
[]
{
1
,
0.75
,
0.5
,
0.25
,
0
};
private
List
<
CacheStateListener
>
_cacheStateListeners
=
new
ArrayList
<>();
public
DefaultCachingComponent
(
Host
pHost
,
public
DefaultCachingComponent
(
Host
pHost
,
CacheInvalidationStrategy
pInvalidationStrategy
,
CacheInvalidationStrategy
pInvalidationStrategy
,
CacheReplacementStrategy
pReplacementStrategy
,
CacheReplacementStrategy
pReplacementStrategy
,
...
@@ -79,7 +86,7 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -79,7 +86,7 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
_invalidationStrategy
=
pInvalidationStrategy
;
_invalidationStrategy
=
pInvalidationStrategy
;
_replacementStrategy
=
pReplacementStrategy
;
_replacementStrategy
=
pReplacementStrategy
;
_decisionStrategy
=
pDecisionStrategy
;
_de
faultDe
cisionStrategy
=
pDecisionStrategy
;
}
}
private
TransitionEngine
getTransitionEngine
()
throws
AssertionError
{
private
TransitionEngine
getTransitionEngine
()
throws
AssertionError
{
...
@@ -90,9 +97,17 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -90,9 +97,17 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
}
}
}
}
@Override
public
void
registerCacheStateListener
(
CacheStateListener
pListener
)
{
_cacheStateListeners
.
add
(
pListener
);
}
@Override
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
)
{
Class
<
T
>
pCacheEntryClass
)
{
CacheDecisionStrategy
decisionStrategy
=
getCacheDecisionStrategy
(
pCacheEntryClass
);
Set
<
RoadNetworkEdge
>
allEverActiveEdges
=
RoadNetwork
.
CURRENT_ROAD_NETWORK
.
getAllEverActiveEdges
();
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
if
(
cacheEntries
==
null
)
{
if
(
cacheEntries
==
null
)
{
...
@@ -104,13 +119,16 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -104,13 +119,16 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
for
(
T
t
:
cacheEntries
)
{
for
(
T
t
:
cacheEntries
)
{
Object
position
=
getEdgeOrPosition
(
t
);
Object
position
=
getEdgeOrPosition
(
t
);
if
(!
similarCacheEntries
.
containsKey
(
position
))
{
if
(!(
position
instanceof
RoadNetworkEdge
)
||
allEverActiveEdges
.
contains
((
position
)))
{
similarCacheEntries
.
put
(
position
,
new
HashMap
<>());
if
(!
similarCacheEntries
.
containsKey
(
position
))
{
}
similarCacheEntries
.
put
(
position
,
new
HashMap
<>());
if
(!
similarCacheEntries
.
get
(
position
).
containsKey
(
t
.
getValue
().
getClass
()))
{
}
similarCacheEntries
.
get
(
position
).
put
(
t
.
getValue
().
getClass
(),
new
ArrayList
<
PointInformation
>());
if
(!
similarCacheEntries
.
get
(
position
).
containsKey
(
t
.
getValue
().
getClass
()))
{
similarCacheEntries
.
get
(
position
).
put
(
t
.
getValue
().
getClass
(),
new
ArrayList
<
PointInformation
>());
}
similarCacheEntries
.
get
(
position
).
get
(
t
.
getValue
().
getClass
()).
add
(
t
);
}
}
similarCacheEntries
.
get
(
position
).
get
(
t
.
getValue
().
getClass
()).
add
(
t
);
}
}
List
<
T
>
decidedInformation
=
new
ArrayList
<>();
List
<
T
>
decidedInformation
=
new
ArrayList
<>();
...
@@ -118,7 +136,7 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -118,7 +136,7 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
.
values
())
{
.
values
())
{
for
(
List
<
PointInformation
>
similarInformation
:
similarEdges
.
values
())
{
for
(
List
<
PointInformation
>
similarInformation
:
similarEdges
.
values
())
{
if
(
similarInformation
.
size
()
>=
_minObservations
)
{
if
(
similarInformation
.
size
()
>=
_minObservations
)
{
PointInformation
correctInformation
=
_
decisionStrategy
PointInformation
correctInformation
=
decisionStrategy
.
decideOnCorrectInformation
(
similarInformation
);
.
decideOnCorrectInformation
(
similarInformation
);
decidedInformation
.
add
((
T
)
correctInformation
);
decidedInformation
.
add
((
T
)
correctInformation
);
...
@@ -138,6 +156,13 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -138,6 +156,13 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
@Override
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
,
Class
<?>
pCacheValueClass
,
RoadNetworkEdge
pEdge
)
{
Class
<
T
>
pCacheEntryClass
,
Class
<?>
pCacheValueClass
,
RoadNetworkEdge
pEdge
)
{
CacheDecisionStrategy
decisionStrategy
=
getCacheDecisionStrategy
(
pCacheEntryClass
);
Set
<
RoadNetworkEdge
>
allEverActiveEdges
=
RoadNetwork
.
CURRENT_ROAD_NETWORK
.
getAllEverActiveEdges
();
if
(!
allEverActiveEdges
.
contains
(
pEdge
))
{
return
null
;
}
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
if
(
cacheEntries
==
null
)
{
if
(
cacheEntries
==
null
)
{
...
@@ -149,8 +174,6 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -149,8 +174,6 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
for
(
T
t
:
cacheEntries
)
{
for
(
T
t
:
cacheEntries
)
{
Object
position
=
getEdgeOrPosition
(
t
);
Object
position
=
getEdgeOrPosition
(
t
);
// System.out.println(t.getDetectionDate() + " --> " + ((AggregatedInformation)t).getAggregationInformation().getMinTimestamp());
if
(
position
.
equals
(
pEdge
)
&&
(
pCacheValueClass
==
null
||
t
.
getValue
().
getClass
().
equals
(
pCacheValueClass
)))
{
if
(
position
.
equals
(
pEdge
)
&&
(
pCacheValueClass
==
null
||
t
.
getValue
().
getClass
().
equals
(
pCacheValueClass
)))
{
if
(!
similarCacheEntries
.
containsKey
(
t
.
getValue
().
getClass
()))
{
if
(!
similarCacheEntries
.
containsKey
(
t
.
getValue
().
getClass
()))
{
similarCacheEntries
.
put
(
t
.
getValue
().
getClass
(),
new
ArrayList
<
PointInformation
>());
similarCacheEntries
.
put
(
t
.
getValue
().
getClass
(),
new
ArrayList
<
PointInformation
>());
...
@@ -164,7 +187,7 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -164,7 +187,7 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
for
(
List
<
PointInformation
>
similarInformation
:
similarCacheEntries
.
values
())
{
for
(
List
<
PointInformation
>
similarInformation
:
similarCacheEntries
.
values
())
{
if
(
similarInformation
.
size
()
>=
_minObservations
)
{
if
(
similarInformation
.
size
()
>=
_minObservations
)
{
PointInformation
correctInformation
=
_
decisionStrategy
PointInformation
correctInformation
=
decisionStrategy
.
decideOnCorrectInformation
(
similarInformation
);
.
decideOnCorrectInformation
(
similarInformation
);
decidedInformation
.
add
((
T
)
correctInformation
);
decidedInformation
.
add
((
T
)
correctInformation
);
...
@@ -174,6 +197,21 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -174,6 +197,21 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
return
decidedInformation
;
return
decidedInformation
;
}
}
private
<
T
extends
PointInformation
>
CacheDecisionStrategy
getCacheDecisionStrategy
(
Class
<
T
>
pCacheEntryClass
)
throws
AssertionError
{
if
(!
_decisionStrategies
.
containsKey
(
pCacheEntryClass
))
{
CacheDecisionStrategy
clone
=
_defaultDecisionStrategy
.
clone
();
TransitionEngine
tEngine
=
getTransitionEngine
();
clone
=
tEngine
.
createMechanismProxy
(
CacheDecisionStrategy
.
class
,
clone
,
DECISION_STRATEGY
+
pCacheEntryClass
.
getSimpleName
());
_decisionStrategies
.
put
(
pCacheEntryClass
,
clone
);
}
CacheDecisionStrategy
decisionStrategy
=
_decisionStrategies
.
get
(
pCacheEntryClass
);
return
decisionStrategy
;
}
public
void
setMinObservations
(
int
pMinObservations
)
{
public
void
setMinObservations
(
int
pMinObservations
)
{
this
.
_minObservations
=
pMinObservations
;
this
.
_minObservations
=
pMinObservations
;
}
}
...
@@ -217,29 +255,78 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -217,29 +255,78 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
List
<
PointInformation
>
entries
=
_cache
.
get
(
pCacheEntry
.
getClass
());
List
<
PointInformation
>
entries
=
_cache
.
get
(
pCacheEntry
.
getClass
());
List
<
PointInformation
>
toBeRemoved
=
new
ArrayList
<>();
if
(
pCacheEntry
instanceof
AggregatedInformation
&&
((
AggregatedInformation
)
pCacheEntry
).
isAggregated
())
{
for
(
PointInformation
pointInformation
:
entries
)
{
List
<
PointInformation
>
toBeRemoved
=
new
ArrayList
<>();
if
(
_replacementStrategy
.
replaceInformation
(
pointInformation
,
pCacheEntry
))
{
for
(
PointInformation
pointInformation
:
entries
)
{
toBeRemoved
.
add
(
pointInformation
);
if
(
_replacementStrategy
.
replaceInformation
(
pointInformation
,
pCacheEntry
))
{
toBeRemoved
.
add
(
pointInformation
);
}
}
for
(
PointInformation
pointInformation
:
toBeRemoved
)
{
entries
.
remove
(
pointInformation
);
}
}
}
}
for
(
PointInformation
pointInformation
:
toBeRemoved
)
{
shrinkCache
(
_maxCacheSize
-
1
);
entries
.
remove
(
pointInformation
);
entries
.
add
(
pCacheEntry
);
for
(
CacheStateListener
cacheStateListener
:
_cacheStateListeners
)
{
cacheStateListener
.
entryStored
(
pCacheEntry
);
}
}
private
void
shrinkCache
(
int
maxSize
)
{
while
(
maxSize
<
getTotalCacheSize
())
{
int
maxSizeValue
=
0
;
List
<
PointInformation
>
removedValues
=
null
;
List
<
PointInformation
>
removedList
=
null
;
for
(
List
<
PointInformation
>
informationList
:
_cache
.
values
())
{
Map
<
Object
,
List
<
PointInformation
>>
perPosition
=
new
HashMap
<>();
for
(
PointInformation
pointInformation
:
informationList
)
{
Object
position
=
getEdgeOrPosition
(
pointInformation
);
if
(!
perPosition
.
containsKey
(
position
))
{
perPosition
.
put
(
position
,
new
ArrayList
<>());
}
perPosition
.
get
(
position
).
add
(
pointInformation
);
}
for
(
Entry
<
Object
,
List
<
PointInformation
>>
entry
:
perPosition
.
entrySet
())
{
if
(
maxSizeValue
<
entry
.
getValue
().
size
())
{
maxSizeValue
=
entry
.
getValue
().
size
();
removedValues
=
entry
.
getValue
();
removedList
=
informationList
;
}
}
}
removedList
.
removeAll
(
removedValues
);
CacheDecisionStrategy
decisionStrategy
=
getCacheDecisionStrategy
(
removedValues
.
get
(
0
).
getClass
());
PointInformation
correctInformation
=
decisionStrategy
.
decideOnCorrectInformation
(
removedValues
);
for
(
CacheStateListener
cacheStateListener
:
_cacheStateListeners
)
{
cacheStateListener
.
entriesRemoved
(
removedValues
,
correctInformation
);
}
}
}
}
while
(
entries
.
size
()
>
_maxCacheSizePerEntry
-
1
)
{
private
int
getTotalCacheSize
()
{
entries
.
remove
(
0
);
int
sum
=
0
;
for
(
List
<
PointInformation
>
informationList
:
_cache
.
values
())
{
sum
+=
informationList
.
size
();
}
}
entries
.
add
(
pCacheEntry
)
;
return
sum
;
}
}
@Override
@Override
public
void
initialize
()
{
public
void
initialize
()
{
_cache
.
clear
();
_cache
.
clear
();
TransitionEngine
tEngine
=
getTransitionEngine
();
_decisionStrategy
=
tEngine
.
createMechanismProxy
(
CacheDecisionStrategy
.
class
,
_decisionStrategy
,
DECISION_STRATEGY
);
}
}
@Override
@Override
...
@@ -262,14 +349,20 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -262,14 +349,20 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
}
}
@Override
@Override
public
void
performDecisionTransition
(
Class
<?
extends
CacheDecisionStrategy
>
pCacheDecisionStrategy
)
{
public
void
performDecisionTransition
(
Class
<?
extends
Object
>
pInformationClass
,
Class
<?
extends
CacheDecisionStrategy
>
pCacheDecisionStrategy
)
{
getTransitionEngine
().
executeAtomicTransition
(
DECISION_STRATEGY
,
pCacheDecisionStrategy
);
getTransitionEngine
().
executeAtomicTransition
(
DECISION_STRATEGY
+
pInformationClass
.
getSimpleName
()
,
pCacheDecisionStrategy
);
}
}
@Override
@Override
public
void
adjustCacheSizePerEntry
(
int
pMaxCacheSizePerEntry
)
{
public
void
setMaxSize
(
int
pMaxCacheSize
)
{
getTransitionEngine
().
alterLocalState
(
DECISION_STRATEGY
,
CacheSizeAwareCacheDecisionStrategy
.
class
,
"CacheSize"
,
pMaxCacheSizePerEntry
);
_maxCacheSize
=
pMaxCacheSize
;
_maxCacheSizePerEntry
=
pMaxCacheSizePerEntry
;
shrinkCache
(
_maxCacheSize
);
}
@Override
public
void
adjustCacheSizePerEntry
(
Class
<?
extends
Object
>
pInformationClass
,
int
pMaxCacheSizePerEntry
)
{
getTransitionEngine
().
alterLocalState
(
DECISION_STRATEGY
+
pInformationClass
.
getSimpleName
(),
CacheSizeAwareCacheDecisionStrategy
.
class
,
"CacheSize"
,
pMaxCacheSizePerEntry
);
}
}
@Override
@Override
...
@@ -307,10 +400,6 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
...
@@ -307,10 +400,6 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
}
}
}
}
public
CacheDecisionStrategy
getDecisionStrategy
()
{
return
_decisionStrategy
;
}
@Override
@Override
public
String
getNodeDescription
()
{
public
String
getNodeDescription
()
{
return
" "
+
getHost
().
getId
();
return
" "
+
getHost
().
getId
();
...
...
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/AveragingCacheDecisionStrategy.java
View file @
d202296e
...
@@ -84,4 +84,9 @@ public class AveragingCacheDecisionStrategy extends AbstractCacheDecisionStrateg
...
@@ -84,4 +84,9 @@ public class AveragingCacheDecisionStrategy extends AbstractCacheDecisionStrateg
public
Map
<
CacheDecisionStrategyParameters
,
String
>
getParams
()
{
public
Map
<
CacheDecisionStrategyParameters
,
String
>
getParams
()
{
return
_params
;
return
_params
;
}
}
@Override
public
AveragingCacheDecisionStrategy
clone
()
{
return
new
AveragingCacheDecisionStrategy
(
_params
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/MajorityVotingCacheDecisionStrategy.java
View file @
d202296e
...
@@ -83,4 +83,9 @@ public class MajorityVotingCacheDecisionStrategy extends AbstractCacheDecisionSt
...
@@ -83,4 +83,9 @@ public class MajorityVotingCacheDecisionStrategy extends AbstractCacheDecisionSt
return
_params
;
return
_params
;
}
}
@Override
public
MajorityVotingCacheDecisionStrategy
clone
()
{
return
new
MajorityVotingCacheDecisionStrategy
(
_params
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/MajorityVotingVectoralCacheDecisionStrategy.java
View file @
d202296e
...
@@ -103,4 +103,9 @@ public class MajorityVotingVectoralCacheDecisionStrategy extends AbstractCacheDe
...
@@ -103,4 +103,9 @@ public class MajorityVotingVectoralCacheDecisionStrategy extends AbstractCacheDe
return
_params
;
return
_params
;
}
}
@Override
public
MajorityVotingVectoralCacheDecisionStrategy
clone
()
{
return
new
MajorityVotingVectoralCacheDecisionStrategy
(
_params
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/NewestCacheDecisionStrategy.java
View file @
d202296e
...
@@ -56,4 +56,9 @@ public class NewestCacheDecisionStrategy extends AbstractCacheDecisionStrategy i
...
@@ -56,4 +56,9 @@ public class NewestCacheDecisionStrategy extends AbstractCacheDecisionStrategy i
return
_params
;
return
_params
;
}
}
@Override
public
NewestCacheDecisionStrategy
clone
()
{
return
new
NewestCacheDecisionStrategy
(
_params
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/OptimalCacheDecisionStrategy.java
View file @
d202296e
...
@@ -107,4 +107,9 @@ public class OptimalCacheDecisionStrategy extends AbstractCacheDecisionStrategy
...
@@ -107,4 +107,9 @@ public class OptimalCacheDecisionStrategy extends AbstractCacheDecisionStrategy
return
_params
;
return
_params
;
}
}
@Override
public
OptimalCacheDecisionStrategy
clone
()
{
return
new
OptimalCacheDecisionStrategy
(
_params
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/RandomCacheDecisionStrategy.java
View file @
d202296e
...
@@ -58,4 +58,9 @@ public class RandomCacheDecisionStrategy extends AbstractCacheDecisionStrategy i
...
@@ -58,4 +58,9 @@ public class RandomCacheDecisionStrategy extends AbstractCacheDecisionStrategy i
return
_params
;
return
_params
;
}
}
@Override
public
RandomCacheDecisionStrategy
clone
()
{
return
new
RandomCacheDecisionStrategy
(
_params
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/TTLbasedCacheDecisionStrategy.java
View file @
d202296e
...
@@ -200,4 +200,9 @@ public class TTLbasedCacheDecisionStrategy extends AbstractCacheDecisionStrategy
...
@@ -200,4 +200,9 @@ public class TTLbasedCacheDecisionStrategy extends AbstractCacheDecisionStrategy
public
void
setCacheSize
(
int
pCacheSize
)
{
public
void
setCacheSize
(
int
pCacheSize
)
{
_maxCacheSize
=
pCacheSize
;
_maxCacheSize
=
pCacheSize
;
}
}
@Override
public
TTLbasedCacheDecisionStrategy
clone
()
{
return
new
TTLbasedCacheDecisionStrategy
(
_params
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/TTLbasedVectoralCacheDecisionStrategy.java
View file @
d202296e
...
@@ -28,6 +28,7 @@ import java.util.Map;
...
@@ -28,6 +28,7 @@ import java.util.Map;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.RoadProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.TemporalDependencyMatrix
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.TemporalDependencyMatrix
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.MechanismState
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.MechanismState
;
...
@@ -51,7 +52,6 @@ public class TTLbasedVectoralCacheDecisionStrategy extends AbstractCacheDecision
...
@@ -51,7 +52,6 @@ public class TTLbasedVectoralCacheDecisionStrategy extends AbstractCacheDecision
private
double
costWrongKeep
=
1
;
private
double
costWrongKeep
=
1
;
private
double
costWrongChange
=
1
;
private
double
costWrongChange
=
1
;
@MechanismState
(
value
=
"CacheSize"
)
private
int
cacheSize
=
Integer
.
MAX_VALUE
;
private
int
cacheSize
=
Integer
.
MAX_VALUE
;
private
Object
_lastDecision
=
null
;
private
Object
_lastDecision
=
null
;
...
@@ -114,71 +114,84 @@ public class TTLbasedVectoralCacheDecisionStrategy extends AbstractCacheDecision
...
@@ -114,71 +114,84 @@ public class TTLbasedVectoralCacheDecisionStrategy extends AbstractCacheDecision
}
}
boolean
differentValue
=
false
;
boolean
differentValue
=
false
;
List
<
Integer
>
possibleValues
=
new
ArrayList
<>();
if
(
differentValue
)
{
List
<
Integer
>
possibleValues
=
new
ArrayList
<>();
for
(
T
t
:
pSimilarPointInformation
)
{
for
(
T
t
:
pSimilarPointInformation
)
{
if
(!
t
.
hasAttribute
(
AvailableInformationAttributes
.
TTL
))
{
if
(!
t
.
hasAttribute
(
AvailableInformationAttributes
.
TTL
))
{
throw
new
AssertionError
(
"Unable to perform TTL-based majority voting witout TTL"
);
throw
new
AssertionError
(
"Unable to perform TTL-based majority voting witout TTL"
);
}
}
long
timestamp
=
t
.
getDetectionDate
();
long
timestamp
=
t
.
getDetectionDate
();
if
(
timestamp
<
minTimestamp
)
{
if
(
timestamp
<
minTimestamp
)
{
minTimestamp
=
timestamp
;
minTimestamp
=
timestamp
;
}
}
if
(
timestamp
>
maxTimestamp
)
{
if
(
timestamp
>
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
maxTimestamp
=
timestamp
;
}
}
Object
currentValue
=
t
.
getValue
();
Object
currentValue
=
t
.
getValue
();
if
(
currentValue
instanceof
VectoralProperty
)
{
if
(
currentValue
instanceof
VectoralProperty
)
{
VectoralProperty
currentProperty
=
(
VectoralProperty
)
currentValue
;
VectoralProperty
currentProperty
=
(
VectoralProperty
)
currentValue
;
currentValue
=
currentProperty
.
getMostProbableIndex
();
currentValue
=
currentProperty
.
getMostProbableIndex
();
if
(!
value
.
equals
(
currentValue
))
{
if
(!
value
.
equals
(
currentValue
))
{
differentValue
=
true
;
differentValue
=
true
;
}
}
for
(
int
i
=
0
;
i
<
currentProperty
.
getValueProbabilities
().
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
currentProperty
.
getValueProbabilities
().
length
;
i
++)
{
if
(!
possibleValues
.
contains
(
i
))
{
if
(!
possibleValues
.
contains
(
i
))
{
possibleValues
.
add
(
i
);
possibleValues
.
add
(
i
);
}
}
}
}
}
}
}
}
VectoralProperty
currentProperty
=
null
;
VectoralProperty
currentProperty
=
null
;
VectoralQoIBasedImpactFunction
<
T
>
impactFunction
=
new
VectoralQoIBasedImpactFunction
<>(
pSimilarPointInformation
,
accuracy
,
cacheSize
,
_lastDecision
);
VectoralQoIBasedImpactFunction
<
T
>
impactFunction
=
new
VectoralQoIBasedImpactFunction
<>(
pSimilarPointInformation
,
accuracy
,
cacheSize
,
_lastDecision
);
for
(
T
t
:
pSimilarPointInformation
)
{
for
(
T
t
:
pSimilarPointInformation
)
{
RoadInformation
roadInformation
=
((
RoadInformation
)
t
);
RoadInformation
roadInformation
=
((
RoadInformation
)
t
);
VectoralProperty
property
=
(
VectoralProperty
)
roadInformation
.
getValue
();
VectoralProperty
property
=
(
VectoralProperty
)
roadInformation
.
getValue
();
double
impact
=
impactFunction
.
calculateImpact
(
t
);
double
impact
=
impactFunction
.
calculateImpact
(
t
);
TemporalDependencyMatrix
dependencyMatrix
=
property
.
getDependencyMatrix
();
TemporalDependencyMatrix
dependencyMatrix
=
property
.
getDependencyMatrix
();
dependencyMatrix
=
modifyDependencyMatrix
(
dependencyMatrix
.
age
((
maxTimestamp
-
property
.
getDetectionDate
())
/
SCALING
),
impact
);
dependencyMatrix
=
modifyDependencyMatrix
(
dependencyMatrix
.
age
((
maxTimestamp
-
property
.
getDetectionDate
())
/
SCALING
),
impact
);
VectoralProperty
agedProperty
=
property
.
age
(
1
,
dependencyMatrix
);
VectoralProperty
agedProperty
=
property
.
age
(
1
,
dependencyMatrix
);
if
(
currentProperty
!=
null
)
{
if
(
currentProperty
!=
null
)
{
currentProperty
=
currentProperty
.
combine
(
agedProperty
);
currentProperty
=
currentProperty
.
combine
(
agedProperty
);
}
else
{
}
else
{
currentProperty
=
agedProperty
;
currentProperty
=
agedProperty
;
}
}
}
}
if
(
Double
.
isNaN
(
currentProperty
.
getValueProbabilities
()[
0
]))
{
if
(
Double
.
isNaN
(
currentProperty
.
getValueProbabilities
()[
0
]))
{
return
pSimilarPointInformation
.
get
(
pSimilarPointInformation
.
size
()
-
1
);
return
pSimilarPointInformation
.
get
(
pSimilarPointInformation
.
size
()
-
1
);
}
}
RoadInformation
roadInformation
=
new
RoadInformation
(
currentProperty
);
copyAttributes
((
RoadInformation
)
pSimilarPointInformation
.
get
(
pSimilarPointInformation
.
size
()
-
1
),
roadInformation
);
addAggregationInformation
(
pSimilarPointInformation
,
roadInformation
);
_lastDecision
=
roadInformation
.
getValue
();
RoadInformation
roadInformation
=
new
RoadInformation
(
currentProperty
);
return
(
T
)
roadInformation
;
}
else
{
RoadProperty
currentProperty
=
(
RoadProperty
)
pSimilarPointInformation
.
get
(
pSimilarPointInformation
.
size
()
-
1
).
getValue
();
copyAttributes
((
RoadInformation
)
pSimilarPointInformation
.
get
(
pSimilarPointInformation
.
size
()
-
1
),
roadInformation
);
RoadInformation
roadInformation
=
new
RoadInformation
(
currentProperty
);
addAggregationInformation
(
pSimilarPointInformation
,
roadInformation
);
_lastDecision
=
roadInformation
.
getValue
();
copyAttributes
((
RoadInformation
)
pSimilarPointInformation
.
get
(
pSimilarPointInformation
.
size
()
-
1
),
roadInformation
);
addAggregationInformation
(
pSimilarPointInformation
,
roadInformation
);
return
(
T
)
roadInformation
;
_lastDecision
=
roadInformation
.
getValue
();
return
(
T
)
roadInformation
;
}
}
}
/**
/**
...
@@ -216,4 +229,9 @@ public class TTLbasedVectoralCacheDecisionStrategy extends AbstractCacheDecision
...
@@ -216,4 +229,9 @@ public class TTLbasedVectoralCacheDecisionStrategy extends AbstractCacheDecision
cacheSize
=
pCacheSize
;
cacheSize
=
pCacheSize
;
}
}
@Override
public
TTLbasedVectoralCacheDecisionStrategy
clone
()
{
return
new
TTLbasedVectoralCacheDecisionStrategy
(
_params
);
}
}
}
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