Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
qzed committed Jun 20, 2017
2 parents 7842111 + e815954 commit 644667e
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import microtrafficsim.core.map.features.Street;
import microtrafficsim.core.simulation.configs.CrossingLogicConfig;
import microtrafficsim.core.simulation.configs.SimulationConfig;
import microtrafficsim.math.Vec2d;

import java.util.HashMap;

Expand Down Expand Up @@ -122,7 +123,7 @@ private HashMap<Long, StreetEntity> extractEdges(ExchangeFormat fmt, ExchangeFor
backward = new DirectedEdge(
entity.getId(),
gec.getLength(),
gec.getDestinationDirection(), gec.getOriginDirection(),
Vec2d.mul(gec.getDestinationDirection(), -1.0), Vec2d.mul(gec.getOriginDirection(), -1.0),
Orientation.BACKWARD,
destination, origin,
gec.getStreetType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import microtrafficsim.core.exfmt.ecs.components.StreetComponent;
import microtrafficsim.core.exfmt.ecs.entities.LineEntity;
import microtrafficsim.core.logic.streets.DirectedEdge;
import microtrafficsim.math.Vec2d;


public class DirectedEdgeInjector implements ExchangeFormat.Injector<DirectedEdge> {
Expand All @@ -22,18 +23,18 @@ public void inject(ExchangeFormat fmt, ExchangeFormat.Context ctx, Container dst

if (src.getEntity().getForwardEdge() == src) {
gec.setForwardLanes(src.getNumberOfLanes());
gec.setForwardMaxVelocity(src.getMaxVelocity());
gec.setForwardMaxVelocity(src.getRawMaxVelocity());
gec.setOrigin(src.getOrigin().getId());
gec.setOriginDirection(src.getOriginDirection());
gec.setDestination(src.getDestination().getId());
gec.setDestinationDirection(src.getDestinationDirection());
} else {
gec.setBackwardLanes(src.getNumberOfLanes());
gec.setBackwardMaxVelocity(src.getMaxVelocity());
gec.setBackwardMaxVelocity(src.getRawMaxVelocity());
gec.setOrigin(src.getDestination().getId());
gec.setOriginDirection(src.getDestinationDirection());
gec.setOriginDirection(Vec2d.mul(src.getDestinationDirection(), -1.0));
gec.setDestination(src.getOrigin().getId());
gec.setDestinationDirection(src.getOriginDirection());
gec.setDestinationDirection(Vec2d.mul(src.getOriginDirection(), -1.0));
}

// Inject the street-geometry if it has not already been injected. This might be necessary when the street
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ public int getMaxVelocity() {
return streetInfo.maxVelocity;
}

/**
* @return max allowed velocity in km/h
*/
public float getRawMaxVelocity() {
return streetInfo.raw.maxVelocity;
}

public byte getPriorityLevel() {
return streetInfo.priorityLevel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ public void didMove() {

if (!driver.getRoute().isEmpty()) {
int distance = lane.getAssociatedEdge().getLength() - cellPosition;
int maxVelocity = Math.min(getMaxVelocity(), lane.getAssociatedEdge().getMaxVelocity());
if (maxVelocity >= distance && vehicleInFront == null)
if (getMaxVelocity() >= distance && vehicleInFront == null)
lane.getAssociatedEdge().getDestination().registerVehicle(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Dominic Parga Cacheiro, Maximilian Luz
*/
public class DarkMonochromeStyleSheet extends BasicStyleSheet {
private final EasyMarkableLogger logger = new EasyMarkableLogger(DarkMonochromeStyleSheet.class);
private final static EasyMarkableLogger logger = new EasyMarkableLogger(DarkMonochromeStyleSheet.class);

private final static LineWidthBaseFunction LINE_WIDTH_BASE_FUNCTION = (offset, base, exp1, exp2, zoom) -> {
if (zoom >= 12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Dominic Parga Cacheiro, Maximilian Luz
*/
public class DarkStyleSheet extends BasicStyleSheet {
private final EasyMarkableLogger logger = new EasyMarkableLogger(DarkStyleSheet.class);
private final static EasyMarkableLogger logger = new EasyMarkableLogger(DarkStyleSheet.class);


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Dominic Parga Cacheiro, Maximilian Luz
*/
public class LightMonochromeStyleSheet extends BasicStyleSheet {
private final EasyMarkableLogger logger = new EasyMarkableLogger(LightMonochromeStyleSheet.class);
private final static EasyMarkableLogger logger = new EasyMarkableLogger(LightMonochromeStyleSheet.class);

private final static LineWidthBaseFunction LINE_WIDTH_BASE_FUNCTION = (offset, base, exp1, exp2, zoom) -> {
if (zoom >= 12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Dominic Parga Cacheiro, Maximilian Luz
*/
public class LightStyleSheet extends BasicStyleSheet {
private final EasyMarkableLogger logger = new EasyMarkableLogger(LightStyleSheet.class);
private final static EasyMarkableLogger logger = new EasyMarkableLogger(LightStyleSheet.class);


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


/**
Expand All @@ -32,6 +34,7 @@ public class VehicleSimulation implements Simulation {
private boolean paused;
private Timer timer;
private TimerTask timerTask;
private Lock executionLock;
private int age;
private List<StepListener> stepListeners;

Expand All @@ -44,6 +47,7 @@ public class VehicleSimulation implements Simulation {
public VehicleSimulation() {
paused = true;
timer = new Timer();
executionLock = new ReentrantLock();
this.stepListeners = new LinkedList<>();
}

Expand Down Expand Up @@ -174,38 +178,39 @@ public final void runOneStep() {

@Override
public final void doRunOneStep() {
executionLock.lock();
willRunOneStep();

if (scenario.isPrepared()) {
if (logger.isDebugEnabled()) {
if (logger.isTraceEnabled()) {
time = System.nanoTime();
vehicleStepExecutor.willMoveAll(scenario);
logger.trace(
StringUtils.buildTimeString("time brake() etc. = ", System.nanoTime() - time, "ns").toString()
);

time = System.nanoTime();
long stamp = System.nanoTime();
vehicleStepExecutor.moveAll(scenario);
logger.trace(
StringUtils.buildTimeString("time move() = ", System.nanoTime() - time, "ns").toString()
StringUtils.buildTimeString("time move() = ", System.nanoTime() - stamp, "ns").toString()
);

time = System.nanoTime();
stamp = System.nanoTime();
vehicleStepExecutor.didMoveAll(scenario);
logger.trace(
StringUtils.buildTimeString("time didMove() = ", System.nanoTime() - time, "ns").toString()
StringUtils.buildTimeString("time didMove() = ", System.nanoTime() - stamp, "ns").toString()
);

time = System.nanoTime();
stamp = System.nanoTime();
vehicleStepExecutor.spawnAll(scenario);
logger.trace(
StringUtils.buildTimeString("time spawn() = ", System.nanoTime() - time, "ns").toString()
StringUtils.buildTimeString("time spawn() = ", System.nanoTime() - stamp, "ns").toString()
);

time = System.nanoTime();
stamp = System.nanoTime();
vehicleStepExecutor.updateNodes(scenario);
logger.trace(
StringUtils.buildTimeString("time updateNodes() = ", System.nanoTime() - time, "ns").toString()
StringUtils.buildTimeString("time updateNodes() = ", System.nanoTime() - stamp, "ns").toString()
);
} else {
vehicleStepExecutor.willMoveAll(scenario);
Expand All @@ -218,6 +223,7 @@ public final void doRunOneStep() {
}

didRunOneStep();
executionLock.unlock();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,14 @@ public void display(RenderContext context, MapBuffer map) {
Vec2d dir = projection.project(ctarget).sub(pos).normalize();

// adjust position to lane
Lane lane = logic.getLane();
if (lane == null) continue;

DirectedEdge edge = lane.getAssociatedEdge();
StreetEntity street = edge.getEntity();
int lane = v.getIndexOfCurrentLane();
if (lane == -1) continue;

double laneOffset;
if (street.getForwardEdge() != null && street.getBackwardEdge() != null) {
laneOffset = edge.getLanes().size() - lane.getIndex() - 0.5;
if (v.isCurrentStreetBidirectional()) {
laneOffset = v.getNumberOfLanesOnCurrentEdge() - v.getIndexOfCurrentLane() - 0.5;
} else {
laneOffset = (edge.getLanes().size() - 1.0) / 2.0 - lane.getIndex();
laneOffset = (v.getNumberOfLanesOnCurrentEdge() - 1.0) / 2.0 - v.getIndexOfCurrentLane();
}
laneOffset *= laneOffsetSign * VEHICLE_LANE_OFFSET_SCALE * VEHICLE_SCALE_NORM;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,14 @@ public void display(RenderContext context, MapBuffer map) {
Vec2d dir = projection.project(ctarget).sub(pos).normalize();

// adjust position to lane
Lane lane = logic.getLane();
if (lane == null) continue;

DirectedEdge edge = lane.getAssociatedEdge();
StreetEntity street = edge.getEntity();
int lane = v.getIndexOfCurrentLane();
if (lane == -1) continue;

double laneOffset;
if (street.getForwardEdge() != null && street.getBackwardEdge() != null) {
laneOffset = edge.getLanes().size() - lane.getIndex() - 0.5;
if (v.isCurrentStreetBidirectional()) {
laneOffset = v.getNumberOfLanesOnCurrentEdge() - v.getIndexOfCurrentLane() - 0.5;
} else {
laneOffset = (edge.getLanes().size() - 1.0) / 2.0 - lane.getIndex();
laneOffset = (v.getNumberOfLanesOnCurrentEdge() - 1.0) / 2.0 - v.getIndexOfCurrentLane();
}
laneOffset *= laneOffsetSign * VEHICLE_LANE_OFFSET_SCALE * VEHICLE_SCALE_NORM;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ public class Vehicle implements VisualizationVehicleEntity {
private static final float MIN_TARGET_DISTANCE = 1.0f;

private VehicleEntity entity;

private Color color;

private Coordinate position;
private double layer;
private Coordinate target;
private Color color;
private double layer;

private boolean isStreetBidirectional;
private int nLanesOnEdge;
private int idxLane = -1;



/**
Expand Down Expand Up @@ -124,6 +131,10 @@ public void updatePosition() {
pSegment /= dSegment;
position.lat = a.lat + (b.lat - a.lat) * pSegment;
position.lon = a.lon + (b.lon - a.lon) * pSegment;

isStreetBidirectional = edge.getEntity().getForwardEdge() != null && edge.getEntity().getBackwardEdge() != null;
nLanesOnEdge = edge.getNumberOfLanes();
idxLane = entity.getLogic().getLane().getIndex();
}


Expand Down Expand Up @@ -153,4 +164,16 @@ public double getLayer() {
public Coordinate getTarget() {
return target;
}

public int getNumberOfLanesOnCurrentEdge() {
return nLanesOnEdge;
}

public int getIndexOfCurrentLane() {
return idxLane;
}

public boolean isCurrentStreetBidirectional() {
return isStreetBidirectional;
}
}

0 comments on commit 644667e

Please sign in to comment.