X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=bgl.cpp;h=c35110b0682be288013d45eca339eb59f1a3f503;hp=cbe45b52d798865b2ad1ce0b7ad09218cd689ed7;hb=a602fc812857788265c72c27b132f34b9d7d107c;hpb=5d7d80c871a0e44729c520e76063369482316636 diff --git a/bgl.cpp b/bgl.cpp index cbe45b5..c35110b 100644 --- a/bgl.cpp +++ b/bgl.cpp @@ -170,7 +170,34 @@ static void single_source_shortest_paths(int v1, vertex_index_map(identity_property_map()). distance_map(vertex_distances)); } - + +static int distances[N][N]; + +void graph_layout_prepare() { + Graph g; + int v1, v2; + + FOR_VERTEX(v1) { + int *d= distances[v1]; + FOR_VERTEX(v2) d[v2]= -1; + d[v1]= 0; + breadth_first_search + (g, v1, + vertex_index_map(identity_property_map()). + visitor(make_bfs_visitor(record_distances(d,on_tree_edge())))); + printf("%02x:",v1); + FOR_VERTEX(v2) printf(" %02x:%d",v2,d[v2]); + putchar('\n'); + } + printf("---\n"); + FOR_VERTEX(v1) { + int *d= distances[v1]; + printf("%02x:",v1); + FOR_VERTEX(v2) printf(" %02x:%d",v2,d[v2]); + putchar('\n'); + } +} + double graph_layout_cost(const Vertices v, const double vertex_areas[N]) { /* For each (vi,vj) computes shortest path s_ij = |vi..vj| * along edges, and actual distance d_ij = |vi-vj|. @@ -189,33 +216,48 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]) { * divisions, to avoid division by zero.) */ static const double d2_epsilon= 1e-6; - - double edge_weights[N*V6], vertex_distances[N], total_cost=0; - int v1,v2,e,f; - FOR_VERTEX(v1) - FOR_VEDGE_X(v1,e,v2, - f= v1 | e << ESHIFT, - edge_weights[f]= NAN) - edge_weights[f]= hypotD(v[v1], v[v2]); + // double edge_weights[V6<=0); + + double s= dist * meanedgelength * 0.03; + + double enoughdistance= d - s; + if (enoughdistance > 1e-6) continue; + + /* energy = 1/2 stiffness deviation^2 + * where stiffness = 1/d + */ + + double cost= pow(enoughdistance,4); + + //double s2= s*s + d2_epsilon; + //double sd2= s2 / d2; + //double cost_contrib= a1*a2 * (sd2 - 1) / (d2*d2); + //double cost_contrib= sd2; + + printf("layout %03x..%03x dist=%d mean=%g s=%g d=%g enough=%g" + " cost+=%g\n", v1,v2, dist, meanedgelength, + s,d, enoughdistance, cost); + total_cost += cost; } } return total_cost;