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
adee2028
Commit
adee2028
authored
Oct 30, 2017
by
Tobias Meuser
Browse files
Added additionally required decision strategies
parent
12002fdc
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/VehicleMovementModel.java
View file @
adee2028
...
...
@@ -59,6 +59,8 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public
class
VehicleMovementModel
implements
MovementModel
,
EventHandler
,
FutureLocationSensor
{
private
static
final
Location
DEFAULT_LOCATION
=
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
);
private
boolean
_reuseComponents
=
false
;
private
static
VehicleMovementModel
MOVEMENT
;
...
...
@@ -95,7 +97,6 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private
List
<
Position
>
intersections
;
/**
* Constructor for the movement model using the sumo TraCI API
* @param timeBetweenMoveOperations The time between two movement operations.
...
...
@@ -168,7 +169,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
components
.
add
(
comp
);
freeComponents
.
add
(
comp
);
comp
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
)
);
comp
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
}
/**
...
...
@@ -199,7 +200,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
initialized
=
true
;
}
// Initial placement
actuator
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
)
);
actuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
try
{
final
SiSComponent
sis
=
actuator
.
getHost
().
getComponent
(
SiSComponent
.
class
);
...
...
@@ -340,6 +341,12 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
}
if
(
Time
.
getCurrentTime
()
<
5
*
Time
.
SECOND
)
{
for
(
SimLocationActuator
simLocationActuator
:
freeComponents
)
{
simLocationActuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
}
}
// Reschedule next step
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
,
this
,
null
,
0
);
}
...
...
@@ -371,7 +378,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
}
catch
(
ComponentNotAvailableException
e
)
{
e
.
printStackTrace
();
}
simLocationActuator
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
)
);
simLocationActuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
if
(
_reuseComponents
)
{
freeComponents
.
add
(
simLocationActuator
);
...
...
src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java
View file @
adee2028
...
...
@@ -78,10 +78,6 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
for
(
List
<
PointInformation
>
similarEntries
:
similarCacheEntries
.
values
())
{
PointInformation
correctInformation
=
_decisionStrategy
.
decideOnCorrectInformation
(
similarEntries
);
if
(
correctInformation
==
null
)
{
System
.
out
.
println
();
}
decidedInformation
.
add
((
T
)
correctInformation
);
}
...
...
@@ -163,4 +159,8 @@ public class DefaultCachingComponent implements CachingComponent, ConnectivityLi
}
}
public
CacheDecisionStrategy
getDecisionStrategy
()
{
return
_decisionStrategy
;
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/CacheDecisionStrategyType.java
View file @
adee2028
...
...
@@ -28,7 +28,7 @@ import java.util.Map;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
public
enum
CacheDecisionStrategyType
{
DEFAULT
(
NewestCacheDecisionStrategy
.
class
),
NEWEST
(
NewestCacheDecisionStrategy
.
class
),
TTL
(
TTLbasedCacheDecisionStrategy
.
class
),
MAJORITY
(
MajorityVotingCacheDecisionStrategy
.
class
);
DEFAULT
(
NewestCacheDecisionStrategy
.
class
),
NEWEST
(
NewestCacheDecisionStrategy
.
class
),
TTL
(
TTLbasedCacheDecisionStrategy
.
class
),
MAJORITY
(
MajorityVotingCacheDecisionStrategy
.
class
)
,
OPTIMAL
(
OptimalCacheDecisionStrategy
.
class
),
RANDOM
(
RandomCacheDecisionStrategy
.
class
)
;
private
final
Class
<?
extends
CacheDecisionStrategy
>
decisionStrategy
;
private
final
Map
<
String
,
String
>
params
=
new
HashMap
<>();
...
...
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/MajorityVotingCacheDecisionStrategy.java
View file @
adee2028
...
...
@@ -33,7 +33,6 @@ public class MajorityVotingCacheDecisionStrategy implements CacheDecisionStrateg
@Override
public
<
T
extends
PointInformation
>
T
decideOnCorrectInformation
(
List
<
T
>
pSimilarPointInformation
)
{
Map
<
Object
,
Integer
>
voting
=
new
HashMap
<>();
for
(
T
t
:
pSimilarPointInformation
)
{
if
(!
voting
.
containsKey
(
t
.
getValue
()))
{
...
...
@@ -59,7 +58,7 @@ public class MajorityVotingCacheDecisionStrategy implements CacheDecisionStrateg
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
if
(
t
.
getValue
().
equals
(
maxEntry
.
get
Value
())
&&
timestamp
>
maxTimestamp
)
{
if
(
t
.
getValue
().
equals
(
maxEntry
.
get
Key
())
&&
timestamp
>
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
maxFitting
=
t
;
}
...
...
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/OptimalCacheDecisionStrategy.java
0 → 100755
View file @
adee2028
/*
* 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.vehicular.caching.decision
;
import
java.util.List
;
import
de.tud.kom.p2psim.impl.topology.movement.VehicleMovementModel
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge
;
public
class
OptimalCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
RoadNetwork
_roadNetwork
;
private
boolean
_lastJamState
=
false
;
private
long
_lastChange
=
0
;
public
OptimalCacheDecisionStrategy
()
{
}
@Override
public
<
T
extends
PointInformation
>
T
decideOnCorrectInformation
(
List
<
T
>
pSimilarPointInformation
)
{
if
(
pSimilarPointInformation
.
size
()
==
1
)
{
T
decision
=
pSimilarPointInformation
.
get
(
0
);
return
decision
;
}
else
if
(
pSimilarPointInformation
.
size
()
==
0
)
{
return
null
;
}
if
(
_roadNetwork
==
null
)
{
_roadNetwork
=
VehicleMovementModel
.
getRoadNetwork
();
}
RoadNetworkEdge
edge
=
_roadNetwork
.
getEdge
(
"A5.8"
);
boolean
jam
=
false
;
if
(
edge
.
getMaxSpeed
()
<
1
)
{
jam
=
true
;
}
if
(
jam
!=
_lastJamState
)
{
_lastChange
=
Time
.
getCurrentTime
();
}
long
maxTimestamp
=
-
1
;
T
maxFitting
=
null
;
T
maxFittingIncludingTimestamp
=
null
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
if
(
t
.
getValue
().
equals
(
jam
)
&&
timestamp
>
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
maxFitting
=
t
;
if
(
timestamp
>
_lastChange
)
{
maxFittingIncludingTimestamp
=
t
;
}
}
}
if
(
maxFitting
==
null
)
{
maxTimestamp
=
-
1
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
if
(
timestamp
>
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
maxFitting
=
t
;
}
}
}
if
(
maxFittingIncludingTimestamp
==
null
)
{
maxTimestamp
=
-
1
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
if
(
timestamp
>
maxTimestamp
&&
timestamp
>
_lastChange
)
{
maxTimestamp
=
timestamp
;
maxFittingIncludingTimestamp
=
t
;
}
}
}
if
(
maxFittingIncludingTimestamp
!=
null
)
{
return
maxFittingIncludingTimestamp
;
}
return
maxFitting
;
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/RandomCacheDecisionStrategy.java
0 → 100755
View file @
adee2028
/*
* 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.vehicular.caching.decision
;
import
java.util.List
;
import
java.util.Random
;
import
de.tudarmstadt.maki.simonstrator.api.Randoms
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
public
class
RandomCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
Random
_random
=
Randoms
.
getRandom
(
getClass
());
public
RandomCacheDecisionStrategy
()
{
}
@Override
public
<
T
extends
PointInformation
>
T
decideOnCorrectInformation
(
List
<
T
>
pSimilarPointInformation
)
{
if
(
pSimilarPointInformation
.
size
()
==
1
)
{
T
decision
=
pSimilarPointInformation
.
get
(
0
);
return
decision
;
}
else
if
(
pSimilarPointInformation
.
size
()
==
0
)
{
return
null
;
}
return
pSimilarPointInformation
.
get
(
_random
.
nextInt
(
pSimilarPointInformation
.
size
()));
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/TTLbasedCacheDecisionStrategy.java
View file @
adee2028
...
...
@@ -33,29 +33,48 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.Poin
public
class
TTLbasedCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
static
final
long
SCALING
=
Time
.
SECOND
;
private
static
final
double
ACCURACY_FACTOR
=
100000
;
private
long
ttl
=
300
*
Time
.
SECOND
/
SCALING
;
private
double
accuracy
=
1
;
private
double
costWrongKeep
=
1
;
private
double
costWrongChange
=
1
;
private
Object
_lastDecision
=
false
;
public
TTLbasedCacheDecisionStrategy
(
Map
<
String
,
String
>
pParams
)
{
for
(
Entry
<
String
,
String
>
param
:
pParams
.
entrySet
())
{
switch
(
param
.
getKey
())
{
case
"ACCURACY"
:
accuracy
=
Double
.
valueOf
(
param
.
getValue
());
break
;
case
"COST_RATIO"
:
double
ratio
=
Double
.
valueOf
(
param
.
getValue
());
costWrongChange
=
2
/
(
ratio
+
1
);
costWrongKeep
=
2
-
costWrongChange
;
break
;
default
:
break
;
}
}
}
public
double
getCostWrongChange
()
{
return
costWrongChange
;
}
public
double
getCostWrongKeep
()
{
return
costWrongKeep
;
}
@Override
public
<
T
extends
PointInformation
>
T
decideOnCorrectInformation
(
List
<
T
>
pSimilarPointInformation
)
{
if
(
pSimilarPointInformation
.
size
()
==
1
)
{
return
pSimilarPointInformation
.
get
(
0
);
T
decision
=
pSimilarPointInformation
.
get
(
0
);
_lastDecision
=
decision
.
getValue
();
return
decision
;
}
else
if
(
pSimilarPointInformation
.
size
()
==
0
)
{
return
null
;
}
...
...
@@ -91,9 +110,14 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
double
rate
=
difference
/
((
double
)
(
pSimilarPointInformation
.
size
()
-
1
)
*
SCALING
);
rate
=
Math
.
min
(
rate
,
ttl
/
1
0
);
rate
=
Math
.
min
(
rate
,
ttl
/
2
0
);
double
b
=
determineB
(
rate
,
1
-
accuracy
,
ttl
,
costWrongKeep
,
costWrongChange
);
double
b
;
if
(
Boolean
.
FALSE
.
equals
(
_lastDecision
))
{
b
=
determineB
(
rate
,
1
-
accuracy
,
ttl
,
costWrongKeep
,
costWrongChange
);
}
else
{
b
=
determineB
(
rate
,
1
-
accuracy
,
ttl
,
costWrongChange
,
costWrongKeep
);
}
Map
<
Object
,
Double
>
weight
=
new
HashMap
<>();
...
...
@@ -110,7 +134,7 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
weight
.
put
(
t
.
getValue
(),
sumImpact
);
}
double
maxWeight
=
0
;
double
maxWeight
=
-
1
;
Object
maxValue
=
null
;
for
(
Object
key
:
weight
.
keySet
())
{
...
...
@@ -120,7 +144,7 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
}
}
maxTimestamp
=
0
;
maxTimestamp
=
-
1
;
T
maxFitting
=
null
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
...
...
@@ -131,9 +155,11 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
}
}
_lastDecision
=
maxFitting
.
getValue
();
return
maxFitting
;
}
else
{
maxTimestamp
=
0
;
maxTimestamp
=
-
1
;
T
maxFitting
=
null
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
(
long
)
t
.
getAttribute
(
AvailableInformationAttributes
.
TTL
);
...
...
@@ -144,6 +170,8 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
}
}
_lastDecision
=
maxFitting
.
getValue
();
return
maxFitting
;
}
}
...
...
@@ -193,28 +221,41 @@ public class TTLbasedCacheDecisionStrategy implements CacheDecisionStrategy {
double
leftSide
;
double
rightSide
;
double
step
=
0.
5
;
double
step
=
5
;
if
(
errorProbability
<
0.5
)
{
b
=
-
1
*
reversed
;
b
=
-
2
*
step
*
reversed
;
}
else
{
b
=
1
*
reversed
;
b
=
2
*
step
*
reversed
;
}
int
similar
=
0
;
double
lastDifference
=
-
1
;
do
{
leftSide
=
calculateWeightingForOldState
(
optimalAmount
,
rate
,
errorProbability
,
ttl
,
b
);
rightSide
=
calculateWeightingForNewState
(
optimalAmount
,
rate
,
errorProbability
,
ttl
,
b
);
if
(
Math
.
abs
(
Math
.
round
((
rightSide
-
leftSide
)
*
ACCURACY_FACTOR
))
==
lastDifference
)
{
similar
++;
}
else
{
lastDifference
=
Math
.
abs
(
Math
.
round
((
rightSide
-
leftSide
)
*
ACCURACY_FACTOR
));
similar
=
0
;
}
if
(
Double
.
isNaN
(
leftSide
)
||
Double
.
isNaN
(
rightSide
))
{
if
(
Double
.
isNaN
(
leftSide
)
||
Double
.
isNaN
(
rightSide
)
||
similar
>
100
)
{
if
(
reversed
!=
-
1
)
{
return
determineB
(
rate
,
errorProbability
,
ttl
,
costSlow
,
costFast
,
-
1
);
double
determineB
=
determineB
(
rate
,
errorProbability
,
ttl
,
costSlow
,
costFast
,
-
1
);
if
(!
Double
.
isNaN
(
determineB
))
{
return
determineB
;
}
else
{
return
b
;
}
}
else
{
return
Double
.
NaN
;
}
}
leftSide
=
Math
.
round
(
leftSide
*
100000
);
rightSide
=
Math
.
round
(
rightSide
*
100000
);
leftSide
=
Math
.
round
(
leftSide
*
ACCURACY_FACTOR
);
rightSide
=
Math
.
round
(
rightSide
*
ACCURACY_FACTOR
);
if
(
leftSide
>
rightSide
)
{
if
(
b
<
0
)
{
...
...
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