FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTsamodel.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 FMTSAMODEL_H
9#define FMTSAMODEL_H
10
11#include "FMTsemodel.hpp"
12#include <memory>
13#include <vector>
14#include <random>
15#include <boost/serialization/vector.hpp>
16#include <boost/serialization/serialization.hpp>
17#include <boost/serialization/nvp.hpp>
18#include <boost/serialization/export.hpp>
19
20namespace Spatial
21{
22 class FMTforest;
23 class FMTsaschedule;
24 class FMTexponentialschedule;
25}
26
27
28namespace Models
29{
30
43class FMTEXPORT FMTsamodel final: public FMTsemodel
44 {
45 // DocString: FMTsamodel::Serialize
49 friend class boost::serialization::access;
50 template<class Archive>
51 void serialize(Archive& ar, const unsigned int version)
52 {
53 ar& boost::serialization::make_nvp("semodel", boost::serialization::base_object<FMTsemodel>(*this));
54 }
55 enum FMTsamove
56 {
57 Local = 1,
58 ReBuilder = 2,
59 AreaConflictDestrutor = 3,
60 AdjacencyConflictDestrutor = 4,
61 MoveCount = 5
62 };
63 class FMTmovestats
64 {
65 public:
66 FMTmovestats() = default;
67 FMTmovestats(const FMTmovestats& rhs) = default;
68 FMTmovestats& operator=(const FMTmovestats& rhs) = default;
69 // DocString: FMTsamodel::FMTmovestats::MoveType
70 //The move done
71 FMTsamove MoveType;
72 // DocString: FMTsamodel::FMTmovestats::MoveSize
73 //Number of element changed
74 size_t MoveSize;
75 // DocString: FMTsamodel::FMTmovestats::ObjectiveImpact
76 //The amount of objective change due to the move
77 double ObjectiveImpact;
78 // DocString: FMTsamodel::FMTmovestats::Accepted
79 //If the move was Accepted
80 bool Accepted;
81 };
82 // DocString: FMTsamodel::TotalMoves
84 size_t TotalMoves;
85 // DocString: FMTsamodel::CycleMoves
87 mutable std::vector<FMTmovestats>CycleMoves;
88 // DocString: FMTsamodel::LastGlobalObjectiveValue
90 double LastGlobalObjectiveValue;
91 // DocString: FMTsamodel::Generator
93 mutable std::default_random_engine Generator;
94 // DocString: FMTsamodel::CoolingSchedule
96 std::unique_ptr<Spatial::FMTsaschedule> CoolingSchedule;
97 // DocString: FMTsamodel::NotAcceptedMovesCount
99 std::array<size_t, FMTsamove::MoveCount>NotAcceptedMovesCount;
100 // DocString: FMTsamodel()
104 FMTsamodel(const FMTsemodel& rhs);
105 protected:
106 // DocString: FMTspatialschedule::GetFromBindings
110 std::vector<bool> GetFromBindings(const Spatial::FMTspatialschedule::actionbindings& bindingactions) const;
111 // DocString: FMTsamodel::GetCycleMoves
115 size_t GetCycleMoves() const;
116 // DocString: FMTsamodel::GetAcceptedCycleMoves
120 size_t GetAcceptedCycleMoves() const;
121 // DocString: FMTsamodel::AllowDestruction
126 // DocString: FMTsamodel::AllowMove
130 bool AllowMove(const FMTsamove& move) const;
131 // DocString: FMTsamodel::AllowAnyMove
135 bool AllowAnyMove() const;
136 // DocString: FMTsamodel::GetAMove
141 // DocString: FMTsamodel::evaluate
146 bool IsBetter(const Spatial::FMTspatialschedule& actual, const Spatial::FMTspatialschedule& candidat) const;
147 // DocString: FMTsamodel::DoLocalMove
153 const std::vector<Spatial::FMTcoordinate>* movable,
154 boost::unordered_map<Core::FMTdevelopment, bool>* operability) const;
155 // DocString: FMTsamodel::DoConflictDestruction
161 std::vector<std::vector<Spatial::FMTcoordinate>> selectionpool, const int& period) const;
162 // DocString: FMTsamodel::DoEventsAreaConflictDestrutorMove
167 const Spatial::FMTspatialschedule::actionbindings& bindings) const;
168 // DocString: FMTsamodel::DoEventsAdjacencyConflictDestrutorMove
173 const Spatial::FMTspatialschedule::actionbindings& bindings) const;
174 // DocString: FMTsamodel::move
180 const std::vector<Spatial::FMTcoordinate>*movable = nullptr,
181 boost::unordered_map<Core::FMTdevelopment, bool>*operability= nullptr) const;
182 // DocString: FMTsamodel::warmup
188 const std::vector<Spatial::FMTcoordinate>*movable = nullptr,
189 boost::unordered_map<Core::FMTdevelopment, bool>*operability = nullptr,
190 double initprobability = 0.5,size_t iterations=10);
191 // DocString: FMTsamodel::initialgrow
196 // DocString: FMTsamodel::initialbuild
201 // DocString: FMTsamodel::schedulesbuild
205 void SchedulesBuild(const std::vector<Core::FMTschedule>&schedules);
206 // DocString: FMTsamodel::swap_ptr
210 virtual void swap_ptr(const std::unique_ptr<FMTmodel>& rhs);
211 // DocString: FMTsamodel:GetLocalMoveSize
215 size_t GetLocalMoveSize() const;
216 // DocString: FMTsamodel::GetRebuild
222 // DocString: FMTsamodel::isCycleProvenOptimal
227 // DocString: FMTsamodel::Dofactorization
232 // DocString: FMTsamodel::LogSolutionStatus
236 void LogSolutionStatus() const;
237 // DocString: FMTsamodel::LogTemperatureStatus
241 void LogCycleStatus() const;
242 // DocString: FMTsamodel::CoolDown
246 void CoolDown();
247 // DocString: FMTsamodel::UpdateFailedMoveCount
252 public:
253 // DocString: FMTsemodel::LogMovesReport
257 void LogMovesReport() const;
258 // DocString: FMTsamodel::isProvenOptimal
262 bool isProvenOptimal() const;
263 // DocString: FMTsamodel::initialsolve
268 // DocString: FMTsamodel::build
273 virtual bool build(std::vector<Core::FMTschedule> schedules = std::vector<Core::FMTschedule>());
274 // DocString: FMTsamodel::solve
278 virtual bool solve();
279 // DocString: FMTsamodel::presolve
284 virtual std::unique_ptr<FMTmodel>presolve(std::vector<Core::FMTactualdevelopment> optionaldevelopments = std::vector<Core::FMTactualdevelopment>()) const;
285 // DocString: FMTsamodel::getcopy
292 virtual std::unique_ptr<FMTmodel> getcopy(int period = 0) const;
300 FMTsamodel(const FMTmodel& rhs);
302 FMTsamodel(const FMTmodel& rhs,const Spatial::FMTforest& forest);
304 FMTsamodel& operator = (const FMTsamodel& rhs);
305 // DocString: FMTsamodel::clone
309 virtual std::unique_ptr<FMTmodel>clone() const final;
310
311 Graph::FMTgraphstats buildperiod();
312
313 };
314}
315
316BOOST_CLASS_EXPORT_KEY(Models::FMTsamodel)
317
318#endif // FMTSAMODEL_H
#define FMTEXPORT
Definition: FMTutility.hpp:92
Definition: FMTmodel.hpp:60
Definition: FMTsamodel.hpp:44
bool AllowMove(const FMTsamove &move) const
void SchedulesBuild(const std::vector< Core::FMTschedule > &schedules)
void UpdateFailedMoveCount()
virtual std::unique_ptr< FMTmodel > clone() const final
~FMTsamodel()
Destructor.
std::vector< bool > GetFromBindings(const Spatial::FMTspatialschedule::actionbindings &bindingactions) const
Spatial::FMTspatialschedule DoEventsAdjacencyConflictDestrutorMove(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings) const
virtual void swap_ptr(const std::unique_ptr< FMTmodel > &rhs)
FMTsamodel()
Constructor.
bool AllowAnyMove() const
Spatial::FMTspatialschedule DoLocalMove(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings, const std::vector< Spatial::FMTcoordinate > *movable, boost::unordered_map< Core::FMTdevelopment, bool > *operability) const
void LogCycleStatus() const
Spatial::FMTspatialschedule DoEventsAreaConflictDestrutorMove(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings) const
virtual std::unique_ptr< FMTmodel > getcopy(int period=0) const
size_t GetAcceptedCycleMoves() const
void LogMovesReport() const
void LogSolutionStatus() const
FMTsamodel(const FMTsamodel &rhs)
Copy constructor.
bool isProvenOptimal() const
virtual bool solve()
Spatial::FMTspatialschedule Move(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings, const std::vector< Spatial::FMTcoordinate > *movable=nullptr, boost::unordered_map< Core::FMTdevelopment, bool > *operability=nullptr) const
double Warmup(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings, const std::vector< Spatial::FMTcoordinate > *movable=nullptr, boost::unordered_map< Core::FMTdevelopment, bool > *operability=nullptr, double initprobability=0.5, size_t iterations=10)
virtual std::unique_ptr< FMTmodel > presolve(std::vector< Core::FMTactualdevelopment > optionaldevelopments=std::vector< Core::FMTactualdevelopment >()) const
virtual bool build(std::vector< Core::FMTschedule > schedules=std::vector< Core::FMTschedule >())
FMTsamodel(const FMTmodel &rhs, const Spatial::FMTforest &forest)
Copy constructor to use parent as argument in constructor.
Spatial::FMTspatialschedule DoConflictDestruction(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings, std::vector< std::vector< Spatial::FMTcoordinate > > selectionpool, const int &period) const
FMTsamove GetAMove(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings) const
size_t GetCycleMoves() const
bool isCycleProvenOptimal() const
size_t GetLocalMoveSize() const
bool AllowDestruction(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule::actionbindings &bindings) const
FMTsamodel(const FMTmodel &rhs)
Copy constructor to use parent as argument in constructor.
bool IsBetter(const Spatial::FMTspatialschedule &actual, const Spatial::FMTspatialschedule &candidat) const
Spatial::FMTspatialschedule GetRebuild(const Spatial::FMTspatialschedule &actual) const
Definition: FMTsemodel.hpp:33
Definition: FMTforest.hpp:27
Definition: FMTspatialschedule.hpp:44
std::vector< std::vector< Spatial::FMTbindingspatialaction > > actionbindings
Definition: FMTspatialschedule.hpp:49
Namespace for using/building unidirectional graphs in FMT.
Definition: FMTareaparser.hpp:31
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTareaparser.hpp:50
The spatial namespace provides classes for spatialy explicit simulation/optimization based on raster ...
Definition: FMTareaparser.hpp:36