34 #include "libcola/gradient_projection.h" 35 #include "libcola/cluster.h" 36 #include "libcola/straightener.h" 37 #include "libcola/exceptions.h" 38 #include "libcola/pseudorandom.h" 40 namespace vpsc {
class Rectangle; }
42 class ColaTopologyAddon;
58 class NonOverlapConstraints;
59 class NonOverlapConstraintExemptions;
68 typedef std::pair<unsigned, unsigned>
Edge;
73 #define StandardEdgeLengths EdgeLengths() 88 Lock(
unsigned id,
double X,
double Y) : id(id), x(X), y(Y) {
90 unsigned getID()
const {
102 typedef std::vector<cola::Lock>
Locks;
122 Resize(
unsigned id,
double x,
double y,
double w,
double h)
123 : id(id), target(x,x+w,y,y+h) {}
124 unsigned getID()
const {
141 struct DesiredPosition {
147 typedef std::vector<cola::DesiredPosition> DesiredPositions;
154 typedef std::pair<unsigned,double> DesiredPositionInDim;
155 typedef std::vector<DesiredPositionInDim> DesiredPositionsInDim;
180 Locks& locks=__locksNotUsed,
181 Resizes& resizes=__resizesNotUsed)
186 : locks(__locksNotUsed)
196 virtual bool operator()() {
return true; }
201 static Locks __locksNotUsed;
202 static Resizes __resizesNotUsed;
219 TestConvergence(
const double tol = 1e-4,
const unsigned maxiterations = 100)
221 maxiterations(maxiterations)
226 virtual bool operator()(
const double new_stress, std::valarray<double> & X, std::valarray<double> & Y)
233 if (old_stress == DBL_MAX) {
234 old_stress = new_stress;
235 return iterations >= maxiterations;
240 (old_stress - new_stress) / (new_stress + 1e-10) < tolerance
241 || iterations > maxiterations;
242 old_stress = new_stress;
246 old_stress = DBL_MAX;
249 const double tolerance;
250 const unsigned maxiterations;
294 std::vector<Edge>
const & es,
296 const double idealLength,
300 bool useNeighbourStress =
false);
307 constrainedLayout =
true;
312 constrainedLayout =
true;
314 for (
size_t i = 0; i < ccs.size(); ++i) {
315 ccsp->push_back(ccs.at(i));
338 this->unsatisfiableX = unsatisfiableX;
339 this->unsatisfiableY = unsatisfiableY;
346 std::valarray<double>
const & startX,
347 std::valarray<double>
const & startY);
353 this->scaling=scaling;
360 this->externalSolver=externalSolver;
369 constrainedLayout =
true;
370 this->avoidOverlaps = horizontal ? Horizontal : Both;
376 constrainedLayout =
true;
377 nonOverlappingClusters =
true;
386 double bendWeight = 0.01,
double potBendWeight = 0.1,
387 bool xSkipping =
true) {
388 for(std::vector<straightener::Edge*>::const_iterator e=straightenEdges->begin();
389 e!=straightenEdges->end();e++) {
390 (*e)->rerouteAround(boundingBoxes);
392 constrainedLayout =
true;
393 this->xSkipping = xSkipping;
394 this->straightenEdges = straightenEdges;
395 this->bendWeight = bendWeight;
396 this->potBendWeight = potBendWeight;
402 for(
unsigned i=0;i<n;i++) {
403 boundingBoxes[i]->moveCentre(X[i],Y[i]);
408 if (using_default_done)
413 if(constrainedLayout) {
427 void run(
bool x=
true,
bool y=
true);
439 void runOnce(
bool x=
true,
bool y=
true);
440 void straighten(std::vector<straightener::Edge*>&,
vpsc::Dim);
441 void setConstrainedLayout(
bool c) {
444 double computeStress();
446 double euclidean_distance(
unsigned i,
unsigned j) {
448 (X[i] - X[j]) * (X[i] - X[j]) +
449 (Y[i] - Y[j]) * (Y[i] - Y[j]));
451 double compute_stress(std::valarray<double>
const & Dij);
452 void majorize(std::valarray<double>
const & Dij,GradientProjection* gp, std::valarray<double>& coords, std::valarray<double>
const & startCoords);
453 void newton(std::valarray<double>
const & Dij,GradientProjection* gp, std::valarray<double>& coords, std::valarray<double>
const & startCoords);
456 std::valarray<double> lap2;
457 std::valarray<double> Q;
458 std::valarray<double> Dij;
460 TestConvergence *done;
461 bool using_default_done;
462 PreIteration* preIteration;
469 std::valarray<double> X, Y;
472 std::valarray<double> startX;
473 std::valarray<double> startY;
475 bool constrainedLayout;
476 bool nonOverlappingClusters;
496 RootCluster *clusterHierarchy;
497 GradientProjection *gpX, *gpY;
500 NonOverlapConstraintsMode avoidOverlaps;
501 std::vector<straightener::Edge*>* straightenEdges;
503 double bendWeight, potBendWeight;
525 class ConstrainedFDLayout;
547 virtual void freeAssociatedObjects(
void)
551 virtual void handleResizes(
const Resizes& resizeList,
unsigned n,
552 std::valarray<double>& X, std::valarray<double>& Y,
557 COLA_UNUSED(resizeList);
562 COLA_UNUSED(boundingBoxes);
563 COLA_UNUSED(clusterHierarchy);
565 virtual void computePathLengths(
unsigned short** G)
569 virtual double computeStress(
void)
const 573 virtual bool useTopologySolver(
void)
const 577 virtual void makeFeasible(
bool generateNonOverlapConstraints,
581 COLA_UNUSED(generateNonOverlapConstraints);
582 COLA_UNUSED(boundingBoxes);
583 COLA_UNUSED(clusterHierarchy);
593 COLA_UNUSED(clusterHierarchy);
596 const vpsc::Dim dim, std::valarray<double>& g,
598 std::valarray<double> &coords,
599 DesiredPositionsInDim& des,
double oldStress)
608 COLA_UNUSED(oldStress);
654 const std::vector<cola::Edge>& es,
655 const double idealLength,
670 void run(
bool x=
true,
bool y=
true);
683 void runOnce(
bool x=
true,
bool y=
true);
725 void setDesiredPositions(DesiredPositions *desiredPositions);
735 clusterHierarchy = hierarchy;
756 unsatisfiable.resize(2);
757 unsatisfiable[0]=unsatisfiableX;
758 unsatisfiable[1]=unsatisfiableY;
859 double computeStress()
const;
863 std::valarray<double> X, Y;
865 double applyForcesAndConstraints(
const vpsc::Dim dim,
const double oldStress);
866 double computeStepSize(
const SparseMatrix& H,
const std::valarray<double>& g,
867 const std::valarray<double>& d)
const;
868 void computeDescentVectorOnBothAxes(
const bool xaxis,
const bool yaxis,
869 double stress, std::valarray<double>& x0, std::valarray<double>& x1);
870 void moveTo(
const vpsc::Dim dim, std::valarray<double>& target);
871 double applyDescentVector(
872 const std::valarray<double>& d,
873 const std::valarray<double>& oldCoords,
874 std::valarray<double> &coords,
875 const double oldStress,
878 void computePathLengths(
879 const std::vector<Edge>& es, std::valarray<double> eLengths);
880 void generateNonOverlapAndClusterCompoundConstraints(
882 void handleResizes(
const Resizes&);
883 void setPosition(std::valarray<double>& pos);
884 void moveBoundingBoxes();
885 bool noForces(
double,
double,
unsigned)
const;
886 void computeForces(
const vpsc::Dim dim, SparseMap &H,
887 std::valarray<double> &g);
888 void recGenerateClusterVariablesAndConstraints(
890 cola::NonOverlapConstraints *noc,
Cluster *cluster,
892 std::vector<double> offsetDir(
double minD);
894 void computeNeighbours(std::vector<Edge> es);
895 std::vector<std::vector<unsigned> > neighbours;
896 std::vector<std::vector<double> > neighbourLengths;
898 bool using_default_done;
907 std::vector<UnsatisfiableConstraintInfos*> unsatisfiable;
909 DesiredPositions *desiredPositions;
913 double rectClusterBuffer;
914 double m_idealEdgeLength;
915 bool m_generateNonOverlapConstraints;
916 bool m_useNeighbourStress;
917 const std::valarray<double> m_edge_lengths;
919 NonOverlapConstraintExemptions *m_nonoverlap_exemptions;
925 struct ProjectionResult {
927 std::string unsatinfo;
948 bool preventOverlaps,
int accept=0,
unsigned debugLevel=0);
966 unsigned debugLevel=0);
969 ConstrainedMajorizationLayout* simpleCMLFactory(
971 std::vector<Edge>
const & es,
972 RootCluster* clusterHierarchy,
973 const double idealLength,
974 bool useNeighbourStress =
false 985 void dijkstra(
const unsigned s,
const unsigned n,
double* d,
986 const std::vector<cola::Edge>& es,
987 const std::valarray<double> & eLengths);
995 RootCluster *clusterHierarchy,
997 std::valarray<double> &coords);
999 const DesiredPositionsInDim& des, std::valarray<double>& coords);
void run(bool x=true, bool y=true)
Implements the main layout loop, taking descent steps until stress is no-longer significantly reduced...
Definition: cola.cpp:320
The Graph class represents graphs consisting of nodes and edges.
Definition: graphs.h:180
std::vector< NodeIndexes > ListOfNodeIndexes
A vector of NodeIndexes.
Definition: cola.h:65
void setStraightenEdges(std::vector< straightener::Edge *> *straightenEdges, double bendWeight=0.01, double potBendWeight=0.1, bool xSkipping=true)
Definition: cola.h:385
libtopology: Extensions for topology preservation for libcola and libavoid libraries.
Definition: shape.h:41
void setConstraints(const cola::CompoundConstraints &ccs)
Specify a set of compound constraints to apply to the layout.
Definition: colafd.cpp:189
void outputInstanceToSVG(std::string filename=std::string())
Generates an SVG file containing debug output and code that can be used to regenerate the instance...
Definition: colafd.cpp:1369
A Resize specifies a new required bounding box for a node.
Definition: cola.h:107
ProjectionResult solve(vpsc::Variables &vs, vpsc::Constraints &cs, vpsc::Rectangles &rs, unsigned debugLevel=0)
Constructs a solver and attempts to solve the passed constraints on the passed vars.
Implements the Constrained Majorization graph layout algorithm (deprecated).
Definition: cola.h:270
void setUseNeighbourStress(bool useNeighbourStress)
Specifies whether neighbour stress should be used.
Definition: colafd.cpp:201
A default functor that is called after each iteration of the layout algorithm.
Definition: cola.h:216
void runOnce(bool x=true, bool y=true)
Same as run(), but only applies one iteration.
Definition: colafd.cpp:386
void runOnce(bool x=true, bool y=true)
Same as run(), but only applies one iteration.
Definition: cola.cpp:398
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
std::vector< cola::Lock > Locks
A vector of Lock objects.
Definition: cola.h:102
std::vector< unsigned > NodeIndexes
A vector of node Indexes.
Definition: cola.h:59
This class can be passed to libcola to replace some functionality to provide topology preserving layo...
Definition: cola_topology_addon.h:44
std::pair< unsigned, unsigned > Edge
Edges are simply a pair of indices to entries in the Node vector.
Definition: cola.h:68
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
Definition: assertions.h:61
A Lock specifies a required position for a node.
Definition: cola.h:78
void setUnsatisfiableConstraintInfo(UnsatisfiableConstraintInfos *unsatisfiableX, UnsatisfiableConstraintInfos *unsatisfiableY)
Register to receive information about unsatisfiable constraints.
Definition: cola.h:752
void setExternalSolver(bool externalSolver)
Definition: cola.h:359
std::vector< Variable * > Variables
A vector of pointers to Variable objects.
Definition: constraint.h:38
Interface for writing COLA addons to handle topology preserving layout.
Definition: cola.h:531
std::vector< double > EdgeLengths
Definition: cola.h:72
std::vector< double > readLinearD(void)
Retrieve a copy of the "D matrix" computed by the computePathLengths method, linearised as a vector...
Definition: colafd.cpp:147
std::vector< Constraint * > Constraints
A vector of pointers to Constraint objects.
Definition: constraint.h:125
void setStickyNodes(const double stickyWeight, std::valarray< double > const &startX, std::valarray< double > const &startY)
Definition: cola.cpp:158
PreIteration(Locks &locks=__locksNotUsed, Resizes &resizes=__resizesNotUsed)
Constructs a PreIteration object that handles locking and resizing of nodes.
Definition: cola.h:179
Lock(unsigned id, double X, double Y)
Constructs a Lock object for a given node and position.
Definition: cola.h:88
std::vector< Rectangle * > Rectangles
A vector of pointers to Rectangle objects.
Definition: rectangle.h:246
void setAvoidOverlaps(bool horizontal=false)
Definition: cola.h:368
A default functor that is called before each iteration in the main loop of the ConstrainedFDLayout::r...
Definition: cola.h:168
std::vector< cola::Resize > Resizes
A vector of Resize objects.
Definition: cola.h:135
Holds the cluster hierarchy specification for a diagram.
Definition: cluster.h:172
Resize(unsigned id, double x, double y, double w, double h)
Constructs a Resize object for a given node and it's new bounding box.
Definition: cola.h:122
std::vector< unsigned > readLinearG(void)
Retrieve a copy of the "G matrix" computed by the computePathLengths method, linearised as a vector...
Definition: colafd.cpp:159
void freeAssociatedObjects(void)
A convenience method that can be called from Java to free the memory of nodes (Rectangles), CompoundConstraints, etc.
Definition: colafd.cpp:916
void setNonOverlappingClusters()
Definition: cola.h:375
A rectangle represents a fixed-size shape in the diagram that may be moved to prevent overlaps and sa...
Definition: rectangle.h:78
ConstrainedMajorizationLayout(vpsc::Rectangles &rs, std::vector< Edge > const &es, RootCluster *clusterHierarchy, const double idealLength, EdgeLengths eLengths=StandardEdgeLengths, TestConvergence *doneTest=nullptr, PreIteration *preIteration=nullptr, bool useNeighbourStress=false)
Constructs a constrained majorization layout instance.
Definition: cola.cpp:40
A cluster defines a hierarchical partitioning over the nodes which should be kept disjoint by the lay...
Definition: cluster.h:50
void run(bool x=true, bool y=true)
Implements the main layout loop, taking descent steps until stress is no-longer significantly reduced...
Definition: colafd.cpp:316
void setTopology(TopologyAddonInterface *topology)
Set an addon for doing topology preserving layout.
Definition: colafd.cpp:944
void moveBoundingBoxes()
Definition: cola.h:401
libcola: Force-directed network layout subject to separation constraints library. ...
Definition: box.cpp:25
The x-dimension (0).
Definition: rectangle.h:43
Dim
Indicates the x- or y-dimension.
Definition: rectangle.h:41
ProjectionResult projectOntoCCs(vpsc::Dim dim, vpsc::Rectangles &rs, cola::CompoundConstraints ccs, bool preventOverlaps, int accept=0, unsigned debugLevel=0)
Attempt to do a projection onto a vector of cola CompoundConstraints.
Implements a constrained force-directed layout algorithm.
Definition: cola.h:622
std::vector< UnsatisfiableConstraintInfo * > UnsatisfiableConstraintInfos
A vector of pointers to UnsatisfiableConstraintInfo objects.
Definition: compound_constraints.h:826
ConstrainedFDLayout(const vpsc::Rectangles &rs, const std::vector< cola::Edge > &es, const double idealLength, const EdgeLengths &eLengths=StandardEdgeLengths, TestConvergence *doneTest=nullptr, PreIteration *preIteration=nullptr)
Constructs a constrained force-directed layout instance.
Definition: colafd.cpp:96
void setClusterHierarchy(RootCluster *hierarchy)
Specifies an optional hierarchy for clustering nodes.
Definition: cola.h:733
void setScaling(bool scaling)
Definition: cola.h:352
std::vector< CompoundConstraint * > CompoundConstraints
A vector of pointers to CompoundConstraint objects.
Definition: compound_constraints.h:259
void setConstraints(cola::CompoundConstraints *ccs)
Specify a set of compound constraints to apply to the layout.
Definition: cola.h:306
void setAvoidNodeOverlaps(bool avoidOverlaps, ListOfNodeIndexes listOfNodeGroups=ListOfNodeIndexes())
Specifies whether non-overlap constraints should be automatically generated between all nodes...
Definition: colafd.cpp:194
void makeFeasible(double xBorder=1, double yBorder=1)
Finds a feasible starting position for nodes that satisfies the given constraints.
Definition: colafd.cpp:604
void setUnsatisfiableConstraintInfo(UnsatisfiableConstraintInfos *unsatisfiableX, UnsatisfiableConstraintInfos *unsatisfiableY)
Register to receive information about unsatisfiable constraints.
Definition: cola.h:335