/**********************************************************
*
* Solve a quadratic function f(X) = X' A X + b X
* subject to a set of separation constraints cs
*
* Tim Dwyer, 2006
**********************************************************/
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <float.h>
#include <cassert>
#include <libvpsc/solve_VPSC.h>
#include <libvpsc/variable.h>
#include <libvpsc/constraint.h>
#include "gradient_projection.h"
#include <iostream>
#include "isinf.h"
#include <math.h>
using namespace std;
using namespace vpsc;
//#define CONMAJ_LOGGING 1
unsigned m;
for(unsigned i=0;i<m;i++) {
}
}
/*
* Use gradient-projection to solve an instance of
* the Variable Placement with Separation Constraints problem.
* Uses sparse matrix techniques to handle pairs of dummy
* vars.
*/
unsigned i,j,counter;
if(max_iterations==0) return 0;
bool converged=false;
//cerr << "in gradient projection: n=" << n << endl;
for (i=0;i<n;i++) {
}
try {
} catch (char const *str) {
}
for (i=0;i<n;i++) {
}
(*it)->updatePosition();
}
converged=true;
// find steepest descent direction
// g = 2 ( b - Ax )
for (i=0; i<n; i++) {
g[i] = b[i];
for (j=0; j<n; j++) {
g[i] -= A[i][j]*place[j];
}
g[i] *= 2.0;
}
(*it)->computeDescentVector();
}
// compute step size: alpha = ( g' g ) / ( 2 g' A g )
// g terms for dummy vars cancel out so don't consider
for (i=0; i<n; i++) {
numerator += g[i]*g[i];
r=0;
for (j=0; j<n; j++) {
r += A[i][j]*g[j];
}
denominator -= 2.0 * r*g[i];
}
// move to new unconstrained position
for (i=0; i<n; i++) {
}
}
//project to constraint boundary
try {
} catch (char const *str) {
}
for (i=0;i<n;i++) {
}
(*it)->updatePosition();
}
// compute d, the vector from last pnt to projection pnt
for (i=0; i<n; i++) {
}
// now compute beta, optimal step size from last pnt to projection pnt
// beta = ( g' d ) / ( 2 d' A d )
numerator = 0, denominator = 0;
for (i=0; i<n; i++) {
numerator += g[i] * d[i];
r=0;
for (j=0; j<n; j++) {
r += A[i][j] * d[j];
}
denominator += 2.0 * r * d[i];
}
}
// beta > 1.0 takes us back outside the feasible region
// beta < 0 clearly not useful and may happen due to numerical imp.
for (i=0; i<n; i++) {
}
}
}
double test=0;
for (i=0; i<n; i++) {
}
}
converged=false;
}
}
return counter;
}
// Setup an instance of the Variable Placement with Separation Constraints
// for one iteration.
// Generate transient local constraints --- such as non-overlap constraints
// --- that are only relevant to one iteration, and merge these with the
// global constraint list (including alignment constraints,
// dir-edge constraints, containment constraints, etc).
//assert(lcs.size()==0);
}
}
if(nonOverlapConstraints) {
unsigned m=0;
if(k==HORIZONTAL) {
Rectangle::setXBorder(0);
} else {
}
for(unsigned i=0;i<m;i++) {
}
}
unsigned m = 0 ;
}
}
}
delete *i;
}
dummy_vars.clear();
}
if(acs) {
(*ac)->updatePosition();
}
}
unsigned m,n;
delete vpsc;
delete [] cs;
delete [] vs;
delete *i;
}
//cout << " Vars count = " << vars.size() << " Dummy vars cnt=" << dummy_vars.size() << endl;
DummyVarPair* p = *i;
delete p->left;
delete p->right;
}
}
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 :