QGIS API Documentation  2.13.0-Master
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 
48  class Sol
49  {
50  public:
51  int *s;
52  double cost;
53  };
54 
55  typedef struct _subpart
56  {
60  int probSize;
61 
66 
70  int subSize;
71 
75  int *sub;
79  int *sol;
83  int seed;
84  } SubPart;
85 
86  typedef struct _chain
87  {
88  int degree;
89  double delta;
90  int *feat;
91  int *label;
92  } Chain;
93 
99  class CORE_EXPORT Problem
100  {
101 
102  friend class Pal;
103 
104  public:
105  Problem();
106 
107  //Problem(char *lorena_file, bool displayAll);
108 
109  ~Problem();
110 
115  void addCandidatePosition( LabelPosition* position ) { mLabelPositions.append( position ); }
116 
118  // problem inspection functions
119  int getNumFeatures() { return nbft; }
120  // features counted 0...n-1
121  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
122  // both features and candidates counted 0..n-1
123  LabelPosition* getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
125 
126 
127  void reduce();
128 
132  void popmusic();
133 
137  void chain_search();
138 
139  QList<LabelPosition*> * getSolution( bool returnInactive );
140 
141  PalStat * getStats();
142 
143  /* useful only for postscript post-conversion*/
144  //void toFile(char *label_file);
145 
146  SubPart *subPart( int r, int featseed, int *isIn );
147 
148  void initialization();
149 
150  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
151  double compute_subsolution_cost( SubPart *part, int *s, int * nbOverlap );
152 
156  double popmusic_chain( SubPart *part );
157 
158  double popmusic_tabu( SubPart *part );
159 
165  double popmusic_tabu_chain( SubPart *part );
166 
170  void init_sol_empty();
171  void init_sol_falp();
172 
173  static bool compareLabelArea( pal::LabelPosition* l1, pal::LabelPosition* l2 );
174 
175  private:
176 
180  int nbLabelledLayers;
181 
185  QStringList labelledLayersName;
186 
190  int nblp;
194  int all_nblp;
195 
199  int nbft;
200 
201 
205  bool displayAll;
206 
210  double bbox[4];
211 
212  double *labelPositionCost;
213  int *nbOlap;
214 
215  QList< LabelPosition* > mLabelPositions;
216 
217  RTree<LabelPosition*, double, 2, double> *candidates; // index all candidates
218  RTree<LabelPosition*, double, 2, double> *candidates_sol; // index active candidates
219  RTree<LabelPosition*, double, 2, double> *candidates_subsol; // idem for subparts
220 
221  //int *feat; // [nblp]
222  int *featStartId; // [nbft]
223  int *featNbLp; // [nbft]
224  double *inactiveCost; //
225 
226  Sol *sol; // [nbft]
227  int nbActive;
228 
229  double nbOverlap;
230 
231  int *featWrap;
232 
233  Chain *chain( SubPart *part, int seed );
234 
235  Chain *chain( int seed );
236 
237  Pal *pal;
238 
239  void solution_cost();
240  void check_solution();
241  };
242 
243 } // namespace
244 
245 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:115
int getFeatureCandidateCount(int i)
Definition: problem.h:121
int probSize
of features in problem
Definition: problem.h:60
double cost
Definition: problem.h:52
int degree
Definition: problem.h:88
Main Pal labelling class.
Definition: pal.h:84
int * label
Definition: problem.h:91
void seed(uint32_t value)
struct pal::_chain Chain
int * sol
sub solution
Definition: problem.h:79
struct pal::_subpart SubPart
int * sub
wrap bw sub feat and main feat
Definition: problem.h:75
int * s
Definition: problem.h:51
int * feat
Definition: problem.h:90
int getNumFeatures()
Definition: problem.h:119
int subSize
total # features (prob + border)
Definition: problem.h:70
Summary statistics of labelling problem.
Definition: palstat.h:44
LabelPosition is a candidate feature label position.
Definition: labelposition.h:50
Representation of a labeling problem.
Definition: problem.h:99
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:123
int borderSize
of features bounding the problem
Definition: problem.h:65
double delta
Definition: problem.h:89
int seed
first feat in sub part
Definition: problem.h:83