Adaptagrams
blocks.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libvpsc - A solver for the problem of Variable Placement with
5  * Separation Constraints.
6  *
7  * Copyright (C) 2005-2012 Monash University
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  * See the file LICENSE.LGPL distributed with the library.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * Author(s): Tim Dwyer
20  * Michael Wybrow
21 */
22 
23 /*
24  * @brief A block structure defined over the variables
25  *
26  * A block structure defined over the variables such that each block contains
27  * 1 or more variables, with the invariant that all constraints inside a block
28  * are satisfied by keeping the variables fixed relative to one another
29  *
30  */
31 
32 #ifndef VPSC_BLOCKS_H
33 #define VPSC_BLOCKS_H
34 
35 #ifdef LIBVPSC_LOGGING
36 #define LOGFILE "libvpsc.log"
37 #endif
38 
39 #include <list>
40 #include <vector>
41 
42 // size_t is strangely not defined on some older MinGW GCC versions.
43 #include <cstddef>
44 
45 namespace vpsc {
46 class Block;
47 class Variable;
48 class Constraint;
49 /*
50  * A block structure defined over the variables such that each block contains
51  * 1 or more variables, with the invariant that all constraints inside a block
52  * are satisfied by keeping the variables fixed relative to one another
53  */
54 class Blocks
55 {
56 public:
57  Blocks(std::vector<Variable*> const &vs);
58  ~Blocks(void);
59  void mergeLeft(Block *r);
60  void mergeRight(Block *l);
61  void split(Block *b, Block *&l, Block *&r, Constraint *c);
62  std::list<Variable*> *totalOrder();
63  void cleanup();
64  double cost();
65 
66  size_t size() const;
67  Block *at(size_t index) const;
68  void insert(Block *block);
69 
70  long blockTimeCtr;
71 private:
72  void dfsVisit(Variable *v, std::list<Variable*> *order);
73  void removeBlock(Block *doomed);
74 
75  std::vector<Block*> m_blocks;
76  std::vector<Variable*> const &vs;
77  size_t nvs;
78 };
79 
80 inline size_t Blocks::size() const
81 {
82  return m_blocks.size();
83 }
84 
85 inline Block *Blocks::at(size_t index) const
86 {
87  return m_blocks[index];
88 }
89 
90 inline void Blocks::insert(Block *block)
91 {
92  m_blocks.push_back(block);
93 }
94 
95 }
96 #endif // VPSC_BLOCKS_H
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
Definition: assertions.h:61