7#ifndef FMTSpatialSchedule_H
8#define FMTSpatialSchedule_H
10#include "FMTLayer.hpp"
18 class FMTGCBMTransition;
36class FMTSpatialGraphs;
52 typedef std::vector<std::vector<Spatial::FMTBindingSpatialAction>>
actionbindings;
94 const std::vector<FMTCoordinate>::const_iterator& firstcoord,
95 const std::vector<FMTCoordinate>::const_iterator& endcoord);
116 bool empty()
const {
return m_mapping.empty();};
141 bool allowAction(
const int& targetaction,
const std::vector<Spatial::FMTBindingSpatialAction>&bindingactions,
const FMTCoordinate& location,
const int& period)
const;
156 const std::vector<int>& actiontargets,
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;
192 const std::vector<Spatial::FMTBindingSpatialAction>& bindingactions,
193 const int& period,
const std::set<FMTCoordinate>& operables)
const;
207 const int& previousperiod,
const int& actionid, std::vector<FMTCoordinate>& operated)
const;
220 const Core::FMTYields& ylds,
const std::vector<Core::FMTTheme>& themes);
233 const Core::FMTYields& ylds,
const std::vector<Core::FMTTheme>& themes);
300 void logSolutionStatus(
const size_t& iteration,
const double& objective,
const double& primalinfeasibility)
const;
313 bool withsense =
true,
bool withfactorization =
false,
bool withspatial =
true)
const;
337 std::string
getPatchStats(
const std::vector<Core::FMTAction>& actions)
const;
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;
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;
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);
418 const size_t& randomiterations,
419 unsigned int seed = 0,
436 void setGrow(
const std::vector<FMTCoordinate>& p_coordinates,
582 const std::vector<Core::FMTAction>& p_PresolveActions,
601 std::vector<Core::FMTActualDevelopment>
getArea(
int period = 0,
bool beforegrowanddeath =
false)
const;
634 m_InEvent(p_InIt), m_OutEvent(p_OutIt), m_Event(p_Event){}
660 std::vector<EventSpread>::const_iterator p_first,
661 std::vector<EventSpread>::const_iterator p_end);
689 std::vector<const Graph::FMTLineGraph*>
_getFromEvents(
const Core::FMTConstraint& constraint,
const std::vector<Core::FMTAction>& actions,
const int& start,
const int& stop)
const;
738 std::vector<double>m_ConstraintsFactor;
748 std::vector<int>>m_OperabilityCache;
751 static std::vector<Spatial::FMTCoordinate>m_Movables;
754 static const int m_BUFFER_LOOKUP = 1;
767 double _evaluateSpatialAdjacency(
773 const std::vector<bool>& p_actions)
const;
788 double _evaluateSpatialGroups(
796 const std::vector<bool>& p_actions)
const;
811 std::vector<FMTEventContainer::const_iterator> _getSpatialGroupsConflict(
819 const std::vector<bool>& p_actions)
const;
832 std::vector<FMTEventContainer::const_iterator> _getAdjacencyConflict(
838 const std::vector<bool>& p_actions)
const;
846 size_t _getNonSpatialCellsCount()
const;
855 static double _getExponentialFactorization(
double p_value,
double p_factor);
863 double _getConstraintFloorValue(
double p_inValue)
const;
872 double _getRulesEvaluation(
const std::vector<FMTPatchRules>& p_rules,
882 static std::vector<std::pair<Core::FMTDevelopment, std::vector<int>>> _putTabouInCache(
890 static void _setTabouOutOfCache(
#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