SCIP-SDP  3.2.0
reader_cbf.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of SCIPSDP - a solving framework for mixed-integer */
4 /* semidefinite programs based on SCIP. */
5 /* */
6 /* Copyright (C) 2011-2013 Discrete Optimization, TU Darmstadt */
7 /* EDOM, FAU Erlangen-Nürnberg */
8 /* 2014-2020 Discrete Optimization, TU Darmstadt */
9 /* */
10 /* */
11 /* This program is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public License */
13 /* as published by the Free Software Foundation; either version 3 */
14 /* of the License, or (at your option) any later version. */
15 /* */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with this program; if not, write to the Free Software */
23 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
24 /* */
25 /* */
26 /* Based on SCIP - Solving Constraint Integer Programs */
27 /* Copyright (C) 2002-2020 Zuse Institute Berlin */
28 /* SCIP is distributed under the terms of the SCIP Academic Licence, */
29 /* see file COPYING in the SCIP distribution. */
30 /* */
31 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
32 
33 /* #define SCIP_MORE_DEBUG */
34 
68 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
69 
70 #include <assert.h>
71 #include <string.h> /* for strcmp */
72 
73 #include "scipsdp/reader_cbf.h"
74 #include "scipsdp/cons_sdp.h"
75 #include "scip/cons_linear.h"
76 
77 
78 #define READER_NAME "cbfreader"
79 #define READER_DESC "file reader and writer for MISDPs in cbf format"
80 #define READER_EXTENSION "cbf"
81 
82 #define CBF_VERSION_NR 2
83 #define CBF_CHECK_NONNEG TRUE
86  /* TODO: currently doesn't work for ranged rows (which are not created by sdpa
87  * reader) */
88 
89 /* Use CBF_NAME_FORMAT instead of %s when parsing lines, to avoid buffer overflow. */
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 /* Last 3 chars reserved for '\r\n\0' */
94 #define CBF_MAX_NAME 512
95 
98 
99 struct CBF_Data
100 {
101  int npsdvars;
102  int* psdvarsizes;
103  SCIP_Bool* psdvarrank1;
104  SCIP_VAR**** createdpsdvars;
105  SCIP_Bool noorigsdpcons;
106  SCIP_Bool* sdpblockrank1;
107  int nsdpblocksrank1;
109  int nvars;
110  SCIP_VAR** createdvars;
111  int nconss;
112  SCIP_CONS** createdconss;
114  int nsdpblocks;
115  int* sdpblocksizes;
116  int* sdpnblocknonz;
117  int* sdpnblockvars;
118  int** nvarnonz;
119  SCIP_VAR*** sdpblockvars;
120  int** sdprow;
121  int** sdpcol;
122  SCIP_Real** sdpval;
123  int nnonz;
124  int*** rowpointer;
125  int*** colpointer;
126  SCIP_Real*** valpointer;
127  int* sdpconstnblocknonz;
129  int** sdpconstrow;
130  int** sdpconstcol;
131  SCIP_Real** sdpconstval;
132  int constnnonz;
133 };
134 
135 typedef struct CBF_Data CBF_DATA;
136 
138 /*
139  * Local methods
140  */
141 
143 static
144 SCIP_RETCODE CBFfgets(
145  SCIP_FILE* pFile,
146  SCIP_Longint* linecount
147  )
148 {
149  assert( pFile != NULL );
150  assert( linecount != NULL );
151 
152  /* Find first non-commentary line */
153  while ( SCIPfgets(CBF_LINE_BUFFER, (int) sizeof(CBF_LINE_BUFFER), pFile) != NULL )
154  {
155  ++(*linecount);
156 
157  if ( CBF_LINE_BUFFER[0] != '#' )
158  return SCIP_OKAY;
159  }
160 
161  return SCIP_READERROR;
162 }
163 
165 static
166 SCIP_RETCODE CBFreadObjsense(
167  SCIP* scip,
168  SCIP_FILE* pfile,
169  SCIP_Longint* linecount
170  )
171 {
172  assert( scip != NULL );
173  assert( pfile != NULL );
174  assert( linecount != NULL );
175 
176  SCIP_CALL( CBFfgets(pfile, linecount) );
177 
178  if ( sscanf(CBF_LINE_BUFFER, CBF_NAME_FORMAT, CBF_NAME_BUFFER) != 1 )
179  {
180  SCIPerrorMessage("Could not read OBJSENSE in line &d.\n", linecount);
181  SCIPABORT();
182  return SCIP_READERROR;
183  }
184 
185  if ( strcmp(CBF_NAME_BUFFER, "MIN") == 0 )
186  {
187  SCIP_CALL( SCIPsetObjsense(scip, SCIP_OBJSENSE_MINIMIZE) );
188  }
189  else if ( strcmp(CBF_NAME_BUFFER, "MAX") == 0 )
190  {
191  SCIP_CALL( SCIPsetObjsense(scip, SCIP_OBJSENSE_MAXIMIZE) );
192  }
193  else
194  {
195  SCIPerrorMessage("OBJSENSE in line %d should be either MIN or MAX.\n", linecount);
196  SCIPABORT();
197  return SCIP_READERROR; /*lint !e527*/
198  }
199 
200  return SCIP_OKAY;
201 }
202 
204 static
205 SCIP_RETCODE CBFreadVar(
206  SCIP* scip,
207  SCIP_FILE* pfile,
208  SCIP_Longint* linecount,
209  CBF_DATA* data
210  )
211 {
212  char varname[SCIP_MAXSTRLEN];
213  SCIP_VAR* var;
214  int nvartypevars;
215  int nvartypes;
216  int cnt = 0;
217  int t;
218  int v;
219 #ifndef NDEBUG
220  int snprintfreturn;
221 #endif
222 
223  assert( scip != NULL );
224  assert( pfile != NULL );
225  assert( linecount != NULL );
226  assert( data != NULL );
227 
228  SCIP_CALL( CBFfgets(pfile, linecount) );
229 
230  if ( sscanf(CBF_LINE_BUFFER, "%i %i", &(data->nvars), &nvartypes) != 2 )
231  {
232  SCIPerrorMessage("Could not read number of scalar variables and conic domains in line %d.\n", linecount);
233  SCIPABORT();
234  return SCIP_READERROR;
235  }
236 
237  if ( data->nvars < 0 )
238  {
239  SCIPerrorMessage("Number of scalar variables %d in line %d should be non-negative!\n", data->nvars, linecount);
240  SCIPABORT();
241  return SCIP_READERROR; /*lint !e527*/
242  }
243 
244  if ( nvartypes < 0 )
245  {
246  SCIPerrorMessage("Number of conic variable domains %d in line %d should be non-negative!\n", nvartypes, linecount);
247  SCIPABORT();
248  return SCIP_READERROR; /*lint !e527*/
249  }
250  assert( data->nvars >= 0 && nvartypes >= 0 );
251 
252  /* loop through different variable types */
253  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->createdvars), data->nvars) );
254  for (t = 0; t < nvartypes; t++)
255  {
256  SCIP_Real lb;
257  SCIP_Real ub;
258 
259  SCIP_CALL( CBFfgets(pfile, linecount) );
260 
261  if ( sscanf(CBF_LINE_BUFFER, CBF_NAME_FORMAT" %i", CBF_NAME_BUFFER, &nvartypevars) != 2 )
262  {
263  SCIPerrorMessage("Could not read conic domain and number of corresponding scalar variables in line %d.\n", linecount);
264  SCIPABORT();
265  return SCIP_READERROR;
266  }
267 
268  if ( nvartypevars <= 0 )
269  {
270  SCIPerrorMessage("Number of scalar variables %d in line %d should be positive!\n", nvartypevars, linecount);
271  SCIPABORT();
272  return SCIP_READERROR; /*lint !e527*/
273  }
274 
275  lb = -SCIPinfinity(scip);
276  ub = SCIPinfinity(scip);
277 
278  if ( strcmp(CBF_NAME_BUFFER, "L+") == 0 )
279  {
280  lb = 0.0;
281  }
282  else if ( strcmp(CBF_NAME_BUFFER, "L-") == 0 )
283  {
284  ub = 0.0;
285  }
286  else if ( strcmp(CBF_NAME_BUFFER, "F") != 0 )
287  {
288  SCIPerrorMessage("CBF-Reader of SCIP-SDP currently only supports non-negative, non-positive and free variables!\n");
289  SCIPABORT();
290  return SCIP_READERROR; /*lint !e527*/
291  }
292 
293  /* create corresponding variables */
294  for (v = 0; v < nvartypevars; v++)
295  {
296 #ifndef NDEBUG
297  snprintfreturn = SCIPsnprintf(varname, SCIP_MAXSTRLEN, "x_%d", cnt);
298  assert( snprintfreturn < SCIP_MAXSTRLEN);
299 #else
300  (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN, "x_%d", cnt);
301 #endif
302 
303  SCIP_CALL( SCIPcreateVar(scip, &var, varname, lb, ub, 0.0, SCIP_VARTYPE_CONTINUOUS,
304  TRUE, FALSE, NULL, NULL, NULL, NULL, NULL));/*lint !e732*//*lint !e747*/
305 
306  SCIP_CALL( SCIPaddVar(scip, var) );
307  data->createdvars[cnt++] = var;/*lint !e732*//*lint !e747*/
308 
309  /* release variable for the reader */
310  SCIP_CALL( SCIPreleaseVar(scip, &var) );
311  }
312  }
313 
314  if ( cnt != data->nvars )
315  {
316  SCIPerrorMessage("Total number of scalar variables for different cone types not equal to total number of scalar variables!\n");
317  SCIPABORT();
318  return SCIP_READERROR; /*lint !e527*/
319  }
320 
321  return SCIP_OKAY;
322 }
323 
325 static
326 SCIP_RETCODE CBFreadPsdVar(
327  SCIP* scip,
328  SCIP_FILE* pfile,
329  SCIP_Longint* linecount,
330  CBF_DATA* data
331  )
332 { /*lint --e{818}*/
333  char varname[SCIP_MAXSTRLEN];
334  SCIP_VAR* var;
335  int i;
336  int j;
337  int t;
338  int sizepsdvar;
339  int nscalarvars;
340 #ifndef NDEBUG
341  int snprintfreturn;
342 #endif
343 
344  assert( scip != NULL );
345  assert( pfile != NULL );
346  assert( linecount != NULL );
347  assert( data != NULL );
348 
349  /* PSDVAR need to be in front of PSDCON! */
350  if ( data->nsdpblocks > -1 )
351  {
352  SCIPerrorMessage("Need to have 'PSDVAR' section before 'PSDCON' section!\n");
353  SCIPABORT();
354  return SCIP_READERROR; /*lint !e527*/
355  }
356 
357  SCIP_CALL( CBFfgets(pfile, linecount) );
358 
359  if ( sscanf(CBF_LINE_BUFFER, "%i", &(data->npsdvars)) != 1 )
360  {
361  SCIPerrorMessage("Could not read number of psd variables in line %d.\n", linecount);
362  SCIPABORT();
363  return SCIP_READERROR;
364  }
365 
366  if ( data->npsdvars < 0 )
367  {
368  SCIPerrorMessage("Number of psd variables %d in line %d should be non-negative!\n", data->npsdvars, linecount);
369  SCIPABORT();
370  return SCIP_READERROR; /*lint !e527*/
371  }
372  assert( data->npsdvars >= 0 );
373 
374  /* loop through different psd variables */
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) );
378 
379  for (t = 0; t < data->npsdvars; t++)
380  {
381  SCIP_Real lb;
382  SCIP_Real ub;
383  int cnt = 0;
384 
385  SCIP_CALL( CBFfgets(pfile, linecount) );
386 
387  if ( sscanf(CBF_LINE_BUFFER, "%i", &sizepsdvar) != 1 )
388  {
389  SCIPerrorMessage("Could not read the size of psd variable %d in line %d.\n", t, linecount);
390  SCIPABORT();
391  return SCIP_READERROR;
392  }
393 
394  if ( sizepsdvar <= 0 )
395  {
396  SCIPerrorMessage("Size %d of psd variable %d in line %d should be positive!\n", sizepsdvar, t, linecount);
397  SCIPABORT();
398  return SCIP_READERROR; /*lint !e527*/
399  }
400 
401  /* for each psd variable of size n_i create 1/2*n_i*(n_i+1) scalar variables */
402  nscalarvars = sizepsdvar * (sizepsdvar + 1) / 2;
403  data->psdvarsizes[t] = sizepsdvar;
404 
405  /* initialize rank-1 information for each psd variable with FALSE, will eventually be changed when reading PSDVARRANK1 */
406  data->psdvarrank1[t] = FALSE;
407 
408  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->createdpsdvars[t]), sizepsdvar) );
409 
410  lb = -SCIPinfinity(scip);
411  ub = SCIPinfinity(scip);
412 
413  for (i = 0; i < sizepsdvar; ++i)
414  {
415  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->createdpsdvars[t][i]), i+1) );
416  for (j = 0; j <= i; ++j)
417  {
418 #ifndef NDEBUG
419  snprintfreturn = SCIPsnprintf(varname, SCIP_MAXSTRLEN, "y_%d%d%d", t, i, j);
420  assert( snprintfreturn < SCIP_MAXSTRLEN);
421 #else
422  (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN, "y_%d%d%d", t, i, j);
423 #endif
424 
425  SCIP_CALL( SCIPcreateVar(scip, &var, varname, lb, ub, 0.0, SCIP_VARTYPE_CONTINUOUS,
426  TRUE, FALSE, NULL, NULL, NULL, NULL, NULL));/*lint !e732*//*lint !e747*/
427 
428  SCIP_CALL( SCIPaddVar(scip, var) );
429  data->createdpsdvars[t][i][j] = var;/*lint !e732*//*lint !e747*/
430  ++cnt;
431 
432  /* release variable for the reader */
433  SCIP_CALL( SCIPreleaseVar(scip, &var) );
434  }
435  }
436  assert( cnt == nscalarvars );
437  }
438 
439  return SCIP_OKAY;
440 }
441 
443 static
444 SCIP_RETCODE CBFreadPsdVarRank1(
445  SCIP* scip,
446  SCIP_FILE* pfile,
447  SCIP_Longint* linecount,
448  CBF_DATA* data
449  )
450 { /*lint --e{818}*/
451  int nrank1psdvars;
452  int i;
453  int v;
454 
455  assert( scip != NULL );
456  assert( pfile != NULL );
457  assert( linecount != NULL );
458  assert( data != NULL );
459 
460  /* PSDVAR need to be in front of PSDVARRANK1! */
461  if ( data->npsdvars < 0 )
462  {
463  SCIPerrorMessage("Need to have 'PSDVAR' section before 'PSDVARRANK1' section!\n");
464  SCIPABORT();
465  return SCIP_READERROR; /*lint !e527*/
466  }
467 
468  SCIP_CALL( CBFfgets(pfile, linecount) );
469 
470  if ( sscanf(CBF_LINE_BUFFER, "%i", &(nrank1psdvars)) != 1 )
471  {
472  SCIPerrorMessage("Could not read number of psd variables with a rank-1 constraint in line %d.\n", linecount);
473  SCIPABORT();
474  return SCIP_READERROR;
475  }
476 
477  if ( nrank1psdvars < 0 )
478  {
479  SCIPerrorMessage("Number of psd variables with a rank-1 constraint %d in line %d should be non-negative!\n", nrank1psdvars, linecount);
480  SCIPABORT();
481  return SCIP_READERROR; /*lint !e527*/
482  }
483 
484  assert( nrank1psdvars >= 0 );
485  assert( data->nsdpblocksrank1 >= 0 );
486 
487  data->nsdpblocksrank1 += nrank1psdvars;
488 
489  for (i = 0; i < nrank1psdvars; i++)
490  {
491  SCIP_CALL( CBFfgets(pfile, linecount) );
492 
493  if ( sscanf(CBF_LINE_BUFFER, "%i", &v) != 1 )
494  {
495  SCIPerrorMessage("Could not read index of psd variable with a rank-1 constraint in line %d.\n", linecount);
496  SCIPABORT();
497  return SCIP_READERROR;
498  }
499 
500  if ( v < 0 || v >= data->npsdvars )
501  {
502  SCIPerrorMessage("Given rank-1 constraint in line %d for matrix variable %d which does not exist!\n", linecount, v);
503  SCIPABORT();
504  return SCIP_READERROR; /*lint !e527*/
505  }
506 
507  data->psdvarrank1[v] = TRUE;
508  }
509 
510  return SCIP_OKAY;
511 }
512 
514 static
515 SCIP_RETCODE CBFreadCon(
516  SCIP* scip,
517  SCIP_FILE* pfile,
518  SCIP_Longint* linecount,
519  CBF_DATA* data
520  )
521 {
522  char consname[SCIP_MAXSTRLEN];
523  SCIP_CONS* cons;
524  int nconstypes;
525  int nconstypeconss;
526  int t;
527  int c;
528  int cnt = 0;
529 #ifndef NDEBUG
530  int snprintfreturn;
531 #endif
532 
533  assert( scip != NULL );
534  assert( pfile != NULL );
535  assert( linecount != NULL );
536  assert( data != NULL );
537 
538  SCIP_CALL( CBFfgets(pfile, linecount) );
539 
540  if ( sscanf(CBF_LINE_BUFFER, "%i %i", &(data->nconss), &nconstypes) != 2 )
541  {
542  SCIPerrorMessage("Could not read number of scalar constraints and conic domains in line %d.\n", linecount);
543  SCIPABORT();
544  return SCIP_READERROR;
545  }
546 
547  if ( data->nconss < 0 )
548  {
549  SCIPerrorMessage("Number of scalar constraints %d in line %d should be non-negative!\n", data->nconss, linecount);
550  SCIPABORT();
551  return SCIP_READERROR; /*lint !e527*/
552  }
553 
554  if ( nconstypes < 0 )
555  {
556  SCIPerrorMessage("Number of conic constraint domains %d in line %d should be non-negative!\n", nconstypes, linecount);
557  SCIPABORT();
558  return SCIP_READERROR; /*lint !e527*/
559  }
560  assert( data->nconss >= 0 && nconstypes >= 0 );
561 
562  /* loop through different constraint types */
563  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->createdconss), data->nconss) );
564  for (t = 0; t < nconstypes; t++)
565  {
566  SCIP_Real lhs;
567  SCIP_Real rhs;
568 
569  SCIP_CALL( CBFfgets(pfile, linecount) );
570 
571  if ( sscanf(CBF_LINE_BUFFER, CBF_NAME_FORMAT" %i", CBF_NAME_BUFFER, &nconstypeconss) != 2 )
572  {
573  SCIPerrorMessage("Could not read conic domain and number of corresponding scalar constraints in line %d.\n", linecount);
574  SCIPABORT();
575  return SCIP_READERROR;
576  }
577 
578  if ( nconstypeconss <= 0 )
579  {
580  SCIPerrorMessage("Number of constraints %d in line %d should be positive!\n", nconstypeconss, linecount);
581  SCIPABORT();
582  return SCIP_READERROR; /*lint !e527*/
583  }
584 
585  lhs = -SCIPinfinity(scip);
586  rhs = SCIPinfinity(scip);
587 
588  if ( strcmp(CBF_NAME_BUFFER, "L+") == 0 )
589  {
590  lhs = 0.0;
591  }
592  else if ( strcmp(CBF_NAME_BUFFER, "L-") == 0 )
593  {
594  rhs = 0.0;
595  }
596  else if ( strcmp(CBF_NAME_BUFFER, "L=") == 0 )
597  {
598  lhs = 0.0;
599  rhs = 0.0;
600  }
601  else
602  {
603  SCIPerrorMessage("CBF-Reader of SCIP-SDP currently only supports linear greater or equal, less or equal and"
604  "equality constraints!\n");
605  SCIPABORT();
606  return SCIP_READERROR; /*lint !e527*/
607  }
608 
609  /* create corresponding constraints */
610  for (c = 0; c < nconstypeconss; c++)
611  {
612 #ifndef NDEBUG
613  snprintfreturn = SCIPsnprintf(consname, SCIP_MAXSTRLEN, "LP_%d", cnt);
614  assert( snprintfreturn < SCIP_MAXSTRLEN);
615 #else
616  (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN, "linear_%d", cnt);
617 #endif
618 
619  SCIP_CALL( SCIPcreateConsLinear(scip, &cons, consname, 0, NULL, NULL, lhs, rhs,
620  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE));
621 
622  SCIP_CALL( SCIPaddCons(scip, cons) );
623  data->createdconss[cnt++] = cons;
624 
625  /* release constraint for the reader. */
626  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
627  }
628  }
629 
630  if ( cnt != data->nconss )
631  {
632  SCIPerrorMessage("Total number of constraints for different cone types not equal to total number of constraints!\n");
633  SCIPABORT();
634  return SCIP_READERROR; /*lint !e527*/
635  }
636 
637  return SCIP_OKAY;
638 }
639 
641 static
642 SCIP_RETCODE CBFreadInt(
643  SCIP* scip,
644  SCIP_FILE* pfile,
645  SCIP_Longint* linecount,
646  CBF_DATA* data
647  )
648 { /*lint --e{818}*/
649  int nintvars;
650  int i;
651  int v;
652  SCIP_Bool infeasible;
653 
654  assert( scip != NULL );
655  assert( pfile != NULL );
656  assert( linecount != NULL );
657  assert( data != NULL );
658 
659  if ( data->createdvars == NULL )
660  {
661  SCIPerrorMessage("Need to have 'VAR' section before 'INT' section!\n");
662  SCIPABORT();
663  return SCIP_READERROR; /*lint !e527*/
664  }
665  assert( data->nvars >= 0 );
666 
667  SCIP_CALL( CBFfgets(pfile, linecount) );
668 
669  if ( sscanf(CBF_LINE_BUFFER, "%i", &nintvars) != 1 )
670  {
671  SCIPerrorMessage("Could not read number of integer variables in line %d.\n", linecount);
672  SCIPABORT();
673  return SCIP_READERROR;
674  }
675 
676  if ( nintvars < 0 )
677  {
678  SCIPerrorMessage("Number of integrality constraints %d in line %d should be non-negative.\n", nintvars, linecount);
679  SCIPABORT();
680  return SCIP_READERROR; /*lint !e527*/
681  }
682 
683  for (i = 0; i < nintvars; i++)
684  {
685  SCIP_CALL( CBFfgets(pfile, linecount) );
686 
687  if ( sscanf(CBF_LINE_BUFFER, "%i", &v) != 1 )
688  {
689  SCIPerrorMessage("Could not read variable index in line %d.\n", linecount);
690  SCIPABORT();
691  return SCIP_READERROR; /*lint !e527*/
692  }
693 
694  SCIP_CALL( SCIPchgVarType(scip, data->createdvars[v], SCIP_VARTYPE_INTEGER, &infeasible) );
695 
696  if ( infeasible )
697  {
698  SCIPerrorMessage("Infeasibility detected because of integrality of variable %s!\n", SCIPvarGetName(data->createdvars[v]));
699  SCIPABORT();
700  return SCIP_READERROR; /*lint !e527*/
701  }
702  }
703 
704  return SCIP_OKAY;
705 }
706 
708 static
709 SCIP_RETCODE CBFreadPsdCon(
710  SCIP* scip,
711  SCIP_FILE* pfile,
712  SCIP_Longint* linecount,
713  CBF_DATA* data
714  )
715 {
716  int b;
717  int ncbfsdpblocks;
718 
719  assert( scip != NULL );
720  assert( pfile != NULL );
721  assert( linecount != NULL );
722  assert( data != NULL );
723 
724  SCIP_CALL( CBFfgets(pfile, linecount) );
725 
726  if ( sscanf(CBF_LINE_BUFFER, "%i", &ncbfsdpblocks) != 1 )
727  {
728  SCIPerrorMessage("Could not read number of psd constraints in line %d.\n", linecount);
729  SCIPABORT();
730  return SCIP_READERROR;
731  }
732 
733  if ( ncbfsdpblocks < 0 )
734  {
735  SCIPerrorMessage("Number of SDP-blocks %d in line %d should be non-negative!\n", ncbfsdpblocks, linecount);
736  SCIPABORT();
737  return SCIP_READERROR; /*lint !e527*/
738  }
739 
740  /* increase number of sdp blocks by number of psd variables that need to be transformed into a psd constraint
741  * with scalar variables */
742  if ( data->npsdvars > 0 )
743  data->nsdpblocks = ncbfsdpblocks + data->npsdvars;
744  else
745  data->nsdpblocks = ncbfsdpblocks;
746 
747  data->noorigsdpcons = FALSE;
748  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpblocksizes), data->nsdpblocks) );
749  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpblockrank1), data->nsdpblocks) );
750 
751  for (b = 0; b < ncbfsdpblocks; b++)
752  {
753  SCIP_CALL( CBFfgets(pfile, linecount) );
754  if ( sscanf(CBF_LINE_BUFFER, "%i", &(data->sdpblocksizes[b])) != 1 )
755  {
756  SCIPerrorMessage("Could not read size of psd constraint %d in line %d.\n", b, linecount);
757  SCIPABORT();
758  return SCIP_READERROR;
759  }
760 
761  if ( data->sdpblocksizes[b] <= 0 )
762  {
763  SCIPerrorMessage("Size %d of SDP-block %d in line %d should be positive!\n", data->sdpblocksizes[b], b, linecount);
764  SCIPABORT();
765  return SCIP_READERROR; /*lint !e527*/
766  }
767 
768  /* initialize rank-1 information to FALSE, will eventually be changed in PSDCONRANK1 */
769  data->sdpblockrank1[b] = FALSE;
770  }
771 
772  for (b = 0; b < data->npsdvars; b++)
773  {
774  /* read rank-1 information and size for psd variables (if existing, recall PSDVAR needs to be in front of
775  PSDCON) */
776  data->sdpblocksizes[ncbfsdpblocks + b] = data->psdvarsizes[b];
777  data->sdpblockrank1[ncbfsdpblocks + b] = data->psdvarrank1[b];
778  }
779 
780  return SCIP_OKAY;
781 }
782 
784 static
785 SCIP_RETCODE CBFreadPsdConRank1(
786  SCIP* scip,
787  SCIP_FILE* pfile,
788  SCIP_Longint* linecount,
789  CBF_DATA* data
790  )
791 {
792  int c;
793  int i;
794  int nrank1sdpblocks;
795 
796  assert( scip != NULL );
797  assert( pfile != NULL );
798  assert( linecount != NULL );
799  assert( data != NULL );
800 
801  /* PSDCON need to be in front of PSDCONRANK1! */
802  if ( data->nsdpblocks < 0 )
803  {
804  SCIPerrorMessage("Need to have 'PSDCON' section before 'PSDCONRANK1' section!\n");
805  SCIPABORT();
806  return SCIP_READERROR; /*lint !e527*/
807  }
808 
809  SCIP_CALL( CBFfgets(pfile, linecount) );
810 
811  if ( sscanf(CBF_LINE_BUFFER, "%i", &(nrank1sdpblocks)) != 1 )
812  {
813  SCIPerrorMessage("Could not read number of psd constraints with a rank-1 constraint in line %d.\n", linecount);
814  SCIPABORT();
815  return SCIP_READERROR;
816  }
817 
818  if ( nrank1sdpblocks < 0 )
819  {
820  SCIPerrorMessage("Number of psd constraints with a rank-1 constraint %d in line %d should be non-negative!\n", nrank1sdpblocks, linecount);
821  SCIPABORT();
822  return SCIP_READERROR; /*lint !e527*/
823  }
824 
825  assert( nrank1sdpblocks >= 0 );
826  assert( data->nsdpblocksrank1 >= 0 );
827 
828  data->nsdpblocksrank1 += nrank1sdpblocks;
829 
830  for (i = 0; i < nrank1sdpblocks; i++)
831  {
832  SCIP_CALL( CBFfgets(pfile, linecount) );
833  if ( sscanf(CBF_LINE_BUFFER, "%i", &c) != 1 )
834  {
835  SCIPerrorMessage("Could not read index of psd constraint with a rank-1 constraint in line %d.\n", linecount);
836  SCIPABORT();
837  return SCIP_READERROR;
838  }
839 
840  if ( c < 0 || c >= data->nsdpblocks )
841  {
842  SCIPerrorMessage("Given rank-1 constraint in line %d for sdp constraint %d which does not exist!\n", linecount, c);
843  SCIPABORT();
844  return SCIP_READERROR; /*lint !e527*/
845  }
846 
847  data->sdpblockrank1[c] = TRUE;
848  }
849 
850  return SCIP_OKAY;
851 }
852 
854 static
855 SCIP_RETCODE CBFreadObjFcoord(
856  SCIP* scip,
857  SCIP_FILE* pfile,
858  SCIP_Longint* linecount,
859  CBF_DATA* data
860  )
861 { /*lint --e{818}*/
862  SCIP_Real val;
863  int nobjcoefs;
864  int nzerocoef = 0;
865  int i;
866  int v;
867  int row;
868  int col;
869 
870  assert( scip != NULL );
871  assert( pfile != NULL );
872  assert( linecount != NULL );
873  assert( data != NULL );
874 
875  if ( data->createdpsdvars == NULL )
876  {
877  SCIPerrorMessage("Need to have 'PSDVAR' section before 'OBJFCOORD' section!\n");
878  SCIPABORT();
879  return SCIP_READERROR; /*lint !e527*/
880  }
881  assert( data->npsdvars >= 0 );
882 
883  SCIP_CALL( CBFfgets(pfile, linecount) );
884 
885  if ( sscanf(CBF_LINE_BUFFER, "%i", &nobjcoefs) != 1 )
886  {
887  SCIPerrorMessage("Could not read number of objective coefficients for matrix variables in line %d.\n", linecount);
888  SCIPABORT();
889  return SCIP_READERROR;
890  }
891 
892  if ( nobjcoefs < 0 )
893  {
894  SCIPerrorMessage("Number of objective coefficients for matrix variables %d in line %d should be non-negative!\n", nobjcoefs, linecount);
895  SCIPABORT();
896  return SCIP_READERROR; /*lint !e527*/
897  }
898 
899  for (i = 0; i < nobjcoefs; i++)
900  {
901  SCIP_CALL( CBFfgets(pfile, linecount) );
902 
903  if ( sscanf(CBF_LINE_BUFFER, "%i %i %i %lf", &v, &row, &col, &val) != 4 )
904  {
905  SCIPerrorMessage("Could not read entry of OBJFCOORD in line %d.\n", linecount);
906  SCIPABORT();
907  return SCIP_READERROR;
908  }
909 
910  if ( v < 0 || v >= data->npsdvars )
911  {
912  SCIPerrorMessage("Given objective coefficient in line %d for matrix variable %d which does not exist!\n", linecount, v);
913  SCIPABORT();
914  return SCIP_READERROR; /*lint !e527*/
915  }
916 
917  if ( row < 0 || row >= data->psdvarsizes[v] )
918  {
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]);
921  SCIPABORT();
922  return SCIP_READERROR; /*lint !e527*/
923  }
924 
925  if ( col < 0 || col >= data->psdvarsizes[v] )
926  {
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]);
929  SCIPABORT();
930  return SCIP_READERROR; /*lint !e527*/
931  }
932 
933  if ( SCIPisZero(scip, val) )
934  {
935  ++nzerocoef;
936  }
937  else
938  {
939  /* make sure matrix is in lower triangular form */
940  if ( row < col )
941  {
942  SCIP_CALL( SCIPchgVarObj(scip, data->createdpsdvars[v][col][row], 2*val) );
943  }
944  else if ( row == col )
945  {
946  SCIP_CALL( SCIPchgVarObj(scip, data->createdpsdvars[v][col][row], val) );
947  }
948  else
949  {
950  SCIP_CALL( SCIPchgVarObj(scip, data->createdpsdvars[v][row][col], 2*val) );
951  }
952  }
953  }
954 
955  if ( nzerocoef > 0 )
956  {
957  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
958  "OBJFCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
959  }
960 
961  return SCIP_OKAY;
962 }
963 
965 static
966 SCIP_RETCODE CBFreadObjAcoord(
967  SCIP* scip,
968  SCIP_FILE* pfile,
969  SCIP_Longint* linecount,
970  CBF_DATA* data
971  )
972 { /*lint --e{818}*/
973  SCIP_Real val;
974  int nobjcoefs;
975  int nzerocoef = 0;
976  int i;
977  int v;
978 
979  assert( scip != NULL );
980  assert( pfile != NULL );
981  assert( linecount != NULL );
982  assert( data != NULL );
983 
984  if ( data->createdvars == NULL )
985  {
986  SCIPerrorMessage("Need to have 'VAR' section before 'OBJACOORD' section!\n");
987  SCIPABORT();
988  return SCIP_READERROR; /*lint !e527*/
989  }
990  assert( data->nvars >= 0 );
991 
992  SCIP_CALL( CBFfgets(pfile, linecount) );
993 
994  if ( sscanf(CBF_LINE_BUFFER, "%i", &nobjcoefs) != 1 )
995  {
996  SCIPerrorMessage("Could not read number of objective coefficients for scalar variables in line %d.\n", linecount);
997  SCIPABORT();
998  return SCIP_READERROR;
999  }
1000 
1001  if ( nobjcoefs < 0 )
1002  {
1003  SCIPerrorMessage("Number of objective coefficients for scalar variables %d in line %d should be non-negative!\n", nobjcoefs, linecount);
1004  SCIPABORT();
1005  return SCIP_READERROR; /*lint !e527*/
1006  }
1007 
1008  for (i = 0; i < nobjcoefs; i++)
1009  {
1010  SCIP_CALL( CBFfgets(pfile, linecount) );
1011  if ( sscanf(CBF_LINE_BUFFER, "%i %lf", &v, &val) != 2 )
1012  {
1013  SCIPerrorMessage("Could not read entry of OBJACOORD in line %d.\n", linecount);
1014  SCIPABORT();
1015  return SCIP_READERROR;
1016  }
1017 
1018  if ( v < 0 || v >= data->nvars )
1019  {
1020  SCIPerrorMessage("Given objective coefficient in line %d for scalar variable %d which does not exist!\n", linecount, v);
1021  SCIPABORT();
1022  return SCIP_READERROR; /*lint !e527*/
1023  }
1024 
1025  if ( SCIPisZero(scip, val) )
1026  {
1027  ++nzerocoef;
1028  }
1029  else
1030  {
1031  SCIP_CALL( SCIPchgVarObj(scip, data->createdvars[v], val) );
1032  }
1033  }
1034 
1035  if ( nzerocoef > 0 )
1036  {
1037  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
1038  "OBJACOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
1039  }
1040 
1041  return SCIP_OKAY;
1042 }
1043 
1045 static
1046 SCIP_RETCODE CBFreadFcoord(
1047  SCIP* scip,
1048  SCIP_FILE* pfile,
1049  SCIP_Longint* linecount,
1050  CBF_DATA* data
1051  )
1052 { /*lint --e{818}*/
1053  SCIP_Real val;
1054  int nzerocoef = 0;
1055  int ncoefs;
1056  int c;
1057  int i;
1058  int v;
1059  int row;
1060  int col;
1061 
1062  assert( scip != NULL );
1063  assert( pfile != NULL );
1064  assert( linecount != NULL );
1065  assert( data != NULL );
1066 
1067  if ( data->createdpsdvars == NULL )
1068  {
1069  SCIPerrorMessage("Need to have 'PSDVAR' section before 'FCOORD' section!\n");
1070  SCIPABORT();
1071  return SCIP_READERROR; /*lint !e527*/
1072  }
1073  assert( data->npsdvars >= 0 );
1074 
1075  if ( data->createdconss == NULL )
1076  {
1077  SCIPerrorMessage("Need to have 'CON' section before 'FCOORD' section!\n");
1078  SCIPABORT();
1079  return SCIP_READERROR; /*lint !e527*/
1080  }
1081  assert( data->nconss >= 0 );
1082 
1083  SCIP_CALL( CBFfgets(pfile, linecount) );
1084 
1085  if ( sscanf(CBF_LINE_BUFFER, "%i", &ncoefs) != 1 )
1086  {
1087  SCIPerrorMessage("Could not read number of coefficients for psd variables in line %d.\n", linecount);
1088  SCIPABORT();
1089  return SCIP_READERROR;
1090  }
1091 
1092  if ( ncoefs < 0 )
1093  {
1094  SCIPerrorMessage("Number of matrix variable coefficients %d in line %d should be non-negative!\n", ncoefs, linecount);
1095  SCIPABORT();
1096  return SCIP_READERROR; /*lint !e527*/
1097  }
1098 
1099  for (i = 0; i < ncoefs; i++)
1100  {
1101  SCIP_CALL( CBFfgets(pfile, linecount) );
1102 
1103  if ( sscanf(CBF_LINE_BUFFER, "%i %i %i %i %lf", &c, &v, &row, &col, &val) != 5 )
1104  {
1105  SCIPerrorMessage("Could not read entry of FCOORD in line %d.\n", linecount);
1106  SCIPABORT();
1107  return SCIP_READERROR;
1108  }
1109 
1110  if ( c < 0 || c >= data->nconss )
1111  {
1112  SCIPerrorMessage("Given matrix variable coefficient in line %d for constraint %d which does not exist!\n", linecount, c);
1113  SCIPABORT();
1114  return SCIP_READERROR; /*lint !e527*/
1115  }
1116 
1117  if ( v < 0 || v >= data->npsdvars )
1118  {
1119  SCIPerrorMessage("Given coefficient in line %d for matrix variable %d which does not exist!\n", linecount, v);
1120  SCIPABORT();
1121  return SCIP_READERROR; /*lint !e527*/
1122  }
1123 
1124  if ( row < 0 || row >= data->psdvarsizes[v] )
1125  {
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]);
1128  SCIPABORT();
1129  return SCIP_READERROR; /*lint !e527*/
1130  }
1131 
1132  if ( col < 0 || col >= data->psdvarsizes[v] )
1133  {
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]);
1136  SCIPABORT();
1137  return SCIP_READERROR; /*lint !e527*/
1138  }
1139 
1140  if ( SCIPisZero(scip, val) )
1141  {
1142  ++nzerocoef;
1143  }
1144  else
1145  {
1146  /* make sure matrix is in lower triangular form */
1147  if ( row < col )
1148  {
1149  SCIP_CALL( SCIPaddCoefLinear(scip, data->createdconss[c], data->createdpsdvars[v][col][row], 2*val) );/*lint !e732*//*lint !e747*/
1150  }
1151  else if ( row == col )
1152  SCIP_CALL( SCIPaddCoefLinear(scip, data->createdconss[c], data->createdpsdvars[v][row][col], val) );/*lint !e732*//*lint !e747*/
1153  else
1154  {
1155  SCIP_CALL( SCIPaddCoefLinear(scip, data->createdconss[c], data->createdpsdvars[v][row][col], 2*val) );/*lint !e732*//*lint !e747*/
1156  }
1157  }
1158  }
1159 
1160  if ( nzerocoef > 0 )
1161  {
1162  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
1163  "FCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
1164  }
1165 
1166  return SCIP_OKAY;
1167 }
1168 
1170 static
1171 SCIP_RETCODE CBFreadAcoord(
1172  SCIP* scip,
1173  SCIP_FILE* pfile,
1174  SCIP_Longint* linecount,
1175  CBF_DATA* data
1176  )
1177 { /*lint --e{818}*/
1178  SCIP_Real val;
1179  int nzerocoef = 0;
1180  int ncoefs;
1181  int c;
1182  int i;
1183  int v;
1184 
1185  assert( scip != NULL );
1186  assert( pfile != NULL );
1187  assert( linecount != NULL );
1188  assert( data != NULL );
1189 
1190  if ( data->createdvars == NULL )
1191  {
1192  SCIPerrorMessage("Need to have 'VAR' section before 'ACOORD' section!\n");
1193  SCIPABORT();
1194  return SCIP_READERROR; /*lint !e527*/
1195  }
1196  assert( data->nvars >= 0 );
1197 
1198  if ( data->createdconss == NULL )
1199  {
1200  SCIPerrorMessage("Need to have 'CON' section before 'ACOORD' section!\n");
1201  SCIPABORT();
1202  return SCIP_READERROR; /*lint !e527*/
1203  }
1204  assert( data->nconss >= 0 );
1205 
1206  SCIP_CALL( CBFfgets(pfile, linecount) );
1207 
1208  if ( sscanf(CBF_LINE_BUFFER, "%i", &ncoefs) != 1 )
1209  {
1210  SCIPerrorMessage("Could not read number of linear coefficients in line %d.\n", linecount);
1211  SCIPABORT();
1212  return SCIP_READERROR;
1213  }
1214 
1215  if ( ncoefs < 0 )
1216  {
1217  SCIPerrorMessage("Number of linear coefficients %d in line %d should be non-negative!\n", ncoefs, linecount);
1218  SCIPABORT();
1219  return SCIP_READERROR; /*lint !e527*/
1220  }
1221 
1222  for (i = 0; i < ncoefs; i++)
1223  {
1224  SCIP_CALL( CBFfgets(pfile, linecount) );
1225  if ( sscanf(CBF_LINE_BUFFER, "%i %i %lf", &c, &v, &val) != 3 )
1226  {
1227  SCIPerrorMessage("Could not read entry of ACOORD in line %d.\n", linecount);
1228  SCIPABORT();
1229  return SCIP_READERROR;
1230  }
1231 
1232  if ( c < 0 || c >= data->nconss )
1233  {
1234  SCIPerrorMessage("Given linear coefficient in line %d for constraint %d which does not exist!\n", linecount, c);
1235  SCIPABORT();
1236  return SCIP_READERROR; /*lint !e527*/
1237  }
1238 
1239  if ( v < 0 || v >= data->nvars )
1240  {
1241  SCIPerrorMessage("Given linear coefficient in line %d for variable %d which does not exist!\n", linecount, v);
1242  SCIPABORT();
1243  return SCIP_READERROR; /*lint !e527*/
1244  }
1245 
1246  if ( SCIPisZero(scip, val) )
1247  {
1248  ++nzerocoef;
1249  }
1250  else
1251  {
1252  SCIP_CALL( SCIPaddCoefLinear(scip, data->createdconss[c], data->createdvars[v], val) );/*lint !e732*//*lint !e747*/
1253  }
1254  }
1255 
1256  if ( nzerocoef > 0 )
1257  {
1258  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
1259  "ACOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
1260  }
1261 
1262  return SCIP_OKAY;
1263 }
1264 
1266 static
1267 SCIP_RETCODE CBFreadBcoord(
1268  SCIP* scip,
1269  SCIP_FILE* pfile,
1270  SCIP_Longint* linecount,
1271  CBF_DATA* data
1272  )
1273 { /*lint --e{818}*/
1274  SCIP_Real val;
1275  int nzerocoef = 0;
1276  int nsides;
1277  int c;
1278  int i;
1279 
1280  assert( scip != NULL );
1281  assert( pfile != NULL );
1282  assert( linecount != NULL );
1283  assert( data != NULL );
1284 
1285  if ( data->createdconss == NULL )
1286  {
1287  SCIPerrorMessage("Need to have 'CON' section before 'BCOORD' section!\n");
1288  SCIPABORT();
1289  return SCIP_READERROR; /*lint !e527*/
1290  }
1291  assert( data->nconss >= 0 );
1292 
1293  SCIP_CALL( CBFfgets(pfile, linecount) );
1294 
1295  if ( sscanf(CBF_LINE_BUFFER, "%i", &nsides) != 1 )
1296  {
1297  SCIPerrorMessage("Could not read number of constant parts in scalar constraints in line %d.\n", linecount);
1298  SCIPABORT();
1299  return SCIP_READERROR;
1300  }
1301 
1302  if ( nsides < 0 )
1303  {
1304  SCIPerrorMessage("Number of constant parts %d in line %d should be non-negative!\n", nsides, linecount);
1305  SCIPABORT();
1306  return SCIP_READERROR; /*lint !e527*/
1307  }
1308 
1309  for (i = 0; i < nsides; i++)
1310  {
1311  SCIP_CALL( CBFfgets(pfile, linecount) );
1312 
1313  if ( sscanf(CBF_LINE_BUFFER, "%i %lf", &c, &val) != 2 )
1314  {
1315  SCIPerrorMessage("Could not read entry of BCOORD in line %d.\n", linecount);
1316  SCIPABORT();
1317  return SCIP_READERROR;
1318  }
1319 
1320  if ( c < 0 || c >= data->nconss )
1321  {
1322  SCIPerrorMessage("Given constant part in line %d for scalar constraint %d which does not exist!\n", linecount, c);
1323  SCIPABORT();
1324  return SCIP_READERROR; /*lint !e527*/
1325  }
1326 
1327  if ( SCIPisZero(scip, val) )
1328  {
1329  ++nzerocoef;
1330  }
1331  else
1332  {
1333  /* check type */
1334  if ( ! SCIPisInfinity(scip, -SCIPgetLhsLinear(scip, data->createdconss[c])) )
1335  {
1336  /* greater or equal constraint -> left-hand side (minus since we have Ax + b >= 0) */
1337  SCIP_CALL( SCIPchgLhsLinear(scip, data->createdconss[c], -val) );
1338  }
1339 
1340  if ( ! SCIPisInfinity(scip, SCIPgetRhsLinear(scip, data->createdconss[c]) ) )
1341  {
1342  /* less or equal constraint -> right-hand side (minus since we have Ax + b <= 0) */
1343  SCIP_CALL( SCIPchgRhsLinear(scip, data->createdconss[c], -val) );
1344  }
1345  }
1346  }
1347 
1348  if ( nzerocoef > 0 )
1349  {
1350  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
1351  "BCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
1352  }
1353 
1354  return SCIP_OKAY;
1355 }
1356 
1358 static
1359 SCIP_RETCODE CBFreadHcoord(
1360  SCIP* scip,
1361  SCIP_FILE* pfile,
1362  SCIP_Longint* linecount,
1363  CBF_DATA* data
1364  )
1365 {
1366  SCIP_Real val;
1367  int** sdpvar;
1368  int nnonz;
1369  int i;
1370  int b;
1371  int v;
1372  int row;
1373  int col;
1374  int firstindforvar;
1375  int nextindaftervar;
1376  int nzerocoef = 0;
1377  int ncbfsdpblocks;
1378  int nauxnonz = 0; /* number of nonzeros in each auxiliary sdp block for reformulating matrix variables using
1379  * scalar variables */
1380 
1381  assert( scip != NULL );
1382  assert( pfile != NULL );
1383  assert( linecount != NULL );
1384  assert( data != NULL );
1385 
1386  if ( data->nsdpblocks < 0 )
1387  {
1388  SCIPerrorMessage("Need to have 'PSDCON' section before 'HCOORD' section!\n");
1389  SCIPABORT();
1390  return SCIP_READERROR; /*lint !e527*/
1391  }
1392  assert( data->nvars >= 0 );
1393 
1394  if ( data->nvars < 0 )
1395  {
1396  SCIPerrorMessage("Need to have 'VAR' section before 'HCOORD' section!\n");
1397  SCIPABORT();
1398  return SCIP_READERROR; /*lint !e527*/
1399  }
1400 
1401  /* get number of sdp blocks specified by PSDCON (without auxiliary sdp blocks for reformulating matrix variables
1402  * using scalar variables), save number of nonzeros needed for the auxiliary sdp blocks in nauxnonz */
1403  if ( data->npsdvars > 0 )
1404  {
1405  ncbfsdpblocks = data->nsdpblocks - data->npsdvars;
1406  for (i = 0; i < data->npsdvars; i++)
1407  nauxnonz += data->psdvarsizes[i] * (data->psdvarsizes[i] + 1) / 2;
1408  }
1409  else
1410  {
1411  ncbfsdpblocks = data->nsdpblocks;
1412  nauxnonz = 0;
1413  }
1414 
1415  /* initialize sdpnblocknonz with 0 */
1416  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpnblocknonz), data->nsdpblocks) );
1417  for (b = 0; b < data->nsdpblocks; b++)
1418  data->sdpnblocknonz[b] = 0;
1419 
1420  SCIP_CALL( CBFfgets(pfile, linecount) );
1421 
1422  if ( sscanf(CBF_LINE_BUFFER, "%i", &nnonz) != 1 )
1423  {
1424  SCIPerrorMessage("Could not read number of nonzero coefficients of SDP-constraints in line %d.\n", linecount);
1425  SCIPABORT();
1426  return SCIP_READERROR;
1427  }
1428 
1429  data->nnonz = nnonz + nauxnonz;
1430  if ( nnonz < 0 )
1431  {
1432  SCIPerrorMessage("Number of nonzero coefficients of SDP-constraints %d in line %d should be non-negative!\n", nnonz, linecount);
1433  SCIPABORT();
1434  return SCIP_READERROR; /*lint !e527*/
1435  }
1436 
1437  /* allocate memory (nnonz for each block, since we do not yet know the distribution) */
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) );
1442 
1443  for (b = 0; b < data->nsdpblocks; b++)
1444  {
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) );
1449  }
1450 
1451  for (i = 0; i < nnonz; i++)
1452  {
1453  SCIP_CALL( CBFfgets(pfile, linecount) );
1454 
1455  if ( sscanf(CBF_LINE_BUFFER, "%i %i %i %i %lf", &b, &v, &row, &col, &val) != 5 )
1456  {
1457  SCIPerrorMessage("Could not read entry of HCOORD in line %d.\n", linecount);
1458  SCIPABORT();
1459  return SCIP_READERROR;
1460  }
1461 
1462  if ( b < 0 || b >= ncbfsdpblocks )
1463  {
1464  SCIPerrorMessage("Given SDP-coefficient in line %d for SDP-constraint %d which does not exist!\n", linecount, b);
1465  SCIPABORT();
1466  return SCIP_READERROR; /*lint !e527*/
1467  }
1468 
1469  if ( v < 0 || v >= data->nvars )
1470  {
1471  SCIPerrorMessage("Given SDP-coefficient in line %d for variable %d which does not exist!\n", linecount, v);
1472  SCIPABORT();
1473  return SCIP_READERROR; /*lint !e527*/
1474  }
1475 
1476  if ( row < 0 || row >= data->sdpblocksizes[b] )
1477  {
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]);
1480  SCIPABORT();
1481  return SCIP_READERROR; /*lint !e527*/
1482  }
1483 
1484  if ( col < 0 || col >= data->sdpblocksizes[b] )
1485  {
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]);
1488  SCIPABORT();
1489  return SCIP_READERROR; /*lint !e527*/
1490  }
1491 
1492  if ( SCIPisZero(scip, val) )
1493  {
1494  ++nzerocoef;
1495  }
1496  else
1497  {
1498  sdpvar[b][data->sdpnblocknonz[b]] = v;
1499 
1500  /* make sure matrix is in lower triangular form */
1501  if ( col > row )
1502  {
1503  data->sdprow[b][data->sdpnblocknonz[b]] = col;
1504  data->sdpcol[b][data->sdpnblocknonz[b]] = row;
1505  }
1506  else
1507  {
1508  data->sdprow[b][data->sdpnblocknonz[b]] = row;
1509  data->sdpcol[b][data->sdpnblocknonz[b]] = col;
1510  }
1511 
1512  data->sdpval[b][data->sdpnblocknonz[b]] = val;
1513  data->sdpnblocknonz[b]++;
1514  }
1515  }
1516 
1517  /* construct entries for auxiliary sdp blocks (reformulation of psdvars) */
1518  if ( data->npsdvars > 0 )
1519  {
1520  val = 1.0;
1521  for (v = 0; v < data->npsdvars; v++)
1522  {
1523  b = ncbfsdpblocks + v;
1524  for (row = 0; row < data->psdvarsizes[v]; row++)
1525  {
1526  for (col = 0; col <= row; col++)
1527  {
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]++;
1533  }
1534  }
1535  assert( data->sdpnblocknonz[b] == data->psdvarsizes[v] * (data->psdvarsizes[v] + 1) / 2 );
1536  assert( b == data->nsdpblocks - 1 );
1537  }
1538  }
1539 
1540  /* construct pointer arrays */
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) );
1547 
1548  /* sdp blocks as specified in cbf file in HCOORD */
1549  for (b = 0; b < ncbfsdpblocks; b++)
1550  {
1551  /* sort the nonzeroes by non-decreasing variable indices */
1552  SCIPsortIntIntIntReal(sdpvar[b], data->sdprow[b], data->sdpcol[b], data->sdpval[b], data->sdpnblocknonz[b]);
1553 
1554  /* create the pointer arrays and insert used variables into vars-array */
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) );
1562 
1563  for (v = 0; v < data->nvars; v++)
1564  {
1565  SCIP_Bool varused = FALSE;
1566 
1567  firstindforvar = nextindaftervar; /* this variable starts where the last one ended */
1568  data->nvarnonz[b][data->sdpnblockvars[b]] = 0;
1569 
1570  while (nextindaftervar < data->sdpnblocknonz[b] && sdpvar[b][nextindaftervar] == v) /* get the first index that doesn't belong to this variable */
1571  {
1572  nextindaftervar++;
1573  varused = TRUE;
1574  data->nvarnonz[b][data->sdpnblockvars[b]]++;
1575  }
1576 
1577  if ( varused )
1578  {
1579  data->sdpblockvars[b][data->sdpnblockvars[b]] = data->createdvars[v];/*lint !e732*//*lint !e747*/ /* if the variable is used, add it to the vars array */
1580  data->rowpointer[b][data->sdpnblockvars[b]] = &(data->sdprow[b][firstindforvar]); /* save a pointer to the first nonzero belonging to this variable */
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]++;
1584  }
1585  }
1586 
1587  assert( nextindaftervar == data->sdpnblocknonz[b] );
1588  }
1589 
1590  /* auxiliary sdp blocks (reformulation of psd variables) */
1591  if ( data->npsdvars > 0 )
1592  {
1593  assert( data->nsdpblocks == ncbfsdpblocks + data->npsdvars );
1594  for (v = 0; v < data->npsdvars; v++)
1595  {
1596  int varidx = 0;
1597 
1598  /* create the pointer arrays and insert used variables into vars-array */
1599  b = ncbfsdpblocks + v;
1600 
1601  data->sdpnblockvars[b] = data->sdpnblocknonz[b];
1602 
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]) );
1608 
1609  for (row = 0; row < data->psdvarsizes[v]; row++)
1610  {
1611  for (col = 0; col <= row; col++)
1612  {
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]);
1618  varidx++;
1619  }
1620  }
1621  assert( varidx == data->sdpnblocknonz[b] );
1622  }
1623  }
1624 
1625  /* free SDP-var array which is no longer needed */
1626  for (b = 0; b < data->nsdpblocks; b++)
1627  SCIPfreeBlockMemoryArray(scip, &(sdpvar[b]), data->nnonz);
1628 
1629  SCIPfreeBlockMemoryArray(scip, &sdpvar, data->nsdpblocks);
1630 
1631  if ( nzerocoef > 0 )
1632  {
1633  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
1634  "HCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
1635  }
1636 
1637  return SCIP_OKAY;
1638 }
1640 static
1641 SCIP_RETCODE CBFreadDcoord(
1642  SCIP* scip,
1643  SCIP_FILE* pfile,
1644  SCIP_Longint* linecount,
1645  CBF_DATA* data
1646  )
1647 {
1648  SCIP_Real val;
1649  int nzerocoef = 0;
1650  int constnnonz;
1651  int b;
1652  int i;
1653  int row;
1654  int col;
1655 
1656  assert( scip != NULL );
1657  assert( pfile != NULL );
1658  assert( linecount != NULL );
1659  assert( data != NULL );
1660 
1661  if ( data->nsdpblocks < 0 )
1662  {
1663  SCIPerrorMessage("Need to have 'PSDCON' section before 'DCOORD' section!\n");
1664  SCIPABORT();
1665  return SCIP_READERROR; /*lint !e527*/
1666  }
1667 
1668  if ( data->nvars < 0 )
1669  {
1670  SCIPerrorMessage("Need to have 'VAR' section before 'DCOORD' section!\n");
1671  SCIPABORT();
1672  return SCIP_READERROR; /*lint !e527*/
1673  }
1674 
1675  SCIP_CALL( CBFfgets(pfile, linecount) );
1676 
1677  if ( sscanf(CBF_LINE_BUFFER, "%i", &constnnonz) != 1 )
1678  {
1679  SCIPerrorMessage("Could not read number of constant entries of SDP-constraints in line %d.\n", linecount);
1680  SCIPABORT();
1681  return SCIP_READERROR;
1682  }
1683 
1684  if ( constnnonz < 0 )
1685  {
1686  SCIPerrorMessage("Number of constant entries of SDP-constraints %d in line %d should be non-negative!\n", constnnonz, linecount);
1687  SCIPABORT();
1688  return SCIP_READERROR; /*lint !e527*/
1689  }
1690 
1691  data->constnnonz = constnnonz;
1692  if ( constnnonz > 0 )
1693  {
1694  /* initialize sdpconstnblocknonz with 0 */
1695  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(data->sdpconstnblocknonz), data->nsdpblocks) );
1696  for (b = 0; b < data->nsdpblocks; b++)
1697  data->sdpconstnblocknonz[b] = 0;
1698 
1699  /* allocate memory (constnnonz for each block, since we do not yet know the distribution) */
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) );
1703 
1704  for (b = 0; b < data->nsdpblocks; b++)
1705  {
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) );
1709  }
1710 
1711  for (i = 0; i < constnnonz; i++)
1712  {
1713  SCIP_CALL( CBFfgets(pfile, linecount) );
1714  if ( sscanf(CBF_LINE_BUFFER, "%i %i %i %lf", &b, &row, &col, &val) != 4 )
1715  {
1716  SCIPerrorMessage("Could not read entry of DCOORD in line %d.\n", linecount);
1717  SCIPABORT();
1718  return SCIP_READERROR;
1719  }
1720 
1721  if ( b < 0 || b >= data->nsdpblocks )
1722  {
1723  SCIPerrorMessage("Given constant entry in line %d for SDP-constraint %d which does not exist!\n", linecount, b);
1724  SCIPABORT();
1725  return SCIP_READERROR; /*lint !e527*/
1726  }
1727 
1728  if ( row < 0 || row >= data->sdpblocksizes[b] )
1729  {
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]);
1732  SCIPABORT();
1733  return SCIP_READERROR; /*lint !e527*/
1734  }
1735 
1736  if ( col < 0 || col >= data->sdpblocksizes[b] )
1737  {
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]);
1740  SCIPABORT();
1741  return SCIP_READERROR; /*lint !e527*/
1742  }
1743 
1744  if ( SCIPisZero(scip, val) )
1745  {
1746  ++nzerocoef;
1747  }
1748  else
1749  {
1750  /* make sure matrix is in lower triangular form */
1751  if ( col > row )
1752  {
1753  data->sdpconstrow[b][data->sdpconstnblocknonz[b]] = col;
1754  data->sdpconstcol[b][data->sdpconstnblocknonz[b]] = row;
1755  }
1756  else
1757  {
1758  data->sdpconstrow[b][data->sdpconstnblocknonz[b]] = row;
1759  data->sdpconstcol[b][data->sdpconstnblocknonz[b]] = col;
1760  }
1761  data->sdpconstval[b][data->sdpconstnblocknonz[b]] = -val;
1762  data->sdpconstnblocknonz[b]++;
1763  }
1764  }
1765  }
1766 
1767  if ( nzerocoef > 0 )
1768  {
1769  SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
1770  "DCOORD: Found %d coefficients with absolute value less than epsilon = %g.\n", nzerocoef, SCIPepsilon(scip));
1771  }
1772 
1773  return SCIP_OKAY;
1774 }
1775 
1777 static
1778 SCIP_RETCODE CBFfreeData(
1779  SCIP* scip,
1780  CBF_DATA* data
1781  )
1782 {
1783  SCIP_Bool allocated = FALSE;
1784  int b = 0;
1785  int i;
1786  int t;
1787  int ncbfsdpblocks;
1788 
1789  assert( scip != NULL );
1790  assert( data != NULL );
1791 
1792  /* we only allocated memory for the const blocks if there were any nonzeros */
1793  /* TODO: could also think about saving this in the struct instead, which would cost one bool and save some (unimportant) time here */
1794  while ( data->sdpconstnblocknonz != NULL && allocated == FALSE && b < data->nsdpblocks)
1795  {
1796  if (data->sdpconstnblocknonz[b] > 0)
1797  allocated = TRUE;
1798  b++;
1799  }
1800 
1801  if ( allocated )
1802  {
1803  for (b = 0; b < data->nsdpblocks; b++)
1804  {
1805  SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpconstval[b]), data->constnnonz);
1806  SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpconstcol[b]), data->constnnonz);
1807  SCIPfreeBlockMemoryArrayNull(scip, &(data->sdpconstrow[b]), data->constnnonz);
1808  }
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);
1813  }
1814 
1815  /* we only allocated memory for the sdpblocks if there were any nonzeros */
1816  b = 0;
1817  while (allocated == FALSE && b < data->nsdpblocks)
1818  {
1819  if (data->sdpnblocknonz[b] > 0)
1820  allocated = TRUE;
1821  b++;
1822  }
1823 
1824  if ( allocated )
1825  {
1826  /* get number of sdp blocks specified by PSDCON (without auxiliary sdp blocks for reformulating matrix variables
1827  * using scalar variables), save number of nonzeros needed for the auxiliary sdp blocks in nauxnonz */
1828  if ( data->npsdvars > 0 )
1829  ncbfsdpblocks = data->nsdpblocks - data->npsdvars;
1830  else
1831  ncbfsdpblocks = data->nsdpblocks;
1832 
1833  if ( data->noorigsdpcons )
1834  {
1835  /* no SDP constraints specified in the CBF file! */
1836  assert( ncbfsdpblocks == 0 );
1837 
1838  for (b = 0; b < data->nsdpblocks; b++)
1839  {
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]);
1848  }
1849 
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);
1862  }
1863  else
1864  {
1865  /* some SDP constraints specified in the CBF file! */
1866  assert( ncbfsdpblocks > 0 );
1867 
1868  for (b = 0; b < ncbfsdpblocks; b++)
1869  {
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);
1878  }
1879 
1880  if ( data->npsdvars > 0 )
1881  {
1882  for (b = ncbfsdpblocks; b < data->nsdpblocks; b++)
1883  {
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]);
1892  }
1893  }
1894 
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);
1907  }
1908  }
1909 
1910  if (data->nconss > 0)
1911  {
1912  SCIPfreeBlockMemoryArrayNull(scip, &data->createdconss, data->nconss);
1913  }
1914 
1915  if (data->nvars > 0)
1916  SCIPfreeBlockMemoryArrayNull(scip, &data->createdvars, data->nvars);
1917 
1918  if ( data-> npsdvars > 0 )
1919  {
1920  for (t = 0; t < data->npsdvars; t++)
1921  {
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]);
1925  }
1926 
1927  SCIPfreeBlockMemoryArrayNull(scip, &(data->psdvarrank1), data->npsdvars);
1928  SCIPfreeBlockMemoryArrayNull(scip, &(data->psdvarsizes), data->npsdvars);
1929  SCIPfreeBlockMemoryArrayNull(scip, &(data->createdpsdvars), data->npsdvars);
1930  }
1931 
1932  return SCIP_OKAY;
1933 }
1934 
1935 
1936 /*
1937  * Callback methods of reader
1938  */
1939 
1940 
1942 static
1943 SCIP_DECL_READERCOPY(readerCopyCbf)
1944 { /*lint --e{715,818}*/
1945  assert(scip != NULL);
1946 
1947  SCIP_CALL( SCIPincludeReaderCbf(scip) );
1948 
1949  return SCIP_OKAY;
1950 }
1951 
1953 static
1954 SCIP_DECL_READERREAD(readerReadCbf)
1955 { /*lint --e{715,818}*/
1956  SCIP_FILE* scipfile;
1957  SCIP_Longint linecount = 0;
1958  SCIP_Bool versionread = FALSE;
1959  SCIP_Bool objread = FALSE;
1960  CBF_DATA* data;
1961  int b;
1962 
1963  assert( result != NULL );
1964 
1965  *result = SCIP_DIDNOTRUN;
1966 
1967  SCIPdebugMsg(scip, "Reading file %s ...\n", filename);
1968 
1969  scipfile = SCIPfopen(filename, "r");
1970 
1971  if ( ! scipfile )
1972  return SCIP_READERROR;
1973 
1974  SCIP_CALL( SCIPallocBuffer(scip, &data) );
1975  data->nsdpblocks = -1;
1976  data->nsdpblocksrank1 = 0;
1977  data->nconss = -1;
1978  data->nvars = -1;
1979  data->npsdvars = -1;
1980  data->constnnonz = 0;
1981  data->nnonz = 0;
1982  data->noorigsdpcons= FALSE;
1983 
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;
1998 
1999  /* create empty problem */
2000  SCIP_CALL( SCIPcreateProb(scip, filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
2001 
2002  while( CBFfgets(scipfile, &linecount) == SCIP_OKAY )
2003  {
2004  /* Parse keyword on non-empty lines */
2005  if ( sscanf(CBF_LINE_BUFFER, CBF_NAME_FORMAT, CBF_NAME_BUFFER) == 1 )
2006  {
2007  /* first line should be version number */
2008  if ( ! versionread )
2009  {
2010  if ( strcmp(CBF_NAME_BUFFER, "VER") == 0 )
2011  {
2012  int ver;
2013 
2014  SCIP_CALL( CBFfgets(scipfile, &linecount) );
2015 
2016  if ( sscanf(CBF_LINE_BUFFER, "%i", &ver) == 1 )
2017  {
2018  SCIPdebugMsg(scip, "file version %d.\n", ver);
2019  if ( ver < 1 )
2020  {
2021  SCIPerrorMessage("Strange version number %d; need at least version 1.\n", ver);
2022  SCIPABORT();
2023  return SCIP_READERROR; /*lint !e527*/
2024  }
2025  else if ( ver > CBF_VERSION_NR )
2026  {
2027  SCIPerrorMessage("Version %d too new; only supported up to version %d.\n", CBF_VERSION_NR);
2028  SCIPABORT();
2029  return SCIP_READERROR; /*lint !e527*/
2030  }
2031  else
2032  versionread = TRUE;
2033  }
2034  else
2035  return SCIP_READERROR;
2036  }
2037  else
2038  {
2039  SCIPerrorMessage("First keyword should be VER.\n");
2040  SCIPABORT();
2041  return SCIP_READERROR; /*lint !e527*/
2042  }
2043  }
2044  else
2045  {
2046  if ( strcmp(CBF_NAME_BUFFER, "OBJSENSE") == 0 )
2047  {
2048  SCIPdebugMsg(scip, "Reading OBJSENSE\n");
2049  SCIP_CALL( CBFreadObjsense(scip, scipfile, &linecount) );
2050  objread = TRUE;
2051  }
2052  else if ( strcmp(CBF_NAME_BUFFER, "VAR") == 0 )
2053  {
2054  SCIPdebugMsg(scip, "Reading VAR\n");
2055  SCIP_CALL( CBFreadVar(scip, scipfile, &linecount, data) );
2056  }
2057  else if ( strcmp(CBF_NAME_BUFFER, "CON") == 0 )
2058  {
2059  SCIPdebugMsg(scip, "Reading CON\n");
2060  SCIP_CALL( CBFreadCon(scip, scipfile, &linecount, data) );
2061  }
2062  else if ( strcmp(CBF_NAME_BUFFER, "INT") == 0 )
2063  {
2064  SCIPdebugMsg(scip, "Reading INT\n");
2065  SCIP_CALL( CBFreadInt(scip, scipfile, &linecount, data) );
2066  }
2067  else if ( strcmp(CBF_NAME_BUFFER, "PSDCON") == 0 )
2068  {
2069  SCIPdebugMsg(scip, "Reading PSDCON\n");
2070  SCIP_CALL( CBFreadPsdCon(scip, scipfile, &linecount, data) );
2071  }
2072  else if ( strcmp(CBF_NAME_BUFFER, "PSDVAR") == 0 )
2073  {
2074  SCIPdebugMsg(scip, "Reading PSDVAR\n");
2075  SCIP_CALL( CBFreadPsdVar(scip, scipfile, &linecount, data) );
2076  }
2077  else if ( strcmp(CBF_NAME_BUFFER, "PSDCONRANK1") == 0 )
2078  {
2079  SCIPdebugMsg(scip, "Reading PSDCONRANK1\n");
2080  SCIP_CALL( CBFreadPsdConRank1(scip, scipfile, &linecount, data) );
2081  }
2082  else if ( strcmp(CBF_NAME_BUFFER, "PSDVARRANK1") == 0 )
2083  {
2084  SCIPdebugMsg(scip, "Reading PSDVARRANK1\n");
2085  SCIP_CALL( CBFreadPsdVarRank1(scip, scipfile, &linecount, data) );
2086  }
2087  else if ( strcmp(CBF_NAME_BUFFER, "OBJFCOORD") == 0 )
2088  {
2089  SCIPdebugMsg(scip, "Reading OBJFCOORD\n");
2090  SCIP_CALL( CBFreadObjFcoord(scip, scipfile, &linecount, data) );
2091  }
2092  else if ( strcmp(CBF_NAME_BUFFER, "OBJACOORD") == 0 )
2093  {
2094  SCIPdebugMsg(scip, "Reading OBJACOORD\n");
2095  SCIP_CALL( CBFreadObjAcoord(scip, scipfile, &linecount, data) );
2096  }
2097  else if ( strcmp(CBF_NAME_BUFFER, "OBJBCOORD") == 0 )
2098  {
2099  SCIPerrorMessage("constant part in objective value not supported by SCIP!\n");
2100  SCIPABORT();
2101  return SCIP_READERROR; /*lint !e527*/
2102  }
2103  else if ( strcmp(CBF_NAME_BUFFER, "FCOORD") == 0 )
2104  {
2105  SCIPdebugMsg(scip, "Reading FCOORD\n");
2106  SCIP_CALL( CBFreadFcoord(scip, scipfile, &linecount, data) );
2107  }
2108  else if ( strcmp(CBF_NAME_BUFFER, "ACOORD") == 0 )
2109  {
2110  SCIPdebugMsg(scip, "Reading ACOORD\n");
2111  SCIP_CALL( CBFreadAcoord(scip, scipfile, &linecount, data) );
2112  }
2113  else if ( strcmp(CBF_NAME_BUFFER, "BCOORD") == 0 )
2114  {
2115  SCIPdebugMsg(scip, "Reading BCOORD\n");
2116  SCIP_CALL( CBFreadBcoord(scip, scipfile, &linecount, data) );
2117  }
2118  else if ( strcmp(CBF_NAME_BUFFER, "HCOORD") == 0 )
2119  {
2120  SCIPdebugMsg(scip, "Reading HCOORD\n");
2121  SCIP_CALL( CBFreadHcoord(scip, scipfile, &linecount, data) );
2122  }
2123  else if ( strcmp(CBF_NAME_BUFFER, "DCOORD") == 0 )
2124  {
2125  SCIPdebugMsg(scip, "Reading DCOORD\n");
2126  SCIP_CALL( CBFreadDcoord(scip, scipfile, &linecount, data) );
2127  }
2128  else
2129  {
2130  SCIPerrorMessage("Keyword %s in line %d not recognized!\n", CBF_NAME_BUFFER, linecount);
2131  SCIPABORT();
2132  return SCIP_READERROR; /*lint !e527*/
2133  }
2134  }
2135  }
2136  }
2137 
2138  /* Psd vars are created using scalar vars and a corresponding psd constraint that gets created in the function
2139  * CBFreadPsdCon. If there are no psd cons in the original problem, then the psd constraint for the reformulation of the
2140  * original psd vars needs to be created at this point! */
2141  if ( data->npsdvars > data->nsdpblocks )
2142  {
2143  int nauxvars;
2144  int varidx;
2145  int row;
2146  int col;
2147  int val;
2148 
2149  assert( data->nsdpblocks == -1 );
2150  assert( data->createdpsdvars != NULL );
2151  assert( data->psdvarrank1 != NULL );
2152  assert( data->npsdvars >= 0 );
2153 
2154  data->noorigsdpcons = TRUE;
2155 
2156  data->nsdpblocks = data->npsdvars;
2157  data->nnonz = 0;
2158 
2159  /* allocate memory for auxiliary sdp blocks */
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) );
2172 
2173  for (b = 0; b < data->nsdpblocks; b++)
2174  {
2175  nauxvars = data->psdvarsizes[b] * (data->psdvarsizes[b] + 1) / 2;
2176  data->nnonz += nauxvars;
2177  varidx = 0;
2178 
2179  data->sdpblocksizes[b] = data->psdvarsizes[b];
2180  data->sdpblockrank1[b] = data->psdvarrank1[b];
2181  data->sdpnblocknonz[b] = nauxvars;
2182  data->sdpnblockvars[b] = nauxvars;
2183 
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) );
2192 
2193  val = 1;
2194  for (row = 0; row < data->psdvarsizes[b]; row++)
2195  {
2196  for (col = 0; col <= row; col++)
2197  {
2198  data->sdprow[b][varidx] = row;
2199  data->sdpcol[b][varidx] = col;
2200  data->sdpval[b][varidx] = val;
2201 
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]);
2207  varidx++;
2208  }
2209  }
2210  assert( varidx == nauxvars );
2211  }
2212  }
2213 
2214  if ( ! objread )
2215  {
2216  SCIPerrorMessage("Keyword OBJSENSE is missing!\n");
2217  SCIPABORT();
2218  return SCIP_READERROR; /*lint !e527*/
2219  }
2220 
2221  /* close the file (and make sure SCIPfclose returns 0) */
2222  if ( SCIPfclose(scipfile) )
2223  return SCIP_READERROR;
2224 
2225 #ifdef SCIP_MORE_DEBUG
2226  for (b = 0; b < SCIPgetNConss(scip); b++)
2227  {
2228  SCIP_CALL( SCIPprintCons(scip, SCIPgetConss(scip)[b], NULL) );
2229  SCIPinfoMessage(scip, NULL, "\n");
2230  }
2231 #endif
2232 
2233  /* create SDP-constraints */
2234  for (b = 0; b < data->nsdpblocks; b++)
2235  {
2236  SCIP_CONS* sdpcons;
2237  char sdpconname[SCIP_MAXSTRLEN];
2238 #ifndef NDEBUG
2239  int snprintfreturn;
2240 #endif
2241 
2242  assert( data->sdpblocksizes[b] > 0 );
2243  assert( (data->sdpnblockvars[b] > 0 && data->sdpnblocknonz[b] > 0) || (data->sdpconstnblocknonz[b] > 0) );
2244 
2245 #ifndef NDEBUG
2246  snprintfreturn = SCIPsnprintf(sdpconname, SCIP_MAXSTRLEN, "SDP_%d", b);
2247  assert( snprintfreturn < SCIP_MAXSTRLEN);
2248 #else
2249  (void) SCIPsnprintf(sdpconname, SCIP_MAXSTRLEN, "SDP_%d", b);
2250 #endif
2251 
2252  /* special treatment of case without constant PSD blocks */
2253  if ( data->sdpconstnblocknonz == NULL )
2254  {
2255  if ( ! data->sdpblockrank1[b] )
2256  {
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) );
2260  }
2261  else
2262  {
2263  SCIP_CALL( SCIPcreateConsSdpRank1(scip, &sdpcons, sdpconname, data->sdpnblockvars[b], data->sdpnblocknonz[b],
2264  data->sdpblocksizes[b], data->nvarnonz[b], data->colpointer[b], data->rowpointer[b], data->valpointer[b],
2265  data->sdpblockvars[b], 0, NULL, NULL, NULL) );
2266  }
2267  }
2268  else
2269  {
2270  if ( ! data->sdpblockrank1[b] )
2271  {
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]) );
2276  }
2277  else
2278  {
2279  SCIP_CALL( SCIPcreateConsSdpRank1(scip, &sdpcons, sdpconname, data->sdpnblockvars[b], data->sdpnblocknonz[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]) );
2283  }
2284  }
2285 
2286 #ifdef SCIP_MORE_DEBUG
2287  SCIP_CALL( SCIPprintCons(scip, sdpcons, NULL) );
2288 #endif
2289 
2290  SCIP_CALL( SCIPaddCons(scip, sdpcons) );
2291 
2292  SCIP_CALL( SCIPreleaseCons(scip, &sdpcons) );
2293  }
2294 
2295  SCIP_CALL( CBFfreeData(scip, data) );
2296  SCIPfreeBufferNull(scip, &data);
2297 
2298  *result = SCIP_SUCCESS;
2299 
2300  return SCIP_OKAY;
2301 }
2302 
2303 
2305 static
2306 SCIP_DECL_READERWRITE(readerWriteCbf)
2307 { /*lint --e{715,818}*/
2308  SCIP_VAR** linvars;
2309  SCIP_Real* linvals;
2310  SCIP_VAR** sdpvars;
2311  SCIP_Real** sdpval;
2312  SCIP_Real* sdpconstval;
2313  int** sdpcol;
2314  int** sdprow;
2315  int* sdpconstcol;
2316  int* sdpconstrow;
2317  int* sdpnvarnonz;
2318  int* varsenses;
2319  int* consssenses;
2320  int nsdpconss;
2321  int sdpnvars;
2322  int sdpnnonz;
2323  int totalsdpnnonz;
2324  int sdpblocksize;
2325  int sdparraylength;
2326  int totalsdpconstnnonz;
2327  int sdpconstnnonz;
2328  int nobjnonz;
2329  int nnonz;
2330  int nbnonz;
2331  int nsenses;
2332  int nconsssenses;
2333  int lastsense;
2334  int consind;
2335  int c;
2336  int i;
2337  int v;
2338  int nrank1sdpblocks;
2339 
2340  assert( scip != NULL );
2341  assert( result != NULL );
2342 
2343  SCIPdebugMsg(scip, "Writing problem in CBF format to file.\n");
2344  *result = SCIP_DIDNOTRUN;
2345 
2346  if ( transformed )
2347  {
2348  SCIPerrorMessage("CBF reader currently only supports writing original problems!\n");
2349  SCIPABORT();
2350  return SCIP_READERROR; /*lint !e527*/
2351  }
2352 
2353  for (c = 0; c < nconss; c++)
2354  {
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 ) )
2358  {
2359  SCIPerrorMessage("CBF reader currently only supports linear and SDP constraints!\n");
2360  SCIPABORT();
2361  return SCIP_READERROR; /*lint !e527*/
2362  }
2363  }
2364 
2365 #ifndef NDEBUG
2366  for (v = 0; v < nvars; v++)
2367  {
2368  assert( SCIPvarGetStatus(vars[v]) == SCIP_VARSTATUS_ORIGINAL );
2369  }
2370 #endif
2371 
2372  /* write version number */
2373  SCIPinfoMessage(scip, file, "VER\n%d\n\n", CBF_VERSION_NR);
2374 
2375  /* write objective sense */
2376  SCIPinfoMessage(scip, file, "OBJSENSE\n%s\n\n", objsense == SCIP_OBJSENSE_MINIMIZE ? "MIN" : "MAX");
2377 
2378  /* collect different variable senses */
2379  SCIP_CALL( SCIPallocBufferArray(scip, &varsenses, nvars) );
2380  for (v = 0; v < nvars; v++)
2381  {
2382  SCIP_Real lb;
2383  SCIP_Real ub;
2384 
2385  lb = SCIPvarGetLbOriginal(vars[v]);
2386  ub = SCIPvarGetUbOriginal(vars[v]);
2387 
2388  varsenses[v] = 0;
2389  if ( SCIPisZero(scip, lb) )
2390  varsenses[v] = 1;
2391  else
2392  {
2393  if ( ! SCIPisInfinity(scip, -lb) )
2394  {
2395  SCIPerrorMessage("Can only handle variables with lower bound 0 or minus infinity.\n");
2396  SCIPABORT();
2397  return SCIP_READERROR; /*lint !e527*/
2398  }
2399  }
2400 
2401  if ( SCIPisZero(scip, ub) )
2402  varsenses[v] = -1;
2403  else
2404  {
2405  if ( ! SCIPisInfinity(scip, ub) )
2406  {
2407  SCIPerrorMessage("Can only handle variables with upper bound 0 or infinity.\n");
2408  SCIPABORT();
2409  return SCIP_READERROR; /*lint !e527*/
2410  }
2411  }
2412  }
2413 
2414  /* now determine senses of constraints - possibly disable constraints */
2415  SCIP_CALL( SCIPallocBufferArray(scip, &consssenses, nconss) );
2416  for (c = 0; c < nconss; c++)
2417  {
2418  SCIP_Real lhs;
2419  SCIP_Real rhs;
2420 
2421  consssenses[c] = 2;
2422 
2423  /* only count linear constraints */
2424  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "linear") != 0 )
2425  continue;
2426 
2427  lhs = SCIPgetLhsLinear(scip, conss[c]);
2428  rhs = SCIPgetRhsLinear(scip, conss[c]);
2429 
2430 #ifdef CBF_CHECK_NONNEG
2431  /* check if there are constraints that would determine senses of variables */
2432  if ( SCIPgetNVarsLinear(scip, conss[c]) == 1 && ! SCIPisEQ(scip, SCIPgetLhsLinear(scip, conss[c]), SCIPgetRhsLinear(scip, conss[c])) )
2433  {
2434  /* the nonzero should be a true nonzero */
2435  assert( ! SCIPisZero(scip, SCIPgetValsLinear(scip, conss[c])[0]) );
2436  assert( SCIPgetVarsLinear(scip, conss[c]) != NULL );
2437 
2438  v = SCIPvarGetProbindex(SCIPgetVarsLinear(scip, conss[c])[0]);
2439  assert( 0 <= v && v < nvars );
2440 
2441  if ( SCIPgetValsLinear(scip, conss[c])[0] > 0.0 )
2442  {
2443  if ( SCIPisZero(scip, lhs) )
2444  {
2445  varsenses[v] = 1;
2446  continue;
2447  }
2448  else if ( SCIPisZero(scip, rhs) )
2449  {
2450  varsenses[v] = -1;
2451  continue;
2452  }
2453  }
2454  else
2455  {
2456  if ( SCIPisZero(scip, lhs) )
2457  {
2458  varsenses[v] = -1;
2459  continue;
2460  }
2461  else if ( SCIPisZero(scip, rhs) )
2462  {
2463  varsenses[v] = 1;
2464  continue;
2465  }
2466  }
2467  }
2468 #endif
2469 
2470  if ( SCIPisEQ(scip, lhs, rhs) )
2471  {
2472  assert( ! SCIPisInfinity(scip, -lhs) );
2473  assert( ! SCIPisInfinity(scip, rhs) );
2474  consssenses[c] = 0;
2475  }
2476  else
2477  {
2478  if ( ! SCIPisInfinity(scip, -lhs) && ! SCIPisInfinity(scip, rhs) )
2479  {
2480  SCIPerrorMessage("Cannot handle ranged rows.\n");
2481  SCIPABORT();
2482  return SCIP_READERROR; /*lint !e527*/
2483  }
2484 
2485  if ( ! SCIPisInfinity(scip, -lhs) )
2486  consssenses[c] = 1;
2487  else if ( ! SCIPisInfinity(scip, rhs) )
2488  consssenses[c] = -1;
2489  }
2490  }
2491 
2492  /* compute different varsenses */
2493  nsenses = 0;
2494  lastsense = 2;
2495  for (v = 0; v < nvars; v++)
2496  {
2497  if ( varsenses[v] != lastsense )
2498  {
2499  ++nsenses;
2500  lastsense = varsenses[v];
2501  }
2502  }
2503 
2504  /* write variable senses */
2505  SCIPinfoMessage(scip, file, "VAR\n%d %d\n", nvars, nsenses);
2506  lastsense = varsenses[0];
2507  nsenses = 1;
2508  for (v = 1; v < nvars; v++)
2509  {
2510  if ( varsenses[v] != lastsense )
2511  {
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);
2516  else
2517  {
2518  assert( lastsense == 1 );
2519  SCIPinfoMessage(scip, file, "L+ %d\n", nsenses);
2520  }
2521  nsenses = 0;
2522  lastsense = varsenses[v];
2523  }
2524  ++nsenses;
2525  }
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);
2530  else
2531  {
2532  assert( lastsense == 1 );
2533  SCIPinfoMessage(scip, file, "L+ %d\n\n", nsenses);
2534  }
2535 
2536  /* write integrality constraints */
2537  if ( nbinvars + nintvars > 0 )
2538  {
2539  SCIPinfoMessage(scip, file, "INT\n%d\n", nbinvars + nintvars);
2540 
2541  for (v = 0; v < nbinvars + nintvars; v++)
2542  {
2543  assert( SCIPvarIsIntegral(vars[v]) );
2544  SCIPinfoMessage(scip, file, "%d\n", v);
2545  }
2546  SCIPinfoMessage(scip, file, "\n");
2547  }
2548 
2549  /* compute different consssenses */
2550  nsenses = 0;
2551  lastsense = 3;
2552  i = 0;
2553  for (c = 0; c < nconss; c++)
2554  {
2555  if ( consssenses[c] == 2 )
2556  continue;
2557 
2558  ++i;
2559  if ( consssenses[c] != lastsense )
2560  {
2561  ++nsenses;
2562  lastsense = consssenses[c];
2563  }
2564  }
2565 
2566  /* write constraint senses */
2567  SCIPinfoMessage(scip, file, "CON\n%d %d\n", i, nsenses);
2568  nconsssenses = nsenses;
2569  c = 0;
2570  while (c < nconss && consssenses[c] == 2)
2571  ++c;
2572  if ( c < nconss )
2573  {
2574  lastsense = consssenses[c];
2575  nsenses = 1;
2576  ++c;
2577  for (; c < nconss; ++c)
2578  {
2579  if ( consssenses[c] == 2 )
2580  continue;
2581 
2582  if ( consssenses[c] != lastsense )
2583  {
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);
2588  else
2589  {
2590  assert( lastsense == 1 );
2591  SCIPinfoMessage(scip, file, "L+ %d\n", nsenses);
2592  }
2593  nsenses = 0;
2594  lastsense = consssenses[c];
2595  }
2596  ++nsenses;
2597  }
2598  }
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);
2603  else
2604  {
2605  assert( lastsense == 1 );
2606  SCIPinfoMessage(scip, file, "L+ %d\n\n", nsenses);
2607  }
2608 
2609  /* count number of SDP constraints (conshdlrGetNConss doesn't seem to work before transformation) */
2610  nsdpconss = 0;
2611  for (c = 0; c < nconss; c++)
2612  {
2613  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDP") == 0 || strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDPrank1") == 0 )
2614  ++nsdpconss;
2615  }
2616 
2617  /* write SDP constraints */
2618  SCIPinfoMessage(scip, file, "PSDCON\n%d\n", nsdpconss);
2619 
2620  for (c = 0; c < nconss; c++)
2621  {
2622  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDPrank1") != 0 )
2623  continue;
2624 
2625  SCIPinfoMessage(scip, file, "%d\n", SCIPconsSdpGetBlocksize(scip, conss[c]));
2626  }
2627 
2628  SCIPinfoMessage(scip, file, "\n");
2629 
2630  /* count number of rank-1 SDP constraints */
2631  nrank1sdpblocks = 0;
2632  for (c = 0; c < nconss; c++)
2633  {
2634  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDPrank1") == 0 )
2635  ++nrank1sdpblocks;
2636  }
2637 
2638  /* write rank-1 SDP constraints (if existing) */
2639  if ( nrank1sdpblocks > 0 )
2640  {
2641  SCIPinfoMessage(scip, file, "PSDCONRANK1\n%d\n", nrank1sdpblocks);
2642  consind = 0;
2643 
2644  for (c = 0; c < nconss; c++)
2645  {
2646  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDPrank1") != 0 )
2647  continue;
2648 
2649  assert( SCIPconsSdpShouldBeRankOne(conss[c]) );
2650  SCIPinfoMessage(scip, file, "%d\n", consind);
2651  consind++;
2652  }
2653 
2654  SCIPinfoMessage(scip, file, "\n");
2655  }
2656 
2657  /* count number of nonzero objective coefficients */
2658  nobjnonz = 0;
2659  for (v = 0; v < nvars; v++)
2660  {
2661  if ( ! SCIPisZero(scip, SCIPvarGetObj(vars[v])) )
2662  ++nobjnonz;
2663  }
2664 
2665  /* write objective */
2666  SCIPinfoMessage(scip, file, "OBJACOORD\n%d\n", nobjnonz);
2667 
2668  for (v = 0; v < nvars; v++)
2669  {
2670  SCIP_Real obj;
2671 
2672  obj = SCIPvarGetObj(vars[v]);
2673  if ( ! SCIPisZero(scip, obj) )
2674  {
2675  SCIPinfoMessage(scip, file, "%d %.15g\n", v, obj);
2676  }
2677  }
2678  SCIPinfoMessage(scip, file, "\n");
2679 
2680  /* write coefficients of linear constraints */
2681  if ( nconsssenses > 0 )
2682  {
2683  /* count number of nonzero coefficients in linear constraints */
2684  nnonz = 0;
2685  nbnonz = 0;
2686  for (c = 0; c < nconss; c++)
2687  {
2688  if ( consssenses[c] == -1 )
2689  {
2690  assert( ! SCIPisInfinity(scip, SCIPgetRhsLinear(scip, conss[c])) );
2691  nnonz += SCIPgetNVarsLinear(scip, conss[c]);
2692  if ( ! SCIPisZero(scip, SCIPgetRhsLinear(scip, conss[c])) )
2693  ++nbnonz;
2694  }
2695  else if ( consssenses[c] == 1 )
2696  {
2697  assert( ! SCIPisInfinity(scip, -SCIPgetLhsLinear(scip, conss[c])) );
2698  nnonz += SCIPgetNVarsLinear(scip, conss[c]);
2699  if ( ! SCIPisZero(scip, SCIPgetLhsLinear(scip, conss[c])) )
2700  ++nbnonz;
2701  }
2702  else if ( consssenses[c] == 0 )
2703  {
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])) )
2707  ++nbnonz;
2708  }
2709  }
2710 
2711  /* write linear nonzero coefficients */
2712  SCIPinfoMessage(scip, file, "ACOORD\n%d\n", nnonz);
2713  consind = 0;
2714  for (c = 0; c < nconss; c++)
2715  {
2716  if ( consssenses[c] == -1 || consssenses[c] == 0 || consssenses[c] == 1 )
2717  {
2718  assert( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "linear") == 0 );
2719 
2720  linvars = SCIPgetVarsLinear(scip, conss[c]);
2721  linvals = SCIPgetValsLinear(scip, conss[c]);
2722 
2723  for (v = 0; v < SCIPgetNVarsLinear(scip, conss[c]); v++)
2724  {
2725  i = SCIPvarGetProbindex(linvars[v]);
2726  assert( 0 <= i && i < nvars );
2727  SCIPinfoMessage(scip, file, "%d %d %.15g\n", consind, i, linvals[v]);
2728  }
2729  ++consind;
2730  }
2731  }
2732  SCIPinfoMessage(scip, file, "\n");
2733 
2734  /* write constant part of linear constraints */
2735  SCIPinfoMessage(scip, file, "BCOORD\n%d\n", nbnonz);
2736  consind = 0;
2737  for (c = 0; c < nconss; c++)
2738  {
2739  SCIP_Real val;
2740  if ( consssenses[c] == -1 )
2741  {
2742  val = SCIPgetRhsLinear(scip, conss[c]);
2743  if ( ! SCIPisZero(scip, val) )
2744  SCIPinfoMessage(scip, file, "%d %.15g\n", consind, -val);
2745  consind++;
2746  }
2747  else if ( consssenses[c] == 1 )
2748  {
2749  val = SCIPgetLhsLinear(scip, conss[c]);
2750  if ( ! SCIPisZero(scip, val) )
2751  SCIPinfoMessage(scip, file, "%d %.15g\n", consind, -val);
2752  consind++;
2753  }
2754  else if ( consssenses[c] == 0 )
2755  {
2756  val = SCIPgetLhsLinear(scip, conss[c]);
2757  if ( ! SCIPisZero(scip, val) )
2758  SCIPinfoMessage(scip, file, "%d %.15g\n", consind, -val);
2759  consind++;
2760  }
2761  }
2762  SCIPinfoMessage(scip, file, "\n");
2763  }
2764 
2765  /* count SDP nonzeros */
2766  totalsdpnnonz = 0;
2767  totalsdpconstnnonz = 0;
2768  for (c = 0; c < nconss; c++)
2769  {
2770  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),"SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])),"SDPrank1") != 0 )
2771  continue;
2772 
2773  SCIP_CALL( SCIPconsSdpGetNNonz(scip, conss[c], &sdpnnonz, &sdpconstnnonz) );
2774  totalsdpnnonz += sdpnnonz;
2775  totalsdpconstnnonz += sdpconstnnonz;
2776  }
2777 
2778  /* allocate memory for SDPdata */
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) );
2787 
2788  sdparraylength = totalsdpnnonz;
2789  sdpconstnnonz = totalsdpconstnnonz;
2790 
2791  /* write SDP nonzeros */
2792  if ( totalsdpnnonz > 0 )
2793  {
2794  SCIPinfoMessage(scip, file, "HCOORD\n%d\n", totalsdpnnonz);
2795  consind = 0;
2796  for (c = 0; c < nconss; c++)
2797  {
2798  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDPrank1") != 0 )
2799  continue;
2800 
2801  /* initialization for SDPconsSDPGetData-call */
2802  sdparraylength = totalsdpnnonz;
2803  sdpconstnnonz = totalsdpconstnnonz;
2804 
2805  SCIP_CALL( SCIPconsSdpGetData(scip, conss[c], &sdpnvars, &sdpnnonz, &sdpblocksize, &sdparraylength, sdpnvarnonz,
2806  sdpcol, sdprow, sdpval, sdpvars, &sdpconstnnonz, sdpconstcol, sdpconstrow, sdpconstval, NULL, NULL, NULL) );
2807 
2808  assert( sdpconstnnonz <= totalsdpconstnnonz );
2809  assert( sdparraylength <= totalsdpnnonz);
2810 
2811  for (v = 0; v < sdpnvars; v++)
2812  {
2813  for (i = 0; i < sdpnvarnonz[v]; i++)
2814  {
2815  int ind;
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]);
2819  }
2820  }
2821  consind++;
2822  }
2823  SCIPinfoMessage(scip, file, "\n");
2824  }
2825 
2826  /* write nonzeros of constant part of SDP constraint */
2827  if ( totalsdpnnonz > 0 )
2828  {
2829  SCIPinfoMessage(scip, file, "DCOORD\n%d\n", totalsdpconstnnonz);
2830  consind = 0;
2831  for (c = 0; c < nconss; c++)
2832  {
2833  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDP") != 0 && strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(conss[c])), "SDPrank1") != 0 )
2834  continue;
2835 
2836  /* initialization for SDPconsSDPGetData-call */
2837  sdparraylength = totalsdpnnonz;
2838  sdpconstnnonz = totalsdpconstnnonz;
2839 
2840  SCIP_CALL( SCIPconsSdpGetData(scip, conss[c], &sdpnvars, &sdpnnonz, &sdpblocksize, &sdparraylength, sdpnvarnonz,
2841  sdpcol, sdprow, sdpval, sdpvars, &sdpconstnnonz, sdpconstcol, sdpconstrow, sdpconstval, NULL, NULL, NULL) );
2842 
2843  assert( sdpconstnnonz <= totalsdpconstnnonz );
2844  assert( sdparraylength <= totalsdpnnonz);
2845 
2846  for (i = 0; i < sdpconstnnonz; i++)
2847  {
2848  SCIPinfoMessage(scip, file, "%d %d %d %.15g\n", consind, sdpconstrow[i], sdpconstcol[i], -sdpconstval[i]);
2849  }
2850  consind++;
2851  }
2852  }
2853 
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);
2864 
2865  *result = SCIP_SUCCESS;
2866 
2867  return SCIP_OKAY;
2868 }
2869 
2870 
2871 /*
2872  * reader specific interface methods
2873  */
2874 
2876 SCIP_RETCODE SCIPincludeReaderCbf(
2877  SCIP* scip
2878  )
2879 {
2880  SCIP_READERDATA* readerdata = NULL;
2881  SCIP_READER* reader;
2882 
2883  /* include reader */
2884  SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
2885 
2886  assert( reader != NULL );
2887 
2888  /* set non fundamental callbacks via setter functions */
2889  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyCbf) );
2890  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadCbf) );
2891  SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWriteCbf) );
2892 
2893  return SCIP_OKAY;
2894 }
static SCIP_RETCODE CBFfgets(SCIP_FILE *pFile, SCIP_Longint *linecount)
Definition: reader_cbf.c:146
static SCIP_RETCODE CBFreadBcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:1269
static SCIP_RETCODE CBFreadHcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:1361
static SCIP_RETCODE CBFreadPsdVarRank1(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:446
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)
Definition: cons_sdp.c:5269
char CBF_LINE_BUFFER[CBF_MAX_LINE]
Definition: reader_cbf.c:98
static SCIP_RETCODE CBFreadPsdCon(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:711
#define CBF_MAX_NAME
Definition: reader_cbf.c:96
static SCIP_RETCODE CBFreadObjFcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:857
file reader for mixed-integer semidefinite programs in CBF format
#define READER_DESC
Definition: reader_cbf.c:79
static SCIP_DECL_READERCOPY(readerCopyCbf)
Definition: reader_cbf.c:1945
static SCIP_RETCODE CBFreadObjsense(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount)
Definition: reader_cbf.c:168
static SCIP_RETCODE CBFfreeData(SCIP *scip, CBF_DATA *data)
Definition: reader_cbf.c:1780
static SCIP_RETCODE CBFreadAcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:1173
char CBF_NAME_BUFFER[CBF_MAX_NAME]
Definition: reader_cbf.c:99
static SCIP_RETCODE CBFreadDcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:1643
#define CBF_VERSION_NR
Definition: reader_cbf.c:82
static SCIP_RETCODE CBFreadInt(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:644
#define READER_EXTENSION
Definition: reader_cbf.c:80
Constraint handler for SDP-constraints.
SCIP_RETCODE SCIPincludeReaderCbf(SCIP *scip)
Definition: reader_cbf.c:2878
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)
Definition: cons_sdp.c:5150
static SCIP_RETCODE CBFreadFcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:1048
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)
Definition: cons_sdp.c:4603
SCIP_Bool SCIPconsSdpShouldBeRankOne(SCIP_CONS *cons)
Definition: cons_sdp.c:5099
#define CBF_MAX_LINE
Definition: reader_cbf.c:95
#define READER_NAME
Definition: reader_cbf.c:78
static SCIP_RETCODE CBFreadVar(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:207
static SCIP_DECL_READERREAD(readerReadCbf)
Definition: reader_cbf.c:1956
static SCIP_RETCODE CBFreadCon(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:517
int SCIPconsSdpGetBlocksize(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sdp.c:4735
static SCIP_RETCODE CBFreadPsdConRank1(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:787
SCIP_RETCODE SCIPconsSdpGetNNonz(SCIP *scip, SCIP_CONS *cons, int *nnonz, int *constnnonz)
Definition: cons_sdp.c:4710
static SCIP_RETCODE CBFreadObjAcoord(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:968
static SCIP_RETCODE CBFreadPsdVar(SCIP *scip, SCIP_FILE *pfile, SCIP_Longint *linecount, CBF_DATA *data)
Definition: reader_cbf.c:328
#define CBF_NAME_FORMAT
Definition: reader_cbf.c:94
static SCIP_DECL_READERWRITE(readerWriteCbf)
Definition: reader_cbf.c:2308