QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 #define SIP_NO_FILE
34 
35 
36 #include "qgis_core.h"
37 #include <list>
38 #include <QList>
39 #include "rtree.hpp"
40 
41 namespace pal
42 {
43 
44  class LabelPosition;
45  class Label;
46 
52  class Sol
53  {
54  public:
55  int *s = nullptr;
56  double cost;
57  };
58 
59  typedef struct _subpart
60  {
61 
65  int probSize;
66 
71 
75  int subSize;
76 
80  int *sub = nullptr;
81 
85  int *sol = nullptr;
86 
90  int seed;
91  } SubPart;
92 
93  typedef struct _chain
94  {
95  int degree;
96  double delta;
97  int *feat = nullptr;
98  int *label = nullptr;
99  } Chain;
100 
107  class CORE_EXPORT Problem
108  {
109 
110  friend class Pal;
111 
112  public:
113  Problem();
114 
115  //Problem(char *lorena_file, bool displayAll);
116 
117  ~Problem();
118 
120  Problem( const Problem &other ) = delete;
122  Problem &operator=( const Problem &other ) = delete;
123 
129  void addCandidatePosition( LabelPosition *position ) { mLabelPositions.append( position ); }
130 
132  // problem inspection functions
133  int getNumFeatures() { return nbft; }
134  // features counted 0...n-1
135  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
136  // both features and candidates counted 0..n-1
137  LabelPosition *getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
139 
140 
141  void reduce();
142 
146  void popmusic();
147 
151  void chain_search();
152 
153  QList<LabelPosition *> getSolution( bool returnInactive );
154 
155  PalStat *getStats();
156 
157  /* useful only for postscript post-conversion*/
158  //void toFile(char *label_file);
159 
160  SubPart *subPart( int r, int featseed, int *isIn );
161 
162  void initialization();
163 
164  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
165  double compute_subsolution_cost( SubPart *part, int *s, int *nbOverlap );
166 
170  double popmusic_chain( SubPart *part );
171 
172  double popmusic_tabu( SubPart *part );
173 
179  double popmusic_tabu_chain( SubPart *part );
180 
184  void init_sol_empty();
185  void init_sol_falp();
186 
187  static bool compareLabelArea( pal::LabelPosition *l1, pal::LabelPosition *l2 );
188 
189  private:
190 
194  int nbLabelledLayers = 0;
195 
199  QStringList labelledLayersName;
200 
204  int nblp = 0;
205 
209  int all_nblp = 0;
210 
214  int nbft = 0;
215 
216 
220  bool displayAll = false;
221 
225  double bbox[4];
226 
227  double *labelPositionCost = nullptr;
228  int *nbOlap = nullptr;
229 
230  QList< LabelPosition * > mLabelPositions;
231 
232  RTree<LabelPosition *, double, 2, double> *candidates = nullptr; // index all candidates
233  RTree<LabelPosition *, double, 2, double> *candidates_sol = nullptr; // index active candidates
234  RTree<LabelPosition *, double, 2, double> *candidates_subsol = nullptr; // idem for subparts
235 
236  //int *feat; // [nblp]
237  int *featStartId = nullptr; // [nbft]
238  int *featNbLp = nullptr; // [nbft]
239  double *inactiveCost = nullptr; //
240 
241  Sol *sol = nullptr; // [nbft]
242  int nbActive = 0;
243 
244  double nbOverlap = 0.0;
245 
246  int *featWrap = nullptr;
247 
248  Chain *chain( SubPart *part, int seed );
249 
250  Chain *chain( int seed );
251 
252  Pal *pal = nullptr;
253 
254  void solution_cost();
255  void check_solution();
256  };
257 
258 } // namespace
259 
260 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:129
int getFeatureCandidateCount(int i)
Definition: problem.h:135
int probSize
of features in problem
Definition: problem.h:65
double cost
Definition: problem.h:56
int degree
Definition: problem.h:95
Main Pal labeling class.
Definition: pal.h:87
void seed(uint32_t value)
struct pal::_chain Chain
struct pal::_subpart SubPart
int * s
Definition: problem.h:55
int getNumFeatures()
Definition: problem.h:133
int subSize
total # features (prob + border)
Definition: problem.h:75
Summary statistics of labeling problem.
Definition: palstat.h:48
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
Representation of a labeling problem.
Definition: problem.h:107
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:137
int borderSize
of features bounding the problem
Definition: problem.h:70
double delta
Definition: problem.h:96
int seed
first feat in sub part
Definition: problem.h:90