34#ifndef RECTANGLE_OVERLAP_LOGGING
35 #define RECTANGLE_OVERLAP_LOGGING 0
53 const std::vector<Constraint *> &heap2) {
54 heap1.insert(heap1.end(), heap2.begin(), heap2.end());
60 assert(std::is_heap(
heap.begin(),
heap.end(),
gt));
66 assert(std::is_heap(
heap.begin(),
heap.end(),
gt));
73 assert(std::is_heap(
heap.begin(),
heap.end(),
gt));
78void Block::addVariable(
Variable *v) {
103 in = setUpConstraintHeap(
true);
106 out = setUpConstraintHeap(
false);
109std::vector<Constraint *> Block::setUpConstraintHeap(
bool use_in) {
110 std::vector<Constraint *> h;
112 vector<Constraint*> *cs= use_in ? &v->
in : &v->
out;
115 if ((c->left->block !=
this && use_in) || (c->right->block !=
this && !use_in)) {
126 f<<
" merging on: "<<*c<<
",c->left->offset="<<c->
left->
offset<<
",c->right->offset="<<c->
right->
offset<<
"\n";
138 f<<
" merged block="<<(b->
deleted?*
this:*b)<<
"\n";
151 f<<
" merging: "<<*b<<
"dist="<<
dist<<
"\n";
168 f<<
" merging constraint heaps... \n";
182 vector<Constraint*> outOfDate;
183 while (!
in.empty()) {
190 f<<
" checking constraint ... "<<*v;
191 f<<
" timestamps: left="<<lb->
timeStamp<<
" right="<<rb->
timeStamp<<
" constraint="<<v->timeStamp<<
"\n";
197 f<<
" violated internal constraint found! "<<*v<<
"\n";
198 f<<
" lb="<<*lb<<
"\n";
199 f<<
" rb="<<*rb<<
"\n";
204 f<<
" ... skipping internal constraint\n";
209 outOfDate.push_back(v);
212 f<<
" reinserting out of date (reinsert later)\n";
230 if(
out.empty())
return nullptr;
234 if(
out.empty())
return nullptr;
260 if(canFollowRight(c,u)) {
261 dfdv+=c->lm=compute_dfdv(c->right,v,min_lm);
262 if(min_lm==
nullptr||c->lm<min_lm->
lm) min_lm=c;
266 if(canFollowLeft(c,u)) {
267 dfdv-=c->
lm=-compute_dfdv(c->left,v,min_lm);
268 if(min_lm==
nullptr||c->lm<min_lm->
lm) min_lm=c;
288 Direction dir =
NONE,
bool changedDirection =
false) {
292 if(canFollowLeft(c,u)) {
294 changedDirection =
true;
299 Pair p=compute_dfdv_between(r,c->left,v,
300 LEFT,changedDirection);
301 dfdv -= c->lm = -p.first;
307 if(canFollowRight(c,u)) {
309 changedDirection =
true;
314 Pair p=compute_dfdv_between(r,c->right,v,
315 RIGHT,changedDirection);
316 dfdv += c->lm = p.first;
318 m = changedDirection && c->
lm < p.second->lm
331 if(canFollowRight(c,u)) {
333 reset_active_lm(c->right,v);
337 if(canFollowLeft(c,u)) {
339 reset_active_lm(c->left,v);
349 reset_active_lm(
vars.front(),
nullptr);
350 compute_dfdv(
vars.front(),
nullptr,min_lm);
355 reset_active_lm(
vars.front(),
nullptr);
356 min_lm=compute_dfdv_between(rv,lv,
nullptr).second;
365 if (canFollowLeft(c,u))
366 populateSplitBlock(b, c->left, v);
369 if (canFollowRight(c,u))
370 populateSplitBlock(b, c->right, v);
382 f<<
" need to split between: "<<*vl<<
" and "<<*vr<<
"\n";
387 f<<
" going to split on: "<<*c<<
"\n";
414 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.