FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTlpmodel.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#ifdef FMTWITHOSI
9#ifndef FMTlpmodel_H_INCLUDED
10#define FMTlpmodel_H_INCLUDED
11
12#include "FMTsrmodel.hpp"
13#include <boost/serialization/export.hpp>
14#include <boost/serialization/split_member.hpp>
15#include <boost/serialization/unordered_map.hpp>
16#include <boost/serialization/vector.hpp>
17#include <limits>
18
19namespace Heuristics
20{
21 class FMToperatingareascheduler;
22 class FMToperatingareaclusterer;
23 class FMToperatingareacluster;
24 class FMToperatingareascheme;
25}
26
27namespace Models
28{
29// DocString: FMTmatrixelement
36 {
37 goalvariable=0,//period base
38 levelvariable=1,//general
40 constraint=3,//period base...
41 strictlypositive=4,//when an output have negative coef, be sure that the value of the output in the graph is strictly positive (like in woodstock)
42 nr_items=5
43 };
44
45// DocString: FMTlpmodel
57 {
58 // DocString: FMTlpmodel::serialize
62 friend class boost::serialization::access;
63 template<class Archive>
64 void save(Archive& ar, const unsigned int version) const
65 {
66 ar& boost::serialization::make_nvp("model", boost::serialization::base_object<FMTsrmodel>(*this));
67 ar& BOOST_SERIALIZATION_NVP(elements);
68 }
69 template<class Archive>
70 void load(Archive& ar, const unsigned int version)
71 {
72 ar& boost::serialization::make_nvp("model", boost::serialization::base_object<FMTsrmodel>(*this));
73 ar& BOOST_SERIALIZATION_NVP(elements);
74 }
75 // DocString: FMTlpmodel::elements
77 std::vector<std::unordered_map<std::string,
78 std::vector<std::vector<int>>>>elements;
79 // DocString: FMTlpmodel::getclusterer
85 const std::vector<Heuristics::FMToperatingareacluster>& initialcluster,
86 const Core::FMToutput& areaoutput,
87 const Core::FMToutput& statisticoutput,
88 const int& period,int minimalnumberofclusters = -1,int maximalnumberofclusters = -1) const;
89 // DocString: FMTlpmodel::getsetmatrixelement
95 int getsetmatrixelement(const Core::FMTconstraint& constraint,
96 const FMTmatrixelement& element_type, const std::map<int, double>& indexes,
97 int period = -1,
98 double lowerbound = std::numeric_limits<double>::min(),
99 double upperbound = std::numeric_limits<double>::max());
100 // DocString: FMTlpmodel::getgoals
104 bool getgoals(const std::vector<std::string>& goalsnames, std::map<int,double>& index,const double& sense) const;
105 // DocString: FMTlpmodel::getlevelfromlevelname
109 int getlevelfromlevelname(const std::string& variable_level, int period,
110 Core::FMTconstraint constraint = Core::FMTconstraint()) const;
111 // DocString: FMTlpmodel::getsetlevel
116 int getsetlevel(const Core::FMTconstraint& constraint,const std::string& variable_level,int period);
117 // DocString: FMTlpmodel::getmatrixelement
122 std::vector<std::vector<int>>getmatrixelement(const Core::FMTconstraint& constraint,int period) const;
123 // DocString: FMTlpmodel::locatelevels
127 void locatelevels(const std::vector<Core::FMToutputnode>& nodes,int period, std::map<int, double>& variables,const Core::FMTconstraint& constraint, double multiplier = 1);
128 // DocString: FMTlpmodel::locatenodes
134 std::vector<std::map<int, double>> locatenodes(const std::vector<Core::FMToutputnode>& nodes, int period, std::map<int, double>& variables,double multiplier = 1) const;
135 // DocString: FMTlpmodel::updatematrixelements
141 void updatematrixelements(std::vector<int>& matrixelements, const std::vector<int>& deletedelements) const;
142 // DocString: FMTlpmodel::updateconstraintsmapping
147 void updateconstraintsmapping(const std::vector<int>& Dvariables,const std::vector<int>& Dconstraints);
148 // DocString: FMTlpmodel::updateconstraintsmapping
155 bool updatematrixngraph(bool updategraph = true);
156 // DocString: FMTlpmodel::getamountofpaths
160 //size_t getamountofpaths(const Core::FMTdevelopment& dev, const int& actionid) const;
161 // DocString: FMTlpmodel::ismatrixelement
165 bool ismatrixelement(const Core::FMTconstraint& constraint,
166 const FMTmatrixelement& element_type, int period) const;
167 // DocString: FMTlpmodel::containsmatrixelements
171 bool containsmatrixelements(const Core::FMTconstraint& constraint,int period) const;
172 // DocString: FMTlpmodel::issamematrixelement
176 bool issamematrixelement(const int& matrixindex, const FMTmatrixelement& element_type,
177 const double& lowerb, const double& upperb, const std::map<int, double>& variables) const;
178
179 // DocString: FMTlpmodel::getobjectivebounds
183 std::vector<int>setobjectivebounds(bool dolower = true, bool doupper = true, double tolerance = FMT_DBL_TOLERANCE);
184 // DocString: FMTlpmodel::updatematrixnaming
188 void updatematrixnaming();
189 // DocString: FMTlpmodel::updategeneralconstraintsnaming
193 void updategeneralconstraintsnaming(std::vector<std::string>& colnames,
194 std::vector<std::string>& rownames) const;
195 // DocString: FMTlpmodel::setpositiveoutputsinmatrix
199 bool setpositiveoutputsinmatrix(const Core::FMTconstraint& constraint, const std::vector<std::map<int, double>>& strictlypositivesoutputs,int period);
200 virtual void swap_ptr(const std::unique_ptr<FMTmodel>& rhs);
201 // DocString: FMTlpmodel::FMTlpmodel(const FMTsrmodel&)
205 FMTlpmodel(const FMTsrmodel& rhs);
206 // DocString: FMTlpmodel::trysetsolution(const std::vector<Core::FMTschedule>&)
210 bool trysetsolution(const std::vector<Core::FMTschedule>& schedules);
211 public:
212 // DocString: FMTlpmodel::clearcache
217 // DocString: FMTlpmodel::clearconstraintlocation
222 // DocString: FMTlpmodel(const FMTmodel,FMTsolverinterface)
227 FMTlpmodel(const FMTmodel& base, FMTsolverinterface lsolvertype);
228 // DocString: FMTlpmodel()
233 // DocString: FMTlpmodel(const FMTmodel, const Graph::FMTgraph<Graph::FMTvertexproperties,Graph::FMTedgeproperties>, const FMTlpsolver, const std::vector<std::unordered_map<std::string,std::vector<std::vector<int>>>>)
238 const FMTlpsolver& lsolver,const std::vector<std::unordered_map<std::string,std::vector<std::vector<int>>>>& lelements);
239 // DocString: FMTlpmodel(const FMTlpmodel)
244 // DocString: FMTlpmodel::initialsolve
252 // DocString: FMTlpmodel(FMTlpmodel&&)
256 FMTlpmodel(FMTlpmodel&& rhs)=default;
257 // DocString: FMTlpmodel::operator=(FMTlpmodel&& rhs)
261 FMTlpmodel& operator =(FMTlpmodel&& rhs) =default;
262 // DocString: FMTlpmodel::setstrictlypositivesoutputsmatrix
267 // DocString: FMTlpmodel::getoutput
275 virtual std::map<std::string, double> getoutput(const Core::FMToutput& output,
276 int period, Core::FMToutputlevel level = Core::FMToutputlevel::standard) const;
277 // DocString: FMTlpmodel::getreplanningconstraints
282 virtual std::vector<Core::FMTconstraint> getreplanningconstraints(const std::string& modeltype, const std::vector<Core::FMTconstraint>& localconstraints, const int& period) const;
283 // DocString: FMTlpmodel::addscheduletoobjective
287 void addscheduletoobjective(const Core::FMTschedule& schedule,double weight = 1000);
288 // DocString: FMTlpmodel::operator==
292 bool operator == (const FMTlpmodel& rhs) const;
293 // DocString: FMTlpmodel::operator!=
297 bool operator != (const FMTlpmodel& rhs) const;
298 // DocString: FMTlpmodel::setobjective
305 // DocString: FMTlpmodel::setconstraint
312 // DocString: FMTlpmodel::eraseconstraint
318 // DocString: FMTlpmodel::getvariabilities
327 std::map<std::string, std::vector<double>>getvariabilities(const std::vector<Core::FMToutput>& outputs,
328 const int& periodstart,const int& periodstop);
329 // DocString: FMTlpmodel::getmodelfromproportions
334 FMTlpmodel getmodelfromproportions(const std::vector<Core::FMTmask>& globalmasks,
335 std::vector<double> tolerances) const;
336 // DocString: FMTlpmodel::getareavariabilities
342 std::map<std::string, std::vector<double>>getareavariabilities(const std::vector<Core::FMToutput>& localoutputs,
343 const std::vector<Core::FMTmask>& globalmasks,
344 std::vector<double> tolerances = std::vector<double>()) const;
345 // DocString: FMTlpmodel::eraseperiod
351 Graph::FMTgraphstats eraseperiod(bool constraintsonly = false);
352 // DocString: FMTlpmodel::getoperatingareaschedulerheuristics
359 std::vector<Heuristics::FMToperatingareascheduler>getoperatingareaschedulerheuristics(const std::vector<Heuristics::FMToperatingareascheme>& opareas,
360 const Core::FMToutputnode& node,
361 size_t numberofheuristics=1,
362 bool copysolver=true);
363 // DocString: FMTlpmodel::getoperatingareaclustererheuristics
369 std::vector<Heuristics::FMToperatingareaclusterer>getoperatingareaclustererheuristics(const std::vector<Heuristics::FMToperatingareacluster>& clusters,
370 const Core::FMToutput& statisticoutput,
371 const Core::FMToutput& areaoutput,
372 const int& period,
373 size_t numberofheuristics=1,
374 int minimalnumberofclusters = -1,
375 int maximalnumberofclusters = -1) const;
376 // DocString: FMTlpmodel::resolve
381 bool resolve();
382 // DocString: FMTlpmodel::operator=
386 FMTlpmodel& operator = (const FMTlpmodel& rhs);
387 // DocString: ~FMTlpmodel()
391 ~FMTlpmodel() = default;
392 // DocString: FMTlpmodel::getlpmodel
401 FMTlpmodel getlocalmodel(FMTmodel localmodel = FMTmodel(),int period = 0) const;
402 // DocString: FMTlpmodel::getObjValue
406 double getObjValue() const;
407 // DocString: FMTlpmodel::writeLP
411 void writeLP(const std::string& location);
412 // DocString: FMTlpmodel::writeMPS
416 void writeMPS(const std::string& location);
417 // DocString: FMTlpmodel::clone
421 virtual std::unique_ptr<FMTmodel>clone() const;
422 // DocString: FMTlpmodel::presolve
427 virtual std::unique_ptr<FMTmodel>presolve(std::vector<Core::FMTactualdevelopment> optionaldevelopments = std::vector<Core::FMTactualdevelopment>()) const;
428 // DocString: FMTmodel::build
435 virtual bool build(std::vector<Core::FMTschedule> schedules=std::vector<Core::FMTschedule>());
436 // DocString: FMTmodel::solve
440 virtual bool solve();
441 // DocString: FMTlpmodel::getcopy
448 virtual std::unique_ptr<FMTmodel> getcopy(int period = 0) const;
449
450 };
451
452}
453
454BOOST_CLASS_EXPORT_KEY(Models::FMTlpmodel)
455
456#endif
457#endif
#define FMT_DBL_TOLERANCE
Definition: FMTutility.hpp:11
#define FMTEXPORT
Definition: FMTutility.hpp:92
Definition: FMTconstraint.hpp:54
Definition: FMToutput.hpp:39
Definition: FMToutputnode.hpp:20
Definition: FMTschedule.hpp:31
Definition: FMTgraph.hpp:78
Definition: FMTgraphstats.hpp:28
Definition: FMToperatingareaclusterer.hpp:30
Definition: FMTlpmodel.hpp:57
void writeMPS(const std::string &location)
FMTlpmodel(const FMTmodel &base, FMTsolverinterface lsolvertype)
FMTlpmodel(const FMTlpmodel &rhs)
Graph::FMTgraphstats eraseconstraint(const Core::FMTconstraint &constraint, int period=-1)
void clearconstraintlocation()
Graph::FMTgraphstats eraseperiod(bool constraintsonly=false)
Graph::FMTgraphstats setconstraint(const Core::FMTconstraint &constraint)
virtual std::unique_ptr< FMTmodel > getcopy(int period=0) const
FMTlpmodel getlocalmodel(FMTmodel localmodel=FMTmodel(), int period=0) const
void writeLP(const std::string &location)
virtual bool build(std::vector< Core::FMTschedule > schedules=std::vector< Core::FMTschedule >())
FMTlpmodel(const FMTmodel &base, const Graph::FMTgraph< Graph::FMTvertexproperties, Graph::FMTedgeproperties > &lgraph, const FMTlpsolver &lsolver, const std::vector< std::unordered_map< std::string, std::vector< std::vector< int > > > > &lelements)
Graph::FMTgraphstats setobjective(const Core::FMTconstraint &objective)
void setstrictlypositivesoutputsmatrix()
virtual std::unique_ptr< FMTmodel > presolve(std::vector< Core::FMTactualdevelopment > optionaldevelopments=std::vector< Core::FMTactualdevelopment >()) const
virtual std::map< std::string, double > getoutput(const Core::FMToutput &output, int period, Core::FMToutputlevel level=Core::FMToutputlevel::standard) const
std::map< std::string, std::vector< double > > getvariabilities(const std::vector< Core::FMToutput > &outputs, const int &periodstart, const int &periodstop)
double getObjValue() const
FMTlpmodel(FMTlpmodel &&rhs)=default
~FMTlpmodel()=default
std::vector< Heuristics::FMToperatingareascheduler > getoperatingareaschedulerheuristics(const std::vector< Heuristics::FMToperatingareascheme > &opareas, const Core::FMToutputnode &node, size_t numberofheuristics=1, bool copysolver=true)
std::vector< Heuristics::FMToperatingareaclusterer > getoperatingareaclustererheuristics(const std::vector< Heuristics::FMToperatingareacluster > &clusters, const Core::FMToutput &statisticoutput, const Core::FMToutput &areaoutput, const int &period, size_t numberofheuristics=1, int minimalnumberofclusters=-1, int maximalnumberofclusters=-1) const
std::map< std::string, std::vector< double > > getareavariabilities(const std::vector< Core::FMToutput > &localoutputs, const std::vector< Core::FMTmask > &globalmasks, std::vector< double > tolerances=std::vector< double >()) const
virtual bool solve()
void addscheduletoobjective(const Core::FMTschedule &schedule, double weight=1000)
virtual std::unique_ptr< FMTmodel > clone() const
FMTlpmodel getmodelfromproportions(const std::vector< Core::FMTmask > &globalmasks, std::vector< double > tolerances) const
virtual std::vector< Core::FMTconstraint > getreplanningconstraints(const std::string &modeltype, const std::vector< Core::FMTconstraint > &localconstraints, const int &period) const
Definition: FMTlpsolver.hpp:39
Definition: FMTmodel.hpp:60
Definition: FMTsrmodel.hpp:44
FMToutputlevel
Definition: FMTutility.hpp:17
@ standard
Definition: FMTutility.hpp:18
Namespace regrouping all tools for solving LP/MIP problems using an heuristic.
Definition: FMTareaparser.hpp:43
Namespace containing all enumerator and classes used to construct or manipulate the different type of...
Definition: FMTareaparser.hpp:50
FMTmatrixelement
Definition: FMTlpmodel.hpp:36
@ nr_items
Definition: FMTlpmodel.hpp:42
@ strictlypositive
Definition: FMTlpmodel.hpp:41
@ goalvariable
Definition: FMTlpmodel.hpp:37
@ objectivevariable
Definition: FMTlpmodel.hpp:39
@ levelvariable
Definition: FMTlpmodel.hpp:38
@ constraint
Definition: FMTlpmodel.hpp:40
FMTsolverinterface
Definition: FMTsolverinterface.hpp:21