FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTeventcontainer.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTeventCONTAINER_H
9#define FMTeventCONTAINER_H
10
11#include "FMTevent.hpp"
12#include <boost/serialization/serialization.hpp>
13#include <boost/serialization/nvp.hpp>
14#include <boost/serialization/set.hpp>
15#include <unordered_set>
16#include <boost/unordered_set.hpp>
17#include "FMTobject.hpp"
18
19
20namespace Spatial
21{
22
23class FMTbindingspatialaction;
24
25// DocString: FMTeventcontainer
35{
36 friend class boost::serialization::access;
37 template<class Archive>
38 void serialize(Archive& ar, const unsigned int version)
39 {
40 ar & boost::serialization::make_nvp("FMTobject", boost::serialization::base_object<FMTobject>(*this));
41 ar & BOOST_SERIALIZATION_NVP(events);
42 }
43
44 public:
45 typedef typename std::set<FMTevent>::value_type value_type;
46 typedef typename std::set<FMTevent>::iterator iterator;
47 typedef typename std::set<FMTevent>::const_iterator const_iterator;
48 typedef typename std::set<FMTevent>::const_reverse_iterator const_reverse_iterator;
49 // DocString: FMTeventcontainer()
54 // DocString: ~FMTeventcontainer()
59 // DocString: FMTeventcontainer(const FMTeventcontainer&)
64 // DocString: FMTeventcontainer::operator=
69 // DocString: FMTeventcontainer::operator==
73 bool operator==(const FMTeventcontainer& rhs) const;
74 // DocString: FMTeventcontainer::swap
79 // DocString: FMTeventcontainer::begin
83 const_iterator begin() const{return events.cbegin();}
84 // DocString: FMTeventcontainer::end
88 const_iterator end() const{return events.cend();}
89 // DocString: FMTeventcontainer::empty
93 bool empty() const {return events.empty();}
94 // DocString: FMTeventcontainer::size
98 size_t size() const {return events.size();}
99 // DocString: FMTeventcontainer::find
103 const_iterator find(const int& period, const FMTcoordinate& coord) const;
104 // DocString: FMTeventcontainer::find
108 const_iterator find(const FMTevent& event) const { return events.find(event); }
109 // DocString: FMTeventcontainer::insert
113 void insert(const FMTevent& event)
114 {
115 events.insert(event);
116 }
117 // DocString: FMTeventcontainer::merge
121 void merge(const FMTeventcontainer& levents);
122 // DocString: FMTeventcontainer::erase(const FMTevent&)
126 void erase(const FMTevent& event);
127 // DocString: FMTeventcontainer::erase(const const_iterator)
132 // DocString: FMTeventcontainer::clear
136 void clear (){events.clear();}
137 // DocString: FMTeventcontainer::lasperiod
138 /*
139 Return the period of the last event in the container
140 */
141 int lastperiod()const;
142 // DocString: FMTeventcontainer::firstperiod
143 /*
144 Return the period of the first event in the container
145 */
146 int firstperiod()const;
147 // DocString: FMTeventcontainer::erasecoordinate
148 /*
149 Erase all coordinate corresponding to coord in events from the period start.
150 */
151 //void erasecoordinate(const FMTcoordinate& coord, const int& periodstart);
152 // DocString: FMTeventcontainer::erasecoordinate
153 /*
154 Erase all coordinate corresponding to coord in events from the period start.
155 */
156 void erasecoordinate(const FMTcoordinate& coord, const int& periodstart,const std::vector<std::vector<bool>>& actionstarget);
157 // DocString: FMTeventcontainer::getbounds(const int&)
158 /*
159 Return a pair of iterator pointing to the first and the last elements in the period
160 */
161 std::pair<const_iterator,const_iterator> getbounds(const int& period) const;
162 // DocString: FMTeventcontainer::addaction(const FMTcoordinate&, const int&, const int&,const FMTbindingspatialaction&)
163 /*
164 Add an action at coordinate and add to existing event if possible or aggregate events based on binding
165 */
166 void addaction (const FMTcoordinate& coord, const int& period,const int& actionid,const FMTbindingspatialaction& binding);
167 // DocString: FMTeventcontainer::addactions()
168 /*
169 Add actions at coordinate and add to existing event if possible or aggregate events based on (bindings).
170 (bindings) must be the size of the vector of action in model because we use (actionids) to find the right ones.
171 */
172 void addactions(const FMTcoordinate& coord, const int& period, const std::vector<int>& actionids, const std::vector<FMTbindingspatialaction>& bindings);
173 // DocString: FMTeventcontainer::getevents(const int&, const int&)
174 /*
175 Get events at specified period with specified action
176 */
177 std::vector<const_iterator> getevents(const int& period, const int& action_id) const;
178 // DocString: FMTeventcontainer::getevents(const int&, const int&,const FMTcoordinate&,const FMTcoordinate&)
179 /*
180 Get events at specified period with specified action for a minimal and maximalcoordinate.
181 */
182 std::vector<const_iterator> getevents(const int& period, const int& action_id,
183 const FMTcoordinate& minimalcoordinate, const FMTcoordinate& maximalcoordinate) const;
184 // DocString: FMTeventcontainer::getmultipleevents()
185 /*
186 Get events at specified period with specified action for a minimal and maximalcoordinate.
187 */
188 std::vector<std::vector<const_iterator>> getmultipleevents(const int& period, const std::vector<int>& action_ids,
189 const FMTcoordinate& minimalcoordinate, const FMTcoordinate& maximalcoordinate) const;
190 // DocString: FMTeventcontainer::getevents(const int&, const std::vector<int>&)
191 /*
192 Get events at specified period with multiple actions id
193 */
194 std::vector<const_iterator> getevents(const int& period, const std::vector<int>& actions_id) const;
195 // DocString: FMTeventcontainer::getevents(const int&, const std::vector<bool>&)
196 /*
197 Get events at specified period is action is used
198 */
199 std::vector<const_iterator> getevents(const int& period, const std::vector<bool>& actions_used) const;
200 // DocString: FMTeventcontainer::getevents(const int&, const std::vector<bool>&,const FMTcoordinate&, const FMTcoordinate&)
201 /*
202 Get events at specified period for multiple (actions_used), between a minimal coordinate and a maximal coordinate.
203 */
204 std::vector<const_iterator> getevents(const int& period, const std::vector<bool>& actions_used,
205 const FMTcoordinate& minimalcoordinate, const FMTcoordinate& maximalcoordinate) const;
206 // DocString: FMTeventcontainer::getevents(const int&, const FMTcoordinate&)
207 /*
209 */
210 std::vector<const_iterator> getevents(const int& period, const FMTcoordinate& coord) const;
211 // DocString: FMTeventcontainer::getevents(const int&, const FMTcoordinate&)
212 /*
213 Get events starting from a period based on a buffer around events returns the events to delete if you remove coord
214 The newevents container is the container containing modified events resulting from erasing the coord. Following a move,
215 get the infeasibility of the erased events, add the infeasibility of the events in the newevents added the this container with erased events.
216 */
217 FMTeventcontainer geteventstoerase(const int& fromperiod, const std::vector<std::vector<bool>>& actionstarget,
218 const FMTcoordinate& coord,const size_t& buffer,FMTeventcontainer& newevents) const;
219 // DocString: FMTeventcontainer::geteventstoadd
220 /*
221 Add the action to the coordinate and return the modified events that infeasibility need to be calculated (removed). The newevents
222 contains the new events to calculated infeasibility you need to delete the vector returned and add the newevents to the container and
223 calculate the infeasibility of those events.
224 */
225 FMTeventcontainer geteventstoadd(const FMTcoordinate& coord, const int& period, const int& actionid,
226 const FMTbindingspatialaction& binding, FMTeventcontainer& newevents) const;
227 // DocString: FMTeventcontainer::getcontainer
228 /*
229 Get container subset on the interesting coordinates.
230 */
231 FMTeventcontainer getcontainer(std::vector<FMTcoordinate> coordinates, const int& minperiod, const int& maxperiod, const size_t& buffer) const;
232
233 // DocString: FMTeventcontainer::addupdate
234 /*
235 Update the events container.
236 Used to calculate infeasibility.
237 */
238 FMTeventcontainer addupdate(const FMTeventcontainer& newevents,const FMTeventcontainer& eventstoremove);
239
240 // DocString: FMTeventcontainer::getevents(const int&, const std::set<FMTcoordinate>&)
241 /*
243 */
244 std::vector<const_iterator> getevents(const int& period, const std::set<FMTcoordinate>& territory) const;
245 // DocString: FMTeventcontainer::minimaldistance
251 double minimaldistance(const FMTevent&,const unsigned int& distancel,const int& period, const std::vector<int>& actionsid) const;
252 // DocString: FMTeventcontainer::minimaldistance
258 const double& lowerdistancetoevent,
259 const double& upperdistancetoevent,
260 const int& period, const std::vector<bool>& actionsused,
261 boost::unordered_set<FMTeventrelation>& relations) const;
262 private:
264 std::set<FMTevent> events;
265 //Actually not needed
266 /*iterator end(){return events.end();}
267 iterator begin(){return events.begin();}*/
269 const_iterator upper_bound(const int& period) const;
271 const_iterator upper_bound(const int& period,const FMTcoordinate& maxxycoord) const;
274 const_iterator lower_bound(const int& period) const;
277 const_iterator lower_bound(const int& period, const FMTcoordinate& minxycoord) const;
281 void erase(const FMTcoordinate& coord, const std::vector<const_iterator>& iterators);
282 // DocString: FMTeventcontainer::pushaction
283 /*
284 Push an action in container
285 */
286 void pushaction(const std::vector<FMTeventcontainer::const_iterator>& iterators,
287 const FMTcoordinate& coord, const int& period, const int& actionid,size_t neighborsize);
288 // DocString: FMTeventcontainer::getaroundevents()
289 /*
290 Return iterators to events considerate around based on neighborsize
291 */
292 std::vector<FMTeventcontainer::const_iterator> getaroundevents(const std::vector<FMTeventcontainer::const_iterator>& iterators,
293 const FMTcoordinate& coord, const size_t& neighborsize) const;
294 // DocString: FMTeventcontainer::fastsort
295 /*
296 Sort events by proximity to a coordinate
297 */
298 void nthelements(std::vector<FMTeventcontainer::const_iterator>& iterators,const FMTcoordinate& coord,const size_t& nelement) const;
299
300 class FMTeventiteratorsorter
301 {
302 FMTcoordinate basecoordinate;
303 public:
304 FMTeventiteratorsorter(const FMTcoordinate& coordinate);
305 bool operator() (const FMTeventcontainer::const_iterator& eventit1, const FMTeventcontainer::const_iterator& eventit2) const;
306 };
307
308
309};
310
311
312}
313#endif // FMTeventCONTAINER_H
#define FMTEXPORT
Definition: FMTutility.hpp:92
Definition: FMTobject.hpp:50
Definition: FMTbindingspatialaction.hpp:19
Definition: FMTcoordinate.hpp:25
Definition: FMTevent.hpp:28
Definition: FMTeventcontainer.hpp:35
bool empty() const
Definition: FMTeventcontainer.hpp:93
void insert(const FMTevent &event)
Definition: FMTeventcontainer.hpp:113
size_t size() const
Definition: FMTeventcontainer.hpp:98
FMTeventcontainer & operator=(const FMTeventcontainer &rhs)
std::vector< const_iterator > getevents(const int &period, const int &action_id) const
std::pair< const_iterator, const_iterator > getbounds(const int &period) const
std::vector< std::vector< const_iterator > > getmultipleevents(const int &period, const std::vector< int > &action_ids, const FMTcoordinate &minimalcoordinate, const FMTcoordinate &maximalcoordinate) const
double evaluatedistance(const FMTevent &, const double &lowerdistancetoevent, const double &upperdistancetoevent, const int &period, const std::vector< bool > &actionsused, boost::unordered_set< FMTeventrelation > &relations) const
std::vector< const_iterator > getevents(const int &period, const std::vector< int > &actions_id) const
std::set< FMTevent >::value_type value_type
Definition: FMTeventcontainer.hpp:45
void merge(const FMTeventcontainer &levents)
void erase(const FMTevent &event)
std::set< FMTevent >::iterator iterator
Definition: FMTeventcontainer.hpp:46
const_iterator begin() const
Definition: FMTeventcontainer.hpp:83
FMTeventcontainer geteventstoadd(const FMTcoordinate &coord, const int &period, const int &actionid, const FMTbindingspatialaction &binding, FMTeventcontainer &newevents) const
std::vector< const_iterator > getevents(const int &period, const FMTcoordinate &coord) const
FMTeventcontainer getcontainer(std::vector< FMTcoordinate > coordinates, const int &minperiod, const int &maxperiod, const size_t &buffer) const
const_iterator erase(const const_iterator event)
void swap(FMTeventcontainer &rhs)
bool operator==(const FMTeventcontainer &rhs) const
std::vector< const_iterator > getevents(const int &period, const std::vector< bool > &actions_used, const FMTcoordinate &minimalcoordinate, const FMTcoordinate &maximalcoordinate) const
std::vector< const_iterator > getevents(const int &period, const int &action_id, const FMTcoordinate &minimalcoordinate, const FMTcoordinate &maximalcoordinate) const
std::vector< const_iterator > getevents(const int &period, const std::set< FMTcoordinate > &territory) const
std::set< FMTevent >::const_iterator const_iterator
Definition: FMTeventcontainer.hpp:47
FMTeventcontainer addupdate(const FMTeventcontainer &newevents, const FMTeventcontainer &eventstoremove)
const_iterator find(const FMTevent &event) const
Definition: FMTeventcontainer.hpp:108
void clear()
Definition: FMTeventcontainer.hpp:136
FMTeventcontainer(const FMTeventcontainer &rhs)
void erasecoordinate(const FMTcoordinate &coord, const int &periodstart, const std::vector< std::vector< bool > > &actionstarget)
double minimaldistance(const FMTevent &, const unsigned int &distancel, const int &period, const std::vector< int > &actionsid) const
std::vector< const_iterator > getevents(const int &period, const std::vector< bool > &actions_used) const
FMTeventcontainer geteventstoerase(const int &fromperiod, const std::vector< std::vector< bool > > &actionstarget, const FMTcoordinate &coord, const size_t &buffer, FMTeventcontainer &newevents) const
void addaction(const FMTcoordinate &coord, const int &period, const int &actionid, const FMTbindingspatialaction &binding)
const_iterator find(const int &period, const FMTcoordinate &coord) const
const_iterator end() const
Definition: FMTeventcontainer.hpp:88
void addactions(const FMTcoordinate &coord, const int &period, const std::vector< int > &actionids, const std::vector< FMTbindingspatialaction > &bindings)
std::set< FMTevent >::const_reverse_iterator const_reverse_iterator
Definition: FMTeventcontainer.hpp:48
The spatial namespace provides classes for spatialy explicit simulation/optimization based on raster ...
Definition: FMTareaparser.hpp:36