FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTSpatialSchedule.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#ifndef FMTSpatialSchedule_H
8#define FMTSpatialSchedule_H
9
10#include "FMTLayer.hpp"
11#include "FMTLineGraph.h"
12#include "FMTEventContainer.h"
14#include "FMTVirtualLineGraph.h"
15#include "FMTSolutionTracker.h"
16
17namespace Core {
18 class FMTGCBMTransition;
19 class FMTOutput;
20 class FMTModel;
21 class FMTConstraint;
22 class FMTYields;
23 class FMTAction;
24 class FMTDevelopment;
25}
26
27namespace Models{
28 class FMTSeModel;
29}
30
31
32
33namespace Spatial
34{
35class FMTForest;
36class FMTSpatialGraphs;
37class FMTPatchRules;
39 {
41 FMTpartial = 2
42 };
43
44// DocString: FMTSpatialSchedule
49class FMTEXPORT FMTSpatialSchedule : public FMTLayer<FMTVirtualLineGraph>
50{
51 public:
52 typedef std::vector<std::vector<Spatial::FMTBindingSpatialAction>> actionbindings;
53 // DocString: FMTSpatialSchedule()
58 // DocString: ~FMTSpatialSchedule()
62 virtual ~FMTSpatialSchedule() = default;
63 // DocString: FMTSpatialSchedule::=
70 // DocString: FMTSpatialSchedule(const FMTSpatialSchedule)
75 FMTSpatialSchedule(const FMTSpatialSchedule& other) = default;
76 // DocString: FMTSpatialSchedule(const FMTForest,size_t)
83 FMTSpatialSchedule(const FMTForest& p_InitialMap,
84 size_t p_LengthReserve, FMTSpatialGraphs& p_SpatialGraph);
85
86 // DocString: FMTSpatialSchedule(const FMTSpatialSchedule,const std::vector<FMTCoordinate>)
94 const std::vector<FMTCoordinate>::const_iterator& firstcoord,
95 const std::vector<FMTCoordinate>::const_iterator& endcoord);
96
97 // DocString: FMTSpatialSchedule::==
103 bool operator == (const FMTSpatialSchedule& rhs)const;
104 // DocString: FMTSpatialSchedule::!=
110 bool operator != (const FMTSpatialSchedule& rhs)const;
111 // DocString: FMTSpatialSchedule::empty
116 bool empty() const {return m_mapping.empty();};
117 // DocString: FMTSpatialSchedule::actPeriod
122 int actPeriod() const;
123 // DocString: FMTSpatialSchedule::getForestPeriod
131 FMTForest getForestPeriod(const int& period,bool periodStart=false) const;
132 // DocString: FMTSpatialSchedule::allowAction
141 bool allowAction(const int& targetaction,const std::vector<Spatial::FMTBindingSpatialAction>&bindingactions,const FMTCoordinate& location, const int& period) const;
142 // DocString: FMTSpatialSchedule::getUpdatedScheduling
154 std::vector<std::set<Spatial::FMTCoordinate>>getUpdatedScheduling(
155 const Models::FMTModel& model,
156 const std::vector<int>& actiontargets,
157 boost::unordered_map<Core::FMTDevelopment, std::vector<bool>>& cachedaction,
158 const std::vector<boost::unordered_set<Core::FMTDevelopment>>& scheduleoperabilities,
159 bool schedule_only = true,
160 std::vector<std::set<Spatial::FMTCoordinate>> original= std::vector<std::set<Spatial::FMTCoordinate>>(),
161 std::vector<FMTCoordinate> updatedcoordinate= std::vector<FMTCoordinate>()) const;
162
163 // DocString: FMTSpatialSchedule::evaluatespatialconstraint
170 double evaluateSpatialConstraint(const Core::FMTConstraint& p_SpatialConstraint,
171 const FMTSpatialGraphs& p_SpatialGraph) const;
172 // DocString: FMTSpatialSchedule::evaluateDistance
176 /*double evaluateDistance(const FMTEvent& eventof,
177 const double& lowerdistancetoevent,
178 const double& upperdistancetoevent,
179 const int& period, const std::vector<bool>& actionsused,
180 std::unordered_set<size_t>& relations,
181 const std::vector<FMTEventContainer::const_iterator>& events) const;*/
182 // DocString: FMTSpatialSchedule::verifySpatialFeasibility
191 std::set<FMTCoordinate> verifySpatialFeasibility(const int& targetaction,
192 const std::vector<Spatial::FMTBindingSpatialAction>& bindingactions,
193 const int& period, const std::set<FMTCoordinate>& operables) const;
194 // DocString: FMTSpatialSchedule::buildHarvest
206 FMTEventContainer buildHarvest(const double& target, const Spatial::FMTBindingSpatialAction& targetaction, std::default_random_engine& generator, std::set<FMTCoordinate> mapping_pass,
207 const int& previousperiod, const int& actionid, std::vector<FMTCoordinate>& operated) const;
208 // DocString: FMTSpatialSchedule::operateEvents
219 double operateEvents(const FMTEventContainer& cuts,const Core::FMTAction& action, const int& action_id, const Core::FMTTransition& Transition,
220 const Core::FMTYields& ylds, const std::vector<Core::FMTTheme>& themes);
221 // DocString: FMTSpatialSchedule::operateCoord
232 void operateCoord(const FMTCoordinate& coord,const Core::FMTAction& action, const int& action_id, const FMTBindingSpatialAction& bindingspaction, const Core::FMTTransition& Transition,
233 const Core::FMTYields& ylds, const std::vector<Core::FMTTheme>& themes);
234 // DocString: FMTSpatialSchedule::grow
238 void grow();
239 // DocString: FMTSpatialSchedule::setNewPeriod
243 //void setNewPeriod();
244 // DocString: FMTSpatialSchedule::getSchedules
251 std::vector<Core::FMTSchedule> getSchedules(const FMTSpatialGraphs p_Graphs,bool withlock=false) const;
252 // DocString: FMTSpatialSchedule::isBetterThan
259 std::vector<int> isBetterThan(const FMTSpatialSchedule& newsolution,
260 const Spatial::FMTSpatialGraphs& p_Graphs) const;
261 // DocString: FMTSpatialSchedule::getConstraintEvaluation
268 double getConstraintEvaluation(const FMTSpatialGraphs& p_Graphs, size_t p_ConstraintId) const;
269 // DocString: FMTSpatialSchedule::getConstraintsValues
275 std::vector<double> getConstraintsValues(const Spatial::FMTSpatialGraphs& p_Graphs) const;
276 // DocString: FMTSpatialSchedule::getWeightedFactors
282 std::vector<double> getWeightedFactors(const Spatial::FMTSpatialGraphs& p_Graphs) const;
283 // DocString: FMTSpatialSchedule::getdualinfeasibility
291 double getPrimalInfeasibility(const std::vector<const Core::FMTConstraint*>& constraints,
292 const Spatial::FMTSpatialGraphs& p_Graphs, bool withfactorization = false) const;
293 // DocString: FMTSpatialSchedule::logSolutionStatus
300 void logSolutionStatus(const size_t& iteration, const double& objective, const double& primalinfeasibility) const;
301 // DocString: FMTSpatialSchedule::getSolutionStatus
311 void getSolutionStatus(double& objective, double& primalinfeasibility,
312 const FMTSpatialGraphs& p_Graphs,
313 bool withsense = true, bool withfactorization = false,bool withspatial = true) const;
314 // DocString: FMTSpatialSchedule::getGlobalObjective
321 double getGlobalObjective(const FMTSpatialGraphs& p_Graphs) const;
322 // DocString: FMTSpatialSchedule::getobjectivevaluey
329 double getObjectiveValue(const FMTSpatialGraphs& p_Graphs,bool withsense = true) const;
330
331 // DocString: FMTSpatialSchedule::getPatchStats
337 std::string getPatchStats(const std::vector<Core::FMTAction>& actions) const;
338 // DocString: FMTSpatialSchedule::lastDistLayer
345 FMTLayer<std::string> lastDistLayer(const std::vector<Core::FMTAction>& modelactions, const int& period) const;
346 // DocString: FMTSpatialSchedule::getGCBMtransitions
355 std::vector<Core::FMTGCBMTransition> getGCBMtransitions(FMTLayer<std::string>& stackedactions, const std::vector<Core::FMTAction>& modelactions, const std::vector<Core::FMTTheme>& classifiers, const int& period) const;
356 // DocString: FMTSpatialSchedule::getPredictors
367 std::vector<std::vector<Graph::FMTPredictor>> getPredictors(FMTLayer<int>& predictorids, const Models::FMTModel& model, const std::vector<std::string>& yieldnames, const int& period,bool periodonevalues = false,bool withGCBMid = true) const;
368
369 // DocString: FMTSpatialSchedule::eraseLastPeriod
374 // DocString: FMTSpatialSchedule::getBindingActions
381 std::vector<Spatial::FMTBindingSpatialAction> getBindingActions(const Models::FMTModel& model, const int& period) const;
382 // DocString: FMTSpatialSchedule::getBindingActionsByPeriod
389 // DocString: FMTSpatialSchedule::referenceBuild
401 std::map<std::string, double> referenceBuild(const Core::FMTSchedule& schedule, const Models::FMTModel& model,
402 const std::vector<boost::unordered_set<Core::FMTDevelopment>>& scheduleoperabilities,
403 std::default_random_engine& p_randomEngine,
404 bool schedule_only = true,
405 bool scheduleatfirstpass = true);
406 // DocString: FMTSpatialSchedule::greedyReferenceBuild
417 std::map<std::string, double> greedyReferenceBuild(const Core::FMTSchedule& schedule, const FMTSpatialGraphs& p_Graphs,
418 const size_t& randomiterations,
419 unsigned int seed = 0,
420 double tolerance = FMT_DBL_TOLERANCE,
421 bool log = true);
422 // DocString: FMTSpatialSchedule::randomBuild
429 Graph::FMTGraphStats randomBuild(const Models::FMTModel& model, std::default_random_engine& generator);
430 // DocString: FMTSpatialSchedule::setGrow
436 void setGrow(const std::vector<FMTCoordinate>& p_coordinates,
437 const Models::FMTModel& p_model);
438 // DocString: FMTSpatialSchedule::perturbGraph
447 void perturbGraph(const FMTCoordinate& coordinate,const int& period,
448 const Models::FMTModel& model, std::default_random_engine& generator,
449 const actionbindings& bindings);
450 // DocString: FMTSpatialSchedule::isBetterByGroup
457 bool isBetterByGroup(const FMTSpatialSchedule& rhs, const FMTSpatialGraphs& p_Graphs) const;
458 // DocString: FMTSpatialSchedule::swap
464 // DocString: FMTSpatialSchedule::getMovableCoordinates
471 std::vector<Spatial::FMTCoordinate>getMovableCoordinates(const Models::FMTModel& model,const int& period) const;
472
473 // DocString: FMTSpatialSchedule::getPeriodWithMaximalEvents
479 int getPeriodWithMaximalEvents(const std::vector<bool>& actions) const;
480 // DocString: FMTSpatialSchedule::getAreaConflictCoordinates
488 std::vector<std::vector<Spatial::FMTCoordinate>>getAreaConflictCoordinates(const actionbindings& bindingactions,const int& period,bool conflictonly=true) const;
489 // DocString: FMTSpatialSchedule::getAdjacencyConflictCoordinates
497 std::vector<std::vector<Spatial::FMTCoordinate>>getAdjacencyConflictCoordinates(const actionbindings& bindingactions,const int& period, bool conflictonly = true) const;
498 // DocString: FMTSpatialSchedule::isPartial
503 bool isPartial() const;
504 // DocString: FMTSpatialSchedule::emptyEvents
509 bool emptyEvents() const;
510 // DocString: FMTSpatialSchedule::copyFromPartial
516 // DocString: FMTSpatialSchedule::copyFromPartial
522 // DocString: FMTSpatialSchedule::setConstraintsFactor
528 void setConstraintsFactor(const Models::FMTModel& model,const std::vector<double>&factors);
529 // DocString: FMTSpatialSchedule::needsRefactorization
535 bool needsRefactorization(const FMTSpatialGraphs& p_Graphs) const;
536 // DocString: FMTSpatialSchedule::getConstraintsFactor
541 const std::vector<double>& getConstraintsFactor() const;
542 // DocString: FMTSpatialSchedule::getOutput
552 std::map<std::string,double> getOutput(const FMTSpatialGraphs& p_Graphs, const Core::FMTOutput& p_output,
553 int p_period,Core::FMToutputlevel level = Core::FMToutputlevel::totalonly) const;
554 // DocString: FMTSpatialSchedule::getSpatialOutput
563 const Core::FMTOutput& output,const int& period) const;
564 // DocString: FMTSpatialSchedule::getOutputByCoordinate
572 std::vector<std::pair<FMTCoordinate, double>>getOutputByCoordinate(const Models::FMTModel & model,
573 const Core::FMTOutput& output, const int& period) const;
574 // DocString: FMTSpatialSchedule::postSolve
581 void postSolve(const Core::FMTMaskFilter& p_Filter,
582 const std::vector<Core::FMTAction>& p_PresolveActions,
583 Spatial::FMTSpatialGraphs& p_Graphs);
584 // DocString: FMTSpatialSchedule::preSolve
593 FMTSpatialGraphs& p_Graphs,size_t p_ReserveSize) const;
594 // DocString: FMTSpatialSchedule::getArea
601 std::vector<Core::FMTActualDevelopment>getArea(int period = 0, bool beforegrowanddeath = false) const;
602
603 // DocString: FMTSpatialSchedule::getBaseSchedule
610 // DocString: FMTSpatialSchedule::setSpatialGraphs
616 void setSpatialGraphs(const Spatial::FMTSpatialSchedule& p_ToCopy, FMTSpatialGraphs& p_SpatialGraph);
617 // DocString: FMTSpatialSchedule::getGroupsConflict
624 std::vector<FMTCoordinate> getGroupsConflict(const Core::FMTConstraint& p_SpatialConstraint,
625 const FMTSpatialGraphs& p_SpatialGraph) const;
626 // DocString: FMTSpatialSchedule::EventSpread
631 {
632 EventSpread(FMTLayer::const_iterator p_InIt,
633 FMTLayer::iterator p_OutIt, FMTEventContainer::iterator p_Event):
634 m_InEvent(p_InIt), m_OutEvent(p_OutIt), m_Event(p_Event){}
635 FMTLayer::const_iterator m_InEvent;
636 FMTLayer::iterator m_OutEvent;
638 };
639 // DocString: FMTSpatialSchedule::getPotentialSpread
645 std::vector<EventSpread>getPotentialSpread(int p_period);
646 // DocString: FMTSpatialSchedule::canDoEventSpread
652 bool canDoEventSpread(int p_period) const;
653 // DocString: FMTSpatialSchedule::setSpread
660 std::vector<EventSpread>::const_iterator p_first,
661 std::vector<EventSpread>::const_iterator p_end);
662 // DocString: FMTSpatialSchedule::setStaticsMovableCoordinates
668 // DocString: FMTSpatialSchedule::enableSolutionTracker
673 void enableSolutionTracker(const FMTSpatialGraphs& p_SpatialGraph);
674 // DocString: FMTSpatialSchedule::disableSolutionTracker
679 protected:
680 // DocString: FMTSpatialSchedule::_getFromEvents(const Core::FMTConstraint&, const std::vector<Core::FMTAction>&, const int&, const int&)
689 std::vector<const Graph::FMTLineGraph*>_getFromEvents(const Core::FMTConstraint& constraint, const std::vector<Core::FMTAction>& actions, const int& start, const int& stop) const;
690 // DocString: FMTSpatialSchedule::_getFromEvents(const Core::FMTOutputNode&, const std::vector<Core::FMTAction>&, const int&)
698 std::vector<FMTCoordinate>_getFromEvents(const Core::FMTOutputNode& node, const std::vector<Core::FMTAction>& actions, const int& period) const;
699 // DocString: FMTSpatialSchedule::_getOutputFromGraph
713 std::map<std::string,double> _getOutputFromGraph(const Graph::FMTLineGraph& linegraph, const Models::FMTModel & model,
714 const Core::FMTOutputNode& node, const double* solution,const int&period, const Core::FMTMask& nodemask,
715 boost::unordered_map<Core::FMTMask, double>& nodecache, const Core::FMTTheme* p_theme,Core::FMToutputlevel level = Core::FMToutputlevel::totalonly) const;
716 // DocString: FMTSpatialSchedule::getMaximalPatchSizes
720 //std::vector<size_t>getMaximalPatchSizes(const std::vector<FMTspatialaction>& spactions) const;
721 // DocString: FMTSpatialSchedule::_inScheduleOperabilities
730 bool _inScheduleOperabilities(const std::vector<boost::unordered_set<Core::FMTDevelopment>>& scheduleoperabilities,
731 Core::FMTDevelopment const* dev,const int& actionid, const Core::FMTAction& action) const;
732 private:
733 // DocString: FMTSpatialSchedule::m_scheduleType
734 //Schedule type complete or partial
735 FMTSpatialScheduletype m_scheduleType = FMTSpatialScheduletype::FMTcomplete;
736 // DocString: FMTSpatialSchedule::m_ConstraintsFactor
737 //Constraints factors.
738 std::vector<double>m_ConstraintsFactor;
739 // DocString: FMTSpatialSchedule::m_events
740 //Events of the schedule
741 FMTEventContainer m_events;
742 // DocString: FMTSpatialSchedule::m_Tracker
743 // Non spatial solution tracker
744 FMTSolutionTracker m_Tracker;
745 // DocString: FMTSpatialSchedule::m_OperabilityCache
746 //Operability cache
747 static boost::unordered_map<Core::FMTDevelopment,
748 std::vector<int>>m_OperabilityCache;
749 // DocString: FMTSpatialSchedule::m_Movables
750 //Coordinates where you can actualy operate something.
751 static std::vector<Spatial::FMTCoordinate>m_Movables;
752 // DocString: FMTSpatialSchedule::m_BUFFER_LOOKUP
753 //buffer lookup for events
754 static const int m_BUFFER_LOOKUP = 1;
755
756 // DocString: FMTSpatialSchedule::_evaluateSpatialAdjacency
767 double _evaluateSpatialAdjacency(
768 int p_period,
769 int p_greenup,
770 int p_lowerLookup,
771 int p_upperLookup,
772 bool p_testLower,
773 const std::vector<bool>& p_actions) const;
774
775 // DocString: FMTSpatialSchedule::_evaluateSpatialGroups
788 double _evaluateSpatialGroups(
789 const FMTSpatialGraphs& p_SpatialGraph,
790 int p_period,
791 int p_greenup,
792 int p_lowerLookup,
793 int p_upperLookup,
794 int p_theme,
795 bool p_testLower,
796 const std::vector<bool>& p_actions) const;
797
798 // DocString: FMTSpatialSchedule::_getSpatialGroupsConflict
811 std::vector<FMTEventContainer::const_iterator> _getSpatialGroupsConflict(
812 const FMTSpatialGraphs& p_SpatialGraph,
813 int p_period,
814 int p_greenup,
815 int p_lowerLookup,
816 int p_upperLookup,
817 int p_theme,
818 bool p_testLower,
819 const std::vector<bool>& p_actions) const;
820
821 // DocString: FMTSpatialSchedule::_getAdjacencyConflict
832 std::vector<FMTEventContainer::const_iterator> _getAdjacencyConflict(
833 int p_period,
834 int p_greenup,
835 int p_lowerLookup,
836 int p_upperLookup,
837 bool p_testLower,
838 const std::vector<bool>& p_actions) const;
839
840
841 // DocString: FMTSpatialSchedule::_getNonSpatialCellsCount
846 size_t _getNonSpatialCellsCount() const;
847
848 // DocString: FMTSpatialSchedule::_getExponentialFactorization
855 static double _getExponentialFactorization(double p_value, double p_factor);
856
857 // DocString: FMTSpatialSchedule::_getConstraintFloorValue
863 double _getConstraintFloorValue(double p_inValue) const;
864
865 // DocString: FMTSpatialSchedule::_getRulesEvaluation
872 double _getRulesEvaluation(const std::vector<FMTPatchRules>& p_rules,
873 const FMTSpatialGraphs& p_SpatialGraph) const;
874
875 // DocString: FMTSpatialSchedule::_putTabouInCache
882 static std::vector<std::pair<Core::FMTDevelopment, std::vector<int>>> _putTabouInCache(
883 const Models::FMTModel& p_model,
884 std::map<Core::FMTDevelopment, std::vector<bool>>& p_tabou);
885 // DocString: FMTSpatialSchedule::_setTabouOutOfCache
890 static void _setTabouOutOfCache(
891 std::vector<std::pair<Core::FMTDevelopment, std::vector<int>>>& p_GoodValues);
892
893
894
895
896
897
898
899
900};
901}
902
903
904#endif // FMTSpatialSchedule_H
#define FMT_DBL_TOLERANCE
Definition: FMTutility.h:11
#define FMTEXPORT
Definition: FMTutility.h:125
List of specifications dictating the operability of a subset of developments to this action.
Definition: FMTAction.h:43
Representation of a line in the optimize section, an objective being considered a constraint.
Definition: FMTConstraint.h:52
Base class of FMTActualDevelopment and FMTFuturDevelopment representing a forest stand.
Definition: FMTDevelopment.h:44
Filter built from masks used to preSolve and postsolve FMTMask objects.
Definition: FMTMaskFilter.h:31
Core class holding, as a boost dynamic bitset, which theme attributes are part of a mask.
Definition: FMTMask.h:96
Node of an output representing a set of developments in the graph, holding a source,...
Definition: FMTOutputNode.h:25
Class letting the user formulate a constraint in the optimize section or collect data across the grap...
Definition: FMTOutput.h:37
Spatially referenced schedule describing the area of developments for which an action can be operated...
Definition: FMTSchedule.h:29
Class holding the attributes and aggregates of a single theme, describing a part of a FMTMask.
Definition: FMTTheme.h:47
List of FMTFork describing the transition of an action, disturbing a development to generate new deve...
Definition: FMTTransition.h:35
FMTList containing multiple yield handlers as seen in the yield section, holding the information rela...
Definition: FMTYields.h:44
Statistics about a FMTGraph and its FMTLpSolver: their size, elements and type of elements.
Definition: FMTGraphStats.h:28
Simple graph where each action generates a single new vertex (0-—0-—0-—0), used with FMTLayer to simu...
Definition: FMTLineGraph.h:27
Base class for the different models in FMT.
Definition: FMTModel.h:62
Spatial binding of an action, holding the green up, adjacency, size and neighbors constraints used to...
Definition: FMTBindingSpatialAction.h:23
Spatially referenced coordinate holding an x and y position on a raster grid.
Definition: FMTCoordinate.h:29
Container of FMTEvent handling event comparison and distance calculation efficiently,...
Definition: FMTEventContainer.h:32
std::set< FMTEvent >::iterator iterator
Definition: FMTEventContainer.h:35
Spatially referenced layer of Core::FMTDevelopment representing the forest.
Definition: FMTForest.h:33
Definition: FMTParser.h:54
Track the constraint values of a spatial solution as line graphs are added to or removed from the sol...
Definition: FMTSolutionTracker.h:36
Container of the line graphs of a spatially explicit model, organized by constraint family,...
Definition: FMTSpatialGraphs.h:52
Map containing a line graph for each cell, representing the stand, the action and the transition at e...
Definition: FMTSpatialSchedule.h:50
FMTSpatialSchedule()=default
Default constructor for FMTSpatialSchedule.
std::map< std::string, double > greedyReferenceBuild(const Core::FMTSchedule &schedule, const FMTSpatialGraphs &p_Graphs, const size_t &randomiterations, unsigned int seed=0, double tolerance=FMT_DBL_TOLERANCE, bool log=true)
Call the simulate function multiple times to find the best possible spatialization for a schedule usi...
double getGlobalObjective(const FMTSpatialGraphs &p_Graphs) const
Return the global objective, mixing the objective and the infeasibility, where a lower value is a bet...
Graph::FMTGraphStats randomBuild(const Models::FMTModel &model, std::default_random_engine &generator)
Randomly create a solution for one period using a generator.
FMTSpatialSchedule(const FMTSpatialSchedule &other, const std::vector< FMTCoordinate >::const_iterator &firstcoord, const std::vector< FMTCoordinate >::const_iterator &endcoord)
Create a partial copy of the complete solution based on coordinates.
FMTSpatialSchedule & operator=(const FMTSpatialSchedule &rhs)=default
Copy assignment operator for FMTSpatialSchedule.
double operateEvents(const FMTEventContainer &cuts, const Core::FMTAction &action, const int &action_id, const Core::FMTTransition &Transition, const Core::FMTYields &ylds, const std::vector< Core::FMTTheme > &themes)
Operate a container of events for an action and return the operated area.
void setSpatialGraphs(const Spatial::FMTSpatialSchedule &p_ToCopy, FMTSpatialGraphs &p_SpatialGraph)
Set the spatial graphs from another schedule.
std::vector< Core::FMTActualDevelopment > getArea(int period=0, bool beforegrowanddeath=false) const
Get the area of a period based on the solution.
std::vector< Spatial::FMTBindingSpatialAction > getBindingActions(const Models::FMTModel &model, const int &period) const
Get the binding actions based on the model constraints for a period.
std::map< std::string, double > _getOutputFromGraph(const Graph::FMTLineGraph &linegraph, const Models::FMTModel &model, const Core::FMTOutputNode &node, const double *solution, const int &period, const Core::FMTMask &nodemask, boost::unordered_map< Core::FMTMask, double > &nodecache, const Core::FMTTheme *p_theme, Core::FMToutputlevel level=Core::FMToutputlevel::totalonly) const
Get the requested output from a line graph into the period values.
FMTLayer< double > getSpatialOutput(const Models::FMTModel &model, const Core::FMTOutput &output, const int &period) const
Get the output value for the whole layer for a period and an output.
void disableSolutionTracker()
Disable the non spatial solution tracker.
std::set< FMTCoordinate > verifySpatialFeasibility(const int &targetaction, const std::vector< Spatial::FMTBindingSpatialAction > &bindingactions, const int &period, const std::set< FMTCoordinate > &operables) const
Return the evaluation value of a distance spatial constraint.
std::map< std::string, double > referenceBuild(const Core::FMTSchedule &schedule, const Models::FMTModel &model, const std::vector< boost::unordered_set< Core::FMTDevelopment > > &scheduleoperabilities, std::default_random_engine &p_randomEngine, bool schedule_only=true, bool scheduleatfirstpass=true)
Simulate a schedule of actions on the actual spatially explicit forest.
FMTSpatialSchedule preSolve(const Core::FMTMaskFilter &p_filter, FMTSpatialGraphs &p_Graphs, size_t p_ReserveSize) const
Return a presolved solution of the original solution.
FMTSpatialSchedule(const FMTSpatialSchedule &other)=default
Copy constructor for FMTSpatialSchedule.
FMTLayer< std::string > lastDistLayer(const std::vector< Core::FMTAction > &modelactions, const int &period) const
Return a layer with the sum of all the graph outputs related to a constraint for a period.
double getConstraintEvaluation(const FMTSpatialGraphs &p_Graphs, size_t p_ConstraintId) const
Return the evaluated value of a solution constraint.
void setConstraintsFactor(const Models::FMTModel &model, const std::vector< double > &factors)
Set the constraint factors for normalization.
FMTEventContainer buildHarvest(const double &target, const Spatial::FMTBindingSpatialAction &targetaction, std::default_random_engine &generator, std::set< FMTCoordinate > mapping_pass, const int &previousperiod, const int &actionid, std::vector< FMTCoordinate > &operated) const
Build a container of harvest events for a target action until the area target is reached.
std::vector< double > getWeightedFactors(const Spatial::FMTSpatialGraphs &p_Graphs) const
Generate the constraint factors based on the actual solution.
void setStaticsMovableCoordinates(const Models::FMTModel &p_model)
Set the static movable coordinates from a model.
bool allowAction(const int &targetaction, const std::vector< Spatial::FMTBindingSpatialAction > &bindingactions, const FMTCoordinate &location, const int &period) const
Check the events around a location during the green up delay periods to see if a neighboring action i...
double getPrimalInfeasibility(const std::vector< const Core::FMTConstraint * > &constraints, const Spatial::FMTSpatialGraphs &p_Graphs, bool withfactorization=false) const
Return the primal infeasibility of a set of constraints.
std::map< std::string, double > getOutput(const FMTSpatialGraphs &p_Graphs, const Core::FMTOutput &p_output, int p_period, Core::FMToutputlevel level=Core::FMToutputlevel::totalonly) const
Get the output value for a period using the solution.
std::vector< int > isBetterThan(const FMTSpatialSchedule &newsolution, const Spatial::FMTSpatialGraphs &p_Graphs) const
Compare two spatial schedules and return, for each constraint group, true if this solution has a bett...
bool empty() const
Test whether the map is empty.
Definition: FMTSpatialSchedule.h:116
std::vector< std::pair< FMTCoordinate, double > > getOutputByCoordinate(const Models::FMTModel &model, const Core::FMTOutput &output, const int &period) const
Return the output value by coordinate for an output, a model and a period.
std::vector< EventSpread > getPotentialSpread(int p_period)
Return the potential event spreads for a period.
double evaluateSpatialConstraint(const Core::FMTConstraint &p_SpatialConstraint, const FMTSpatialGraphs &p_SpatialGraph) const
Return the evaluation value of a spatial constraint.
double getObjectiveValue(const FMTSpatialGraphs &p_Graphs, bool withsense=true) const
Return the objective value of the spatial schedule.
void enableSolutionTracker(const FMTSpatialGraphs &p_SpatialGraph)
Enable the non spatial solution tracker using the spatial graphs.
bool needsRefactorization(const FMTSpatialGraphs &p_Graphs) const
Return true if the solution looks unscaled and needs new factors.
void perturbGraph(const FMTCoordinate &coordinate, const int &period, const Models::FMTModel &model, std::default_random_engine &generator, const actionbindings &bindings)
Change one graph in the solution, removing its contribution to the objective and adding the contribut...
int actPeriod() const
Return the last period in the graph, which is the active one.
void swap(FMTSpatialSchedule &rhs)
Swap this FMTSpatialSchedule with another one.
std::vector< std::vector< Spatial::FMTCoordinate > > getAdjacencyConflictCoordinates(const actionbindings &bindingactions, const int &period, bool conflictonly=true) const
Return the adjacency conflict coordinates that need to be destroyed.
bool isPartial() const
Return true if the solution is partial.
std::vector< const Graph::FMTLineGraph * > _getFromEvents(const Core::FMTConstraint &constraint, const std::vector< Core::FMTAction > &actions, const int &start, const int &stop) const
Return the line graphs of the events for a constraint, actions and a period range.
std::vector< FMTCoordinate > _getFromEvents(const Core::FMTOutputNode &node, const std::vector< Core::FMTAction > &actions, const int &period) const
Return the coordinates present in the events for an output node, actions and a period.
bool isBetterByGroup(const FMTSpatialSchedule &rhs, const FMTSpatialGraphs &p_Graphs) const
Compare this solution to another one by constraint group.
FMTSpatialSchedule getBaseSchedule(const FMTSpatialGraphs &p_SpatialGraph) const
Return the base schedule of the spatial graphs.
std::vector< FMTCoordinate > getGroupsConflict(const Core::FMTConstraint &p_SpatialConstraint, const FMTSpatialGraphs &p_SpatialGraph) const
Return the coordinates in conflict with a group spatial constraint.
std::vector< Core::FMTSchedule > getSchedules(const FMTSpatialGraphs p_Graphs, bool withlock=false) const
Set a new period in the schedule.
std::vector< std::vector< Spatial::FMTBindingSpatialAction > > actionbindings
Definition: FMTSpatialSchedule.h:52
void logSolutionStatus(const size_t &iteration, const double &objective, const double &primalinfeasibility) const
Log the status of the solution.
std::vector< std::set< Spatial::FMTCoordinate > > getUpdatedScheduling(const Models::FMTModel &model, const std::vector< int > &actiontargets, boost::unordered_map< Core::FMTDevelopment, std::vector< bool > > &cachedaction, const std::vector< boost::unordered_set< Core::FMTDevelopment > > &scheduleoperabilities, bool schedule_only=true, std::vector< std::set< Spatial::FMTCoordinate > > original=std::vector< std::set< Spatial::FMTCoordinate > >(), std::vector< FMTCoordinate > updatedcoordinate=std::vector< FMTCoordinate >()) const
Return, for all actions, the coordinates with operable developments at the end of the graph.
int getPeriodWithMaximalEvents(const std::vector< bool > &actions) const
Return the period with the maximal number of events for a set of actions.
std::vector< double > getConstraintsValues(const Spatial::FMTSpatialGraphs &p_Graphs) const
Return the values of each constraint, used for normalization.
bool canDoEventSpread(int p_period) const
Return true if an event spread can be done for a period.
std::vector< std::vector< Spatial::FMTCoordinate > > getAreaConflictCoordinates(const actionbindings &bindingactions, const int &period, bool conflictonly=true) const
Return the coordinates of the events that do not have the right area in the worst period.
std::vector< std::vector< Graph::FMTPredictor > > getPredictors(FMTLayer< int > &predictorids, const Models::FMTModel &model, const std::vector< std::string > &yieldnames, const int &period, bool periodonevalues=false, bool withGCBMid=true) const
Get the predictors for the whole solution and write the predictor ids into a layer.
void postSolve(const Core::FMTMaskFilter &p_Filter, const std::vector< Core::FMTAction > &p_PresolveActions, Spatial::FMTSpatialGraphs &p_Graphs)
Postsolve the spatial solution.
void copyFromPartial(FMTSpatialSchedule &rhs)
Copy the elements from a partial solution, also allowing a swap.
bool _inScheduleOperabilities(const std::vector< boost::unordered_set< Core::FMTDevelopment > > &scheduleoperabilities, Core::FMTDevelopment const *dev, const int &actionid, const Core::FMTAction &action) const
Return the maximal patch size of a vector of spatial actions.
void operateCoord(const FMTCoordinate &coord, const Core::FMTAction &action, const int &action_id, const FMTBindingSpatialAction &bindingspaction, const Core::FMTTransition &Transition, const Core::FMTYields &ylds, const std::vector< Core::FMTTheme > &themes)
Operate a coordinate and add it to the events.
void copyFromPartial(const FMTSpatialSchedule &rhs)
Copy the elements from a partial solution.
std::string getPatchStats(const std::vector< Core::FMTAction > &actions) const
Return the patch statistics (area, perimeter) of the events for a set of actions.
void grow()
Grow every graph of the schedule by one period.
FMTSpatialSchedule(const FMTForest &p_InitialMap, size_t p_LengthReserve, FMTSpatialGraphs &p_SpatialGraph)
Construct a FMTSpatialSchedule from a forest, initializing every graph in the map based on the develo...
void setGrow(const std::vector< FMTCoordinate > &p_coordinates, const Models::FMTModel &p_model)
Set natural growth on coordinates, removing every action.
actionbindings getBindingActionsByPeriod(const Models::FMTModel &model) const
Get the binding actions based on the model constraints in a vector by period.
bool emptyEvents() const
Return true if there are no events.
virtual ~FMTSpatialSchedule()=default
Default destructor for FMTSpatialSchedule.
std::vector< Spatial::FMTCoordinate > getMovableCoordinates(const Models::FMTModel &model, const int &period) const
Return the coordinates where something can be operated for a period.
FMTForest getForestPeriod(const int &period, bool periodStart=false) const
Return the forest corresponding to a period.
void getSolutionStatus(double &objective, double &primalinfeasibility, const FMTSpatialGraphs &p_Graphs, bool withsense=true, bool withfactorization=false, bool withspatial=true) const
Get the objective value and the primal infeasibility of the solution.
void eraseLastPeriod()
Erase the last period of the FMTSpatialSchedule.
std::vector< Core::FMTGCBMTransition > getGCBMtransitions(FMTLayer< std::string > &stackedactions, const std::vector< Core::FMTAction > &modelactions, const std::vector< Core::FMTTheme > &classifiers, const int &period) const
Return the GCBM transitions of the solution and fill a layer with the stacked actions.
void setSpread(std::vector< EventSpread >::const_iterator p_first, std::vector< EventSpread >::const_iterator p_end)
Apply a range of event spreads to the solution.
const std::vector< double > & getConstraintsFactor() const
Get the constraint factors for normalization.
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
FMToutputlevel
Enumerator describing the level of detail of an output (standard, total only, development).
Definition: FMTutility.h:22
@ totalonly
Definition: FMTutility.h:24
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTAreaParser.h:54
Definition: FMTAreaParser.h:40
FMTSpatialScheduletype
Definition: FMTSpatialSchedule.h:39
@ FMTcomplete
Definition: FMTSpatialSchedule.h:40
@ FMTpartial
Definition: FMTSpatialSchedule.h:41
Helper holding the input iterator, output iterator and event of an event spread move.
Definition: FMTSpatialSchedule.h:631
FMTEventContainer::iterator m_Event
Definition: FMTSpatialSchedule.h:637
FMTLayer::const_iterator m_InEvent
Definition: FMTSpatialSchedule.h:635
FMTLayer::iterator m_OutEvent
Definition: FMTSpatialSchedule.h:636
EventSpread(FMTLayer::const_iterator p_InIt, FMTLayer::iterator p_OutIt, FMTEventContainer::iterator p_Event)
Definition: FMTSpatialSchedule.h:632