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
7cfc2df9
Commit
7cfc2df9
authored
Feb 27, 2018
by
Deepak Jayaram
Browse files
feb 27 fine tuning
parent
ad6c5644
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/vehicular/caching/CooperativeCachingComponent.java
View file @
7cfc2df9
...
...
@@ -46,7 +46,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
public
class
CooperativeCachingComponent
extends
DefaultCachingComponent
implements
CachingComponent
,
ConnectivityListener
{
private
double
vehicleRate
=
0.0
;
// vehicles/s
private
double
vehicleRate
=
0.0
;
// vehicles/s
(it gives the No. of vehicles for 1 second)
public
CooperativeCachingComponent
(
Host
pHost
,
CacheInvalidationStrategy
pInvalidationStrategy
,
...
...
@@ -59,14 +59,60 @@ public class CooperativeCachingComponent extends DefaultCachingComponent
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getCacheEntries
(
Class
<
T
>
pCacheEntryClass
)
{
if
(
_cache
.
containsKey
(
pCacheEntryClass
))
{
List
<?
extends
PointInformation
>
cacheEntries
=
_cache
.
get
(
pCacheEntryClass
);
List
<
T
>
results
=
new
ArrayList
<>();
int
invalidatedCount
=
0
;
long
maxTimestamp
=
-
1
;
for
(
int
i
=
0
;
i
<
cacheEntries
.
size
();
i
++)
{
PointInformation
object
=
cacheEntries
.
get
(
i
);
if
(
_invalidationStrategy
.
checkInformation
(
object
))
{
invalidatedCount
++;
if
(
maxTimestamp
<
object
.
getDetectionDate
())
{
maxTimestamp
=
object
.
getDetectionDate
();
}
}
}
if
(
invalidatedCount
==
cacheEntries
.
size
())
{
cacheEntries
.
clear
();
}
else
if
(
invalidatedCount
>
1
)
{
for
(
int
i
=
0
;
i
<
cacheEntries
.
size
();
i
++)
{
PointInformation
object
=
cacheEntries
.
get
(
i
);
if
(
_invalidationStrategy
.
checkInformation
(
object
))
{
if
(
maxTimestamp
!=
object
.
getDetectionDate
())
{
cacheEntries
.
remove
(
i
--);
}
}
}
}
if
(
cacheEntries
.
size
()
>
0
)
{
PointInformation
object
=
cacheEntries
.
get
(
0
);
if
(
object
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
)
!=
null
)
{
vehicleRate
=
(
double
)
(
object
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
));
}
else
{
vehicleRate
=
1
/
(
double
)
Time
.
SECOND
;
// USE A DEFAULT CONSTANT VEHICULAR RATE
}
if
(
vehicleRate
>
0.0
)
{
long
timeDiff
=
((
long
)
(
1
/
vehicleRate
));
long
minValidInformation
=
Math
.
max
(
Time
.
getCurrentTime
()
-
(
long
)
object
.
getAttribute
(
AvailableInformationAttributes
.
TTL
),
0
);
for
(
long
timestamp
=
minValidInformation
+
timeDiff
;
timestamp
<
object
.
getDetectionDate
();
timestamp
+=
timeDiff
)
{
PointInformation
pointInformation
=
object
.
createDefaultInformation
();
pointInformation
.
setDetectionTime
(
timestamp
);
results
.
add
((
T
)
pointInformation
);
}
}
}
for
(
int
i
=
0
;
i
<
cacheEntries
.
size
();
i
++)
{
PointInformation
object
=
cacheEntries
.
get
(
i
);
long
nextUpdate
=
0
;
PointInformation
nextObj
;
...
...
@@ -75,37 +121,33 @@ public class CooperativeCachingComponent extends DefaultCachingComponent
nextObj
=
cacheEntries
.
get
(
i
+
1
);
nextUpdate
=
nextObj
.
getDetectionDate
();
if
(
nextObj
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
)
!=
null
)
{
vehicleRate
=
(
double
)
nextObj
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
);
vehicleRate
=
(
double
)
(
nextObj
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
)
)
;
}
else
{
vehicleRate
=
1
/
(
double
)
Time
.
SECOND
;
// USE A DEFAULT CONSTANT VEHICULAR RATE
}
}
else
{
nextUpdate
=
Time
.
getCurrentTime
();
if
(
object
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
)
!=
null
)
{
if
(
i
==
0
)
{
//
to measure vehicleRate for FIRST PUB from the time simulation started
(Simulator.getStartTime())
long
timeDiffOfFirstPub
=
object
.
getDetectionDate
()
-
Simulator
.
getStartTime
(
);
if
(
i
==
0
)
{
//
TO MEASURE VEHICLERATE FOR FIRST PUB FROM THE TIME SIMULATION STARTED
(Simulator.getStartTime())
long
timeDiffOfFirstPub
=
(
object
.
getDetectionDate
());
if
(
timeDiffOfFirstPub
>
0
)
{
vehicleRate
=
(
vehicleRate
*
object
.
getDetectionDate
())/
timeDiffOfFirstPub
;
vehicleRate
=
(
double
)
object
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
);
vehicleRate
=
(
vehicleRate
*
object
.
getDetectionDate
())
/
timeDiffOfFirstPub
;
}
}
else
{
vehicleRate
=
(
double
)
object
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
);
vehicleRate
=
(
double
)
(
object
.
getAttribute
(
AvailableInformationAttributes
.
VEHICULAR_RATE
)
)
;
}
}
else
{
vehicleRate
=
1
/
(
double
)
Time
.
SECOND
;
// USE A DEFAULT CONSTANT VEHICULAR RATE
}
}
if
(
_invalidationStrategy
.
checkInformation
(
object
))
{
cacheEntries
.
remove
(
i
--);
continue
;
}
results
.
add
((
T
)
object
);
if
(
vehicleRate
>
0.0
)
{
long
timeDiff
=
((
long
)
(
1
/
vehicleRate
));
for
(
long
timestamp
=
object
.
getDetectionDate
()
+
timeDiff
;
timestamp
<
=
nextUpdate
;
timestamp
+=
timeDiff
)
{
+
timeDiff
;
timestamp
<
nextUpdate
;
timestamp
+=
timeDiff
)
{
PointInformation
pointInformation
=
object
.
clonePointInformation
();
pointInformation
.
setDetectionTime
(
timestamp
);
...
...
@@ -113,6 +155,15 @@ public class CooperativeCachingComponent extends DefaultCachingComponent
}
}
}
for
(
int
i
=
0
;
i
<
results
.
size
();
i
++)
{
PointInformation
object
=
results
.
get
(
i
);
if
(
_invalidationStrategy
.
checkInformation
(
object
))
{
results
.
remove
(
i
--);
continue
;
}
}
return
results
;
}
return
null
;
...
...
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