View Javadoc
1   /**
2    * 
3    */
4   package org.opentrafficsim.water.demand;
5   
6   import org.locationtech.jts.geom.Coordinate;
7   import org.locationtech.jts.geom.MultiPolygon;
8   import org.locationtech.jts.geom.Point;
9   import org.opentrafficsim.water.AbstractNamed;
10  import org.opentrafficsim.water.RepeatableRandomStream;
11  
12  import nl.tudelft.simulation.jstats.streams.StreamInterface;
13  
14  /**
15   * A region that generates demand. Examples are municipalities or (in Europe), NUTS regions.
16   * <p>
17   * Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="http://opentrafficsim.org/docs/current/license.html">OpenTrafficSim License</a>.
19   * </p>
20   * <p>
21   * Based on software from the IDVV project, which is Copyright (c) 2013 Rijkswaterstaat - Dienst Water, Verkeer en Leefomgeving
22   * and licensed without restrictions to Delft University of Technology, including the right to sub-license sources and derived
23   * products to third parties.
24   * </p>
25   * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
26   * initial version Nov 6, 2016 <br>
27   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
28   */
29  public class Region extends AbstractNamed implements Comparable<Region>
30  {
31      /** */
32      private static final long serialVersionUID = 1L;
33  
34      /** the region to whic this region belongs, e.g. Municipality - Province - Country. */
35      private Region superRegion;
36  
37      /** the number of inhabitants in the region. */
38      private double inhabitants;
39  
40      /** the number of jobs in the region. */
41      private double jobs;
42  
43      /** the center of the region. */
44      private Coordinate center;
45  
46      /** the shape of this region. */
47      private MultiPolygon area;
48  
49      /** export ton/teu factor. */
50      private double exportTonTEU;
51  
52      /** import ton/teu factor. */
53      private double importTonTEU;
54  
55      /** export empty factor. */
56      private double exportEmptyFactor;
57  
58      /** import empty factor. */
59      private double importEmptyFactor;
60  
61      /** current Import TEU per year. */
62      private double currentImportTEUperYear = 0;
63  
64      /** current Export TEU per year. */
65      private double currentExportTEUperYear = 0;
66  
67      /** repeatable stream. */
68      private static StreamInterface randomStream = null;
69  
70      /**
71       * @param name String; the name of the region
72       * @param superRegion the region of which this region is part; can be null
73       * @param center Coordinate; the coordinate that denotes the center of the region
74       */
75      public Region(final String name, final Region superRegion, final Coordinate center)
76      {
77          super(name);
78          this.superRegion = superRegion;
79          this.center = center;
80  
81          randomStream = RepeatableRandomStream.create(this.getName());
82      }
83  
84      /**
85       * @return the superRegion
86       */
87      public final Region getSuperRegion()
88      {
89          return this.superRegion;
90      }
91  
92      /**
93       * @param jobs double; the jobs to set
94       */
95      public final void setJobs(final double jobs)
96      {
97          this.jobs = jobs;
98      }
99  
100     /**
101      * @return the jobs
102      */
103     public final double getJobs()
104     {
105         return (this.jobs > 0) ? this.jobs : 1;
106     }
107 
108     /**
109      * @return the center
110      */
111     public final Coordinate getCenter()
112     {
113         return this.center;
114     }
115 
116     /**
117      * @return the inhabitants
118      */
119     public final double getInhabitants()
120     {
121         return this.inhabitants;
122     }
123 
124     /**
125      * @param inhabitants double; set inhabitants
126      */
127     protected final void setInhabitants(final double inhabitants)
128     {
129         this.inhabitants = inhabitants;
130     }
131 
132     /**
133      * @return the exportTonTEU
134      */
135     public final double getExportTonTEU()
136     {
137         return this.exportTonTEU;
138     }
139 
140     /**
141      * @param exportTonTEU double; the exportTonTEU to set
142      */
143     public final void setExportTonTEU(final double exportTonTEU)
144     {
145         this.exportTonTEU = exportTonTEU;
146     }
147 
148     /**
149      * @return the importTonTEU
150      */
151     public final double getImportTonTEU()
152     {
153         return this.importTonTEU;
154     }
155 
156     /**
157      * @param importTonTEU double; the importTonTEU to set
158      */
159     public final void setImportTonTEU(final double importTonTEU)
160     {
161         this.importTonTEU = importTonTEU;
162     }
163 
164     /**
165      * @return the exportEmptyFactor
166      */
167     public final double getExportEmptyFactor()
168     {
169         return this.exportEmptyFactor;
170     }
171 
172     /**
173      * @param exportEmptyFactor double; the exportEmptyFactor to set
174      */
175     public final void setExportEmptyFactor(final double exportEmptyFactor)
176     {
177         this.exportEmptyFactor = exportEmptyFactor;
178     }
179 
180     /**
181      * @return the importEmptyFactor
182      */
183     public final double getImportEmptyFactor()
184     {
185         return this.importEmptyFactor;
186     }
187 
188     /**
189      * @param importEmptyFactor double; the importEmptyFactor to set
190      */
191     public final void setImportEmptyFactor(final double importEmptyFactor)
192     {
193         this.importEmptyFactor = importEmptyFactor;
194     }
195 
196     /**
197      * @return the currentExportTEUperYear
198      */
199     public final double getCurrentExportTEUperYear()
200     {
201         return this.currentExportTEUperYear;
202     }
203 
204     /**
205      * @param newExportTEUPerYear double; update currentExportTEUperYear
206      */
207     public final void setCurrentExportTEUperYear(final double newExportTEUPerYear)
208     {
209         this.currentExportTEUperYear = newExportTEUPerYear;
210     }
211 
212     /**
213      * @param newExportTEUPerYear double; add to currentExportTEUperYear
214      */
215     public final void addCurrentExportTEUperYear(final double newExportTEUPerYear)
216     {
217         this.currentExportTEUperYear += newExportTEUPerYear;
218     }
219 
220     /**
221      * @return the currentExportTEUperYear
222      */
223     public final double getCurrentImportTEUperYear()
224     {
225         return this.currentImportTEUperYear;
226     }
227 
228     /**
229      * @param newImportTEUPerYear double; update currentExportTEUperYear
230      */
231     public final void setCurrentImportTEUperYear(final double newImportTEUPerYear)
232     {
233         this.currentImportTEUperYear = newImportTEUPerYear;
234     }
235 
236     /**
237      * @param newImportTEUPerYear double; add to currentExportTEUperYear
238      */
239     public final void addCurrentImportTEUperYear(final double newImportTEUPerYear)
240     {
241         this.currentImportTEUperYear += newImportTEUPerYear;
242     }
243 
244     /**
245      * @return the area
246      */
247     public final MultiPolygon getArea()
248     {
249         return this.area;
250     }
251 
252     /**
253      * @param area MultiPolygon; the area to set
254      */
255     public final void setArea(final MultiPolygon area)
256     {
257         this.area = area;
258     }
259 
260     /**
261      * @param p Point; point
262      * @return whether point is within region bounds
263      */
264     public final boolean isInArea(final Point p)
265     {
266         return this.area.contains(p);
267     }
268 
269     /** {@inheritDoc} */
270     @Override
271     public final int compareTo(final Region other)
272     {
273         return this.getName().compareTo(other.getName());
274     }
275 
276     /** {@inheritDoc} */
277     @Override
278     @SuppressWarnings("checkstyle:designforextension")
279     public String toString()
280     {
281         return "Region " + this.getName();
282     }
283 
284 }