- double a2= vertex_areas[v2];
- double d2= hypotD2plus(v[v1],v[v2], d2_epsilon);
- double s= vertex_distances[v2];
- double sd= s / d2;
- double sd2= sd*sd;
- double cost_contrib= a1*a2 * (sd2 - 1) / (d2*d2);
- //printf("layout %03x..%03x (a=%g,%g) s=%g d2=%g cost+=%g\n",
- // v1,v2, a1,a2, s,d2, cost_contrib);
- total_cost += cost_contrib;
+ if (v1 == v2) continue;
+
+ double d= hypotD(v[v1],v[v2]);
+
+ int dist= distances[v1][v2];
+ assert(dist>=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;