QGIS API Documentation  2.99.0-Master (7d4f81d)
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 
128  void addCandidatePosition( LabelPosition *position ) { mLabelPositions.append( position ); }
129 
131  // problem inspection functions
132  int getNumFeatures() { return nbft; }
133  // features counted 0...n-1
134  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
135  // both features and candidates counted 0..n-1
136  LabelPosition *getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
138 
139 
140  void reduce();
141 
145  void popmusic();
146 
150  void chain_search();
151 
152  QList<LabelPosition *> *getSolution( bool returnInactive );
153 
154  PalStat *getStats();
155 
156  /* useful only for postscript post-conversion*/
157  //void toFile(char *label_file);
158 
159  SubPart *subPart( int r, int featseed, int *isIn );
160 
161  void initialization();
162 
163  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
164  double compute_subsolution_cost( SubPart *part, int *s, int *nbOverlap );
165 
169  double popmusic_chain( SubPart *part );
170 
171  double popmusic_tabu( SubPart *part );
172 
178  double popmusic_tabu_chain( SubPart *part );
179 
183  void init_sol_empty();
184  void init_sol_falp();
185 
186  static bool compareLabelArea( pal::LabelPosition *l1, pal::LabelPosition *l2 );
187 
188  private:
189 
193  int nbLabelledLayers;
194 
198  QStringList labelledLayersName;
199 
203  int nblp;
204 
208  int all_nblp;
209 
213  int nbft;
214 
215 
219  bool displayAll;
220 
224  double bbox[4];
225 
226  double *labelPositionCost = nullptr;
227  int *nbOlap = nullptr;
228 
229  QList< LabelPosition * > mLabelPositions;
230 
231  RTree<LabelPosition *, double, 2, double> *candidates; // index all candidates
232  RTree<LabelPosition *, double, 2, double> *candidates_sol; // index active candidates
233  RTree<LabelPosition *, double, 2, double> *candidates_subsol; // idem for subparts
234 
235  //int *feat; // [nblp]
236  int *featStartId; // [nbft]
237  int *featNbLp; // [nbft]
238  double *inactiveCost; //
239 
240  Sol *sol; // [nbft]
241  int nbActive;
242 
243  double nbOverlap;
244 
245  int *featWrap = nullptr;
246 
247  Chain *chain( SubPart *part, int seed );
248 
249  Chain *chain( int seed );
250 
251  Pal *pal = nullptr;
252 
253  void solution_cost();
254  void check_solution();
255  };
256 
257 } // namespace
258 
259 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:128
int getFeatureCandidateCount(int i)
Definition: problem.h:134
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:88
void seed(uint32_t value)
struct pal::_chain Chain
struct pal::_subpart SubPart
int * s
Definition: problem.h:55
int getNumFeatures()
Definition: problem.h:132
int subSize
total # features (prob + border)
Definition: problem.h:75
Summary statistics of labeling problem.
Definition: palstat.h:47
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:136
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