Message Boards Message Boards

Unexpected result from TravelTime[ ]

Posted 1 day ago

Consider travel times between three cities in Romania :

TravelTime[Entity["City", {"AlbaIulia", "Alba", "Romania"}], 
 Entity["City", {"Harman", "Brasov", "Romania"}]]
TravelTime[Entity["City", {"AlbaIulia", "Alba", "Romania"}], 
 Entity["City", {"Prejmer", "Brasov", "Romania"}]]

Three hours between "AlbaIulia" and "Harman", which seems correct, and a bit more between "AlbaIulia" and "Prejmer". But, for further computation, I need to convert these durations in minutes.

In[200]:= Quantity[
 TravelTime[Entity["City", {"AlbaIulia", "Alba", "Romania"}], 
  Entity["City", {"Prejmer", "Brasov", "Romania"}]], "Minute"]
Quantity[
 TravelTime[Entity["City", {"AlbaIulia", "Alba", "Romania"}], 
  Entity["City", {"Harman", "Brasov", "Romania"}]], "Minute"]

Out[200]= Quantity[188, ("Minutes")^2]

Out[201]= Quantity[1/20, ("Hours")^2]

There are two problems. First, why square minutes? In addition, while the first "distance" is correct (188 minutes), the second one is a nonsense : 1/20 and the unit is square hour instead of minute!

Is there a bug? Best regards,

Claude

POSTED BY: Claude Mante

TravelTime already returns results as a (MixedUnited) Quantity, so wrapping the results in Quantity is going to end up doing quantity arithmetic (in this case, an implicit times operation):

In[32]:= Quantity[Quantity[3, "Feet"], "Meters"]

Out[32]= Quantity[1250/127, ("Feet")^2]

To convert the results to minutes, use UnitConvert (or QuantityMagnitude if you just want the numeric value)instead:

In[10]:= UnitConvert[
 Quantity[MixedMagnitude[{3, 8}], 
  MixedUnit[{"Hours", "Minutes"}]], "Minutes"]

Out[10]= Quantity[188, "Minutes"]

In[11]:= QuantityMagnitude[
 Quantity[MixedMagnitude[{3, 8}], 
  MixedUnit[{"Hours", "Minutes"}]], "Minutes"]

Out[11]= 188
POSTED BY: Nick Lariviere
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract