49#define READER_NAME "csolreader"
50#define READER_DESC "file reader which reads and writes csol-files"
51#define READER_EXTENSION "csol"
53#define COL_MAX_LINELEN 65535
69 while ( isspace((
unsigned char)**s) )
74 while ( (**s != 0) && (!isspace((
unsigned char)**s)) )
87 assert(reader != NULL);
88 assert(strcmp(SCIPreaderGetName(reader),
READER_NAME) == 0);
101 const char* probname;
103 SCIP_Bool correctinstance;
104 TCLIQUE_GRAPH* graph;
106 SCIP_CONS** constraints;
119 assert(reader != NULL);
120 assert(strcmp(SCIPreaderGetName(reader),
READER_NAME) == 0);
121 assert(scip != NULL);
122 assert(result != NULL);
123 assert(filename != NULL);
124 *result = SCIP_SUCCESS;
126 if ( SCIPgetStage(scip) == SCIP_STAGE_INIT )
128 SCIPerrorMessage(
"Please read in problem before reading the solution!\n");
132 if (NULL == (fp = SCIPfopen(filename,
"r")))
134 SCIPerrorMessage(
"cannot open file <%s> for reading\n", filename);
140 if( SCIPfgets(buf, (
int)
sizeof(buf), fp) == NULL )
141 return SCIP_READERROR;
144 while ( !isspace((
unsigned char)buf[i]) )
148 SCIP_CALL( SCIPallocBufferArray(scip, &solprobname, i+2) );
149 (void) SCIPstrncpy(solprobname, buf, i);
151 printf(
"Reading solution for %s...\n", solprobname);
154 probname = SCIPgetProbName(scip);
157 correctinstance = TRUE;
158 for ( j = 0; j <= i; j++ )
160 if ( solprobname[j] != probname[j] )
162 correctinstance = FALSE;
165 if ( !correctinstance )
167 SCIPerrorMessage(
"The selected solution file doesn't belong to the current problem!\n");
173 assert(graph != NULL);
181 SCIP_CALL( SCIPallocBufferArray(scip, &sets, nsets) );
182 SCIP_CALL( SCIPallocBufferArray(scip, &setlengths, nsets) );
183 for ( i = 0; i < nsets; i++ )
188 SCIP_CALL( SCIPallocBufferArray(scip, &(sets[i]), size) );
193 SCIPfgets(buf, (
int)
sizeof(buf), fp);
198 sets[color][setlengths[color]] = i;
199 sets[color][setlengths[color]+1] = -1;
204 for ( i = 0; i < nsets; i++ )
208 while ( sets[i][j] != -1 )
230 printf(
"testing validity...\n");
232 for ( i = 0; i < nsets; i++ )
234 for ( j = 0; j < setlengths[i]; j++ )
236 for ( k = j+1; k < setlengths[i]; k++ )
238 if ( tcliqueIsEdge(graph, sets[i][j], sets[i][k]) )
240 SCIPerrorMessage(
"The solution is not valid!\n");
250 assert(constraints != NULL);
252 for ( i = 0; i < nsets; i++ )
256 for ( j = 0; j < setlengths[i]; j++ )
258 if ( sets[i][j] == node )
262 if ( tcliqueIsEdge(graph, sets[i][j], node) )
267 if ( j == setlengths[i] )
269 sets[i][setlengths[i]] = node;
270 sets[i][setlengths[i]+1] = -1;
277 for ( i = 0; i < nsets; i++ )
279 SCIPsortDownInt(sets[i], setlengths[i]);
281 assert(setindex == i);
283 SCIP_CALL( SCIPcreateVar(scip, &var, NULL, 0.0, 1.0, 1.0, SCIP_VARTYPE_BINARY,
284 TRUE, FALSE, NULL, NULL, NULL, NULL, (SCIP_VARDATA*)(
size_t)setindex) );
287 SCIP_CALL( SCIPaddVar(scip, var) );
288 SCIP_CALL( SCIPchgVarUbLazy(scip, var, 1.0) );
291 for ( j = 0; j < setlengths[i]; j++ )
293 SCIP_CALL( SCIPaddCoefSetppc(scip, constraints[sets[i][j]], var) );
300 for ( i = nsets-1; i >= 0; i-- )
302 SCIPfreeBufferArray(scip, &(sets[i]));
304 SCIPfreeBufferArray(scip, &setlengths);
305 SCIPfreeBufferArray(scip, &sets);
306 SCIPfreeBufferArray(scip, &solprobname);
323 SCIP_Bool colorpossible;
324 TCLIQUE_GRAPH* oldgraph;
339 *result = SCIP_DIDNOTRUN;
344 assert(originalnodes != NULL);
346 assert(deletednodes != NULL);
349 assert(sets != NULL && nsetelements != NULL);
352 sol = SCIPgetBestSol(scip);
355 SCIP_CALL( SCIPallocBufferArray(scip, &colors, nnodes) );
356 for ( i = 0; i < nnodes; i++ )
363 for ( i = 0; i < nsets; i++ )
368 for ( j = 0; j < nsetelements[i]; j++ )
370 if ( colors[originalnodes[sets[i][j]]] == -1 )
372 colors[originalnodes[sets[i][j]]] = actcolor;
381 while ( deletednodes[i] == -1 )
389 node = deletednodes[i];
391 while ( colors[node] == -1 )
393 colorpossible = TRUE;
394 firstedge = tcliqueGetFirstAdjedge(oldgraph, node);
395 lastedge = tcliqueGetLastAdjedge(oldgraph, node);
396 while ( firstedge <= lastedge )
398 if ( colors[*firstedge] == j )
400 colorpossible = FALSE;
405 if ( colorpossible == TRUE )
417 SCIPinfoMessage(scip, file,
"%s %d generated by ColumnGenerationColoring\n", name, actcolor);
418 for ( i = 0; i < nnodes; i++ )
420 SCIPinfoMessage(scip, file,
"%d ", colors[i]);
423 SCIPfreeBufferArray(scip, &colors);
425 *result = SCIP_SUCCESS;
440 SCIP_READERDATA* readerdata;
450 SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyCsol) );
451 SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadCsol) );
452 SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWriteCsol) );
int COLORprobGetNewNodeForOriginalNode(SCIP *scip, int node)
TCLIQUE_GRAPH * COLORprobGetOriginalGraph(SCIP *scip)
SCIP_CONS ** COLORprobGetConstraints(SCIP *scip)
SCIP_RETCODE COLORprobAddNewStableSet(SCIP *scip, int *stablesetnodes, int nstablesetnodes, int *setindex)
int * COLORprobGetOriginalNodesForNewNodes(SCIP *scip)
int COLORprobGetNNodes(SCIP *scip)
int COLORprobGetOriginalNNodes(SCIP *scip)
SCIP_VAR * COLORprobGetVarForStableSet(SCIP *scip, int setindex)
void COLORprobGetStableSets(SCIP *scip, int ***stablesets, int **nelements, int *nstablesets)
TCLIQUE_GRAPH * COLORprobGetGraph(SCIP *scip)
SCIP_RETCODE COLORprobAddVarForStableSet(SCIP *scip, int setindex, SCIP_VAR *var)
int * COLORprobGetDeletedNodes(SCIP *scip)
problem data for vertex coloring algorithm
file reader for vertex coloring instances
static SCIP_DECL_READERWRITE(readerWriteCsol)
static SCIP_DECL_READERCOPY(readerCopyCsol)
SCIP_RETCODE SCIPincludeReaderCsol(SCIP *scip)
static SCIP_DECL_READERREAD(readerReadCsol)
static long getNextNumber(char **s)
file reader and writer for vertex coloring solutions