Adaptagrams
solve_VPSC.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libvpsc - A solver for the problem of Variable Placement with
5  * Separation Constraints.
6  *
7  * Copyright (C) 2005-2013 Monash University
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  * See the file LICENSE.LGPL distributed with the library.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * Author(s): Tim Dwyer
20  * Michael Wybrow
21 */
22 
23 //
24 // TODO: Really, we should have three classes: VPSC, IncrementalVPSC and
25 // StaticVPSC, where the latter two inherit from VPSC. StaticVPSC would be
26 // the equivalent of what is currently VPSC.
27 // Also, a lot of the code specific to one or other of these concrete
28 // implementations should be moved from Block and Blocks: e.g. mergeLeft etc.
29 //
30 #ifndef VPSC_SOLVE_VPSC_H
31 #define VPSC_SOLVE_VPSC_H
32 
33 #include <vector>
34 
42 namespace vpsc {
43 class Variable;
44 typedef std::vector<Variable*> Variables;
45 class Constraint;
46 class Blocks;
47 typedef std::vector<Constraint*> Constraints;
48 
60 class Solver {
61 public:
65  virtual bool satisfy();
69  virtual bool solve();
70 
71  Solver(Variables const &vs, Constraints const &cs);
72  virtual ~Solver();
75  Variables const & getVariables() { return vs; }
76 protected:
77  Blocks *bs;
78  size_t m;
79  std::vector<Constraint*> const &cs;
80  size_t n;
81  std::vector<Variable*> const &vs;
82  bool needsScaling;
83 
84  void printBlocks();
85  void copyResult();
86 private:
87  void refine();
88  bool constraintGraphIsCyclic(const unsigned n, Variable* const vs[]);
89  bool blockGraphIsCyclic();
90 };
91 
105 class IncSolver : public Solver {
106 public:
107  IncSolver(Variables const &vs, Constraints const &cs);
110  bool satisfy();
114  bool solve();
118  void addConstraint(Constraint *constraint);
119 private:
120  void moveBlocks();
121  void splitBlocks();
122 
123  unsigned splitCnt;
124  Constraints inactive;
125  Constraints violated;
126  Constraint* mostViolated(Constraints &l);
127 };
128 
129 }
130 #endif // VPSC_SOLVE_VPSC_H
A variable is comprised of an ideal position, final position and a weight.
Definition: variable.h:44
Incremental solver for Variable Placement with Separation Constraints problem instance.
Definition: solve_VPSC.h:105
virtual bool satisfy()
Results in an approximate solution subject to the constraints.
Definition: solve_VPSC.cpp:132
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
Definition: assertions.h:61
void copyResult()
Definition: solve_VPSC.cpp:115
Static solver for Variable Placement with Separation Constraints problem instance.
Definition: solve_VPSC.h:60
std::vector< Variable * > Variables
A vector of pointers to Variable objects.
Definition: constraint.h:38
std::vector< Constraint * > Constraints
A vector of pointers to Constraint objects.
Definition: constraint.h:125
A constraint determines a minimum or exact spacing required between two Variable objects.
Definition: constraint.h:44
Variables const & getVariables()
Returns the Variables in this problem instance.
Definition: solve_VPSC.h:75
bool solve()
Results in an optimum solution subject to the constraints.
Definition: solve_VPSC.cpp:212
bool satisfy()
Results in an approximate solution subject to the constraints.
Definition: solve_VPSC.cpp:243
virtual bool solve()
Results in an optimum solution subject to the constraints.
Definition: solve_VPSC.cpp:205
void addConstraint(Constraint *constraint)
Adds a constraint to the existing VPSC solver.
Definition: solve_VPSC.cpp:87