35using std::ostringstream;
39#ifndef RECTANGLE_OVERLAP_LOGGING
40 #define RECTANGLE_OVERLAP_LOGGING 0
45 :
VPSC(n, vs, m_, cs_) {
46 inactive.assign(cs_, cs_ + m_);
54 : bs(n, vs), cs(cs_), m(m_) {
57 assert(!constraintGraphIsCyclic(n,vs));
68 for(
unsigned i=0;i<
m;i++) {
86 if(!v->block->deleted) {
91 for(
unsigned i=0;i<
m;i++) {
92 if(
cs[i]->slack()<-0.0000001) {
95 f<<
"Error: Unsatisfied constraint: "<<*
cs[i]<<
"\n";
98 throw std::runtime_error(
"Unsatisfied constraint");
104 for (
bool solved =
false; !solved;) {
107 b->setUpInConstraints();
108 b->setUpOutConstraints();
112 if(c!=
nullptr && c->
lm<0) {
115 f<<
"Split on constraint: "<<*c<<
"\n";
118 Block *l=
nullptr, *r=
nullptr;
127 for(
unsigned i=0;i<
m;i++) {
128 if(
cs[i]->slack()<-0.0000001) {
129 assert(
cs[i]->slack()>-0.0000001);
130 throw std::runtime_error(
"Unsatisfied constraint");
148 f<<
"solve_inc()...\n";
150 double lastcost,cost =
bs.
cost();
158 f<<
" cost="<<cost<<
"\n";
160 }
while(fabs(lastcost-cost)>0.0001);
178 f<<
"satisfy_inc()...\n";
183 while(mostViolated(inactive,v)<-0.0000001) {
189 if(splitCtr++>10000) {
190 throw std::runtime_error(
"Cycle Error!");
200 f<<
" finished merges.\n";
203 for(
unsigned i=0;i<
m;i++) {
205 if(v->
slack()<-0.0000001) {
208 s<<
"Unsatisfied constraint: "<<*v;
209 throw std::runtime_error(
s.str());
214 f<<
" finished cleanup.\n";
221 f<<
"moveBlocks()...\n";
224 b->wposn = b->desiredWeightedPosition();
225 b->posn = b->wposn / b->weight;
229 f<<
" moved blocks.\n";
238 if(v!=
nullptr && v->
lm < -0.0000001) {
241 f<<
" found split point: "<<*v<<
" lm="<<v->
lm<<
"\n";
246 double pos = b2->
posn;
249 l->wposn = l->posn * l->weight;
250 r->wposn = r->posn * r->weight;
254 inactive.push_back(v);
257 f<<
" new blocks: "<<*l<<
" and "<<*r<<
"\n";
263 f<<
" finished splits.\n";
272double IncVPSC::mostViolated(ConstraintList &l,
Constraint* &v) {
273 double minSlack = DBL_MAX;
276 f<<
"Looking for most violated...\n";
278 ConstraintList::iterator end = l.end();
279 ConstraintList::iterator deletePoint = end;
280 for(ConstraintList::iterator i=l.begin();i!=end;i++) {
282 double slack = c->
slack();
283 if (slack < minSlack) {
293 if(deletePoint != end && minSlack<-0.0000001) {
294 *deletePoint = l.back();
299 f<<
" most violated is: "<<*v<<
"\n";
312bool VPSC::constraintGraphIsCyclic(
const unsigned n,
Variable *vs[]) {
313 map<Variable*, node*> varmap;
314 vector<std::unique_ptr<node>>
graph;
315 for(
unsigned i=0;i<n;i++) {
317 varmap[vs[i]]=
graph.back().get();
319 for(
unsigned i=0;i<n;i++) {
322 varmap[vs[i]]->
in.insert(varmap[l]);
327 varmap[vs[i]]->
out.insert(varmap[r]);
330 while(!
graph.empty()) {
332 vector<std::unique_ptr<node>>::iterator i=
graph.begin();
333 for(;i!=
graph.end();i++) {
353bool VPSC::blockGraphIsCyclic() {
354 map<Block*, node*> bmap;
355 vector<std::unique_ptr<node>>
graph;
358 bmap[b]=
graph.back().get();
361 b->setUpInConstraints();
365 bmap[b]->
in.insert(bmap[l]);
366 b->deleteMinInConstraint();
367 c=b->findMinInConstraint();
370 b->setUpOutConstraints();
371 c=b->findMinOutConstraint();
374 bmap[b]->
out.insert(bmap[r]);
375 b->deleteMinOutConstraint();
376 c=b->findMinOutConstraint();
379 while(!
graph.empty()) {
381 vector<std::unique_ptr<node>>::iterator i=
graph.begin();
382 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()
static int in(Extype_t lhs, Exid_t *rhs, Exdisc_t *disc)
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[])