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
b7c5c6a6
Commit
b7c5c6a6
authored
Jun 07, 2018
by
Jose Ignacio Monreal Bailey
Browse files
Created TrafficLightModel
parent
2859bb00
Changes
2
Show whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/movement/vehicular/sumo/simulation/controller/traci/TraciSimulationController.java
View file @
b7c5c6a6
...
...
@@ -71,7 +71,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
private
double
_endY
;
private
Map
<
String
,
VehicleInformationContainer
>
_positons
=
new
HashMap
<>();
private
Map
<
String
,
Location
>
trafficLightsPosition
=
new
HashMap
<>();
private
boolean
_initalized
=
false
;
...
...
@@ -984,11 +983,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
return
result
;
}
@Override
public
Location
getTrafficLightPosition
(
String
pTrafficLightID
)
{
return
trafficLightsPosition
.
get
(
pTrafficLightID
);
}
public
List
<
RoadNetworkLink
>
getControlledLinks
(
String
pTrafficLightID
)
{
SumoCommand
trafficLightCommand
=
Trafficlight
.
getControlledLinks
(
pTrafficLightID
);
Object
controlledLinksObject
=
requestObject
(
trafficLightCommand
);
...
...
src/de/tud/kom/p2psim/impl/topology/placement/TrafficLightPlacementModel.java
View file @
b7c5c6a6
package
de.tud.kom.p2psim.impl.topology.placement
;
import
de.tud.kom.p2psim.api.topology.
movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.
mov
ement.
SimLocationActuator
;
import
de.tud.kom.p2psim.api.topology.
TopologyComponent
;
import
de.tud.kom.p2psim.api.topology.
plac
ement.
PlacementModel
;
import
de.tud.kom.p2psim.impl.topology.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
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.TrafficLightController
;
import
de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.trafficlights.TrafficLight
;
import
de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
public
class
TrafficLightPlacementModel
implements
MovementModel
,
EventHandler
{
private
static
TrafficLightPlacementModel
PLACEMENT
;
private
final
List
<
SimLocationActuator
>
components
;
private
final
Map
<
String
,
SimLocationActuator
>
idComponentMatcher
;
public
class
TrafficLightPlacementModel
implements
PlacementModel
,
EventHandler
{
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
double
scenarioWidth
=
0
;
private
double
scenarioHeight
=
0
;
private
static
final
Location
DEFAULT_LOCATION
=
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
);
private
boolean
initialized
=
false
;
private
SimulationSetupExtractor
controller
;
private
TrafficLightController
controller
;
private
SimulationSetupExtractor
extractor
;
private
List
<
Location
>
intersections
;
private
int
currentIndex
=
0
;
@XMLConfigurableConstructor
({
"sumoExe"
,
"sumoConfigFile"
,
"offsetX"
,
"offsetY"
,
"width"
,
"height"
})
public
TrafficLightPlacementModel
(
String
sumoExe
,
String
sumoConfigFile
,
String
offsetX
,
String
offsetY
,
String
width
,
String
height
)
{
PLACEMENT
=
this
;
this
.
components
=
new
LinkedList
<>();
this
.
idComponentMatcher
=
new
HashMap
<>();
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
);
}
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
long
currentTime
=
Time
.
getCurrentTime
()
/
timestepConversion
;
while
(
controller
.
getStep
()
-
controller
.
getStart
()
<
currentTime
)
{
if
(!
controller
.
nextStep
())
{
return
;
}
}
List
<
TrafficLight
>
allTrafficLights
=
controller
.
getAllTrafficLights
();
for
(
int
i
=
0
;
i
<
allTrafficLights
.
size
()
;
++
i
)
{
TrafficLight
trafficlight
=
allTrafficLights
.
get
(
i
);
}
/*
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.getLongitude(), position.getLatitude()));
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);
}
initializeModel
();
}
// Reschedule next step
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
*/
protected
void
initializeModel
()
{
if
(
this
.
sumoExe
!=
null
)
{
controller
=
TraciSimulationController
.
createSimulationController
(
sumoExe
,
sumoConfigFile
);
controller
.
init
();
controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
intersections
=
controller
.
getAllIntersections
(
true
);
}
@Override
public
void
addComponent
(
SimLocationActuator
actuator
)
{
actuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
components
.
add
(
actuator
);
}
@Override
public
void
placeComponent
(
SimLocationActuator
actuator
)
{
actuator
.
updateCurrentLocation
(
DEFAULT_LOCATION
);
if
(!
initialized
)
{
initializeModel
();
}
}
public
void
addComponent
(
TopologyComponent
comp
)
{
protected
void
initializeModel
()
{
if
(!
initialized
)
{
if
(
sumoExe
!=
null
)
{
TraciSimulationController
traciSimulationController
=
TraciSimulationController
.
createSimulationController
(
sumoExe
,
sumoConfigFile
);
controller
=
traciSimulationController
;
controller
.
setObservedArea
(
offsetX
,
offsetY
,
offsetX
+
width
,
offsetY
+
height
);
controller
.
init
();
controller
.
nextStep
();
extractor
=
traciSimulationController
;
}
scenarioWidth
=
extractor
.
getScenarioWidth
();
scenarioHeight
=
extractor
.
getScenarioHeight
();
System
.
out
.
println
(
"Initialization: done."
);
@Override
public
PositionVector
place
(
TopologyComponent
comp
)
{
if
(
currentIndex
<
intersections
.
size
())
{
Location
intersection
=
intersections
.
get
(
currentIndex
);
currentIndex
++;
return
new
PositionVector
(
intersection
.
getLongitude
(),
intersection
.
getLatitude
());
}
else
{
return
new
PositionVector
(
Double
.
NaN
,
Double
.
NaN
);
}
}
@Override
public
void
setTimeBetweenMoveOperations
(
long
tim
e
)
{
public
void
eventOccurred
(
Object
content
,
int
typ
e
)
{
}
}
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