Adaptagrams
block.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-2008 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 */
21 
22 /*
23  * \brief A block is a group of variables that must be moved together to improve
24  * the goal function without violating already active constraints.
25  * The variables in a block are spanned by a tree of active constraints.
26  */
27 
28 #ifndef VPSC_BLOCK_H
29 #define VPSC_BLOCK_H
30 
31 #include <iostream>
32 #include <vector>
33 
34 template <class T, class TCompare> class PairingHeap;
35 
36 namespace vpsc {
37 class Variable;
38 class Constraint;
39 class CompareConstraints;
40 class Blocks;
41 
42 struct PositionStats {
43  PositionStats() : scale(0), AB(0), AD(0), A2(0) {}
44  void addVariable(Variable* const v);
45  double scale;
46  double AB;
47  double AD;
48  double A2;
49 };
50 
51 class Block
52 {
53  typedef std::vector<Variable*> Variables;
54  typedef std::vector<Constraint*> Constraints;
55  typedef Variables::iterator Vit;
56  typedef Constraints::iterator Cit;
57  typedef Constraints::const_iterator Cit_const;
58 
59  friend std::ostream& operator <<(std::ostream &os,const Block &b);
60 public:
61  Variables *vars;
62  double posn;
63  //double weight;
64  //double wposn;
65  PositionStats ps;
66  Block(Blocks *blocks, Variable* const v=nullptr);
67  ~Block(void);
68  Constraint* findMinLM();
69  Constraint* findMinLMBetween(Variable* const lv, Variable* const rv);
70  Constraint* findMinInConstraint();
71  Constraint* findMinOutConstraint();
72  void deleteMinInConstraint();
73  void deleteMinOutConstraint();
74  void updateWeightedPosition();
75  void merge(Block *b, Constraint *c, double dist);
76  Block* merge(Block *b, Constraint *c);
77  void mergeIn(Block *b);
78  void mergeOut(Block *b);
79  void split(Block *&l, Block *&r, Constraint *c);
80  Constraint* splitBetween(Variable* vl, Variable* vr, Block* &lb, Block* &rb);
81  void setUpInConstraints();
82  void setUpOutConstraints();
83  double cost();
84  bool deleted;
85  long timeStamp;
86  PairingHeap<Constraint*,CompareConstraints> *in;
87  PairingHeap<Constraint*,CompareConstraints> *out;
88  bool getActivePathBetween(Constraints& path, Variable const* u,
89  Variable const* v, Variable const *w) const;
90  bool isActiveDirectedPathBetween(
91  Variable const* u, Variable const* v) const;
92  bool getActiveDirectedPathBetween(Constraints& path, Variable const * u, Variable const * v) const;
93 private:
94  typedef enum {NONE, LEFT, RIGHT} Direction;
95  typedef std::pair<double, Constraint*> Pair;
96  void reset_active_lm(Variable* const v, Variable* const u);
97  void list_active(Variable* const v, Variable* const u);
98  double compute_dfdv(Variable* const v, Variable* const u);
99  double compute_dfdv(Variable* const v, Variable* const u, Constraint *&min_lm);
100  bool split_path(Variable*, Variable* const, Variable* const,
101  Constraint* &min_lm, bool desperation);
102  bool canFollowLeft(Constraint const* c, Variable const* last) const;
103  bool canFollowRight(Constraint const* c, Variable const* last) const;
104  void populateSplitBlock(Block *b, Variable* v, Variable const* u);
105  void addVariable(Variable* v);
106  void setUpConstraintHeap(PairingHeap<Constraint*,CompareConstraints>* &h,bool in);
107 
108  // Parent container, that holds the blockTimeCtr.
109  Blocks *blocks;
110 };
111 }
112 
113 #endif // VPSC_BLOCK_H
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
Definition: assertions.h:61
std::vector< Variable * > Variables
A vector of pointers to Variable objects.
Definition: constraint.h:38
std::vector< Constraint * > Constraints
A vector of pointers to Constraint objects.
Definition: constraint.h:125
No constraint:
Lateral constraints imply only a separation: