Skip to content

Commit 0f9b621

Browse files
committed
Merge remote-tracking branch 'origin/v9-minor'
2 parents f629611 + cb374fe commit 0f9b621

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
@@ -320,6 +320,8 @@ Build system
320320
Miscellaneous
321321
-------------
322322

323+
- when writing a problem with non-generic names, warnings are printed if variable or constraint names are not unique
324+
323325
@section RN922 SCIP 9.2.2
324326
*************************
325327

src/scip/reader.c

+68
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ SCIP_RETCODE SCIPreaderWrite(
279279
SCIP_READER* reader, /**< reader */
280280
SCIP_PROB* prob, /**< problem data */
281281
SCIP_SET* set, /**< global SCIP settings */
282+
SCIP_MESSAGEHDLR* msghdlr, /**< message handler */
282283
FILE* file, /**< output file (or NULL for standard output) */
283284
const char* extension, /**< file format */
284285
SCIP_Bool genericnames, /**< using generic variable and constraint names? */
@@ -310,6 +311,7 @@ SCIP_RETCODE SCIPreaderWrite(
310311
int nconss;
311312
int nvars;
312313
int i;
314+
int nduplicates;
313315

314316
/* only readers marked as exact can read and write in exact solving mode */
315317
if( set->exact_enable && !reader->exact )
@@ -323,6 +325,45 @@ SCIP_RETCODE SCIPreaderWrite(
323325
fixedvars = SCIPprobGetFixedVars(prob);
324326
nfixedvars = SCIPprobGetNFixedVars(prob);
325327

328+
/* check if multiple variables have the same name */
329+
if ( !genericnames )
330+
{
331+
nduplicates = 0;
332+
333+
for( i = 0; i < nvars; ++i )
334+
{
335+
if( vars[i] != (SCIP_VAR*) SCIPprobFindVar(prob, (void*) SCIPvarGetName(vars[i])) )
336+
{
337+
if( nduplicates < 3 )
338+
{
339+
SCIPmessageFPrintWarning(msghdlr, "The same variable name <%s> has been used for at least two different variables.\n", SCIPvarGetName(vars[i]));
340+
}
341+
++nduplicates;
342+
}
343+
}
344+
345+
for( i = 0; i < nfixedvars; ++i )
346+
{
347+
if( fixedvars[i] != (SCIP_VAR*) SCIPprobFindVar(prob, (void*) SCIPvarGetName(fixedvars[i])) )
348+
{
349+
if( nduplicates < 3 )
350+
{
351+
SCIPmessageFPrintWarning(msghdlr, "The same variable name <%s> has been used for at least two different variables.\n", SCIPvarGetName(fixedvars[i]));
352+
}
353+
++nduplicates;
354+
}
355+
}
356+
357+
if( nduplicates > 0 )
358+
{
359+
if( nduplicates > 3 )
360+
{
361+
SCIPmessageFPrintWarning(msghdlr, "In total %d duplicate variable names.\n", nduplicates);
362+
}
363+
SCIPmessageFPrintWarning(msghdlr, "This will likely result in wrong output files. Please use unique variable names.\n");
364+
}
365+
}
366+
326367
/* case of the transformed problem, we want to write currently valid problem */
327368
if( SCIPprobIsTransformed(prob) )
328369
{
@@ -384,6 +425,33 @@ SCIP_RETCODE SCIPreaderWrite(
384425
nconss = SCIPprobGetNConss(prob);
385426
}
386427

428+
/* check if multiple constraints have the same name */
429+
if ( !genericnames )
430+
{
431+
nduplicates = 0;
432+
433+
for( i = 0; i < SCIPprobGetNConss(prob); ++i )
434+
{
435+
if( conss[i] != (SCIP_CONS*) SCIPprobFindCons(prob, (void*) SCIPconsGetName(conss[i])) )
436+
{
437+
if( nduplicates < 3 )
438+
{
439+
SCIPmessageFPrintWarning(msghdlr, "The same constraint name <%s> has been used for at least two different constraints.\n", SCIPconsGetName(conss[i]));
440+
}
441+
++nduplicates;
442+
}
443+
}
444+
445+
if( nduplicates > 0)
446+
{
447+
if( nduplicates > 3 )
448+
{
449+
SCIPmessageFPrintWarning(msghdlr, "In total %d duplicate constraint names.\n", nduplicates);
450+
}
451+
SCIPmessageFPrintWarning(msghdlr, "This can result in wrong output files, especially with indicator constraints.\n");
452+
}
453+
}
454+
387455
if( genericnames )
388456
{
389457
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
@@ -2543,9 +2543,9 @@ SCIP_RETCODE printProblem(
25432543
SCIP_RETCODE retcode;
25442544

25452545
if( extension != NULL )
2546-
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, file, extension, genericnames, &result);
2546+
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, scip->messagehdlr, file, extension, genericnames, &result);
25472547
else
2548-
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, file, "cip", genericnames, &result);
2548+
retcode = SCIPreaderWrite(scip->set->readers[i], prob, scip->set, scip->messagehdlr, file, "cip", genericnames, &result);
25492549

25502550
/* check for reader errors */
25512551
if( retcode == SCIP_WRITEERROR )

0 commit comments

Comments
 (0)