32#ifndef RECTANGLE_OVERLAP_LOGGING
33 #define RECTANGLE_OVERLAP_LOGGING 0
51 const std::vector<Constraint *> &heap2) {
52 heap1.insert(heap1.end(), heap2.begin(), heap2.end());
58 assert(std::is_heap(
heap.begin(),
heap.end(),
gt));
64 assert(std::is_heap(
heap.begin(),
heap.end(),
gt));
71 assert(std::is_heap(
heap.begin(),
heap.end(),
gt));
76void Block::addVariable(
Variable *v) {
101 in = setUpConstraintHeap(
true);
104 out = setUpConstraintHeap(
false);
107std::vector<Constraint *> Block::setUpConstraintHeap(
bool use_in) {
108 std::vector<Constraint *> h;
110 vector<Constraint*> *cs= use_in ? &v->
in : &v->
out;
113 if ((c->left->block !=
this && use_in) || (c->right->block !=
this && !use_in)) {
124 f<<
" merging on: "<<*c<<
",c->left->offset="<<c->
left->
offset<<
",c->right->offset="<<c->
right->
offset<<
"\n";
136 f<<
" merged block="<<(b->
deleted?*
this:*b)<<
"\n";
149 f<<
" merging: "<<*b<<
"dist="<<
dist<<
"\n";
166 f<<
" merging constraint heaps... \n";
180 vector<Constraint*> outOfDate;
181 while (!
in.empty()) {
188 f<<
" checking constraint ... "<<*v;
189 f<<
" timestamps: left="<<lb->
timeStamp<<
" right="<<rb->
timeStamp<<
" constraint="<<v->timeStamp<<
"\n";
195 f<<
" violated internal constraint found! "<<*v<<
"\n";
196 f<<
" lb="<<*lb<<
"\n";
197 f<<
" rb="<<*rb<<
"\n";
202 f<<
" ... skipping internal constraint\n";
207 outOfDate.push_back(v);
210 f<<
" reinserting out of date (reinsert later)\n";
228 if(
out.empty())
return nullptr;
232 if(
out.empty())
return nullptr;
258 if(canFollowRight(c,u)) {
259 dfdv+=c->lm=compute_dfdv(c->right,v,min_lm);
260 if(min_lm==
nullptr||c->lm<min_lm->
lm) min_lm=c;
264 if(canFollowLeft(c,u)) {
265 dfdv-=c->
lm=-compute_dfdv(c->left,v,min_lm);
266 if(min_lm==
nullptr||c->lm<min_lm->
lm) min_lm=c;
286 Direction dir =
NONE,
bool changedDirection =
false) {
290 if(canFollowLeft(c,u)) {
292 changedDirection =
true;
297 Pair p=compute_dfdv_between(r,c->left,v,
298 LEFT,changedDirection);
299 dfdv -= c->lm = -p.first;
305 if(canFollowRight(c,u)) {
307 changedDirection =
true;
312 Pair p=compute_dfdv_between(r,c->right,v,
313 RIGHT,changedDirection);
314 dfdv += c->lm = p.first;
316 m = changedDirection && c->
lm < p.second->lm
329 if(canFollowRight(c,u)) {
331 reset_active_lm(c->right,v);
335 if(canFollowLeft(c,u)) {
337 reset_active_lm(c->left,v);
347 reset_active_lm(
vars.front(),
nullptr);
348 compute_dfdv(
vars.front(),
nullptr,min_lm);
353 reset_active_lm(
vars.front(),
nullptr);
354 min_lm=compute_dfdv_between(rv,lv,
nullptr).second;
363 if (canFollowLeft(c,u))
364 populateSplitBlock(b, c->left, v);
367 if (canFollowRight(c,u))
368 populateSplitBlock(b, c->right, v);
380 f<<
" need to split between: "<<*vl<<
" and "<<*vr<<
"\n";
385 f<<
" going to split on: "<<*c<<
"\n";
412 c += v->
weight * diff * diff;
static agxbuf last
last message
std::ostream & operator<<(std::ostream &os, const Block &b)
static Constraint * findMin(std::vector< Constraint * > &heap)
get the minimum heap element
static void make_heap(std::vector< Constraint * > &heap)
#define RECTANGLE_OVERLAP_LOGGING
static void insert(std::vector< Constraint * > &heap, Constraint *c)
add an item to a heap
static void deleteMin(std::vector< Constraint * > &heap)
remove the minimum heap element
static void merge_heaps(std::vector< Constraint * > &heap1, const std::vector< Constraint * > &heap2)
add all elements from heap2 into the heap heap1
static bool gt(const Constraint *const lhs, const Constraint *const rhs)
> comparator for constraints
#define LOGFILE
A block structure defined over the variables.
std::vector< Constraint * > out
Constraint * findMinInConstraint()
std::vector< Variable * > vars
void split(Block *&l, Block *&r, Constraint *c)
Constraint * splitBetween(Variable *vl, Variable *vr, Block *&lb, Block *&rb)
void deleteMinOutConstraint()
Block(Variable *v=nullptr)
std::vector< Constraint * > in
void setUpOutConstraints()
void setUpInConstraints()
double desiredWeightedPosition()
Constraint * findMinOutConstraint()
void merge(Block *b, Constraint *c, double dist)
void deleteMinInConstraint()
Constraint * findMinLMBetween(Variable *lv, Variable *rv)
static void insert(PairHeap *h, Pair edge)
static bool compareConstraints(const Constraint *const l, const Constraint *const r)
static double dist(int dim, double *x, double *y)
A constraint determines a minimum or exact spacing required between two variables.