X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=energy.c;h=9bd66e31a93e0360c8c9614d0f3760afa6ef3fa8;hp=a4cfbb1491221f90b4e454105e8e04473ed89f99;hb=93cdc1e3e283f1c11d952b7651a02aa90ae1b07a;hpb=cd84cbc4ca24530cfd110b53019706babc3986a5 diff --git a/energy.c b/energy.c index a4cfbb1..9bd66e3 100644 --- a/energy.c +++ b/energy.c @@ -46,20 +46,34 @@ static const CostContribution costs[]= { #endif #if XBITS==4 -#define STOP_EPSILON 1e-6 +#define STOP_EPSILON 1.2e-4 COST( 3e5, line_bending_cost) - COST( 10e2, edge_length_variation_cost) - COST( 9.0e1, rim_proximity_cost) // 5e1 is too much + COST( 10e3, edge_length_variation_cost) + COST( 9.0e3, rim_proximity_cost) // 5e1 is too much // 2.5e1 is too little // 0.2e1 grows compared to previous ? // 0.6e0 shrinks compared to previous ? - COST( 1e12, edge_angle_cost) +// COST( 1e12, edge_angle_cost) #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.3) COST( 1e18, noncircular_rim_cost) #endif #if XBITS==5 +#define STOP_EPSILON 1.2e-4 + COST( 3e7, line_bending_cost) + COST( 10e2, prop_edge_length_variation_cost) + COST( 9.0e3, rim_proximity_cost) // 5e1 is too much + // 2.5e1 is too little + // 0.2e1 grows compared to previous ? + // 0.6e0 shrinks compared to previous ? + +// COST( 1e12, edge_angle_cost) + #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.3) + COST( 1e18, noncircular_rim_cost) +#endif + +#if XBITS>=6 /* nonsense follows but never mind */ #define STOP_EPSILON 1e-6 COST( 3e5, line_bending_cost) COST( 10e2, edge_length_variation_cost) @@ -89,7 +103,7 @@ void compute_energy_separately(const struct Vertices *vs, int ci; for (ci=0; cia, section); + precomps[ci](vs->a, section); inparallel_barrier(); } for (ci=0; ci - void compute_vertex_areas(const Vertices vertices, int section) { int v0,v1,v2, e1,e2; // int k; @@ -250,24 +262,7 @@ double line_bending_cost(const Vertices vertices, int section) { double a[D3], b[D3], axb[D3]; double total_cost= 0; - if (quitting_last_iteration) { - char buf[100]; - int n= sprintf(buf, - "section=%d thr=%#08lx qi=0x%03x START\n", - section,(unsigned long)pthread_self(), N); - write(2,buf,n); - quitting_reported_threads= 1; - } - FOR_EDGE(qi,e,ri, OUTER) { - if (quitting_last_iteration) { - char buf[100]; - int n= sprintf(buf, - "section=%d thr=%#08lx qi=0x%03x,e=%d,ri=0x%03x\n", - section,(unsigned long)pthread_self(),qi,e,ri); - write(2,buf,n); - } - pi= EDGE_END2(qi,(e+3)%V6); if (pi<0) continue; //if (!(qi&XMASK)) fprintf(stderr,"%02x-%02x-%02x (%d)\n",pi,qi,ri,e); @@ -308,6 +303,32 @@ double edge_length_variation_cost(const Vertices vertices, int section) { return cost; } +/*---------- proportional edge length variation ----------*/ + + /* + * Definition: + * + * See the diagram above. + * r + * cost = ( |PQ| - |QR| ) + * Q,e + */ + +double prop_edge_length_variation_cost(const Vertices vertices, int section) { + double cost= 0, exponent_r= 2; + int q, e,r, eback; + + FOR_EDGE(q,e,r, OUTER) { + eback= edge_reverse(q,e); + double le= edge_lengths[q][e]; + double leback= edge_lengths[q][eback]; + double diff= le - leback; + double num= MIN(le, leback); + cost += pow(diff / (num + 1e-6), exponent_r); + } + return cost; +} + /*---------- rim proximity cost ----------*/ static void find_nearest_oncircle(double oncircle[D3], const double p[D3]) {