Debian Codegraph @

lib/vpsc/block.h

raw
1 /**
2 * \brief A block is a group of variables that must be moved together to improve
3 * the goal function without violating already active constraints.
4 * The variables in a block are spanned by a tree of active constraints.
5 *
6 * Authors:
7 * Tim Dwyer <[email protected]>
8 *
9 * Copyright (C) 2005 Authors
10 *
11 * This version is released under the CPL (Common Public License) with
12 * the Graphviz distribution.
13 * A version is also available under the LGPL as part of the Adaptagrams
14 * project: https://github.com/mjwybrow/adaptagrams.
15 * If you make improvements or bug fixes to this code it would be much
16 * appreciated if you could also contribute those changes back to the
17 * Adaptagrams repository.
18 */
19
20 #pragma once
21
22 #include <vector>
23 #include <iostream>
24 struct Variable;
25 struct Constraint;
26
27 class Block
28 {
29 friend std::ostream& operator <<(std::ostream &os,const Block &b);
30 public:
31 std::vector<Variable*> vars;
32 double posn;
33 double weight;
34 double wposn;
35 Block(Variable *v=nullptr);
36 Block(const Block &) = delete;
37 Constraint* findMinLM();
38 Constraint* findMinLMBetween(Variable* lv, Variable* rv);
39 Constraint* findMinInConstraint();
40 Constraint* findMinOutConstraint();
41 void deleteMinInConstraint();
42 void deleteMinOutConstraint();
43 double desiredWeightedPosition();
44 void merge(Block *b, Constraint *c, double dist);
45 void merge(Block *b, Constraint *c);
46 void mergeIn(Block *b);
47 void mergeOut(Block *b);
48 void split(Block *&l, Block *&r, Constraint *c);
49 Constraint* splitBetween(Variable* vl, Variable* vr, Block* &lb, Block* &rb);
50 void setUpInConstraints();
51 void setUpOutConstraints();
52 double cost();
53 bool deleted;
54 long timeStamp;
55 std::vector<Constraint *> in;
56 std::vector<Constraint *> out;
57 private:
58 typedef enum {NONE, LEFT, RIGHT} Direction;
59 typedef std::pair<double, Constraint*> Pair;
60 void reset_active_lm(Variable *v, Variable *u);
61 double compute_dfdv(Variable *v, Variable *u, Constraint *&min_lm);
62 Pair compute_dfdv_between(
63 Variable*, Variable*, Variable*, Direction, bool);
64 bool canFollowLeft(const Constraint *c, const Variable *last);
65 bool canFollowRight(const Constraint *c, const Variable *last);
66 void populateSplitBlock(Block *b, Variable *v, Variable *u);
67 void addVariable(Variable *v);
68 std::vector<Constraint *> setUpConstraintHeap(bool use_in);
69 };