Adaptagrams
variable.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-2008 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 */
21 
22 #ifndef VPSC_VARIABLE_H
23 #define VPSC_VARIABLE_H
24 
25 #include <vector>
26 #include <iostream>
27 
28 #include "libvpsc/block.h"
29 #include "libvpsc/assertions.h"
30 
31 namespace vpsc {
32 
33 class Constraint;
34 typedef std::vector<Constraint*> Constraints;
35 
44 class Variable
45 {
46  friend std::ostream& operator <<(std::ostream &os, const Variable &v);
47  friend class Block;
48  friend class Constraint;
49  friend class Solver;
50 public:
51  int id; // useful in log files
52  double desiredPosition;
53  double finalPosition;
54  double weight; // how much the variable wants to
55  // be at it's desired position
56  double scale; // translates variable to another space
57  double offset;
58  Block *block;
59  bool visited;
60  bool fixedDesiredPosition;
61  Constraints in;
62  Constraints out;
63  char *toString();
64  inline Variable(const int id, const double desiredPos=-1.0,
65  const double weight=1.0, const double scale=1.0)
66  : id(id)
67  , desiredPosition(desiredPos)
68  , finalPosition(desiredPos)
69  , weight(weight)
70  , scale(scale)
71  , offset(0)
72  , block(nullptr)
73  , visited(false)
74  , fixedDesiredPosition(false)
75  {
76  }
77  double dfdv(void) const {
78  return 2. * weight * ( position() - desiredPosition );
79  }
80 private:
81  inline double position(void) const {
82  return (block->ps.scale*block->posn+offset)/scale;
83  }
84  inline double unscaledPosition(void) const {
85  COLA_ASSERT(block->ps.scale == 1);
86  COLA_ASSERT(scale == 1);
87  return block->posn + offset;
88  }
89 };
90 
92 typedef std::vector<Variable*> Variables;
93 
94 }
95 #endif // VPSC_VARIABLE_H
A variable is comprised of an ideal position, final position and a weight.
Definition: variable.h:44
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
Definition: assertions.h:61
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