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 #include "constraint.h"
14 #include <cassert>
15 Constraint::Constraint(Variable *left, Variable *right, double gap, bool equality)
16 : left(left),
17 right(right),
18 gap(gap),
19 timeStamp(0),
20 active(false),
21 visited(false),
22 equality(equality)
23 {
24 left->out.push_back(this);
25 right->in.push_back(this);
26 }
27 Constraint::~Constraint() {
28 Constraints::iterator i;
29 for(i=left->out.begin(); i!=left->out.end(); i++) {
30 if(*i==this) break;
31 }
32 left->out.erase(i);
33 for(i=right->in.begin(); i!=right->in.end(); i++) {
34 if(*i==this) break;
35 }
36 right->in.erase(i);
37 }
38 std::ostream& operator <<(std::ostream &os, const Constraint &c)
39 {
40 if(&c==NULL) {
41 os<<"NULL";
42 } else {
43 const char *type=c.equality?"=":"<=";
44 os<<*c.left<<"+"<<c.gap<<type<<*c.right<<"("<<c.slack()<<")"<<(c.active?"-active":"");
45 }
46 return os;
47 }