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
75b30e05
Commit
75b30e05
authored
May 02, 2022
by
Julian Zobel
Browse files
rm traci
parent
6bbe4677
Changes
38
Expand all
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
75b30e05
...
...
@@ -403,13 +403,6 @@
<version>
${project.version}
</version>
</dependency>
<!-- Traci as a Service -->
<dependency>
<groupId>
maki
</groupId>
<artifactId>
simonstrator-traci
</artifactId>
<version>
0.2-SNAPSHOT
</version>
</dependency>
</dependencies>
</project>
src/de/tud/kom/p2psim/impl/topology/movement/RSUMovementModel.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.topology.movement
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
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.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
// FIXME javaDoc
public
class
RSUMovementModel
implements
MovementModel
{
private
final
List
<
SimLocationActuator
>
components
;
private
final
String
sumoExe
;
private
final
String
sumoConfigFile
;
private
final
String
sumoIntersections
;
private
final
int
offsetX
;
private
final
int
offsetY
;
private
final
int
width
;
private
final
int
height
;
private
final
long
timestepConversion
=
Time
.
SECOND
;
private
boolean
initialized
=
false
;
private
SimulationSetupExtractor
_controller
;
private
List
<
Location
>
_intersections
;
private
int
_currentIndex
=
0
;
private
final
Map
<
INodeID
,
Integer
>
hostIntersectionMatching
=
new
HashMap
<>();
@XMLConfigurableConstructor
({
"sumoExe"
,
"sumoConfigFile"
,
"offsetX"
,
"offsetY"
,
"width"
,
"height"
})
public
RSUMovementModel
(
String
sumoExe
,
String
sumoConfigFile
,
String
offsetX
,
String
offsetY
,
String
width
,
String
height
)
{
this
.
components
=
new
LinkedList
<>();
this
.
sumoExe
=
sumoExe
;
this
.
sumoConfigFile
=
sumoConfigFile
;
this
.
sumoIntersections
=
null
;
this
.
offsetX
=
Integer
.
parseInt
(
offsetX
);
this
.
offsetY
=
Integer
.
parseInt
(
offsetY
);
this
.
width
=
Integer
.
parseInt
(
width
);
this
.
height
=
Integer
.
parseInt
(
height
);
}
@XMLConfigurableConstructor
({
"sumoIntersections"
,
"offsetX"
,
"offsetY"
,
"width"
,
"height"
})
public
RSUMovementModel
(
String
sumoIntersections
,
String
offsetX
,
String
offsetY
,
String
width
,
String
height
)
{
this
.
components
=
new
LinkedList
<>();
this
.
sumoIntersections
=
sumoIntersections
;
this
.
sumoExe
=
null
;
this
.
sumoConfigFile
=
null
;
this
.
offsetX
=
Integer
.
parseInt
(
offsetX
);
this
.
offsetY
=
Integer
.
parseInt
(
offsetY
);
this
.
width
=
Integer
.
parseInt
(
width
);
this
.
height
=
Integer
.
parseInt
(
height
);
}
@Override
public
final
void
addComponent
(
SimLocationActuator
comp
)
{
components
.
add
(
comp
);
}
@Override
public
void
setTimeBetweenMoveOperations
(
long
time
)
{
//Do nothing, only used for placement of RSU
}
@Override
public
synchronized
void
placeComponent
(
SimLocationActuator
actuator
)
{
if
(!
initialized
)
{
initializeModel
();
initialized
=
true
;
}
if
(
_currentIndex
<
_intersections
.
size
())
{
// Initial placement
Location
intersection
=
_intersections
.
get
(
_currentIndex
);
actuator
.
updateCurrentLocation
(
new
PositionVector
(
intersection
.
getLongitudeOrX
(),
intersection
.
getLatitudeOrY
()));
hostIntersectionMatching
.
put
(
actuator
.
getHost
().
getId
(),
_currentIndex
);
_currentIndex
++;
//Put interfaces online
try
{
RoutedNetLayer
routedNetLayer
=
actuator
.
getHost
().
getComponent
(
RoutedNetLayer
.
class
);
for
(
SimNetInterface
netInterface
:
routedNetLayer
.
getSimNetworkInterfaces
())
{
if
(
netInterface
.
isOffline
())
{
netInterface
.
goOnline
();
}
}
}
catch
(
ComponentNotAvailableException
e
)
{
e
.
printStackTrace
();
}
}
else
{
actuator
.
updateCurrentLocation
(
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
));
}
}
/**
* Initializes the movement model by executing BonnMotion and parsing the
* resulting movement trace.
*/
protected
void
initializeModel
()
{
if
(
this
.
sumoExe
!=
null
)
{
_controller
=
TraciSimulationController
.
createSimulationController
(
sumoExe
,
sumoConfigFile
,
1
);
_controller
.
init
(
Time
.
SECOND
);
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
_intersections
=
_controller
.
getAllIntersections
(
true
);
}
else
{
_controller
=
new
XMLSimulationController
(
null
,
sumoIntersections
);
_controller
.
init
(
Time
.
SECOND
);
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
_intersections
=
_controller
.
getAllIntersections
(
true
);
}
// System.out.println("Require " + _intersections.size() + " RSUs");
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/topology/movement/VehicleMovementModel.java
deleted
100644 → 0
View file @
6bbe4677
/*
* 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.topology.movement
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Queue
;
import
java.util.Random
;
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.SimLocationActuator
;
import
de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tud.kom.p2psim.impl.vehicular.DefaultVehicleInformationComponent
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
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.common.graph.INodeID
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
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
boolean
_reuseComponents
=
false
;
private
static
VehicleMovementModel
MOVEMENT
;
public
static
final
int
TIMESTEP_RATIO
=
1
;
private
long
timeBetweenMoveOperations
;
private
final
List
<
SimLocationActuator
>
components
;
private
final
Queue
<
SimLocationActuator
>
freeComponents
;
private
final
Map
<
String
,
SimLocationActuator
>
idComponentMatcher
;
private
final
Map
<
INodeID
,
String
>
hostVehicleIDMatching
=
new
HashMap
<>();
private
final
int
offsetX
;
private
final
int
offsetY
;
private
final
int
width
;
private
final
int
height
;
private
final
String
sumoExe
;
private
final
String
sumoConfigFile
;
private
final
String
sumoTrace
;
private
String
sumoIntersections
;
private
boolean
initialized
=
false
;
private
VehicleController
_controller
;
private
SimulationSetupExtractor
_extractor
;
private
double
_percentageOfKnownRoutes
=
1
;
private
int
_startTime
;
/**
* Constructor for the movement model using the sumo TraCI API
* @param timeBetweenMoveOperations The time between two movement operations.
* @param sumoExe The path to the executable of sumo
* @param sumoConfigFile The path to the configuration file of the scenario
* @param offsetX The offset that should be used. If no offset is required, offset 0 shall be used.
* @param offsetY The offset that should be used. If no offset is required, offset 0 shall be used.
* @param width The width of the scenario.
* @param height The height of the scenario.
*/
@XMLConfigurableConstructor
({
"timeBetweenMoveOperations"
,
"sumoExe"
,
"sumoConfigFile"
,
"offsetX"
,
"offsetY"
,
"width"
,
"height"
})
public
VehicleMovementModel
(
long
timeBetweenMoveOperations
,
String
sumoExe
,
String
sumoConfigFile
,
String
offsetX
,
String
offsetY
,
String
width
,
String
height
)
{
MOVEMENT
=
this
;
this
.
timeBetweenMoveOperations
=
timeBetweenMoveOperations
;
this
.
components
=
new
LinkedList
<>();
this
.
freeComponents
=
new
LinkedList
<>();
this
.
idComponentMatcher
=
new
HashMap
<>();
this
.
sumoExe
=
sumoExe
;
this
.
sumoConfigFile
=
sumoConfigFile
;
this
.
sumoTrace
=
null
;
this
.
offsetX
=
Integer
.
parseInt
(
offsetX
);
this
.
offsetY
=
Integer
.
parseInt
(
offsetY
);
this
.
width
=
Integer
.
parseInt
(
width
);
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();
}
/**
* Constructor for the movement model using the a generated sumo trace file
* @param timeBetweenMoveOperations The time between two movement operations.
* @param sumoTrace The path to the vehicle movement file (*.xml)
* @param sumoIntersections The path to the intersections file (*.csv)
* @param offsetX The offset that should be used. If no offset is required, offset 0 shall be used.
* @param offsetY The offset that should be used. If no offset is required, offset 0 shall be used.
* @param width The width of the scenario.
* @param height The height of the scenario.
*/
@XMLConfigurableConstructor
({
"timeBetweenMoveOperations"
,
"sumoTrace"
,
"sumoIntersections"
,
"offsetX"
,
"offsetY"
,
"width"
,
"height"
})
public
VehicleMovementModel
(
long
timeBetweenMoveOperations
,
String
sumoTrace
,
String
sumoIntersections
,
int
offsetX
,
int
offsetY
,
int
width
,
int
height
)
{
MOVEMENT
=
this
;
this
.
timeBetweenMoveOperations
=
timeBetweenMoveOperations
;
this
.
components
=
new
LinkedList
<>();
this
.
freeComponents
=
new
LinkedList
<>();
this
.
idComponentMatcher
=
new
HashMap
<>();
this
.
sumoExe
=
null
;
this
.
sumoConfigFile
=
null
;
this
.
sumoTrace
=
sumoTrace
;
this
.
sumoIntersections
=
sumoIntersections
;
this
.
offsetX
=
offsetX
;
this
.
offsetY
=
offsetY
;
this
.
width
=
width
;
this
.
height
=
height
;
}
/**
* @param pPercentageOfKnownRoutes the percentageOfKnownRoutes to set
*/
public
void
setPercentageOfKnownRoutes
(
double
pPercentageOfKnownRoutes
)
{
_percentageOfKnownRoutes
=
pPercentageOfKnownRoutes
;
}
public
void
setStartTime
(
long
pStartTime
)
{
_startTime
=
(
int
)
(
pStartTime
/
timeBetweenMoveOperations
);
}
public
void
setReuseComponents
(
boolean
pReuseComponents
)
{
_reuseComponents
=
pReuseComponents
;
if
(
_reuseComponents
)
{
System
.
err
.
println
(
"WARNING: Enabling the reuse of components might cause strange behaviors of your simulation!"
);
}
}
/**
* Adding an additional component to be moved by this movement model
* @param comp The component to be added.
*/
@Override
public
final
void
addComponent
(
SimLocationActuator
comp
)
{
components
.
add
(
comp
);
freeComponents
.
add
(
comp
);
comp
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
}
/**
* Returns the time between movement operations
* @return time between movement operations
*/
public
long
getTimeBetweenMoveOperations
()
{
return
timeBetweenMoveOperations
;
}
/**
* Set the time between movement operations
* @param time the time between movement operations
*/
@Override
public
void
setTimeBetweenMoveOperations
(
long
time
)
{
this
.
timeBetweenMoveOperations
=
time
;
}
/**
* Place a component at the correct location
* @param actuator The component to be placed.
*/
@Override
public
void
placeComponent
(
SimLocationActuator
actuator
)
{
if
(!
initialized
)
{
initializeModel
();
VehicleMovementModel
.
getRoadNetwork
();
initialized
=
true
;
}
// Initial placement
actuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
}
/**
* Initializes the movement model by executing BonnMotion and parsing the
* resulting movement trace.
*/
protected
void
initializeModel
()
{
// Schedule first step
if
(!
initialized
)
{
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
*
TIMESTEP_RATIO
,
this
,
null
,
0
);
if
(
sumoExe
!=
null
)
{
TraciSimulationController
simulationController
=
TraciSimulationController
.
createSimulationController
(
sumoExe
,
sumoConfigFile
,
TIMESTEP_RATIO
);
_controller
=
simulationController
;
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
simulationController
.
setStartTime
(
_startTime
);
_controller
.
init
(
timeBetweenMoveOperations
);
_controller
.
nextStep
(
timeBetweenMoveOperations
);
_extractor
=
simulationController
;
}
else
{
XMLSimulationController
simulationController
;
if
(
sumoIntersections
==
null
||
sumoIntersections
.
equals
(
""
))
{
simulationController
=
new
XMLSimulationController
(
sumoTrace
);
}
else
{
simulationController
=
new
XMLSimulationController
(
sumoTrace
,
sumoIntersections
);
}
_controller
=
simulationController
;
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
_controller
.
init
(
timeBetweenMoveOperations
);
_controller
.
nextStep
(
timeBetweenMoveOperations
);
_extractor
=
simulationController
;
}
System
.
out
.
println
(
"Initialization: done."
);
}
}
/**
* Used for the periodical updates of the vehicle positions
* @param content not used in this case, should be null
* @param type not used in this case, should be 0
*/
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
/*
* One event for all nodes (synchronized movement), as this boosts
* simulation performance due to less recalculations in the network
* models.
*/
long
currentTime
=
Time
.
getCurrentTime
()
/
timeBetweenMoveOperations
;
System
.
out
.
println
(
"Performing movement for step "
+
currentTime
);
while
(
_controller
.
getStep
()
-
_controller
.
getStart
()
<
currentTime
)
{
if
(!
_controller
.
nextStep
(
timeBetweenMoveOperations
))
{
return
;
}
}
List
<
String
>
allVehicles
=
_controller
.
getAllVehicles
();
for
(
int
i
=
0
;
i
<
allVehicles
.
size
();
i
++)
{
String
vehicle
=
allVehicles
.
get
(
i
);
Location
position
=
_controller
.
getVehiclePosition
(
vehicle
);
if
(
position
==
null
)
{
allVehicles
.
remove
(
i
--);
continue
;
}
SimLocationActuator
component
=
requestSimActuator
(
vehicle
);
try
{
RoutedNetLayer
routedNetLayer
=
component
.
getHost
().
getComponent
(
RoutedNetLayer
.
class
);
for
(
SimNetInterface
netInterface
:
routedNetLayer
.
getSimNetworkInterfaces
())
{
if
(
netInterface
.
isOffline
())
{
netInterface
.
goOnline
();
}
}
}
catch
(
ComponentNotAvailableException
e
)
{
e
.
printStackTrace
();
}
component
.
updateCurrentLocation
(
new
PositionVector
(
position
.
getLongitudeOrX
(),
position
.
getLatitudeOrY
()));
component
.
setMovementSpeed
(
_controller
.
getVehicleSpeed
(
vehicle
));
}
if
(
allVehicles
.
size
()
!=
idComponentMatcher
.
size
())
{
ArrayList
<
String
>
registeredVehicles
=
new
ArrayList
<>(
idComponentMatcher
.
keySet
());
for
(
int
i
=
0
;
i
<
registeredVehicles
.
size
();
i
++)
{
String
vehicle
=
registeredVehicles
.
get
(
i
);
if
(!
allVehicles
.
contains
(
vehicle
))
{
addFreeHost
(
vehicle
);
}
}
}
if
(
Time
.
getCurrentTime
()
<
5
*
Time
.
SECOND
)
{
for
(
SimLocationActuator
simLocationActuator
:
freeComponents
)
{
simLocationActuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
}
}
// Reschedule next step
Event
.
scheduleWithDelay
(
timeBetweenMoveOperations
*
TIMESTEP_RATIO
,
this
,
null
,
0
);
}
/**
* Remove a vehicle from the set of moved components as the vehicle has stopped driving
* @param vehicleID The stopped vehicle
*/
private
void
addFreeHost
(
String
vehicleID
)
{
if
(
idComponentMatcher
.
containsKey
(
vehicleID
))
{
SimLocationActuator
simLocationActuator
=
idComponentMatcher
.
remove
(
vehicleID
);
if
(
simLocationActuator
!=
null
)
{
try
{
VehicleInformationComponent
vehicularHostComponent
=
simLocationActuator
.
getHost
().
getComponent
(
VehicleInformationComponent
.
class
);
vehicularHostComponent
.
resetVehicleID
();
}
catch
(
ComponentNotAvailableException
e
)
{
// Nothing to do here
}
hostVehicleIDMatching
.
remove
(
simLocationActuator
.
getHost
().
getId
());
try
{
RoutedNetLayer
routedNetLayer
=
simLocationActuator
.
getHost
().
getComponent
(
RoutedNetLayer
.
class
);
for
(
SimNetInterface
netInterface
:
routedNetLayer
.
getSimNetworkInterfaces
())
{
if
(
netInterface
.
isOnline
())
{
netInterface
.
goOffline
();
}
}
}
catch
(
ComponentNotAvailableException
e
)
{
e
.
printStackTrace
();
}
simLocationActuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
if
(
_reuseComponents
)
{
freeComponents
.
add
(
simLocationActuator
);
}
}
}
}
/**
* Request a component for a vehicle. If no component has been assigned to the vehicle yet, a new component is assigned.
* @param vehicle The vehicle for which a component is requested.
* @throws RuntimeException If no component can be assigned.
* @return The component for the vehicle.
*/
private
SimLocationActuator
requestSimActuator
(
String
vehicle
)
{
if
(!
idComponentMatcher
.
containsKey
(
vehicle
))
{
SimLocationActuator
simLocationActuator
=
freeComponents
.
poll
();
if
(
simLocationActuator
!=
null
)
{
VehicleInformationComponent
vehicularHostComponent
;
try
{
vehicularHostComponent
=
simLocationActuator
.
getHost
().
getComponent
(
VehicleInformationComponent
.
class
);
}
catch
(
ComponentNotAvailableException
e
)
{
Host
host
=
simLocationActuator
.
getHost
();
boolean
routeKnown
;
if
(
_knownRoutesRandom
.
nextDouble
()
<
_percentageOfKnownRoutes
)
{
routeKnown
=
true
;
}
else
{
routeKnown
=
false
;
}
vehicularHostComponent
=
new
DefaultVehicleInformationComponent
(
host
,
_controller
,
_extractor
,
routeKnown
);
host
.
registerComponent
(
vehicularHostComponent
);
}
vehicularHostComponent
.
setVehicleID
(
vehicle
);
idComponentMatcher
.
put
(
vehicle
,
simLocationActuator
);
hostVehicleIDMatching
.
put
(
simLocationActuator
.
getHost
().
getId
(),
vehicle
);
}
else
{
if
(
idComponentMatcher
.
size
()
!=
0
)
{
throw
new
RuntimeException
(
"Unable to assign new components. Please increase node amount"
+
(
_reuseComponents
?
"."
:
" or enable the reuse of components."
));
}
}
}
return
idComponentMatcher
.
get
(
vehicle
);
}
public
static
RoadNetwork
getRoadNetwork
()
{
return
MOVEMENT
.
_extractor
.
getRoadNetwork
();
}
}
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/SimulationSetupInformationProvider.java
deleted
100755 → 0
View file @
6bbe4677
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
javax.xml.parsers.ParserConfigurationException
;
import
javax.xml.parsers.SAXParser
;
import
javax.xml.parsers.SAXParserFactory
;
import
org.xml.sax.SAXException
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.CancelParsingSAXException
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.SimulationSetupInformationHandler
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
public
class
SimulationSetupInformationProvider
{
private
static
final
SimulationSetupInformationProvider
ONLY_INSTANCE
=
new
SimulationSetupInformationProvider
();
private
SimulationSetupInformationHandler
_handler
=
new
SimulationSetupInformationHandler
();
private
SimulationSetupInformationProvider
()
{
}
public
static
SimulationSetupInformationProvider
getOnlyInstance
()
{
return
ONLY_INSTANCE
;
}
public
Location
getUpperLeft
()
{
return
_handler
.
getUpperLeft
();
}
public
Location
getLowerRight
()
{
return
_handler
.
getLowerRight
();
}
public
static
void
init
(
String
pNetFileLocation
)
{
try
{
SAXParser
parser
=
SAXParserFactory
.
newInstance
().
newSAXParser
();
parser
.
parse
(
new
FileInputStream
(
pNetFileLocation
),
ONLY_INSTANCE
.
_handler
);
}
catch
(
CancelParsingSAXException
e
)
{
return
;
}
catch
(
ParserConfigurationException
|
SAXException
|
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/VehicleInformationContainer.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.topology.movement.vehicular.sumo.simulation.controller
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute
;
public
class
VehicleInformationContainer
{
private
Location
_position
;
private
double
_heading
;
private
double
_speed
;
private
RoadNetworkRoute
_route
;
public
VehicleInformationContainer
(
Location
pPosition
,
double
pHeading
,
double
pSpeed
,
RoadNetworkRoute
pRoute
)
{
_position
=
pPosition
;
_heading
=
pHeading
;
_speed
=
pSpeed
;
_route
=
pRoute
;
}
public
Location
getPosition
()
{
return
_position
;
}
public
double
getHeading
()
{
return
_heading
;
}
public
double
getSpeed
()
{
return
_speed
;
}
public
RoadNetworkRoute
getRoute
()
{
return
_route
;
}
public
void
setRoute
(
RoadNetworkRoute
pRoute
)
{
_route
=
pRoute
;
}
}
\ No newline at end of file
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/csv/RoadSideUnitInformationHandler.java
deleted
100755 → 0
View file @
6bbe4677
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Scanner
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
public
class
RoadSideUnitInformationHandler
{
private
List
<
Location
>
_positions
=
new
ArrayList
<>();
private
boolean
_observedAreaSet
=
false
;
private
double
_startX
=
-
1
;
private
double
_startY
=
-
1
;
private
double
_endX
=
-
1
;
private
double
_endY
=
-
1
;
public
List
<
Location
>
getIntersections
()
{
if
(!
_observedAreaSet
)
{
return
_positions
;
}
else
{
List
<
Location
>
result
=
new
ArrayList
<>();
for
(
Location
position
:
_positions
)
{
if
(
_startX
<=
position
.
getLongitudeOrX
()
&&
position
.
getLongitudeOrX
()
<=
_endX
&&
_startY
<=
position
.
getLatitudeOrY
()
&&
position
.
getLatitudeOrY
()
<=
_endY
)
{
result
.
add
(
new
PositionVector
(
position
.
getLongitudeOrX
()
-
_startX
,
position
.
getLatitudeOrY
()
-
_startY
,
0
));
}
}
return
result
;
}
}
public
void
parseIntersectionsFile
(
String
pRoadSideUnitDataPath
)
{
File
file
=
new
File
(
pRoadSideUnitDataPath
);
try
{
FileInputStream
inputStream
=
new
FileInputStream
(
file
);
Scanner
scanner
=
new
Scanner
(
inputStream
);
while
(
scanner
.
hasNextLine
())
{
String
line
=
scanner
.
nextLine
();
if
(
line
.
contains
(
";"
))
{
String
[]
split
=
line
.
split
(
";"
);
if
(
split
.
length
==
2
)
{
double
x
=
Double
.
parseDouble
(
split
[
0
]);
double
y
=
Double
.
parseDouble
(
split
[
1
]);
_positions
.
add
(
new
PositionVector
(
x
,
y
,
0
));
}
}
}
scanner
.
close
();
}
catch
(
FileNotFoundException
e
)
{
System
.
err
.
println
(
"Unable to read file "
+
e
.
getMessage
());
}
}
public
void
setObservedArea
(
double
pStartX
,
double
pStartY
,
double
pEndX
,
double
pEndY
)
{
_startX
=
pStartX
;
_startY
=
pStartY
;
_endX
=
pEndX
;
_endY
=
pEndY
;
_observedAreaSet
=
true
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java
deleted
100755 → 0
View file @
6bbe4677
This diff is collapsed.
Click to expand it.
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/xml/CancelParsingSAXException.java
deleted
100755 → 0
View file @
6bbe4677
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml
;
import
org.xml.sax.SAXException
;
public
class
CancelParsingSAXException
extends
SAXException
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
}
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/xml/SimulationSetupInformationHandler.java
deleted
100755 → 0
View file @
6bbe4677
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml
;
import
org.xml.sax.Attributes
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.helpers.DefaultHandler
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
public
class
SimulationSetupInformationHandler
extends
DefaultHandler
{
private
Location
_upperLeft
;
private
Location
_lowerRight
;
@Override
public
void
startElement
(
String
pUri
,
String
pLocalName
,
String
pQName
,
Attributes
pAttributes
)
throws
SAXException
{
if
(
pQName
.
equals
(
"location"
))
{
String
meterBoundary
=
pAttributes
.
getValue
(
"convBoundary"
);
if
(
meterBoundary
!=
null
)
{
String
[]
edges
=
meterBoundary
.
split
(
","
);
_upperLeft
=
new
PositionVector
(
Double
.
valueOf
(
edges
[
0
]),
Double
.
valueOf
(
edges
[
1
]),
0
);
_lowerRight
=
new
PositionVector
(
Double
.
valueOf
(
edges
[
2
]),
Double
.
valueOf
(
edges
[
3
]),
0
);
}
throw
new
CancelParsingSAXException
();
}
}
public
Location
getLowerRight
()
{
return
_lowerRight
;
}
public
Location
getUpperLeft
()
{
return
_upperLeft
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/xml/VehicleDataInformationHandler.java
deleted
100755 → 0
View file @
6bbe4677
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml
;
import
java.util.HashMap
;
import
org.xml.sax.Attributes
;
import
org.xml.sax.SAXException
;
import
org.xml.sax.helpers.DefaultHandler
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
public
class
VehicleDataInformationHandler
extends
DefaultHandler
{
private
boolean
_next
=
true
;
private
boolean
_run
=
true
;
private
HashMap
<
String
,
VehicleInformationContainer
>
_vehiclePositions
=
new
HashMap
<>();
private
double
_currentStep
=
-
1
;
private
boolean
_observedAreaSet
=
false
;
private
double
_startX
=
-
1
;
private
double
_startY
=
-
1
;
private
double
_endX
=
-
1
;
private
double
_endY
=
-
1
;
private
HashMap
<
String
,
VehicleInformationContainer
>
_nextVehiclePositions
=
new
HashMap
<>();
private
double
_nextStep
=
-
1
;
private
static
final
String
doublePattern
=
"-?[0-9]*\\.?[0-9]+"
;
private
boolean
_terminated
=
false
;
@Override
public
void
startElement
(
String
pUri
,
String
pLocalName
,
String
pQName
,
Attributes
pAttributes
)
throws
SAXException
{
if
(
pQName
.
equals
(
"timestep"
))
{
while
(!
_next
)
{
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
_next
=
false
;
String
value
=
pAttributes
.
getValue
(
"time"
);
if
(
value
.
matches
(
doublePattern
))
{
_nextStep
=
Double
.
valueOf
(
value
);
}
}
else
if
(
pQName
.
equals
(
"vehicle"
))
{
String
id
=
pAttributes
.
getValue
(
"id"
);
String
lonString
=
pAttributes
.
getValue
(
"x"
);
String
latString
=
pAttributes
.
getValue
(
"y"
);
String
speedString
=
pAttributes
.
getValue
(
"speed"
);
String
headingString
=
pAttributes
.
getValue
(
"angle"
);
if
(
lonString
.
matches
(
doublePattern
)
&&
latString
.
matches
(
doublePattern
)
&&
headingString
.
matches
(
doublePattern
)
&&
speedString
.
matches
(
doublePattern
)
)
{
double
lon
=
Double
.
valueOf
(
lonString
);
double
lat
=
Double
.
valueOf
(
latString
);
double
heading
=
Double
.
valueOf
(
headingString
);
double
speed
=
Double
.
valueOf
(
speedString
);
if
(
_observedAreaSet
)
{
if
(
_startX
<=
lon
&&
lon
<=
_endX
&&
_startY
<=
lat
&&
lat
<=
_endY
)
{
_nextVehiclePositions
.
put
(
id
,
new
VehicleInformationContainer
(
new
PositionVector
(
lon
-
_startX
,
lat
-
_startY
,
0
),
heading
,
speed
,
null
));
}
}
else
{
_nextVehiclePositions
.
put
(
id
,
new
VehicleInformationContainer
(
new
PositionVector
(
lon
,
lat
,
0
),
heading
,
speed
,
null
));
}
}
}
}
@Override
public
void
endElement
(
String
pUri
,
String
pLocalName
,
String
pQName
)
throws
SAXException
{
if
(
pQName
.
equals
(
"timestep"
))
{
_run
=
false
;
}
else
if
(
pQName
.
equals
(
"fcd-export"
))
{
while
(!
_next
)
{
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
_next
=
false
;
_run
=
false
;
_terminated
=
true
;
}
}
public
void
setObservedArea
(
double
pStartX
,
double
pStartY
,
double
pEndX
,
double
pEndY
)
{
_startX
=
pStartX
;
_startY
=
pStartY
;
_endX
=
pEndX
;
_endY
=
pEndY
;
_observedAreaSet
=
true
;
}
public
boolean
isTerminated
()
{
return
_terminated
;
}
public
HashMap
<
String
,
VehicleInformationContainer
>
getVehiclePositions
()
{
return
_vehiclePositions
;
}
public
void
readNext
()
{
while
(
_run
)
{
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
_vehiclePositions
=
_nextVehiclePositions
;
_currentStep
=
_nextStep
;
_nextStep
=
-
1
;
_nextVehiclePositions
=
new
HashMap
<>();
_run
=
true
;
_next
=
true
;
}
public
boolean
isRunning
()
{
return
_run
;
}
public
double
getStep
()
{
return
_currentStep
;
}
}
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/xml/XMLSimulationController.java
deleted
100755 → 0
View file @
6bbe4677
package
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml
;
import
java.io.FileInputStream
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
javax.xml.parsers.SAXParser
;
import
javax.xml.parsers.SAXParserFactory
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController
;
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.RoadNetworkRoute
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoAdditionalRouteAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException
;
public
class
XMLSimulationController
implements
VehicleController
,
SimulationSetupExtractor
,
Runnable
{
private
String
_vehicleDataPath
;
private
String
_roadSideUnitDataPath
;
private
List
<
String
>
_vehicles
;
private
Map
<
Double
,
Map
<
String
,
VehicleInformationContainer
>>
_positonsByTimestamp
=
new
HashMap
<>();
private
int
_futureInformation
=
0
;
private
boolean
_initalized
=
false
;
private
VehicleDataInformationHandler
_vehicleDataInformationHandler
=
new
VehicleDataInformationHandler
();
private
RoadSideUnitInformationHandler
_roadSideUnitInformationHandler
=
new
RoadSideUnitInformationHandler
();
private
double
_start
=
-
1
;
private
double
_step
;
public
XMLSimulationController
(
String
pVehicleDataPath
,
String
pRoadSideUnitDataPath
)
{
this
(
pVehicleDataPath
);
_roadSideUnitDataPath
=
pRoadSideUnitDataPath
;
}
public
XMLSimulationController
(
String
pVehicleDataPath
)
{
_vehicleDataPath
=
pVehicleDataPath
;
}
@Override
public
void
init
(
long
timeBetweenMoveOperations
)
{
if
(!
_initalized
)
{
if
(
_vehicleDataPath
!=
null
)
{
Thread
thread
=
new
Thread
(
this
);
thread
.
start
();
for
(
int
i
=
0
;
i
<
_futureInformation
;
i
++)
{
nextStep
(
Time
.
SECOND
);
}
}
if
(
_roadSideUnitDataPath
!=
null
)
{
_roadSideUnitInformationHandler
.
parseIntersectionsFile
(
_roadSideUnitDataPath
);
}
_initalized
=
true
;
}
}
@Override
public
Location
getVehiclePosition
(
String
pVehicleID
)
{
return
getVehiclePosition
(
_step
,
pVehicleID
);
}
public
VehicleInformationContainer
requestVehicleInformation
(
String
pVehicleID
)
{
return
_vehicleDataInformationHandler
.
getVehiclePositions
().
get
(
pVehicleID
);
}
@Override
public
boolean
nextStep
(
long
pTimeScale
)
{
_vehicleDataInformationHandler
.
readNext
();
_step
=
_vehicleDataInformationHandler
.
getStep
()
-
_futureInformation
;
if
(
_start
==
-
1
)
{
_start
=
_vehicleDataInformationHandler
.
getStep
();
}
double
newStep
=
_step
+
_futureInformation
;
if
(!
_positonsByTimestamp
.
containsKey
(
newStep
))
{
Map
<
String
,
VehicleInformationContainer
>
vehiclePositions
=
new
HashMap
<>();
_positonsByTimestamp
.
put
(
newStep
,
vehiclePositions
);
List
<
String
>
allVehicles
=
new
ArrayList
<>(
_vehicleDataInformationHandler
.
getVehiclePositions
().
keySet
());
for
(
String
vehicle
:
allVehicles
)
{
VehicleInformationContainer
vehiclePosition
=
requestVehicleInformation
(
vehicle
);
if
(
vehiclePosition
!=
null
)
{
vehiclePositions
.
put
(
vehicle
,
vehiclePosition
);
}
}
}
return
!
_vehicleDataInformationHandler
.
isTerminated
();
}
@Override
public
List
<
String
>
getAllVehicles
()
{
return
getAllVehicles
(
_step
);
}
@Override
public
double
getStep
()
{
return
_step
;
}
@Override
public
double
getStart
()
{
return
_start
;
}
@Override
public
void
run
()
{
try
{
SAXParser
parser
=
SAXParserFactory
.
newInstance
().
newSAXParser
();
parser
.
parse
(
new
FileInputStream
(
_vehicleDataPath
),
_vehicleDataInformationHandler
);
}
catch
(
RuntimeException
e
)
{
throw
e
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
void
setObservedArea
(
double
pStartX
,
double
pStartY
,
double
pEndX
,
double
pEndY
)
{
_vehicleDataInformationHandler
.
setObservedArea
(
pStartX
,
pStartY
,
pEndX
,
pEndY
);
_roadSideUnitInformationHandler
.
setObservedArea
(
pStartX
,
pStartY
,
pEndX
,
pEndY
);
}
@Override
public
Location
getVehiclePosition
(
double
pStep
,
String
pVehicleID
)
{
Map
<
String
,
VehicleInformationContainer
>
map
=
_positonsByTimestamp
.
get
(
pStep
);
return
map
.
get
(
pVehicleID
).
getPosition
();
}
@Override
public
List
<
String
>
getAllVehicles
(
double
pStep
)
{
Map
<
String
,
VehicleInformationContainer
>
map
=
_positonsByTimestamp
.
get
(
pStep
);
return
new
ArrayList
<>(
map
.
keySet
());
}
@Override
public
double
getMaximumAvailablePrediction
()
{
double
max
=
Collections
.
max
(
_positonsByTimestamp
.
keySet
());
return
max
;
}
@Override
public
List
<
Location
>
getAllIntersections
(
boolean
pCluster
)
{
return
_roadSideUnitInformationHandler
.
getIntersections
();
}
@Override
public
double
getScenarioWidth
()
{
return
-
1
;
}
@Override
public
double
getScenarioHeight
()
{
return
-
1
;
}
@Override
public
double
getVehicleLength
(
String
pVehicleID
)
{
throw
new
UnsupportedOperationException
(
"This method is not supported for "
+
getClass
().
getSimpleName
());
}
@Override
public
RoadNetworkRoute
getCurrentRoute
(
String
pVehicleID
)
{
throw
new
UnsupportedOperationException
(
"This method is not supported for "
+
getClass
().
getSimpleName
());
}
@Override
public
RoadNetwork
getRoadNetwork
()
{
return
null
;
}
@Override
public
void
rerouteVehicle
(
String
pVehicle
,
RoadNetworkRoute
pRoute
)
{
throw
new
UnsupportedOperationException
(
"This method is not supported for "
+
getClass
().
getSimpleName
());
}
@Override
public
RoadNetworkRoute
findNewRoute
(
String
pVehicle
)
throws
NoAdditionalRouteAvailableException
{
throw
new
UnsupportedOperationException
(
"This method is not supported for "
+
getClass
().
getSimpleName
());
}
@Override
public
RoadNetworkRoute
findNewRoute
(
String
pVehicle
,
List
<
RoadNetworkEdge
>
pEdgesToAvoid
,
boolean
pKeepDestination
)
throws
NoAdditionalRouteAvailableException
,
NoExitAvailableException
{
throw
new
UnsupportedOperationException
(
"This method is not supported for "
+
getClass
().
getSimpleName
());
}
@Override
public
void
stopVehicle
(
String
pVehicle
)
{
throw
new
UnsupportedOperationException
(
"This method is not supported for "
+
getClass
().
getSimpleName
());
}
@Override
public
double
getVehicleSpeed
(
String
pVehicleID
)
{
return
_vehicleDataInformationHandler
.
getVehiclePositions
().
get
(
pVehicleID
).
getSpeed
();
}
@Override
public
double
getVehicleHeading
(
String
pVehicleID
)
{
return
_vehicleDataInformationHandler
.
getVehiclePositions
().
get
(
pVehicleID
).
getHeading
();
}
}
src/de/tud/kom/p2psim/impl/topology/placement/RSUPlacement.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.topology.placement
;
import
java.util.List
;
import
de.tud.kom.p2psim.api.topology.TopologyComponent
;
import
de.tud.kom.p2psim.api.topology.placement.PlacementModel
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
/**
*/
public
class
RSUPlacement
implements
PlacementModel
{
private
final
String
sumoExe
;
private
final
String
sumoConfigFile
;
private
final
String
sumoIntersections
;
private
final
int
offsetX
;
private
final
int
offsetY
;
private
final
int
width
;
private
final
int
height
;
private
SimulationSetupExtractor
_controller
;
private
List
<
Location
>
_intersections
;
private
int
_currentIndex
=
0
;
@XMLConfigurableConstructor
({
"sumoExe"
,
"sumoConfigFile"
,
"offsetX"
,
"offsetY"
,
"width"
,
"height"
})
public
RSUPlacement
(
String
sumoExe
,
String
sumoConfigFile
,
String
offsetX
,
String
offsetY
,
String
width
,
String
height
)
{
this
.
sumoExe
=
sumoExe
;
this
.
sumoConfigFile
=
sumoConfigFile
;
this
.
sumoIntersections
=
null
;
this
.
offsetX
=
Integer
.
parseInt
(
offsetX
);
this
.
offsetY
=
Integer
.
parseInt
(
offsetY
);
this
.
width
=
Integer
.
parseInt
(
width
);
this
.
height
=
Integer
.
parseInt
(
height
);
initializeModel
();
}
@XMLConfigurableConstructor
({
"sumoIntersections"
,
"offsetX"
,
"offsetY"
,
"width"
,
"height"
})
public
RSUPlacement
(
String
sumoIntersections
,
String
offsetX
,
String
offsetY
,
String
width
,
String
height
)
{
this
.
sumoIntersections
=
sumoIntersections
;
this
.
sumoExe
=
null
;
this
.
sumoConfigFile
=
null
;
this
.
offsetX
=
Integer
.
parseInt
(
offsetX
);
this
.
offsetY
=
Integer
.
parseInt
(
offsetY
);
this
.
width
=
Integer
.
parseInt
(
width
);
this
.
height
=
Integer
.
parseInt
(
height
);
initializeModel
();
}
/**
* Initializes the movement model by executing BonnMotion and parsing the
* resulting movement trace.
*/
protected
void
initializeModel
()
{
if
(
this
.
sumoExe
!=
null
)
{
_controller
=
TraciSimulationController
.
createSimulationController
(
sumoExe
,
sumoConfigFile
,
1
);
_controller
.
init
(
Time
.
SECOND
);
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
_intersections
=
_controller
.
getAllIntersections
(
true
);
}
else
{
_controller
=
new
XMLSimulationController
(
null
,
sumoIntersections
);
_controller
.
init
(
Time
.
SECOND
);
_controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
_intersections
=
_controller
.
getAllIntersections
(
true
);
}
}
@Override
public
void
addComponent
(
TopologyComponent
comp
)
{
//
}
@Override
public
PositionVector
place
(
TopologyComponent
comp
)
{
if
(
_currentIndex
<
_intersections
.
size
())
{
Location
intersection
=
_intersections
.
get
(
_currentIndex
);
_currentIndex
++;
return
new
PositionVector
(
intersection
.
getLongitudeOrX
(),
intersection
.
getLatitudeOrY
());
}
else
{
return
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
);
}
}
}
src/de/tud/kom/p2psim/impl/vehicular/DefaultVehicleInformationComponent.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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
;
import
java.util.List
;
import
java.util.Set
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.privacy.PrivacyComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.privacy.PrivacyLevel
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.VehicleProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.route.Route
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController
;
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.exception.NoAdditionalRouteAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException
;
public
class
DefaultVehicleInformationComponent
implements
VehicleInformationComponent
{
private
Host
host
;
private
VehicleController
controller
;
private
SimulationSetupExtractor
extractor
;
private
String
vehicleID
;
private
long
_startingTime
=
-
1
;
public
DefaultVehicleInformationComponent
(
Host
host
,
VehicleController
controller
,
SimulationSetupExtractor
extractor
,
boolean
pRouteKnown
)
{
this
.
host
=
host
;
this
.
controller
=
controller
;
this
.
extractor
=
extractor
;
try
{
SiSComponent
siSComponent
=
getHost
().
getComponent
(
SiSComponent
.
class
);
siSComponent
.
provide
().
nodeState
(
SiSTypes
.
ROAD_EDGE
,
new
SiSDataCallback
<
RoadNetworkEdge
>()
{
@Override
public
RoadNetworkEdge
getValue
(
INodeID
pNodeID
,
SiSProviderHandle
pProviderHandle
)
throws
InformationNotAvailableException
{
if
(
pNodeID
==
getHost
().
getId
())
{
if
(
isValid
())
{
RoadNetworkRoute
route
=
getCurrentRoute
();
if
(
route
!=
null
)
{
return
route
.
getStart
();
}
}
}
return
null
;
}
@Override
public
Set
<
INodeID
>
getObservedNodes
()
{
return
INodeID
.
getSingleIDSet
(
getHost
().
getId
());
}
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
new
SiSInfoProperties
();
}
});
siSComponent
.
provide
().
nodeState
(
SiSTypes
.
HEADING
,
new
SiSDataCallback
<
Double
>()
{
@Override
public
Double
getValue
(
INodeID
pNodeID
,
SiSProviderHandle
pProviderHandle
)
throws
InformationNotAvailableException
{
if
(
pNodeID
==
getHost
().
getId
())
{
if
(
isValid
())
{
return
controller
.
getVehicleHeading
(
vehicleID
);
}
}
return
null
;
}
@Override
public
Set
<
INodeID
>
getObservedNodes
()
{
return
INodeID
.
getSingleIDSet
(
getHost
().
getId
());
}
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
new
SiSInfoProperties
();
}
});
siSComponent
.
provide
().
nodeState
(
SiSTypes
.
VEHICLE_LENGTH
,
new
SiSDataCallback
<
Double
>()
{
@Override
public
Double
getValue
(
INodeID
pNodeID
,
SiSProviderHandle
pProviderHandle
)
throws
InformationNotAvailableException
{
if
(
pNodeID
==
getHost
().
getId
())
{
if
(
isValid
())
{
return
controller
.
getVehicleLength
(
vehicleID
);
}
}
return
null
;
}
@Override
public
Set
<
INodeID
>
getObservedNodes
()
{
return
INodeID
.
getSingleIDSet
(
getHost
().
getId
());
}
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
new
SiSInfoProperties
();
}
});
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
)
{
// Nothing to do!
}
}
@Override
public
VehicleProperty
getVehicleProperty
()
{
PrivacyLevel
privacyLevel
=
PrivacyLevel
.
NO_PRIVACY
;
try
{
PrivacyComponent
privacyComponent
=
getHost
().
getComponent
(
PrivacyComponent
.
class
);
privacyLevel
=
privacyComponent
.
getPrivacyLevel
();
}
catch
(
ComponentNotAvailableException
e
)
{
// Nothing to be done
}
return
new
VehicleProperty
(
host
.
getId
().
value
(),
getLastLocation
(),
getCurrentRoute
().
getStart
(),
getCurrentSpeed
(),
getLength
(),
privacyLevel
);
}
@Override
public
void
setVehicleID
(
String
pVehicleID
)
{
vehicleID
=
pVehicleID
;
_startingTime
=
Time
.
getCurrentTime
();
}
@Override
public
long
getStartingTime
()
{
return
_startingTime
;
}
@Override
public
void
resetVehicleID
()
{
vehicleID
=
null
;
}
@Override
public
void
initialize
()
{
// TODO Auto-generated method stub
}
@Override
public
void
shutdown
()
{
// TODO Auto-generated method stub
}
@Override
public
Host
getHost
()
{
return
host
;
}
@Override
public
RoadNetworkRoute
getCurrentRoute
()
{
return
controller
.
getCurrentRoute
(
vehicleID
);
}
@Override
public
boolean
changeCurrentRoute
(
RoadNetworkRoute
pRoute
)
{
controller
.
rerouteVehicle
(
vehicleID
,
pRoute
);
return
true
;
}
public
double
getLength
()
{
return
controller
.
getVehicleLength
(
vehicleID
);
}
@Override
public
RoadNetworkRoute
findNewRoute
()
{
try
{
return
controller
.
findNewRoute
(
vehicleID
);
}
catch
(
NoAdditionalRouteAvailableException
e
)
{
return
null
;
}
}
@Override
public
RoadNetworkRoute
findNewRoute
(
List
<
RoadNetworkEdge
>
pEdgesToAvoid
,
boolean
pKeepDestination
)
{
try
{
return
controller
.
findNewRoute
(
vehicleID
,
pEdgesToAvoid
,
pKeepDestination
);
}
catch
(
NoAdditionalRouteAvailableException
|
NoExitAvailableException
e
)
{
return
null
;
}
}
@Override
public
boolean
isValid
()
{
return
vehicleID
!=
null
;
}
@Override
public
void
stopVehicle
()
{
controller
.
stopVehicle
(
vehicleID
);
}
@Override
public
double
getCurrentSpeed
()
{
return
controller
.
getVehicleSpeed
(
vehicleID
);
}
@Override
public
void
addRouteListener
(
RouteListener
listener
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
removeRouteListener
(
RouteListener
listener
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
addRouteSegmentListener
(
RouteSegmentListener
listener
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
removeRouteSegmentListener
(
RouteSegmentListener
listener
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
Route
getRoute
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
Location
getLastLocation
()
{
return
controller
.
getVehiclePosition
(
vehicleID
);
}
@Override
public
void
requestLocationUpdates
(
LocationRequest
pRequest
,
LocationListener
pListener
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
removeLocationUpdates
(
LocationListener
pListener
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
LocationRequest
getLocationRequest
()
{
throw
new
UnsupportedOperationException
();
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/DefaultCachingComponent.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.tud.kom.p2psim.impl.vehicular.caching
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID
;
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.NetworkComponent.NetInterfaceName
;
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.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.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheSizeAwareCacheDecisionStrategy
;
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.information.AggregatedInformation
;
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.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.RoadNetworkRoute
;
public
class
DefaultCachingComponent
implements
CachingComponent
,
ConnectivityListener
{
private
Map
<
Class
<?
extends
Object
>,
List
<
PointInformation
>>
_cache
=
new
HashMap
<>();
private
Map
<
Integer
,
Integer
>
_lastColorValues
=
new
HashMap
<>();
private
Host
_host
;
private
CacheInvalidationStrategy
_invalidationStrategy
;
private
CacheReplacementStrategy
_replacementStrategy
;
private
CacheDecisionStrategy
_defaultDecisionStrategy
;
private
Map
<
Class
<?
extends
Object
>,
CacheDecisionStrategy
>
_decisionStrategies
=
new
HashMap
<>();
private
int
_minObservations
=
0
;
private
int
_maxCacheSize
=
Integer
.
MAX_VALUE
;
private
double
[]
informationRatios
=
new
double
[]
{
1
,
0.75
,
0.5
,
0.25
,
0
};
private
List
<
CacheStateListener
>
_cacheStateListeners
=
new
ArrayList
<>();
public
DefaultCachingComponent
(
Host
pHost
,
CacheInvalidationStrategy
pInvalidationStrategy
,
CacheReplacementStrategy
pReplacementStrategy
,
CacheDecisionStrategy
pDecisionStrategy
)
{
_host
=
pHost
;
if
(
_host
!=
null
)
{
NetInterface
cellular
=
_host
.
getNetworkComponent
().
getByName
(
NetInterfaceName
.
MOBILE
);
cellular
.
addConnectivityListener
(
this
);
}
_invalidationStrategy
=
pInvalidationStrategy
;
_replacementStrategy
=
pReplacementStrategy
;
_defaultDecisionStrategy
=
pDecisionStrategy
;
}
private
TransitionEngine
getTransitionEngine
()
throws
AssertionError
{
try
{
return
getHost
().
getComponent
(
TransitionEngine
.
class
);
}
catch
(
ComponentNotAvailableException
e
)
{
throw
new
AssertionError
(
"Unable to get transition engine!"
);
}
}
@Override
public
void
registerCacheStateListener
(
CacheStateListener
pListener
)
{
_cacheStateListeners
.
add
(
pListener
);
}
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
)
{
CacheDecisionStrategy
decisionStrategy
=
getCacheDecisionStrategy
(
pCacheEntryClass
);
Set
<
RoadNetworkEdge
>
allEverActiveEdges
=
RoadNetwork
.
CURRENT_ROAD_NETWORK
.
getAllEverActiveEdges
();
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
if
(
cacheEntries
==
null
)
{
return
null
;
}
Map
<
Object
,
Map
<
Class
<?
extends
Object
>,
List
<
PointInformation
>>>
similarCacheEntries
=
new
HashMap
<>();
for
(
T
t
:
cacheEntries
)
{
Object
position
=
getEdgeOrPosition
(
t
);
if
(!(
position
instanceof
RoadNetworkEdge
)
||
allEverActiveEdges
.
contains
((
position
)))
{
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
>());
}
similarCacheEntries
.
get
(
position
).
get
(
t
.
getValue
().
getClass
()).
add
(
t
);
}
}
List
<
T
>
decidedInformation
=
new
ArrayList
<>();
for
(
Map
<
Class
<?
extends
Object
>,
List
<
PointInformation
>>
similarEdges
:
similarCacheEntries
.
values
())
{
for
(
List
<
PointInformation
>
similarInformation
:
similarEdges
.
values
())
{
if
(
similarInformation
.
size
()
>=
_minObservations
)
{
PointInformation
correctInformation
=
decisionStrategy
.
decideOnCorrectInformation
(
similarInformation
);
decidedInformation
.
add
((
T
)
correctInformation
);
}
}
}
return
decidedInformation
;
}
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
,
RoadNetworkEdge
pEdge
)
{
return
getDecidedCacheEntries
(
pCacheEntryClass
,
null
,
pEdge
);
}
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
,
Class
<?>
pCacheValueClass
,
RoadNetworkEdge
pEdge
)
{
return
getDecidedCacheEntries
(
pCacheEntryClass
,
pCacheValueClass
,
pEdge
,
null
);
}
@Override
public
<
T
extends
PointInformation
>
List
<
T
>
getDecidedCacheEntries
(
Class
<
T
>
pCacheEntryClass
,
Class
<?>
pCacheValueClass
,
RoadNetworkEdge
pEdge
,
INodeID
pWithoutID
)
{
CacheDecisionStrategy
decisionStrategy
=
getCacheDecisionStrategy
(
pCacheEntryClass
);
Set
<
RoadNetworkEdge
>
allEverActiveEdges
=
RoadNetwork
.
CURRENT_ROAD_NETWORK
.
getAllEverActiveEdges
();
if
(!
allEverActiveEdges
.
contains
(
pEdge
))
{
return
null
;
}
List
<
T
>
cacheEntries
=
getCacheEntries
(
pCacheEntryClass
);
if
(
cacheEntries
==
null
)
{
return
null
;
}
Map
<
Class
<?
extends
Object
>,
List
<
PointInformation
>>
similarCacheEntries
=
new
HashMap
<>();
for
(
T
t
:
cacheEntries
)
{
if
(
pWithoutID
==
null
||
!
t
.
getAttribute
(
AvailableInformationAttributes
.
OWNER
).
equals
(
pWithoutID
))
{
Object
position
=
getEdgeOrPosition
(
t
);
if
(
position
.
equals
(
pEdge
)
&&
(
pCacheValueClass
==
null
||
t
.
getValue
().
getClass
().
equals
(
pCacheValueClass
)))
{
if
(!
similarCacheEntries
.
containsKey
(
t
.
getValue
().
getClass
()))
{
similarCacheEntries
.
put
(
t
.
getValue
().
getClass
(),
new
ArrayList
<
PointInformation
>());
}
similarCacheEntries
.
get
(
t
.
getValue
().
getClass
()).
add
(
t
);
}
}
}
List
<
T
>
decidedInformation
=
new
ArrayList
<>();
for
(
List
<
PointInformation
>
similarInformation
:
similarCacheEntries
.
values
())
{
if
(
similarInformation
.
size
()
>=
_minObservations
)
{
PointInformation
correctInformation
=
decisionStrategy
.
decideOnCorrectInformation
(
similarInformation
);
decidedInformation
.
add
((
T
)
correctInformation
);
}
}
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
)
{
this
.
_minObservations
=
pMinObservations
;
}
@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
<>();
for
(
int
i
=
0
;
i
<
cacheEntries
.
size
();
i
++)
{
PointInformation
object
=
cacheEntries
.
get
(
i
);
if
(
_invalidationStrategy
.
checkInformation
(
object
))
{
cacheEntries
.
remove
(
i
--);
continue
;
}
results
.
add
((
T
)
object
);
}
return
results
;
}
return
null
;
}
@Override
public
<
T
extends
PointInformation
>
boolean
containsEntry
(
T
pCacheEntry
)
{
if
(
_cache
.
containsKey
(
pCacheEntry
.
getClass
()))
{
List
<?
extends
Object
>
cacheEntries
=
_cache
.
get
(
pCacheEntry
.
getClass
());
return
cacheEntries
.
contains
(
pCacheEntry
);
}
return
false
;
}
@Override
public
<
T
extends
PointInformation
>
void
storeCacheEntry
(
T
pCacheEntry
)
{
if
(!
_cache
.
containsKey
(
pCacheEntry
.
getClass
()))
{
_cache
.
put
(
pCacheEntry
.
getClass
(),
new
ArrayList
<>());
}
List
<
PointInformation
>
entries
=
_cache
.
get
(
pCacheEntry
.
getClass
());
if
(
pCacheEntry
instanceof
AggregatedInformation
&&
((
AggregatedInformation
)
pCacheEntry
).
isAggregated
())
{
List
<
PointInformation
>
toBeRemoved
=
new
ArrayList
<>();
for
(
PointInformation
pointInformation
:
entries
)
{
if
(
_replacementStrategy
.
replaceInformation
(
pointInformation
,
pCacheEntry
))
{
toBeRemoved
.
add
(
pointInformation
);
}
}
for
(
PointInformation
pointInformation
:
toBeRemoved
)
{
entries
.
remove
(
pointInformation
);
}
}
shrinkCache
(
_maxCacheSize
);
entries
.
add
(
pCacheEntry
);
for
(
CacheStateListener
cacheStateListener
:
_cacheStateListeners
)
{
cacheStateListener
.
entryStored
(
pCacheEntry
);
}
}
private
void
shrinkCache
(
int
maxSize
)
{
while
(
getTotalCacheSize
()
>
maxSize
)
{
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
(!((
RoadNetworkEdge
)
entry
.
getKey
()).
isActive
())
{
removedValues
=
entry
.
getValue
();
removedList
=
informationList
;
break
;
}
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
);
}
}
}
private
int
getTotalCacheSize
()
{
int
sum
=
0
;
for
(
List
<
PointInformation
>
informationList
:
_cache
.
values
())
{
sum
+=
informationList
.
size
();
}
return
sum
;
}
@Override
public
void
initialize
()
{
_cache
.
clear
();
}
@Override
public
void
shutdown
()
{
}
@Override
public
Host
getHost
()
{
return
_host
;
}
@Override
public
void
wentOnline
(
Host
pHost
,
NetInterface
pNetInterface
)
{
_cache
.
clear
();
}
@Override
public
void
wentOffline
(
Host
pHost
,
NetInterface
pNetInterface
)
{
}
@Override
public
void
performDecisionTransition
(
Class
<?
extends
Object
>
pInformationClass
,
Class
<?
extends
CacheDecisionStrategy
>
pCacheDecisionStrategy
)
{
getTransitionEngine
().
executeAtomicTransition
(
DECISION_STRATEGY
+
pInformationClass
.
getSimpleName
(),
pCacheDecisionStrategy
);
}
@Override
public
void
setMaxSize
(
int
pMaxCacheSize
)
{
_maxCacheSize
=
pMaxCacheSize
;
shrinkCache
(
_maxCacheSize
);
}
@Override
public
void
adjustCacheSizePerEntry
(
Class
<?
extends
Object
>
pInformationClass
,
int
pMaxCacheSizePerEntry
)
{
getTransitionEngine
().
alterLocalState
(
DECISION_STRATEGY
+
pInformationClass
.
getSimpleName
(),
CacheSizeAwareCacheDecisionStrategy
.
class
,
"CacheSize"
,
pMaxCacheSizePerEntry
);
}
@Override
public
void
clear
()
{
_cache
.
clear
();
}
@Override
public
<
T
extends
PointInformation
>
void
partialClear
(
Class
<
T
>
pCacheEntryClass
,
Class
<?>
pCacheValueClass
,
RoadNetworkEdge
pEdge
)
{
List
<
PointInformation
>
cacheEntries
=
_cache
.
get
(
pCacheEntryClass
);
if
(
cacheEntries
==
null
)
{
return
;
}
List
<
PointInformation
>
toBeRemoved
=
new
ArrayList
<>();
for
(
PointInformation
entry
:
cacheEntries
)
{
if
((
pEdge
==
null
||
getEdgeOrPosition
(
entry
).
equals
(
pEdge
))
&&
(
pCacheEntryClass
==
null
||
entry
.
getValue
().
getClass
().
equals
(
pCacheValueClass
)))
{
toBeRemoved
.
add
(
entry
);
}
}
cacheEntries
.
removeAll
(
toBeRemoved
);
}
public
Object
getEdgeOrPosition
(
PointInformation
information
)
{
if
(
information
.
hasAttribute
(
AvailableInformationAttributes
.
EDGE
))
{
return
information
.
getAttribute
(
AvailableInformationAttributes
.
EDGE
);
}
else
if
(
information
instanceof
RoadInformation
)
{
return
((
RoadInformation
)
information
).
getEdge
();
}
else
{
return
information
.
getLocation
();
}
}
@Override
public
String
getNodeDescription
()
{
if
(
getHost
().
getId
().
value
()
>
47
)
{
return
" "
+
getHost
().
getId
();
}
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
();
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/AveragingCacheDecisionStrategy.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.Map
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.NumericVectoralProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralJamProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation
;
public
class
AveragingCacheDecisionStrategy
extends
AbstractCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
Map
<
CacheDecisionStrategyParameters
,
String
>
_params
;
@TransferState
(
value
=
{
"Params"
})
public
AveragingCacheDecisionStrategy
(
Map
<
CacheDecisionStrategyParameters
,
String
>
pParams
)
{
_params
=
pParams
;
}
@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
;
}
double
sum
=
0
;
double
count
=
0
;
NumericVectoralProperty
cloned
=
null
;
for
(
T
t
:
pSimilarPointInformation
)
{
RoadInformation
roadInformation
=
((
RoadInformation
)
t
);
NumericVectoralProperty
property
=
(
NumericVectoralProperty
)
roadInformation
.
getValue
();
if
(
cloned
==
null
)
{
cloned
=
property
.
clone
();
}
sum
+=
property
.
getMostProbableValue
();
count
++;
}
double
value
=
sum
/
count
;
if
(
cloned
instanceof
VectoralJamProperty
)
{
((
VectoralJamProperty
)
cloned
).
setSpeed
(((
int
)(
value
/
VectoralJamProperty
.
SCALING
))
*
VectoralJamProperty
.
SCALING
);
}
else
{
throw
new
AssertionError
(
"Unknown data type "
+
cloned
.
getClass
().
getSimpleName
());
}
RoadInformation
aggregate
=
new
RoadInformation
(
cloned
);
addAggregationInformation
(
pSimilarPointInformation
,
aggregate
);
return
(
T
)
aggregate
;
}
public
Map
<
CacheDecisionStrategyParameters
,
String
>
getParams
()
{
return
_params
;
}
@Override
public
AveragingCacheDecisionStrategy
clone
()
{
return
new
AveragingCacheDecisionStrategy
(
_params
);
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/CacheDecisionStrategyType.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.lang.reflect.Constructor
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters
;
public
enum
CacheDecisionStrategyType
{
DEFAULT
(
NewestCacheDecisionStrategy
.
class
),
NEWEST
(
NewestCacheDecisionStrategy
.
class
),
MAJORITY
(
MajorityVotingCacheDecisionStrategy
.
class
),
AVERAGING
(
AveragingCacheDecisionStrategy
.
class
),
TTL
(
TTLbasedCacheDecisionStrategy
.
class
),
OPTIMAL
(
OptimalCacheDecisionStrategy
.
class
),
RANDOM
(
RandomCacheDecisionStrategy
.
class
),
TTL_VECTOR
(
TTLbasedVectoralCacheDecisionStrategy
.
class
),
MAJORITY_VECTOR
(
MajorityVotingVectoralCacheDecisionStrategy
.
class
);
private
final
Class
<?
extends
CacheDecisionStrategy
>
decisionStrategy
;
private
final
Map
<
CacheDecisionStrategyParameters
,
String
>
params
=
new
HashMap
<>();
private
CacheDecisionStrategyType
(
final
Class
<?
extends
CacheDecisionStrategy
>
decisionStrategy
)
{
this
.
decisionStrategy
=
decisionStrategy
;
}
public
CacheDecisionStrategy
getDecisionStrategy
()
{
try
{
try
{
Constructor
<?
extends
CacheDecisionStrategy
>
constructor
=
decisionStrategy
.
getConstructor
(
Map
.
class
);
return
constructor
.
newInstance
(
params
);
}
catch
(
NoSuchMethodException
|
SecurityException
|
IllegalArgumentException
|
InvocationTargetException
e
)
{
return
decisionStrategy
.
newInstance
();
}
}
catch
(
InstantiationException
|
IllegalAccessException
e
)
{
throw
new
AssertionError
(
e
);
}
}
public
void
addAttribute
(
CacheDecisionStrategyParameters
pParam
,
String
pValue
)
{
params
.
put
(
pParam
,
pValue
);
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/MajorityVotingCacheDecisionStrategy.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.RoadInformation
;
public
class
MajorityVotingCacheDecisionStrategy
extends
AbstractCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
Map
<
CacheDecisionStrategyParameters
,
String
>
_params
;
@TransferState
(
value
=
{
"Params"
})
public
MajorityVotingCacheDecisionStrategy
(
Map
<
CacheDecisionStrategyParameters
,
String
>
pParams
)
{
_params
=
pParams
;
}
@Override
public
<
T
extends
PointInformation
>
T
decideOnCorrectInformation
(
List
<
T
>
pSimilarPointInformation
)
{
Map
<
Object
,
Integer
>
voting
=
new
HashMap
<>();
for
(
T
t
:
pSimilarPointInformation
)
{
Object
value
=
t
.
getValue
();
if
(
value
instanceof
VectoralProperty
)
{
value
=
((
VectoralProperty
)
value
).
getMostProbableValue
();
}
if
(!
voting
.
containsKey
(
value
))
{
voting
.
put
(
value
,
0
);
}
voting
.
put
(
value
,
voting
.
get
(
value
)
+
1
);
}
Entry
<
Object
,
Integer
>
maxEntry
=
null
;
for
(
Entry
<
Object
,
Integer
>
entry
:
voting
.
entrySet
())
{
if
(
maxEntry
==
null
)
{
maxEntry
=
entry
;
}
if
(
maxEntry
.
getValue
()
<
entry
.
getValue
())
{
maxEntry
=
entry
;
}
}
long
maxTimestamp
=
0
;
T
maxFitting
=
null
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
if
((
t
.
getValue
().
equals
(
maxEntry
.
getKey
())
||
t
.
getValue
()
instanceof
VectoralProperty
&&
((
VectoralProperty
)
t
.
getValue
()).
getMostProbableValue
().
equals
(
maxEntry
.
getKey
()))
&&
timestamp
>
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
maxFitting
=
t
;
}
}
addAggregationInformation
(
pSimilarPointInformation
,
maxFitting
);
return
maxFitting
;
}
public
Map
<
CacheDecisionStrategyParameters
,
String
>
getParams
()
{
return
_params
;
}
@Override
public
MajorityVotingCacheDecisionStrategy
clone
()
{
return
new
MajorityVotingCacheDecisionStrategy
(
_params
);
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/MajorityVotingVectoralCacheDecisionStrategy.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.Map
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.TemporalDependencyMatrix
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters
;
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.information.RoadInformation
;
public
class
MajorityVotingVectoralCacheDecisionStrategy
extends
AbstractCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
static
final
long
SCALING
=
Time
.
SECOND
;
private
Map
<
CacheDecisionStrategyParameters
,
String
>
_params
;
@TransferState
(
value
=
{
"Params"
})
public
MajorityVotingVectoralCacheDecisionStrategy
(
Map
<
CacheDecisionStrategyParameters
,
String
>
pParams
)
{
_params
=
pParams
;
}
@Override
public
<
T
extends
PointInformation
>
T
decideOnCorrectInformation
(
List
<
T
>
pSimilarPointInformation
)
{
VectoralProperty
currentProperty
=
null
;
long
minTimestamp
=
Long
.
MAX_VALUE
;
long
maxTimestamp
=
0
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
if
(
timestamp
<
minTimestamp
)
{
minTimestamp
=
timestamp
;
}
if
(
timestamp
>
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
}
}
for
(
T
t
:
pSimilarPointInformation
)
{
RoadInformation
roadInformation
=
((
RoadInformation
)
t
);
VectoralProperty
property
=
(
VectoralProperty
)
roadInformation
.
getValue
();
TemporalDependencyMatrix
dependencyMatrix
=
property
.
getDependencyMatrix
();
VectoralProperty
agedProperty
=
property
.
age
((
maxTimestamp
-
property
.
getDetectionDate
())
/
SCALING
,
dependencyMatrix
);
if
(
currentProperty
!=
null
)
{
currentProperty
=
currentProperty
.
combine
(
agedProperty
);
}
else
{
currentProperty
=
agedProperty
;
}
}
// TemporalDependencyMatrix dependencyMatrix = currentProperty.getDependencyMatrix();
//
// VectoralProperty agedProperty = currentProperty.age((Time.getCurrentTime() - maxTimestamp) / SCALING, dependencyMatrix);
RoadInformation
roadInformation
=
new
RoadInformation
(
currentProperty
);
copyAttributes
((
RoadInformation
)
pSimilarPointInformation
.
get
(
0
),
roadInformation
);
addAggregationInformation
(
pSimilarPointInformation
,
roadInformation
);
return
(
T
)
roadInformation
;
}
/**
* @param pT
* @param pRoadInformation
*/
private
void
copyAttributes
(
RoadInformation
pSrc
,
RoadInformation
pDest
)
{
for
(
AvailableInformationAttributes
attribute
:
pSrc
.
getAvailableAttributes
())
{
pDest
.
setAttribute
(
attribute
,
pSrc
.
getAttribute
(
attribute
));
}
}
public
Map
<
CacheDecisionStrategyParameters
,
String
>
getParams
()
{
return
_params
;
}
@Override
public
MajorityVotingVectoralCacheDecisionStrategy
clone
()
{
return
new
MajorityVotingVectoralCacheDecisionStrategy
(
_params
);
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/NewestCacheDecisionStrategy.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.Map
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.information.PointInformation
;
public
class
NewestCacheDecisionStrategy
extends
AbstractCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
Map
<
CacheDecisionStrategyParameters
,
String
>
_params
;
@TransferState
(
value
=
{
"Params"
})
public
NewestCacheDecisionStrategy
(
Map
<
CacheDecisionStrategyParameters
,
String
>
pParams
)
{
_params
=
pParams
;
}
@Override
public
<
T
extends
PointInformation
>
T
decideOnCorrectInformation
(
List
<
T
>
pSimilarPointInformation
)
{
long
newestDetectionTime
=
0
;
T
chosenInformation
=
null
;
for
(
T
t
:
pSimilarPointInformation
)
{
if
(
t
.
getDetectionDate
()
>
newestDetectionTime
)
{
newestDetectionTime
=
t
.
getDetectionDate
();
chosenInformation
=
t
;
}
}
return
chosenInformation
;
}
public
Map
<
CacheDecisionStrategyParameters
,
String
>
getParams
()
{
return
_params
;
}
@Override
public
NewestCacheDecisionStrategy
clone
()
{
return
new
NewestCacheDecisionStrategy
(
_params
);
}
}
src/de/tud/kom/p2psim/impl/vehicular/caching/decision/OptimalCacheDecisionStrategy.java
deleted
100755 → 0
View file @
6bbe4677
/*
* 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.Map
;
import
de.tudarmstadt.maki.simonstrator.api.Time
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.JamProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.environment.data.properties.vectoral.VectoralProperty
;
import
de.tudarmstadt.maki.simonstrator.api.component.transition.TransferState
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.AbstractCacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategy
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.caching.decision.CacheDecisionStrategyParameters
;
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.roadnetwork.RoadNetworkEdge
;
public
class
OptimalCacheDecisionStrategy
extends
AbstractCacheDecisionStrategy
implements
CacheDecisionStrategy
{
private
Map
<
CacheDecisionStrategyParameters
,
String
>
_params
;
@TransferState
(
value
=
{
"Params"
})
public
OptimalCacheDecisionStrategy
(
Map
<
CacheDecisionStrategyParameters
,
String
>
pParams
)
{
_params
=
pParams
;
}
@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
;
}
RoadNetworkEdge
edge
=
(
RoadNetworkEdge
)
pSimilarPointInformation
.
get
(
0
).
getAttribute
(
AvailableInformationAttributes
.
EDGE
);
double
actualSpeed
=
edge
.
getCurrentSpeed
();
JamProperty
jamProperty
=
edge
.
getJamProperty
();
long
maxTimestamp
;
if
(
jamProperty
!=
null
)
{
maxTimestamp
=
jamProperty
.
getDetectionDate
();
}
else
{
maxTimestamp
=
-
1
;
}
double
difference
=
Double
.
MAX_VALUE
;
T
maxFitting
=
null
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
Object
currentValue
=
t
.
getValue
();
if
(
currentValue
instanceof
VectoralProperty
)
{
currentValue
=
((
VectoralProperty
)
currentValue
).
getMostProbableValue
();
}
if
(
timestamp
>=
maxTimestamp
)
{
if
(
currentValue
.
equals
(
actualSpeed
))
{
maxFitting
=
t
;
difference
=
0
;
}
else
if
(
currentValue
instanceof
Number
&&
Math
.
abs
(((
Number
)
currentValue
).
doubleValue
()
-
actualSpeed
)
<
difference
)
{
maxFitting
=
t
;
difference
=
Math
.
abs
(((
Number
)
currentValue
).
doubleValue
()
-
actualSpeed
);
}
}
}
if
(
maxFitting
==
null
)
{
maxTimestamp
=
-
1
;
for
(
T
t
:
pSimilarPointInformation
)
{
long
timestamp
=
t
.
getDetectionDate
();
if
(
timestamp
>=
maxTimestamp
)
{
maxTimestamp
=
timestamp
;
maxFitting
=
t
;
}
}
}
return
maxFitting
;
}
public
Map
<
CacheDecisionStrategyParameters
,
String
>
getParams
()
{
return
_params
;
}
@Override
public
OptimalCacheDecisionStrategy
clone
()
{
return
new
OptimalCacheDecisionStrategy
(
_params
);
}
}
Prev
1
2
Next
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