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"
19 class Constraint
20 {
21 friend std::ostream& operator <<(std::ostream &os,const Constraint &c);
22 public:
23 Variable *left;
24 Variable *right;
25 double gap;
26 double lm;
27 Constraint(Variable *left, Variable *right, double gap, bool equality=false);
28 ~Constraint();
29 inline double slack() const { return right->position() - gap - left->position(); }
30 long timeStamp;
31 bool active;
32 bool visited;
33 bool equality;
34 };
35 #include <float.h>
36 #include "block.h"
37 static inline bool compareConstraints(Constraint *const &l, Constraint *const &r) {
38 double const sl =
39 l->left->block->timeStamp > l->timeStamp
40 ||l->left->block==l->right->block
41 ?-DBL_MAX:l->slack();
42 double const sr =
43 r->left->block->timeStamp > r->timeStamp
44 ||r->left->block==r->right->block
45 ?-DBL_MAX:r->slack();
46 if(sl==sr) {
47 // arbitrary choice based on id
48 if(l->left->id==r->left->id) {
49 if(l->right->id<r->right->id) return true;
50 return false;
51 }
52 if(l->left->id<r->left->id) return true;
53 return false;
54 }
55 return sl < sr;
56 }
58 #endif // SEEN_REMOVEOVERLAP_CONSTRAINT_H