constraint.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include <vpsc/constraint.h>
  19. #include <cassert>
  20. Constraint::Constraint(Variable *left_, Variable *right_, double gap_)
  21. : left(left_), right(right_), gap(gap_), timeStamp(0), active(false),
  22. visited(false) {
  23. left->out.push_back(this);
  24. right->in.push_back(this);
  25. }
  26. Constraint::~Constraint() {
  27. Constraints::iterator i;
  28. for(i=left->out.begin(); i!=left->out.end(); i++) {
  29. if(*i==this) break;
  30. }
  31. left->out.erase(i);
  32. for(i=right->in.begin(); i!=right->in.end(); i++) {
  33. if(*i==this) break;
  34. }
  35. right->in.erase(i);
  36. }
  37. std::ostream& operator <<(std::ostream &os, const Constraint &c)
  38. {
  39. os<<*c.left<<"+"<<c.gap<<"<="<<*c.right<<"("<<c.slack()<<")"<<(c.active?"-active":"");
  40. return os;
  41. }