📄 read.w,v
字号:
text@d52 3d180 1d184 1a184 1#include "read.h"@@;d188 1d191 1a191 1const char *read_rcs_id="$Id: read.w,v 1.140 1998/07/31 17:56:24 neto Exp neto $";d282 3d292 3d305 1d354 5a358 1 @@<Generate random edge lengths using the given seed@@>@@;d409 6d424 7a430 1typedef enum { EUC_2D, CEIL_2D, EXPLICIT, RANDOM_EDGES } edge_weight_type_t;d436 1a436 1p->edge_weight_type = EUC_2D;d457 1a457 1typedef enum { NONE, LOWER_DIAG_ROW, FULL_MATRIX, UPPER_ROW } d460 5d469 1a469 1p->edge_weight_format = NONE;d636 37d674 2a675 1they fit. This scheme saves space and time (because of cache effects).d677 1a677 2@@<Get the rest of the line into |rest_of_line|, but skip the colon@@>@@;gb_init_rand( atol(rest_of_line) );d765 1a765 2to mean |nint(\alpha)=floor(0.5+\alpha)|.d836 3a852 6@@ We need to include the interface definition for the numericalfunctions|floor|, |sqrt|, and |hypot|.@@<Other includes@@>=#include <math.h>d869 124d1018 12d1035 4d1082 2d1109 4a1112 2 errorif(p->edge_weight_format != NONE, "Edge weight format should be NONE, but is %d",p->edge_weight_format);d1116 2a1117 1 errorif(p->edge_weight_format==NONE,"Edge weight shouldn't be NONE, but it is");d1120 1d1209 9d1228 4@1.140log@Doh! needed a break too.@text@d52 3d186 1a186 1const char *read_rcs_id="$Id: read.w,v 1.139 1998/07/31 17:51:53 neto Exp neto $";d859 1a859 1te $x,y$ coordinates and deleted the last point.'')d865 6d883 5a887 1 p->coord[lex_last] = p->coord[p->n];d969 2d973 1a973 1write_tsp_file(tsp_instance_t *tsp,FILE *out) d975 9a983 1if(out) { d986 4a989 2if (tsp->comment) {fprintf(out,"COMMENT: %s\n",tsp->comment);}fprintf(out,"DIMENSION: %d\n",tsp->n);d1007 1a1010 1}d1015 1d1021 2a1022 2for (i=0;i<tsp->n;i++) {fprintf(out,"%d %20g %20g\n",i+1,tsp->coord[i].x[0],tsp->coord[i].x[1]);d1034 1a1034 1 for (row=0;row<tsp->n;row++) {d1044 2a1045 2 for (row=0;row<tsp->n;row++) { for (col=0;col<tsp->n;col++) {d1054 2a1055 2 for (row=0;row<tsp->n;row++) { for (col=row+1;col<tsp->n;col++) {@1.139log@added default: to satisfy GCC's complaint about missing RANDOM EDGESin a switch.@text@d52 4d183 1a183 1const char *read_rcs_id="$Id: read.w,v 1.138 1998/07/25 22:10:34 neto Exp neto $";d895 1d897 1@1.138log@Remove the lexicographically last vertex.@text@d52 3d179 1a179 1const char *read_rcs_id="$Id: read.w,v 1.137 1998/07/25 18:10:50 neto Exp neto $";d891 1@1.137log@Some of forcing even number of vertic3s.@text@d52 3d176 1a176 1const char *read_rcs_id="$Id: read.w,v 1.136 1998/07/24 20:38:33 neto Exp neto $";a317 1 if ( force_even_num && (p->n % 2) ) p->n--;d826 3a829 1@@d831 40d873 2a874 1d881 2a882 1 errorif(p->edge_weight_format != NONE,"Edge weight format should be NONE, but is %d",edge_weight_format);@1.136log@Added changes to allow truncating the odd vertex out.Not finished.@text@d52 4d173 1a173 1const char *read_rcs_id="$Id: read.w,v 1.135 1998/07/16 21:58:55 neto Exp neto $";d825 2a826 2@@c...@1.135log@Added the LGPL notice in each file.@text@d1 1a1 2d52 3d169 1a169 1const char *read_rcs_id="$Id: read.w,v 1.134 1998/05/08 22:23:57 neto Exp neto $";d222 1a222 1read_tsp_file(FILE *in, FILE *debug)d225 4a228 2 @@<Set the problem defaults@@>@@; @@<Read in the problem@@>@@;d241 1a241 1tsp_instance_t * read_tsp_file(FILE *in, FILE *out);d253 6a258 2The |n| field is the number of cities in the problem. d266 1d273 1a273 1@@<Set the problem defaults@@>=d283 1a283 1@@<Read in the problem@@>=d310 2a311 1 p->n = atoi(rest_of_line);d391 1a391 1@@ @@<Set the problem defaults@@>=d419 1a419 1@@ @@<Set the problem defaults@@>=d434 1a434 1 p->edge_weights = new_arr_of(length_t*,p->n);d436 2a437 2 for ( row = 0 ; row < p->n ; row++ ) { p->edge_weights[row] = new_arr_of(length_t,p->n);d439 1a439 1 for ( row = 0 ; row < p->n ; row++ ) { /* Now actually read the weights. */d452 1a452 1 p->edge_weights = new_arr_of(length_t*,p->n);d454 2a455 2 for ( row = 0 ; row < p->n ; row++ ) { p->edge_weights[row] = new_arr_of(length_t,p->n);d457 2a458 2 for ( row = 0 ; row < p->n ; row++ ) { /* Now actually read the weights. */ for ( col = 0 ; col < p->n ; col++ ) {d465 1a465 1 for ( row = 0; row < p->n ; row++ ) {d477 1a477 1 p->edge_weights = new_arr_of(length_t*,p->n);d479 2a480 2 for ( row = 0 ; row < p->n ; row++ ) { p->edge_weights[row] = new_arr_of(length_t,p->n);d483 1a483 1 for ( row = 0 ; row < p->n ; row++ ) { d485 1a485 1 for ( col = row+1 ; col < p->n ; col++ ) {d504 1a504 1@@ @@<Set the problem defaults@@>=d527 2d531 8a538 7{ int i,j; p->coord = new_arr_of(coord_2d,p->n); /* Allocate the space for the coordinates. */ for ( i=0; i<p->n; i++ ) { fscanf(in," %d ",&j); fscanf(in," %lf %lf ",&p->coord[j-1].x[0],&p->coord[j-1].x[1]);d568 1a568 1@@<Set the problem defaults@@>=d577 1a577 1We may want to output PostScript in the future.d582 1a582 1 for ( i=0; i<p->n; i++ ) {d593 3a595 3p->short_edge_weights = new_arr_of(short*,p->n);for (i=0;i<p->n;i++) { p->short_edge_weights[i] = new_arr_of(short,p->n);d598 1a598 1for (i=0;i<p->n;i++)d602 1a602 1if ( p->n <=10 ) {d604 2a605 2 for (i=0;i<p->n;i++) { for (j=0;j<p->n;j++) printf(" %4d",p->short_edge_weights[i][j]);d614 1a614 1@@ @@<Set the problem defaults@@>=d819 22d860 2a861 2 fprintf(debug,"/N {%d} def %% number of nodes\n",p->n); if ( p->n < 8191 )d887 1a887 1for (i=0; i<p->n ; i++) {@1.134log@Better comment.Also, added writing abilities for matrix forms.@text@d1 47a47 1@@i copyrt.wd53 4d167 1a167 1const char *read_rcs_id="$Id: read.w,v 1.133 1997/12/13 20:05:45 neto Exp neto $";@1.133log@Ok, so I got the name of write... wrong@text@d7 3d117 1a117 1const char *read_rcs_id="$Id: read.w,v 1.132 1997/12/13 20:03:05 neto Exp neto $";d604 2a605 1The TSPLIB documentation uses the |aint| function in place of the |floor| d614 6d633 5a819 1fprintf(out,"DIMENSION: %d\n",tsp->n);d827 11a837 1default: errorif(1,"Finish the code, David!");a838 1fprintf(out,"EOF\n");d854 40@1.132log@Added first (compiling) draft of write tsp instance@text@d7 3d114 1a114 1const char *read_rcs_id="$Id: read.w,v 1.131 1997/12/13 17:25:18 neto Exp neto $";d798 1a798 1write_tsp_instance(tsp_instance_t *tsp,FILE *out) d821 1a821 1void write_tsp_instance(tsp_instance_t *tsp,FILE *out);@1.131log@Stripped the newlines off the error messages.@text@d7 3d111 1a111 1const char *read_rcs_id="$Id: read.w,v 1.130 1997/10/18 15:16:19 neto Exp neto $";d122 1a122 1@@<Exported routines@@>@@;d152 1a152 1@@<Exported routines@@>=d180 1a180 1@@<Exported routines@@>=d681 1a681 1@@<Exported routines@@>=d790 38@1.130log@More readability (matchword).Hopefully fix garbage output on error (move keyword[0]=0).Added support for CEIL 2D@text@d7 5d108 1a108 1const char *read_rcs_id="$Id: read.w,v 1.129 1997/10/17 21:47:44 neto Exp neto $";d260 1a260 1 errorif(1,"%d: Don't know what the keyword %s is!\n",lineno,keyword);d282 1a282 1 errorif( r != 0, "%d: Missed the colon.\n", lineno);d286 1a286 1 @@|"%d: Couldn't read after the colon; truncated file?\n", lineno);@@;d313 1a313 1 errorif(1,"%d: Apology: Unknown edge weight type \"%s\".\n",lineno,rest_of_line);d340 1a340 1 errorif(1,"%d: Unknown edge weight format \"%s\".\n",lineno,rest_of_line);@1.129log@Fixed to compile.@text@d7 3d103 1a103 1const char *read_rcs_id="$Id: read.w,v 1.128 1997/10/17 21:00:25 neto Exp neto $";d208 1a215 1keyword[0]=0;d218 1d220 1a220 1 if ( r==EOF ) {more_input=0;break;}d224 1a224 1 if ( 0==strcmp(keyword,"EOF") ) {d226 1a226 1 }@@+ else if ( 0==strcmp(keyword,"NAME") ) {d229 2a230 2 }@@+ else if ( 0==strcmp(keyword,"COMMENT") ) { @@<Get the rest of the line into |rest_of_line|, but skip the colon@@>d232 1a232 1 }@@+ else if ( 0==strcmp(keyword,"TYPE") ) {d235 1a235 1 }@@+ else if ( 0==strcmp(keyword,"DIMENSION") ) {d238 1a238 1 }@@+ else if ( 0==strcmp(keyword,"DISPLAY_DATA_TYPE") ) {d241 1a241 1 }@@+ else if ( 0==strcmp(keyword,"EDGE_WEIGHT_TYPE") ) {d243 1a243 1 }@@+ else if ( 0==strcmp(keyword,"EDGE_WEIGHT_FORMAT") ) {d245 1a245 1 }@@+ else if ( 0==strcmp(keyword,"EDGE_WEIGHT_SECTION") ) {d247 1a247 1 }@@+ else if ( 0==strcmp(keyword,"NODE_COORD_SECTION") ) {d249 1a249 1 }@@+ else if ( 0==strcmp(keyword,"DISPLAY_DATA_SECTION") ) {d251 1a251 1 }@@+ else if ( 0==strcmp(keyword,"SEED") ) {d301 2d312 1a312 1typedef enum { EUC_2D, EXPLICIT, RANDOM_EDGES } edge_weight_type_t;d612 10d623 2a624 1about 15% slower on an SGI Challenge, even using the native C compilerd685 1a685 1on an Intel 486.d713 7@1.128log@Made coordinates indexed by number, not name, i.e. x[0] and x[1] insteadof x and y. This reduces the code size in kdtree by removingthe CUTDIMEN kludge.@text@d7 5d100 1a100 1const char *read_rcs_id="$Id: read.w,v 1.127 1997/09/27 18:04:39 neto Exp neto $";d455 1a455 1 fscanf(in," %lf %lf ",&p->coord[j-1].x,&p->coord[j-1].y);d753 1a753 1 fprintf(debug,"%f %f ts\n",p->coord[i].x,p->coord[i].y);@1.127log@Fixed RCS log behaviour@text@d7 3d95 1a95 1const char *read_rcs_id="$Id: read.w,v 1.126 1997/08/15 20:18:25 neto Exp neto $";d451 4a454 4 p->xmin = min(p->xmin,p->coord[j-1].x); p->ymin = min(p->ymin,p->coord[j-1].y); p->xmax = max(p->xmax,p->coord[j-1].x); p->ymax = max(p->ymax,p->coord[j-1].y);d459 10a468 2@@ @@<Early type definitions@@>=typedef struct { double x, y; } coord_2d;d596 2a597 2 double xd = coord_array[i].x - coord_array[j].x; double yd = coord_array[i].y - coord_array[j].y;d628 2a629 2 double xd = coord_array[i].x - coord_array[j].x; double yd = coord_array[i].y - coord_array[j].y;d645 2a646 2 double xd = coord_array[i].x - coord_array[j].x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -