MATSIM
HouseholdsAlgorithmRunner.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * HouseholdsAlgorithmRunner
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2012 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 package org.matsim.households;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
29 
30 
37 
38  private static final Logger log = LogManager.getLogger(HouseholdsAlgorithmRunner.class);
39 
40  private final List<HouseholdAlgorithm> householdAlgorithms = new ArrayList<HouseholdAlgorithm>();
41 
45  public final void runAlgorithms(Households hh){
46  for(int i = 0; i < this.householdAlgorithms.size(); i++){
47  HouseholdAlgorithm algorithm = this.householdAlgorithms.get(i);
48  log.info("Running algorithm " + algorithm.getClass().getName());
49  Counter c = new Counter (" household # ");
50  for(Household household : hh.getHouseholds().values()){
51  algorithm.run(household);
52  c.incCounter();
53  }
54  c.printCounter();
55  log.info("Done running algorithm.");
56  }
57  }
58 
59  public void runAlgorithms(Household h){
60  for(HouseholdAlgorithm algorithm : this.householdAlgorithms){
61  log.info("Running algorithm " + algorithm.getClass().getName() + " on household " + h.getId());
62  algorithm.run(h);
63  }
64  }
65 
66 
70  public final void clearAlgorithms(){
71  this.householdAlgorithms.clear();
72  }
73 
80  public boolean removeAlgorithm(final HouseholdAlgorithm algorithm){
81  return this.householdAlgorithms.remove(algorithm);
82  }
83 
84 
90  public final void addAlgorithm(final HouseholdAlgorithm algorithm){
91  this.householdAlgorithms.add(algorithm);
92  }
93 }
final void addAlgorithm(final HouseholdAlgorithm algorithm)
Map< Id< Household >, Household > getHouseholds()
boolean removeAlgorithm(final HouseholdAlgorithm algorithm)