Debian Codegraph @

lib/vpsc/constraint.h

raw
1 /**
2 * \brief A constraint determines a minimum or exact spacing required between
3 * two variables.
4 *
5 * Authors:
6 * Tim Dwyer <[email protected]>
7 *
8 * Copyright (C) 2005 Authors
9 *
10 * This version is released under the CPL (Common Public License) with
11 * the Graphviz distribution.
12 * A version is also available under the LGPL as part of the Adaptagrams
13 * project: https://github.com/mjwybrow/adaptagrams.
14 * If you make improvements or bug fixes to this code it would be much
15 * appreciated if you could also contribute those changes back to the
16 * Adaptagrams repository.
17 */
18
19 #pragma once
20
21 #include <iostream>
22 #include <vpsc/variable.h>
23
24 struct Constraint
25 {
26 friend std::ostream& operator <<(std::ostream &os,const Constraint &c);
27 public:
28 Variable *left;
29 Variable *right;
30 double gap;
31 double lm;
32 Constraint(Variable *left, Variable *right, double gap);
33 ~Constraint();
34 double slack() const { return right->position() - gap - left->position(); }
35 long timeStamp;
36 bool active;
37 bool visited;
38 };
39 #include <float.h>
40 #include <vpsc/block.h>
41 static inline bool compareConstraints(const Constraint *const l,
42 const Constraint *const r) {
43 double const sl =
44 l->left->block->timeStamp > l->timeStamp
45 ||l->left->block==l->right->block
46 ?-DBL_MAX:l->slack();
47 double const sr =
48 r->left->block->timeStamp > r->timeStamp
49 ||r->left->block==r->right->block
50 ?-DBL_MAX:r->slack();
51 if(sl==sr) {
52 // arbitrary choice based on id
53 if(l->left->id==r->left->id) {
54 if(l->right->id<r->right->id) return true;
55 return false;
56 }
57 if(l->left->id<r->left->id) return true;
58 return false;
59 }
60 return sl < sr;
61 }