How to Get Exact Job Sequence

I am trying to get the jobs sequence using this

  VehicleRoute vehicleRoute;
   vehicleRoute.getTourActivities().getJobs()

but it is not giving me exact sequence. Let suppose correct sequence of jobs on a particular route is stop4-> stop3->stop5 but above code gave me stop3-> stop4->stop5. I need the exact sequence. how can I get it?

you can use as List:

List lista= route.getTourActivities().getActivities();

or

for (VehicleRoute route : solution.getRoutes()) {
for (TourActivity act : route.getActivities()) {
act.getLocation().getId();

}
}

1 Like

I already tried but location Id is not same as a job ID.

if you want to retrieve job id from a tour activity, you need:

String jobId = ((TourActivity.JobActivity) activity).getJob().getId();
1 Like

How would we iterate over a TourActivity.JobActivity. I am trying below code but it is not working.

                  Iterator<TourActivity.JobActivity> ta=vehicleRoute.getActivities().iterator();
                  while(ta.hasNext()){

                  	String jobId = ((TourActivity.JobActivity) ta).getJob().getId();

				  }

try using the following instead?

Iterator<TourActivity> ta

I tried this:

Iterator<TourActivity> ta=vehicleRoute.getActivities().iterator();
              while(ta.hasNext())
              String jobId = ((TourActivity.JobActivity) ta).getJob().getId();

But it gave this exception :
java.util.Collections$UnmodifiableCollection$1 cannot be cast to com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity$JobActivity

String jobId = ((TourActivity.JobActivity) ta.next()).getJob().getId();