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