001/* *********************************************************************** *
002 * project: org.matsim.*
003 * VehicleBasedIncompatiblePlansIdentifierFactory.java
004 *                                                                         *
005 * *********************************************************************** *
006 *                                                                         *
007 * copyright       : (C) 2013 by the members listed in the COPYING,        *
008 *                   LICENSE and WARRANTY file.                            *
009 * email           : info at matsim dot org                                *
010 *                                                                         *
011 * *********************************************************************** *
012 *                                                                         *
013 *   This program is free software; you can redistribute it and/or modify  *
014 *   it under the terms of the GNU General Public License as published by  *
015 *   the Free Software Foundation; either version 2 of the License, or     *
016 *   (at your option) any later version.                                   *
017 *   See also COPYING, LICENSE and WARRANTY file                           *
018 *                                                                         *
019 * *********************************************************************** */
020package org.matsim.contrib.socnetsim.sharedvehicles;
021
022import java.util.Collection;
023import java.util.Set;
024
025import org.matsim.api.core.v01.Id;
026import org.matsim.api.core.v01.population.Person;
027import org.matsim.api.core.v01.population.Plan;
028
029import org.matsim.contrib.socnetsim.framework.population.JointPlans;
030import org.matsim.contrib.socnetsim.framework.replanning.grouping.ReplanningGroup;
031import org.matsim.contrib.socnetsim.framework.replanning.selectors.IncompatiblePlansIdentifier;
032import org.matsim.contrib.socnetsim.framework.replanning.selectors.IncompatiblePlansIdentifierFactory;
033import org.matsim.contrib.socnetsim.framework.replanning.selectors.IncompatiblePlansIdentifierImpl;
034
035/**
036 * @author thibautd
037 */
038public class VehicleBasedIncompatiblePlansIdentifierFactory implements IncompatiblePlansIdentifierFactory {
039        private final Collection<String> modes;
040
041        public VehicleBasedIncompatiblePlansIdentifierFactory(final Collection<String> modes) {
042                this.modes = modes;
043        }
044
045        @Override
046        public IncompatiblePlansIdentifier createIdentifier(
047                        final JointPlans jointPlans,
048                        final ReplanningGroup group) {
049                final IncompatiblePlansIdentifierImpl identifier = new IncompatiblePlansIdentifierImpl();
050
051                for ( Person person : group.getPersons() ) {
052                        for ( Plan plan : person.getPlans() ) {
053                                final Set<Id> vehicles = SharedVehicleUtils.getVehiclesInPlan( plan , modes );
054                                identifier.put( plan , vehicles );
055                        }
056                }
057                
058                return identifier;
059        }
060}
061