QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 
34 #ifndef _PROBLEM_H
35 #define _PROBLEM_H
36 
37 #include <list>
38 #include <pal/pal.h>
39 #include "rtree.hpp"
40 
41 namespace pal
42 {
43 
44  class LabelPosition;
45  class Label;
46 
47  class Sol
48  {
49  public:
50  int *s;
51  double cost;
52  };
53 
54  typedef struct _subpart
55  {
59  int probSize;
60 
65 
69  int subSize;
70 
74  int *sub;
78  int *sol;
82  int seed;
83  } SubPart;
84 
85  typedef struct _chain
86  {
87  int degree;
88  double delta;
89  int *feat;
90  int *label;
91  } Chain;
92 
96  class CORE_EXPORT Problem
97  {
98 
99  friend class Pal;
100 
101  private:
102 
106  int nbLabelledLayers;
107 
111  char **labelledLayersName;
112 
116  int nblp;
120  int all_nblp;
121 
125  int nbft;
126 
127 
131  bool displayAll;
132 
136  double bbox[4];
137 
141  double scale;
142 
143  double *labelPositionCost;
144  int *nbOlap;
145 
146  LabelPosition **labelpositions;
147 
148  RTree<LabelPosition*, double, 2, double> *candidates; // index all candidates
149  RTree<LabelPosition*, double, 2, double> *candidates_sol; // index active candidates
150  RTree<LabelPosition*, double, 2, double> *candidates_subsol; // idem for subparts
151 
152  //int *feat; // [nblp]
153  int *featStartId; // [nbft]
154  int *featNbLp; // [nbft]
155  double *inactiveCost; //
156 
157  Sol *sol; // [nbft]
158  int nbActive;
159 
160  double nbOverlap;
161 
162  int *featWrap;
163 
164  Chain *chain( SubPart *part, int seed );
165 
166  Chain *chain( int seed );
167 
168  Pal *pal;
169 
170  void solution_cost();
171  void check_solution();
172 
173  public:
174  Problem();
175 
176  //Problem(char *lorena_file, bool displayAll);
177 
178  ~Problem();
179 
181  // problem inspection functions
182  int getNumFeatures() { return nbft; }
183  // features counted 0...n-1
184  int getFeatureCandidateCount( int i ) { return featNbLp[i]; }
185  // both features and candidates counted 0..n-1
186  LabelPosition* getFeatureCandidate( int fi, int ci ) { return labelpositions[ featStartId[fi] + ci]; }
188 
189 
190  void reduce();
191 
192 
193  void post_optimization();
194 
195 
199  void popmusic();
200 
204  void chain_search();
205 
206  std::list<LabelPosition*> * getSolution( bool returnInactive );
207 
208  PalStat * getStats();
209 
210  /* useful only for postscript post-conversion*/
211  //void toFile(char *label_file);
212 
213  SubPart *subPart( int r, int featseed, int *isIn );
214 
215  void initialization();
216 
217  double compute_feature_cost( SubPart *part, int feat_id, int label_id, int *nbOverlap );
218  double compute_subsolution_cost( SubPart *part, int *s, int * nbOverlap );
219 
220  double popmusic_chain( SubPart *part );
221 
222  double popmusic_tabu( SubPart *part );
223  double popmusic_tabu_chain( SubPart *part );
224 
225  void init_sol_empty();
226  void init_sol_falp();
227 
228  static bool compareLabelArea( pal::LabelPosition* l1, pal::LabelPosition* l2 );
229 
230 #ifdef _EXPORT_MAP_
231  void drawLabels( std::ofstream &svgmap );
232 #endif
233 
234  };
235 
236 } // namespace
237 
238 #endif
int getFeatureCandidateCount(int i)
Definition: problem.h:184
int probSize
of features in problem
Definition: problem.h:59
double cost
Definition: problem.h:51
int degree
Definition: problem.h:87
Pal main class.
Definition: pal.h:126
int * label
Definition: problem.h:90
void seed(uint32_t value)
struct pal::_chain Chain
int * sol
sub solution
Definition: problem.h:78
struct pal::_subpart SubPart
int * sub
wrap bw sub feat and main feat
Definition: problem.h:74
int * s
Definition: problem.h:50
int * feat
Definition: problem.h:89
int getNumFeatures()
Definition: problem.h:182
int subSize
total # features (prob + border)
Definition: problem.h:69
Summury of problem.
Definition: palstat.h:44
LabelPositon is a candidate feature label position.
Definition: labelposition.h:53
Represent a problem.
Definition: problem.h:96
LabelPosition * getFeatureCandidate(int fi, int ci)
Definition: problem.h:186
int borderSize
of features bounding the problem
Definition: problem.h:64
double delta
Definition: problem.h:88
int seed
first feat in sub part
Definition: problem.h:82