Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortest-ish #2555

Merged
merged 46 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b7064fc
add plumbing for shortest distance(ish) routes for just auto costing
kevinkreiser Aug 24, 2020
a2a1435
changelog stub
kevinkreiser Aug 24, 2020
bcabf61
Update CHANGELOG.md
kevinkreiser Aug 24, 2020
eabdb9e
typos
kevinkreiser Aug 24, 2020
c3d4847
Merge remote-tracking branch 'origin/shortestish' into shortestish
kevinkreiser Aug 24, 2020
b998edf
Merge branch 'master' into shortestish
nilsnolde Sep 11, 2020
ba4b2e1
add gurka test for shortest auto
nilsnolde Sep 11, 2020
5dc06c8
add truck shortest
nilsnolde Sep 13, 2020
4ce4b11
resolve conflicts with master
nilsnolde Sep 21, 2020
5a20b24
Merge branch 'master' into shortestish
nilsnolde Sep 21, 2020
211cdc1
add shortest to other profiles, update test; motor_scooter & bike sti…
nilsnolde Sep 21, 2020
8e37b95
add to docs
nilsnolde Sep 21, 2020
6547eca
add stashed changes
nilsnolde Sep 21, 2020
48c1874
format
nilsnolde Sep 21, 2020
25feb2d
Merge branch 'master' into shortestish
kevinkreiser Sep 24, 2020
9f2d677
resolve proto.options
nilsnolde Oct 5, 2020
e33083e
comment scooter/bike/ped test until better solution has been found
nilsnolde Oct 5, 2020
12fe6e6
Merge branch 'master' into shortestish [ci skip]
nilsnolde Oct 15, 2020
2cdeec3
fix tests for ped, bike, scooter
nilsnolde Oct 16, 2020
467b74d
fix tests for ped, bike, scooter
nilsnolde Oct 16, 2020
bb597d3
some more docu info
nilsnolde Oct 16, 2020
fa23b48
strike-through auto_shorter
nilsnolde Oct 16, 2020
ee00a92
resolve error in debug-lint build
nilsnolde Oct 16, 2020
b987eed
Merge branch 'shortestish' of github.com:valhalla/valhalla into short…
nilsnolde Oct 16, 2020
f517ee4
Merge branch 'master' into shortestish
nilsnolde Oct 16, 2020
609b52b
choose a saner tag combo so it doesn't break in the future
nilsnolde Oct 17, 2020
59affa1
sidewalk_factor was missing in docs
nilsnolde Oct 17, 2020
314f5e7
wrong assert for ferry speed
nilsnolde Oct 17, 2020
895a11e
Merge branch 'master' into shortestish
nilsnolde Oct 20, 2020
b86d0b0
missed shortest_ in other overload
nilsnolde Oct 20, 2020
5fbdc78
resolve conflict with master
nilsnolde Oct 20, 2020
e99b3a4
some major flaws in ped/bike edgecost computation; some places (trans…
nilsnolde Oct 20, 2020
c6712ca
profiles -> costing models
nilsnolde Oct 20, 2020
29ea4d3
revert change to get road speed in pedestrian edgecost
nilsnolde Oct 20, 2020
f351177
introduce code to change auto_shorter to auto with shortest: true; ad…
nilsnolde Oct 20, 2020
99c4b68
remove auto_shorter from other locations
nilsnolde Oct 20, 2020
3c76b00
revert removing auto_shorter from codebase
nilsnolde Oct 21, 2020
c6cd36f
mdk auto_shorter and fix merge conflict bug
kevinkreiser Oct 23, 2020
cb7eb25
patch up bicycle cost for shortest and fix base_cost to retain the ti…
kevinkreiser Oct 24, 2020
ad712eb
further gut costing stuff that is no longer needed, update tests
kevinkreiser Oct 24, 2020
f126b0c
move deprecation tests into other tests and only test parsing
kevinkreiser Oct 24, 2020
a6a95b4
remove redundant test from cmakelists
nilsnolde Oct 24, 2020
0adf518
consistent use of rapidjson shortcut methods
nilsnolde Oct 24, 2020
d378b9b
profile is an osrm term
kevinkreiser Oct 25, 2020
8a07b1b
Merge remote-tracking branch 'origin/shortestish' into shortestish
kevinkreiser Oct 25, 2020
15880ba
simplify test
kevinkreiser Oct 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add plumbing for shortest distance(ish) routes for just auto costing
  • Loading branch information
kevinkreiser committed Aug 24, 2020
commit b7064fc2b73e2d141db5f8bdb3fc572f1b0fc2ac
1 change: 1 addition & 0 deletions proto/options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ message CostingOptions {
optional float bike_share_penalty = 57;
optional float rail_ferry_cost = 58;
optional float use_rail_ferry = 59;
optional bool shortest = 60;

// these are not specified directly by the user but they get filled in as the request is parsed and fulfilled
optional Costing costing = 90;
Expand Down
38 changes: 30 additions & 8 deletions src/sif/autocost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,21 @@ Cost AutoCost::EdgeCost(const baldr::DirectedEdge* edge,
const baldr::GraphTile* tile,
const uint32_t seconds) const {
auto speed = tile->GetSpeed(edge, flow_mask_, seconds);
assert(speed < speedfactor_.size());
float sec = (edge->length() * speedfactor_[speed]);

if (shortest_) {
return Cost(edge->length(), sec);
}

float factor =
(edge->use() == Use::kFerry)
? ferry_factor_
: (edge->use() == Use::kRailFerry) ? rail_ferry_factor_ : density_factor_[edge->density()];

factor += highway_factor_ * kHighwayFactor[static_cast<uint32_t>(edge->classification())] +
surface_factor_ * kSurfaceFactor[static_cast<uint32_t>(edge->surface())];

if (edge->toll()) {
factor += toll_factor_;
}
Expand All @@ -461,8 +469,6 @@ Cost AutoCost::EdgeCost(const baldr::DirectedEdge* edge,
factor *= alley_factor_;
}

assert(speed < speedfactor_.size());
float sec = (edge->length() * speedfactor_[speed]);
return Cost(sec * factor, sec);
}

Expand Down Expand Up @@ -502,7 +508,7 @@ Cost AutoCost::TransitionCost(const baldr::DirectedEdge* edge,
if (!edge->has_flow_speed() || flow_mask_ == 0)
seconds *= trans_density_factor_[node->density()];

c.cost += seconds;
c.cost += shortest_ ? 0.f : seconds;
c.secs += seconds;
}
return c;
Expand Down Expand Up @@ -546,8 +552,8 @@ Cost AutoCost::TransitionCostReverse(const uint32_t idx,
if (!edge->has_flow_speed() || flow_mask_ == 0)
seconds *= trans_density_factor_[node->density()];

c.cost += shortest_ ? 0 : seconds;
c.secs += seconds;
c.cost += seconds;
}
return c;
}
Expand Down Expand Up @@ -675,6 +681,7 @@ cost_ptr_t CreateAutoCost(const CostingOptions& costing_options) {
}

/**
* //TODO: delete this in favor of just using the "shortest" costing option
* Derived class providing an alternate costing for driving that is intended
* to provide a short path.
*/
Expand Down Expand Up @@ -709,9 +716,14 @@ class AutoShorterCost : public AutoCost {
const baldr::GraphTile* tile,
const uint32_t seconds) const {
auto speed = tile->GetSpeed(edge, flow_mask_, seconds);
float sec = edge->length() * speedfactor_[speed];

if (shortest_) {
return Cost(edge->length(), sec);
}

float factor = (edge->use() == Use::kFerry) ? ferry_factor_ : 1.0f;
return Cost(edge->length() * adjspeedfactor_[speed] * factor,
edge->length() * speedfactor_[speed]);
return Cost(edge->length() * adjspeedfactor_[speed] * factor, sec);
}

/**
Expand Down Expand Up @@ -1012,11 +1024,16 @@ class HOVCost : public AutoCost {
const baldr::GraphTile* tile,
const uint32_t seconds) const {
auto speed = tile->GetSpeed(edge, flow_mask_, seconds);
float sec = edge->length() * speedfactor_[speed];

if (shortest_) {
return Cost(edge->length(), sec);
}

float factor = (edge->use() == Use::kFerry) ? ferry_factor_ : density_factor_[edge->density()];
if ((edge->forwardaccess() & kHOVAccess) && !(edge->forwardaccess() & kAutoAccess)) {
factor *= kHOVFactor;
}
float sec = (edge->length() * speedfactor_[speed]);
return Cost(sec * factor, sec);
}

Expand Down Expand Up @@ -1218,11 +1235,16 @@ class TaxiCost : public AutoCost {
const baldr::GraphTile* tile,
const uint32_t seconds) const {
auto speed = tile->GetSpeed(edge, flow_mask_, seconds);
float sec = edge->length() * speedfactor_[speed];

if (shortest_) {
return Cost(edge->length(), sec);
}

float factor = (edge->use() == Use::kFerry) ? ferry_factor_ : density_factor_[edge->density()];
if ((edge->forwardaccess() & kTaxiAccess) && !(edge->forwardaccess() & kAutoAccess)) {
factor *= kTaxiFactor;
}
float sec = (edge->length() * speedfactor_[speed]);
return Cost(sec * factor, sec);
}

Expand Down
4 changes: 3 additions & 1 deletion src/sif/dynamiccost.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace sif {

DynamicCost::DynamicCost(const CostingOptions& options, const TravelMode mode)
: pass_(0), allow_transit_connections_(false), allow_destination_only_(true), travel_mode_(mode),
flow_mask_(kDefaultFlowMask) {
flow_mask_(kDefaultFlowMask), shortest_(options.shotest()) {
// Parse property tree to get hierarchy limits
// TODO - get the number of levels
uint32_t n_levels = sizeof(kDefaultMaxUpTransitions) / sizeof(kDefaultMaxUpTransitions[0]);
Expand Down Expand Up @@ -218,6 +218,8 @@ void ParseSharedCostOptions(const rapidjson::Value& value, CostingOptions* pbf_c
if (name) {
pbf_costing_options->set_name(*name);
}
auto shortest = rapidjson::get<bool>(value, "/shortest", false);
pbf_costing_options.set_shortest(shortest);
}

void ParseCostingOptions(const rapidjson::Document& doc,
Expand Down
7 changes: 7 additions & 0 deletions valhalla/sif/dynamiccost.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@ class DynamicCost {
// A mask which determines which flow data the costing should use from the tile
uint8_t flow_mask_;

// Whether or not to do shortest (by length) routes
// Note: hierarchy pruning means some costings (auto, truck, etc) won't do absolute shortest
bool shortest_;

/**
* Get the base transition costs (and ferry factor) from the costing options.
* @param costing_options Protocol buffer of costing options.
Expand Down Expand Up @@ -785,6 +789,9 @@ class DynamicCost {
const uint32_t idx) const {
// Cases with both time and penalty: country crossing, ferry, rail_ferry, gate, toll booth
sif::Cost c;
if (shortest_) {
return c; // shortest ignores any penalties in favor of path length
}
if (node->type() == baldr::NodeType::kBorderControl) {
c += country_crossing_cost_;
}
Expand Down