32using std::ostringstream;
36#ifndef RECTANGLE_OVERLAP_LOGGING
37 #define RECTANGLE_OVERLAP_LOGGING 0
42 :
VPSC(n, vs, m_, cs_) {
43 inactive.assign(cs_, cs_ + m_);
51 : bs(n, vs), cs(cs_), m(m_) {
54 assert(!constraintGraphIsCyclic(n,vs));
65 for(
unsigned i=0;i<
m;i++) {
83 if(!v->block->deleted) {
88 for(
unsigned i=0;i<
m;i++) {
89 if(
cs[i]->slack()<-0.0000001) {
92 f<<
"Error: Unsatisfied constraint: "<<*
cs[i]<<
"\n";
95 throw "Unsatisfied constraint";
101 for (
bool solved =
false; !solved;) {
104 b->setUpInConstraints();
105 b->setUpOutConstraints();
109 if(c!=
nullptr && c->
lm<0) {
112 f<<
"Split on constraint: "<<*c<<
"\n";
115 Block *l=
nullptr, *r=
nullptr;
124 for(
unsigned i=0;i<
m;i++) {
125 if(
cs[i]->slack()<-0.0000001) {
126 assert(
cs[i]->slack()>-0.0000001);
127 throw "Unsatisfied constraint";
145 f<<
"solve_inc()...\n";
147 double lastcost,cost =
bs.
cost();
155 f<<
" cost="<<cost<<
"\n";
157 }
while(fabs(lastcost-cost)>0.0001);
175 f<<
"satisfy_inc()...\n";
180 while(mostViolated(inactive,v)<-0.0000001) {
186 if(splitCtr++>10000) {
187 throw "Cycle Error!";
197 f<<
" finished merges.\n";
200 for(
unsigned i=0;i<
m;i++) {
202 if(v->
slack()<-0.0000001) {
205 s<<
"Unsatisfied constraint: "<<*v;
206 throw s.str().c_str();
211 f<<
" finished cleanup.\n";
218 f<<
"moveBlocks()...\n";
221 b->wposn = b->desiredWeightedPosition();
222 b->posn = b->wposn / b->weight;
226 f<<
" moved blocks.\n";
235 if(v!=
nullptr && v->
lm < -0.0000001) {
238 f<<
" found split point: "<<*v<<
" lm="<<v->
lm<<
"\n";
243 double pos = b2->
posn;
246 l->wposn = l->posn * l->weight;
247 r->wposn = r->posn * r->weight;
251 inactive.push_back(v);
254 f<<
" new blocks: "<<*l<<
" and "<<*r<<
"\n";
260 f<<
" finished splits.\n";
269double IncVPSC::mostViolated(ConstraintList &l,
Constraint* &v) {
270 double minSlack = DBL_MAX;
273 f<<
"Looking for most violated...\n";
275 ConstraintList::iterator end = l.end();
276 ConstraintList::iterator deletePoint = end;
277 for(ConstraintList::iterator i=l.begin();i!=end;i++) {
279 double slack = c->
slack();
280 if (slack < minSlack) {
290 if(deletePoint != end && minSlack<-0.0000001) {
291 *deletePoint = l[l.size()-1];
292 l.resize(l.size()-1);
296 f<<
" most violated is: "<<*v<<
"\n";
309bool VPSC::constraintGraphIsCyclic(
const unsigned n,
Variable *vs[]) {
310 map<Variable*, node*> varmap;
311 vector<std::unique_ptr<node>>
graph;
312 for(
unsigned i=0;i<n;i++) {
314 varmap[vs[i]]=
graph.back().get();
316 for(
unsigned i=0;i<n;i++) {
319 varmap[vs[i]]->
in.insert(varmap[l]);
324 varmap[vs[i]]->
out.insert(varmap[r]);
327 while(!
graph.empty()) {
329 vector<std::unique_ptr<node>>::iterator i=
graph.begin();
330 for(;i!=
graph.end();i++) {
350bool VPSC::blockGraphIsCyclic() {
351 map<Block*, node*> bmap;
352 vector<std::unique_ptr<node>>
graph;
355 bmap[b]=
graph.back().get();
358 b->setUpInConstraints();
362 bmap[b]->
in.insert(bmap[l]);
363 b->deleteMinInConstraint();
364 c=b->findMinInConstraint();
367 b->setUpOutConstraints();
368 c=b->findMinOutConstraint();
371 bmap[b]->
out.insert(bmap[r]);
372 b->deleteMinOutConstraint();
373 c=b->findMinOutConstraint();
376 while(!
graph.empty()) {
378 vector<std::unique_ptr<node>>::iterator i=
graph.begin();
379 for(;i!=
graph.end();i++) {
static void out(agerrlevel_t level, const char *fmt, va_list args)
Report messages using a user-supplied or default write function.
#define RECTANGLE_OVERLAP_LOGGING
#define LOGFILE
A block structure defined over the variables.
std::vector< Constraint * > out
void split(Block *&l, Block *&r, Constraint *c)
Constraint * splitBetween(Variable *vl, Variable *vr, Block *&lb, Block *&rb)
std::vector< Constraint * > in
void merge(Block *b, Constraint *c, double dist)
void split(Block *b, Block *&l, Block *&r, Constraint *c)
std::list< Variable * > totalOrder()
Agraph_t * graph(char *name)
A constraint determines a minimum or exact spacing required between two variables.
IncVPSC(const unsigned n, Variable *vs[], const unsigned m, Constraint *cs[])
VPSC(const unsigned n, Variable *vs[], const unsigned m, Constraint *cs[])