Skip to content

Commit cb374fe

Browse files
committed
Merge remote-tracking branch 'origin/v92-bugfix' into v9-minor
2 parents 8c17cf4 + 13041fa commit cb374fe

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Build system
5858
Miscellaneous
5959
-------------
6060

61+
- when writing a problem with non-generic names, warnings are printed if variable or constraint names are not unique
62+
6163
@section RN922 SCIP 9.2.2
6264
*************************
6365

src/scip/reader.c

+68
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ SCIP_RETCODE SCIPreaderWrite(
271271
SCIP_READER* reader, /**< reader */
272272
SCIP_PROB* prob, /**< problem data */
273273
SCIP_SET* set, /**< global SCIP settings */
274+
SCIP_MESSAGEHDLR* msghdlr, /**< message handler */
274275
FILE* file, /**< output file (or NULL for standard output) */
275276
const char* extension, /**< file format */
276277
SCIP_Bool genericnames, /**< using generic variable and constraint names? */
@@ -302,12 +303,52 @@ SCIP_RETCODE SCIPreaderWrite(
302303
int nconss;
303304
int nvars;
304305
int i;
306+
int nduplicates;
305307

306308
vars = SCIPprobGetVars(prob);
307309
nvars = SCIPprobGetNVars(prob);
308310
fixedvars = SCIPprobGetFixedVars(prob);
309311
nfixedvars = SCIPprobGetNFixedVars(prob);
310312

313+
/* check if multiple variables have the same name */
314+
if ( !genericnames )
315+
{
316+
nduplicates = 0;
317+
318+
for( i = 0; i < nvars; ++i )
319+
{
320+
if( vars[i] != (SCIP_VAR*) SCIPprobFindVar(prob, (void*) SCIPvarGetName(vars[i])) )
321+
{
322+
if( nduplicates < 3 )
323+
{
324+
SCIPmessageFPrintWarning(msghdlr, "The same variable name <%s> has been used for at least two different variables.\n", SCIPvarGetName(vars[i]));
325+
}
326+
++nduplicates;
327+
}
328+
}
329+
330+
for( i = 0; i < nfixedvars; ++i )
331+
{
332+
if( fixedvars[i] != (SCIP_VAR*) SCIPprobFindVar(prob, (void*) SCIPvarGetName(fixedvars[i])) )
333+
{
334+
if( nduplicates < 3 )
335+
{
336+
SCIPmessageFPrintWarning(msghdlr, "The same variable name <%s> has been used for at least two different variables.\n", SCIPvarGetName(fixedvars[i]));
337+
}
338+
++nduplicates;
339+
}
340+
}
341+
342+
if( nduplicates > 0 )
343+
{
344+
if( nduplicates > 3 )
345+
{
346+
SCIPmessageFPrintWarning(msghdlr, "In total %d duplicate variable names.\n", nduplicates);
347+
}
348+
SCIPmessageFPrintWarning(msghdlr, "This will likely result in wrong output files. Please use unique variable names.\n");
349+
}
350+
}
351+
311352
/* case of the transformed problem, we want to write currently valid problem */
312353
if( SCIPprobIsTransformed(prob) )
313354
{
@@ -369,6 +410,33 @@ SCIP_RETCODE SCIPreaderWrite(
369410
nconss = SCIPprobGetNConss(prob);
370411
}
371412

413+
/* check if multiple constraints have the same name */
414+
if ( !genericnames )
415+
{
416+
nduplicates = 0;
417+
418+
for( i = 0; i < SCIPprobGetNConss(prob); ++i )
419+
{
420+
if( conss[i] != (SCIP_CONS*) SCIPprobFindCons(prob, (void*) SCIPconsGetName(conss[i])) )
421+
{
422+
if( nduplicates < 3 )
423+
{
424+
SCIPmessageFPrintWarning(msghdlr, "The same constraint name <%s> has been used for at least two different constraints.\n", SCIPconsGetName(conss[i]));
425+
}
426+
++nduplicates;
427+
}
428+
}
429+
430+
if( nduplicates > 0)
431+
{
432+
if( nduplicates > 3 )
433+
{
434+
SCIPmessageFPrintWarning(msghdlr, "In total %d duplicate constraint names.\n", nduplicates);
435+
}
436+
SCIPmessageFPrintWarning(msghdlr, "This can result in wrong output files, especially with indicator constraints.\n");
437+
}
438+
}
439+
372440
if( genericnames )
373441
{
374442
SCIP_VAR* var;

src/scip/reader.h

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ SCIP_RETCODE SCIPreaderWrite(
8787
SCIP_READER* reader, /**< reader */
8888
SCIP_PROB* prob, /**< problem data */
8989
SCIP_SET* set, /**< global SCIP settings */
90+
SCIP_MESSAGEHDLR* msghdlr, /**< message handler */
9091
FILE* file, /**< output file (or NULL for standard output) */
9192
const char* format, /**< file format (or NULL) */
9293
SCIP_Bool genericnames, /**< using generic variable and constraint names? */

src/scip/scip_solvingstats.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2319,9 +2319,9 @@ SCIP_RETCODE printProblem(
23192319
SCIP_RETCODE retcode;
23202320

23212321
if( extension != NULL )
2322-
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, file, extension, genericnames, &result);
2322+
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, scip->messagehdlr, file, extension, genericnames, &result);
23232323
else
2324-
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, file, "cip", genericnames, &result);
2324+
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, scip->messagehdlr, file, "cip", genericnames, &result);
23252325

23262326
/* check for reader errors */
23272327
if( retcode == SCIP_WRITEERROR )

0 commit comments

Comments
 (0)