FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
PYexportSpatial.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 PYEXPORTSPATIAL_H_INCLUDED
9#define PYEXPORTSPATIAL_H_INCLUDED
10
11#include "FMTCoordinate.h"
12#include "FMTForest.h"
13#include "FMTSpatialSchedule.h"
14//#include "FMTspatialaction.h"
15#include "FMTEventContainer.h"
16//#include "FMTSaSchedule.h"
17#include "FMTGraph.hpp"
18//#include "FMTSaSolution.h"
19#include "boost/python.hpp"
20
21namespace Python
22{
23BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getforestperiod_overloads, getForestPeriod, 1, 2)
24BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getconstraintevaluation_overloads,getConstraintEvaluation,2,2)
25BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getobjectivevalue_overloads,getObjectiveValue,2,2)
27 {
28 namespace bp = boost::python;
29 bp::object SpatialModule(bp::handle<>(bp::borrowed(PyImport_AddModule("FMT.Spatial"))));
30 bp::scope().attr("Spatial") = SpatialModule;
31 bp::scope Spatial_scope = SpatialModule;
32 bp::scope().attr("__doc__") = ".. module:: Spatial\n"
33 "\n"
34 " :platform: Unix, Windows\n"
35 " :synopsis: Spatial module used for Simulation.\n"
36 "\n";
37
38 bp::class_<Spatial::FMTCoordinate>("FMTcoordinate", "@DocString(FMTCoordinate)")
39 .def(bp::init<unsigned int,unsigned int>())
40 .def("__lt__",&Spatial::FMTCoordinate::operator <,
41 "@DocString(FMTCoordinate::operator<)")
43 "@DocString(FMTCoordinate::getx)")
45 "@DocString(FMTCoordinate::gety)")
46 .def("getSpatialCoordinate",&Spatial::FMTCoordinate::getSpatialCoordinate,
47 "@DocString(FMTCoordinate::getSpatialCoordinate)")
48 .setattr("__hash__",&boost::pyHash<Spatial::FMTCoordinate>);
49
50 define_FMTlayer<Core::FMTDevelopment>();
51 //Mainly to iter over FMTForest
52 definePyPair<Spatial::FMTCoordinate,Core::FMTDevelopment>();
53 definePyPair<Spatial::FMTCoordinate const,Core::FMTDevelopment>();
54 definePyPair<Spatial::FMTCoordinate,Graph::FMTLineGraph>();
55 definePyPair<Spatial::FMTCoordinate const,Graph::FMTLineGraph>();
56
57
58
59 bp::class_<Spatial::FMTForest, bp::bases<Spatial::FMTLayer<Core::FMTDevelopment>>>("FMTforest", "@DocString(FMTForest)")
60 .def(bp::init<Spatial::FMTForest>())
61 .def("getarea",&Spatial::FMTForest::getArea,
62 "@DocString(FMTForest::getarea)")
63 .def("grow",&Spatial::FMTForest::grow,
64 "@DocString(FMTForest::grow)")
65 .def("getage",&Spatial::FMTForest::getAge,
66 "@DocString(FMTForest::getage)")
67 .def("setperiod",&Spatial::FMTForest::setPeriod,
68 "@DocString(FMTForest::setperiod)");
69
70
71 definePyList<Spatial::FMTForest>();
72
73 bp::class_<Spatial::FMTEventContainer>("FMTeventcontainer", "@DocString(FMTEventContainer)")
74 .def(bp::init<Spatial::FMTEventContainer>());
75
76 definePyList<Spatial::FMTEventContainer>();
77
78 /*
79 bp::class_<Spatial::FMTspatialaction, bp::bases<Core::FMTAction>>("FMTspatialaction", "@DocString(FMTspatialaction)")
80 .def(bp::init<Core::FMTAction>())
81 .add_property("neighbors", bp::make_getter(&Spatial::FMTspatialaction::neighbors, bp::return_value_policy<bp::return_by_value>()),
82 make_setter(&Spatial::FMTspatialaction::neighbors, bp::return_value_policy<bp::return_by_value>()))
83 .def_readwrite("green_up",&Spatial::FMTspatialaction::green_up,
84 "@DocString(FMTspatialaction::green_up)")
85 .def_readwrite("adjacency",&Spatial::FMTspatialaction::adjacency,
86 "@DocString(FMTspatialaction::adjacency)")
87 .def_readwrite("minimal_size",&Spatial::FMTspatialaction::minimal_size,
88 "@DocString(FMTspatialaction::minimal_size)")
89 .def_readwrite("maximal_size",&Spatial::FMTspatialaction::maximal_size,
90 "@DocString(FMTspatialaction::maximal_size)")
91 .def_readwrite("neighbors_size",&Spatial::FMTspatialaction::neighbors_size,
92 "@DocString(FMTspatialaction::neighbors_size)")
93 .def_readwrite("greenup_weight",&Spatial::FMTspatialaction::greenup_weight,
94 "@DocString(FMTspatialaction::greenup_weight)")
95 .def_readwrite("adjacency_weight",&Spatial::FMTspatialaction::adjacency_weight,
96 "@DocString(FMTspatialaction::adjacency_weight)")
97 .def_readwrite("size_weight",&Spatial::FMTspatialaction::size_weight,
98 "@DocString(FMTspatialaction::size_weight)");
99 definePyList<Spatial::FMTspatialaction>();*/
100
101
102 //bp::class_<Spatial::FMTSaSchedule, boost::noncopyable>("Abstract_FMTsaschedule","@DocString(FMTSaSchedule)", bp::no_init);
103
104
105 //bp::class_<Spatial::FMTExponentialSchedule, bp::bases<Spatial::FMTSaSchedule>>("FMTexponentialschedule", "@DocString(FMTExponentialSchedule)")
106 // .def(bp::init<double>());
107
108 /*bp::enum_<Spatial::FMTsamovetype>("FMTsamovetype")
109 .value("shotgun", Spatial::FMTsamovetype::shotgun)
110 .value("cluster", Spatial::FMTsamovetype::cluster)
111 .value("opt1", Spatial::FMTsamovetype::opt1);
112
113 bp::class_<Spatial::FMTSaSolution, bp::bases<Spatial::FMTLayer<Graph::FMTLineGraph>>>("FMTsasolution", "@DocString(FMTSaSolution)")
114 .def("get_stats",&Spatial::FMTSaSolution::getsolution_stats, "@DocString(FMTSaSolution::getsolution_stats)")
115 .def("getobjfvalue",&Spatial::FMTSaSolution::getobjfvalue, "@DocString(FMTSaSolution::getobjfvalue)")
116 .def("get_forest_at_period",&Spatial::FMTSaSolution::getForestPeriod, "@DocString(FMTSaSolution::getForestPeriod)")
117 .def("get_graphs_outputs", &Spatial::FMTSaSolution::getgraphsoutputs);
118
119 definePyList<Spatial::FMTSaSolution>();
120 */
121
122 define_FMTlayer<Graph::FMTLineGraph>();
123
124 bp::class_<Spatial::FMTSpatialSchedule, bp::bases<Spatial::FMTLayer<Graph::FMTLineGraph>>>("FMTSpatialSchedule", "@DocString(FMTSpatialSchedule)")
125 .def(bp::init<Spatial::FMTSpatialSchedule>())
126 .def("getforestperiod", &Spatial::FMTSpatialSchedule::getForestPeriod, getforestperiod_overloads(bp::args("period","periodstart"),"@DocString(FMTSpatialSchedule::getforestperiod)"))
127 .def("getoutputbycoordinate", &Spatial::FMTSpatialSchedule::getOutputByCoordinate, "@DocString(FMTSpatialSchedule::getoutputbycoordinate)")
128 .def("getbindingactions", &Spatial::FMTSpatialSchedule::getBindingActions, "@DocString(FMTSpatialSchedule::getbindingactions)")
129 .def("operatecoord", &Spatial::FMTSpatialSchedule::operateCoord, "@DocString(FMTSpatialSchedule::operatecoord)")
130 .def("getconstraintevaluation", &Spatial::FMTSpatialSchedule::getConstraintEvaluation, getconstraintevaluation_overloads(bp::args("constraint","model"),"@DocString(FMTSpatialSchedule::getconstraintevaluation)"))
131 .def("grow", &Spatial::FMTSpatialSchedule::grow, "@DocString(FMTSpatialSchedule::grow)");
132 definePyList<Spatial::FMTSpatialSchedule>();
133
134 bp::class_<Spatial::FMTBindingSpatialAction>("FMTbindingspatialaction", "@DocString(FMTBindingSpatialAction)")
135 .def("getminimaladjacency", &Spatial::FMTBindingSpatialAction::getMinimalAdjacency,boost::python::return_value_policy<boost::python::copy_const_reference>(),"@DocString(FMTSpatialSchedule::getminimaladjacency)")
136 .def("getminimalsize",&Spatial::FMTBindingSpatialAction::getMinimalSize,boost::python::return_value_policy<boost::python::copy_const_reference>(),"@DocString(FMTSpatialSchedule::getminimalsize)")
137 .def("getmaximalsize",&Spatial::FMTBindingSpatialAction::getMaximalSize,boost::python::return_value_policy<boost::python::copy_const_reference>(), "@DocString(FMTSpatialSchedule::getmaximalsize)");
138
139 definePyList<Spatial::FMTBindingSpatialAction>();
140
141 }
142}
143
144#endif // PYEXPORTSPATIAL_H_INCLUDED
const size_t & getMinimalAdjacency() const
Return the minimal adjacency.
Definition: FMTBindingSpatialAction.h:123
const size_t & getMinimalSize() const
Return the minimal size.
Definition: FMTBindingSpatialAction.h:141
const size_t & getMaximalSize() const
Return the maximal size.
Definition: FMTBindingSpatialAction.h:150
const std::vector< double > getSpatialCoordinate(std::vector< double > geoTransform) const
Return the spatial coordinate using a geographic transform.
uint16_t getY() const
Return the y position of the coordinate.
uint16_t getX() const
Return the x position of the coordinate.
void setPeriod(int period)
Set the period of every development of the forest.
std::vector< Core::FMTActualDevelopment > getArea() const
Return the actual developments of the forest, aggregating the area of identical developments by cell ...
FMTLayer< int > getAge() const
Return a layer with the age of each development.
FMTForest grow() const
Grow every development of the forest by one period.
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.
double getConstraintEvaluation(const FMTSpatialGraphs &p_Graphs, size_t p_ConstraintId) const
Return the evaluated value of a solution constraint.
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.
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 grow()
Grow every graph of the schedule by one period.
FMTForest getForestPeriod(const int &period, bool periodStart=false) const
Return the forest corresponding to a period.
Definition: PYdefinitions.h:14
void exportSpatial()
Definition: PYexportSpatial.h:26