54 #include "scip/cons_linear.h" 55 #include "scip/cons_indicator.h" 57 #define READER_NAME "sdpareader" 58 #define READER_DESC "file reader and writer for MISDPs in sdpa format" 59 #define READER_EXTENSION "dat-s" 61 #define SDPA_MIN_BUFFERLEN 65536 66 SCIP_Bool* sdpblockrank1;
69 SCIP_VAR** createdvars;
71 SCIP_CONS** createdconss;
77 SCIP_VAR*** sdpblockvars;
83 SCIP_Real*** valpointer;
84 int* sdpconstnblocknonz;
88 SCIP_Real** sdpconstval;
113 assert( scip != NULL );
114 assert( file != NULL );
115 assert( buffer != NULL );
116 assert( bufferlen != NULL );
117 assert( success != NULL );
120 if ( *buffer == NULL )
122 assert( *bufferlen == 0 );
126 assert( *bufferlen >= 2 );
129 (*buffer)[*bufferlen-2] =
'\0';
132 if ( SCIPfgets(*buffer, *bufferlen, file) == NULL )
139 while ( (*buffer)[*bufferlen-2] !=
'\0' )
143 assert( (*buffer)[*bufferlen-1] ==
'\0' );
146 newsize = SCIPcalcMemGrowSize(scip, *bufferlen + 1);
147 SCIP_CALL( SCIPreallocBlockMemoryArray(scip, buffer, *bufferlen, newsize) );
148 assert( newsize >= *bufferlen + 1 );
151 (*buffer)[newsize-2] =
'\0';
154 if ( SCIPfgets(*buffer + *bufferlen - 1, newsize - *bufferlen + 1, file) == NULL )
159 *bufferlen = newsize;
174 SCIP_Longint* linecount,
180 assert( buffer != NULL );
181 assert( bufferlen != NULL );
182 assert( linecount != NULL );
183 assert( success != NULL );
188 SCIP_CALL(
readLine(scip, file, buffer, bufferlen, success) );
194 if ( strncmp(*buffer,
"*INTEGER", 8) == 0 || strncmp(*buffer,
"*RANK1", 5) == 0 )
197 while ( **buffer ==
'*' || **buffer ==
'"' || **buffer ==
'\n' );
201 comment = strpbrk(*buffer,
"*\"=");
202 if ( comment != NULL )
216 SCIP_Longint* linecount,
220 assert( buffer != NULL );
221 assert( bufferlen != NULL );
222 assert( linecount != NULL );
223 assert( success != NULL );
228 SCIP_CALL(
readLine(scip, file, buffer, bufferlen, success) );
234 if ( strncmp(*buffer,
"*INTEGER", 8) == 0 || strncmp(*buffer,
"*RANK1", 5) == 0 )
237 while ( **buffer ==
'\n' );
251 SCIP_Longint* linecount,
263 assert( nread != NULL );
266 SCIP_CALL(
readLine(scip, file, buffer, bufferlen, &success) );
272 while ( *str !=
'\0' )
275 while ( isspace(*str) )
279 if ( isdigit(*str) || *str ==
'-' || *str ==
'+' )
283 SCIPwarningMessage(scip,
"Warning: Already read %d values in line %" SCIP_LONGINT_FORMAT
", dropping following numbers in the same line.\n", cnt, *linecount);
288 val = strtod(str, &endptr);
289 if ( endptr == NULL )
291 SCIPerrorMessage(
"Could not read number in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
293 return SCIP_READERROR;
296 if ( SCIPisInfinity(scip, val) || SCIPisInfinity(scip, -val) )
298 SCIPerrorMessage(
"Given value in line %" SCIP_LONGINT_FORMAT
" for variable %d is infinity, which is not allowed.\n",
301 return SCIP_READERROR;
308 else if ( *str ==
'*' || *str ==
'\"' || *str ==
'=' )
313 SCIP_CALL(
readLine(scip, file, buffer, bufferlen, &success) );
326 SCIPerrorMessage(
"Found invalid symbol in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
328 return SCIP_READERROR;
345 SCIP_Longint* linecount,
357 assert( nread != NULL );
360 SCIP_CALL(
readLine(scip, file, buffer, bufferlen, &success) );
366 while ( *str !=
'\0' )
369 while ( isspace(*str) )
373 if ( isdigit(*str) || *str ==
'-' || *str ==
'+' )
377 SCIPwarningMessage(scip,
"Warning: Already read %d values in line %" SCIP_LONGINT_FORMAT
", dropping following numbers in the same line.\n", cnt, *linecount);
382 val = (int) strtol(str, &endptr, 10);
383 if ( endptr == NULL )
385 SCIPerrorMessage(
"Could not read number in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
387 return SCIP_READERROR;
393 else if ( *str ==
'*' || *str ==
'\"' || *str ==
'=' )
398 SCIP_CALL(
readLine(scip, file, buffer, bufferlen, &success) );
411 SCIPerrorMessage(
"Found invalid symbol in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
413 return SCIP_READERROR;
433 assert( scip != NULL );
434 assert( data != NULL );
436 SCIPfreeBlockMemoryArrayNull(scip, &data->buffer, data->bufferlen);
439 if ( data->nsdpblocks > 0 )
441 assert( data->nvars > 0 );
443 if ( data->sdprow != NULL )
445 for (b = 0; b < data->nsdpblocks; b++)
447 assert( data->sdpmemsize[b] > 0);
448 assert( data->sdpconstmemsize[b] > 0);
450 SCIPfreeBlockMemoryArrayNull(scip, &(data->valpointer[b]), data->nvars);
451 SCIPfreeBlockMemoryArrayNull(scip, &(data->colpointer[b]), data->nvars);
452 SCIPfreeBlockMemoryArrayNull(scip, &(data->rowpointer[b]), data->nvars);
453 SCIPfreeBlockMemoryArrayNull(scip, &(data->nvarnonz[b]), data->nvars);
454 SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpblockvars[b]), data->nvars);
455 SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpconstval[b]), data->sdpconstmemsize[b]);
456 SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpconstcol[b]), data->sdpconstmemsize[b]);
457 SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpconstrow[b]), data->sdpconstmemsize[b]);
458 SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpval[b]), data->sdpmemsize[b]);
459 SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpcol[b]), data->sdpmemsize[b]);
460 SCIPfreeBlockMemoryArrayNull(scip, &(data->sdprow[b]), data->sdpmemsize[b]);
463 SCIPfreeBlockMemoryArrayNull(scip, &data->valpointer, data->nsdpblocks);
464 SCIPfreeBlockMemoryArrayNull(scip, &data->colpointer, data->nsdpblocks);
465 SCIPfreeBlockMemoryArrayNull(scip, &data->rowpointer, data->nsdpblocks);
466 SCIPfreeBlockMemoryArrayNull(scip, &data->nvarnonz, data->nsdpblocks);
467 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpblockvars, data->nsdpblocks);
468 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpnblockvars, data->nsdpblocks);
469 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpconstval, data->nsdpblocks);
470 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpconstcol, data->nsdpblocks);
471 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpconstrow, data->nsdpblocks);
472 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpval, data->nsdpblocks);
473 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpcol, data->nsdpblocks);
474 SCIPfreeBlockMemoryArrayNull(scip, &data->sdprow, data->nsdpblocks);
475 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpconstnblocknonz, data->nsdpblocks);
476 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpnblocknonz, data->nsdpblocks);
477 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpconstmemsize, data->nsdpblocks);
478 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpmemsize, data->nsdpblocks);
481 SCIPfreeBlockMemoryArrayNull(scip, &data->createdconss, data->nlinconss);
482 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpblockrank1, data->nsdpblocks);
483 SCIPfreeBlockMemoryArrayNull(scip, &data->sdpblocksizes, data->nsdpblocks);
484 SCIPfreeBlockMemoryArrayNull(scip, &data->createdvars, data->nvars);
486 SCIPfreeBufferNull(scip, &data);
489 if ( SCIPfclose(file) )
490 return SCIP_READERROR;
501 SCIP_Longint* linecount,
507 char varname[SCIP_MAXSTRLEN];
514 assert( scip != NULL );
515 assert( file != NULL );
516 assert( linecount != NULL );
517 assert( data != NULL );
519 SCIP_CALL(
readNextLine(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
522 SCIPerrorMessage(
"Unexpected end of file in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
526 if ( sscanf(data->buffer,
"%i", &data->nvars) != 1 )
528 SCIPerrorMessage(
"Could not read number of scalar variables in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
532 if ( data->nvars < 0 )
534 SCIPerrorMessage(
"Number of scalar variables %d in line %" SCIP_LONGINT_FORMAT
" should be non-negative!\n",
535 data->nvars, *linecount);
539 assert( data->nvars >= 0 );
542 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->createdvars), data->nvars) );
545 for (v = 0; v < data->nvars; v++)
548 snprintfreturn = SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"x_%d", cnt);
549 assert( snprintfreturn < SCIP_MAXSTRLEN );
551 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"x_%d", cnt);
554 SCIP_CALL( SCIPcreateVar(scip, &var, varname, -SCIPinfinity(scip), SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS, TRUE, FALSE, NULL, NULL, NULL,
557 SCIP_CALL( SCIPaddVar(scip, var) );
558 data->createdvars[cnt++] = var;
561 SCIP_CALL( SCIPreleaseVar(scip, &var) );
568 return SCIP_READERROR;
577 SCIP_Longint* linecount,
583 assert( scip != NULL );
584 assert( file != NULL );
585 assert( linecount != NULL );
586 assert( data != NULL );
588 SCIP_CALL(
readNextLine(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
591 SCIPerrorMessage(
"Unexpected end of file in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
595 if ( sscanf(data->buffer,
"%i", &data->nconsblocks) != 1 )
597 SCIPerrorMessage(
"Could not read number of SDP blocks in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
601 if ( data->nconsblocks < 0 )
603 SCIPerrorMessage(
"Number of SDP blocks %d in line %" SCIP_LONGINT_FORMAT
" should be non-negative!\n",
604 data->nconsblocks, *linecount);
608 assert( data->nconsblocks >= 0 );
614 return SCIP_READERROR;
623 SCIP_Longint* linecount,
628 char consname[SCIP_MAXSTRLEN];
642 SCIP_CALL( SCIPallocBufferArray(scip, &blocksizes, data->nconsblocks) );
643 SCIP_CALL( SCIPallocBufferArray(scip, &sdpblocksizes, data->nconsblocks) );
645 assert( scip != NULL );
646 assert( file != NULL );
647 assert( linecount != NULL );
648 assert( data != NULL );
650 SCIP_CALL(
readLineInts(scip, file, &data->buffer, &data->bufferlen, linecount, data->nconsblocks, blocksizes, &nblocks) );
654 else if ( data->nconsblocks != nblocks )
656 SCIPerrorMessage(
"Number of specified blocksizes %d in line %" SCIP_LONGINT_FORMAT
657 " does not match number of blocks %d.\n", nblocks, *linecount, data->nconsblocks);
661 assert( nblocks == data->nconsblocks );
663 for (i = 0; i < nblocks; i++)
666 if ( *(blocksizes + i) < 0 )
668 if ( data->idxlinconsblock == -1 )
669 data->idxlinconsblock = i;
672 SCIPerrorMessage(
"Only one LP block can be defined in line %" SCIP_LONGINT_FORMAT
673 " but at least two blocksizes are negative.\n", *linecount);
676 data->nlinconss = - *(blocksizes + i);
680 if ( *(blocksizes + i) == 0 )
682 SCIPerrorMessage(
"Encountered a block size of 0 in line %" SCIP_LONGINT_FORMAT
" which is not valid.\n",
686 *(sdpblocksizes + nsdpblocks) = *(blocksizes + i);
691 assert( data->idxlinconsblock < 0 || data->nlinconss > 0 );
692 assert( data->idxlinconsblock >= 0 || data->nlinconss == 0 );
694 if ( data->nlinconss < 0 )
696 SCIPerrorMessage(
"Number of linear constraints %d in line %" SCIP_LONGINT_FORMAT
" should be non-negative!\n",
697 data->nlinconss, *linecount);
701 assert( data->nlinconss >= 0 );
702 assert( nsdpblocks >= 0 );
704 data->nsdpblocks = nsdpblocks;
706 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpblocksizes), data->nsdpblocks) );
707 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpblockrank1), data->nsdpblocks) );
708 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->createdconss), data->nlinconss) );
710 for (b = 0; b < nsdpblocks; b++)
712 assert( sdpblocksizes[b] > 0 );
714 data->sdpblocksizes[b] = *(sdpblocksizes + b);
717 data->sdpblockrank1[b] = FALSE;
721 for (c = 0; c < data->nlinconss; c++)
724 snprintfreturn = SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"LP_%d", cnt);
725 assert( snprintfreturn < SCIP_MAXSTRLEN );
727 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"linear_%d", cnt);
730 SCIP_CALL( SCIPcreateConsLinear(scip, &cons, consname, 0, NULL, NULL, 0.0, SCIPinfinity(scip), TRUE, TRUE, TRUE, TRUE, TRUE,
731 FALSE, FALSE, FALSE, FALSE, FALSE) );
733 SCIP_CALL( SCIPaddCons(scip, cons) );
734 data->createdconss[cnt++] = cons;
737 SCIP_CALL( SCIPreleaseCons(scip, &cons) );
740 assert( cnt == data->nlinconss );
742 SCIPfreeBufferArray(scip, &sdpblocksizes);
743 SCIPfreeBufferArray(scip, &blocksizes);
748 SCIPfreeBufferArray(scip, &sdpblocksizes);
749 SCIPfreeBufferArray(scip, &blocksizes);
752 return SCIP_READERROR;
761 SCIP_Longint* linecount,
770 assert( scip != NULL );
771 assert( file != NULL );
772 assert( linecount != NULL );
773 assert( data != NULL );
775 SCIP_CALL( SCIPallocBufferArray(scip, &objvals, data->nvars ) );
777 if ( data->createdvars == NULL )
779 SCIPerrorMessage(
"Number of variables needs to be specified before objective values!\n");
782 assert( data->nvars >= 0 );
784 SCIP_CALL(
readLineDoubles(scip, file, &data->buffer, &data->bufferlen, linecount, data->nvars, objvals, &nreadvals) );
786 if ( nreadvals == -1 )
788 else if ( nreadvals != data->nvars )
790 SCIPerrorMessage(
"Number of objective coefficients %i in line %" SCIP_LONGINT_FORMAT
791 " does not match the number of variables %d.\n", nreadvals, *linecount, data->nvars);
795 assert( data->nvars == nreadvals );
797 for (v = 0; v < data->nvars; v++)
799 if ( SCIPisZero(scip, *(objvals + v)) )
802 SCIP_CALL( SCIPchgVarObj(scip, data->createdvars[v], *(objvals + v)) );
807 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
"Found %d objective coefficients with absolute value less than epsilon = %g.\n",
808 nzerocoef, SCIPepsilon(scip));
811 SCIPfreeBufferArray(scip, &objvals);
817 SCIPfreeBufferArray(scip, &objvals);
820 return SCIP_READERROR;
829 SCIP_Longint* linecount,
833 SCIP_VAR* indvar = 0;
834 SCIP_Real** sdpval_local = NULL;
835 SCIP_Real** sdpconstval_local = NULL;
837 SCIP_Bool infeasible;
839 int** sdprow_local = NULL;
840 int** sdpcol_local = NULL;
841 int** sdpconstrow_local = NULL;
842 int** sdpconstcol_local = NULL;
844 int* nentriessdp = NULL;
845 int* nentriessdpconst = NULL;
846 int* nentrieslincon = NULL;
850 int emptysdpblocks = 0;
851 int emptylinconsblocks = 0;
853 int blockidxoffset = 0;
860 assert( scip != NULL );
861 assert( file != NULL );
862 assert( linecount != NULL );
863 assert( data != NULL );
865 assert( data->nvars >= 0 );
867 if ( data->nvars < 0 || data-> createdvars == NULL )
869 SCIPerrorMessage(
"Number of variables needs to be specified before entries of the blocks!\n");
873 SCIP_CALL( SCIPallocBufferArray(scip, &nentrieslincon, data->nlinconss) );
875 if ( data->nsdpblocks > 0 )
877 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpmemsize), data->nsdpblocks) );
878 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstmemsize), data->nsdpblocks) );
880 SCIP_CALL( SCIPallocBufferArray(scip, &nentriessdp, data->nsdpblocks) );
881 SCIP_CALL( SCIPallocBufferArray(scip, &nentriessdpconst, data->nsdpblocks) );
884 for (b = 0; b < data->nsdpblocks; b++)
886 data->sdpmemsize[b] = 8;
887 data->sdpconstmemsize[b] = 8;
888 nentriessdpconst[b] = 0;
892 for (c = 0; c < data->nlinconss; c++)
893 nentrieslincon[c] = 0;
895 if ( data->nsdpblocks < 0 )
897 SCIPerrorMessage(
"Number of blocks needs to be specified before entries of the blocks!\n");
901 if ( data->sdpblocksizes == NULL )
903 SCIPerrorMessage(
"Sizes of the SDP blocks need to be specified before entries of the blocks!\n");
906 assert( data->nlinconss >= 0 );
909 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpnblocknonz), data->nsdpblocks) );
910 for (b = 0; b < data->nsdpblocks; b++)
911 data->sdpnblocknonz[b] = 0;
914 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpvar), data->nsdpblocks) );
915 SCIP_CALL( SCIPallocBufferArray(scip, &(sdprow_local), data->nsdpblocks) );
916 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpcol_local), data->nsdpblocks) );
917 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpval_local), data->nsdpblocks) );
919 for (b = 0; b < data->nsdpblocks; b++)
921 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpvar[b]), data->sdpmemsize[b]) );
922 SCIP_CALL( SCIPallocBufferArray(scip, &(sdprow_local[b]), data->sdpmemsize[b]) );
923 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpcol_local[b]), data->sdpmemsize[b]) );
924 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpval_local[b]), data->sdpmemsize[b]) );
928 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstnblocknonz), data->nsdpblocks) );
929 for (b = 0; b < data->nsdpblocks; b++)
930 data->sdpconstnblocknonz[b] = 0;
933 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpconstrow_local), data->nsdpblocks) );
934 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpconstcol_local), data->nsdpblocks) );
935 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpconstval_local), data->nsdpblocks) );
937 for (b = 0; b < data->nsdpblocks; b++)
939 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpconstrow_local[b]), data->sdpconstmemsize[b]) );
940 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpconstcol_local[b]), data->sdpconstmemsize[b]) );
941 SCIP_CALL( SCIPallocBufferArray(scip, &(sdpconstval_local[b]), data->sdpconstmemsize[b]) );
946 SCIP_CALL(
readNextLine(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
949 SCIPerrorMessage(
"Unexpected end of file in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
955 if ( strncmp(data->buffer,
"*INTEGER", 8) == 0 || strncmp(data->buffer,
"*RANK1", 5) == 0 )
958 if ( sscanf(data->buffer,
"%i %i %i %i %lf", &v, &b, &row, &col, &val) != 5 )
960 SCIPerrorMessage(
"Could not read block entry in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
974 if ( b != data->idxlinconsblock )
977 if ( b > data->idxlinconsblock && data->idxlinconsblock >= 0 )
983 if ( v < - 1 || v >= data->nvars )
985 SCIPerrorMessage(
"Given coefficient in line %" SCIP_LONGINT_FORMAT
" for variable %d which does not exist!\n",
990 if ( b < 0 || b >= data->nsdpblocks )
992 SCIPerrorMessage(
"Given coefficient in line %" SCIP_LONGINT_FORMAT
" for SDP block %d which does not exist!\n",
993 *linecount, b + 1 + blockidxoffset);
996 assert( 0 <= b && b < data->nsdpblocks );
998 if ( row < 0 || row >= data->sdpblocksizes[b] )
1000 SCIPerrorMessage(
"Row index %d of given coefficient in line %" SCIP_LONGINT_FORMAT
" is negative or larger than blocksize %d!\n",
1001 row +1, *linecount, data->sdpblocksizes[b]);
1005 if ( col < 0 || col >= data->sdpblocksizes[b] )
1007 SCIPerrorMessage(
"Column index %d of given coefficient in line %" SCIP_LONGINT_FORMAT
" is negative or larger than blocksize %d!\n",
1008 col + 1, *linecount, data->sdpblocksizes[b]);
1015 if ( SCIPisZero(scip, val) )
1020 assert( nentriessdp != NULL );
1021 assert( sdpvar != NULL );
1022 assert( sdprow_local != NULL );
1023 assert( sdpcol_local != NULL );
1024 assert( sdpval_local != NULL );
1026 if ( SCIPisInfinity(scip, val) || SCIPisInfinity(scip, -val) )
1028 SCIPerrorMessage(
"Given coefficient in line %" SCIP_LONGINT_FORMAT
" for variable %d is infinity, which is not allowed.\n",
1036 if ( nentriessdp[b] >= data->sdpmemsize[b] )
1038 int newsize = SCIPcalcMemGrowSize(scip, data->sdpmemsize[b] + 1);
1039 assert( newsize > data->sdpmemsize[b] );
1040 assert( newsize > nentriessdp[b] );
1042 SCIP_CALL( SCIPreallocBufferArray(scip, &(sdpvar[b]), newsize) );
1043 SCIP_CALL( SCIPreallocBufferArray(scip, &(sdprow_local[b]), newsize) );
1044 SCIP_CALL( SCIPreallocBufferArray(scip, &(sdpcol_local[b]), newsize) );
1045 SCIP_CALL( SCIPreallocBufferArray(scip, &(sdpval_local[b]), newsize) );
1046 data->sdpmemsize[b] = newsize;
1049 sdpvar[b][data->sdpnblocknonz[b]] = v;
1054 sdprow_local[b][data->sdpnblocknonz[b]] = col;
1055 sdpcol_local[b][data->sdpnblocknonz[b]] = row;
1059 sdprow_local[b][data->sdpnblocknonz[b]] = row;
1060 sdpcol_local[b][data->sdpnblocknonz[b]] = col;
1063 sdpval_local[b][data->sdpnblocknonz[b]] = val;
1064 data->sdpnblocknonz[b]++;
1071 if ( SCIPisZero(scip, val) )
1076 assert( nentriessdpconst != NULL );
1077 assert( sdpconstrow_local != NULL );
1078 assert( sdpconstcol_local != NULL );
1079 assert( sdpconstval_local != NULL );
1081 if ( SCIPisInfinity(scip, val) || SCIPisInfinity(scip, -val) )
1083 SCIPerrorMessage(
"Given constant part in line %" SCIP_LONGINT_FORMAT
" of block %d is infinity, which is not allowed.\n",
1088 nentriessdpconst[b]++;
1091 if ( nentriessdpconst[b] >= data->sdpconstmemsize[b] )
1093 int newsize = SCIPcalcMemGrowSize(scip, data->sdpconstmemsize[b] + 1);
1094 assert( newsize > data->sdpconstmemsize[b] );
1095 assert( newsize > nentriessdpconst[b] );
1097 SCIP_CALL( SCIPreallocBufferArray(scip, &(sdpconstrow_local[b]), newsize) );
1098 SCIP_CALL( SCIPreallocBufferArray(scip, &(sdpconstcol_local[b]), newsize) );
1099 SCIP_CALL( SCIPreallocBufferArray(scip, &(sdpconstval_local[b]), newsize) );
1101 data->sdpconstmemsize[b] = newsize;
1107 sdpconstrow_local[b][data->sdpconstnblocknonz[b]] = col;
1108 sdpconstcol_local[b][data->sdpconstnblocknonz[b]] = row;
1112 sdpconstrow_local[b][data->sdpconstnblocknonz[b]] = row;
1113 sdpconstcol_local[b][data->sdpconstnblocknonz[b]] = col;
1115 sdpconstval_local[b][data->sdpconstnblocknonz[b]] = val;
1116 data->sdpconstnblocknonz[b]++;
1123 if ( v >= data->nvars )
1125 SCIPerrorMessage(
"Given linear coefficient in line %" SCIP_LONGINT_FORMAT
" for variable %d which does not exist!\n",
1133 SCIPerrorMessage(
"Given linear coefficient in line %" SCIP_LONGINT_FORMAT
" is not located on the diagonal!\n",
1138 assert( row == col );
1140 if ( row < 0 || row >= data->nlinconss )
1142 SCIPerrorMessage(
"Given linear coefficient in line %" SCIP_LONGINT_FORMAT
" for linear constraint %d which does not exist!\n",
1143 *linecount, row + 1);
1150 if ( SCIPisInfinity(scip, val) || SCIPisInfinity(scip, -val) )
1152 SCIPerrorMessage(
"Given linear coefficient in line %" SCIP_LONGINT_FORMAT
" for variable %d is infinity, which is not allowed.\n",
1157 if ( SCIPisZero(scip, val) )
1163 SCIP_CALL( SCIPaddCoefLinear(scip, data->createdconss[row], data->createdvars[v],val) );
1164 nentrieslincon[row]++;
1172 SCIP_VAR* slackvar = 0;
1173 char name[SCIP_MAXSTRLEN];
1181 snprintfreturn = SCIPsnprintf(name, SCIP_MAXSTRLEN,
"indslack_cons_indicator_%d", nindcons);
1182 assert( snprintfreturn < SCIP_MAXSTRLEN);
1184 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN,
"indslack_cons_indicator_%d", nindcons);
1187 SCIP_CALL( SCIPcreateVar(scip, &slackvar, name, 0.0, SCIPinfinity(scip), 0.0,
1188 SCIP_VARTYPE_CONTINUOUS, TRUE, FALSE, 0, 0, 0, 0, 0));
1189 SCIP_CALL( SCIPaddVar(scip, slackvar) );
1191 SCIP_CALL( SCIPaddCoefLinear(scip,data->createdconss[row] , slackvar, +1.0) );
1194 snprintfreturn = SCIPsnprintf(name, SCIP_MAXSTRLEN,
"indlin_cons_indicator_%d", nindcons);
1195 assert( snprintfreturn < SCIP_MAXSTRLEN);
1197 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN,
"indlin_cons_indicator_%d", nindcons);
1200 SCIP_CALL( SCIPchgConsName(scip, data->createdconss[row], name) );
1203 snprintfreturn = SCIPsnprintf(name, SCIP_MAXSTRLEN,
"cons_indicator_%d", nindcons);
1204 assert( snprintfreturn < SCIP_MAXSTRLEN);
1206 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN,
"cons_indicator_%d", nindcons);
1208 indvar = data->createdvars[v];
1209 SCIP_CALL( SCIPchgVarLbGlobal(scip, indvar, 0.0) );
1210 SCIP_CALL( SCIPchgVarUbGlobal(scip, indvar, 1.0) );
1211 SCIP_CALL( SCIPchgVarType(scip, indvar, SCIP_VARTYPE_BINARY, &infeasible) );
1212 SCIP_CALL( SCIPcreateConsIndicatorLinCons( scip, &indcons, name, indvar,data->createdconss[row], slackvar,
1213 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1214 SCIP_CALL( SCIPaddCons(scip, indcons) );
1217 SCIP_CALL( SCIPreleaseCons(scip, &indcons) );
1218 SCIP_CALL( SCIPreleaseVar(scip, &slackvar) );
1226 if ( SCIPisInfinity(scip, val) || SCIPisInfinity(scip, -val))
1228 SCIPerrorMessage(
"Given constant part in line %" SCIP_LONGINT_FORMAT
" of block %d is infinity, which is not allowed.\n",
1233 if ( SCIPisZero(scip, val) )
1237 assert( ! SCIPisInfinity(scip, - SCIPgetLhsLinear(scip, data->createdconss[row])) );
1238 assert( SCIPisInfinity(scip, SCIPgetRhsLinear(scip, data->createdconss[row])) );
1241 SCIP_CALL( SCIPchgLhsLinear(scip, data->createdconss[row], val) );
1247 SCIP_CALL(
readNextLine(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
1253 for (b = 0; b < data->nsdpblocks; b++)
1255 if ( nentriessdp[b] == 0 )
1260 if ( data->idxlinconsblock >= 0 && b >= data->idxlinconsblock )
1263 SCIPerrorMessage(
"SDP block number %d does not contain any nonzero entries!\n", b + 1 + blockidxoffset);
1267 if ( emptysdpblocks > 0 )
1270 for (c = 0; c < data->nlinconss; c++)
1272 if ( nentrieslincon[c] == 0 )
1274 SCIPerrorMessage(
"Linear constraint number %d does not contain nonzero entries!\n", c + 1);
1275 emptylinconsblocks++;
1279 if ( emptylinconsblocks > 0 )
1282 if ( data->nsdpblocks > 0 )
1284 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdprow), data->nsdpblocks) );
1285 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpcol), data->nsdpblocks) );
1286 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpval), data->nsdpblocks) );
1288 for (b = 0; b < data->nsdpblocks; b++)
1290 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdprow[b]), data->sdpmemsize[b]) );
1291 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpcol[b]), data->sdpmemsize[b]) );
1292 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpval[b]), data->sdpmemsize[b]) );
1295 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstrow), data->nsdpblocks) );
1296 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstcol), data->nsdpblocks) );
1297 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstval), data->nsdpblocks) );
1299 for (b = 0; b < data->nsdpblocks; b++)
1301 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstrow[b]), data->sdpconstmemsize[b]) );
1302 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstcol[b]), data->sdpconstmemsize[b]) );
1303 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstval[b]), data->sdpconstmemsize[b]) );
1307 for (b = 0; b < data->nsdpblocks; b++)
1311 for (nonz = 0; nonz < data->sdpnblocknonz[b]; nonz++)
1313 if ( sdpcol_local[b][nonz] > sdprow_local[b][nonz] )
1315 data->sdprow[b][nonz] = sdpcol_local[b][nonz];
1316 data->sdpcol[b][nonz] = sdprow_local[b][nonz];
1320 data->sdprow[b][nonz] = sdprow_local[b][nonz];
1321 data->sdpcol[b][nonz] = sdpcol_local[b][nonz];
1323 data->sdpval[b][nonz] = sdpval_local[b][nonz];
1326 for (nonz = 0; nonz < data->sdpconstnblocknonz[b]; nonz++)
1328 if ( sdpconstcol_local[b][nonz] > sdpconstrow_local[b][nonz] )
1330 data->sdpconstrow[b][nonz] = sdpconstcol_local[b][nonz];
1331 data->sdpconstcol[b][nonz] = sdpconstrow_local[b][nonz];
1335 data->sdpconstrow[b][nonz] = sdpconstrow_local[b][nonz];
1336 data->sdpconstcol[b][nonz] = sdpconstcol_local[b][nonz];
1338 data->sdpconstval[b][nonz] = sdpconstval_local[b][nonz];
1343 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpnblockvars), data->nsdpblocks) );
1344 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpblockvars), data->nsdpblocks) );
1345 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->nvarnonz), data->nsdpblocks) );
1346 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->rowpointer), data->nsdpblocks) );
1347 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->colpointer), data->nsdpblocks) );
1348 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->valpointer), data->nsdpblocks) );
1351 for (b = 0; b < data->nsdpblocks; b++)
1354 SCIPsortIntIntIntReal(sdpvar[b], data->sdprow[b], data->sdpcol[b], data->sdpval[b], data->sdpnblocknonz[b]);
1357 nextindaftervar = 0;
1358 data->sdpnblockvars[b] = 0;
1359 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpblockvars[b]), data->nvars) );
1360 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->nvarnonz[b]), data->nvars) );
1361 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->rowpointer[b]), data->nvars) );
1362 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->colpointer[b]), data->nvars) );
1363 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->valpointer[b]), data->nvars) );
1365 for (v = 0; v < data->nvars; v++)
1367 SCIP_Bool varused = FALSE;
1369 firstindforvar = nextindaftervar;
1370 data->nvarnonz[b][data->sdpnblockvars[b]] = 0;
1373 while ( nextindaftervar < data->sdpnblocknonz[b] && sdpvar[b][nextindaftervar] == v )
1377 data->nvarnonz[b][data->sdpnblockvars[b]]++;
1383 data->sdpblockvars[b][data->sdpnblockvars[b]] = data->createdvars[v];
1385 data->rowpointer[b][data->sdpnblockvars[b]] = &(data->sdprow[b][firstindforvar]);
1386 data->colpointer[b][data->sdpnblockvars[b]] = &(data->sdpcol[b][firstindforvar]);
1387 data->valpointer[b][data->sdpnblockvars[b]] = &(data->sdpval[b][firstindforvar]);
1388 data->sdpnblockvars[b]++;
1391 assert( nextindaftervar == data->sdpnblocknonz[b] );
1394 if ( nzerocoef > 0 )
1395 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
1396 "Found %d block coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
1399 for (b = 0; b < data->nsdpblocks; b++)
1401 SCIPfreeBufferArray(scip, &(sdpconstval_local[b]));
1402 SCIPfreeBufferArray(scip, &(sdpconstcol_local[b]));
1403 SCIPfreeBufferArray(scip, &(sdpconstrow_local[b]));
1404 SCIPfreeBufferArray(scip, &(sdpval_local[b]));
1405 SCIPfreeBufferArray(scip, &(sdpcol_local[b]));
1406 SCIPfreeBufferArray(scip, &(sdprow_local[b]));
1407 SCIPfreeBufferArray(scip, &(sdpvar[b]));
1409 SCIPfreeBufferArray(scip, &(sdpconstval_local));
1410 SCIPfreeBufferArray(scip, &(sdpconstcol_local));
1411 SCIPfreeBufferArray(scip, &(sdpconstrow_local));
1412 SCIPfreeBufferArray(scip, &(sdpval_local));
1413 SCIPfreeBufferArray(scip, &(sdpcol_local));
1414 SCIPfreeBufferArray(scip, &(sdprow_local));
1415 SCIPfreeBufferArray(scip, &sdpvar);
1416 SCIPfreeBufferArray(scip, &nentriessdpconst);
1417 SCIPfreeBufferArray(scip, &nentriessdp);
1420 SCIPfreeBufferArray(scip, &nentrieslincon);
1426 if ( data->nsdpblocks > 0 )
1428 if ( sdpvar != NULL )
1431 for (b = 0; b < data->nsdpblocks; b++)
1433 SCIPfreeBufferArrayNull(scip, &(sdpconstval_local[b]));
1434 SCIPfreeBufferArrayNull(scip, &(sdpconstcol_local[b]));
1435 SCIPfreeBufferArrayNull(scip, &(sdpconstrow_local[b]));
1436 SCIPfreeBufferArrayNull(scip, &(sdpval_local[b]));
1437 SCIPfreeBufferArrayNull(scip, &(sdpcol_local[b]));
1438 SCIPfreeBufferArrayNull(scip, &(sdprow_local[b]));
1439 SCIPfreeBufferArrayNull(scip, &(sdpvar[b]));
1442 SCIPfreeBufferArrayNull(scip, &(sdpconstval_local));
1443 SCIPfreeBufferArrayNull(scip, &(sdpconstcol_local));
1444 SCIPfreeBufferArrayNull(scip, &(sdpconstrow_local));
1445 SCIPfreeBufferArrayNull(scip, &(sdpval_local));
1446 SCIPfreeBufferArrayNull(scip, &(sdpcol_local));
1447 SCIPfreeBufferArrayNull(scip, &(sdprow_local));
1448 SCIPfreeBufferArrayNull(scip, &sdpvar);
1449 SCIPfreeBufferArrayNull(scip, &nentriessdpconst);
1450 SCIPfreeBufferArrayNull(scip, &nentriessdp);
1452 SCIPfreeBufferArrayNull(scip, &nentrieslincon);
1455 return SCIP_READERROR;
1464 SCIP_Longint* linecount,
1471 assert( scip != NULL );
1472 assert( file != NULL );
1473 assert( linecount != NULL );
1474 assert( data != NULL );
1476 if ( data->createdvars == NULL )
1478 SCIPerrorMessage(
"Number of variables needs to be specified before integer section!\n");
1482 assert( data->nvars >= 0 );
1485 SCIP_CALL(
readNextLineStar(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
1488 if ( strncmp(data->buffer,
"*RANK1", 5) == 0 )
1492 if ( strncmp(data->buffer,
"*", 1) != 0 )
1494 SCIPerrorMessage(
"Expected '*' at the beginning of line %" SCIP_LONGINT_FORMAT
" in the INT-section.\n",
1499 if ( sscanf(data->buffer + 1,
"%i", &v) != 1 )
1501 SCIPerrorMessage(
"Could not read variable index in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
1505 if ( v < 1 || v > data->nvars )
1507 SCIPerrorMessage(
"Given integrality in line %" SCIP_LONGINT_FORMAT
" for variable %d which does not exist!\n",
1514 if ( SCIPvarGetType(data->createdvars[v]) != SCIP_VARTYPE_BINARY )
1516 SCIP_Bool infeasible;
1518 SCIP_CALL( SCIPchgVarType(scip, data->createdvars[v], SCIP_VARTYPE_INTEGER, &infeasible) );
1522 SCIPerrorMessage(
"Infeasibility detected because of integrality of variable %s!\n",
1523 SCIPvarGetName(data->createdvars[v]));
1529 SCIP_CALL(
readNextLineStar(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
1536 return SCIP_READERROR;
1545 SCIP_Longint* linecount,
1550 int blockidxoffset = 0;
1553 assert( scip != NULL );
1554 assert( file != NULL );
1555 assert( linecount != NULL );
1556 assert( data != NULL );
1558 if ( data->sdpblocksizes == NULL )
1560 SCIPerrorMessage(
"SDP blocks need to be specified before rank-1 section!\n");
1564 assert( data->nvars >= 0 );
1567 SCIP_CALL(
readNextLineStar(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
1572 if ( strncmp(data->buffer,
"*INTEGER", 8) == 0 )
1574 SCIPerrorMessage(
"Integer section in line %" SCIP_LONGINT_FORMAT
" needs to be in front of rank1 section.\n",
1580 if ( strncmp(data->buffer,
"*", 1) != 0 )
1582 SCIPerrorMessage(
"Expected '*' at the beginning of line %" SCIP_LONGINT_FORMAT
" in the RANK1-section.\n", *linecount);
1587 ps = data->buffer + 1;
1588 if ( sscanf(ps,
"%i", &v) != 1 )
1590 SCIPerrorMessage(
"Could not read SDP block index in line %" SCIP_LONGINT_FORMAT
".\n", *linecount);
1600 if ( v == data->idxlinconsblock )
1602 SCIPerrorMessage(
"Given rank1 in line %" SCIP_LONGINT_FORMAT
" for the LP block which is not valid.\n",
1608 if ( data->idxlinconsblock >= 0 && v > data->idxlinconsblock )
1614 if ( v < 0 || v >= data->nsdpblocks )
1616 SCIPerrorMessage(
"Given rank1 in line %" SCIP_LONGINT_FORMAT
" for SDP block %d which does not exist!\n",
1617 *linecount, v + 1 + blockidxoffset);
1621 data->sdpblockrank1[v] = TRUE;
1622 ++data->nsdpblocksrank1;
1624 SCIP_CALL(
readNextLineStar(scip, file, &data->buffer, &data->bufferlen, linecount, &success) );
1631 return SCIP_READERROR;
1644 assert( scip != NULL );
1657 SCIP_Longint linecount = 0;
1661 assert( result != NULL );
1663 *result = SCIP_DIDNOTRUN;
1665 SCIPdebugMsg(scip,
"Reading file %s ...\n", filename);
1667 file = SCIPfopen(filename,
"r");
1670 return SCIP_READERROR;
1672 SCIP_CALL( SCIPallocBuffer(scip, &data) );
1673 data->nsdpblocks = -1;
1674 data->nsdpblocksrank1 = 0;
1675 data->nlinconss = 0;
1677 data->nconsblocks = -1;
1678 data->idxlinconsblock = -1;
1679 data->bufferlen = 0;
1680 data->sdpblockrank1 = NULL;
1681 data->createdvars = NULL;
1682 data->createdconss = NULL;
1683 data->sdpblocksizes = NULL;
1684 data->sdpnblocknonz = NULL;
1685 data->sdpnblockvars = NULL;
1686 data->nvarnonz = NULL;
1687 data->sdpblockvars = NULL;
1688 data->sdprow = NULL;
1689 data->sdpcol = NULL;
1690 data->sdpval = NULL;
1691 data->rowpointer = NULL;
1692 data->colpointer = NULL;
1693 data->valpointer = NULL;
1694 data->sdpconstnblocknonz = NULL;
1695 data->sdpconstrow = NULL;
1696 data->sdpconstcol = NULL;
1697 data->sdpconstval = NULL;
1698 data->sdpmemsize = NULL;
1699 data->sdpconstmemsize = NULL;
1700 data->buffer = NULL;
1703 SCIP_CALL( SCIPcreateProb(scip, filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
1705 SCIP_CALL( SCIPsetObjsense(scip, SCIP_OBJSENSE_MINIMIZE) );
1708 SCIPdebugMsg(scip,
"Reading number of variables\n");
1711 SCIPdebugMsg(scip,
"Reading number of blocks\n");
1714 SCIPdebugMsg(scip,
"Reading blocksizes\n");
1717 SCIPdebugMsg(scip,
"Reading objective values\n");
1720 SCIPdebugMsg(scip,
"Reading block entries\n");
1723 if ( strncmp(data->buffer,
"*INTEGER", 8) == 0 )
1725 SCIPdebugMsg(scip,
"Reading integer section\n");
1726 SCIP_CALL(
SDPAreadInt(scip, file, &linecount, data) );
1729 if ( strncmp(data->buffer,
"*RANK1", 5) == 0 )
1731 SCIPdebugMsg(scip,
"Reading rank1 section\n");
1735 #ifdef SCIP_MORE_DEBUG 1736 for (b = 0; b < SCIPgetNConss(scip); b++)
1738 SCIP_CALL( SCIPprintCons(scip, SCIPgetConss(scip)[b], NULL) );
1739 SCIPinfoMessage(scip, NULL,
"\n");
1744 for (b = 0; b < data->nsdpblocks; b++)
1747 char sdpconname[SCIP_MAXSTRLEN];
1751 assert( data->sdpblocksizes[b] > 0 );
1752 assert( (data->sdpnblockvars[b] > 0 && data->sdpnblocknonz[b] > 0) || (data->sdpconstnblocknonz[b] > 0) );
1754 snprintfreturn = SCIPsnprintf(sdpconname, SCIP_MAXSTRLEN,
"SDP_%d", b);
1755 assert( snprintfreturn < SCIP_MAXSTRLEN );
1757 (void) SCIPsnprintf(sdpconname, SCIP_MAXSTRLEN,
"SDP_%d", b);
1761 if ( data->sdpconstnblocknonz == NULL )
1763 if ( ! data->sdpblockrank1[b] )
1765 SCIP_CALL(
SCIPcreateConsSdp(scip, &sdpcons, sdpconname, data->sdpnblockvars[b], data->sdpnblocknonz[b],
1766 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b],
1767 data->valpointer[b], data->sdpblockvars[b], 0, NULL, NULL, NULL, TRUE) );
1771 SCIP_CALL(
SCIPcreateConsSdpRank1(scip, &sdpcons, sdpconname, data->sdpnblockvars[b], data->sdpnblocknonz[b],
1772 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b],
1773 data->valpointer[b], data->sdpblockvars[b], 0, NULL, NULL, NULL, TRUE) );
1778 if ( ! data->sdpblockrank1[b] )
1780 SCIP_CALL(
SCIPcreateConsSdp(scip, &sdpcons, sdpconname, data->sdpnblockvars[b],data->sdpnblocknonz[b],
1781 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b],data->rowpointer[b], data->valpointer[b],
1782 data->sdpblockvars[b], data->sdpconstnblocknonz[b],data->sdpconstcol[b], data->sdpconstrow[b],
1783 data->sdpconstval[b], TRUE) );
1787 SCIP_CALL(
SCIPcreateConsSdpRank1(scip, &sdpcons, sdpconname, data->sdpnblockvars[b], data->sdpnblocknonz[b],
1788 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b], data->valpointer[b],
1789 data->sdpblockvars[b], data->sdpconstnblocknonz[b], data->sdpconstcol[b], data->sdpconstrow[b],
1790 data->sdpconstval[b], TRUE) );
1793 #ifdef SCIP_MORE_DEBUG 1794 SCIP_CALL( SCIPprintCons(scip, sdpcons, NULL) );
1796 SCIP_CALL( SCIPaddCons(scip, sdpcons) );
1798 SCIP_CALL( SCIPreleaseCons(scip, &sdpcons) );
1804 *result = SCIP_SUCCESS;
1818 SCIP_Real* sdpconstval;
1832 int totalsdpnnonz = 0;
1835 int totalsdpconstnnonz = 0;
1841 int nchangedconss = 0;
1842 int nvarbndslinconss = 0;
1844 int nrank1sdpblocks = 0;
1850 assert( scip != NULL );
1851 assert( result != NULL );
1852 assert( nvars > 0 );
1853 assert( nconss >= 0 );
1855 SCIPdebugMsg(scip,
"Writing problem in SDPA format to file.\n");
1856 *result = SCIP_DIDNOTRUN;
1860 SCIPerrorMessage(
"SDPA reader currently only supports writing original problems!\n");
1861 return SCIP_READERROR;
1865 for (v = 0; v < nvars; v++)
1866 assert( SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_ORIGINAL );
1870 SCIPinfoMessage(scip, file,
"%d\n", nvars);
1873 SCIP_CALL( SCIPallocBufferArray(scip, &varsenses, nvars) );
1875 for (v = 0; v < nvars; v++)
1880 lb = SCIPvarGetLbOriginal(vars[v]);
1881 ub = SCIPvarGetUbOriginal(vars[v]);
1884 if ( SCIPisZero(scip, lb) )
1891 if ( ! SCIPisInfinity(scip, -lb) )
1893 SCIPerrorMessage(
"Can only handle variables with lower bound 0 or minus infinity.\n");
1894 SCIPfreeBufferArray(scip, &varsenses);
1895 return SCIP_READERROR;
1899 if ( SCIPisZero(scip, ub) )
1906 if ( ! SCIPisInfinity(scip, ub) )
1908 SCIPerrorMessage(
"Can only handle variables with upper bound 0 or infinity.\n");
1909 SCIPfreeBufferArray(scip, &varsenses);
1910 return SCIP_READERROR;
1916 SCIP_CALL( SCIPallocBufferArray(scip, &consssenses, nconss) );
1919 for (c = 0; c < nconss; c++)
1921 if ( (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"linear") != 0)
1922 && (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0)
1923 && (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0))
1925 SCIPerrorMessage(
"SDPA reader currently only supports linear, SDP and SDPrank1 constraints!\n");
1926 SCIPfreeBufferArray(scip, &consssenses);
1927 SCIPfreeBufferArray(scip, &varsenses);
1928 return SCIP_READERROR;
1932 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") == 0 )
1936 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"linear") == 0 )
1938 lhs = SCIPgetLhsLinear(scip, conss[c]);
1939 rhs = SCIPgetRhsLinear(scip, conss[c]);
1941 if ( SCIPisEQ(scip, lhs, rhs) )
1943 assert( ! SCIPisInfinity(scip, -lhs) && ! SCIPisInfinity(scip, rhs) );
1949 if ( ! SCIPisInfinity(scip, -lhs) && ! SCIPisInfinity(scip, rhs) )
1951 SCIPerrorMessage(
"Cannot handle ranged rows.\n");
1952 SCIPfreeBufferArray(scip, &consssenses);
1953 SCIPfreeBufferArray(scip, &varsenses);
1954 return SCIP_READERROR;
1958 assert( SCIPisInfinity(scip, -lhs) || SCIPisInfinity(scip, rhs) );
1960 if ( ! SCIPisInfinity(scip, -lhs) )
1962 else if ( ! SCIPisInfinity(scip, rhs) )
1963 consssenses[c] = -1;
1971 assert( (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0)
1972 || (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0) );
1979 totalsdpnnonz += sdpnnonz;
1980 totalsdpconstnnonz += sdpconstnnonz;
1984 nblocks = nsdpconss;
1986 if ( nblocks > 0 && totalsdpnnonz == 0 )
1988 SCIPerrorMessage(
"There are %d SDP blocks but no nonzero coefficients. \n", nblocks);
1989 SCIPfreeBufferArray(scip, &consssenses);
1990 SCIPfreeBufferArray(scip, &varsenses);
1991 return SCIP_READERROR;
1994 if ( nvarbndslinconss + nlinconss > 0 )
1998 SCIPinfoMessage(scip, file,
"%d\n", nblocks);
2001 for (c = 0; c < nconss; c++)
2003 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") )
2009 if ( nvarbndslinconss + nlinconss > 0 )
2010 SCIPinfoMessage(scip, file,
"-%d \n", nvarbndslinconss + nlinconss);
2012 SCIPinfoMessage(scip, file,
"\n");
2016 if ( objsense == SCIP_OBJSENSE_MAXIMIZE )
2019 SCIPinfoMessage(scip, NULL,
"WARNING: Transforming original maximization problem to a minimization problem by multiplying all objective coefficients by -1. \n");
2022 for (v = 0; v < nvars; v++)
2026 obj = SCIPvarGetObj(vars[v]);
2028 if ( ! SCIPisZero(scip, obj) )
2029 SCIPinfoMessage(scip, file,
"%.15g ", obj * objcoeff);
2031 SCIPinfoMessage(scip, file,
"%.15g ", 0.0);
2033 SCIPinfoMessage(scip, file,
"\n");
2036 if ( nvarbndslinconss > 0 )
2038 for (c = 0; c < nvars; c++)
2040 assert(varsenses[c] == 0 || varsenses[c] == -1 || varsenses[c] == 1 );
2042 if (varsenses[c] == 0 )
2045 if ( varsenses[c] == -1 )
2048 SCIPinfoMessage(scip, file,
"%d %d %d %d -1.0\n", c + 1, nsdpconss + 1, linconsind, linconsind);
2053 SCIPinfoMessage(scip, file,
"%d %d %d %d 1.0\n", c + 1, nsdpconss + 1, linconsind, linconsind);
2058 if ( nsdpconss > 0 )
2061 SCIP_CALL( SCIPallocBufferArray(scip, &sdpnvarnonz, nvars) );
2062 SCIP_CALL( SCIPallocBufferArray(scip, &sdpcol, totalsdpnnonz) );
2063 SCIP_CALL( SCIPallocBufferArray(scip, &sdprow, totalsdpnnonz) );
2064 SCIP_CALL( SCIPallocBufferArray(scip, &sdpval, totalsdpnnonz) );
2065 SCIP_CALL( SCIPallocBufferArray(scip, &sdpvars, nvars) );
2066 SCIP_CALL( SCIPallocBufferArray(scip, &sdpconstcol, totalsdpconstnnonz) );
2067 SCIP_CALL( SCIPallocBufferArray(scip, &sdpconstrow, totalsdpconstnnonz) );
2068 SCIP_CALL( SCIPallocBufferArray(scip, &sdpconstval, totalsdpconstnnonz) );
2070 sdparraylength = totalsdpnnonz;
2071 sdpconstnnonz = totalsdpconstnnonz;
2075 for (c = 0; c < nconss; c++)
2077 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") == 0
2078 || strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") == 0 )
2081 if ( totalsdpnnonz > 0 )
2086 assert( sdpnvarnonz != NULL );
2087 assert( sdpcol != NULL );
2088 assert( sdprow != NULL );
2089 assert( sdpval != NULL );
2090 assert( sdpvars != NULL );
2091 assert( sdpconstcol != NULL );
2092 assert( sdpconstrow != NULL );
2093 assert( sdpconstval != NULL );
2096 sdparraylength = totalsdpnnonz;
2097 sdpconstnnonz = totalsdpconstnnonz;
2099 SCIP_CALL(
SCIPconsSdpGetData(scip, conss[c], &sdpnvars, &sdpnnonz, &sdpblocksize, &sdparraylength,
2100 sdpnvarnonz, sdprow, sdpcol, sdpval, sdpvars, &sdpconstnnonz, sdpconstrow, sdpconstcol,
2101 sdpconstval, NULL, NULL, NULL) );
2103 assert( sdpconstnnonz <= totalsdpconstnnonz );
2104 assert( sdparraylength <= totalsdpnnonz );
2106 for (v = 0; v < sdpnvars; v++)
2108 for (i = 0; i < sdpnvarnonz[v]; i++)
2111 ind = SCIPvarGetProbindex(sdpvars[v]);
2112 assert( 0 <= ind && ind < nvars );
2113 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", ind + 1, consind + 1, sdprow[v][i]+ 1, sdpcol[v][i] + 1,
2121 sdparraylength = totalsdpnnonz;
2123 assert( sdpconstnnonz <= totalsdpconstnnonz );
2124 assert( sdparraylength <= totalsdpnnonz );
2126 for (i = 0; i < sdpconstnnonz; i++)
2128 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", 0, consind + 1, sdpconstrow[i] + 1, sdpconstcol[i] + 1,
2136 assert( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"linear") == 0 );
2140 lhs = SCIPgetLhsLinear(scip, conss[c]);
2141 rhs = SCIPgetRhsLinear(scip, conss[c]);
2145 if ( ! SCIPisInfinity(scip, rhs) && SCIPisInfinity(scip, -lhs) )
2151 linvars = SCIPgetVarsLinear(scip, conss[c]);
2152 linvals = SCIPgetValsLinear(scip, conss[c]);
2154 if ( ! SCIPisEQ(scip, lhs, rhs) )
2156 for (v = 0; v < SCIPgetNVarsLinear(scip, conss[c]); v++)
2158 i = SCIPvarGetProbindex(linvars[v]);
2159 assert( 0 <= i && i < nvars );
2160 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", i + 1, nsdpconss + 1, linconsind, linconsind, linvals[v] * conssign);
2165 val = SCIPgetRhsLinear(scip, conss[c]);
2167 val = SCIPgetLhsLinear(scip, conss[c]);
2169 if ( ! SCIPisZero(scip, val) )
2170 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", 0, nsdpconss + 1, linconsind, linconsind, val * conssign);
2174 for (v = 0; v < SCIPgetNVarsLinear(scip, conss[c]); v++)
2176 i = SCIPvarGetProbindex(linvars[v]);
2177 assert( 0 <= i && i < nvars );
2178 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", i + 1, nsdpconss + 1, linconsind,linconsind, linvals[v] * conssign);
2183 val = SCIPgetRhsLinear(scip, conss[c]);
2185 val = SCIPgetLhsLinear(scip, conss[c]);
2187 if ( ! SCIPisZero(scip, val) )
2188 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", 0, nsdpconss + 1, linconsind, linconsind, val * conssign);
2192 for (v = 0; v < SCIPgetNVarsLinear(scip, conss[c]); v++)
2194 i = SCIPvarGetProbindex(linvars[v]);
2195 assert( 0 <= i && i < nvars );
2196 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", i + 1, nsdpconss + 1, linconsind,linconsind, linvals[v] * conssign*(-1));
2201 val = SCIPgetRhsLinear(scip, conss[c]);
2203 val = SCIPgetLhsLinear(scip, conss[c]);
2205 if ( ! SCIPisZero(scip, val) )
2206 SCIPinfoMessage(scip, file,
"%d %d %d %d %.15g\n", 0, nsdpconss + 1, linconsind, linconsind, val * conssign*(-1));
2211 if ( nchangedconss > 0 )
2212 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
"Changed the sign of %d constraints. \n", nchangedconss);
2215 if ( nbinvars + nintvars > 0 )
2217 SCIPinfoMessage(scip, file,
"*INTEGER\n");
2218 for (v = 0; v < nbinvars + nintvars; v++)
2220 assert( SCIPvarIsIntegral(vars[v]) );
2221 SCIPinfoMessage(scip, file,
"*%d\n", v + 1);
2226 if ( nrank1sdpblocks > 0 )
2229 SCIPinfoMessage(scip, file,
"*RANK1\n");
2230 for (c = 0; c < nconss; c++)
2232 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"linear") == 0 )
2235 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") == 0
2236 || strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") == 0 )
2239 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") == 0 )
2242 SCIPinfoMessage(scip, file,
"*%d\n", consind);
2247 if ( nsdpconss > 0 )
2249 SCIPfreeBufferArray(scip, &sdpconstval);
2250 SCIPfreeBufferArray(scip, &sdpconstrow);
2251 SCIPfreeBufferArray(scip, &sdpconstcol);
2252 SCIPfreeBufferArray(scip, &sdpvars);
2253 SCIPfreeBufferArray(scip, &sdpval);
2254 SCIPfreeBufferArray(scip, &sdprow);
2255 SCIPfreeBufferArray(scip, &sdpcol);
2256 SCIPfreeBufferArray(scip, &sdpnvarnonz);
2258 SCIPfreeBufferArray(scip, &consssenses);
2259 SCIPfreeBufferArray(scip, &varsenses);
2261 *result = SCIP_SUCCESS;
2276 SCIP_READERDATA* readerdata = NULL;
2277 SCIP_READER* reader;
2282 assert( reader != NULL );
2285 SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopySdpa) );
2286 SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadSdpa) );
2287 SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWriteSdpa) );
static SCIP_RETCODE SDPAreadNBlocks(SCIP *scip, SCIP_FILE *file, SCIP_Longint *linecount, SDPA_DATA *data)
file reader for mixed-integer semidefinite programs in SDPA format
static SCIP_RETCODE SDPAreadObjVals(SCIP *scip, SCIP_FILE *file, SCIP_Longint *linecount, SDPA_DATA *data)
#define SDPA_MIN_BUFFERLEN
static SCIP_DECL_READERREAD(readerReadSdpa)
static SCIP_RETCODE SDPAfreeData(SCIP *scip, SCIP_FILE *file, SDPA_DATA *data)
struct SDPA_Data SDPA_DATA
static SCIP_RETCODE readNextLine(SCIP *scip, SCIP_FILE *file, char **buffer, int *bufferlen, SCIP_Longint *linecount, SCIP_Bool *success)
SCIP_RETCODE SCIPcreateConsSdpRank1(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, int nnonz, int blocksize, int *nvarnonz, int **col, int **row, SCIP_Real **val, SCIP_VAR **vars, int constnnonz, int *constcol, int *constrow, SCIP_Real *constval, SCIP_Bool removeduplicates)
static SCIP_DECL_READERWRITE(readerWriteSdpa)
SCIP_RETCODE SCIPcreateConsSdp(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, int nnonz, int blocksize, int *nvarnonz, int **col, int **row, SCIP_Real **val, SCIP_VAR **vars, int constnnonz, int *constcol, int *constrow, SCIP_Real *constval, SCIP_Bool removeduplicates)
static SCIP_RETCODE SDPAreadBlockSize(SCIP *scip, SCIP_FILE *file, SCIP_Longint *linecount, SDPA_DATA *data)
static SCIP_RETCODE SDPAreadBlocks(SCIP *scip, SCIP_FILE *file, SCIP_Longint *linecount, SDPA_DATA *data)
Constraint handler for SDP-constraints.
SCIP_RETCODE SCIPconsSdpGetData(SCIP *scip, SCIP_CONS *cons, int *nvars, int *nnonz, int *blocksize, int *arraylength, int *nvarnonz, int **col, int **row, SCIP_Real **val, SCIP_VAR **vars, int *constnnonz, int *constcol, int *constrow, SCIP_Real *constval, SCIP_Bool *rankone, int **maxevsubmat, SCIP_Bool *addedquadcons)
SCIP_Bool SCIPconsSdpShouldBeRankOne(SCIP_CONS *cons)
static SCIP_RETCODE readLineInts(SCIP *scip, SCIP_FILE *file, char **buffer, int *bufferlen, SCIP_Longint *linecount, int nvals, int *values, int *nread)
static SCIP_DECL_READERCOPY(readerCopySdpa)
static SCIP_RETCODE readLine(SCIP *scip, SCIP_FILE *file, char **buffer, int *bufferlen, SCIP_Bool *success)
int SCIPconsSdpGetBlocksize(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE readLineDoubles(SCIP *scip, SCIP_FILE *file, char **buffer, int *bufferlen, SCIP_Longint *linecount, int nvals, SCIP_Real *values, int *nread)
static SCIP_RETCODE SDPAreadInt(SCIP *scip, SCIP_FILE *file, SCIP_Longint *linecount, SDPA_DATA *data)
SCIP_RETCODE SCIPincludeReaderSdpa(SCIP *scip)
static SCIP_RETCODE readNextLineStar(SCIP *scip, SCIP_FILE *file, char **buffer, int *bufferlen, SCIP_Longint *linecount, SCIP_Bool *success)
SCIP_RETCODE SCIPconsSdpGetNNonz(SCIP *scip, SCIP_CONS *cons, int *nnonz, int *constnnonz)
static SCIP_RETCODE SDPAreadRank1(SCIP *scip, SCIP_FILE *file, SCIP_Longint *linecount, SDPA_DATA *data)
static SCIP_RETCODE SDPAreadNVars(SCIP *scip, SCIP_FILE *file, SCIP_Longint *linecount, SDPA_DATA *data)