cola.h revision 7201e2073c415e91642d7704773ab7e0c24b7654
#ifndef COLA_H
#define COLA_H
#include <utility>
#include <iterator>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cassert>
#include "shortest_paths.h"
#include "gradient_projection.h"
#include <libvpsc/generate-constraints.h>
#include "straightener.h"
// a graph component with a list of node_ids giving indices for some larger list of nodes
// for the nodes in this component, and a list of edges - node indices relative to this component
struct Component {
~Component() {
}
}
}
};
// for a graph of n nodes, return connected components
void connectedComponents(
const SimpleConstraints &scx,
const SimpleConstraints &scy,
// defines references to three variables for which the goal function
// will be altered to prefer points u-b-v are in a linear arrangement
// such that b is placed at u+t(v-u).
struct LinearConstraint {
LinearConstraint(unsigned u, unsigned v, unsigned b, double w,
double* X, double* Y)
tAtProjection(true)
{
if(tAtProjection) {
double uvx = X[v] - X[u],
uvy = Y[v] - Y[u],
vbx = X[b] - X[u],
vby = Y[b] - Y[u];
// p is the projection point of b on line uv
//double px = scalarProj * uvx + X[u];
//double py = scalarProj * uvy + Y[u];
// take t=|up|/|uv|
} else {
double numerator=X[b]-X[u];
double denominator=X[v]-X[u];
// if line is close to vertical then use Y coords to compute T
numerator=Y[b]-Y[u];
denominator=Y[v]-Y[u];
}
denominator=1;
}
}
duv=t*(1-t);
dub=t-1;
dvv=t*t;
dvb=-t;
dbb=1;
//printf("New LC: t=%f\n",t);
}
unsigned u;
unsigned v;
unsigned b;
double w; // weight
double t;
// 2nd partial derivatives of the goal function
// (X[b] - (1-t) X[u] - t X[v])^2
double duu;
double duv;
double dub;
double dvv;
double dvb;
double dbb;
// Length of each segment as a fraction of the total edge length
double frac_ub;
double frac_bv;
bool tAtProjection;
};
double old_stress;
: old_stress(DBL_MAX),
iterations(0) { }
virtual ~TestConvergence() {}
//std::cout<<"iteration="<<iterations<<", new_stress="<<new_stress<<std::endl;
if (old_stress == DBL_MAX) {
if(++iterations>=maxiterations) {;
return true;
} else {
return false;
}
}
bool converged =
|| ++iterations > maxiterations;
return converged;
}
double tolerance;
unsigned maxiterations;
unsigned iterations;
};
double* eweights,
double idealLength,
: constrainedLayout(false),
tol(0.0001),
X(new double[n]),
Y(new double[n]),
{
double** D=new double*[n];
for(unsigned i=0;i<n;i++) {
D[i]=new double[n];
}
// Lij_{i!=j}=1/(Dij^2)
//
for(unsigned i = 0; i<n; i++) {
X[i]=rs[i]->getCentreX();
Y[i]=rs[i]->getCentreY();
double degree = 0;
for(unsigned j=0;j<n;j++) {
double w = edge_length * D[i][j];
Dij[i][j]=w;
if(i==j) continue;
}
delete [] D[i];
}
delete [] D;
}
void moveBoundingBoxes() {
for(unsigned i=0;i<lapSize;i++) {
boundingBoxes[i]->moveCentreX(X[i]);
boundingBoxes[i]->moveCentreY(Y[i]);
}
}
void setupConstraints(
bool avoidOverlaps,
void setupDummyVars();
if(boundingBoxes) {
delete [] boundingBoxes;
}
if(constrainedLayout) {
}
for(unsigned i=0;i<lapSize;i++) {
}
delete [] X;
delete [] Y;
}
bool run();
bool avoidOverlaps;
bool constrainedLayout;
double euclidean_distance(unsigned i, unsigned j) {
return sqrt(
(X[i] - X[j]) * (X[i] - X[j]) +
(Y[i] - Y[j]) * (Y[i] - Y[j]));
}
double compute_stress(double **Dij);
double* b);
unsigned n; // is lapSize + dummyVars
unsigned lapSize; // lapSize is the number of variables for actual nodes
double** lap2; // graph laplacian
double** Q; // quadratic terms matrix used in computations
double** Dij;
double tol;
double *X, *Y;
double edge_length;
};
}
#endif // COLA_H
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4