82 edges.push_back(make_pair(u,v));
85vector<Edge>
random_dag(
unsigned depth,
unsigned maxbranch,
unsigned &V,
87 printf(
"DAG depth=%d\nmaxbranch=%d\nextraedgeprob%f\n",depth,maxbranch,
EXTRAEDGEPROB);
89 unsigned lstart=0, lend=1;
91 for(
unsigned i=0;i<depth;i++) {
92 for(
unsigned j=lstart;j<lend;j++) {
95 for(
unsigned k=0;k<maxbranch;k++) {
96 double r=(double)rand()/(double)RAND_MAX;
113 for(
unsigned i=0;i<V;++i) {
114 for(
unsigned j=i+1;j<V;++j) {
115 double r=(double)rand()/(double)RAND_MAX;
131 double xBorder=0, yBorder=0;
132 static const double EXTRA_GAP=1e-5;
133 unsigned n=
rs.size();
140 for(Variables::iterator v=vs.begin();v!=vs.end();++v,++i) {
147 vpsc::Rectangles::iterator r=
rs.begin();
148 for(Variables::iterator v=vs.begin();v!=vs.end();++v,++r) {
149 assert((*v)->finalPosition==(*v)->finalPosition);
150 (*r)->moveCentreX((*v)->finalPosition);
162 for(Variables::iterator v=vs.begin();v!=vs.end();++v,++r) {
163 (*r)->moveCentreY((*v)->finalPosition);
172 for(Variables::iterator v=vs.begin();v!=vs.end();++v,++r) {
173 (*r)->moveCentreX((*v)->finalPosition);
178 }
catch (
char *str) {
179 std::cerr<<str<<std::endl;
180 for(vpsc::Rectangles::iterator r=
rs.begin();r!=
rs.end();++r) {
181 std::cerr << **r <<std::endl;
203 std::vector<topology::Edge*>& routes,
204 std::vector<topology::Node*>& topologyNodes,
double defaultEdgeLength) {
205 printf(
"Removing overlaps...\n");
208 printf(
"Running libavoid to compute routes...\n");
209 clock_t libavoidstarttime=clock();
217 for(
unsigned i=0;i<
rs.size();++i) {
233 unsigned int shapeID = i + 1;
239 for(
unsigned i=0;i<
edges.size();++i) {
242 unsigned int connID = i +
rs.size() + 1;
249 vector<topology::EdgePoint*> eps;
250 eps.push_back(
new topology::EdgePoint( topologyNodes[e.first],
251 topology::EdgePoint::CENTRE));
252 for(
size_t j=1;j+1<route.
size();j++) {
254 const unsigned nodeID=p.
id-1;
255 topology::Node*
node=topologyNodes[nodeID];
256 topology::EdgePoint::RectIntersect ri;
258 case 0: ri=topology::EdgePoint::BR;
260 case 1: ri=topology::EdgePoint::TR;
262 case 2: ri=topology::EdgePoint::TL;
264 case 3: ri=topology::EdgePoint::BL;
266 default: ri=topology::EdgePoint::CENTRE;
268 eps.push_back(
new topology::EdgePoint(
node,ri));
270 eps.push_back(
new topology::EdgePoint(topologyNodes[e.second],
271 topology::EdgePoint::CENTRE));
272 topology::Edge* edgeRoute=
new topology::Edge(i,defaultEdgeLength, eps);
273 edgeRoute->assertConvexBends();
274 routes.push_back(edgeRoute);
277 writeFile(topologyNodes,routes,
"beautify0.svg");
278 assert(topology::assertNoSegmentRectIntersection(topologyNodes,routes));
279 double libavoidtime=double(clock()-libavoidstarttime)/double(CLOCKS_PER_SEC);
280 cout <<
"done. Libavoid ran in " << libavoidtime <<
" seconds" << endl;
287 int seed = time(
nullptr);
302 printf(
"random seed=%d\n",seed);
305 double defaultEdgeLength=40;
307 cout <<
"V="<<V<<endl;
308 cout <<
"E="<<
es.size()<<endl;
311 vector<pair<double,double> > startpos(V);
312 for(
unsigned i=0;i<V;i++) {
314 startpos[i]=make_pair(x,y);
316 vector<vpsc::Rectangle*>
rs;
317 vector<topology::Node*> topologyNodes;
318 vector<topology::Edge*> routes;
319 for(
unsigned i=0;i<V;i++) {
323 topologyNodes.push_back(
new topology::Node(i,r));
326 clock_t unconstrainedstarttime=clock();
338 double unconstrainedtime=double(clock()-unconstrainedstarttime)/double(CLOCKS_PER_SEC);
339 totaltime+=unconstrainedstarttime;
340 cout<<
"unconstrained layout ran in "<<unconstrainedtime<<
" seconds"<<endl;
341 clock_t makefeasiblestarttime=clock();
343 double makefeasibletime=double(clock()-makefeasiblestarttime)/double(CLOCKS_PER_SEC);
344 totaltime+=makefeasibletime;
345 cout<<
"makefeasible ran in "<<makefeasibletime<<
" seconds"<<endl;
346 clock_t beautifystarttime=clock();
349 writeFile(topologyNodes,routes,
"beautify1.svg");
350 std::stringstream dunnartfile;
351 dunnartfile <<
"v" << V <<
"e" << (int)
es.size() <<
".svg";
355 double beautifytime=double(clock()-beautifystarttime)/double(CLOCKS_PER_SEC);
356 totaltime+=beautifytime;
357 cout<<
"beautify ran in "<<beautifytime<<
" seconds"<<endl;
358 cout<<
"TOTAL="<<totaltime<<endl;
359 cout <<
"---------------------------------------------"<< endl;
360 cout <<V<<
" & "<<
es.size()<<
" & "<<unconstrainedtime<<
" & "<<makefeasibletime<<
" & "<<beautifytime<<
" & "<<totaltime<<
" \\\\ % Seed: "<< seed <<endl;
361 writeFile(topologyNodes,routes,
"beautify2.svg");
363 for(
unsigned i=0;i<V;i++) {
The ConnRef class represents a connector object.
const PolyLine & route(void) const
Returns a reference to the current raw "debug" route for the connector.
The Point class defines a point in the plane.
unsigned short vn
The vertex number associated with this point.
unsigned int id
The ID associated with this point.
A dynamic Polygon, to which points can be easily added and removed.
size_t size(void) const
Returns the number of points in this polygon.
std::vector< Point > ps
A vector of the points that make up the Polygon.
The Router class represents a libavoid router instance.
void addShape(ShapeRef *shape)
bool processTransaction(void)
Finishes the current transaction and processes all the queued object changes efficiently.
The ShapeRef class represents a shape object.
Implements a constrained force-directed layout algorithm.
void run(bool x=true, bool y=true)
Implements the main layout loop, taking descent steps until stress is no-longer significantly reduced...
void setTopology(TopologyAddonInterface *topology)
Set an addon for doing topology preserving layout.
void makeFeasible(double xBorder=1, double yBorder=1)
Finds a feasible starting position for nodes that satisfies the given constraints.
void outputInstanceToSVG(std::string filename=std::string())
Generates an SVG file containing debug output and code that can be used to regenerate the instance.
A separation constraint specifies a simple horizontal or vertical spacing constraint between 2 nodes ...
Incremental solver for Variable Placement with Separation Constraints problem instance.
bool solve()
Results in an optimum solution subject to the constraints.
A rectangle represents a fixed-size shape in the diagram that may be moved to prevent overlaps and sa...
static void setXBorder(double x)
double getCentreY() const
double getCentreX() const
static void setYBorder(double y)
A variable is comprised of an ideal position, final position and a weight.
double getRand(double range)
vector< vpsc::Rectangle * > rs
void writeFile(const topology::Nodes &vs, const topology::Edges &es, const string &outputFileName)
void writeDunnartFile(const topology::Nodes &vs, const vector< std::pair< unsigned int, unsigned int > > &es, const string &outputFileName)
Inkscape::XML::Node * node
Standard libavoid include file which includes all libavoid header files.
static const unsigned BRANCHFACTOR
void removeoverlaps(vpsc::Rectangles &rs, bool bothaxes)
void makeEdge(unsigned u, unsigned v, vector< Edge > &edges, CompoundConstraints &ccs)
static const unsigned DAGDEPTH
void makeFeasible(vpsc::Rectangles &rs, vector< cola::Edge > &edges, std::vector< topology::Edge * > &routes, std::vector< topology::Node * > &topologyNodes, double defaultEdgeLength)
vector< Edge > random_dag(unsigned depth, unsigned maxbranch, unsigned &V, CompoundConstraints &ccs)
static const double EXTRAEDGEPROB
@ PolyLineRouting
This option specifies that the router should maintain the structures necessary to allow poly-line con...
libcola: Force-directed network layout subject to separation constraints library.
std::vector< CompoundConstraint * > CompoundConstraints
A vector of pointers to CompoundConstraint objects.
std::pair< unsigned, unsigned > Edge
Edges are simply a pair of indices to entries in the Node vector.
libvpsc: Variable Placement with Separation Constraints quadratic program solver library.
@ YDIM
The y-dimension (1).
std::vector< vpsc::Variable * > Variables
A vector of pointers to Variable objects.
std::vector< vpsc::Constraint * > Constraints
A vector of pointers to Constraint objects.
void generateXConstraints(const Rectangles &rs, const Variables &vars, Constraints &cs, const bool useNeighbourLists)
void generateYConstraints(const Rectangles &rs, const Variables &vars, Constraints &cs)
std::vector< Rectangle * > Rectangles
A vector of pointers to Rectangle objects.
Contains the interface for the Router class.
Edges edges(Path const &p, Crossings const &cr, unsigned ix)