final ArrayList<Candidate> choiceSet = new ArrayList<Candidate>(); for ( Subtour subtour : subtours ) { if ( !subtour.isClosed() ) { continue; subtour.getTrips().get( 0 ).getOriginActivity().getFacilityId() !=null ? subtour.getTrips().get( 0 ).getOriginActivity().getFacilityId() : subtour.getTrips().get( 0 ).getOriginActivity().getLinkId(); subtour.getTrips().size() == 1 ? singleTripSubtourModes : chainBasedModes; trips.subList( 0, trips.indexOf( subtour.getTrips().get( 0 ) )), mode); if (lastDestination != null) {
private List<Subtour> getRootSubtoursWithMode(final Plan plan) { final Collection<Subtour> allSubtours = TripStructureUtils.getSubtours( plan , tripRouter.getStageActivityTypes() ); final List<Subtour> roots = new ArrayList<Subtour>(); for ( Subtour s : allSubtours ) { if ( s.getParent() != null ) continue; if ( !containsMode( s ) ) continue; roots.add( s ); } return roots; }
); for ( final Subtour s : subtours ) { if ( s.getParent() != null ) continue; // is not a root tour boolean isFirstTrip = true; for ( final Trip t : s.getTrips() ) { for ( final SubtourRecord record : vehicularTours ) { final Subtour s = record.subtour; assert s.getParent() == null; final Id anchor = s.getTrips().get( 0 ).getOriginActivity().getFacilityId()!=null ? s.getTrips().get( 0 ).getOriginActivity().getFacilityId() : s.getTrips().get( 0 ).getOriginActivity().getLinkId();
if ( !mutated.contains( s.getParent() ) ) { nMutatedWithoutMutatedFather++; for ( Trip t : s.getTrips() ) { Assert.assertEquals( "unexpected mutated trip length", if (subtour.getChildren().isEmpty()) { checkSubtour(subtour); } else {
boolean containsMutatedMode = false; for (Trip trip : mutated.getTripsWithoutSubSubtours()) { if ( expectedMode.equals( trip.getLegsOnly().get( 0 ).getMode() ) ) { assertTrue( if ( !mutateds.contains( s.getParent() ) ) { nMutatedWithoutMutatedFather++;
plan, Arrays.asList( new Subtour( Arrays.asList( new Trip( act1 , trip1 , act2 ),
boolean atLeastOneSubtourWithDifferentChainBasedModes = false; if (subtour.getChildren().isEmpty()) { String modePreviousTripSameSubtour = null; for (Trip trip: subtour.getTrips()) {
Activity home2 = createActivityFromLocationId(anchorAtFacilities, fact, "home", createId(2,anchorAtFacilities)); plan.addActivity(home2); Subtour subtour1 = new Subtour( Arrays.asList( new Trip(somewhereElse, Collections.<PlanElement>singletonList(leg1), home1), new Trip(work, Collections.<PlanElement>singletonList(leg3), home2)), false); Subtour subtour2 = new Subtour(Arrays.asList( new Trip(home1, Collections.<PlanElement>singletonList(leg2), work), new Trip(work, Collections.<PlanElement>singletonList(leg3), home2)), true);
plan.addActivity(somewhereElse); Subtour subtour1 = new Subtour( Arrays.asList( new Trip(home1, Collections.<PlanElement>singletonList(leg2), work), new Trip(home2, Collections.<PlanElement>singletonList(leg1), somewhereElse)), false); Subtour subtour2 = new Subtour(Arrays.asList( new Trip(home1, Collections.<PlanElement>singletonList(leg2), work), new Trip(work, Collections.<PlanElement>singletonList(leg3), home2)), true);
@Override public void run(final Plan plan) { final List<Id> vehs = new ArrayList<Id>( vehicleRessources.identifyVehiclesUsableForAgent( plan.getPerson().getId() ) ); // make sure order is deterministic Collections.sort( vehs ); final List<Subtour> rootSubtours = getRootSubtoursWithMode( plan ); if ( rootSubtours.isEmpty() ) return; final Subtour toHandle = rootSubtours.get( random.nextInt( rootSubtours.size() ) ); final Id veh = vehs.get( random.nextInt( vehs.size() ) ); for ( Trip t : toHandle.getTrips() ) { if ( !identifyMainMode( t ).equals( mode ) ) continue; for ( Leg l : t.getLegsOnly() ) { if ( !(l.getRoute() instanceof NetworkRoute) ) continue; final NetworkRoute route = (NetworkRoute) l.getRoute(); route.setVehicleId( veh ); } } }
/*for tests*/ double calcOverlap(final GroupPlans gps) { final List<SubtourRecord> tours = getVehicularToursSortedByStartTime( gps ); double overlap = 0; for ( final SubtourRecord tour : tours ) { Id veh = null; for ( final Trip t : tour.subtour.getTrips() ) { veh = getVehicle( t ); if ( veh != null ) break; } for ( final VehicleRecord vr : tour.possibleVehicles ) { if ( vr.id.equals( veh ) ) { overlap += Math.max( 0 , vr.availableFrom - tour.startTime ); if ( vr.availableFrom < tour.endTime ) { vr.availableFrom = tour.endTime; } break; } } } return overlap; }
@Test public void testFatherhood() throws Exception { for (Fixture f : allFixtures( useFacilitiesAsAnchorPoint )) { final Collection<Subtour> subtours = TripStructureUtils.getSubtours( f.plan , CHECKER); for (Subtour s : subtours) { for ( Subtour child : s.getChildren() ) { assertEquals( "[anchorAtFacilities="+f.useFacilitiesAsAnchorPoint+"] "+ "wrong father!", child.getParent(), s); } if ( s.getParent() != null ) { assertTrue( "[anchorAtFacilities="+f.useFacilitiesAsAnchorPoint+"] "+ "father does not have subtour has a child", s.getParent().getChildren().contains( s )); } } } }