QGIS API Documentation  2.12.0-Lyon
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 _PROBLEM_H
31 #define _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 
44  class Sol
45  {
46  public:
47  int *s;
48  double cost;
49  };
50 
51  typedef struct _subpart
52  {
56  int probSize;
57 
62 
66  int subSize;
67 
71  int *sub;
75  int *sol;
79  int seed;
80  } SubPart;
81 
82  typedef struct _chain
83  {
84  int degree;
85  double delta;
86  int *feat;
87  int *label;
88  } Chain;
89 
93  class CORE_EXPORT Problem
94  {
95 
96  friend class Pal;
97 
98  public:
99  Problem();
100 
101  //Problem(char *lorena_file, bool displayAll);
102 
103  ~Problem();
104 
109  void addCandidatePosition( LabelPosition* position ) { mLabelPositions.append( position ); }
110 
112  // problem inspection functions
113  int getNumFeatures() { return nbft; }
114  // features counted 0...n-1
115  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
116  // both features and candidates counted 0..n-1
117  LabelPosition* getFeatureCandidate( int fi, int ci ) { return mLabelPositions.at( featStartId[fi] + ci ); }
119 
120 
121  void reduce();
122 
126  void popmusic();
127 
131  void chain_search();
132 
133  std::list<LabelPosition*> * getSolution( bool returnInactive );
134 
135  PalStat * getStats();
136 
137  /* useful only for postscript post-conversion*/
138  //void toFile(char *label_file);
139 
140  SubPart *subPart( int r, int featseed, int *isIn );
141 
142  void initialization();
143 
144  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
145  double compute_subsolution_cost( SubPart *part, int *s, int * nbOverlap );
146 
150  double popmusic_chain( SubPart *part );
151 
152  double popmusic_tabu( SubPart *part );
153 
159  double popmusic_tabu_chain( SubPart *part );
160 
164  void init_sol_empty();
165  void init_sol_falp();
166 
167  static bool compareLabelArea( pal::LabelPosition* l1, pal::LabelPosition* l2 );
168 
169  private:
170 
174  int nbLabelledLayers;
175 
179  QStringList labelledLayersName;
180 
184  int nblp;
188  int all_nblp;
189 
193  int nbft;
194 
195 
199  bool displayAll;
200 
204  double bbox[4];
205 
206  double *labelPositionCost;
207  int *nbOlap;
208 
209  QList< LabelPosition* > mLabelPositions;
210 
211  RTree<LabelPosition*, double, 2, double> *candidates; // index all candidates
212  RTree<LabelPosition*, double, 2, double> *candidates_sol; // index active candidates
213  RTree<LabelPosition*, double, 2, double> *candidates_subsol; // idem for subparts
214 
215  //int *feat; // [nblp]
216  int *featStartId; // [nbft]
217  int *featNbLp; // [nbft]
218  double *inactiveCost; //
219 
220  Sol *sol; // [nbft]
221  int nbActive;
222 
223  double nbOverlap;
224 
225  int *featWrap;
226 
227  Chain *chain( SubPart *part, int seed );
228 
229  Chain *chain( int seed );
230 
231  Pal *pal;
232 
233  void solution_cost();
234  void check_solution();
235  };
236 
237 } // namespace
238 
239 #endif
void addCandidatePosition(LabelPosition *position)
Adds a candidate label position to the problem.
Definition: problem.h:109
int getFeatureCandidateCount(int i)
Definition: problem.h:115
int probSize
of features in problem
Definition: problem.h:56
double cost
Definition: problem.h:48
int degree
Definition: problem.h:84
Pal main class.
Definition: pal.h:111
int * label
Definition: problem.h:87
void seed(uint32_t value)
struct pal::_chain Chain
int * sol
sub solution
Definition: problem.h:75
struct pal::_subpart SubPart
int * sub
wrap bw sub feat and main feat
Definition: problem.h:71
int * s
Definition: problem.h:47
int * feat
Definition: problem.h:86
int getNumFeatures()
Definition: problem.h:113
int subSize
total # features (prob + border)
Definition: problem.h:66
Summury of problem.
Definition: palstat.h:41
LabelPosition is a candidate feature label position.
Definition: labelposition.h:48
Represent a problem.
Definition: problem.h:93
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:117
int borderSize
of features bounding the problem
Definition: problem.h:61
double delta
Definition: problem.h:85
int seed
first feat in sub part
Definition: problem.h:79