1 /**
2 * \brief A constraint determines a minimum or exact spacing required between
3 * two variables.
4 *
5 * Authors:
6 * Tim Dwyer <tgdwyer@gmail.com>
7 *
8 * Copyright (C) 2005 Authors
9 *
10 * Released under GNU LGPL. Read the file 'COPYING' for more information.
11 */
13 #ifndef SEEN_REMOVEOVERLAP_CONSTRAINT_H
14 #define SEEN_REMOVEOVERLAP_CONSTRAINT_H
16 #include <iostream>
17 #include "variable.h"
18 namespace vpsc {
20 class Constraint
21 {
22 friend std::ostream& operator <<(std::ostream &os,const Constraint &c);
23 public:
24 Variable *left;
25 Variable *right;
26 double gap;
27 double lm;
28 Constraint(Variable *left, Variable *right, double gap, bool equality=false);
29 virtual ~Constraint();
30 inline double slack() const { return right->position() - gap - left->position(); }
31 long timeStamp;
32 bool active;
33 bool visited;
34 bool equality;
35 };
36 #include <float.h>
37 #include "block.h"
38 static inline bool compareConstraints(Constraint *const &l, Constraint *const &r) {
39 double const sl =
40 l->left->block->timeStamp > l->timeStamp
41 ||l->left->block==l->right->block
42 ?-DBL_MAX:l->slack();
43 double const sr =
44 r->left->block->timeStamp > r->timeStamp
45 ||r->left->block==r->right->block
46 ?-DBL_MAX:r->slack();
47 if(sl==sr) {
48 // arbitrary choice based on id
49 if(l->left->id==r->left->id) {
50 if(l->right->id<r->right->id) return true;
51 return false;
52 }
53 if(l->left->id<r->left->id) return true;
54 return false;
55 }
56 return sl < sr;
57 }
58 }
60 #endif // SEEN_REMOVEOVERLAP_CONSTRAINT_H