QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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