Skip to content

Commit

Permalink
Merge pull request #29 from sisl/findfirst
Browse files Browse the repository at this point in the history
more findfirst fixes
  • Loading branch information
MaximeBouton committed Mar 13, 2019
2 parents a3d587e + e97b90f commit 91f96ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/1d/vehicles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function get_headway(veh_rear::Vehicle1D, veh_fore::Vehicle1D, roadway::Straight
end
function get_neighbor_fore(scene::Scene1D, vehicle_index::Int, roadway::StraightRoadway)
ego = scene[vehicle_index]
best_ind = 0
best_ind = nothing
best_gap = Inf
for (i,veh) in enumerate(scene)
if i != vehicle_index
Expand All @@ -27,7 +27,7 @@ function get_neighbor_fore(scene::Scene1D, vehicle_index::Int, roadway::Straight
end
function get_neighbor_rear(scene::Scene1D, vehicle_index::Int, roadway::StraightRoadway)
ego = scene[vehicle_index]
best_ind = 0
best_ind = nothing
best_gap = Inf
for (i,veh) in enumerate(scene)
if i != vehicle_index
Expand All @@ -38,4 +38,4 @@ function get_neighbor_rear(scene::Scene1D, vehicle_index::Int, roadway::Straight
end
end
return NeighborLongitudinalResult(best_ind, best_gap)
end
end
6 changes: 3 additions & 3 deletions src/2d/behaviors/lane_change_models/MOBIL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function observe!(model::MOBIL, scene::Scene, roadway::Roadway, egoid::Int)

Δaccel_n = 0.0
passes_safety_criterion = true
if rear_L.ind != 0
if rear_L.ind != nothing
id = scene[rear_L.ind].id
accel_n_orig = rand(observe!(reset_hidden_state!(model.mlon), scene, roadway, id)).a
veh_ego = Entity(veh_ego, egostate_L)
Expand All @@ -139,7 +139,7 @@ function observe!(model::MOBIL, scene::Scene, roadway::Roadway, egoid::Int)


Δaccel_o = 0.0
if rear_M.ind != 0
if rear_M.ind != nothing
id = scene[rear_M.ind].id
accel_o_orig = rand(observe!(reset_hidden_state!(model.mlon), scene, roadway, id)).a
veh_ego = Entity(veh_ego, egostate_L)
Expand All @@ -163,4 +163,4 @@ function observe!(model::MOBIL, scene::Scene, roadway::Roadway, egoid::Int)

model
end
Base.rand(model::MOBIL) = LaneChangeChoice(model.dir)
Base.rand(model::MOBIL) = LaneChangeChoice(model.dir)
4 changes: 2 additions & 2 deletions src/2d/vehicles/scenes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function get_neighbor_rear_along_lane(
index_to_ignore::Int=-1,
) where {S<:VehicleState,D<:Union{VehicleDef, BicycleModel},I}

best_ind = 0
best_ind = nothing
best_dist = max_distance_rear
tag_target = tag_start

Expand Down Expand Up @@ -277,7 +277,7 @@ function get_neighbor_rear_along_lane(
end
end

if best_ind != 0
if best_ind != nothing
break
end

Expand Down

0 comments on commit 91f96ac

Please sign in to comment.