42#define READER_NAME "colreader"
43#define READER_DESC "file reader for a .col-file representing a graph that should be colored"
44#define READER_EXTENSION "col"
46#define COL_MAX_LINELEN 1024
62 while ( isspace((
unsigned char)**s) )
67 while ( (**s != 0) && (!isspace((
unsigned char)**s)) )
91 SCIP_Bool duplicateedge;
95 assert(filename != NULL);
97 if (NULL == (fp = SCIPfopen(filename,
"r")))
99 SCIPerrorMessage(
"cannot open file <%s> for reading\n", filename);
105 if( SCIPfgets(buf, (
int)
sizeof(buf), fp) == NULL)
106 return SCIP_READERROR;
109 while ( (filename[i] !=
'/') && (filename[i] !=
'\0') )
113 if ( filename[i] !=
'/' )
121 while ( filename[i] ==
'/' && filename[j] !=
'\0' )
124 while ( filename[j] !=
'\0' )
127 if ( filename[j] ==
'/' )
137 return SCIP_READERROR;
139 SCIP_CALL( SCIPallocBufferArray(scip, &probname, (j-i-4)) );
140 (void) strncpy(probname, &filename[i+1], (j-i-5));
141 probname[j-i-5]=
'\0';
144 while( !SCIPfeof(fp) && (buf[0] !=
'p') )
146 SCIPfgets(buf, (
int)
sizeof(buf), fp);
152 SCIPerrorMessage(
"Error! Could not find line starting with 'p'.\n");
153 return SCIP_READERROR;
157 if ( buf[2] !=
'e' || buf[3] !=
'd' || buf[4] !=
'g' || buf[5] !=
'e' )
159 SCIPerrorMessage(
"Line starting with 'p' must continue with 'edge'!\n");
160 return SCIP_READERROR;
165 if ( *char_p ==
's' )
175 SCIPerrorMessage(
"Number of vertices must be positive!\n");
176 return SCIP_READERROR;
181 SCIPerrorMessage(
"Number of edges must be nonnegative!\n");
182 return SCIP_READERROR;
186 SCIP_CALL( SCIPallocBufferArray(scip, &edges, nedges) );
187 for( i = 0; i < nedges; i++)
189 SCIP_CALL( SCIPallocBufferArray(scip, &(edges[i]), 2) );
194 while ( !SCIPfeof(fp) )
196 SCIPfgets(buf, (
int)
sizeof(buf), fp);
199 duplicateedge = FALSE;
204 for ( j = 0; j < i; j++)
206 if ( ((edges[j][0] == begin) && (edges[j][1] == end))
207 || ((edges[j][1] == begin) && (edges[j][0] == end)) )
209 duplicateedge = TRUE;
214 if ( !duplicateedge )
218 SCIPerrorMessage(
"more edges than expected: expected %d many, but got already %d'th (non-duplicate) edge", nedges, i+1);
219 return SCIP_READERROR;
223 assert((edges[i][0] > 0) && (edges[i][0] <= nnodes));
224 assert((edges[i][1] > 0) && (edges[i][1] <= nnodes));
229 if( i + nduplicateedges != nedges )
231 SCIPerrorMessage(
"incorrect number of edges: expected %d many, but got %d many\n", nedges, i + nduplicateedges);
235 printf(
"Read graph: %d nodes, %d edges (%d duplicates)\n", nnodes, nedges, nduplicateedges);
241 SCIPdebugMessage(
"Create LP...\n");
245 SCIP_CALL( SCIPactivatePricer(scip, SCIPfindPricer(scip,
"coloring")) );
246 SCIP_CALL( SCIPsetObjIntegral(scip) );
247 for ( i = nedges-1; i >= 0; i--)
249 SCIPfreeBufferArray(scip, &(edges[i]));
251 SCIPfreeBufferArray(scip, &edges);
252 SCIPfreeBufferArray(scip, &probname);
269 assert(scip != NULL);
270 assert(reader != NULL);
271 assert(strcmp(SCIPreaderGetName(reader),
READER_NAME) == 0);
280 assert(reader != NULL);
281 assert(strcmp(SCIPreaderGetName(reader),
READER_NAME) == 0);
282 assert(scip != NULL);
283 assert(result != NULL);
285 SCIP_CALL(
readCol(scip, filename) );
287 *result = SCIP_SUCCESS;
304 SCIP_READERDATA* readerdata;
313 SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyCol) );
314 SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadCol) );
SCIP_RETCODE SCIPcreateProbColoring(SCIP *scip, const char *name, int nnodes, int nedges, int **edges)
SCIP_RETCODE COLORprobSetUpArrayOfCons(SCIP *scip)
SCIP_RETCODE SCIPincludeReaderCol(SCIP *scip)
static SCIP_RETCODE readCol(SCIP *scip, const char *filename)
static SCIP_DECL_READERREAD(readerReadCol)
static SCIP_DECL_READERCOPY(readerCopyCol)
static long getNextNumber(char **s)
file reader for vertex coloring instances