75 #include "scip/cons_linear.h" 78 #define READER_NAME "cbfreader" 79 #define READER_DESC "file reader and writer for MISDPs in cbf format" 80 #define READER_EXTENSION "cbf" 82 #define CBF_VERSION_NR 2 83 #define CBF_CHECK_NONNEG TRUE 90 #define MACRO_STR_EXPAND(tok) #tok 91 #define MACRO_STR(tok) MACRO_STR_EXPAND(tok) 92 #define CBF_NAME_FORMAT "%" MACRO_STR(CBF_MAX_NAME) "s" 93 #define CBF_MAX_LINE 512 94 #define CBF_MAX_NAME 512 103 SCIP_Bool* psdvarrank1;
104 SCIP_VAR**** createdpsdvars;
105 SCIP_Bool noorigsdpcons;
106 SCIP_Bool* sdpblockrank1;
110 SCIP_VAR** createdvars;
112 SCIP_CONS** createdconss;
119 SCIP_VAR*** sdpblockvars;
126 SCIP_Real*** valpointer;
127 int* sdpconstnblocknonz;
131 SCIP_Real** sdpconstval;
135 typedef struct CBF_Data CBF_DATA;
146 SCIP_Longint* linecount
149 assert( pFile != NULL );
150 assert( linecount != NULL );
161 return SCIP_READERROR;
169 SCIP_Longint* linecount
172 assert(
scip != NULL );
173 assert( pfile != NULL );
174 assert( linecount != NULL );
176 SCIP_CALL(
CBFfgets(pfile, linecount) );
180 SCIPerrorMessage(
"Could not read OBJSENSE in line &d.\n", linecount);
182 return SCIP_READERROR;
187 SCIP_CALL( SCIPsetObjsense(
scip, SCIP_OBJSENSE_MINIMIZE) );
191 SCIP_CALL( SCIPsetObjsense(
scip, SCIP_OBJSENSE_MAXIMIZE) );
195 SCIPerrorMessage(
"OBJSENSE in line %d should be either MIN or MAX.\n", linecount);
197 return SCIP_READERROR;
208 SCIP_Longint* linecount,
212 char varname[SCIP_MAXSTRLEN];
223 assert(
scip != NULL );
224 assert( pfile != NULL );
225 assert( linecount != NULL );
226 assert( data != NULL );
228 SCIP_CALL(
CBFfgets(pfile, linecount) );
230 if ( sscanf(
CBF_LINE_BUFFER,
"%i %i", &(data->nvars), &nvartypes) != 2 )
232 SCIPerrorMessage(
"Could not read number of scalar variables and conic domains in line %d.\n", linecount);
234 return SCIP_READERROR;
237 if ( data->nvars < 0 )
239 SCIPerrorMessage(
"Number of scalar variables %d in line %d should be non-negative!\n", data->nvars, linecount);
241 return SCIP_READERROR;
246 SCIPerrorMessage(
"Number of conic variable domains %d in line %d should be non-negative!\n", nvartypes, linecount);
248 return SCIP_READERROR;
250 assert( data->nvars >= 0 && nvartypes >= 0 );
253 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->createdvars), data->nvars) );
254 for (t = 0; t < nvartypes; t++)
259 SCIP_CALL(
CBFfgets(pfile, linecount) );
263 SCIPerrorMessage(
"Could not read conic domain and number of corresponding scalar variables in line %d.\n", linecount);
265 return SCIP_READERROR;
268 if ( nvartypevars <= 0 )
270 SCIPerrorMessage(
"Number of scalar variables %d in line %d should be positive!\n", nvartypevars, linecount);
272 return SCIP_READERROR;
275 lb = -SCIPinfinity(
scip);
276 ub = SCIPinfinity(
scip);
288 SCIPerrorMessage(
"CBF-Reader of SCIP-SDP currently only supports non-negative, non-positive and free variables!\n");
290 return SCIP_READERROR;
294 for (v = 0; v < nvartypevars; v++)
297 snprintfreturn = SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"x_%d", cnt);
298 assert( snprintfreturn < SCIP_MAXSTRLEN);
300 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"x_%d", cnt);
303 SCIP_CALL( SCIPcreateVar(
scip, &var, varname, lb, ub, 0.0, SCIP_VARTYPE_CONTINUOUS,
304 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL));
306 SCIP_CALL( SCIPaddVar(
scip, var) );
307 data->createdvars[cnt++] = var;
310 SCIP_CALL( SCIPreleaseVar(
scip, &var) );
314 if ( cnt != data->nvars )
316 SCIPerrorMessage(
"Total number of scalar variables for different cone types not equal to total number of scalar variables!\n");
318 return SCIP_READERROR;
329 SCIP_Longint* linecount,
333 char varname[SCIP_MAXSTRLEN];
344 assert(
scip != NULL );
345 assert( pfile != NULL );
346 assert( linecount != NULL );
347 assert( data != NULL );
350 if ( data->nsdpblocks > -1 )
352 SCIPerrorMessage(
"Need to have 'PSDVAR' section before 'PSDCON' section!\n");
354 return SCIP_READERROR;
357 SCIP_CALL(
CBFfgets(pfile, linecount) );
361 SCIPerrorMessage(
"Could not read number of psd variables in line %d.\n", linecount);
363 return SCIP_READERROR;
366 if ( data->npsdvars < 0 )
368 SCIPerrorMessage(
"Number of psd variables %d in line %d should be non-negative!\n", data->npsdvars, linecount);
370 return SCIP_READERROR;
372 assert( data->npsdvars >= 0 );
375 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->createdpsdvars), data->npsdvars) );
376 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->psdvarsizes), data->npsdvars) );
377 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->psdvarrank1), data->npsdvars) );
379 for (t = 0; t < data->npsdvars; t++)
385 SCIP_CALL(
CBFfgets(pfile, linecount) );
389 SCIPerrorMessage(
"Could not read the size of psd variable %d in line %d.\n", t, linecount);
391 return SCIP_READERROR;
394 if ( sizepsdvar <= 0 )
396 SCIPerrorMessage(
"Size %d of psd variable %d in line %d should be positive!\n", sizepsdvar, t, linecount);
398 return SCIP_READERROR;
402 nscalarvars = sizepsdvar * (sizepsdvar + 1) / 2;
403 data->psdvarsizes[t] = sizepsdvar;
406 data->psdvarrank1[t] = FALSE;
408 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->createdpsdvars[t]), sizepsdvar) );
410 lb = -SCIPinfinity(
scip);
411 ub = SCIPinfinity(
scip);
413 for (i = 0; i < sizepsdvar; ++i)
415 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->createdpsdvars[t][i]), i+1) );
416 for (j = 0; j <= i; ++j)
419 snprintfreturn = SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"y_%d%d%d", t, i, j);
420 assert( snprintfreturn < SCIP_MAXSTRLEN);
422 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"y_%d%d%d", t, i, j);
425 SCIP_CALL( SCIPcreateVar(
scip, &var, varname, lb, ub, 0.0, SCIP_VARTYPE_CONTINUOUS,
426 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL));
428 SCIP_CALL( SCIPaddVar(
scip, var) );
429 data->createdpsdvars[t][i][j] = var;
433 SCIP_CALL( SCIPreleaseVar(
scip, &var) );
436 assert( cnt == nscalarvars );
447 SCIP_Longint* linecount,
455 assert(
scip != NULL );
456 assert( pfile != NULL );
457 assert( linecount != NULL );
458 assert( data != NULL );
461 if ( data->npsdvars < 0 )
463 SCIPerrorMessage(
"Need to have 'PSDVAR' section before 'PSDVARRANK1' section!\n");
465 return SCIP_READERROR;
468 SCIP_CALL(
CBFfgets(pfile, linecount) );
472 SCIPerrorMessage(
"Could not read number of psd variables with a rank-1 constraint in line %d.\n", linecount);
474 return SCIP_READERROR;
477 if ( nrank1psdvars < 0 )
479 SCIPerrorMessage(
"Number of psd variables with a rank-1 constraint %d in line %d should be non-negative!\n", nrank1psdvars, linecount);
481 return SCIP_READERROR;
484 assert( nrank1psdvars >= 0 );
485 assert( data->nsdpblocksrank1 >= 0 );
487 data->nsdpblocksrank1 += nrank1psdvars;
489 for (i = 0; i < nrank1psdvars; i++)
491 SCIP_CALL(
CBFfgets(pfile, linecount) );
495 SCIPerrorMessage(
"Could not read index of psd variable with a rank-1 constraint in line %d.\n", linecount);
497 return SCIP_READERROR;
500 if ( v < 0 || v >= data->npsdvars )
502 SCIPerrorMessage(
"Given rank-1 constraint in line %d for matrix variable %d which does not exist!\n", linecount, v);
504 return SCIP_READERROR;
507 data->psdvarrank1[v] = TRUE;
518 SCIP_Longint* linecount,
522 char consname[SCIP_MAXSTRLEN];
533 assert(
scip != NULL );
534 assert( pfile != NULL );
535 assert( linecount != NULL );
536 assert( data != NULL );
538 SCIP_CALL(
CBFfgets(pfile, linecount) );
540 if ( sscanf(
CBF_LINE_BUFFER,
"%i %i", &(data->nconss), &nconstypes) != 2 )
542 SCIPerrorMessage(
"Could not read number of scalar constraints and conic domains in line %d.\n", linecount);
544 return SCIP_READERROR;
547 if ( data->nconss < 0 )
549 SCIPerrorMessage(
"Number of scalar constraints %d in line %d should be non-negative!\n", data->nconss, linecount);
551 return SCIP_READERROR;
554 if ( nconstypes < 0 )
556 SCIPerrorMessage(
"Number of conic constraint domains %d in line %d should be non-negative!\n", nconstypes, linecount);
558 return SCIP_READERROR;
560 assert( data->nconss >= 0 && nconstypes >= 0 );
563 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->createdconss), data->nconss) );
564 for (t = 0; t < nconstypes; t++)
569 SCIP_CALL(
CBFfgets(pfile, linecount) );
573 SCIPerrorMessage(
"Could not read conic domain and number of corresponding scalar constraints in line %d.\n", linecount);
575 return SCIP_READERROR;
578 if ( nconstypeconss <= 0 )
580 SCIPerrorMessage(
"Number of constraints %d in line %d should be positive!\n", nconstypeconss, linecount);
582 return SCIP_READERROR;
585 lhs = -SCIPinfinity(
scip);
586 rhs = SCIPinfinity(
scip);
603 SCIPerrorMessage(
"CBF-Reader of SCIP-SDP currently only supports linear greater or equal, less or equal and" 604 "equality constraints!\n");
606 return SCIP_READERROR;
610 for (c = 0; c < nconstypeconss; c++)
613 snprintfreturn = SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"LP_%d", cnt);
614 assert( snprintfreturn < SCIP_MAXSTRLEN);
616 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"linear_%d", cnt);
619 SCIP_CALL( SCIPcreateConsLinear(
scip, &cons, consname, 0, NULL, NULL, lhs, rhs,
620 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE));
622 SCIP_CALL( SCIPaddCons(
scip, cons) );
623 data->createdconss[cnt++] = cons;
626 SCIP_CALL( SCIPreleaseCons(
scip, &cons) );
630 if ( cnt != data->nconss )
632 SCIPerrorMessage(
"Total number of constraints for different cone types not equal to total number of constraints!\n");
634 return SCIP_READERROR;
645 SCIP_Longint* linecount,
652 SCIP_Bool infeasible;
654 assert(
scip != NULL );
655 assert( pfile != NULL );
656 assert( linecount != NULL );
657 assert( data != NULL );
659 if ( data->createdvars == NULL )
661 SCIPerrorMessage(
"Need to have 'VAR' section before 'INT' section!\n");
663 return SCIP_READERROR;
665 assert( data->nvars >= 0 );
667 SCIP_CALL(
CBFfgets(pfile, linecount) );
671 SCIPerrorMessage(
"Could not read number of integer variables in line %d.\n", linecount);
673 return SCIP_READERROR;
678 SCIPerrorMessage(
"Number of integrality constraints %d in line %d should be non-negative.\n", nintvars, linecount);
680 return SCIP_READERROR;
683 for (i = 0; i < nintvars; i++)
685 SCIP_CALL(
CBFfgets(pfile, linecount) );
689 SCIPerrorMessage(
"Could not read variable index in line %d.\n", linecount);
691 return SCIP_READERROR;
694 SCIP_CALL( SCIPchgVarType(
scip, data->createdvars[v], SCIP_VARTYPE_INTEGER, &infeasible) );
698 SCIPerrorMessage(
"Infeasibility detected because of integrality of variable %s!\n", SCIPvarGetName(data->createdvars[v]));
700 return SCIP_READERROR;
712 SCIP_Longint* linecount,
719 assert(
scip != NULL );
720 assert( pfile != NULL );
721 assert( linecount != NULL );
722 assert( data != NULL );
724 SCIP_CALL(
CBFfgets(pfile, linecount) );
728 SCIPerrorMessage(
"Could not read number of psd constraints in line %d.\n", linecount);
730 return SCIP_READERROR;
733 if ( ncbfsdpblocks < 0 )
735 SCIPerrorMessage(
"Number of SDP-blocks %d in line %d should be non-negative!\n", ncbfsdpblocks, linecount);
737 return SCIP_READERROR;
742 if ( data->npsdvars > 0 )
743 data->nsdpblocks = ncbfsdpblocks + data->npsdvars;
745 data->nsdpblocks = ncbfsdpblocks;
747 data->noorigsdpcons = FALSE;
748 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblocksizes), data->nsdpblocks) );
749 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblockrank1), data->nsdpblocks) );
751 for (b = 0; b < ncbfsdpblocks; b++)
753 SCIP_CALL(
CBFfgets(pfile, linecount) );
756 SCIPerrorMessage(
"Could not read size of psd constraint %d in line %d.\n", b, linecount);
758 return SCIP_READERROR;
761 if ( data->sdpblocksizes[b] <= 0 )
763 SCIPerrorMessage(
"Size %d of SDP-block %d in line %d should be positive!\n", data->sdpblocksizes[b], b, linecount);
765 return SCIP_READERROR;
769 data->sdpblockrank1[b] = FALSE;
772 for (b = 0; b < data->npsdvars; b++)
776 data->sdpblocksizes[ncbfsdpblocks + b] = data->psdvarsizes[b];
777 data->sdpblockrank1[ncbfsdpblocks + b] = data->psdvarrank1[b];
788 SCIP_Longint* linecount,
796 assert(
scip != NULL );
797 assert( pfile != NULL );
798 assert( linecount != NULL );
799 assert( data != NULL );
802 if ( data->nsdpblocks < 0 )
804 SCIPerrorMessage(
"Need to have 'PSDCON' section before 'PSDCONRANK1' section!\n");
806 return SCIP_READERROR;
809 SCIP_CALL(
CBFfgets(pfile, linecount) );
813 SCIPerrorMessage(
"Could not read number of psd constraints with a rank-1 constraint in line %d.\n", linecount);
815 return SCIP_READERROR;
818 if ( nrank1sdpblocks < 0 )
820 SCIPerrorMessage(
"Number of psd constraints with a rank-1 constraint %d in line %d should be non-negative!\n", nrank1sdpblocks, linecount);
822 return SCIP_READERROR;
825 assert( nrank1sdpblocks >= 0 );
826 assert( data->nsdpblocksrank1 >= 0 );
828 data->nsdpblocksrank1 += nrank1sdpblocks;
830 for (i = 0; i < nrank1sdpblocks; i++)
832 SCIP_CALL(
CBFfgets(pfile, linecount) );
835 SCIPerrorMessage(
"Could not read index of psd constraint with a rank-1 constraint in line %d.\n", linecount);
837 return SCIP_READERROR;
840 if ( c < 0 || c >= data->nsdpblocks )
842 SCIPerrorMessage(
"Given rank-1 constraint in line %d for sdp constraint %d which does not exist!\n", linecount, c);
844 return SCIP_READERROR;
847 data->sdpblockrank1[c] = TRUE;
858 SCIP_Longint* linecount,
870 assert(
scip != NULL );
871 assert( pfile != NULL );
872 assert( linecount != NULL );
873 assert( data != NULL );
875 if ( data->createdpsdvars == NULL )
877 SCIPerrorMessage(
"Need to have 'PSDVAR' section before 'OBJFCOORD' section!\n");
879 return SCIP_READERROR;
881 assert( data->npsdvars >= 0 );
883 SCIP_CALL(
CBFfgets(pfile, linecount) );
887 SCIPerrorMessage(
"Could not read number of objective coefficients for matrix variables in line %d.\n", linecount);
889 return SCIP_READERROR;
894 SCIPerrorMessage(
"Number of objective coefficients for matrix variables %d in line %d should be non-negative!\n", nobjcoefs, linecount);
896 return SCIP_READERROR;
899 for (i = 0; i < nobjcoefs; i++)
901 SCIP_CALL(
CBFfgets(pfile, linecount) );
903 if ( sscanf(
CBF_LINE_BUFFER,
"%i %i %i %lf", &v, &row, &col, &val) != 4 )
905 SCIPerrorMessage(
"Could not read entry of OBJFCOORD in line %d.\n", linecount);
907 return SCIP_READERROR;
910 if ( v < 0 || v >= data->npsdvars )
912 SCIPerrorMessage(
"Given objective coefficient in line %d for matrix variable %d which does not exist!\n", linecount, v);
914 return SCIP_READERROR;
917 if ( row < 0 || row >= data->psdvarsizes[v] )
919 SCIPerrorMessage(
"Row index %d of given coefficient in line %d for matrix variable %d in objective function is negative or larger than varsize %d!\n",
920 row, linecount, v, data->psdvarsizes[v]);
922 return SCIP_READERROR;
925 if ( col < 0 || col >= data->psdvarsizes[v] )
927 SCIPerrorMessage(
"Column index %d of given coefficient in line %d for matrix variable %d in objective function is negative or larger than varsize %d!\n",
928 col, linecount, v, data->psdvarsizes[v]);
930 return SCIP_READERROR;
933 if ( SCIPisZero(
scip, val) )
942 SCIP_CALL( SCIPchgVarObj(
scip, data->createdpsdvars[v][col][row], 2*val) );
944 else if ( row == col )
946 SCIP_CALL( SCIPchgVarObj(
scip, data->createdpsdvars[v][col][row], val) );
950 SCIP_CALL( SCIPchgVarObj(
scip, data->createdpsdvars[v][row][col], 2*val) );
957 SCIPverbMessage(
scip, SCIP_VERBLEVEL_HIGH, NULL,
958 "OBJFCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(
scip));
969 SCIP_Longint* linecount,
979 assert(
scip != NULL );
980 assert( pfile != NULL );
981 assert( linecount != NULL );
982 assert( data != NULL );
984 if ( data->createdvars == NULL )
986 SCIPerrorMessage(
"Need to have 'VAR' section before 'OBJACOORD' section!\n");
988 return SCIP_READERROR;
990 assert( data->nvars >= 0 );
992 SCIP_CALL(
CBFfgets(pfile, linecount) );
996 SCIPerrorMessage(
"Could not read number of objective coefficients for scalar variables in line %d.\n", linecount);
998 return SCIP_READERROR;
1001 if ( nobjcoefs < 0 )
1003 SCIPerrorMessage(
"Number of objective coefficients for scalar variables %d in line %d should be non-negative!\n", nobjcoefs, linecount);
1005 return SCIP_READERROR;
1008 for (i = 0; i < nobjcoefs; i++)
1010 SCIP_CALL(
CBFfgets(pfile, linecount) );
1013 SCIPerrorMessage(
"Could not read entry of OBJACOORD in line %d.\n", linecount);
1015 return SCIP_READERROR;
1018 if ( v < 0 || v >= data->nvars )
1020 SCIPerrorMessage(
"Given objective coefficient in line %d for scalar variable %d which does not exist!\n", linecount, v);
1022 return SCIP_READERROR;
1025 if ( SCIPisZero(
scip, val) )
1031 SCIP_CALL( SCIPchgVarObj(
scip, data->createdvars[v], val) );
1035 if ( nzerocoef > 0 )
1037 SCIPverbMessage(
scip, SCIP_VERBLEVEL_HIGH, NULL,
1038 "OBJACOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(
scip));
1049 SCIP_Longint* linecount,
1062 assert(
scip != NULL );
1063 assert( pfile != NULL );
1064 assert( linecount != NULL );
1065 assert( data != NULL );
1067 if ( data->createdpsdvars == NULL )
1069 SCIPerrorMessage(
"Need to have 'PSDVAR' section before 'FCOORD' section!\n");
1071 return SCIP_READERROR;
1073 assert( data->npsdvars >= 0 );
1075 if ( data->createdconss == NULL )
1077 SCIPerrorMessage(
"Need to have 'CON' section before 'FCOORD' section!\n");
1079 return SCIP_READERROR;
1081 assert( data->nconss >= 0 );
1083 SCIP_CALL(
CBFfgets(pfile, linecount) );
1087 SCIPerrorMessage(
"Could not read number of coefficients for psd variables in line %d.\n", linecount);
1089 return SCIP_READERROR;
1094 SCIPerrorMessage(
"Number of matrix variable coefficients %d in line %d should be non-negative!\n", ncoefs, linecount);
1096 return SCIP_READERROR;
1099 for (i = 0; i < ncoefs; i++)
1101 SCIP_CALL(
CBFfgets(pfile, linecount) );
1103 if ( sscanf(
CBF_LINE_BUFFER,
"%i %i %i %i %lf", &c, &v, &row, &col, &val) != 5 )
1105 SCIPerrorMessage(
"Could not read entry of FCOORD in line %d.\n", linecount);
1107 return SCIP_READERROR;
1110 if ( c < 0 || c >= data->nconss )
1112 SCIPerrorMessage(
"Given matrix variable coefficient in line %d for constraint %d which does not exist!\n", linecount, c);
1114 return SCIP_READERROR;
1117 if ( v < 0 || v >= data->npsdvars )
1119 SCIPerrorMessage(
"Given coefficient in line %d for matrix variable %d which does not exist!\n", linecount, v);
1121 return SCIP_READERROR;
1124 if ( row < 0 || row >= data->psdvarsizes[v] )
1126 SCIPerrorMessage(
"Row index %d of given coefficient in line %d for matrix variable %d in scalar constraint %d is negative or larger than varsize %d!\n",
1127 row, linecount, v, c, data->psdvarsizes[v]);
1129 return SCIP_READERROR;
1132 if ( col < 0 || col >= data->psdvarsizes[v] )
1134 SCIPerrorMessage(
"Column index %d of given coefficient in line %d for matrix variable %d in scalar constraint %d is negative or larger than varsize %d!\n",
1135 col, linecount, v, c, data->psdvarsizes[v]);
1137 return SCIP_READERROR;
1140 if ( SCIPisZero(
scip, val) )
1149 SCIP_CALL( SCIPaddCoefLinear(
scip, data->createdconss[c], data->createdpsdvars[v][col][row], 2*val) );
1151 else if ( row == col )
1152 SCIP_CALL( SCIPaddCoefLinear(
scip, data->createdconss[c], data->createdpsdvars[v][row][col], val) );
1155 SCIP_CALL( SCIPaddCoefLinear(
scip, data->createdconss[c], data->createdpsdvars[v][row][col], 2*val) );
1160 if ( nzerocoef > 0 )
1162 SCIPverbMessage(
scip, SCIP_VERBLEVEL_HIGH, NULL,
1163 "FCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(
scip));
1174 SCIP_Longint* linecount,
1185 assert(
scip != NULL );
1186 assert( pfile != NULL );
1187 assert( linecount != NULL );
1188 assert( data != NULL );
1190 if ( data->createdvars == NULL )
1192 SCIPerrorMessage(
"Need to have 'VAR' section before 'ACOORD' section!\n");
1194 return SCIP_READERROR;
1196 assert( data->nvars >= 0 );
1198 if ( data->createdconss == NULL )
1200 SCIPerrorMessage(
"Need to have 'CON' section before 'ACOORD' section!\n");
1202 return SCIP_READERROR;
1204 assert( data->nconss >= 0 );
1206 SCIP_CALL(
CBFfgets(pfile, linecount) );
1210 SCIPerrorMessage(
"Could not read number of linear coefficients in line %d.\n", linecount);
1212 return SCIP_READERROR;
1217 SCIPerrorMessage(
"Number of linear coefficients %d in line %d should be non-negative!\n", ncoefs, linecount);
1219 return SCIP_READERROR;
1222 for (i = 0; i < ncoefs; i++)
1224 SCIP_CALL(
CBFfgets(pfile, linecount) );
1227 SCIPerrorMessage(
"Could not read entry of ACOORD in line %d.\n", linecount);
1229 return SCIP_READERROR;
1232 if ( c < 0 || c >= data->nconss )
1234 SCIPerrorMessage(
"Given linear coefficient in line %d for constraint %d which does not exist!\n", linecount, c);
1236 return SCIP_READERROR;
1239 if ( v < 0 || v >= data->nvars )
1241 SCIPerrorMessage(
"Given linear coefficient in line %d for variable %d which does not exist!\n", linecount, v);
1243 return SCIP_READERROR;
1246 if ( SCIPisZero(
scip, val) )
1252 SCIP_CALL( SCIPaddCoefLinear(
scip, data->createdconss[c], data->createdvars[v], val) );
1256 if ( nzerocoef > 0 )
1258 SCIPverbMessage(
scip, SCIP_VERBLEVEL_HIGH, NULL,
1259 "ACOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(
scip));
1270 SCIP_Longint* linecount,
1280 assert(
scip != NULL );
1281 assert( pfile != NULL );
1282 assert( linecount != NULL );
1283 assert( data != NULL );
1285 if ( data->createdconss == NULL )
1287 SCIPerrorMessage(
"Need to have 'CON' section before 'BCOORD' section!\n");
1289 return SCIP_READERROR;
1291 assert( data->nconss >= 0 );
1293 SCIP_CALL(
CBFfgets(pfile, linecount) );
1297 SCIPerrorMessage(
"Could not read number of constant parts in scalar constraints in line %d.\n", linecount);
1299 return SCIP_READERROR;
1304 SCIPerrorMessage(
"Number of constant parts %d in line %d should be non-negative!\n", nsides, linecount);
1306 return SCIP_READERROR;
1309 for (i = 0; i < nsides; i++)
1311 SCIP_CALL(
CBFfgets(pfile, linecount) );
1315 SCIPerrorMessage(
"Could not read entry of BCOORD in line %d.\n", linecount);
1317 return SCIP_READERROR;
1320 if ( c < 0 || c >= data->nconss )
1322 SCIPerrorMessage(
"Given constant part in line %d for scalar constraint %d which does not exist!\n", linecount, c);
1324 return SCIP_READERROR;
1327 if ( SCIPisZero(
scip, val) )
1334 if ( ! SCIPisInfinity(
scip, -SCIPgetLhsLinear(
scip, data->createdconss[c])) )
1337 SCIP_CALL( SCIPchgLhsLinear(
scip, data->createdconss[c], -val) );
1340 if ( ! SCIPisInfinity(
scip, SCIPgetRhsLinear(
scip, data->createdconss[c]) ) )
1343 SCIP_CALL( SCIPchgRhsLinear(
scip, data->createdconss[c], -val) );
1348 if ( nzerocoef > 0 )
1350 SCIPverbMessage(
scip, SCIP_VERBLEVEL_HIGH, NULL,
1351 "BCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(
scip));
1362 SCIP_Longint* linecount,
1375 int nextindaftervar;
1381 assert(
scip != NULL );
1382 assert( pfile != NULL );
1383 assert( linecount != NULL );
1384 assert( data != NULL );
1386 if ( data->nsdpblocks < 0 )
1388 SCIPerrorMessage(
"Need to have 'PSDCON' section before 'HCOORD' section!\n");
1390 return SCIP_READERROR;
1392 assert( data->nvars >= 0 );
1394 if ( data->nvars < 0 )
1396 SCIPerrorMessage(
"Need to have 'VAR' section before 'HCOORD' section!\n");
1398 return SCIP_READERROR;
1403 if ( data->npsdvars > 0 )
1405 ncbfsdpblocks = data->nsdpblocks - data->npsdvars;
1406 for (i = 0; i < data->npsdvars; i++)
1407 nauxnonz += data->psdvarsizes[i] * (data->psdvarsizes[i] + 1) / 2;
1411 ncbfsdpblocks = data->nsdpblocks;
1416 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpnblocknonz), data->nsdpblocks) );
1417 for (b = 0; b < data->nsdpblocks; b++)
1418 data->sdpnblocknonz[b] = 0;
1420 SCIP_CALL(
CBFfgets(pfile, linecount) );
1424 SCIPerrorMessage(
"Could not read number of nonzero coefficients of SDP-constraints in line %d.\n", linecount);
1426 return SCIP_READERROR;
1429 data->nnonz = nnonz + nauxnonz;
1432 SCIPerrorMessage(
"Number of nonzero coefficients of SDP-constraints %d in line %d should be non-negative!\n", nnonz, linecount);
1434 return SCIP_READERROR;
1438 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &sdpvar, data->nsdpblocks) );
1439 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdprow), data->nsdpblocks) );
1440 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpcol), data->nsdpblocks) );
1441 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpval), data->nsdpblocks) );
1443 for (b = 0; b < data->nsdpblocks; b++)
1445 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(sdpvar[b]), data->nnonz) );
1446 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdprow[b]), data->nnonz) );
1447 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpcol[b]), data->nnonz) );
1448 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpval[b]), data->nnonz) );
1451 for (i = 0; i < nnonz; i++)
1453 SCIP_CALL(
CBFfgets(pfile, linecount) );
1455 if ( sscanf(
CBF_LINE_BUFFER,
"%i %i %i %i %lf", &b, &v, &row, &col, &val) != 5 )
1457 SCIPerrorMessage(
"Could not read entry of HCOORD in line %d.\n", linecount);
1459 return SCIP_READERROR;
1462 if ( b < 0 || b >= ncbfsdpblocks )
1464 SCIPerrorMessage(
"Given SDP-coefficient in line %d for SDP-constraint %d which does not exist!\n", linecount, b);
1466 return SCIP_READERROR;
1469 if ( v < 0 || v >= data->nvars )
1471 SCIPerrorMessage(
"Given SDP-coefficient in line %d for variable %d which does not exist!\n", linecount, v);
1473 return SCIP_READERROR;
1476 if ( row < 0 || row >= data->sdpblocksizes[b] )
1478 SCIPerrorMessage(
"Row index %d of given SDP coefficient in line %d is negative or larger than blocksize %d!\n",
1479 row, linecount, data->sdpblocksizes[b]);
1481 return SCIP_READERROR;
1484 if ( col < 0 || col >= data->sdpblocksizes[b] )
1486 SCIPerrorMessage(
"Column index %d of given SDP coefficient in line %d is negative or larger than blocksize %d!\n",
1487 col, linecount, data->sdpblocksizes[b]);
1489 return SCIP_READERROR;
1492 if ( SCIPisZero(
scip, val) )
1498 sdpvar[b][data->sdpnblocknonz[b]] = v;
1503 data->sdprow[b][data->sdpnblocknonz[b]] = col;
1504 data->sdpcol[b][data->sdpnblocknonz[b]] = row;
1508 data->sdprow[b][data->sdpnblocknonz[b]] = row;
1509 data->sdpcol[b][data->sdpnblocknonz[b]] = col;
1512 data->sdpval[b][data->sdpnblocknonz[b]] = val;
1513 data->sdpnblocknonz[b]++;
1518 if ( data->npsdvars > 0 )
1521 for (v = 0; v < data->npsdvars; v++)
1523 b = ncbfsdpblocks + v;
1524 for (row = 0; row < data->psdvarsizes[v]; row++)
1526 for (col = 0; col <= row; col++)
1528 sdpvar[b][data->sdpnblocknonz[b]] = data->nvars + 1;
1529 data->sdprow[b][data->sdpnblocknonz[b]] = row;
1530 data->sdpcol[b][data->sdpnblocknonz[b]] = col;
1531 data->sdpval[b][data->sdpnblocknonz[b]] = val;
1532 data->sdpnblocknonz[b]++;
1535 assert( data->sdpnblocknonz[b] == data->psdvarsizes[v] * (data->psdvarsizes[v] + 1) / 2 );
1536 assert( b == data->nsdpblocks - 1 );
1541 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpnblockvars), data->nsdpblocks) );
1542 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblockvars), data->nsdpblocks) );
1543 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->nvarnonz), data->nsdpblocks) );
1544 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->rowpointer), data->nsdpblocks) );
1545 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->colpointer), data->nsdpblocks) );
1546 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->valpointer), data->nsdpblocks) );
1549 for (b = 0; b < ncbfsdpblocks; b++)
1552 SCIPsortIntIntIntReal(sdpvar[b], data->sdprow[b], data->sdpcol[b], data->sdpval[b], data->sdpnblocknonz[b]);
1555 nextindaftervar = 0;
1556 data->sdpnblockvars[b] = 0;
1557 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblockvars[b]), data->nvars) );
1558 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->nvarnonz[b]), data->nvars) );
1559 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->rowpointer[b]), data->nvars) );
1560 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->colpointer[b]), data->nvars) );
1561 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->valpointer[b]), data->nvars) );
1563 for (v = 0; v < data->nvars; v++)
1565 SCIP_Bool varused = FALSE;
1567 firstindforvar = nextindaftervar;
1568 data->nvarnonz[b][data->sdpnblockvars[b]] = 0;
1570 while (nextindaftervar < data->sdpnblocknonz[b] && sdpvar[b][nextindaftervar] == v)
1574 data->nvarnonz[b][data->sdpnblockvars[b]]++;
1579 data->sdpblockvars[b][data->sdpnblockvars[b]] = data->createdvars[v];
1580 data->rowpointer[b][data->sdpnblockvars[b]] = &(data->sdprow[b][firstindforvar]);
1581 data->colpointer[b][data->sdpnblockvars[b]] = &(data->sdpcol[b][firstindforvar]);
1582 data->valpointer[b][data->sdpnblockvars[b]] = &(data->sdpval[b][firstindforvar]);
1583 data->sdpnblockvars[b]++;
1587 assert( nextindaftervar == data->sdpnblocknonz[b] );
1591 if ( data->npsdvars > 0 )
1593 assert( data->nsdpblocks == ncbfsdpblocks + data->npsdvars );
1594 for (v = 0; v < data->npsdvars; v++)
1599 b = ncbfsdpblocks + v;
1601 data->sdpnblockvars[b] = data->sdpnblocknonz[b];
1603 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblockvars[b]), data->sdpnblocknonz[b]) );
1604 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->nvarnonz[b]), data->sdpnblocknonz[b]) );
1605 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->rowpointer[b]), data->sdpnblocknonz[b]) );
1606 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->colpointer[b]), data->sdpnblocknonz[b]) );
1607 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->valpointer[b]), data->sdpnblocknonz[b]) );
1609 for (row = 0; row < data->psdvarsizes[v]; row++)
1611 for (col = 0; col <= row; col++)
1613 data->nvarnonz[b][varidx] = 1;
1614 data->sdpblockvars[b][varidx] = data->createdpsdvars[v][row][col];
1615 data->rowpointer[b][varidx] = &(data->sdprow[b][varidx]);
1616 data->colpointer[b][varidx] = &(data->sdpcol[b][varidx]);
1617 data->valpointer[b][varidx] = &(data->sdpval[b][varidx]);
1621 assert( varidx == data->sdpnblocknonz[b] );
1626 for (b = 0; b < data->nsdpblocks; b++)
1627 SCIPfreeBlockMemoryArray(
scip, &(sdpvar[b]), data->nnonz);
1629 SCIPfreeBlockMemoryArray(
scip, &sdpvar, data->nsdpblocks);
1631 if ( nzerocoef > 0 )
1633 SCIPverbMessage(
scip, SCIP_VERBLEVEL_HIGH, NULL,
1634 "HCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(
scip));
1644 SCIP_Longint* linecount,
1656 assert(
scip != NULL );
1657 assert( pfile != NULL );
1658 assert( linecount != NULL );
1659 assert( data != NULL );
1661 if ( data->nsdpblocks < 0 )
1663 SCIPerrorMessage(
"Need to have 'PSDCON' section before 'DCOORD' section!\n");
1665 return SCIP_READERROR;
1668 if ( data->nvars < 0 )
1670 SCIPerrorMessage(
"Need to have 'VAR' section before 'DCOORD' section!\n");
1672 return SCIP_READERROR;
1675 SCIP_CALL(
CBFfgets(pfile, linecount) );
1679 SCIPerrorMessage(
"Could not read number of constant entries of SDP-constraints in line %d.\n", linecount);
1681 return SCIP_READERROR;
1684 if ( constnnonz < 0 )
1686 SCIPerrorMessage(
"Number of constant entries of SDP-constraints %d in line %d should be non-negative!\n", constnnonz, linecount);
1688 return SCIP_READERROR;
1691 data->constnnonz = constnnonz;
1692 if ( constnnonz > 0 )
1695 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpconstnblocknonz), data->nsdpblocks) );
1696 for (b = 0; b < data->nsdpblocks; b++)
1697 data->sdpconstnblocknonz[b] = 0;
1700 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpconstrow), data->nsdpblocks) );
1701 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpconstcol), data->nsdpblocks) );
1702 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpconstval), data->nsdpblocks) );
1704 for (b = 0; b < data->nsdpblocks; b++)
1706 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpconstrow[b]), constnnonz) );
1707 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpconstcol[b]), constnnonz) );
1708 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpconstval[b]), constnnonz) );
1711 for (i = 0; i < constnnonz; i++)
1713 SCIP_CALL(
CBFfgets(pfile, linecount) );
1714 if ( sscanf(
CBF_LINE_BUFFER,
"%i %i %i %lf", &b, &row, &col, &val) != 4 )
1716 SCIPerrorMessage(
"Could not read entry of DCOORD in line %d.\n", linecount);
1718 return SCIP_READERROR;
1721 if ( b < 0 || b >= data->nsdpblocks )
1723 SCIPerrorMessage(
"Given constant entry in line %d for SDP-constraint %d which does not exist!\n", linecount, b);
1725 return SCIP_READERROR;
1728 if ( row < 0 || row >= data->sdpblocksizes[b] )
1730 SCIPerrorMessage(
"Row index %d of given constant SDP-entry in line %d is negative or larger than blocksize %d!\n",
1731 row, linecount, data->sdpblocksizes[b]);
1733 return SCIP_READERROR;
1736 if ( col < 0 || col >= data->sdpblocksizes[b] )
1738 SCIPerrorMessage(
"Column index %d of given constant SDP-entry in line %d is negative or larger than blocksize %d!\n",
1739 col, linecount, data->sdpblocksizes[b]);
1741 return SCIP_READERROR;
1744 if ( SCIPisZero(
scip, val) )
1753 data->sdpconstrow[b][data->sdpconstnblocknonz[b]] = col;
1754 data->sdpconstcol[b][data->sdpconstnblocknonz[b]] = row;
1758 data->sdpconstrow[b][data->sdpconstnblocknonz[b]] = row;
1759 data->sdpconstcol[b][data->sdpconstnblocknonz[b]] = col;
1761 data->sdpconstval[b][data->sdpconstnblocknonz[b]] = -val;
1762 data->sdpconstnblocknonz[b]++;
1767 if ( nzerocoef > 0 )
1769 SCIPverbMessage(
scip, SCIP_VERBLEVEL_HIGH, NULL,
1770 "DCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(
scip));
1783 SCIP_Bool allocated = FALSE;
1789 assert(
scip != NULL );
1790 assert( data != NULL );
1794 while ( data->sdpconstnblocknonz != NULL && allocated == FALSE && b < data->nsdpblocks)
1796 if (data->sdpconstnblocknonz[b] > 0)
1803 for (b = 0; b < data->nsdpblocks; b++)
1805 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpconstval[b]), data->constnnonz);
1806 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpconstcol[b]), data->constnnonz);
1807 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpconstrow[b]), data->constnnonz);
1809 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpconstval, data->nsdpblocks);
1810 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpconstcol, data->nsdpblocks);
1811 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpconstrow, data->nsdpblocks);
1812 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpconstnblocknonz, data->nsdpblocks);
1817 while (allocated == FALSE && b < data->nsdpblocks)
1819 if (data->sdpnblocknonz[b] > 0)
1828 if ( data->npsdvars > 0 )
1829 ncbfsdpblocks = data->nsdpblocks - data->npsdvars;
1831 ncbfsdpblocks = data->nsdpblocks;
1833 if ( data->noorigsdpcons )
1836 assert( ncbfsdpblocks == 0 );
1838 for (b = 0; b < data->nsdpblocks; b++)
1840 SCIPfreeBlockMemoryArrayNull(
scip, &(data->valpointer[b]), data->sdpnblocknonz[b]);
1841 SCIPfreeBlockMemoryArrayNull(
scip, &(data->colpointer[b]), data->sdpnblocknonz[b]);
1842 SCIPfreeBlockMemoryArrayNull(
scip, &(data->rowpointer[b]), data->sdpnblocknonz[b]);
1843 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpval[b]), data->sdpnblocknonz[b]);
1844 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpcol[b]), data->sdpnblocknonz[b]);
1845 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdprow[b]), data->sdpnblocknonz[b]);
1846 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpblockvars[b]), data->sdpnblocknonz[b]);
1847 SCIPfreeBlockMemoryArrayNull(
scip, &(data->nvarnonz[b]), data->sdpnblocknonz[b]);
1850 SCIPfreeBlockMemoryArrayNull(
scip, &data->valpointer, data->nsdpblocks);
1851 SCIPfreeBlockMemoryArrayNull(
scip, &data->colpointer, data->nsdpblocks);
1852 SCIPfreeBlockMemoryArrayNull(
scip, &data->rowpointer, data->nsdpblocks);
1853 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpval, data->nsdpblocks);
1854 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpcol, data->nsdpblocks);
1855 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdprow, data->nsdpblocks);
1856 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpblockvars, data->nsdpblocks);
1857 SCIPfreeBlockMemoryArrayNull(
scip, &data->nvarnonz, data->nsdpblocks);
1858 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpnblockvars, data->nsdpblocks);
1859 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpnblocknonz, data->nsdpblocks);
1860 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpblockrank1, data->nsdpblocks);
1861 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpblocksizes, data->nsdpblocks);
1866 assert( ncbfsdpblocks > 0 );
1868 for (b = 0; b < ncbfsdpblocks; b++)
1870 SCIPfreeBlockMemoryArrayNull(
scip, &(data->valpointer[b]), data->nvars);
1871 SCIPfreeBlockMemoryArrayNull(
scip, &(data->colpointer[b]), data->nvars);
1872 SCIPfreeBlockMemoryArrayNull(
scip, &(data->rowpointer[b]), data->nvars);
1873 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpval[b]), data->nnonz);
1874 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpcol[b]), data->nnonz);
1875 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdprow[b]), data->nnonz);
1876 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpblockvars[b]), data->nvars);
1877 SCIPfreeBlockMemoryArrayNull(
scip, &(data->nvarnonz[b]), data->nvars);
1880 if ( data->npsdvars > 0 )
1882 for (b = ncbfsdpblocks; b < data->nsdpblocks; b++)
1884 SCIPfreeBlockMemoryArrayNull(
scip, &(data->valpointer[b]), data->sdpnblocknonz[b]);
1885 SCIPfreeBlockMemoryArrayNull(
scip, &(data->colpointer[b]), data->sdpnblocknonz[b]);
1886 SCIPfreeBlockMemoryArrayNull(
scip, &(data->rowpointer[b]), data->sdpnblocknonz[b]);
1887 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpval[b]), data->nnonz);
1888 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpcol[b]), data->nnonz);
1889 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdprow[b]), data->nnonz);
1890 SCIPfreeBlockMemoryArrayNull(
scip, &(data->sdpblockvars[b]), data->sdpnblocknonz[b]);
1891 SCIPfreeBlockMemoryArrayNull(
scip, &(data->nvarnonz[b]), data->sdpnblocknonz[b]);
1895 SCIPfreeBlockMemoryArrayNull(
scip, &data->valpointer, data->nsdpblocks);
1896 SCIPfreeBlockMemoryArrayNull(
scip, &data->colpointer, data->nsdpblocks);
1897 SCIPfreeBlockMemoryArrayNull(
scip, &data->rowpointer, data->nsdpblocks);
1898 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpval, data->nsdpblocks);
1899 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpcol, data->nsdpblocks);
1900 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdprow, data->nsdpblocks);
1901 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpblockvars, data->nsdpblocks);
1902 SCIPfreeBlockMemoryArrayNull(
scip, &data->nvarnonz, data->nsdpblocks);
1903 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpnblockvars, data->nsdpblocks);
1904 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpnblocknonz, data->nsdpblocks);
1905 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpblockrank1, data->nsdpblocks);
1906 SCIPfreeBlockMemoryArrayNull(
scip, &data->sdpblocksizes, data->nsdpblocks);
1910 if (data->nconss > 0)
1912 SCIPfreeBlockMemoryArrayNull(
scip, &data->createdconss, data->nconss);
1915 if (data->nvars > 0)
1916 SCIPfreeBlockMemoryArrayNull(
scip, &data->createdvars, data->nvars);
1918 if ( data-> npsdvars > 0 )
1920 for (t = 0; t < data->npsdvars; t++)
1922 for (i = 0; i < data->psdvarsizes[t]; ++i)
1923 SCIPfreeBlockMemoryArrayNull(
scip, &(data->createdpsdvars[t][i]), i+1);
1924 SCIPfreeBlockMemoryArrayNull(
scip, &(data->createdpsdvars[t]), data->psdvarsizes[t]);
1927 SCIPfreeBlockMemoryArrayNull(
scip, &(data->psdvarrank1), data->npsdvars);
1928 SCIPfreeBlockMemoryArrayNull(
scip, &(data->psdvarsizes), data->npsdvars);
1929 SCIPfreeBlockMemoryArrayNull(
scip, &(data->createdpsdvars), data->npsdvars);
1956 SCIP_FILE* scipfile;
1957 SCIP_Longint linecount = 0;
1958 SCIP_Bool versionread = FALSE;
1959 SCIP_Bool objread = FALSE;
1963 assert( result != NULL );
1965 *result = SCIP_DIDNOTRUN;
1967 SCIPdebugMsg(
scip,
"Reading file %s ...\n", filename);
1969 scipfile = SCIPfopen(filename,
"r");
1972 return SCIP_READERROR;
1974 SCIP_CALL( SCIPallocBuffer(
scip, &data) );
1975 data->nsdpblocks = -1;
1976 data->nsdpblocksrank1 = 0;
1979 data->npsdvars = -1;
1980 data->constnnonz = 0;
1982 data->noorigsdpcons= FALSE;
1984 data->psdvarsizes = NULL;
1985 data->psdvarrank1 = NULL;
1986 data->sdpblockrank1 = NULL;
1987 data->sdpblocksizes = NULL;
1988 data->sdpnblocknonz = NULL;
1989 data->sdpnblockvars = NULL;
1990 data->sdpblockvars = NULL;
1991 data->sdprow = NULL;
1992 data->sdpcol = NULL;
1993 data->sdpval = NULL;
1994 data->sdpconstnblocknonz = NULL;
1995 data->sdpconstrow = NULL;
1996 data->sdpconstcol = NULL;
1997 data->sdpconstval = NULL;
2000 SCIP_CALL( SCIPcreateProb(
scip, filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
2002 while(
CBFfgets(scipfile, &linecount) == SCIP_OKAY )
2008 if ( ! versionread )
2014 SCIP_CALL(
CBFfgets(scipfile, &linecount) );
2018 SCIPdebugMsg(
scip,
"file version %d.\n", ver);
2021 SCIPerrorMessage(
"Strange version number %d; need at least version 1.\n", ver);
2023 return SCIP_READERROR;
2027 SCIPerrorMessage(
"Version %d too new; only supported up to version %d.\n",
CBF_VERSION_NR);
2029 return SCIP_READERROR;
2035 return SCIP_READERROR;
2039 SCIPerrorMessage(
"First keyword should be VER.\n");
2041 return SCIP_READERROR;
2048 SCIPdebugMsg(
scip,
"Reading OBJSENSE\n");
2054 SCIPdebugMsg(
scip,
"Reading VAR\n");
2059 SCIPdebugMsg(
scip,
"Reading CON\n");
2064 SCIPdebugMsg(
scip,
"Reading INT\n");
2069 SCIPdebugMsg(
scip,
"Reading PSDCON\n");
2074 SCIPdebugMsg(
scip,
"Reading PSDVAR\n");
2079 SCIPdebugMsg(
scip,
"Reading PSDCONRANK1\n");
2084 SCIPdebugMsg(
scip,
"Reading PSDVARRANK1\n");
2089 SCIPdebugMsg(
scip,
"Reading OBJFCOORD\n");
2094 SCIPdebugMsg(
scip,
"Reading OBJACOORD\n");
2099 SCIPerrorMessage(
"constant part in objective value not supported by SCIP!\n");
2101 return SCIP_READERROR;
2105 SCIPdebugMsg(
scip,
"Reading FCOORD\n");
2110 SCIPdebugMsg(
scip,
"Reading ACOORD\n");
2115 SCIPdebugMsg(
scip,
"Reading BCOORD\n");
2120 SCIPdebugMsg(
scip,
"Reading HCOORD\n");
2125 SCIPdebugMsg(
scip,
"Reading DCOORD\n");
2130 SCIPerrorMessage(
"Keyword %s in line %d not recognized!\n",
CBF_NAME_BUFFER, linecount);
2132 return SCIP_READERROR;
2141 if ( data->npsdvars > data->nsdpblocks )
2149 assert( data->nsdpblocks == -1 );
2150 assert( data->createdpsdvars != NULL );
2151 assert( data->psdvarrank1 != NULL );
2152 assert( data->npsdvars >= 0 );
2154 data->noorigsdpcons = TRUE;
2156 data->nsdpblocks = data->npsdvars;
2160 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblocksizes), data->nsdpblocks) );
2161 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblockrank1), data->nsdpblocks) );
2162 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpnblocknonz), data->nsdpblocks) );
2163 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpnblockvars), data->nsdpblocks) );
2164 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->nvarnonz), data->nsdpblocks) );
2165 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblockvars), data->nsdpblocks) );
2166 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdprow), data->nsdpblocks) );
2167 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpcol), data->nsdpblocks) );
2168 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpval), data->nsdpblocks) );
2169 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->rowpointer), data->nsdpblocks) );
2170 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->colpointer), data->nsdpblocks) );
2171 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->valpointer), data->nsdpblocks) );
2173 for (b = 0; b < data->nsdpblocks; b++)
2175 nauxvars = data->psdvarsizes[b] * (data->psdvarsizes[b] + 1) / 2;
2176 data->nnonz += nauxvars;
2179 data->sdpblocksizes[b] = data->psdvarsizes[b];
2180 data->sdpblockrank1[b] = data->psdvarrank1[b];
2181 data->sdpnblocknonz[b] = nauxvars;
2182 data->sdpnblockvars[b] = nauxvars;
2184 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->nvarnonz[b]), nauxvars) );
2185 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpblockvars[b]), nauxvars) );
2186 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdprow[b]), nauxvars) );
2187 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpcol[b]), nauxvars) );
2188 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->sdpval[b]), nauxvars) );
2189 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->rowpointer[b]), nauxvars) );
2190 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->colpointer[b]), nauxvars) );
2191 SCIP_CALL( SCIPallocBlockMemoryArray(
scip, &(data->valpointer[b]), nauxvars) );
2194 for (row = 0; row < data->psdvarsizes[b]; row++)
2196 for (col = 0; col <= row; col++)
2198 data->sdprow[b][varidx] = row;
2199 data->sdpcol[b][varidx] = col;
2200 data->sdpval[b][varidx] = val;
2202 data->nvarnonz[b][varidx] = 1;
2203 data->sdpblockvars[b][varidx] = data->createdpsdvars[b][row][col];
2204 data->rowpointer[b][varidx] = &(data->sdprow[b][varidx]);
2205 data->colpointer[b][varidx] = &(data->sdpcol[b][varidx]);
2206 data->valpointer[b][varidx] = &(data->sdpval[b][varidx]);
2210 assert( varidx == nauxvars );
2216 SCIPerrorMessage(
"Keyword OBJSENSE is missing!\n");
2218 return SCIP_READERROR;
2222 if ( SCIPfclose(scipfile) )
2223 return SCIP_READERROR;
2225 #ifdef SCIP_MORE_DEBUG 2226 for (b = 0; b < SCIPgetNConss(
scip); b++)
2228 SCIP_CALL( SCIPprintCons(
scip, SCIPgetConss(
scip)[b], NULL) );
2229 SCIPinfoMessage(
scip, NULL,
"\n");
2234 for (b = 0; b < data->nsdpblocks; b++)
2237 char sdpconname[SCIP_MAXSTRLEN];
2242 assert( data->sdpblocksizes[b] > 0 );
2243 assert( (data->sdpnblockvars[b] > 0 && data->sdpnblocknonz[b] > 0) || (data->sdpconstnblocknonz[b] > 0) );
2246 snprintfreturn = SCIPsnprintf(sdpconname, SCIP_MAXSTRLEN,
"SDP_%d", b);
2247 assert( snprintfreturn < SCIP_MAXSTRLEN);
2249 (void) SCIPsnprintf(sdpconname, SCIP_MAXSTRLEN,
"SDP_%d", b);
2253 if ( data->sdpconstnblocknonz == NULL )
2255 if ( ! data->sdpblockrank1[b] )
2257 SCIP_CALL(
SCIPcreateConsSdp(
scip, &sdpcons, sdpconname, data->sdpnblockvars[b], data->sdpnblocknonz[b],
2258 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b], data->valpointer[b],
2259 data->sdpblockvars[b], 0, NULL, NULL, NULL) );
2264 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b], data->valpointer[b],
2265 data->sdpblockvars[b], 0, NULL, NULL, NULL) );
2270 if ( ! data->sdpblockrank1[b] )
2272 SCIP_CALL(
SCIPcreateConsSdp(
scip, &sdpcons, sdpconname, data->sdpnblockvars[b], data->sdpnblocknonz[b],
2273 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b], data->valpointer[b],
2274 data->sdpblockvars[b], data->sdpconstnblocknonz[b], data->sdpconstcol[b], data->sdpconstrow[b],
2275 data->sdpconstval[b]) );
2280 data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b], data->valpointer[b],
2281 data->sdpblockvars[b], data->sdpconstnblocknonz[b], data->sdpconstcol[b], data->sdpconstrow[b],
2282 data->sdpconstval[b]) );
2286 #ifdef SCIP_MORE_DEBUG 2287 SCIP_CALL( SCIPprintCons(
scip, sdpcons, NULL) );
2290 SCIP_CALL( SCIPaddCons(
scip, sdpcons) );
2292 SCIP_CALL( SCIPreleaseCons(
scip, &sdpcons) );
2296 SCIPfreeBufferNull(
scip, &data);
2298 *result = SCIP_SUCCESS;
2312 SCIP_Real* sdpconstval;
2326 int totalsdpconstnnonz;
2338 int nrank1sdpblocks;
2340 assert(
scip != NULL );
2341 assert( result != NULL );
2343 SCIPdebugMsg(
scip,
"Writing problem in CBF format to file.\n");
2344 *result = SCIP_DIDNOTRUN;
2348 SCIPerrorMessage(
"CBF reader currently only supports writing original problems!\n");
2350 return SCIP_READERROR;
2353 for (c = 0; c < nconss; c++)
2355 if ( (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"linear") != 0)
2356 && (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0 )
2357 && (strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0 ) )
2359 SCIPerrorMessage(
"CBF reader currently only supports linear and SDP constraints!\n");
2361 return SCIP_READERROR;
2366 for (v = 0; v < nvars; v++)
2368 assert( SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_ORIGINAL );
2376 SCIPinfoMessage(
scip, file,
"OBJSENSE\n%s\n\n", objsense == SCIP_OBJSENSE_MINIMIZE ?
"MIN" :
"MAX");
2379 SCIP_CALL( SCIPallocBufferArray(
scip, &varsenses, nvars) );
2380 for (v = 0; v < nvars; v++)
2385 lb = SCIPvarGetLbOriginal(vars[v]);
2386 ub = SCIPvarGetUbOriginal(vars[v]);
2389 if ( SCIPisZero(
scip, lb) )
2393 if ( ! SCIPisInfinity(
scip, -lb) )
2395 SCIPerrorMessage(
"Can only handle variables with lower bound 0 or minus infinity.\n");
2397 return SCIP_READERROR;
2401 if ( SCIPisZero(
scip, ub) )
2405 if ( ! SCIPisInfinity(
scip, ub) )
2407 SCIPerrorMessage(
"Can only handle variables with upper bound 0 or infinity.\n");
2409 return SCIP_READERROR;
2415 SCIP_CALL( SCIPallocBufferArray(
scip, &consssenses, nconss) );
2416 for (c = 0; c < nconss; c++)
2424 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"linear") != 0 )
2427 lhs = SCIPgetLhsLinear(
scip, conss[c]);
2428 rhs = SCIPgetRhsLinear(
scip, conss[c]);
2430 #ifdef CBF_CHECK_NONNEG 2432 if ( SCIPgetNVarsLinear(
scip, conss[c]) == 1 && ! SCIPisEQ(
scip, SCIPgetLhsLinear(
scip, conss[c]), SCIPgetRhsLinear(
scip, conss[c])) )
2435 assert( ! SCIPisZero(
scip, SCIPgetValsLinear(
scip, conss[c])[0]) );
2436 assert( SCIPgetVarsLinear(
scip, conss[c]) != NULL );
2438 v = SCIPvarGetProbindex(SCIPgetVarsLinear(
scip, conss[c])[0]);
2439 assert( 0 <= v && v < nvars );
2441 if ( SCIPgetValsLinear(
scip, conss[c])[0] > 0.0 )
2443 if ( SCIPisZero(
scip, lhs) )
2448 else if ( SCIPisZero(
scip, rhs) )
2456 if ( SCIPisZero(
scip, lhs) )
2461 else if ( SCIPisZero(
scip, rhs) )
2470 if ( SCIPisEQ(
scip, lhs, rhs) )
2472 assert( ! SCIPisInfinity(
scip, -lhs) );
2473 assert( ! SCIPisInfinity(
scip, rhs) );
2478 if ( ! SCIPisInfinity(
scip, -lhs) && ! SCIPisInfinity(
scip, rhs) )
2480 SCIPerrorMessage(
"Cannot handle ranged rows.\n");
2482 return SCIP_READERROR;
2485 if ( ! SCIPisInfinity(
scip, -lhs) )
2487 else if ( ! SCIPisInfinity(
scip, rhs) )
2488 consssenses[c] = -1;
2495 for (v = 0; v < nvars; v++)
2497 if ( varsenses[v] != lastsense )
2500 lastsense = varsenses[v];
2505 SCIPinfoMessage(
scip, file,
"VAR\n%d %d\n", nvars, nsenses);
2506 lastsense = varsenses[0];
2508 for (v = 1; v < nvars; v++)
2510 if ( varsenses[v] != lastsense )
2512 if ( lastsense == 0 )
2513 SCIPinfoMessage(
scip, file,
"F %d\n", nsenses);
2514 else if ( lastsense == -1 )
2515 SCIPinfoMessage(
scip, file,
"L- %d\n", nsenses);
2518 assert( lastsense == 1 );
2519 SCIPinfoMessage(
scip, file,
"L+ %d\n", nsenses);
2522 lastsense = varsenses[v];
2526 if ( lastsense == 0 )
2527 SCIPinfoMessage(
scip, file,
"F %d\n\n", nsenses);
2528 else if ( lastsense == -1 )
2529 SCIPinfoMessage(
scip, file,
"L- %d\n\n", nsenses);
2532 assert( lastsense == 1 );
2533 SCIPinfoMessage(
scip, file,
"L+ %d\n\n", nsenses);
2537 if ( nbinvars + nintvars > 0 )
2539 SCIPinfoMessage(
scip, file,
"INT\n%d\n", nbinvars + nintvars);
2541 for (v = 0; v < nbinvars + nintvars; v++)
2543 assert( SCIPvarIsIntegral(vars[v]) );
2544 SCIPinfoMessage(
scip, file,
"%d\n", v);
2546 SCIPinfoMessage(
scip, file,
"\n");
2553 for (c = 0; c < nconss; c++)
2555 if ( consssenses[c] == 2 )
2559 if ( consssenses[c] != lastsense )
2562 lastsense = consssenses[c];
2567 SCIPinfoMessage(
scip, file,
"CON\n%d %d\n", i, nsenses);
2568 nconsssenses = nsenses;
2570 while (c < nconss && consssenses[c] == 2)
2574 lastsense = consssenses[c];
2577 for (; c < nconss; ++c)
2579 if ( consssenses[c] == 2 )
2582 if ( consssenses[c] != lastsense )
2584 if ( lastsense == 0 )
2585 SCIPinfoMessage(
scip, file,
"L= %d\n", nsenses);
2586 else if ( lastsense == -1 )
2587 SCIPinfoMessage(
scip, file,
"L- %d\n", nsenses);
2590 assert( lastsense == 1 );
2591 SCIPinfoMessage(
scip, file,
"L+ %d\n", nsenses);
2594 lastsense = consssenses[c];
2599 if ( lastsense == 0 )
2600 SCIPinfoMessage(
scip, file,
"L= %d\n\n", nsenses);
2601 else if ( lastsense == -1 )
2602 SCIPinfoMessage(
scip, file,
"L- %d\n\n", nsenses);
2605 assert( lastsense == 1 );
2606 SCIPinfoMessage(
scip, file,
"L+ %d\n\n", nsenses);
2611 for (c = 0; c < nconss; c++)
2613 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") == 0 || strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") == 0 )
2618 SCIPinfoMessage(
scip, file,
"PSDCON\n%d\n", nsdpconss);
2620 for (c = 0; c < nconss; c++)
2622 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0 )
2628 SCIPinfoMessage(
scip, file,
"\n");
2631 nrank1sdpblocks = 0;
2632 for (c = 0; c < nconss; c++)
2634 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") == 0 )
2639 if ( nrank1sdpblocks > 0 )
2641 SCIPinfoMessage(
scip, file,
"PSDCONRANK1\n%d\n", nrank1sdpblocks);
2644 for (c = 0; c < nconss; c++)
2646 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0 )
2650 SCIPinfoMessage(
scip, file,
"%d\n", consind);
2654 SCIPinfoMessage(
scip, file,
"\n");
2659 for (v = 0; v < nvars; v++)
2661 if ( ! SCIPisZero(
scip, SCIPvarGetObj(vars[v])) )
2666 SCIPinfoMessage(
scip, file,
"OBJACOORD\n%d\n", nobjnonz);
2668 for (v = 0; v < nvars; v++)
2672 obj = SCIPvarGetObj(vars[v]);
2673 if ( ! SCIPisZero(
scip, obj) )
2675 SCIPinfoMessage(
scip, file,
"%d %.15g\n", v, obj);
2678 SCIPinfoMessage(
scip, file,
"\n");
2681 if ( nconsssenses > 0 )
2686 for (c = 0; c < nconss; c++)
2688 if ( consssenses[c] == -1 )
2690 assert( ! SCIPisInfinity(
scip, SCIPgetRhsLinear(
scip, conss[c])) );
2691 nnonz += SCIPgetNVarsLinear(
scip, conss[c]);
2692 if ( ! SCIPisZero(
scip, SCIPgetRhsLinear(
scip, conss[c])) )
2695 else if ( consssenses[c] == 1 )
2697 assert( ! SCIPisInfinity(
scip, -SCIPgetLhsLinear(
scip, conss[c])) );
2698 nnonz += SCIPgetNVarsLinear(
scip, conss[c]);
2699 if ( ! SCIPisZero(
scip, SCIPgetLhsLinear(
scip, conss[c])) )
2702 else if ( consssenses[c] == 0 )
2704 assert( SCIPisEQ(
scip, SCIPgetLhsLinear(
scip, conss[c]), SCIPgetRhsLinear(
scip, conss[c])) );
2705 nnonz += SCIPgetNVarsLinear(
scip, conss[c]);
2706 if ( ! SCIPisZero(
scip, SCIPgetLhsLinear(
scip, conss[c])) )
2712 SCIPinfoMessage(
scip, file,
"ACOORD\n%d\n", nnonz);
2714 for (c = 0; c < nconss; c++)
2716 if ( consssenses[c] == -1 || consssenses[c] == 0 || consssenses[c] == 1 )
2718 assert( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"linear") == 0 );
2720 linvars = SCIPgetVarsLinear(
scip, conss[c]);
2721 linvals = SCIPgetValsLinear(
scip, conss[c]);
2723 for (v = 0; v < SCIPgetNVarsLinear(
scip, conss[c]); v++)
2725 i = SCIPvarGetProbindex(linvars[v]);
2726 assert( 0 <= i && i < nvars );
2727 SCIPinfoMessage(
scip, file,
"%d %d %.15g\n", consind, i, linvals[v]);
2732 SCIPinfoMessage(
scip, file,
"\n");
2735 SCIPinfoMessage(
scip, file,
"BCOORD\n%d\n", nbnonz);
2737 for (c = 0; c < nconss; c++)
2740 if ( consssenses[c] == -1 )
2742 val = SCIPgetRhsLinear(
scip, conss[c]);
2743 if ( ! SCIPisZero(
scip, val) )
2744 SCIPinfoMessage(
scip, file,
"%d %.15g\n", consind, -val);
2747 else if ( consssenses[c] == 1 )
2749 val = SCIPgetLhsLinear(
scip, conss[c]);
2750 if ( ! SCIPisZero(
scip, val) )
2751 SCIPinfoMessage(
scip, file,
"%d %.15g\n", consind, -val);
2754 else if ( consssenses[c] == 0 )
2756 val = SCIPgetLhsLinear(
scip, conss[c]);
2757 if ( ! SCIPisZero(
scip, val) )
2758 SCIPinfoMessage(
scip, file,
"%d %.15g\n", consind, -val);
2762 SCIPinfoMessage(
scip, file,
"\n");
2767 totalsdpconstnnonz = 0;
2768 for (c = 0; c < nconss; c++)
2770 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0 )
2774 totalsdpnnonz += sdpnnonz;
2775 totalsdpconstnnonz += sdpconstnnonz;
2779 SCIP_CALL( SCIPallocBufferArray(
scip, &sdpnvarnonz, nvars) );
2780 SCIP_CALL( SCIPallocBufferArray(
scip, &sdpcol, totalsdpnnonz) );
2781 SCIP_CALL( SCIPallocBufferArray(
scip, &sdprow, totalsdpnnonz) );
2782 SCIP_CALL( SCIPallocBufferArray(
scip, &sdpval, totalsdpnnonz) );
2783 SCIP_CALL( SCIPallocBufferArray(
scip, &sdpvars, nvars) );
2784 SCIP_CALL( SCIPallocBufferArray(
scip, &sdpconstcol, totalsdpconstnnonz) );
2785 SCIP_CALL( SCIPallocBufferArray(
scip, &sdpconstrow, totalsdpconstnnonz) );
2786 SCIP_CALL( SCIPallocBufferArray(
scip, &sdpconstval, totalsdpconstnnonz) );
2788 sdparraylength = totalsdpnnonz;
2789 sdpconstnnonz = totalsdpconstnnonz;
2792 if ( totalsdpnnonz > 0 )
2794 SCIPinfoMessage(
scip, file,
"HCOORD\n%d\n", totalsdpnnonz);
2796 for (c = 0; c < nconss; c++)
2798 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0 )
2802 sdparraylength = totalsdpnnonz;
2803 sdpconstnnonz = totalsdpconstnnonz;
2805 SCIP_CALL(
SCIPconsSdpGetData(
scip, conss[c], &sdpnvars, &sdpnnonz, &sdpblocksize, &sdparraylength, sdpnvarnonz,
2806 sdpcol, sdprow, sdpval, sdpvars, &sdpconstnnonz, sdpconstcol, sdpconstrow, sdpconstval, NULL, NULL, NULL) );
2808 assert( sdpconstnnonz <= totalsdpconstnnonz );
2809 assert( sdparraylength <= totalsdpnnonz);
2811 for (v = 0; v < sdpnvars; v++)
2813 for (i = 0; i < sdpnvarnonz[v]; i++)
2816 ind = SCIPvarGetProbindex(sdpvars[v]);
2817 assert( 0 <= ind && ind < nvars );
2818 SCIPinfoMessage(
scip, file,
"%d %d %d %d %.15g\n", consind, ind, sdprow[v][i], sdpcol[v][i], sdpval[v][i]);
2823 SCIPinfoMessage(
scip, file,
"\n");
2827 if ( totalsdpnnonz > 0 )
2829 SCIPinfoMessage(
scip, file,
"DCOORD\n%d\n", totalsdpconstnnonz);
2831 for (c = 0; c < nconss; c++)
2833 if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),
"SDPrank1") != 0 )
2837 sdparraylength = totalsdpnnonz;
2838 sdpconstnnonz = totalsdpconstnnonz;
2840 SCIP_CALL(
SCIPconsSdpGetData(
scip, conss[c], &sdpnvars, &sdpnnonz, &sdpblocksize, &sdparraylength, sdpnvarnonz,
2841 sdpcol, sdprow, sdpval, sdpvars, &sdpconstnnonz, sdpconstcol, sdpconstrow, sdpconstval, NULL, NULL, NULL) );
2843 assert( sdpconstnnonz <= totalsdpconstnnonz );
2844 assert( sdparraylength <= totalsdpnnonz);
2846 for (i = 0; i < sdpconstnnonz; i++)
2848 SCIPinfoMessage(
scip, file,
"%d %d %d %.15g\n", consind, sdpconstrow[i], sdpconstcol[i], -sdpconstval[i]);
2854 SCIPfreeBufferArray(
scip, &sdpconstval);
2855 SCIPfreeBufferArray(
scip, &sdpconstrow);
2856 SCIPfreeBufferArray(
scip, &sdpconstcol);
2857 SCIPfreeBufferArray(
scip, &sdpvars);
2858 SCIPfreeBufferArray(
scip, &sdpval);
2859 SCIPfreeBufferArray(
scip, &sdprow);
2860 SCIPfreeBufferArray(
scip, &sdpcol);
2861 SCIPfreeBufferArray(
scip, &sdpnvarnonz);
2862 SCIPfreeBufferArray(
scip, &consssenses);
2863 SCIPfreeBufferArray(
scip, &varsenses);
2865 *result = SCIP_SUCCESS;
2880 SCIP_READERDATA* readerdata = NULL;
2881 SCIP_READER* reader;
2886 assert( reader != NULL );
2889 SCIP_CALL( SCIPsetReaderCopy(
scip, reader, readerCopyCbf) );
2890 SCIP_CALL( SCIPsetReaderRead(
scip, reader, readerReadCbf) );
2891 SCIP_CALL( SCIPsetReaderWrite(
scip, reader, readerWriteCbf) );
static SCIP_RETCODE CBFfgets(SCIP_FILE *pFile, SCIP_Longint *linecount)
static SCIP_RETCODE CBFreadBcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
static SCIP_RETCODE CBFreadHcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
static SCIP_RETCODE CBFreadPsdVarRank1(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
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)
char CBF_LINE_BUFFER[CBF_MAX_LINE]
static SCIP_RETCODE CBFreadPsdCon(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
static SCIP_RETCODE CBFreadObjFcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
file reader for mixed-integer semidefinite programs in CBF format
static SCIP_DECL_READERCOPY(readerCopyCbf)
static SCIP_RETCODE CBFreadObjsense(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount)
static SCIP_RETCODE CBFfreeData(SCIP *scip, CBF_DATA *data)
static SCIP_RETCODE CBFreadAcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
char CBF_NAME_BUFFER[CBF_MAX_NAME]
static SCIP_RETCODE CBFreadDcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
static SCIP_RETCODE CBFreadInt(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Constraint handler for SDP-constraints.
SCIP_RETCODE SCIPincludeReaderCbf(SCIP *scip)
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)
static SCIP_RETCODE CBFreadFcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
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 CBFreadVar(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
static SCIP_DECL_READERREAD(readerReadCbf)
static SCIP_RETCODE CBFreadCon(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
int SCIPconsSdpGetBlocksize(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE CBFreadPsdConRank1(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
SCIP_RETCODE SCIPconsSdpGetNNonz(SCIP *scip, SCIP_CONS *cons, int *nnonz, int *constnnonz)
static SCIP_RETCODE CBFreadObjAcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
static SCIP_RETCODE CBFreadPsdVar(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
static SCIP_DECL_READERWRITE(readerWriteCbf)