QGIS API Documentation  2.99.0-Master (08ee180)
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 <list>
34 #include <QList>
35 #include "rtree.hpp"
36 
37 namespace pal
38 {
39 
40  class LabelPosition;
41  class Label;
42 
48  class Sol
49  {
50  public:
51  int *s;
52  double cost;
53  };
54 
55  typedef struct _subpart
56  {
57 
61  int probSize;
62 
67 
71  int subSize;
72 
76  int *sub;
77 
81  int *sol;
82 
86  int seed;
87  } SubPart;
88 
89  typedef struct _chain
90  {
91  int degree;
92  double delta;
93  int *feat;
94  int *label;
95  } Chain;
96 
103  class CORE_EXPORT Problem
104  {
105 
106  friend class Pal;
107 
108  public:
109  Problem();
110 
111  //Problem(char *lorena_file, bool displayAll);
112 
113  ~Problem();
114 
119  void addCandidatePosition( LabelPosition* position ) { mLabelPositions.append( position ); }
120 
122  // problem inspection functions
123  int getNumFeatures() { return nbft; }
124  // features counted 0...n-1
125  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
126  // both features and candidates counted 0..n-1
127  LabelPosition* getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
129 
130 
131  void reduce();
132 
136  void popmusic();
137 
141  void chain_search();
142 
143  QList<LabelPosition*> * getSolution( bool returnInactive );
144 
145  PalStat * getStats();
146 
147  /* useful only for postscript post-conversion*/
148  //void toFile(char *label_file);
149 
150  SubPart *subPart( int r, int featseed, int *isIn );
151 
152  void initialization();
153 
154  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
155  double compute_subsolution_cost( SubPart *part, int *s, int * nbOverlap );
156 
160  double popmusic_chain( SubPart *part );
161 
162  double popmusic_tabu( SubPart *part );
163 
169  double popmusic_tabu_chain( SubPart *part );
170 
174  void init_sol_empty();
175  void init_sol_falp();
176 
177  static bool compareLabelArea( pal::LabelPosition* l1, pal::LabelPosition* l2 );
178 
179  private:
180 
181  Problem( const Problem& other );
182  Problem& operator=( const Problem& other );
183 
187  int nbLabelledLayers;
188 
192  QStringList labelledLayersName;
193 
197  int nblp;
198 
202  int all_nblp;
203 
207  int nbft;
208 
209 
213  bool displayAll;
214 
218  double bbox[4];
219 
220  double *labelPositionCost;
221  int *nbOlap;
222 
223  QList< LabelPosition* > mLabelPositions;
224 
225  RTree<LabelPosition*, double, 2, double> *candidates; // index all candidates
226  RTree<LabelPosition*, double, 2, double> *candidates_sol; // index active candidates
227  RTree<LabelPosition*, double, 2, double> *candidates_subsol; // idem for subparts
228 
229  //int *feat; // [nblp]
230  int *featStartId; // [nbft]
231  int *featNbLp; // [nbft]
232  double *inactiveCost; //
233 
234  Sol *sol; // [nbft]
235  int nbActive;
236 
237  double nbOverlap;
238 
239  int *featWrap;
240 
241  Chain *chain( SubPart *part, int seed );
242 
243  Chain *chain( int seed );
244 
245  Pal *pal;
246 
247  void solution_cost();
248  void check_solution();
249  };
250 
251 } // namespace
252 
253 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:119
int getFeatureCandidateCount(int i)
Definition: problem.h:125
int probSize
of features in problem
Definition: problem.h:61
double cost
Definition: problem.h:52
int degree
Definition: problem.h:91
Main Pal labelling class.
Definition: pal.h:84
int * label
Definition: problem.h:94
void seed(uint32_t value)
struct pal::_chain Chain
int * sol
sub solution
Definition: problem.h:81
struct pal::_subpart SubPart
int * sub
wrap bw sub feat and main feat
Definition: problem.h:76
int * s
Definition: problem.h:51
int * feat
Definition: problem.h:93
int getNumFeatures()
Definition: problem.h:123
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:103
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:127
int borderSize
of features bounding the problem
Definition: problem.h:66
double delta
Definition: problem.h:92
int seed
first feat in sub part
Definition: problem.h:86