From: Ian Jackson Date: Wed, 2 Jan 2008 21:07:47 +0000 (+0000) Subject: better vertex displacement X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=commitdiff_plain;h=f1dc8f4f3623b15deddba8db85d181a0e1011c9e better vertex displacement --- diff --git a/bgl.h b/bgl.h index d9c5d6b..34736bb 100644 --- a/bgl.h +++ b/bgl.h @@ -9,4 +9,7 @@ double graph_layout_cost(const Vertices v, const double vertex_areas[N]); +double noncircular_rim_cost(const Vertices vertices); +double edgewise_vertex_displacement_cost(const Vertices vertices); + #endif /*BGL_H*/ diff --git a/common.c b/common.c index ba61341..34381e8 100644 --- a/common.c +++ b/common.c @@ -43,6 +43,13 @@ void xprod(double r[D3], const double a[D3], const double b[D3]) { r[2]= a[0]*b[1] - a[1]*b[0]; } +double dotprod(const double a[D3], const double b[D3]) { + int k; + double result= 0; + K result += a[k] * b[k]; + return result; +} + void libdie(const char *lib, int l, const char *str) { fprintf(stderr,"%s library call failed, line %d: %s\n", lib, l, str); } diff --git a/common.h b/common.h index ebc34d1..7e0e86d 100644 --- a/common.h +++ b/common.h @@ -32,6 +32,7 @@ double hypotD2plus(const double p[D3], const double q[D3], double add); double magnD(const double pq[D3]); void xprod(double r[D3], const double a[D3], const double b[D3]); +double dotprod(const double a[D3], const double b[D3]); void flushoutput(void); void diee(const char *what); diff --git a/energy.c b/energy.c index 54c73fa..8961f54 100644 --- a/energy.c +++ b/energy.c @@ -12,9 +12,6 @@ static const char *input_file, *output_file; static char *output_file_tmp; -static double edgewise_vertex_displacement_cost(const Vertices vertices); -static double noncircular_rim_cost(const Vertices vertices); - static void compute_vertex_areas(const Vertices vertices, double areas[N]); static double best_energy= DBL_MAX; @@ -31,16 +28,16 @@ static double compute_energy(const Vertices vertices) { printf("cost > energy |"); COST(1e4, edgewise_vertex_displacement_cost(vertices)); - COST(1e2, graph_layout_cost(vertices,vertex_areas)); - COST(1e4, noncircular_rim_cost(vertices)); - +// COST(1e2, graph_layout_cost(vertices,vertex_areas)); +// COST(1e4, noncircular_rim_cost(vertices)); + printf("| total %# e |", energy); if (energy < best_energy) { FILE *best_f; int r; - + printf(" BEST"); - + best_f= fopen(output_file_tmp,"wb"); if (!best_f) diee("fopen new out"); r= fwrite(vertices,sizeof(Vertices),1,best_f); if (r!=1) diee("fwrite"); if (fclose(best_f)) diee("fclose new best"); @@ -52,7 +49,7 @@ static double compute_energy(const Vertices vertices) { flushoutput(); return energy; -} +} static void addcost(double *energy, double tweight, double tcost) { double tenergy= tweight * tcost; @@ -62,16 +59,16 @@ static void addcost(double *energy, double tweight, double tcost) { static void compute_vertex_areas(const Vertices vertices, double areas[N]) { int v0,v1,v2, e1,e2, k; - + FOR_VERTEX(v0) { double total= 0.0; int count= 0; - + FOR_VEDGE(v0,e1,v1) { e2= (e1+1) % V6; v2= EDGE_END2(v0,e2); if (v2<0) continue; - + double e1v[D3], e2v[D3], av[D3]; K { e1v[k]= vertices[v1][k] - vertices[v0][k]; @@ -105,7 +102,7 @@ static void compute_vertex_areas(const Vertices vertices, double areas[N]) { * In our application we are searching for the optimal locations of * N actualvertices in D3 (3) dimensions - ie, we are searching for * the optimal metapoint in an N*D3-dimensional space. - * + * * So eg with X=Y=100, the simplex will contain 300 metavertices * each of which is an array of 300 doubles for the actualvertex * coordinates. Hopefully this won't be too slow ... @@ -128,7 +125,7 @@ int main(int argc, const char *const *argv) { FILE *initial_f; gsl_vector initial_gsl, step_size_gsl; int r, v, k; - + if (argc!=3 || argv[1][0]=='-' || strncmp(argv[2],"-o",2)) { fputs("usage: minimise -o