( *str !=
'\0'&& ( isspace(*str) || *str ==
':') )
63 while( *str !=
'\0'&& *str !=
':'&& ! isspace(*str) )
70 while( *str !=
'\0'&& ( isspace(*str) || *str ==
':') )
116 if( nodenumber-1 != i)
118cout <<
"warning: nodenumber <"<< nodenumber <<
"> does not match its index in node list <"<< i+1
119<<
">. Node will get number "<< i+1 <<
" when naming variables and constraints!"<< endl;
122node->
x= x_coords[i];
123node->
y= y_coords[i];
128assert( i == graph->
nnodes);
141assert(edge !=
NULL);
142assert(var !=
NULL);
157boolReaderTSP::checkValid(
159 conststd::string& name,
160 conststd::string& type,
161 conststd::string& edgeweighttype,
169cout <<
"parse error in file <"<< name <<
"> dimension should be greater than 0"<< endl ;
175cout <<
"parse error in file <"<< name <<
"> type should be TSP"<< endl;
179 if( !( edgeweighttype ==
"EUC_2D"|| edgeweighttype ==
"MAX_2D"|| edgeweighttype ==
"MAN_2D" 180|| edgeweighttype ==
"GEO"|| edgeweighttype ==
"ATT") )
182cout <<
"parse error in file <"<< name <<
"> unknown weight type, should be EUC_2D, MAX_2D, MAN_2D, ATT, or GEO"<< endl;
188cout <<
"error while reading file <"<< name <<
">, graph is uninitialized. ";
189cout <<
"Probably NODE_COORD_SECTION is missing"<< endl;
223 double* x_coords =
NULL;
224 double* y_coords =
NULL;
227 double** weights =
NULL;
238 stringname =
"MY_OWN_LITTLE_TSP";
240 stringtype =
"TSP";
241 stringedgeweighttype =
"EUC_2D";
261 if( token ==
"NAME")
263 else if( token ==
"TYPE")
265 else if( token ==
"DIMENSION")
274 else if( token ==
"EDGE_WEIGHT_TYPE")
276 else if( token ==
"NODE_COORD_SECTION"|| token ==
"DISPLAY_DATA_SECTION")
287assert(x_coords ==
NULL);
288assert(y_coords ==
NULL);
290x_coords =
new double[
nnodes];
291y_coords =
new double[
nnodes];
292 SCIP_CALL( getNodesFromFile(file, x_coords, y_coords, graph) );
300 else if( token ==
"COMMENT:"|| token ==
"COMMENT"|| token ==
"DISPLAY_DATA_TYPE"|| token ==
"DISPLAY_DATA_TYPE:")
304 else if( token ==
"EOF")
306 else if( token ==
"")
310cout <<
"parse error in file <"<< name <<
"> unknown keyword <"<< token <<
">"<< endl;
321 if( ! checkValid(graph, name, type, edgeweighttype,
nnodes) )
324assert(graph !=
NULL);
328edgeforw = &( graph->
edges[0] );
329edgebackw= &( graph->
edges[nedges/2] );
332weights =
new double* [
nnodes];
333 for( i = 0; i <
nnodes; ++i )
334weights[i] =
new double[
nnodes];
338 for( i = 0; i <
nnodes; i++ )
340nodestart = &graph->
nodes[i];
341 for( j = i+1; j <
nnodes; j++ )
343nodeend = &graph->
nodes[j];
346edgeforw->
adjac= nodeend;
347edgebackw->
adjac= nodestart;
348edgeforw->
back= edgebackw;
349edgebackw->
back= edgeforw;
352 x= x_coords[(*nodestart).id] - x_coords[(*nodeend).id];
353 y= y_coords[(*nodestart).id] - y_coords[(*nodeend).id];
354 if( edgeweighttype ==
"EUC_2D")
356 else if( edgeweighttype ==
"MAX_2D")
358 else if( edgeweighttype ==
"MAN_2D")
360 else if( edgeweighttype ==
"ATT")
361edgeforw->
length= ceil( sqrt( (
x*
x+
y*
y)/10.0 ) );
362 else if( edgeweighttype ==
"GEO")
364 const doublepi = 3.141592653589793;
372coords[0] = x_coords[(*nodestart).id];
373coords[1] = y_coords[(*nodestart).id];
374coords[2] = x_coords[(*nodeend).id];
375coords[3] = y_coords[(*nodeend).id];
377 for( k = 0; k < 4; k++ )
379degs[k] = coords[k] >= 0 ? floor(coords[k]) : ceil(coords[k]);
380mins[k] = coords[k] - degs[k];
381rads[k] = pi*(degs[k]+5.0*mins[k]/3.0)/180.0;
384euler[0] = cos(rads[1]-rads[3]);
385euler[1] = cos(rads[0]-rads[2]);
386euler[2] = cos(rads[0]+rads[2]);
387edgeforw->
length= floor(6378.388 * acos(0.5*((1.0+euler[0])*euler[1]-(1.0-euler[0])*euler[2]))+1.0);
391 if( round_lengths_ )
396weights[i][j] = edgeforw->
length;
397weights[j][i] = edgebackw->
length;
436 if( weights !=
NULL)
438 for( i = 0; i <
nnodes; i++ )
440 delete[] weights[i];
449printf(
"Matrix:\n");
450 for( i = 0; i <
nnodes; i++ )
452 for( j = 0; j <
nnodes; j++ )
453printf(
" %4.0f ",weights[i][j]);
455 delete[] weights[i];
464 for( i = 0; i < nedges/2; i++ )
468stringstream varname;
469edge = &graph->
edges[i];
492 for( i = 0, node = &(graph->
nodes[0]); i <
nnodes; i++, node++ )
496stringstream consname;
497consname <<
"deg_con_v"<< node->
id+1;
505 while( edge !=
NULL)
C++ constraint handler for TSP subtour elimination constraints.
SCIP_Bool create_graph(int n, int m, GRAPH **gr)
void release_graph(GRAPH **gr)
generator for global cuts in undirected graphs
C++ problem data for TSP.
SCIP_DECL_READERREAD(ReaderTSP::scip_read)
SCIP_DECL_READERWRITE(ReaderTSP::scip_write)
SCIP_DECL_READERFREE(ReaderTSP::scip_free)
string getToken(char *&str)
C++ file reader for TSP data files.
Constraint handler for linear constraints in their most general form, .
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
int SCIPfeof(SCIP_FILE *stream)
int SCIPfclose(SCIP_FILE *fp)
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
SCIP_RETCODE SCIPcaptureVar(SCIP *scip, SCIP_VAR *var)
SCIP_Bool SCIPstrToIntValue(const char *str, int *value, char **endptr)
SCIP_Bool SCIPstrToRealValue(const char *str, SCIP_Real *value, char **endptr)
SCIP_RETCODE SCIPcreateConsSubtour(SCIP *scip, SCIP_CONS **cons, const char *name, GRAPH *graph, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable)
SCIP_RETCODE SCIPcreateObjProb(SCIP *scip, const char *name, scip::ObjProbData *objprobdata, SCIP_Bool deleteobject)
C++ wrapper classes for SCIP.
wrapper functions to map file i/o to standard or zlib file i/o
struct SCIP_File SCIP_FILE
struct GraphEdge * first_edge
enum SCIP_Retcode SCIP_RETCODE
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4