Commit e0b6b9a6 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added serialization for RoadNetwork to enable faster startups

parent 03c7c6bf
...@@ -27,6 +27,20 @@ import java.util.Map; ...@@ -27,6 +27,20 @@ import java.util.Map;
public class RoadNetwork { public class RoadNetwork {
private Map<String, RoadNetworkEdge> _roadNetwork; private Map<String, RoadNetworkEdge> _roadNetwork;
public RoadNetwork(SerializableRoadNetwork pRoadNetwork) {
for (SerializableRoadNetworkEdge edge : pRoadNetwork.getAvailableEdges()) {
_roadNetwork.put(edge.getEdgeID(), new RoadNetworkEdge(edge));
}
for (SerializableRoadNetworkEdge edge : pRoadNetwork.getAvailableEdges()) {
RoadNetworkEdge roadNetworkEdge = _roadNetwork.get(edge.getEdgeID());
for (String edgeID : edge.getAccessibleEdges()) {
roadNetworkEdge.addConnectedEdge(_roadNetwork.get(edgeID));
}
}
}
public RoadNetwork(Map<String, RoadNetworkEdge> pRoadNetwork) { public RoadNetwork(Map<String, RoadNetworkEdge> pRoadNetwork) {
_roadNetwork = pRoadNetwork; _roadNetwork = pRoadNetwork;
} }
...@@ -35,7 +49,7 @@ public class RoadNetwork { ...@@ -35,7 +49,7 @@ public class RoadNetwork {
return new ArrayList<>(_roadNetwork.values()); return new ArrayList<>(_roadNetwork.values());
} }
public RoadNetworkEdge getEdge(String pRouteID) { public RoadNetworkEdge getEdge(String pEdge) {
return _roadNetwork.get(pRouteID); return _roadNetwork.get(pEdge);
} }
} }
...@@ -33,6 +33,13 @@ public class RoadNetworkEdge { ...@@ -33,6 +33,13 @@ public class RoadNetworkEdge {
private List<RoadNetworkEdge> _accessibleEdges = new ArrayList<>(); private List<RoadNetworkEdge> _accessibleEdges = new ArrayList<>();
public RoadNetworkEdge(SerializableRoadNetworkEdge pEdge) {
_edgeID = pEdge.getEdgeID();
_angle = pEdge.getAngle();
_laneAmount = pEdge.getLaneAmount();
_maxSpeed = pEdge.getMaxSpeed();
}
public RoadNetworkEdge(String pEdgeID, double pAngle) { public RoadNetworkEdge(String pEdgeID, double pAngle) {
_edgeID = pEdgeID; _edgeID = pEdgeID;
_angle = pAngle; _angle = pAngle;
......
/*
* 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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class SerializableRoadNetwork implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8523360385937842443L;
private Map<String, SerializableRoadNetworkEdge> _roadNetwork;
public SerializableRoadNetwork(RoadNetwork pRoadNetwork) {
for (RoadNetworkEdge edge : pRoadNetwork.getAvailableEdges()) {
_roadNetwork.put(edge.getEdgeID(), new SerializableRoadNetworkEdge(edge));
}
}
public List<SerializableRoadNetworkEdge> getAvailableEdges() {
return new ArrayList<>(_roadNetwork.values());
}
}
/*
* 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.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SerializableRoadNetworkEdge implements Serializable {
/**
*
*/
private static final long serialVersionUID = -311466941428215723L;
private String _edgeID;
private double _angle;
private int _laneAmount;
private double _maxSpeed = 0;
private List<String> _accessibleEdgeIDs = new ArrayList<>();
public SerializableRoadNetworkEdge(RoadNetworkEdge pEdge) {
_edgeID = pEdge.getEdgeID();
_angle = pEdge.getAngle();
_laneAmount = pEdge.getLaneAmount();
_maxSpeed = pEdge.getMaxSpeed();
for (RoadNetworkEdge edge : pEdge.getAccessibleEdges()) {
_accessibleEdgeIDs.add(edge.getEdgeID());
}
}
public String getEdgeID() {
return _edgeID;
}
public double getAngle() {
return _angle;
}
public double getMaxSpeed() {
return _maxSpeed;
}
public int getLaneAmount() {
return _laneAmount;
}
public void increaseLaneAmount() {
_laneAmount++;
}
public void setMaxSpeed(double pMaxSpeed) {
if (pMaxSpeed > _maxSpeed) {
_maxSpeed = pMaxSpeed;
}
}
public List<String> getAccessibleEdges() {
return Collections.unmodifiableList(_accessibleEdgeIDs);
}
public String getDescription() {
return "id: " + _edgeID + ", lanes: " + _laneAmount + ", speed limit: " + _maxSpeed;
}
@Override
public String toString() {
return _edgeID;
}
public boolean isInternal() {
return _edgeID.startsWith(":");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment