QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "pal.h"
34 #include "rtree.hpp"
35 #include <list>
36 #include <QList>
37 
38 namespace pal
39 {
40 
41  class LabelPosition;
42  class Label;
43 
49  class Sol
50  {
51  public:
52  int *s;
53  double cost;
54  };
55 
56  typedef struct _subpart
57  {
61  int probSize;
62 
67 
71  int subSize;
72 
76  int *sub;
80  int *sol;
84  int seed;
85  } SubPart;
86 
87  typedef struct _chain
88  {
89  int degree;
90  double delta;
91  int *feat;
92  int *label;
93  } Chain;
94 
101  class CORE_EXPORT Problem
102  {
103 
104  friend class Pal;
105 
106  public:
107  Problem();
108 
109  //Problem(char *lorena_file, bool displayAll);
110 
111  ~Problem();
112 
117  void addCandidatePosition( LabelPosition* position ) { mLabelPositions.append( position ); }
118 
120  // problem inspection functions
121  int getNumFeatures() { return nbft; }
122  // features counted 0...n-1
123  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
124  // both features and candidates counted 0..n-1
125  LabelPosition* getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
127 
128 
129  void reduce();
130 
134  void popmusic();
135 
139  void chain_search();
140 
141  QList<LabelPosition*> * getSolution( bool returnInactive );
142 
143  PalStat * getStats();
144 
145  /* useful only for postscript post-conversion*/
146  //void toFile(char *label_file);
147 
148  SubPart *subPart( int r, int featseed, int *isIn );
149 
150  void initialization();
151 
152  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
153  double compute_subsolution_cost( SubPart *part, int *s, int * nbOverlap );
154 
158  double popmusic_chain( SubPart *part );
159 
160  double popmusic_tabu( SubPart *part );
161 
167  double popmusic_tabu_chain( SubPart *part );
168 
172  void init_sol_empty();
173  void init_sol_falp();
174 
175  static bool compareLabelArea( pal::LabelPosition* l1, pal::LabelPosition* l2 );
176 
177  private:
178 
182  int nbLabelledLayers;
183 
187  QStringList labelledLayersName;
188 
192  int nblp;
196  int all_nblp;
197 
201  int nbft;
202 
203 
207  bool displayAll;
208 
212  double bbox[4];
213 
214  double *labelPositionCost;
215  int *nbOlap;
216 
217  QList< LabelPosition* > mLabelPositions;
218 
219  RTree<LabelPosition*, double, 2, double> *candidates; // index all candidates
220  RTree<LabelPosition*, double, 2, double> *candidates_sol; // index active candidates
221  RTree<LabelPosition*, double, 2, double> *candidates_subsol; // idem for subparts
222 
223  //int *feat; // [nblp]
224  int *featStartId; // [nbft]
225  int *featNbLp; // [nbft]
226  double *inactiveCost; //
227 
228  Sol *sol; // [nbft]
229  int nbActive;
230 
231  double nbOverlap;
232 
233  int *featWrap;
234 
235  Chain *chain( SubPart *part, int seed );
236 
237  Chain *chain( int seed );
238 
239  Pal *pal;
240 
241  void solution_cost();
242  void check_solution();
243  };
244 
245 } // namespace
246 
247 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:117
int getFeatureCandidateCount(int i)
Definition: problem.h:123
int probSize
of features in problem
Definition: problem.h:61
double cost
Definition: problem.h:53
int degree
Definition: problem.h:89
Main Pal labelling class.
Definition: pal.h:84
int * label
Definition: problem.h:92
void seed(uint32_t value)
struct pal::_chain Chain
int * sol
sub solution
Definition: problem.h:80
struct pal::_subpart SubPart
int * sub
wrap bw sub feat and main feat
Definition: problem.h:76
int * s
Definition: problem.h:52
int * feat
Definition: problem.h:91
int getNumFeatures()
Definition: problem.h:121
int subSize
total # features (prob + border)
Definition: problem.h:71
Summary statistics of labelling problem.
Definition: palstat.h:44
LabelPosition is a candidate feature label position.
Definition: labelposition.h:51
Representation of a labeling problem.
Definition: problem.h:101
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:125
int borderSize
of features bounding the problem
Definition: problem.h:66
double delta
Definition: problem.h:90
int seed
first feat in sub part
Definition: problem.h:84