chiark / gitweb /
before new shortest path graph layout cost function
[moebius2.git] / bgl.cpp
diff --git a/bgl.cpp b/bgl.cpp
index 774be825a1cc53bc017884e94876ddd49c134984..775fb12141c5d806bc3d98f36f9db2600eec7564 100644 (file)
--- a/bgl.cpp
+++ b/bgl.cpp
@@ -81,28 +81,44 @@ namespace boost {
 
 }
 
-struct VertexIndexMap;
-
-namespace boost {
-  struct property_traits<VertexIndexMap> {
-    // Concept Readable Property Map:
-    typedef int value_type, reference, key_type;
-    category 
-class Boost
-  }};
-
-void single_source_shortest_paths(int v1,
-                                 const double edge_weights[/*f*/],
-                                 ) {
+static void single_source_shortest_paths(int v1,
+                                        const double edge_weights[/*f*/],
+                                        double vertex_distances[/*v*/]) {
   boost::dijkstra_shortest_paths
     (g, v1,
      weight_map(edge_weights).
      vertex_index_map(identity_property_map()).
-     
+     distance_map(vertex_distances));
+}
     
-void all_pairs_shortest_paths(const Layout *g) {
-  
+double graph_layout_energy(const Layout *g) {
+  /* For each (vi,vj) computes shortest path pij = vi..vj along edges,
+   * and actual distance dij = vi-vj.
+   *
+   * Energy contribution is proportional to
+   *
+   *     pij - dij   
+   *     ---------  .  Sigma                                 length
+   *           2        e member (edges(vi) union edges(vj)        e
+   *        dij
+   */
+  double edge_weights[N*V6], vertex_distances[N];
+  int v1, e, f;
+
+  FOR_VEDGE_X(v1,e,
+             f= v1 | e << ESHIFT,
+             edge_weights[f]= NaN)
+    edge_weights[f]= hypotD(g.v[v1], g.v[v2]);
+
   FOR_VERTEX(v1) {
+    single_source_shortest_paths(v1, edge_weights, vertex_distances);
+    FOR_VERTEX(v2) {
+      
+            
+      
+    
+    { ) {
+    
        
  0);