-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ile_de_france/src/main/java/org/eqasim/ile_de_france/policies/PolicyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package org.eqasim.ile_de_france.policies; | ||
|
||
public interface PolicyFactory { | ||
Policy createPolicy(String name); | ||
Policy createPolicy(String name, PolicyPersonFilter personFilter); | ||
} |
36 changes: 36 additions & 0 deletions
36
ile_de_france/src/main/java/org/eqasim/ile_de_france/policies/PolicyPersonFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.eqasim.ile_de_france.policies; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.IdSet; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.api.core.v01.population.Population; | ||
|
||
public class PolicyPersonFilter { | ||
private final IdSet<Person> selection; | ||
|
||
PolicyPersonFilter(IdSet<Person> selection) { | ||
this.selection = selection; | ||
} | ||
|
||
public boolean applies(Id<Person> personId) { | ||
return selection == null ? true : selection.contains(personId); | ||
} | ||
|
||
static public PolicyPersonFilter create(Population population, PolicyConfigGroup policy) { | ||
if (policy.personFilter != null && policy.personFilter.length() > 0) { | ||
IdSet<Person> selection = new IdSet<>(Person.class); | ||
|
||
for (Person person : population.getPersons().values()) { | ||
Boolean indicator = (Boolean) person.getAttributes().getAttribute(policy.personFilter); | ||
|
||
if (indicator != null && indicator) { | ||
selection.add(person.getId()); | ||
} | ||
} | ||
|
||
return new PolicyPersonFilter(selection); | ||
} else { | ||
return new PolicyPersonFilter(null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
...e_france/src/main/java/org/eqasim/ile_de_france/policies/routing/FixedRoutingPenalty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
package org.eqasim.ile_de_france.policies.routing; | ||
|
||
import org.eqasim.ile_de_france.policies.PolicyPersonFilter; | ||
import org.matsim.api.core.v01.IdSet; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.population.Person; | ||
|
||
public class FixedRoutingPenalty implements RoutingPenalty { | ||
private final IdSet<Link> linkIds; | ||
private final double penalty; | ||
private final PolicyPersonFilter personFilter; | ||
|
||
public FixedRoutingPenalty(IdSet<Link> linkIds, double penalty) { | ||
public FixedRoutingPenalty(IdSet<Link> linkIds, double penalty, PolicyPersonFilter personFilter) { | ||
this.linkIds = linkIds; | ||
this.penalty = penalty; | ||
this.personFilter = personFilter; | ||
} | ||
|
||
@Override | ||
public double getLinkPenalty(Link link, Person person, double time) { | ||
return linkIds.contains(link.getId()) ? penalty : 0.0; | ||
return linkIds.contains(link.getId()) && personFilter.applies(person.getId()) ? penalty : 0.0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters