RepastHPC  2.3.1
Patch.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * Patch.h
36  *
37  * Created on: Jul 15, 2010
38  * Author: nick
39  */
40 
41 #ifndef PATCH_H_
42 #define PATCH_H_
43 
44 #include "AbstractRelogoAgent.h"
45 #include "RelogoDiscreteSpaceAdder.h"
46 #include "AgentSet.h"
47 #include "repast_hpc/Moore2DGridQuery.h"
48 #include "repast_hpc/VN2DGridQuery.h"
49 #include "Observer.h"
50 #include "relogo.h"
51 
52 namespace repast {
53 namespace relogo {
54 
58 class Patch: public AbstractRelogoAgent {
59 
60 public:
61 
68  Patch(repast::AgentId id, Observer* observer);
69  virtual ~Patch();
70 
74  virtual int pxCor() const {
75  return (int) _location[0];
76  }
77 
81  virtual int pyCor() const {
82  return (int) _location[1];
83  }
84 
93  template<typename PatchType>
95 
104  template<typename PatchType>
106 
114  template<typename PatchType>
115  void neighbors(AgentSet<PatchType>& out);
116 
125  template<typename PatchType>
126  void neighbors4(AgentSet<PatchType>& out);
127 
128 };
129 
130 template<typename PatchType>
133  neighbors(set);
134  return set;
135 }
136 
137 template<typename PatchType>
140  neighbors4(set);
141  return set;
142 }
143 
144 template<typename PatchType>
146  std::vector<RelogoAgent*> vec;
147  const RelogoGridType* grid = _observer->grid();
148  Moore2DGridQuery<RelogoAgent> query(grid);
149  query.query(Point<int> (pxCor(), pyCor()), 1, false, vec);
151  filterVecToSet(vec, out, PATCH_TYPE_ID);
152 }
153 
154 template<typename PatchType>
156  std::vector<RelogoAgent*> vec;
157  const RelogoGridType* grid = _observer->grid();
158  VN2DGridQuery<RelogoAgent> query(grid);
159  query.query(Point<int> (pxCor(), pyCor()), 1, false, vec);
160  filterVecToSet(vec, out, PATCH_TYPE_ID);
161 }
162 
163 }
164 
165 }
166 
167 #endif /* PATCH_H_ */
repast::Moore2DGridQuery
Neighborhood query that gathers neighbors in a Moore (N, S, E, W, NE, etc.) neighborhood.
Definition: Moore2DGridQuery.h:58
repast::relogo::AbstractRelogoAgent
Abstract base class for turtles and patches.
Definition: AbstractRelogoAgent.h:55
repast::AgentId
Agent identity information.
Definition: AgentId.h:60
repast::relogo::Patch::pxCor
virtual int pxCor() const
Gets the patch x coordinate of this patch's location.
Definition: Patch.h:74
repast::relogo::AgentSet
Specialized indexable collection class for agents.
Definition: AgentSet.h:82
repast::relogo::Observer::grid
const RelogoGridType * grid()
Gets the grid managed by this Observer.
Definition: Observer.cpp:154
repast::Grid< RelogoAgent, int >
repast::VN2DGridQuery::query
virtual void query(const Point< int > &center, int range, bool includeCenter, std::vector< T * > &out) const
Queries the Grid for the Von Neumann neighbors surrounding the center point within a specified range.
Definition: VN2DGridQuery.h:81
repast::relogo::Patch::Patch
Patch(repast::AgentId id, Observer *observer)
Creates a Patch that will have the specified id and be managed by the specified Observer.
Definition: Patch.cpp:48
repast::relogo::Patch::neighbors4
AgentSet< PatchType > neighbors4()
Gets the 4 (Von Neumann neighborhood) neighboring Patches of this Patch.
Definition: Patch.h:138
repast::VN2DGridQuery
Neighborhood query that gathers neighbors in a Von Neumann (N, S, E, W) neighborhood.
Definition: VN2DGridQuery.h:56
repast::relogo::Patch::neighbors
AgentSet< PatchType > neighbors()
Gets the 8 (Moore neighborhood) neighboring Patches of this Patch.
Definition: Patch.h:131
repast::Moore2DGridQuery::query
virtual void query(const Point< int > &center, int range, bool includeCenter, std::vector< T * > &out) const
Queries the Grid for the Moore neighbors surrounding the center point within a specified range.
Definition: Moore2DGridQuery.h:86
repast::relogo::Observer
Implementation of a logo Observer.
Definition: Observer.h:110
repast::Point< int >
repast::relogo::Patch
A logo patch.
Definition: Patch.h:58
repast::relogo::Patch::pyCor
virtual int pyCor() const
Gets the patch y coordinate of this patch's location.
Definition: Patch.h:81