Hi Rafael,
For reference, copying my old message in this thread.
On 2 February 2016 at 16:26, Rafael Pereira <
correiod...@gmail.com> wrote:
> 1. How can I set a limit to the number of connections?
There is no such limit on OTP per se (not anymore anyway). Instead
there is a "transferPenalty" parameter (in seconds), which can be used
to make connections (=transfers) less preferable. See
RoutingRequest.java L~147.
Having said that, there is currently no method on the scripting API to
set this parameter, but this would be trivial to add:
OtpsRoutingRequest.java:
public void setTransferPenalty(int transferPenalty) {
req.transferPenalty = transferPenalty
}
> 2. How can I add to the csv output the travel cost based on transit fare ?
Currently it's not possible, there is no fare information on the SPT
itself. Fare computation is rather complex and a bit expensive
CPU-wise, so it is not computed on the fly during the search (and
anyway due to the nature of the fare computation itself it would not
be always possible). Having said that nothing is impossible, a
function to compute the fare for a given state could be possible to
implement.
See FareService.java (and various implementation), and
GraphPathToTripPlanConverter::generateItinerary() to see where it is
called. You can see there that in order to compute fare you need a
"GraphPath" which is a bit expensive to build if you want to do it for
each final state in a search, but doable for evaluating a limited set
of destination in scripting. You can build a GraphPath from a final
state in a SPT. Pseudo-quickly-hacked-not-tested-code:
public Fare Sample::evalFare(ShortestPathTree spt, Graph graph) {
FareService fareService = graph.fareService;
State s0 = spt.getState(v0);
State s1 = spt.getState(v1);
Fare f0 = null;
Fare f1 = null;
if (s0 != null)
f0 = computeFare(s0);
if (s1 != null)
f1 = computeFare(s1);
// Fare averaging function is left as an exercice to the reader :)
return averaging(f0, d0, f1, d1);
}
private Fare Sample::computeFare(State s, FareService fareService) {
GraphPath path = new GraphPath(s, true);
return fareService.getCost(path);
}
And adding the relevant fare information in OtpEvaluatedIndividual.
HTH,
--Laurent