solve_VPSC.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * \brief Solve an instance of the "Variable Placement with Separation
  3. * Constraints" problem.
  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. #pragma once
  19. #include <vector>
  20. #include <vpsc/blocks.h>
  21. struct Variable;
  22. struct Constraint;
  23. class Blocks;
  24. /**
  25. * Variable Placement with Separation Constraints problem instance
  26. */
  27. struct VPSC {
  28. public:
  29. virtual void satisfy();
  30. virtual void solve();
  31. VPSC(const unsigned n, Variable *vs[], const unsigned m, Constraint *cs[]);
  32. virtual ~VPSC() = default;
  33. protected:
  34. Blocks bs;
  35. Constraint **cs;
  36. unsigned m;
  37. void printBlocks();
  38. private:
  39. void refine();
  40. bool constraintGraphIsCyclic(const unsigned n, Variable *vs[]);
  41. bool blockGraphIsCyclic();
  42. };
  43. struct IncVPSC : VPSC {
  44. public:
  45. unsigned splitCnt;
  46. void satisfy();
  47. void solve();
  48. void moveBlocks();
  49. void splitBlocks();
  50. IncVPSC(const unsigned n, Variable *vs[], const unsigned m, Constraint *cs[]);
  51. private:
  52. typedef std::vector<Constraint*> ConstraintList;
  53. ConstraintList inactive;
  54. double mostViolated(ConstraintList &l,Constraint* &v);
  55. };