QGIS API Documentation  2.99.0-Master (314842d)
problem.h
Go to the documentation of this file.
1 /*
2  * libpal - Automated Placement of Labels Library
3  *
4  * Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5  * University of Applied Sciences, Western Switzerland
6  * http://www.hes-so.ch
7  *
8  * Contact:
9  * maxence.laurent <at> heig-vd <dot> ch
10  * or
11  * eric.taillard <at> heig-vd <dot> ch
12  *
13  * This file is part of libpal.
14  *
15  * libpal is free software: you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation, either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * libpal is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with libpal. If not, see <http://www.gnu.org/licenses/>.
27  *
28  */
29 
30 #ifndef PAL_PROBLEM_H
31 #define PAL_PROBLEM_H
32 
33 #include "qgis_core.h"
34 #include <list>
35 #include <QList>
36 #include "rtree.hpp"
37 
38 namespace pal
39 {
40 
41  class LabelPosition;
42  class Label;
43 
49  class Sol
50  {
51  public:
52  int *s = nullptr;
53  double cost;
54  };
55 
56  typedef struct _subpart
57  {
58 
62  int probSize;
63 
68 
72  int subSize;
73 
77  int *sub = nullptr;
78 
82  int *sol = nullptr;
83 
87  int seed;
88  } SubPart;
89 
90  typedef struct _chain
91  {
92  int degree;
93  double delta;
94  int *feat = nullptr;
95  int *label = nullptr;
96  } Chain;
97 
104  class CORE_EXPORT Problem
105  {
106 
107  friend class Pal;
108 
109  public:
110  Problem();
111 
112  //Problem(char *lorena_file, bool displayAll);
113 
114  ~Problem();
115 
117  Problem( const Problem &other ) = delete;
119  Problem &operator=( const Problem &other ) = delete;
120 
125  void addCandidatePosition( LabelPosition *position ) { mLabelPositions.append( position ); }
126 
128  // problem inspection functions
129  int getNumFeatures() { return nbft; }
130  // features counted 0...n-1
131  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
132  // both features and candidates counted 0..n-1
133  LabelPosition *getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
135 
136 
137  void reduce();
138 
142  void popmusic();
143 
147  void chain_search();
148 
149  QList<LabelPosition *> *getSolution( bool returnInactive );
150 
151  PalStat *getStats();
152 
153  /* useful only for postscript post-conversion*/
154  //void toFile(char *label_file);
155 
156  SubPart *subPart( int r, int featseed, int *isIn );
157 
158  void initialization();
159 
160  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
161  double compute_subsolution_cost( SubPart *part, int *s, int *nbOverlap );
162 
166  double popmusic_chain( SubPart *part );
167 
168  double popmusic_tabu( SubPart *part );
169 
175  double popmusic_tabu_chain( SubPart *part );
176 
180  void init_sol_empty();
181  void init_sol_falp();
182 
183  static bool compareLabelArea( pal::LabelPosition *l1, pal::LabelPosition *l2 );
184 
185  private:
186 
190  int nbLabelledLayers;
191 
195  QStringList labelledLayersName;
196 
200  int nblp;
201 
205  int all_nblp;
206 
210  int nbft;
211 
212 
216  bool displayAll;
217 
221  double bbox[4];
222 
223  double *labelPositionCost = nullptr;
224  int *nbOlap = nullptr;
225 
226  QList< LabelPosition * > mLabelPositions;
227 
228  RTree<LabelPosition *, double, 2, double> *candidates; // index all candidates
229  RTree<LabelPosition *, double, 2, double> *candidates_sol; // index active candidates
230  RTree<LabelPosition *, double, 2, double> *candidates_subsol; // idem for subparts
231 
232  //int *feat; // [nblp]
233  int *featStartId; // [nbft]
234  int *featNbLp; // [nbft]
235  double *inactiveCost; //
236 
237  Sol *sol; // [nbft]
238  int nbActive;
239 
240  double nbOverlap;
241 
242  int *featWrap = nullptr;
243 
244  Chain *chain( SubPart *part, int seed );
245 
246  Chain *chain( int seed );
247 
248  Pal *pal = nullptr;
249 
250  void solution_cost();
251  void check_solution();
252  };
253 
254 } // namespace
255 
256 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:125
int getFeatureCandidateCount(int i)
Definition: problem.h:131
int probSize
of features in problem
Definition: problem.h:62
double cost
Definition: problem.h:53
int degree
Definition: problem.h:92
Main Pal labeling class.
Definition: pal.h:85
void seed(uint32_t value)
struct pal::_chain Chain
struct pal::_subpart SubPart
int * s
Definition: problem.h:52
int getNumFeatures()
Definition: problem.h:129
int subSize
total # features (prob + border)
Definition: problem.h:72
Summary statistics of labeling problem.
Definition: palstat.h:44
LabelPosition is a candidate feature label position.
Definition: labelposition.h:52
Representation of a labeling problem.
Definition: problem.h:104
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:133
int borderSize
of features bounding the problem
Definition: problem.h:67
double delta
Definition: problem.h:93
int seed
first feat in sub part
Definition: problem.h:87