mosp LEDA Extension Package  0.7
generator.h
Go to the documentation of this file.
1 //
2 // This program can be freely used in an academic environment
3 // ONLY for research purposes, subject to the following restrictions:
4 //
5 // 1. The origin of this software must not be misrepresented; you must not
6 // claim that you wrote the original software. If you use this software
7 // an acknowledgment in the product documentation is required.
8 // 2. Altered source versions must be plainly marked as such, and must not be
9 // misrepresented as being the original software.
10 // 3. This notice may not be removed or altered from any source distribution.
11 //
12 // Any other use is strictly prohibited by the author, without an explicit
13 // permission.
14 //
15 // Note that this program uses the LEDA library, which is NOT free. For more
16 // details visit Algorithmic Solutions at http://www.algorithmic-solutions.com/
17 //
18 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
19 // ! Any commercial use of this software is strictly !
20 // ! prohibited without explicit permission by the !
21 // ! author. !
22 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23 //
24 // This software is distributed in the hope that it will be useful,
25 // but WITHOUT ANY WARRANTY; without even the implied warranty of
26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 //
28 // Copyright (C) 2004-2010 Dimitris Michail <michail@hua.gr>
29  // end of group generator
76 
77 #ifndef LEP_GENERATOR_H
78 #define LEP_GENERATOR_H
79 
80 #include <LEP/mosp/config.h>
81 #include <set>
82 #include <list>
83 #include <vector>
84 #include <map>
85 
86 #ifdef LEDA_GE_V5
87 #include <LEDA/graph/graph.h>
88 #include <LEDA/core/random_source.h>
89 #include <LEDA/system/assert.h>
90 #include <LEDA/graph/node_map.h>
91 #include <LEDA/graph/edge_map.h>
92 #include <LEDA/core/list.h>
93 #include <LEDA/core/array.h>
94 #else
95 #include <LEDA/graph.h>
96 #include <LEDA/random_source.h>
97 #include <LEDA/std/assert.h>
98 #include <LEDA/node_map.h>
99 #include <LEDA/edge_map.h>
100 #include <LEDA/list.h>
101 #include <LEDA/array.h>
102 #endif
103 
104 namespace mosp
105 {
106 
107 
113  {
114  public:
115 
121  StructuredInstanceGenerator(int apps, int posts, int seed = default_seed);
122 
124  virtual ~StructuredInstanceGenerator();
125 
129  void GenerateGML( std::ostream& o );
130 
138  void GenerateGraph( leda::graph& G,
139  leda::list<leda::node>& A,
140  leda::list<leda::node>& B,
141  leda::node_map<int>& capacity,
142  leda::edge_map<int>& rank
143  );
144 
146  int NumPosts() const { return numPosts; }
147 
149  int NumApplicants() const { return numApplicants; }
150 
151  protected:
152  static const int default_seed = 13;
153 
154  int numApplicants;
155  int numPosts;
156 
157  int seedUsed;
158  leda::random_source randomSource; // random source
159  leda::random_source randomSourceI; // random source in integer mode
160 
161  std::map<int, leda::node> ApplicantToNode;
162  std::map<int, leda::node> PostToNode;
163 
164  void InitializeGraph( leda::graph& G,
165  leda::list<leda::node>& A,
166  leda::list<leda::node>& B,
167  leda::node_map<int>& capacity,
168  leda::edge_map<int>& rank );
169 
170  private:
171  virtual void GenerateEdges( leda::graph& G,
172  leda::list<leda::node>& A,
173  leda::list<leda::node>& B,
174  leda::node_map<int>& capacity,
175  leda::edge_map<int>& rank ) = 0;
176 
177  };
178 
201  {
202  public:
210  VSExponentialInstanceGenerator( int apps, int posts, double Density, double lambda ) :
211  StructuredInstanceGenerator( apps, posts ), EdgeProbability( Density ), Lambda( lambda )
212  {
213  assert( EdgeProbability >= 0.0 && EdgeProbability <= 1.0 );
214  }
215 
224  VSExponentialInstanceGenerator( int apps, int posts, double Density, double lambda, int seed ) :
225  StructuredInstanceGenerator( apps, posts, seed ), EdgeProbability( Density ), Lambda( lambda )
226  {
227  assert( EdgeProbability >= 0.0 && EdgeProbability <= 1.0 );
228  }
229 
231  {
232  }
233 
234  private:
235 
236  virtual void GenerateEdges( leda::graph& G,
237  leda::list<leda::node>& A,
238  leda::list<leda::node>& B,
239  leda::node_map<int>& capacity,
240  leda::edge_map<int>& rank );
241 
242  // probability of an edge beeing there
243  const double EdgeProbability;
244  const double Lambda;
245 
246  // private implementation
247  bool notIncreaseRank( int j );
248  };
249 
291  {
292  public:
299  FSExponentialInstanceGenerator( int apps, int posts, double lambda ) :
300  StructuredInstanceGenerator( apps, posts ), Lambda( lambda )
301  {
302  }
303 
311  FSExponentialInstanceGenerator( int apps, int posts, double lambda, int seed ) :
312  StructuredInstanceGenerator( apps, posts, seed ), Lambda( lambda )
313  {
314  }
315 
317  {
318  }
319 
320  private:
321 
322  virtual void GenerateEdges( leda::graph& G,
323  leda::list<leda::node>& A,
324  leda::list<leda::node>& B,
325  leda::node_map<int>& capacity,
326  leda::edge_map<int>& rank );
327 
328  const double Lambda;
329 
330  // private implementation
331  typedef std::set<int> Cluster;
332  typedef std::list< Cluster > Clustering;
333 
334  Clustering PartitionPosts( int n );
335  Clustering::const_iterator ChooseCluster( const Clustering& c );
336 
337  // private implementation
338  bool notIncreaseRank( int j );
339  };
340 
341 
342 
381  {
382  public:
391  HighlyCorrelatedInstanceGenerator( int apps, int posts, double Density, double TieProp, int capacity )
392  : StructuredInstanceGenerator( apps, posts ), EdgeProbability( Density ),
393  TieProbability( TieProp ), Capacity(capacity)
394  {
395  assert( EdgeProbability >= 0.0 && EdgeProbability <= 1.0 );
396  assert( TieProbability >= 0.0 && TieProbability <= 1.0 );
397  assert( Capacity >= 1 );
398  }
399 
409  HighlyCorrelatedInstanceGenerator( int apps, int posts, double Density, double TieProp, int capacity, int seed )
410  : StructuredInstanceGenerator( apps, posts, seed ), EdgeProbability( Density ),
411  TieProbability( TieProp ), Capacity( capacity )
412  {
413  assert( EdgeProbability >= 0.0 && EdgeProbability <= 1.0 );
414  assert( TieProbability >= 0.0 && TieProbability <= 1.0 );
415  assert( Capacity >= 1 );
416  }
417 
419  {
420  }
421 
422  private:
423 
424  virtual void GenerateEdges( leda::graph& G,
425  leda::list<leda::node>& A,
426  leda::list<leda::node>& B,
427  leda::node_map<int>& capacity,
428  leda::edge_map<int>& rank );
429 
430 
431  // probability of an edge beeing there
432  const double EdgeProbability;
433  // probability of an edge beeing tied to its predecessor
434  const double TieProbability;
435 
436  // fixed posts capacity
437  int Capacity;
438 
439  // get a random subset from the set {0,1,...,n-1}
440  void GetRandomSubset( int n, int k, leda::array<int>& a );
441  };
442 
443 
492  {
493  public:
502  RegionalInstanceGenerator( int apps, int posts, int capacity, int regions, double lambda )
503  : StructuredInstanceGenerator( apps, posts ),
504  Capacity(capacity), Regions(regions), Lambda(lambda)
505  {
506  assert( Capacity >= 1 );
507  assert( Regions >= 1 );
508  assert( Lambda > 0.0 );
509  }
510 
520  RegionalInstanceGenerator( int apps, int posts, int capacity, int regions, double lambda, int seed )
521  : StructuredInstanceGenerator( apps, posts, seed ),
522  Capacity(capacity), Regions(regions), Lambda(lambda)
523  {
524  assert( Capacity >= 1 );
525  assert( Regions >= 1 );
526  assert( Lambda > 0.0 );
527  }
528 
530  {
531  }
532 
533  private:
534 
535  // private implementation
536  typedef std::set<int> Cluster;
537  typedef std::vector< Cluster > Region;
538 
539  bool notIncreaseRank( int j );
540  void CreateRegion( Region& R, int& remainingPosts, int postsPerRegion, int& firstPostNumber );
541  void CreateRegions( std::vector<Region>& R, int regions, int posts );
542  int ChooseRegion( std::vector<Region>& R );
543 
544 
545  virtual void GenerateEdges( leda::graph& G,
546  leda::list<leda::node>& A,
547  leda::list<leda::node>& B,
548  leda::node_map<int>& capacity,
549  leda::edge_map<int>& rank );
550 
551 
552  // private
553  const int Capacity;
554  const int Regions;
555  const double Lambda;
556  };
557 
558 }
559 
560 #endif // LEP_GENERATOR_H
561 
562 /* ex: set ts=4 sw=4 sts=4 et: */
563 
564 
HighlyCorrelatedInstanceGenerator(int apps, int posts, double Density, double TieProp, int capacity)
Create a new generator.
Definition: generator.h:391
The main package namespace.
Definition: RANK_MAX_MATCHING.h:53
HighlyCorrelatedInstanceGenerator(int apps, int posts, double Density, double TieProp, int capacity, int seed)
Create a new generator.
Definition: generator.h:409
VSExponentialInstanceGenerator(int apps, int posts, double Density, double lambda, int seed)
Create a new generator.
Definition: generator.h:224
virtual ~StructuredInstanceGenerator()
Destructor.
int NumPosts() const
Definition: generator.h:146
RegionalInstanceGenerator(int apps, int posts, int capacity, int regions, double lambda)
Create a new generator.
Definition: generator.h:502
An fixed size "exponential" instance generator.
Definition: generator.h:290
FSExponentialInstanceGenerator(int apps, int posts, double lambda)
Create a new generator.
Definition: generator.h:299
FSExponentialInstanceGenerator(int apps, int posts, double lambda, int seed)
Create a new generator.
Definition: generator.h:311
RegionalInstanceGenerator(int apps, int posts, int capacity, int regions, double lambda, int seed)
Create a new generator.
Definition: generator.h:520
StructuredInstanceGenerator(int apps, int posts, int seed=default_seed)
Construct a structured random instance.
VSExponentialInstanceGenerator(int apps, int posts, double Density, double lambda)
Create a new generator.
Definition: generator.h:210
Regional instance generator.
Definition: generator.h:491
void GenerateGraph(leda::graph &G, leda::list< leda::node > &A, leda::list< leda::node > &B, leda::node_map< int > &capacity, leda::edge_map< int > &rank)
Generate a random structured instance.
void GenerateGML(std::ostream &o)
Generate a random structured instance in GML format.
An variable size "exponential" instance generator.
Definition: generator.h:200
A highly correlated instance generator.
Definition: generator.h:380
int NumApplicants() const
Definition: generator.h:149
An instance generator class.
Definition: generator.h:112