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
API
Commits
1053046d
Commit
1053046d
authored
May 18, 2018
by
Tobias Meuser
Browse files
Introduced impact separate function
parent
0fcbf535
Changes
9
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
1053046d
...
...
@@ -95,5 +95,10 @@
<artifactId>
guava
</artifactId>
<version>
18.0
</version>
</dependency>
<dependency>
<groupId>
gov.nist.math
</groupId>
<artifactId>
jama
</artifactId>
<version>
1.0.3
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/de/tudarmstadt/maki/simonstrator/api/component/sensor/environment/data/TemporalDependencyMatrix.java
View file @
1053046d
...
...
@@ -25,6 +25,8 @@ import java.util.Arrays;
import
java.util.HashMap
;
import
java.util.Map
;
import
Jama.Matrix
;
/**
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 12.04.2018
...
...
@@ -82,6 +84,24 @@ public class TemporalDependencyMatrix implements Cloneable {
return
_agedMatrices
.
get
(
pAge
);
}
public
TemporalDependencyMatrix
calculateInverse
()
{
Matrix
dependencyMatrix
=
new
Matrix
(
_dependencies
);
Matrix
unitMatrix
=
new
Matrix
(
age
(
0
).
_dependencies
);
Matrix
inverse
=
dependencyMatrix
.
solve
(
unitMatrix
);
double
[][]
inverseArray
=
inverse
.
getArray
();
return
new
TemporalDependencyMatrix
(
inverseArray
);
}
public
TemporalDependencyMatrix
combine
(
TemporalDependencyMatrix
pOther
)
{
Matrix
ownMatrix
=
new
Matrix
(
_dependencies
);
Matrix
otherMatrix
=
new
Matrix
(
pOther
.
_dependencies
);
Matrix
combined
=
ownMatrix
.
times
(
otherMatrix
);
double
[][]
combinedArray
=
combined
.
getArray
();
return
new
TemporalDependencyMatrix
(
combinedArray
);
}
public
double
[][]
cloneArray
(
double
[][]
pDependencies
)
{
double
[][]
current
=
new
double
[
pDependencies
.
length
][];
...
...
@@ -124,4 +144,30 @@ public class TemporalDependencyMatrix implements Cloneable {
public
double
getChangeProbability
(
int
pI
)
{
return
1
-
_dependencies
[
pI
][
pI
];
}
@Override
public
String
toString
()
{
StringBuffer
buffer
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
_dependencies
.
length
;
i
++)
{
if
(
i
!=
0
)
{
buffer
.
append
(
"\n"
);
}
buffer
.
append
(
Arrays
.
toString
(
_dependencies
[
i
]));
}
return
buffer
.
toString
();
}
public
TemporalDependencyMatrix
average
(
TemporalDependencyMatrix
pOneStepDependencyMatrix2
,
double
weight
)
{
TemporalDependencyMatrix
result
=
clone
();
for
(
int
i
=
0
;
i
<
result
.
_dependencies
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
result
.
_dependencies
[
i
].
length
;
j
++)
{
result
.
_dependencies
[
i
][
j
]
=
(
weight
*
result
.
_dependencies
[
i
][
j
]
+
pOneStepDependencyMatrix2
.
_dependencies
[
i
][
j
])
/
(
weight
+
1
);
}
}
return
result
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/sensor/environment/data/VectoralProperty.java
View file @
1053046d
...
...
@@ -26,6 +26,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.aggregation.AggregationInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge
;
...
...
@@ -35,8 +36,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
*
*/
public
abstract
class
VectoralProperty
implements
RoadProperty
,
Cloneable
{
private
static
final
boolean
TRIM_PROBABILITIES
=
false
;
private
static
final
double
MINIMAL_PROBABILITY
=
0.0001
;
private
static
Map
<
DeviationIdentifier
,
Double
>
_requiredStandardDeviation
=
new
HashMap
<>();
private
final
Location
_location
;
...
...
@@ -45,6 +44,8 @@ public abstract class VectoralProperty implements RoadProperty, Cloneable {
private
double
[]
_valueProbabilities
;
private
AggregationInformation
_aggregationInformation
;
public
VectoralProperty
(
Location
pLocation
,
RoadNetworkEdge
pEdge
,
int
valueAmount
)
{
this
(
pLocation
,
pEdge
,
createProbabilityArray
(
valueAmount
));
}
...
...
@@ -67,9 +68,6 @@ public abstract class VectoralProperty implements RoadProperty, Cloneable {
for
(
int
i
=
0
;
i
<
_valueProbabilities
.
length
;
i
++)
{
double
probability
=
1
/
(
2
*
Math
.
PI
*
Math
.
pow
(
pDeviation
,
2
))
*
Math
.
exp
(-
Math
.
pow
(
i
-
pMean
,
2
)
/
(
2
*
Math
.
pow
(
pDeviation
,
2
)));
if
(
probability
<
MINIMAL_PROBABILITY
&&
TRIM_PROBABILITIES
)
{
probability
=
MINIMAL_PROBABILITY
;
}
_valueProbabilities
[
i
]
=
probability
;
sum
+=
probability
;
}
...
...
@@ -81,15 +79,6 @@ public abstract class VectoralProperty implements RoadProperty, Cloneable {
Arrays
.
fill
(
_valueProbabilities
,
0
);
_valueProbabilities
[(
int
)
Math
.
round
(
pMean
)]
=
1
;
// int lowerMean = (int) Math.floor(pMean);
// int higherMean = (int) Math.ceil(pMean);
// double difference = pMean - lowerMean;
//
// _valueProbabilities[lowerMean] = 1 - difference;
//
// if (lowerMean != higherMean) {
// _valueProbabilities[higherMean] = difference;
// }
}
}
...
...
@@ -122,6 +111,14 @@ public abstract class VectoralProperty implements RoadProperty, Cloneable {
return
_valueProbabilities
;
}
public
AggregationInformation
getAggregationInformation
()
{
return
_aggregationInformation
;
}
public
boolean
isAggregated
()
{
return
_aggregationInformation
!=
null
;
}
public
abstract
Object
getValueAtIndex
(
int
pIndex
);
public
int
getMostProbableIndex
()
{
...
...
@@ -173,9 +170,6 @@ public abstract class VectoralProperty implements RoadProperty, Cloneable {
double
sum
=
0
;
for
(
int
i
=
0
;
i
<
valueProbabilities
.
length
;
i
++)
{
if
(
valueProbabilities
[
i
]
<
MINIMAL_PROBABILITY
&&
TRIM_PROBABILITIES
)
{
valueProbabilities
[
i
]
=
MINIMAL_PROBABILITY
;
}
sum
+=
valueProbabilities
[
i
];
}
for
(
int
i
=
0
;
i
<
valueProbabilities
.
length
;
i
++)
{
...
...
@@ -202,9 +196,6 @@ public abstract class VectoralProperty implements RoadProperty, Cloneable {
double
[]
valueProbabilities
=
result
.
getValueProbabilities
();
for
(
int
i
=
0
;
i
<
valueProbabilities
.
length
;
i
++)
{
valueProbabilities
[
i
]
*=
pVectoralProperty
.
getValueProbabilities
()[
i
];
if
(
valueProbabilities
[
i
]
<
MINIMAL_PROBABILITY
&&
TRIM_PROBABILITIES
)
{
valueProbabilities
[
i
]
=
MINIMAL_PROBABILITY
;
}
sum
+=
valueProbabilities
[
i
];
}
...
...
@@ -335,4 +326,9 @@ public abstract class VectoralProperty implements RoadProperty, Cloneable {
return
super
.
equals
(
pObj
);
}
}
@Override
public
String
toString
()
{
return
Arrays
.
toString
(
_valueProbabilities
);
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/sensor/environment/data/aggregation/AggregationInformation.java
0 → 100755
View file @
1053046d
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.aggregation
;
public
class
AggregationInformation
{
}
src/de/tudarmstadt/maki/simonstrator/api/component/sensor/environment/plugin/VectoralJamEnvironmentSensorPlugin.java
View file @
1053046d
...
...
@@ -112,9 +112,7 @@ public class VectoralJamEnvironmentSensorPlugin implements EnvironmentSensorPlug
double
speed
=
-
1
;
for
(
RoadProperty
roadProperty
:
edge
.
getActiveProperties
())
{
if
(
roadProperty
instanceof
JamProperty
)
{
if
(((
JamProperty
)
roadProperty
).
isJammed
())
{
speed
=
((
JamProperty
)
roadProperty
).
getAverageSpeed
();
}
speed
=
((
JamProperty
)
roadProperty
).
getAverageSpeed
();
}
}
...
...
@@ -129,13 +127,15 @@ public class VectoralJamEnvironmentSensorPlugin implements EnvironmentSensorPlug
vectoralJamProperty
.
setSpeed
(
measuredSpeed
,
_accuracy
,
MeasurementDistributionTypeContainer
.
getDistribution
(
VectoralJamProperty
.
class
));
if
(
edge
.
getEdgeID
().
equals
(
"A5.9"
))
{
for
(
int
i
=
0
;
i
<
vectoralJamProperty
.
getValueProbabilities
().
length
;
i
++)
{
if
(
vectoralJamProperty
.
getValueProbabilities
()[
i
]
>
0.99
)
{
System
.
out
.
println
(
speed
+
" --> "
+
vectoralJamProperty
.
getMostProbableValue
());
}
}
}
// if (edge.getEdgeID().equals("A5.9")) {
// for (int i = 0; i < vectoralJamProperty.getValueProbabilities().length; i++)
// {
// if (vectoralJamProperty.getValueProbabilities()[i] > 0.99) {
// System.out.println(speed + " --> " +
// vectoralJamProperty.getMostProbableValue());
// }
// }
// }
List
<
EnvironmentProperty
>
properties
=
new
ArrayList
<>();
EnvironmentProperty
property
=
vectoralJamProperty
;
...
...
src/de/tudarmstadt/maki/simonstrator/api/component/vehicular/relevance/ImpactFunction.java
0 → 100755
View file @
1053046d
/*
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
public
interface
ImpactFunction
<
T
extends
PointInformation
>
{
double
calculateImpact
(
T
pInformation
);
}
src/de/tudarmstadt/maki/simonstrator/api/component/vehicular/relevance/impl/AbstractQoIBasedImpactFunction.java
0 → 100755
View file @
1053046d
/*
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.impl
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.VectoralProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.AvailableInformationAttributes
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.ImpactFunction
;
public
abstract
class
AbstractQoIBasedImpactFunction
<
T
extends
PointInformation
>
implements
ImpactFunction
<
T
>
{
protected
static
final
long
SCALING
=
Time
.
SECOND
;
protected
static
final
double
ACCURACY_FACTOR
=
100000
;
protected
double
accuracy
;
protected
double
costWrongKeep
=
1
;
protected
double
costWrongChange
=
1
;
protected
double
b
;
protected
double
rate
;
protected
double
numberOfMessages
;
protected
long
ttl
;
protected
long
maxTimestamp
;
protected
long
minTimestamp
;
protected
Object
_lastDecision
;
public
AbstractQoIBasedImpactFunction
(
List
<
T
>
pInformation
,
double
pAccuracy
)
{
this
(
pInformation
,
pAccuracy
,
null
);
}
public
AbstractQoIBasedImpactFunction
(
List
<
T
>
pInformation
,
double
pAccuracy
,
Object
pLastDecision
)
{
accuracy
=
pAccuracy
;
_lastDecision
=
pLastDecision
;
minTimestamp
=
Long
.
MAX_VALUE
;
maxTimestamp
=
0
;
Object
value
=
pInformation
.
get
(
0
).
getValue
();
if
(
value
instanceof
VectoralProperty
)
{
value
=
((
VectoralProperty
)
value
).
getMostProbableIndex
();
}
List
<
Object
>
possibleValues
=
new
ArrayList
<>();
for
(
T
t
:
pInformation
)
{
if
(!
t
.
hasAttribute
(
AvailableInformationAttributes
.
TTL
))
{
throw
new
AssertionError
(
"Unable to perform TTL-based majority voting witout TTL"
);
}
long
timestamp
=
t
.
getDetectionDate
();
if
(
timestamp
<
minTimestamp
)
{
minTimestamp
=
timestamp
;
}
if
(
timestamp
>
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
}
Object
currentValue
=
t
.
getValue
();
if
(
currentValue
instanceof
VectoralProperty
)
{
VectoralProperty
currentProperty
=
(
VectoralProperty
)
currentValue
;
currentValue
=
currentProperty
.
getMostProbableIndex
();
for
(
int
i
=
0
;
i
<
currentProperty
.
getValueProbabilities
().
length
;
i
++)
{
if
(!
possibleValues
.
contains
(
i
))
{
possibleValues
.
add
(
i
);
}
}
}
else
{
if
(!
possibleValues
.
contains
(
currentValue
))
{
possibleValues
.
add
(
currentValue
);
}
}
}
long
difference
=
maxTimestamp
-
minTimestamp
;
rate
=
difference
/
((
double
)
(
pInformation
.
size
()
-
1
)
*
SCALING
);
ttl
=
getTTL
(
pInformation
.
get
(
0
));
numberOfMessages
=
ttl
/
rate
+
1
;
List
<
Double
>
bValues
=
new
ArrayList
<>();
for
(
Object
possibleValue
:
possibleValues
)
{
double
temp
=
determineB
(
pInformation
.
get
(
0
).
getValue
(),
possibleValue
,
getChangeRate
(
pInformation
.
get
(
0
),
rate
),
rate
,
1
-
pAccuracy
,
numberOfMessages
,
costWrongKeep
,
costWrongChange
);
if
(!
Double
.
isNaN
(
temp
))
{
bValues
.
add
(
temp
);
}
}
Collections
.
sort
(
bValues
);
if
(
bValues
.
size
()
>
0
)
{
if
(
bValues
.
size
()
%
2
==
0
)
{
b
=
(
bValues
.
get
(
bValues
.
size
()
/
2
)
+
bValues
.
get
(
bValues
.
size
()
/
2
-
1
))
/
2.0
;
}
else
{
b
=
bValues
.
get
(
bValues
.
size
()
/
2
);
}
}
else
{
b
=
Double
.
NEGATIVE_INFINITY
;
}
}
protected
abstract
double
determineB
(
Object
pExampleValue
,
Object
pPossibleValue
,
double
pChangeRate
,
double
pRate
,
double
pErrorProbability
,
double
pNumberOfMessages
,
double
pCostWrongKeep
,
double
pCostWrongChange
);
@Override
public
double
calculateImpact
(
T
pInformation
)
{
double
impact
=
calculateImpact
(
1
-
accuracy
,
numberOfMessages
,
(((
pInformation
.
getDetectionDate
()
-
maxTimestamp
)
/
SCALING
+
ttl
)
/
(
double
)
ttl
)
*
numberOfMessages
,
b
)
/
(
accuracy
);
return
impact
;
}
protected
<
T
extends
PointInformation
>
long
getTTL
(
T
pT
)
{
return
(
long
)
pT
.
getAttribute
(
AvailableInformationAttributes
.
TTL
)
/
SCALING
;
}
protected
<
T
extends
PointInformation
>
double
getChangeRate
(
T
pT
,
double
pRate
)
{
return
getChangeProbability
((
long
)
(
getTTL
(
pT
)
/
pRate
));
}
protected
double
getChangeProbability
(
long
ttl
)
{
return
1
-
Math
.
pow
(
0.5
,
1
/
(
double
)
ttl
);
}
protected
int
getOptimalMessageAmountForSwitch
(
double
changeProbability
,
double
errorProbability
,
double
costSlow
,
double
costFast
)
{
return
(
int
)
Math
.
round
(
Math
.
log
(-
changeProbability
/
Math
.
log
(
errorProbability
)
*
costSlow
/
costFast
)
/
Math
.
log
(
errorProbability
));
}
public
double
calculateImpact
(
double
errorProbability
,
double
pNumberOfMessages
,
double
pMessageNumber
,
double
b
)
{
double
age
=
pNumberOfMessages
-
pMessageNumber
;
if
(
errorProbability
==
0
)
{
if
(
pMessageNumber
==
pNumberOfMessages
)
{
return
1
;
}
else
{
return
0
;
}
}
else
if
(
errorProbability
==
1
)
{
return
1
;
}
else
if
(
errorProbability
==
0.5
||
b
==
0
)
{
return
(
1
-
errorProbability
)
/
pNumberOfMessages
*
age
+
errorProbability
;
}
else
if
(
b
==
Double
.
NEGATIVE_INFINITY
)
{
if
(
pMessageNumber
==
pNumberOfMessages
)
{
return
1
;
}
else
{
return
0
;
}
}
return
(
1
-
errorProbability
)
*
(
Math
.
exp
(
b
*
age
)
-
Math
.
exp
(
b
*
pNumberOfMessages
))
/
(
1
-
Math
.
exp
(
b
*
pNumberOfMessages
));
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/vehicular/relevance/impl/SimpleQoIBasedImpactFunction.java
0 → 100755
View file @
1053046d
/*
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.impl
;
import
java.util.List
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
public
class
SimpleQoIBasedImpactFunction
<
T
extends
PointInformation
>
extends
AbstractQoIBasedImpactFunction
<
T
>
{
public
SimpleQoIBasedImpactFunction
(
List
<
T
>
pInformation
,
double
pAccuracy
)
{
super
(
pInformation
,
pAccuracy
);
}
@Override
public
double
calculateImpact
(
T
pInformation
)
{
return
accuracy
*
super
.
calculateImpact
(
pInformation
);
}
@Override
protected
double
determineB
(
Object
pUnused
,
Object
pPossibleValue
,
double
pChangeRate
,
double
pRate
,
double
pErrorProbability
,
double
pNumberOfMessages
,
double
pCostWrongKeep
,
double
pCostWrongChange
)
{
return
determineB
(
pPossibleValue
,
pChangeRate
,
pRate
,
pErrorProbability
,
pNumberOfMessages
,
pCostWrongKeep
,
pCostWrongChange
,
1
);
}
protected
double
determineB
(
Object
pPossibleValue
,
double
pChangeRate
,
double
pRate
,
double
pErrorProbability
,
double
pNumberOfMessages
,
double
pCostWrongKeep
,
double
pCostWrongChange
,
int
reversed
)
{
if
(
pErrorProbability
==
0
||
pErrorProbability
==
1
||
pErrorProbability
==
0.5
)
{
return
Double
.
NaN
;
}
double
b
;
int
optimalAmount
=
getOptimalMessageAmountForSwitch
(
pChangeRate
,
pErrorProbability
,
pCostWrongKeep
,
pCostWrongChange
);
if
(
optimalAmount
==
1
)
{
return
Double
.
NEGATIVE_INFINITY
;
}
boolean
first
=
true
;
double
leftSide
;
double
rightSide
;
double
step
=
5
;
if
(
pErrorProbability
<
0.5
)
{
b
=
-
2
*
step
*
reversed
;
}
else
{
b
=
2
*
step
*
reversed
;
}
int
similar
=
0
;
double
lastDifference
=
-
1
;
do
{
leftSide
=
calculateWeightingForOldState
(
optimalAmount
,
pRate
,
pErrorProbability
,
pNumberOfMessages
,
b
);
rightSide
=
calculateWeightingForNewState
(
optimalAmount
,
pRate
,
pErrorProbability
,
pNumberOfMessages
,
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
)
||
similar
>
100
)
{
if
(
reversed
!=
-
1
)
{
double
determineB
=
determineB
(
pPossibleValue
,
pChangeRate
,
pRate
,
pErrorProbability
,
pNumberOfMessages
,
pCostWrongKeep
,
pCostWrongChange
,
-
1
);
if
(!
Double
.
isNaN
(
determineB
))
{
return
determineB
;
}
else
{
return
b
;
}
}
else
{
return
Double
.
NaN
;
}
}
leftSide
=
Math
.
round
(
leftSide
*
ACCURACY_FACTOR
);
rightSide
=
Math
.
round
(
rightSide
*
ACCURACY_FACTOR
);
if
(
leftSide
>
rightSide
)
{
if
(
b
<
0
)
{
b
-=
step
;
if
(!
first
)
{
step
*=
0.5
;
}
}
else
{
b
-=
step
;
step
*=
0.5
;
first
=
false
;
}
}
else
if
(
leftSide
<
rightSide
)
{
if
(
b
>
0
)
{
b
+=
step
;
if
(!
first
)
{
step
*=
0.5
;
}
}
else
{
b
+=
step
;
step
*=
0.5
;
first
=
false
;
}
}
else
{
break
;
}
}
while
(
true
);
return
b
;
}
public
double
calculateWeightingForOldState
(
int
optimalMessageAmount
,
double
rate
,
double
errorProbability
,
double
pNumberOfMessages
,
double
b
)
{
double
impact
=
0
;
for
(
int
a
=
optimalMessageAmount
;
a
<
pNumberOfMessages
;
a
++)
{
impact
+=
calculateImpact
(
errorProbability
,
pNumberOfMessages
,
pNumberOfMessages
-
a
,
b
);
}
return
impact
;
}
public
double
calculateWeightingForNewState
(
int
optimalMessageAmount
,
double
rate
,
double
errorProbability
,
double
numberOfMessages
,
double
b
)
{
double
impact
=
0
;
for
(
int
a
=
0
;
a
<
optimalMessageAmount
;
a
++)
{
impact
+=
calculateImpact
(
errorProbability
,
numberOfMessages
,
numberOfMessages
-
a
,
b
);
}
return
impact
;
}
}
src/de/tudarmstadt/maki/simonstrator/api/component/vehicular/relevance/impl/VectoralQoIBasedImpactFunction.java
0 → 100755
View file @
1053046d
/*
* Copyright (c) 2005-2010 KOM Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.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.tudarmstadt.maki.simonstrator.api.component.vehicular.relevance.impl
;
import
java.util.List
;
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.measurement.MeasurementDistributionTypeContainer
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
public
class
VectoralQoIBasedImpactFunction
<
T
extends
PointInformation
>
extends
AbstractQoIBasedImpactFunction
<
T
>
{
private
static
final
double
MIN_STEP
=
0.00001
;
public
VectoralQoIBasedImpactFunction
(
List
<
T
>
pInformation
,
double
pAccuracy
,
Object
pLastDecision
)
{
super
(
pInformation
,
pAccuracy
,
pLastDecision
);
}
@Override
protected
double
determineB
(
Object
pTemplate
,
Object
pPossibleValue
,
double
pChangeRate
,
double
pRate
,
double
pErrorProbability
,
double
pNumberOfMessages
,
double
pCostWrongKeep
,
double
pCostWrongChange
)
{
if
(!(
pTemplate
instanceof
VectoralProperty
))
{
throw
new
AssertionError
(
"Vectoral property required as input for pTemplate, but got "
+
pTemplate
.
getClass
().
getSimpleName
());
}
return
determineBWithCast
((
VectoralProperty
)
pTemplate
,
(
int
)
pPossibleValue
,
pChangeRate
,
pRate
,
pErrorProbability
,
pNumberOfMessages
,
pCostWrongKeep
,
pCostWrongChange
);
}
public
double
determineBWithCast
(
VectoralProperty
pTemplate
,
int
pPossibleValue
,
double
change
,
double
rate
,
double
errorProbability
,
double
pNumberOfMessages
,
double
costSlow
,
double
costFast
)
{
if
(
errorProbability
==
0
||
errorProbability
==
1
||
errorProbability
==
0.5
)
{
return
Double
.
NaN
;
}
if
(
_lastDecision
!=
null
)
{
if
(
pPossibleValue
==
((
VectoralProperty
)
_lastDecision
).
getMostProbableIndex
())
{
return
Double
.
NaN
;
}
}
else
{
if
(
pPossibleValue
==
pTemplate
.
getDefaultIndex
())
{
return
Double
.
NaN
;
}
}
double
b
;
double
p_c
=
change
;
int
optimalAmount
=
getOptimalMessageAmountForSwitch
(
p_c
,
errorProbability
,
costSlow
,
costFast
);
if
((
int
)
pNumberOfMessages
<=
optimalAmount
)
{
return
Double
.
POSITIVE_INFINITY
;
}
if
(
optimalAmount
==
1
)
{
return
Double
.
NEGATIVE_INFINITY
;
}
boolean
first
=
true
;
double
step
=
10
;
if
(
errorProbability
<
0.5
)
{
b
=
-
1
*
step
;
}
else
{
b
=
1
*
step
;
}
do
{
VectoralProperty
valueAfterN
=
calculateMostProbable
(
pTemplate
,
pPossibleValue
,
optimalAmount
,
rate
,
errorProbability
,
pNumberOfMessages
,
b
);
double
probableValueAfterN
=
Double
.
NaN
;
if
(
valueAfterN
!=
null
)
{
probableValueAfterN
=
valueAfterN
.
getMostProbableIndex
();
}
VectoralProperty
valueBeforeN
=
calculateMostProbable
(
pTemplate
,
pPossibleValue
,
optimalAmount
-
1
,
rate
,
errorProbability
,
pNumberOfMessages
,
b
);
double
probableValueBeforeN
=
Double
.
NaN
;
if
(
valueBeforeN
!=
null
)
{
probableValueBeforeN
=
valueBeforeN
.
getMostProbableIndex
();
}
if
(
probableValueAfterN
==
pPossibleValue
&&
probableValueAfterN
!=
probableValueBeforeN
)
{
return
b
;
}
if
(!
Double
.
isNaN
(
probableValueBeforeN
)
&&
!
Double
.
isNaN
(
probableValueBeforeN
)
&&
step
>=
MIN_STEP
)
{
if
(
probableValueAfterN
!=
pPossibleValue
)
{
if
(
b
<
0
)
{
b
-=
step
;
if
(!
first
)
{
step
*=
0.5
;
}
}
else
{
b
-=
step
;
step
*=
0.5
;
first
=
false
;
}
}
else
if
(
probableValueAfterN
==
pPossibleValue
&&
probableValueAfterN
==
probableValueBeforeN
)
{
if
(
b
>
0
)
{
b
+=
step
;
if
(!
first
)
{
step
*=
0.5
;
}
}
else
{
b
+=
step
;
step
*=
0.5
;
first
=
false
;
}
}
else
{
return
Double
.
NaN
;
}
}
else
{
return
Double
.
NaN
;
}
}
while
(
true
);
}
public
VectoralProperty
calculateMostProbable
(
VectoralProperty
pTemplate
,
int
pNewValue
,
int
optimalMessageAmount
,
double
rate
,
double
errorProbability
,
double
pNumberOfMessages
,
double
b
)
{
VectoralProperty
currentProperty
=
null
;
for
(
int
a
=
optimalMessageAmount
+
1
;
a
<=
pNumberOfMessages
;
a
++)
{
VectoralProperty
jamProperty
=
pTemplate
.
clone
();
if
(
_lastDecision
!=
null
)
{
jamProperty
.
set
(((
VectoralProperty
)
_lastDecision
).
getMostProbableIndex
(),
accuracy
,
MeasurementDistributionTypeContainer
.
getDistribution
(
pTemplate
.
getClass
()));
}
else
{
jamProperty
.
set
(
pTemplate
.
getDefaultIndex
(),
accuracy
,
MeasurementDistributionTypeContainer
.
getDistribution
(
pTemplate
.
getClass
()));
}
TemporalDependencyMatrix
temporalDependencyMatrix
=
jamProperty
.
getDependencyMatrix
();
temporalDependencyMatrix
=
temporalDependencyMatrix
.
age
((
long
)
(
a
*
rate
));
double
impact
=
calculateImpact
(
errorProbability
,
pNumberOfMessages
,
pNumberOfMessages
-
a
,
b
);
if
(
Double
.
isNaN
(
impact
))
{
return
null
;
}
temporalDependencyMatrix
=
modifyDependencyMatrix
(
temporalDependencyMatrix
,
impact
);
jamProperty
=
(
VectoralProperty
)
jamProperty
.
age
(
1
,
temporalDependencyMatrix
);
if
(
currentProperty
!=
null
)
{
currentProperty
=
(
VectoralProperty
)
currentProperty
.
combine
(
jamProperty
);
}
else
{
currentProperty
=
jamProperty
;
}
}
for
(
int
a
=
0
;
a
<=
optimalMessageAmount
;
a
++)
{
VectoralProperty
jamProperty
=
pTemplate
.
clone
();
jamProperty
.
setGaussianWithAccuracy
(
pNewValue
,
accuracy
);
TemporalDependencyMatrix
temporalDependencyMatrix
=
jamProperty
.
getDependencyMatrix
();
temporalDependencyMatrix
=
temporalDependencyMatrix
.
age
((
long
)
(
a
*
rate
));
double
impact
=
calculateImpact
(
errorProbability
,
pNumberOfMessages
,
pNumberOfMessages
-
a
,
b
);
if
(
Double
.
isNaN
(
impact
))
{
return
null
;
}
temporalDependencyMatrix
=
modifyDependencyMatrix
(
temporalDependencyMatrix
,
impact
);
jamProperty
=
(
VectoralProperty
)
jamProperty
.
age
(
1
,
temporalDependencyMatrix
);
if
(
currentProperty
!=
null
)
{
currentProperty
=
(
VectoralProperty
)
currentProperty
.
combine
(
jamProperty
);
}
else
{
currentProperty
=
jamProperty
;
}
}
return
currentProperty
;
}
private
TemporalDependencyMatrix
modifyDependencyMatrix
(
TemporalDependencyMatrix
pDependencyMatrix
,
double
pImpact
)
{
TemporalDependencyMatrix
result
=
pDependencyMatrix
.
clone
();
double
[][]
dependencies
=
result
.
getDependencies
();
for
(
int
i
=
0
;
i
<
dependencies
.
length
;
i
++)
{
double
finalPercentages
=
1.0
/
dependencies
[
i
].
length
;
for
(
int
j
=
0
;
j
<
dependencies
[
i
].
length
;
j
++)
{
dependencies
[
i
][
j
]
=
finalPercentages
+
(
pDependencyMatrix
.
getDependencies
()[
i
][
j
]
-
finalPercentages
)
*
pImpact
;
}
}
return
result
;
}
}
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