From fd733201b82f39655488a286c89142f321ef9dc9 Mon Sep 17 00:00:00 2001 From: Sylvain Chiron Date: Sat, 1 Jul 2017 13:36:41 +0200 Subject: Updated libs from the Adaptagrams project: libavoid, libcola and libvspc; changed the code to match the new API Signed-off-by: Sylvain Chiron --- src/libcola/tests/graphlayouttest.h | 275 ++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 src/libcola/tests/graphlayouttest.h (limited to 'src/libcola/tests/graphlayouttest.h') diff --git a/src/libcola/tests/graphlayouttest.h b/src/libcola/tests/graphlayouttest.h new file mode 100644 index 000000000..58715bab6 --- /dev/null +++ b/src/libcola/tests/graphlayouttest.h @@ -0,0 +1,275 @@ +/* + * vim: ts=4 sw=4 et tw=0 wm=0 + * + * libcola - A library providing force-directed network layout using the + * stress-majorization method subject to separation constraints. + * + * Copyright (C) 2006-2008 Monash University + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file LICENSE; if not, + * write to the Free Software Foundation, Inc., 59 Temple Place, + * Suite 330, Boston, MA 02111-1307 USA + * +*/ + +#include +#include + +#include +#include +#include +#include + +inline double getRand(double range) { + return range*rand()/RAND_MAX; +} + +namespace DFS { +using namespace std; +using namespace cola; +struct Node { + unsigned id; + bool visited; + typedef vector PNodes; + PNodes neighbours; + void visit(vector &order) { + visited=true; + unsigned mid=neighbours.size()/2; + for(unsigned i=0;ivisited) { + neighbours[i]->visit(order); + } + } + order.push_back(id); + for(unsigned i=mid;ivisited) { + neighbours[i]->visit(order); + } + } + } + void visit_leaves(vector &order) { + unsigned mid=neighbours.size()/2; + Node *v; + for(unsigned i=0;ineighbours.size()==0) { + order.push_back(v->id); + } + } + order.push_back(id); + for(unsigned i=mid;ineighbours.size()==0) { + order.push_back(v->id); + } + } + } +}; + +struct Graph { + typedef vector Edges; + typedef vector Nodes; + Nodes nodes; + vector order; + vector > leaves; + Graph(unsigned n,vector &edges) { + nodes.resize(n); + order.resize(0); + leaves.resize(n); + for(Edges::iterator i=edges.begin();i!=edges.end();i++) { + nodes[i->first].neighbours.push_back(&nodes[i->second]); + } + for(unsigned i=0;ivisited) { + i->visit(order); + } + } + for(unsigned i=0;i & X, valarray & Y) { + cout << "stress="<\n"); + for(unsigned int i = 0; i < vs.size(); ++i) { + vpsc::Rectangle *rect = vs[i]->rect; + + int id = i + 1; + fprintf(fp, "\n", id, + rect->getCentreX(), rect->getCentreY()); + } + + for(unsigned int i = 0; i < es.size(); ++i) { + const std::pair& edge = es[i]; + + int id = i + 1 + vs.size(); + fprintf(fp, "\n", id, + edge.first + 1, edge.second + 1); + } + + fprintf(fp, "\n"); + + fclose(fp); + +#if 0 + for(unsigned i=0;i routes; + for(topology::Edges::const_iterator e=es.begin();e!=es.end();++e) { + routes.push_back((*e)->getRoute()); + } + + vector labels(n); + for(unsigned i=0;i rs; + for(topology::Nodes::const_iterator i=vs.begin();i!=vs.end();++i) { + rs.push_back((*i)->rect); + } + OutputFile of(rs,cedges,NULL,outputFileName,true,false); + of.setLabels(labels); + of.routes=&routes; + of.generate(); + + for_each(routes.begin(),routes.end(),delete_object()); +#endif +} + +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4: -- cgit v1.2.3