FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTSaModel.h
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.h"
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#ifdef FMTWITHOSI
31 class FMTLpModel;
32#endif
33// DocString: FMTSaModel
39class FMTEXPORT FMTSaModel final: public FMTSeModel
40 {
41 public:
42 // DocString: FMTSeModel::logMovesReport
46 void logMovesReport() const;
47 // DocString: FMTSaModel::isProvenOptimal
52 bool isProvenOptimal() const;
53 // DocString: FMTSaModel::initialSolve
59 // DocString: FMTSaModel::build
65 virtual bool build(std::vector<Core::FMTSchedule> schedules = std::vector<Core::FMTSchedule>());
66 // DocString: FMTSaModel::solve
71 virtual bool solve();
72 // DocString: FMTSaModel::preSolve
78 virtual std::unique_ptr<FMTModel>preSolve(std::vector<Core::FMTActualDevelopment> optionaldevelopments = std::vector<Core::FMTActualDevelopment>()) const;
79 // DocString: FMTSaModel::getCopy
86 virtual std::unique_ptr<FMTModel> getCopy(int period = 0) const;
87 // DocString: FMTSaModel()
91 FMTSaModel()=default;
92 // DocString: ~FMTSaModel()
97 // DocString: FMTSaModel(const FMTSaModel)
103 // DocString: FMTSaModel(const FMTModel)
108 FMTSaModel(const FMTModel& rhs);
109 // DocString: FMTSaModel(const FMTModel, const FMTForest)
115 FMTSaModel(const FMTModel& rhs, const Spatial::FMTForest& forest);
116 // DocString: FMTSaModel::operator=
122 FMTSaModel& operator = (const FMTSaModel& rhs);
123 // DocString: FMTSaModel::clone
128 virtual std::unique_ptr<FMTModel>clone() const final;
129
130 // DocString: FMTSaModel::buildPeriod
135 Graph::FMTGraphStats buildPeriod();
136 protected:
137 // DocString: FMTSaModel::swapPtr
142 virtual void swapPtr(std::unique_ptr<FMTModel>& rhs);
143 private:
144 // DocString: FMTSaModel::Serialize
151 friend class boost::serialization::access;
152 template<class Archive>
153 void serialize(Archive& ar, const unsigned int version)
154 {
155 ar& boost::serialization::make_nvp("semodel", boost::serialization::base_object<FMTSeModel>(*this));
156 }
157 enum FMTsamove
158 {
159 Local = 1,
160 AreaConflictDestrutor = 2,
161 AdjacencyConflictDestrutor = 3,
162 GroupsConflictDestructor = 4,
163 EventsSpread = 5,
164 //ReBuilder = 7,
165 MoveCount = 6
166 };
167 // DocString: FMTSaModel::getMovesName
173 static std::string getMovesName(FMTsamove p_move);
174 class FMTMoveStats
175 {
176 public:
177 FMTMoveStats() = default;
178 FMTMoveStats(const FMTMoveStats& rhs) = default;
179 FMTMoveStats& operator=(const FMTMoveStats& rhs) = default;
180 // DocString: FMTSaModel::FMTMoveStats::MoveType
181 //The move done
182 FMTsamove MoveType;
183 // DocString: FMTSaModel::FMTMoveStats::MoveSize
184 //Number of element changed
185 size_t MoveSize;
186 // DocString: FMTSaModel::FMTMoveStats::ObjectiveImpact
187 //The amount of objective change due to the move
188 double ObjectiveImpact;
189 // DocString: FMTSaModel::FMTMoveStats::Accepted
190 //If the move was Accepted
191 bool Accepted;
192 };
193 // DocString: FMTSaModel::totalMoves
195 size_t m_TotalMoves;
196 // DocString: FMTSaModel::cycleMoves
198 mutable std::vector<FMTMoveStats>m_CycleMoves;
199 // DocString: FMTSaModel::coolingSchedule
201 std::unique_ptr<Spatial::FMTSaSchedule>m_CoolingSchedule;
202 // DocString: FMTSaModel::notAcceptedMovesCount
204 std::array<size_t, FMTsamove::MoveCount>m_NotAcceptedMovesCount;
205 // DocString: FMTSaModel::m_BestObjective
207 double m_BestObjective;
208 // DocString: FMTSaModel(const FMTSeModel)
213 FMTSaModel(const FMTSeModel& rhs);
214 // DocString: FMTSaModel::_doWriteDisturbances
219 bool _doWriteDisturbances() const;
220 // DocString: FMTSaModel::_writeDisturbances
224 void _writeDisturbances() const;
225 // DocString: FMTSaModel::getFromBindings
232 std::vector<bool> _getFromBindings(const Spatial::FMTSpatialSchedule::actionbindings& bindingactions, bool adjacency = false) const;
233 // DocString: FMTSaModel::getCycleMoves
238 size_t _getCycleMoves() const;
239 // DocString: FMTSaModel::getAcceptedCycleMoves
244 size_t _getAcceptedCycleMoves() const;
245 // DocString: FMTSaModel::allowDestruction
252 bool _allowAreaDestruction(const Spatial::FMTSpatialSchedule& actual, const Spatial::FMTSpatialSchedule::actionbindings& bindings) const;
253 // DocString: FMTSaModel::_allowAdjacencyDestruction
260 bool _allowAdjacencyDestruction(const Spatial::FMTSpatialSchedule& actual, const Spatial::FMTSpatialSchedule::actionbindings& bindings) const;
261 // DocString: FMTSaModel::_allowGroupDestruction
267 bool _allowGroupDestruction(const Spatial::FMTSpatialSchedule& p_actual) const;
268 // DocString: FMTSaModel::_allowEventsSpread
274 bool _allowEventsSpread(const Spatial::FMTSpatialSchedule& p_actual) const;
275 // DocString: FMTSaModel::allowMove
281 bool _allowMove(const FMTsamove& move) const;
282 // DocString: FMTSaModel::allowAnyMove
287 bool _allowAnyMove() const;
288 // DocString: FMTSaModel::getAMove
295 FMTsamove _getAMove(const Spatial::FMTSpatialSchedule& actual, const Spatial::FMTSpatialSchedule::actionbindings& bindings) const;
296 // DocString: FMTSaModel::evaluate
302 bool _isBetter(double p_candidatObjective) const;
303 // DocString: FMTSaModel::doLocalMove
311 const Spatial::FMTSpatialSchedule::actionbindings& bindings) const;
312 // DocString: FMTSaModel::doConflictDestruction
321 Spatial::FMTSpatialSchedule _doConflictDestruction(const Spatial::FMTSpatialSchedule& actual,
323 std::vector<std::vector<Spatial::FMTCoordinate>> selectionpool, const int& period) const;
324 // DocString: FMTSaModel::doEventsAreaConflictDestrutorMove
331 Spatial::FMTSpatialSchedule _doEventsAreaConflictDestrutorMove(const Spatial::FMTSpatialSchedule& actual,
332 const Spatial::FMTSpatialSchedule::actionbindings& bindings) const;
333 // DocString: FMTSaModel::doEventsAdjacencyConflictDestrutorMove
340 Spatial::FMTSpatialSchedule _doEventsAdjacencyConflictDestrutorMove(const Spatial::FMTSpatialSchedule& actual,
341 const Spatial::FMTSpatialSchedule::actionbindings& bindings) const;
342 // DocString: FMTSaModel::doGroupsConflictDestrutorMove
348 Spatial::FMTSpatialSchedule _doGroupsConflictDestrutorMove(const Spatial::FMTSpatialSchedule& p_actual) const;
349 // DocString: FMTSaModel::_doEventsSpread
355 Spatial::FMTSpatialSchedule _doEventsSpread(const Spatial::FMTSpatialSchedule& p_actual) const;
356
357
358 // DocString: FMTSaModel::move
366 const Spatial::FMTSpatialSchedule::actionbindings& bindings) const;
367 // DocString: FMTSaModel::warmup
374 double _warmup(const Spatial::FMTSpatialSchedule& actual,
376 // DocString: FMTSaModel::initialgrow
380 void _initialGrow();
381 // DocString: FMTSaModel::initialbuild
385 void _randomBuild();
386 // DocString: FMTSaModel::schedulesbuild
391 void _schedulesBuild(const std::vector<Core::FMTSchedule>&schedules);
392 // DocString: FMTSaModel::_getLocalMoveSize
397 size_t _getLocalMoveSize() const;
398 // DocString: FMTSaModel::_getMaximalMoveSize
404 size_t _getMaximalMoveSize(size_t p_MaxSize) const;
405 // DocString: FMTSaModel::_getRandomMoveSize
411 size_t _getRandomMoveSize(size_t p_MaxSize) const;
412 // DocString: FMTSaModel::getRebuild
418 Spatial::FMTSpatialSchedule _getRebuild(const Spatial::FMTSpatialSchedule& actual) const;
419 // DocString: FMTSaModel::isCycleProvenOptimal
424 bool _isCycleProvenOptimal() const;
425 // DocString: FMTSaModel::dofactorization
429 void _doFactorization();
430 // DocString: FMTSaModel::logSolutionStatus
434 void _logSolutionStatus() const;
435 // DocString: FMTSaModel::logTemperatureStatus
439 void _logCycleStatus() const;
440 // DocString: FMTSaModel::coolDown
444 void _coolDown();
445 // DocString: FMTSaModel::updateFailedMoveCount
449 void _UpdateFailedMoveCount();
450
451 // DocString: FMTSaModel::_GetSchedules
458 std::vector<Core::FMTSchedule>_GetSchedules(const Spatial::FMTSpatialSchedule& p_SpatialSchedule, bool withlock) const;
459
460 #ifdef FMTWITHOSI
461 // DocString: FMTSaModel::_getRandomLpModel
467 Models::FMTLpModel _getRandomLpModel(const Spatial::FMTSpatialSchedule& p_SpatialSchedule) const;
468 #endif
469
470 // DocString: FMTSaModel::_setBestSolutionTo
476 void _setBestSolutionTo(Spatial::FMTSpatialSchedule& p_NewBestSolution,
477 double p_ObjectiveValue);
478
479 // DocString: FMTSaModel::_getConstraintsStats
489 void _getConstraintsStats(const Spatial::FMTSpatialSchedule& p_NewBestSolution,double& p_Objective,
490 double& p_SpatialRatio, double& p_InventoryRatio, double& p_TotalRatiom,
491 double& p_PrimalInf) const;
492
493
494 // DocString: FMTSaModel::_resetTabouMoves
498 void _resetTabouMoves();
499
500 // DocString: FMTSaModel::_getNonTabouMoves
505 std::vector<FMTsamove> _getNonTabouMoves() const;
506
507 // DocString: FMTSaModel::_allowMove
515 bool _allowMove(FMTsamove p_move, const Spatial::FMTSpatialSchedule& p_actual,
516 const Spatial::FMTSpatialSchedule::actionbindings& p_bindings) const;
517
518
519 };
520}
521
522BOOST_CLASS_EXPORT_KEY(Models::FMTSaModel)
523
524#endif // FMTSAMODEL_H
#define FMTEXPORT
Definition: FMTutility.h:125
Type III LP forest planning model, with the graph divided per period.
Definition: FMTLpModel.h:54
Base class for the different models in FMT.
Definition: FMTModel.h:62
Area restricted model (ARM) using the simulated annealing meta-heuristic to solve the spatial optimiz...
Definition: FMTSaModel.h:40
bool isProvenOptimal() const
Return true if the solution is optimal based on the termination criteria.
virtual std::unique_ptr< FMTModel > clone() const final
Get a clone of the FMTSaModel.
FMTSaModel(const FMTSaModel &rhs)
Copy constructor for FMTSaModel.
bool initialSolve()
Try to solve the model from a cold start.
FMTSaModel(const FMTModel &rhs)
Construct a FMTSaModel from a FMTModel, using the parent as argument.
virtual bool build(std::vector< Core::FMTSchedule > schedules=std::vector< Core::FMTSchedule >())
Try to build the spatial schedule from a schedule if one is provided, otherwise randomly build the mo...
virtual std::unique_ptr< FMTModel > getCopy(int period=0) const
Return a copy of the FMTModel for the selected period.
FMTSaModel(const FMTModel &rhs, const Spatial::FMTForest &forest)
Construct a FMTSaModel from a FMTModel and a forest.
~FMTSaModel()
Destructor for FMTSaModel.
FMTSaModel()=default
Default constructor for FMTSaModel.
virtual bool solve()
Call initialSolve on the solver.
void logMovesReport() const
Log the moves report.
virtual std::unique_ptr< FMTModel > preSolve(std::vector< Core::FMTActualDevelopment > optionaldevelopments=std::vector< Core::FMTActualDevelopment >()) const
Return a presolved copy of the model using a vector of developments and the actual transitions,...
Abstract class for spatially explicit models, parent of FMTSesModel and FMTSaModel.
Definition: FMTSeModel.h:33
Spatially referenced layer of Core::FMTDevelopment representing the forest.
Definition: FMTForest.h:33
Map containing a line graph for each cell, representing the stand, the action and the transition at e...
Definition: FMTSpatialSchedule.h:50
std::vector< std::vector< Spatial::FMTBindingSpatialAction > > actionbindings
Definition: FMTSpatialSchedule.h:52
Definition: FMTAreaParser.h:35
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
Definition: FMTAreaParser.h:40
Definition: FMTAction.h:463
STL namespace.