Scippy

SCIP

Solving Constraint Integer Programs

reader_lp.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file reader_lp.c
17  * @brief LP file reader
18  * @author Tobias Achterberg
19  * @author Marc Pfetsch
20  * @author Stefan Heinz
21  * @author Stefan Vigerske
22  * @author Michael Winkler
23  * @author Lars Schewe
24  *
25  * @todo write fixed (non-active) variables, e.g., for transformed problem
26  */
27 
28 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
29 
30 #include <stdlib.h>
31 #include <assert.h>
32 #include <string.h>
33 #if defined(_WIN32) || defined(_WIN64)
34 #else
35 #include <strings.h> /*lint --e{766}*/ /* needed for strncasecmp() */
36 #endif
37 #include <ctype.h>
38 
39 #include "scip/reader_lp.h"
40 #include "scip/cons_knapsack.h"
41 #include "scip/cons_linear.h"
42 #include "scip/cons_logicor.h"
43 #include "scip/cons_setppc.h"
44 #include "scip/cons_varbound.h"
45 #include "scip/cons_and.h"
46 #include "scip/cons_sos1.h"
47 #include "scip/cons_sos2.h"
48 #include "scip/cons_indicator.h"
49 #include "scip/cons_quadratic.h"
50 #include "scip/cons_soc.h"
52 #include "scip/pub_misc.h"
53 
54 #define READER_NAME "lpreader"
55 #define READER_DESC "file reader for MIPs in IBM CPLEX's LP file format"
56 #define READER_EXTENSION "lp"
57 
58 #define DEFAULT_LINEARIZE_ANDS TRUE /**< Should possible \"and\"-constraints be linearized when writing the lp file? */
59 #define DEFAULT_AGGRLINEARIZATION_ANDS TRUE /**< Should an aggregated linearization for and constraints be used? */
60 
61 /*
62  * Data structures
63  */
64 
65 #define LP_MAX_LINELEN 65536
66 #define LP_MAX_PUSHEDTOKENS 2
67 #define LP_INIT_COEFSSIZE 8192
68 #define LP_INIT_QUADCOEFSSIZE 16
69 #define LP_MAX_PRINTLEN 561 /**< the maximum length of any line is 560 + '\\0' = 561*/
70 #define LP_MAX_NAMELEN 256 /**< the maximum length for any name is 255 + '\\0' = 256 */
71 #define LP_PRINTLEN 100
72 
73 
74 /** LP reading data */
75 struct SCIP_ReaderData
76 {
77  SCIP_Bool linearizeands;
78  SCIP_Bool aggrlinearizationands;
79 };
80 
81 
82 /** Section in LP File */
84 {
86 };
87 typedef enum LpSection LPSECTION;
88 
90 {
92 };
93 typedef enum LpExpType LPEXPTYPE;
94 
95 enum LpSense
96 {
98 };
99 typedef enum LpSense LPSENSE;
100 
101 /** LP reading data */
102 struct LpInput
103 {
104  SCIP_FILE* file;
105  char linebuf[LP_MAX_LINELEN+1];
106  char probname[LP_MAX_LINELEN];
107  char objname[LP_MAX_LINELEN];
108  char* token;
109  char* tokenbuf;
110  char* pushedtokens[LP_MAX_PUSHEDTOKENS];
111  int npushedtokens;
112  int linenumber;
113  int linepos;
114  LPSECTION section;
115  SCIP_OBJSENSE objsense;
116  SCIP_Bool inlazyconstraints; /**< whether we are currently reading the section for lazy constraints */
117  SCIP_Bool inusercuts; /**< whether we are currently reading the section for user cuts */
118  SCIP_Bool initialconss; /**< should model constraints be marked as initial? */
119  SCIP_Bool dynamicconss; /**< should model constraints be subject to aging? */
120  SCIP_Bool dynamiccols; /**< should columns be added and removed dynamically to the LP? */
121  SCIP_Bool dynamicrows; /**< should rows be added and removed dynamically to the LP? */
122  SCIP_Bool haserror;
123  SCIP_Bool comment;
124  SCIP_Bool endline;
125 };
126 typedef struct LpInput LPINPUT;
127 
128 static const char commentchars[] = "\\";
129 
130 
131 /*
132  * Local methods (for reading)
133  */
134 
135 /** issues an error message and marks the LP data to have errors */
136 static
138  SCIP* scip, /**< SCIP data structure */
139  LPINPUT* lpinput, /**< LP reading data */
140  const char* msg /**< error message */
141  )
142 {
143  char formatstr[256];
144 
145  assert(lpinput != NULL);
146 
147  SCIPerrorMessage("Syntax error in line %d ('%s'): %s \n", lpinput->linenumber, lpinput->token, msg);
148  if( lpinput->linebuf[strlen(lpinput->linebuf)-1] == '\n' )
149  {
150  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, " input: %s", lpinput->linebuf);
151  }
152  else
153  {
154  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, " input: %s\n", lpinput->linebuf);
155  }
156  (void) SCIPsnprintf(formatstr, 256, " %%%ds\n", lpinput->linepos);
157  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, (const char*)formatstr, "^");
158  lpinput->section = LP_END;
159  lpinput->haserror = TRUE;
160 }
161 
162 /** returns whether a syntax error was detected */
163 static
165  LPINPUT* lpinput /**< LP reading data */
166  )
167 {
168  assert(lpinput != NULL);
169 
170  return lpinput->haserror;
171 }
172 
173 /** returns whether the given character is a token delimiter */
174 static
176  char c /**< input character */
177  )
178 {
179  switch (c)
180  {
181  case ' ':
182  case '\f':
183  case '\n':
184  case '\r':
185  case '\t':
186  case '\v':
187  case '\0':
188  return TRUE;
189  default:
190  return FALSE;
191  }
192 }
193 
194 /** returns whether the given character is a single token */
195 static
197  char c /**< input character */
198  )
199 {
200  switch (c)
201  {
202  case '-':
203  case '+':
204  case ':':
205  case '<':
206  case '>':
207  case '=':
208  case '[':
209  case ']':
210  case '*':
211  case '^':
212  return TRUE;
213  default:
214  return FALSE;
215  }
216 }
217 
218 /** returns whether the current character is member of a value string */
219 static
221  char c, /**< input character */
222  char nextc, /**< next input character */
223  SCIP_Bool firstchar, /**< is the given character the first char of the token? */
224  SCIP_Bool* hasdot, /**< pointer to update the dot flag */
225  LPEXPTYPE* exptype /**< pointer to update the exponent type */
226  )
227 {
228  assert(hasdot != NULL);
229  assert(exptype != NULL);
230 
231  if( isdigit((unsigned char)c) )
232  return TRUE;
233  else if( (*exptype == LP_EXP_NONE) && !(*hasdot) && (c == '.') && ( isdigit((unsigned char)nextc) || isspace((unsigned char)nextc) || nextc == 'e' || nextc == 'E') )
234  { /* note: we allow for numbers like "24311." for which the next character should be a space or exponent sign */
235  *hasdot = TRUE;
236  return TRUE;
237  }
238  else if( !firstchar && (*exptype == LP_EXP_NONE) && (c == 'e' || c == 'E') )
239  {
240  if( nextc == '+' || nextc == '-' )
241  {
242  *exptype = LP_EXP_SIGNED;
243  return TRUE;
244  }
245  else if( isdigit((unsigned char)nextc) )
246  {
247  *exptype = LP_EXP_UNSIGNED;
248  return TRUE;
249  }
250  }
251  else if( (*exptype == LP_EXP_SIGNED) && (c == '+' || c == '-') )
252  {
253  *exptype = LP_EXP_UNSIGNED;
254  return TRUE;
255  }
256 
257  return FALSE;
258 }
259 
260 /** reads the next line from the input file into the line buffer; skips comments;
261  * returns whether a line could be read
262  */
263 static
265  SCIP* scip, /**< SCIP data structure */
266  LPINPUT* lpinput /**< LP reading data */
267  )
268 {
269  int i;
270 
271  assert(lpinput != NULL);
272 
273  /* if we previously detected a comment we have to parse the remaining line away if there is something left */
274  if( !lpinput->endline && lpinput->comment )
275  {
276  SCIPdebugMsg(scip, "Throwing rest of comment away.\n");
277 
278  do
279  {
280  lpinput->linebuf[LP_MAX_LINELEN-2] = '\0';
281  (void)SCIPfgets(lpinput->linebuf, (int) sizeof(lpinput->linebuf), lpinput->file);
282  }
283  while( lpinput->linebuf[LP_MAX_LINELEN-2] != '\0' );
284 
285  lpinput->comment = FALSE;
286  lpinput->endline = TRUE;
287  }
288 
289  /* read next line */
290  lpinput->linepos = 0;
291  lpinput->linebuf[LP_MAX_LINELEN-2] = '\0';
292 
293  if( SCIPfgets(lpinput->linebuf, (int) sizeof(lpinput->linebuf), lpinput->file) == NULL )
294  {
295  /* clear the line, this is really necessary here! */
296  BMSclearMemoryArray(lpinput->linebuf, LP_MAX_LINELEN);
297 
298  return FALSE;
299  }
300 
301  lpinput->linenumber++;
302 
303  /* if line is too long for our buffer correct the buffer and correct position in file */
304  if( lpinput->linebuf[LP_MAX_LINELEN-2] != '\0' )
305  {
306  char* last;
307 
308  /* buffer is full; erase last token since it might be incomplete */
309  lpinput->endline = FALSE;
310  last = strrchr(lpinput->linebuf, ' ');
311 
312  if( last == NULL )
313  {
314  SCIPwarningMessage(scip, "we read %d characters from the file; this might indicate a corrupted input file!",
315  LP_MAX_LINELEN - 2);
316  lpinput->linebuf[LP_MAX_LINELEN-2] = '\0';
317  SCIPdebugMsg(scip, "the buffer might be corrupted\n");
318  }
319  else
320  {
321  SCIPfseek(lpinput->file, -(long) strlen(last), SEEK_CUR);
322  SCIPdebugMsg(scip, "correct buffer, reread the last %ld characters\n", (long) strlen(last));
323  *last = '\0';
324  }
325  }
326  else
327  {
328  /* found end of line */
329  lpinput->endline = TRUE;
330  }
331  lpinput->linebuf[LP_MAX_LINELEN-1] = '\0'; /* we want to use lookahead of one char -> we need two \0 at the end */
332  lpinput->comment = FALSE;
333 
334  /* skip characters after comment symbol */
335  for( i = 0; commentchars[i] != '\0'; ++i )
336  {
337  char* commentstart;
338 
339  commentstart = strchr(lpinput->linebuf, commentchars[i]);
340  if( commentstart != NULL )
341  {
342  *commentstart = '\0';
343  *(commentstart+1) = '\0'; /* we want to use lookahead of one char -> we need two \0 at the end */
344 
345  lpinput->comment = TRUE;
346  break;
347  }
348  }
349 
350  return TRUE;
351 }
352 
353 /** swaps the addresses of two pointers */
354 static
356  char** pointer1, /**< first pointer */
357  char** pointer2 /**< second pointer */
358  )
359 {
360  char* tmp;
361 
362  tmp = *pointer1;
363  *pointer1 = *pointer2;
364  *pointer2 = tmp;
365 }
366 
367 /** reads the next token from the input file into the token buffer; returns whether a token was read */
368 static
370  SCIP* scip, /**< SCIP data structure */
371  LPINPUT* lpinput /**< LP reading data */
372  )
373 {
374  SCIP_Bool hasdot;
375  LPEXPTYPE exptype;
376  char* buf;
377  int tokenlen;
378 
379  assert(lpinput != NULL);
380  assert(lpinput->linepos < LP_MAX_LINELEN);
381 
382  /* check the token stack */
383  if( lpinput->npushedtokens > 0 )
384  {
385  swapPointers(&lpinput->token, &lpinput->pushedtokens[lpinput->npushedtokens-1]);
386  lpinput->npushedtokens--;
387 
388  SCIPdebugMsg(scip, "(line %d) read token again: '%s'\n", lpinput->linenumber, lpinput->token);
389  return TRUE;
390  }
391 
392  /* skip delimiters */
393  buf = lpinput->linebuf;
394  while( isDelimChar(buf[lpinput->linepos]) )
395  {
396  if( buf[lpinput->linepos] == '\0' )
397  {
398  if( !getNextLine(scip, lpinput) )
399  {
400  lpinput->section = LP_END;
401  SCIPdebugMsg(scip, "(line %d) end of file\n", lpinput->linenumber);
402  return FALSE;
403  }
404  assert(lpinput->linepos == 0);
405  }
406  else
407  lpinput->linepos++;
408  }
409  assert(lpinput->linepos < LP_MAX_LINELEN);
410  assert(!isDelimChar(buf[lpinput->linepos]));
411 
412  /* check if the token is a value */
413  hasdot = FALSE;
414  exptype = LP_EXP_NONE;
415  if( isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1], TRUE, &hasdot, &exptype) )
416  {
417  /* read value token */
418  tokenlen = 0;
419  do
420  {
421  assert(tokenlen < LP_MAX_LINELEN);
422  assert(!isDelimChar(buf[lpinput->linepos]));
423  lpinput->token[tokenlen] = buf[lpinput->linepos];
424  tokenlen++;
425  lpinput->linepos++;
426  }
427  while( isValueChar(buf[lpinput->linepos], buf[lpinput->linepos+1], FALSE, &hasdot, &exptype) );
428  }
429  else
430  {
431  /* read non-value token */
432  tokenlen = 0;
433  do
434  {
435  assert(tokenlen < LP_MAX_LINELEN);
436  lpinput->token[tokenlen] = buf[lpinput->linepos];
437  tokenlen++;
438  lpinput->linepos++;
439  if( tokenlen == 1 && isTokenChar(lpinput->token[0]) )
440  break;
441  }
442  while( !isDelimChar(buf[lpinput->linepos]) && !isTokenChar(buf[lpinput->linepos]) );
443 
444  /* if the token is a power sign '^', skip a following '2'
445  * if the token is an equation sense '<', '>', or '=', skip a following '='
446  * if the token is an equality token '=' and the next character is a '<' or '>', replace the token by the inequality sense
447  */
448  if( tokenlen >= 1 && lpinput->token[tokenlen-1] == '^' && buf[lpinput->linepos] == '2' )
449  {
450  lpinput->linepos++;
451  }
452  if( tokenlen >= 1
453  && (lpinput->token[tokenlen-1] == '<' || lpinput->token[tokenlen-1] == '>' || lpinput->token[tokenlen-1] == '=')
454  && buf[lpinput->linepos] == '=' )
455  {
456  lpinput->linepos++;
457  }
458  else if( lpinput->token[tokenlen-1] == '=' && (buf[lpinput->linepos] == '<' || buf[lpinput->linepos] == '>') )
459  {
460  lpinput->token[tokenlen-1] = buf[lpinput->linepos];
461  lpinput->linepos++;
462  }
463  }
464  assert(tokenlen < LP_MAX_LINELEN);
465  lpinput->token[tokenlen] = '\0';
466 
467  SCIPdebugMsg(scip, "(line %d) read token: '%s'\n", lpinput->linenumber, lpinput->token);
468 
469  return TRUE;
470 }
471 
472 /** puts the current token on the token stack, such that it is read at the next call to getNextToken() */
473 static
475  LPINPUT* lpinput /**< LP reading data */
476  )
477 {
478  assert(lpinput != NULL);
479  assert(lpinput->npushedtokens < LP_MAX_PUSHEDTOKENS);
480 
481  swapPointers(&lpinput->pushedtokens[lpinput->npushedtokens], &lpinput->token);
482  lpinput->npushedtokens++;
483 }
484 
485 /** puts the buffered token on the token stack, such that it is read at the next call to getNextToken() */
486 static
488  LPINPUT* lpinput /**< LP reading data */
489  )
490 {
491  assert(lpinput != NULL);
492  assert(lpinput->npushedtokens < LP_MAX_PUSHEDTOKENS);
493 
494  swapPointers(&lpinput->pushedtokens[lpinput->npushedtokens], &lpinput->tokenbuf);
495  lpinput->npushedtokens++;
496 }
497 
498 /** swaps the current token with the token buffer */
499 static
501  LPINPUT* lpinput /**< LP reading data */
502  )
503 {
504  assert(lpinput != NULL);
505 
506  swapPointers(&lpinput->token, &lpinput->tokenbuf);
507 }
508 
509 /** checks whether the current token is a section identifier, and if yes, switches to the corresponding section */
510 static
512  SCIP* scip, /**< SCIP data structure */
513  LPINPUT* lpinput /**< LP reading data */
514  )
515 {
516  SCIP_Bool iscolon;
517  size_t len;
518 
519  assert(lpinput != NULL);
520 
521  /* remember first token by swapping the token buffer */
522  swapTokenBuffer(lpinput);
523 
524  /* look at next token: if this is a ':', the first token is a name and no section keyword */
525  iscolon = FALSE;
526  if( getNextToken(scip, lpinput) )
527  {
528  iscolon = (*lpinput->token == ':');
529  pushToken(lpinput);
530  }
531 
532  /* reinstall the previous token by swapping back the token buffer */
533  swapTokenBuffer(lpinput);
534 
535  /* check for ':' */
536  if( iscolon )
537  return FALSE;
538 
539  len = strlen(lpinput->token);
540  assert(len < LP_MAX_LINELEN);
541 
542  /* the section keywords are at least 2 characters up to 8 or exactly 15 characters long */
543  if( len > 1 && (len < 9 || len == 15) )
544  {
545  char token[16];
546  int c = 0;
547 
548  while( lpinput->token[c] != '\0' )
549  {
550  token[c] = toupper(lpinput->token[c]); /*lint !e734*/
551  ++c;
552  assert(c < 16);
553  }
554  token[c] = '\0';
555 
556  if( (len == 3 && strcmp(token, "MIN") == 0)
557  || (len == 7 && strcmp(token, "MINIMUM") == 0)
558  || (len == 8 && strcmp(token, "MINIMIZE") == 0) )
559  {
560  SCIPdebugMsg(scip, "(line %d) new section: OBJECTIVE\n", lpinput->linenumber);
561  lpinput->section = LP_OBJECTIVE;
562  lpinput->objsense = SCIP_OBJSENSE_MINIMIZE;
563  return TRUE;
564  }
565 
566  if( (len == 3 && strcmp(token, "MAX") == 0)
567  || (len == 7 && strcmp(token, "MAXIMUM") == 0)
568  || (len == 8 && strcmp(token, "MAXIMIZE") == 0) )
569  {
570  SCIPdebugMsg(scip, "(line %d) new section: OBJECTIVE\n", lpinput->linenumber);
571  lpinput->section = LP_OBJECTIVE;
572  lpinput->objsense = SCIP_OBJSENSE_MAXIMIZE;
573  return TRUE;
574  }
575 
576  if( len == 7 && strcmp(token, "SUBJECT") == 0 )
577  {
578  /* check if the next token is 'TO' */
579  swapTokenBuffer(lpinput);
580  if( getNextToken(scip, lpinput) )
581  {
582  if( strcasecmp(lpinput->token, "TO") == 0 )
583  {
584  SCIPdebugMsg(scip, "(line %d) new section: CONSTRAINTS\n", lpinput->linenumber);
585  lpinput->section = LP_CONSTRAINTS;
586  lpinput->inlazyconstraints = FALSE;
587  lpinput->inusercuts = FALSE;
588  return TRUE;
589  }
590  else
591  pushToken(lpinput);
592  }
593  swapTokenBuffer(lpinput);
594  }
595 
596  if( len == 4 && strcmp(token, "SUCH") == 0 )
597  {
598  /* check if the next token is 'THAT' */
599  swapTokenBuffer(lpinput);
600  if( getNextToken(scip, lpinput) )
601  {
602  if( strcasecmp(lpinput->token, "THAT") == 0 )
603  {
604  SCIPdebugMsg(scip, "(line %d) new section: CONSTRAINTS\n", lpinput->linenumber);
605  lpinput->section = LP_CONSTRAINTS;
606  lpinput->inlazyconstraints = FALSE;
607  lpinput->inusercuts = FALSE;
608  return TRUE;
609  }
610  else
611  pushToken(lpinput);
612  }
613  swapTokenBuffer(lpinput);
614  }
615 
616  if( (len == 2 && strcmp(token, "ST") == 0)
617  || (len == 3 && strcmp(token, "ST.") == 0)
618  || (len == 4 && strcmp(token, "S.T.") == 0) )
619  {
620  SCIPdebugMsg(scip, "(line %d) new section: CONSTRAINTS\n", lpinput->linenumber);
621  lpinput->section = LP_CONSTRAINTS;
622  lpinput->inlazyconstraints = FALSE;
623  lpinput->inusercuts = FALSE;
624  return TRUE;
625  }
626 
627  if( len == 4 && strcmp(token, "LAZY") == 0 )
628  {
629  /* check if the next token is 'CONSTRAINTS' */
630  swapTokenBuffer(lpinput);
631  if( getNextToken(scip, lpinput) )
632  {
633  if( strcasecmp(lpinput->token, "CONSTRAINTS") == 0 )
634  {
635  SCIPdebugMsg(scip, "(line %d) new section: CONSTRAINTS (lazy)\n", lpinput->linenumber);
636  lpinput->section = LP_CONSTRAINTS;
637  lpinput->inlazyconstraints = TRUE;
638  lpinput->inusercuts = FALSE;
639  return TRUE;
640  }
641  else
642  pushToken(lpinput);
643  }
644  swapTokenBuffer(lpinput);
645  }
646 
647  if( len == 4 && strcmp(token, "USER") == 0 )
648  {
649  /* check if the next token is 'CUTS' */
650  swapTokenBuffer(lpinput);
651  if( getNextToken(scip, lpinput) )
652  {
653  if( strcasecmp(lpinput->token, "CUTS") == 0 )
654  {
655  SCIPdebugMsg(scip, "(line %d) new section: CONSTRAINTS (user cuts)\n", lpinput->linenumber);
656  lpinput->section = LP_CONSTRAINTS;
657  lpinput->inlazyconstraints = FALSE;
658  lpinput->inusercuts = TRUE;
659  return TRUE;
660  }
661  else
662  pushToken(lpinput);
663  }
664  swapTokenBuffer(lpinput);
665  }
666 
667  if( (len == 5 && strcmp(token, "BOUND") == 0)
668  || (len == 6 && strcmp(token, "BOUNDS") == 0) )
669  {
670  SCIPdebugMsg(scip, "(line %d) new section: BOUNDS\n", lpinput->linenumber);
671  lpinput->section = LP_BOUNDS;
672  return TRUE;
673  }
674 
675  if( (len == 3 && (strcmp(token, "GEN") == 0 || strcmp(token, "INT") == 0))
676  || (len == 7 && (strcmp(token, "GENERAL") == 0 || strcmp(token, "INTEGER") == 0))
677  || (len == 8 && (strcmp(token, "GENERALS") == 0 || strcmp(token, "INTEGERS") == 0)) )
678  {
679  SCIPdebugMsg(scip, "(line %d) new section: GENERALS\n", lpinput->linenumber);
680  lpinput->section = LP_GENERALS;
681  return TRUE;
682  }
683 
684  if( (len == 3 && strcmp(token, "BIN") == 0)
685  || (len == 6 && strcmp(token, "BINARY") == 0)
686  || (len == 8 && strcmp(token, "BINARIES") == 0) )
687  {
688  SCIPdebugMsg(scip, "(line %d) new section: BINARIES\n", lpinput->linenumber);
689  lpinput->section = LP_BINARIES;
690  return TRUE;
691  }
692 
693  if( (len == 4 && strcmp(token, "SEMI") == 0)
694  || (len == 5 && strcmp(token, "SEMIS") == 0)
695  || (len == 15 && strcmp(token, "SEMI-CONTINUOUS") == 0) )
696  {
697  SCIPdebugMsg(scip, "(line %d) new section: SEMICONTINUOUS\n", lpinput->linenumber);
698  lpinput->section = LP_SEMICONTINUOUS;
699  return TRUE;
700  }
701 
702  if( len == 3 && strcmp(token, "SOS") == 0 )
703  {
704  SCIPdebugMsg(scip, "(line %d) new section: SOS\n", lpinput->linenumber);
705  lpinput->section = LP_SOS;
706  return TRUE;
707  }
708 
709  if( len == 3 && strcmp(token, "END") == 0 )
710  {
711  SCIPdebugMsg(scip, "(line %d) new section: END\n", lpinput->linenumber);
712  lpinput->section = LP_END;
713  return TRUE;
714  }
715  }
716 
717  return FALSE;
718 }
719 
720 /** returns whether the current token is a sign */
721 static
723  LPINPUT* lpinput, /**< LP reading data */
724  int* sign /**< pointer to update the sign */
725  )
726 {
727  assert(lpinput != NULL);
728  assert(sign != NULL);
729  assert(*sign == +1 || *sign == -1);
730 
731  if( lpinput->token[1] == '\0' )
732  {
733  if( *lpinput->token == '+' )
734  return TRUE;
735  else if( *lpinput->token == '-' )
736  {
737  *sign *= -1;
738  return TRUE;
739  }
740  }
741 
742  return FALSE;
743 }
744 
745 /** returns whether the current token is a value */
746 static
748  SCIP* scip, /**< SCIP data structure */
749  LPINPUT* lpinput, /**< LP reading data */
750  SCIP_Real* value /**< pointer to store the value (unchanged, if token is no value) */
751  )
752 {
753  assert(lpinput != NULL);
754  assert(value != NULL);
755 
756  if( strcasecmp(lpinput->token, "INFINITY") == 0 || strcasecmp(lpinput->token, "INF") == 0 )
757  {
758  *value = SCIPinfinity(scip);
759  return TRUE;
760  }
761  else
762  {
763  double val;
764  char* endptr;
765 
766  val = strtod(lpinput->token, &endptr);
767  if( endptr != lpinput->token && *endptr == '\0' )
768  {
769  *value = val;
770  return TRUE;
771  }
772  }
773 
774  return FALSE;
775 }
776 
777 /** returns whether the current token is an equation sense */
778 static
780  LPINPUT* lpinput, /**< LP reading data */
781  LPSENSE* sense /**< pointer to store the equation sense, or NULL */
782  )
783 {
784  assert(lpinput != NULL);
785 
786  if( strcmp(lpinput->token, "<") == 0 )
787  {
788  if( sense != NULL )
789  *sense = LP_SENSE_LE;
790  return TRUE;
791  }
792  else if( strcmp(lpinput->token, ">") == 0 )
793  {
794  if( sense != NULL )
795  *sense = LP_SENSE_GE;
796  return TRUE;
797  }
798  else if( strcmp(lpinput->token, "=") == 0 )
799  {
800  if( sense != NULL )
801  *sense = LP_SENSE_EQ;
802  return TRUE;
803  }
804 
805  return FALSE;
806 }
807 
808 /** returns the variable with the given name, or creates a new variable if it does not exist */
809 static
811  SCIP* scip, /**< SCIP data structure */
812  char* name, /**< name of the variable */
813  SCIP_VAR** var, /**< pointer to store the variable */
814  SCIP_Bool* created /**< pointer to store whether a new variable was created, or NULL */
815  )
816 {
817  assert(name != NULL);
818  assert(var != NULL);
819 
820  *var = SCIPfindVar(scip, name);
821  if( *var == NULL )
822  {
823  SCIP_VAR* newvar;
824  SCIP_Bool dynamiccols;
825  SCIP_Bool initial;
826  SCIP_Bool removable;
827 
828  SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamiccols", &dynamiccols) );
829  initial = !dynamiccols;
830  removable = dynamiccols;
831 
832  /* create new variable of the given name */
833  SCIPdebugMsg(scip, "creating new variable: <%s>\n", name);
834  SCIP_CALL( SCIPcreateVar(scip, &newvar, name, 0.0, SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS,
835  initial, removable, NULL, NULL, NULL, NULL, NULL) );
836  SCIP_CALL( SCIPaddVar(scip, newvar) );
837  *var = newvar;
838 
839  /* because the variable was added to the problem, it is captured by SCIP and we can safely release it right now
840  * without making the returned *var invalid
841  */
842  SCIP_CALL( SCIPreleaseVar(scip, &newvar) );
843 
844  if( created != NULL )
845  *created = TRUE;
846  }
847  else if( created != NULL )
848  *created = FALSE;
849 
850  return SCIP_OKAY;
851 }
852 
853 /** reads the header of the file */
854 static
856  SCIP* scip, /**< SCIP data structure */
857  LPINPUT* lpinput /**< LP reading data */
858  )
859 {
860  assert(lpinput != NULL);
861 
862  /* everything before first section is treated as comment */
863  do
864  {
865  /* get token */
866  if( !getNextToken(scip, lpinput) )
867  return SCIP_OKAY;
868  }
869  while( !isNewSection(scip, lpinput) );
870 
871  return SCIP_OKAY;
872 }
873 
874 /** reads an objective or constraint with name and coefficients */
875 static
877  SCIP* scip, /**< SCIP data structure */
878  LPINPUT* lpinput, /**< LP reading data */
879  SCIP_Bool isobjective, /**< indicates whether we are currently reading the coefficients of the objective */
880  char* name, /**< pointer to store the name of the line; must be at least of size
881  * LP_MAX_LINELEN */
882  int* coefssize, /**< size of vars and coefs arrays */
883  SCIP_VAR*** vars, /**< pointer to store the array with variables (must be freed by caller) */
884  SCIP_Real** coefs, /**< pointer to store the array with coefficients (must be freed by caller) */
885  int* ncoefs, /**< pointer to store the number of coefficients */
886  int* quadcoefssize, /**< size of quadvars1, quadvars2, quadcoefs arrays */
887  SCIP_VAR*** quadvars1, /**< pointer to store the array with first variables in quadratic terms (must be freed by caller) */
888  SCIP_VAR*** quadvars2, /**< pointer to store the array with second variables in quadratic terms (must be freed by caller) */
889  SCIP_Real** quadcoefs, /**< pointer to store the array with coefficients in quadratic terms (must be freed by caller) */
890  int* nquadcoefs, /**< pointer to store the number of quadratic coefficients */
891  SCIP_Bool* newsection /**< pointer to store whether a new section was encountered */
892  )
893 {
894  SCIP_Bool havesign;
895  SCIP_Bool havevalue;
896  SCIP_Real coef;
897  int coefsign;
898  SCIP_Bool inquadpart;
899  SCIP_VAR* firstquadvar;
900 
901  assert(lpinput != NULL);
902  assert(name != NULL);
903  assert(coefssize != NULL);
904  assert(vars != NULL);
905  assert(coefs != NULL);
906  assert(ncoefs != NULL);
907  assert(quadcoefssize != NULL);
908  assert(quadvars1 != NULL);
909  assert(quadvars2 != NULL);
910  assert(quadcoefs != NULL);
911  assert(nquadcoefs != NULL);
912  assert(newsection != NULL);
913 
914  *coefssize = 0;
915  *vars = NULL;
916  *coefs = NULL;
917  *quadvars1 = NULL;
918  *quadvars2 = NULL;
919  *quadcoefs = NULL;
920  *name = '\0';
921  *ncoefs = 0;
922  *quadcoefssize = 0;
923  *nquadcoefs = 0;
924  *newsection = FALSE;
925  inquadpart = FALSE;
926 
927  /* read the first token, which may be the name of the line */
928  if( getNextToken(scip, lpinput) )
929  {
930  /* check if we reached a new section */
931  if( isNewSection(scip, lpinput) )
932  {
933  *newsection = TRUE;
934  return SCIP_OKAY;
935  }
936 
937  /* remember the token in the token buffer */
938  swapTokenBuffer(lpinput);
939 
940  /* get the next token and check, whether it is a colon */
941  if( getNextToken(scip, lpinput) )
942  {
943  if( strcmp(lpinput->token, ":") == 0 )
944  {
945  /* the second token was a colon: the first token is the line name */
946  (void)SCIPmemccpy(name, lpinput->tokenbuf, '\0', LP_MAX_LINELEN);
947 
948  name[LP_MAX_LINELEN - 1] = '\0';
949  SCIPdebugMsg(scip, "(line %d) read constraint name: '%s'\n", lpinput->linenumber, name);
950  }
951  else
952  {
953  /* the second token was no colon: push the tokens back onto the token stack and parse them as coefficients */
954  pushToken(lpinput);
955  pushBufferToken(lpinput);
956  }
957  }
958  else
959  {
960  /* there was only one token left: push it back onto the token stack and parse it as coefficient */
961  pushBufferToken(lpinput);
962  }
963  }
964 
965  /* initialize buffers for storing the coefficients */
966  *coefssize = LP_INIT_COEFSSIZE;
967  SCIP_CALL( SCIPallocBlockMemoryArray(scip, vars, *coefssize) );
968  SCIP_CALL( SCIPallocBlockMemoryArray(scip, coefs, *coefssize) );
969 
970  *quadcoefssize = LP_INIT_QUADCOEFSSIZE;
971  SCIP_CALL( SCIPallocBlockMemoryArray(scip, quadvars1, *quadcoefssize) );
972  SCIP_CALL( SCIPallocBlockMemoryArray(scip, quadvars2, *quadcoefssize) );
973  SCIP_CALL( SCIPallocBlockMemoryArray(scip, quadcoefs, *quadcoefssize) );
974 
975  /* read the coefficients */
976  coefsign = +1;
977  coef = 1.0;
978  havesign = FALSE;
979  havevalue = FALSE;
980  firstquadvar = NULL;
981  *ncoefs = 0;
982  *nquadcoefs = 0;
983  while( getNextToken(scip, lpinput) )
984  {
985  SCIP_VAR* var;
986 
987  /* check if we read a sign */
988  if( isSign(lpinput, &coefsign) )
989  {
990  SCIPdebugMsg(scip, "(line %d) read coefficient sign: %+d\n", lpinput->linenumber, coefsign);
991  havesign = TRUE;
992  continue;
993  }
994 
995  /* check if we read a value */
996  if( isValue(scip, lpinput, &coef) )
997  {
998  SCIPdebugMsg(scip, "(line %d) read coefficient value: %g with sign %+d\n", lpinput->linenumber, coef, coefsign);
999  if( havevalue )
1000  {
1001  syntaxError(scip, lpinput, "two consecutive values.");
1002  return SCIP_OKAY;
1003  }
1004  havevalue = TRUE;
1005  continue;
1006  }
1007 
1008  /* check if we reached an equation sense */
1009  if( isSense(lpinput, NULL) )
1010  {
1011  if( isobjective )
1012  {
1013  syntaxError(scip, lpinput, "no sense allowed in objective");
1014  return SCIP_OKAY;
1015  }
1016 
1017  /* put the sense back onto the token stack */
1018  pushToken(lpinput);
1019  break;
1020  }
1021 
1022  /* check if we reached a new section, that will be only allowed when having no current sign and value and if we
1023  * are not in the qudratic part
1024  */
1025  if( (isobjective || (!havevalue && !havesign)) && !inquadpart && isNewSection(scip, lpinput) )
1026  {
1027  if( havesign && !havevalue )
1028  {
1029  SCIPwarningMessage(scip, "skipped single sign %c without value or variable in objective\n", coefsign == 1 ? '+' : '-');
1030  }
1031  else if( isobjective && havevalue && !SCIPisZero(scip, coef) )
1032  {
1033  SCIPwarningMessage(scip, "constant term %+g in objective is skipped\n", coef * coefsign);
1034  }
1035 
1036  *newsection = TRUE;
1037  return SCIP_OKAY;
1038  }
1039 
1040  /* check if we start a quadratic part */
1041  if( *lpinput->token == '[' )
1042  {
1043  if( inquadpart )
1044  {
1045  syntaxError(scip, lpinput, "cannot start quadratic part while already in quadratic part.");
1046  return SCIP_OKAY;
1047  }
1048  if( havesign && coefsign != +1 )
1049  {
1050  syntaxError(scip, lpinput, "cannot have '-' in front of quadratic part.");
1051  return SCIP_OKAY;
1052  }
1053  if( havevalue )
1054  {
1055  syntaxError(scip, lpinput, "cannot have value in front of quadratic part.");
1056  return SCIP_OKAY;
1057  }
1058 
1059  SCIPdebugMsg(scip, "(line %d) start quadratic part\n", lpinput->linenumber);
1060  inquadpart = TRUE;
1061  continue;
1062  }
1063 
1064  /* check if we end a quadratic part */
1065  if( *lpinput->token == ']' )
1066  {
1067  if( !inquadpart )
1068  {
1069  syntaxError(scip, lpinput, "cannot end quadratic part before starting one.");
1070  return SCIP_OKAY;
1071  }
1072  if( havesign || havevalue || firstquadvar != NULL )
1073  {
1074  if( firstquadvar == NULL )
1075  {
1076  syntaxError(scip, lpinput, "expected value or first quadratic variable.");
1077  }
1078  else
1079  {
1080  syntaxError(scip, lpinput, "expected second quadratic variable.");
1081  }
1082  return SCIP_OKAY;
1083  }
1084 
1085  SCIPdebugMsg(scip, "(line %d) end quadratic part\n", lpinput->linenumber);
1086  inquadpart = FALSE;
1087 
1088  if( isobjective )
1089  {
1090  /* quadratic part in objective has to end with '/2' */
1091  if( !getNextToken(scip, lpinput) )
1092  {
1093  syntaxError(scip, lpinput, "expected '/2' or '/ 2' after end of quadratic part in objective.");
1094  return SCIP_OKAY;
1095  }
1096  if( strcmp(lpinput->token, "/2") == 0 )
1097  {
1098  SCIPdebugMsg(scip, "(line %d) saw '/2' or '/ 2' after quadratic part in objective\n", lpinput->linenumber);
1099  }
1100  else if( *lpinput->token == '/' )
1101  {
1102  /* maybe it says '/ 2' */
1103  if( !getNextToken(scip, lpinput) || *lpinput->token != '2' )
1104  {
1105  syntaxError(scip, lpinput, "expected '/2' or '/ 2' after end of quadratic part in objective.");
1106  return SCIP_OKAY;
1107  }
1108  SCIPdebugMsg(scip, "(line %d) saw '/ 2' after quadratic part in objective\n", lpinput->linenumber);
1109  }
1110  else
1111  {
1112  syntaxError(scip, lpinput, "expected '/2' or '/ 2' after end of quadratic part in objective.");
1113  return SCIP_OKAY;
1114  }
1115  }
1116 
1117  continue;
1118  }
1119 
1120  /* check if we are in between two quadratic variables */
1121  if( *lpinput->token == '*' )
1122  {
1123  if( !inquadpart )
1124  {
1125  syntaxError(scip, lpinput, "cannot have '*' outside of quadratic part.");
1126  return SCIP_OKAY;
1127  }
1128  if( firstquadvar == NULL )
1129  {
1130  syntaxError(scip, lpinput, "cannot have '*' before first variable in quadratic term.");
1131  return SCIP_OKAY;
1132  }
1133 
1134  continue;
1135  }
1136 
1137  /* all but the first coefficient need a sign */
1138  if( !inquadpart && *ncoefs > 0 && !havesign )
1139  {
1140  syntaxError(scip, lpinput, "expected sign ('+' or '-') or sense ('<' or '>').");
1141  return SCIP_OKAY;
1142  }
1143  if( inquadpart && *nquadcoefs > 0 && !havesign )
1144  {
1145  syntaxError(scip, lpinput, "expected sign ('+' or '-').");
1146  return SCIP_OKAY;
1147  }
1148 
1149  /* check if the last variable should be squared */
1150  if( *lpinput->token == '^' )
1151  {
1152  if( !inquadpart )
1153  {
1154  syntaxError(scip, lpinput, "cannot have squares ('^2') outside of quadratic part.");
1155  return SCIP_OKAY;
1156  }
1157  if( firstquadvar == NULL )
1158  {
1159  syntaxError(scip, lpinput, "cannot have square '^2' before variable.");
1160  return SCIP_OKAY;
1161  }
1162 
1163  var = firstquadvar;
1164  }
1165  else
1166  {
1167  /* the token is a variable name: get the corresponding variable (or create a new one) */
1168  SCIP_CALL( getVariable(scip, lpinput->token, &var, NULL) );
1169  }
1170 
1171  if( !inquadpart )
1172  {
1173  /* insert the linear coefficient */
1174  SCIPdebugMsg(scip, "(line %d) read linear coefficient: %+g<%s>\n", lpinput->linenumber, coefsign * coef, SCIPvarGetName(var));
1175  if( !SCIPisZero(scip, coef) )
1176  {
1177  /* resize the vars and coefs array if needed */
1178  if( *ncoefs >= *coefssize )
1179  {
1180  int oldcoefssize;
1181  oldcoefssize = *coefssize;
1182  *coefssize *= 2;
1183  *coefssize = MAX(*coefssize, (*ncoefs)+1);
1184  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, vars, oldcoefssize, *coefssize) );
1185  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, coefs, oldcoefssize, *coefssize) );
1186  }
1187  assert(*ncoefs < *coefssize);
1188 
1189  /* add coefficient */
1190  (*vars)[*ncoefs] = var;
1191  (*coefs)[*ncoefs] = coefsign * coef;
1192  (*ncoefs)++;
1193  }
1194  }
1195  else
1196  {
1197  if( firstquadvar == NULL )
1198  {
1199  /* if first quadratic variable read, store it and continue; expect second one in next round */
1200  firstquadvar = var;
1201  continue;
1202  }
1203 
1204  /* insert the quadratic coefficient */
1205  SCIPdebugMsg(scip, "(line %d) read quadratic coefficient: %+g<%s><%s>\n", lpinput->linenumber, (isobjective ? 0.5 : 1) * coefsign * coef, SCIPvarGetName(firstquadvar), SCIPvarGetName(var));
1206  if( !SCIPisZero(scip, coef) )
1207  {
1208  /* resize the vars and coefs array if needed */
1209  if( *nquadcoefs >= *quadcoefssize )
1210  {
1211  int oldquadcoefssize;
1212  oldquadcoefssize = *quadcoefssize;
1213  *quadcoefssize *= 2;
1214  *quadcoefssize = MAX(*quadcoefssize, (*nquadcoefs)+1);
1215  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, quadcoefs, oldquadcoefssize, *quadcoefssize) );
1216  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, quadvars2, oldquadcoefssize, *quadcoefssize) );
1217  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, quadvars1, oldquadcoefssize, *quadcoefssize) );
1218  }
1219  assert(*nquadcoefs < *quadcoefssize);
1220 
1221  /* add coefficient */
1222  (*quadvars1)[*nquadcoefs] = firstquadvar;
1223  (*quadvars2)[*nquadcoefs] = var;
1224  (*quadcoefs)[*nquadcoefs] = coefsign * coef;
1225  if( isobjective )
1226  (*quadcoefs)[*nquadcoefs] /= 2.0;
1227  (*nquadcoefs)++;
1228  }
1229  }
1230 
1231  /* reset the flags and coefficient value for the next coefficient */
1232  coefsign = +1;
1233  coef = 1.0;
1234  havesign = FALSE;
1235  havevalue = FALSE;
1236  firstquadvar = NULL;
1237  }
1238 
1239  return SCIP_OKAY;
1240 }
1241 
1242 /** reads the objective section */
1243 static
1245  SCIP* scip, /**< SCIP data structure */
1246  LPINPUT* lpinput /**< LP reading data */
1247  )
1248 {
1249  char name[LP_MAX_LINELEN];
1250  SCIP_VAR** vars;
1251  SCIP_Real* coefs;
1252  SCIP_VAR** quadvars1;
1253  SCIP_VAR** quadvars2;
1254  SCIP_Real* quadcoefs;
1255  SCIP_Bool newsection;
1256  int ncoefs;
1257  int coefssize;
1258  int quadcoefssize;
1259  int nquadcoefs;
1260 
1261  assert(lpinput != NULL);
1262 
1263  /* read the objective coefficients */
1264  SCIP_CALL( readCoefficients(scip, lpinput, TRUE, name, &coefssize, &vars, &coefs, &ncoefs,
1265  &quadcoefssize, &quadvars1, &quadvars2, &quadcoefs, &nquadcoefs, &newsection) );
1266 
1267  if( !hasError(lpinput) )
1268  {
1269  int i;
1270 
1271  /* set the linear objective values */
1272  for( i = 0; i < ncoefs; ++i )
1273  {
1274  SCIP_CALL( SCIPchgVarObj(scip, vars[i], SCIPvarGetObj(vars[i]) + coefs[i]) );
1275  }
1276 
1277  /* insert dummy variable and constraint to represent quadratic part of objective; note that
1278  * reading/{initialconss,dynamicconss,dynamicrows,dynamiccols} apply only to model constraints and variables, not
1279  * to an auxiliary objective constraint (otherwise it can happen that an auxiliary objective variable is loose
1280  * with infinite best bound, triggering the problem that an LP that is unbounded because of loose variables with
1281  * infinite best bound cannot be solved)
1282  */
1283  if( nquadcoefs > 0 )
1284  {
1285  SCIP_VAR* quadobjvar;
1286  SCIP_CONS* quadobjcons;
1287  SCIP_Real lhs;
1288  SCIP_Real rhs;
1289  SCIP_Real minusone;
1290 
1291  SCIP_CALL( SCIPcreateVar(scip, &quadobjvar, "quadobjvar", -SCIPinfinity(scip), SCIPinfinity(scip), 1.0,
1293  SCIP_CALL( SCIPaddVar(scip, quadobjvar) );
1294 
1295  if( lpinput->objsense == SCIP_OBJSENSE_MINIMIZE )
1296  {
1297  lhs = -SCIPinfinity(scip);
1298  rhs = 0.0;
1299  }
1300  else
1301  {
1302  lhs = 0.0;
1303  rhs = SCIPinfinity(scip);
1304  }
1305 
1306  minusone = -1.0;
1307  SCIP_CALL( SCIPcreateConsQuadratic(scip, &quadobjcons, "quadobj", 1, &quadobjvar, &minusone, nquadcoefs, quadvars1, quadvars2, quadcoefs, lhs, rhs,
1308  TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
1309 
1310  SCIP_CALL( SCIPaddCons(scip, quadobjcons) );
1311  SCIPdebugMsg(scip, "(line %d) added constraint <%s> to represent quadratic objective: ", lpinput->linenumber, SCIPconsGetName(quadobjcons));
1312  SCIPdebugPrintCons(scip, quadobjcons, NULL);
1313 
1314  SCIP_CALL( SCIPreleaseCons(scip, &quadobjcons) );
1315  SCIP_CALL( SCIPreleaseVar(scip, &quadobjvar) );
1316  }
1317  }
1318 
1319  /* free memory */
1320  SCIPfreeBlockMemoryArrayNull(scip, &quadcoefs, quadcoefssize);
1321  SCIPfreeBlockMemoryArrayNull(scip, &quadvars2, quadcoefssize);
1322  SCIPfreeBlockMemoryArrayNull(scip, &quadvars1, quadcoefssize);
1323  SCIPfreeBlockMemoryArrayNull(scip, &vars, coefssize);
1324  SCIPfreeBlockMemoryArrayNull(scip, &coefs, coefssize);
1325 
1326  return SCIP_OKAY;
1327 }
1328 
1329 /** create indicator constraint */
1330 static
1332  SCIP* scip, /**< SCIP data structure */
1333  LPINPUT* lpinput, /**< LP reading data */
1334  const char* name, /**< name of indicator constraint */
1335  SCIP_VAR* binvar, /**< binary indicator variable */
1336  SCIP_Real binvalue /**< value of indicator part (0/1) */
1337  )
1338 {
1339  char name2[LP_MAX_LINELEN];
1340  SCIP_VAR** linvars;
1341  SCIP_Real* lincoefs;
1342  SCIP_VAR** quadvars1;
1343  SCIP_VAR** quadvars2;
1344  SCIP_Real* quadcoefs;
1345  SCIP_CONS* cons;
1346  SCIP_RETCODE retcode;
1347  LPSENSE linsense;
1348  SCIP_Real linsidevalue;
1349  SCIP_Real linrhs;
1350  SCIP_Bool newsection;
1351  SCIP_Bool linConsEQ;
1352  SCIP_Bool initial;
1353  SCIP_Bool separate;
1354  SCIP_Bool enforce;
1355  SCIP_Bool check;
1356  SCIP_Bool propagate;
1357  SCIP_Bool local;
1358  SCIP_Bool dynamic;
1359  SCIP_Bool removable;
1360  int lincoefssize;
1361  int quadcoefssize;
1362  int nlincoefs;
1363  int nquadcoefs;
1364  int linsidesign;
1365  int j;
1366 
1367  assert( lpinput != NULL );
1368  assert( binvar != NULL );
1369 
1370  retcode = SCIP_OKAY;
1371 
1372  /* check that binvalue is 0 or 1 */
1373  if( !SCIPisFeasEQ(scip, binvalue, 0.0) && !SCIPisFeasEQ(scip, binvalue, 1.0) )
1374  {
1375  syntaxError(scip, lpinput, "value for binary variable must be '0' or '1'.");
1376  return SCIP_OKAY;
1377  }
1378 
1379  if( SCIPisFeasEQ(scip, binvalue, 0.0) )
1380  {
1381  SCIP_VAR* negbinvar;
1382  SCIP_Bool infeasible;
1383 
1384  /* At this point we force the variable binvar to be binary, since we need the negated variable. We have to check
1385  * later whether the type of the variable specified in the file agrees with this specification.
1386  */
1387  /* check whether bounds are correct - might already been set if variable is used in another indicator constraint */
1388  if( SCIPvarGetLbGlobal(binvar) < 0.0 )
1389  SCIP_CALL( SCIPchgVarLb(scip, binvar, 0.0) );
1390  if( SCIPvarGetUbGlobal(binvar) > 1.0 )
1391  SCIP_CALL( SCIPchgVarUb(scip, binvar, 1.0) );
1392  SCIP_CALL( SCIPchgVarType(scip, binvar, SCIP_VARTYPE_BINARY, &infeasible) );
1393  /* don't assert feasibility here because the presolver will and should detect a infeasibility */
1394 
1395  SCIP_CALL( SCIPgetNegatedVar(scip, binvar, &negbinvar) );
1396  binvar = negbinvar;
1397  assert( binvar != NULL );
1398  }
1399 
1400  /* read linear constraint */
1401  SCIP_CALL( readCoefficients(scip, lpinput, FALSE, name2, &lincoefssize, &linvars, &lincoefs, &nlincoefs,
1402  &quadcoefssize, &quadvars1, &quadvars2, &quadcoefs, &nquadcoefs, &newsection) );
1403 
1404  if( hasError(lpinput) )
1405  goto TERMINATE;
1406  if( newsection )
1407  {
1408  syntaxError(scip, lpinput, "expected constraint.");
1409  goto TERMINATE;
1410  }
1411  if( nquadcoefs > 0 )
1412  {
1413  /* @todo could introduce auxiliary variable and move quadratic part into quadratic constraint? */
1414  syntaxError(scip, lpinput, "quadratic indicator constraints not supported.");
1415  goto TERMINATE;
1416  }
1417  if( name2[0] != '\0' )
1418  {
1419  syntaxError(scip, lpinput, "did not expect name for linear constraint.");
1420  goto TERMINATE;
1421  }
1422 
1423  /* read the constraint sense */
1424  if( !getNextToken(scip, lpinput) || !isSense(lpinput, &linsense) )
1425  {
1426  syntaxError(scip, lpinput, "expected constraint sense '<=', '=', or '>='.");
1427  goto TERMINATE;
1428  }
1429  assert(linsense == LP_SENSE_GE || linsense == LP_SENSE_LE || linsense == LP_SENSE_EQ);
1430 
1431  /* read the right hand side */
1432  linsidesign = +1;
1433  if( !getNextToken(scip, lpinput) )
1434  {
1435  syntaxError(scip, lpinput, "missing right hand side.");
1436  goto TERMINATE;
1437  }
1438  if( isSign(lpinput, &linsidesign) )
1439  {
1440  if( !getNextToken(scip, lpinput) )
1441  {
1442  syntaxError(scip, lpinput, "missing value of right hand side.");
1443  goto TERMINATE;
1444  }
1445  }
1446  if( !isValue(scip, lpinput, &linsidevalue) )
1447  {
1448  syntaxError(scip, lpinput, "expected value for right hand side.");
1449  goto TERMINATE;
1450  }
1451  linsidevalue *= linsidesign;
1452 
1453  /* assign the left and right hand side, depending on the constraint sense */
1454  linConsEQ = FALSE;
1455  switch( linsense )
1456  {
1457  case LP_SENSE_GE:
1458  linrhs = -linsidevalue;
1459  for( j = 0; j < nlincoefs; ++j )
1460  lincoefs[j] *= -1;
1461  break;
1462  case LP_SENSE_LE:
1463  linrhs = linsidevalue;
1464  break;
1465  case LP_SENSE_EQ:
1466  linConsEQ = TRUE;
1467  linrhs = linsidevalue;
1468  break;
1469  case LP_SENSE_NOTHING:
1470  default:
1471  /* this case cannot occur because it is caught by the syntax check method isSense() above */
1472  SCIPerrorMessage("invalid constraint sense <%d>\n", linsense);
1473  return SCIP_INVALIDDATA;
1474  }
1475 
1476  /* create and add the indicator constraint */
1477  initial = lpinput->initialconss && !lpinput->inlazyconstraints && !lpinput->inusercuts;
1478  separate = TRUE;
1479  enforce = !lpinput->inusercuts;
1480  check = !lpinput->inusercuts;
1481  propagate = TRUE;
1482  local = FALSE;
1483  dynamic = lpinput->dynamicconss;
1484  removable = lpinput->dynamicrows || lpinput->inusercuts;
1485 
1486  retcode = SCIPcreateConsIndicator(scip, &cons, name, binvar, nlincoefs, linvars, lincoefs, linrhs,
1487  initial, separate, enforce, check, propagate, local, dynamic, removable, FALSE);
1488 
1489  if( retcode != SCIP_OKAY )
1490  goto TERMINATE;
1491 
1492  SCIP_CALL( SCIPaddCons(scip, cons) );
1493  SCIPdebugMsg(scip, "(line %d) created constraint%s: ", lpinput->linenumber,
1494  lpinput->inlazyconstraints ? " (lazy)" : (lpinput->inusercuts ? " (user cut)" : ""));
1495  SCIPdebugPrintCons(scip, cons, NULL);
1496  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
1497 
1498  /* create second constraint if it was an equation */
1499  if( linConsEQ )
1500  {
1501  char newname[SCIP_MAXSTRLEN];
1502 
1503  (void) SCIPsnprintf(newname, SCIP_MAXSTRLEN, "%s_eqneg", name);
1504 
1505  for( j = 0; j < nlincoefs; ++j )
1506  lincoefs[j] *= -1;
1507  linrhs *= -1;
1508  retcode = SCIPcreateConsIndicator(scip, &cons, newname, binvar, nlincoefs, linvars, lincoefs, linrhs,
1509  initial, separate, enforce, check, propagate, local, dynamic, removable, FALSE);
1510 
1511  if( retcode != SCIP_OKAY )
1512  goto TERMINATE;
1513 
1514  SCIP_CALL( SCIPaddCons(scip, cons) );
1515  SCIPdebugMsg(scip, "(line %d) created constraint%s: ", lpinput->linenumber,
1516  lpinput->inlazyconstraints ? " (lazy)" : (lpinput->inusercuts ? " (user cut)" : ""));
1517  SCIPdebugPrintCons(scip, cons, NULL);
1518  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
1519  }
1520 
1521  TERMINATE:
1522  /* free memory */
1523  SCIPfreeBlockMemoryArrayNull(scip, &quadvars1, quadcoefssize);
1524  SCIPfreeBlockMemoryArrayNull(scip, &quadvars2, quadcoefssize);
1525  SCIPfreeBlockMemoryArrayNull(scip, &quadcoefs, quadcoefssize);
1526  SCIPfreeBlockMemoryArrayNull(scip, &lincoefs, lincoefssize);
1527  SCIPfreeBlockMemoryArrayNull(scip, &linvars, lincoefssize);
1528 
1529  SCIP_CALL( retcode );
1530 
1531  return SCIP_OKAY;
1532 }
1533 
1534 /** reads the constraints section
1535  *
1536  * Read linear and indicator constraints.
1537  *
1538  * The CPLEX manual says that indicator constraints are of the following form:
1539  *
1540  * [constraintname:] binaryvariable = value -> linear constraint
1541  *
1542  * We also accept "<->".
1543  */
1544 static
1546  SCIP* scip, /**< SCIP data structure */
1547  LPINPUT* lpinput /**< LP reading data */
1548  )
1549 {
1550  char name[LP_MAX_LINELEN];
1551  SCIP_CONS* cons;
1552  SCIP_VAR** vars;
1553  SCIP_Real* coefs;
1554  SCIP_VAR** quadvars1;
1555  SCIP_VAR** quadvars2;
1556  SCIP_Real* quadcoefs;
1557  LPSENSE sense;
1558  SCIP_RETCODE retcode;
1559  SCIP_Real sidevalue;
1560  SCIP_Real lhs;
1561  SCIP_Real rhs;
1562  SCIP_Bool newsection;
1563  SCIP_Bool initial;
1564  SCIP_Bool separate;
1565  SCIP_Bool enforce;
1566  SCIP_Bool check;
1567  SCIP_Bool propagate;
1568  SCIP_Bool local;
1569  SCIP_Bool modifiable;
1570  SCIP_Bool dynamic;
1571  SCIP_Bool removable;
1572  SCIP_Bool isIndicatorCons;
1573  int ncoefs;
1574  int nquadcoefs;
1575  int sidesign;
1576  int quadcoefssize;
1577  int coefssize;
1578 
1579  assert(lpinput != NULL);
1580 
1581  retcode = SCIP_OKAY;
1582 
1583  /* read coefficients */
1584  SCIP_CALL( readCoefficients(scip, lpinput, FALSE, name, &coefssize, &vars, &coefs, &ncoefs,
1585  &quadcoefssize, &quadvars1, &quadvars2, &quadcoefs, &nquadcoefs, &newsection) );
1586 
1587  if( hasError(lpinput) )
1588  goto TERMINATE;
1589  if( newsection )
1590  {
1591  if( ncoefs > 0 || nquadcoefs > 0 )
1592  syntaxError(scip, lpinput, "expected constraint sense '<=', '=', or '>='.");
1593  goto TERMINATE;
1594  }
1595 
1596  /* read the constraint sense */
1597  if( !getNextToken(scip, lpinput) || !isSense(lpinput, &sense) )
1598  {
1599  syntaxError(scip, lpinput, "expected constraint sense '<=', '=', or '>='.");
1600  goto TERMINATE;
1601  }
1602  assert(sense == LP_SENSE_GE || sense == LP_SENSE_LE || sense == LP_SENSE_EQ);
1603 
1604  /* read the right hand side */
1605  sidesign = +1;
1606  if( !getNextToken(scip, lpinput) )
1607  {
1608  syntaxError(scip, lpinput, "missing right hand side.");
1609  goto TERMINATE;
1610  }
1611  if( isSign(lpinput, &sidesign) )
1612  {
1613  if( !getNextToken(scip, lpinput) )
1614  {
1615  syntaxError(scip, lpinput, "missing value of right hand side.");
1616  goto TERMINATE;
1617  }
1618  }
1619  if( !isValue(scip, lpinput, &sidevalue) )
1620  {
1621  syntaxError(scip, lpinput, "expected value as right hand side.");
1622  goto TERMINATE;
1623  }
1624  sidevalue *= sidesign;
1625 
1626  /* assign the left and right hand side, depending on the constraint sense */
1627  switch( sense )
1628  {
1629  case LP_SENSE_GE:
1630  lhs = sidevalue;
1631  rhs = SCIPinfinity(scip);
1632  break;
1633  case LP_SENSE_LE:
1634  lhs = -SCIPinfinity(scip);
1635  rhs = sidevalue;
1636  break;
1637  case LP_SENSE_EQ:
1638  lhs = sidevalue;
1639  rhs = sidevalue;
1640  break;
1641  case LP_SENSE_NOTHING:
1642  default:
1643  /* this case cannot occur because it is caught by the syntax check method isSense() above */
1644  SCIPerrorMessage("invalid constraint sense <%d>.\n", sense);
1645  return SCIP_INVALIDDATA;
1646  }
1647 
1648  /* check whether we read the first part of an indicator constraint */
1649  isIndicatorCons = FALSE;
1650  if ( getNextToken(scip, lpinput) && !isNewSection(scip, lpinput) )
1651  {
1652  /* check whether we have '<' from a "<->" string */
1653  if ( *lpinput->token == '<' )
1654  {
1655  SCIP_Bool haveequiv = FALSE;
1656  int linepos = lpinput->linepos-1;
1657 
1658  /* check next token - cannot be a new section */
1659  if ( getNextToken(scip, lpinput) )
1660  {
1661  /* check for "<-" */
1662  if ( *lpinput->token == '-' )
1663  {
1664  /* check next token - cannot be a new section */
1665  if ( getNextToken(scip, lpinput) )
1666  {
1667  /* check for "<->" */
1668  if ( *lpinput->token == '>' )
1669  {
1670  lpinput->linepos = linepos;
1671  strcpy(lpinput->token, "<");
1672  syntaxError(scip, lpinput,
1673  "SCIP does not support equivalence (<->) indicator constraints; consider using the \"->\" form.");
1674  haveequiv = TRUE;
1675  }
1676  }
1677  }
1678  }
1679  if ( ! haveequiv )
1680  {
1681  lpinput->linepos = linepos;
1682  strcpy(lpinput->token, "<");
1683  syntaxError(scip, lpinput, "unexpected \"<\".");
1684  }
1685  goto TERMINATE;
1686  }
1687 
1688  /* check for "->" */
1689  if ( *lpinput->token == '-' )
1690  {
1691  /* remember '-' in token buffer */
1692  swapTokenBuffer(lpinput);
1693 
1694  /* check next token - cannot be a new section */
1695  if( getNextToken(scip, lpinput) )
1696  {
1697  /* check for "->" */
1698  if ( *lpinput->token == '>' )
1699  isIndicatorCons = TRUE;
1700  else
1701  {
1702  /* push back last token and '-' */
1703  pushToken(lpinput);
1704  pushBufferToken(lpinput);
1705  }
1706  }
1707  else
1708  pushBufferToken(lpinput);
1709  }
1710  else
1711  pushToken(lpinput);
1712  }
1713 
1714  if( !isIndicatorCons )
1715  {
1716  /* create and add the linear constraint */
1717  initial = lpinput->initialconss && !lpinput->inlazyconstraints && !lpinput->inusercuts;
1718  separate = TRUE;
1719  enforce = !lpinput->inusercuts;
1720  check = !lpinput->inusercuts;
1721  propagate = TRUE;
1722  local = FALSE;
1723  modifiable = FALSE;
1724  dynamic = lpinput->dynamicconss;
1725  removable = lpinput->dynamicrows || lpinput->inusercuts;
1726  if( nquadcoefs == 0 )
1727  {
1728  retcode = SCIPcreateConsLinear(scip, &cons, name, ncoefs, vars, coefs, lhs, rhs,
1729  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, FALSE);
1730  }
1731  else
1732  {
1733  retcode = SCIPcreateConsQuadratic(scip, &cons, name, ncoefs, vars, coefs,
1734  nquadcoefs, quadvars1, quadvars2, quadcoefs, lhs, rhs,
1735  initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable);
1736  }
1737 
1738  if( retcode != SCIP_OKAY )
1739  goto TERMINATE;
1740 
1741  SCIP_CALL( SCIPaddCons(scip, cons) );
1742  SCIPdebugMsg(scip, "(line %d) created constraint%s: ", lpinput->linenumber,
1743  lpinput->inlazyconstraints ? " (lazy)" : (lpinput->inusercuts ? " (user cut)" : ""));
1744  SCIPdebugPrintCons(scip, cons, NULL);
1745  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
1746  }
1747  else
1748  {
1749  /* now we should have an indicator constraint */
1750  if( ncoefs != 1 || nquadcoefs > 0 )
1751  {
1752  syntaxError(scip, lpinput, "Indicator part can only consist of one binary variable.");
1753  goto TERMINATE;
1754  }
1755  if( !SCIPisEQ(scip, coefs[0], 1.0) )
1756  {
1757  syntaxError(scip, lpinput, "There cannot be a coefficient before the binary indicator variable.");
1758  goto TERMINATE;
1759  }
1760  if( sense != LP_SENSE_EQ )
1761  {
1762  syntaxError(scip, lpinput, "Indicator part cannot handle equations.");
1763  goto TERMINATE;
1764  }
1765 
1766  retcode = createIndicatorConstraint(scip, lpinput, name, vars[0], lhs);
1767  }
1768 
1769  TERMINATE:
1770  /* free memory */
1771  SCIPfreeBlockMemoryArrayNull(scip, &quadcoefs, quadcoefssize);
1772  SCIPfreeBlockMemoryArrayNull(scip, &quadvars2, quadcoefssize);
1773  SCIPfreeBlockMemoryArrayNull(scip, &quadvars1, quadcoefssize);
1774  SCIPfreeBlockMemoryArrayNull(scip, &coefs, coefssize);
1775  SCIPfreeBlockMemoryArrayNull(scip, &vars, coefssize);
1776 
1777  SCIP_CALL( retcode );
1778 
1779  return SCIP_OKAY;
1780 }
1781 
1782 /** reads the bounds section */
1783 static
1785  SCIP* scip, /**< SCIP data structure */
1786  LPINPUT* lpinput /**< LP reading data */
1787  )
1788 {
1789  assert(lpinput != NULL);
1790 
1791  while( getNextToken(scip, lpinput) )
1792  {
1793  SCIP_VAR* var;
1794  SCIP_Real value;
1795  SCIP_Real lb;
1796  SCIP_Real ub;
1797  int sign;
1798  SCIP_Bool hassign;
1799  LPSENSE leftsense;
1800 
1801  /* check if we reached a new section */
1802  if( isNewSection(scip, lpinput) )
1803  return SCIP_OKAY;
1804 
1805  /* default bounds are [0,+inf] */
1806  lb = 0.0;
1807  ub = SCIPinfinity(scip);
1808  leftsense = LP_SENSE_NOTHING;
1809 
1810  /* check if the first token is a sign */
1811  sign = +1;
1812  hassign = isSign(lpinput, &sign);
1813  if( hassign && !getNextToken(scip, lpinput) )
1814  {
1815  syntaxError(scip, lpinput, "expected value.");
1816  return SCIP_OKAY;
1817  }
1818 
1819  /* the first token must be either a value or a variable name */
1820  if( isValue(scip, lpinput, &value) )
1821  {
1822  /* first token is a value: the second token must be a sense */
1823  if( !getNextToken(scip, lpinput) || !isSense(lpinput, &leftsense) )
1824  {
1825  syntaxError(scip, lpinput, "expected bound sense '<=', '=', or '>='.");
1826  return SCIP_OKAY;
1827  }
1828 
1829  /* update the bound corresponding to the sense */
1830  switch( leftsense )
1831  {
1832  case LP_SENSE_GE:
1833  ub = sign * value;
1834  break;
1835  case LP_SENSE_LE:
1836  lb = sign * value;
1837  break;
1838  case LP_SENSE_EQ:
1839  lb = sign * value;
1840  ub = sign * value;
1841  break;
1842  case LP_SENSE_NOTHING:
1843  default:
1844  SCIPerrorMessage("invalid bound sense <%d>\n", leftsense);
1845  return SCIP_INVALIDDATA;
1846  }
1847  }
1848  else if( hassign )
1849  {
1850  syntaxError(scip, lpinput, "expected value.");
1851  return SCIP_OKAY;
1852  }
1853  else
1854  pushToken(lpinput);
1855 
1856  /* the next token must be a variable name */
1857  if( !getNextToken(scip, lpinput) )
1858  {
1859  syntaxError(scip, lpinput, "expected variable name.");
1860  return SCIP_OKAY;
1861  }
1862  SCIP_CALL( getVariable(scip, lpinput->token, &var, NULL) );
1863 
1864  /* the next token might be another sense, or the word "free" */
1865  if( getNextToken(scip, lpinput) )
1866  {
1867  LPSENSE rightsense;
1868 
1869  if( isSense(lpinput, &rightsense) )
1870  {
1871  /* check, if the senses fit */
1872  if( leftsense == LP_SENSE_NOTHING
1873  || (leftsense == LP_SENSE_LE && rightsense == LP_SENSE_LE)
1874  || (leftsense == LP_SENSE_GE && rightsense == LP_SENSE_GE) )
1875  {
1876  if( !getNextToken(scip, lpinput) )
1877  {
1878  syntaxError(scip, lpinput, "expected value or sign.");
1879  return SCIP_OKAY;
1880  }
1881 
1882  /* check if the next token is a sign */
1883  sign = +1;
1884  hassign = isSign(lpinput, &sign);
1885  if( hassign && !getNextToken(scip, lpinput) )
1886  {
1887  syntaxError(scip, lpinput, "expected value.");
1888  return SCIP_OKAY;
1889  }
1890 
1891  /* the next token must be a value */
1892  if( !isValue(scip, lpinput, &value) )
1893  {
1894  syntaxError(scip, lpinput, "expected value.");
1895  return SCIP_OKAY;
1896  }
1897 
1898  /* update the bound corresponding to the sense */
1899  switch( rightsense )
1900  {
1901  case LP_SENSE_GE:
1902  lb = sign * value;
1903  break;
1904  case LP_SENSE_LE:
1905  ub = sign * value;
1906  break;
1907  case LP_SENSE_EQ:
1908  lb = sign * value;
1909  ub = sign * value;
1910  break;
1911  case LP_SENSE_NOTHING:
1912  default:
1913  SCIPerrorMessage("invalid bound sense <%d>\n", leftsense);
1914  return SCIP_INVALIDDATA;
1915  }
1916  }
1917  else
1918  {
1919  syntaxError(scip, lpinput, "the two bound senses do not fit.");
1920  return SCIP_OKAY;
1921  }
1922  }
1923  else if( strcasecmp(lpinput->token, "FREE") == 0 )
1924  {
1925  if( leftsense != LP_SENSE_NOTHING )
1926  {
1927  syntaxError(scip, lpinput, "variable with bound is marked as 'free'.");
1928  return SCIP_OKAY;
1929  }
1930  lb = -SCIPinfinity(scip);
1931  ub = SCIPinfinity(scip);
1932  }
1933  else
1934  {
1935  /* the token was no sense: push it back to the token stack */
1936  pushToken(lpinput);
1937  }
1938  }
1939 
1940  /* change the bounds of the variable if bounds have been given (do not destroy earlier specification of bounds) */
1941  if( lb != 0.0 )
1942  SCIP_CALL( SCIPchgVarLb(scip, var, lb) );
1943  /*lint --e{777}*/
1944  if( ub != SCIPinfinity(scip) )
1945  SCIP_CALL( SCIPchgVarUb(scip, var, ub) );
1946  SCIPdebugMsg(scip, "(line %d) new bounds: <%s>[%g,%g]\n", lpinput->linenumber, SCIPvarGetName(var),
1948  }
1949 
1950  return SCIP_OKAY;
1951 }
1952 
1953 /** reads the generals section */
1954 static
1956  SCIP* scip, /**< SCIP data structure */
1957  LPINPUT* lpinput /**< LP reading data */
1958  )
1959 {
1960  assert(lpinput != NULL);
1961 
1962  while( getNextToken(scip, lpinput) )
1963  {
1964  SCIP_VAR* var;
1965  SCIP_Real lb;
1966  SCIP_Real ub;
1967  SCIP_Bool created;
1968  SCIP_Bool infeasible;
1969 
1970  /* check if we reached a new section */
1971  if( isNewSection(scip, lpinput) )
1972  return SCIP_OKAY;
1973 
1974  /* the token must be the name of an existing variable */
1975  SCIP_CALL( getVariable(scip, lpinput->token, &var, &created) );
1976  if( created )
1977  {
1978  syntaxError(scip, lpinput, "unknown variable in generals section.");
1979  return SCIP_OKAY;
1980  }
1981 
1982  lb = SCIPvarGetLbGlobal(var);
1983  ub = SCIPvarGetUbGlobal(var);
1984 
1985  if( !SCIPisFeasIntegral(scip, lb) || !SCIPisFeasIntegral(scip, ub) )
1986  {
1987  SCIPwarningMessage(scip, "variable <%s> declared as integer has non-integral bounds[%.14g, %.14g] -> if feasible, bounds will be adjusted\n", SCIPvarGetName(var), lb, ub);
1988  }
1989 
1990  /* mark the variable to be integral */
1991  SCIP_CALL( SCIPchgVarType(scip, var, SCIP_VARTYPE_INTEGER, &infeasible) );
1992  /* don't assert feasibility here because the presolver will and should detect a infeasibility */
1993  }
1994 
1995  return SCIP_OKAY;
1996 }
1997 
1998 /** reads the binaries section */
1999 static
2001  SCIP* scip, /**< SCIP data structure */
2002  LPINPUT* lpinput /**< LP reading data */
2003  )
2004 {
2005  assert(lpinput != NULL);
2006 
2007  while( getNextToken(scip, lpinput) )
2008  {
2009  SCIP_VAR* var;
2010  SCIP_Real lb;
2011  SCIP_Real ub;
2012  SCIP_Bool created;
2013  SCIP_Bool infeasible;
2014 
2015  /* check if we reached a new section */
2016  if( isNewSection(scip, lpinput) )
2017  return SCIP_OKAY;
2018 
2019  /* the token must be the name of an existing variable */
2020  SCIP_CALL( getVariable(scip, lpinput->token, &var, &created) );
2021  if( created )
2022  {
2023  syntaxError(scip, lpinput, "unknown variable in binaries section.");
2024  return SCIP_OKAY;
2025  }
2026 
2027  lb = SCIPvarGetLbGlobal(var);
2028  ub = SCIPvarGetUbGlobal(var);
2029 
2030  if( (!SCIPisFeasZero(scip, lb) && !SCIPisFeasEQ(scip, lb, 1.0)) ||
2031  (!SCIPisFeasZero(scip, ub) && !SCIPisFeasEQ(scip, ub, 1.0) && !SCIPisInfinity(scip, ub)) )
2032  {
2033  SCIPwarningMessage(scip, "variable <%s> declared as binary has non-binary bounds[%.14g, %.14g] -> if feasible, bounds will be adjusted\n", SCIPvarGetName(var), lb, ub);
2034  }
2035 
2036  /* mark the variable to be binary and change its bounds appropriately */
2037  if( SCIPvarGetLbGlobal(var) < 0.0 )
2038  {
2039  SCIP_CALL( SCIPchgVarLb(scip, var, 0.0) );
2040  }
2041  if( SCIPvarGetUbGlobal(var) > 1.0 )
2042  {
2043  SCIP_CALL( SCIPchgVarUb(scip, var, 1.0) );
2044  }
2045  SCIP_CALL( SCIPchgVarType(scip, var, SCIP_VARTYPE_BINARY, &infeasible) );
2046  /* don't assert feasibility here because the presolver will and should detect a infeasibility */
2047  }
2048 
2049  return SCIP_OKAY;
2050 }
2051 
2052 /** reads the semi-continuous section */
2053 static
2055  SCIP* scip, /**< SCIP data structure */
2056  LPINPUT* lpinput /**< LP reading data */
2057  )
2058 {
2059  SCIP_Real oldlb;
2060  char name[SCIP_MAXSTRLEN];
2061  SCIP_CONS* cons;
2062  SCIP_VAR* var;
2063  SCIP_Bool created;
2064 
2065  SCIP_VAR* vars[2];
2066  SCIP_BOUNDTYPE boundtypes[2];
2067  SCIP_Real bounds[2];
2068 
2069  assert(lpinput != NULL);
2070 
2071  /* if section is titles "semi-continuous", then the parser breaks this into parts */
2072  if( strcasecmp(lpinput->token, "SEMI") == 0 )
2073  {
2074  if( !getNextToken(scip, lpinput) )
2075  {
2076  syntaxError(scip, lpinput, "unexpected end.");
2077  return SCIP_OKAY;
2078  }
2079 
2080  if( strcasecmp(lpinput->token, "-") == 0 )
2081  {
2082  if( !getNextToken(scip, lpinput) || strcasecmp(lpinput->token, "CONTINUOUS") != 0 )
2083  {
2084  syntaxError(scip, lpinput, "expected 'CONTINUOUS' after 'SEMI-'.");
2085  return SCIP_OKAY;
2086  }
2087  }
2088  else
2089  {
2090  pushToken(lpinput);
2091  }
2092  }
2093 
2094  while( getNextToken(scip, lpinput) )
2095  {
2096  /* check if we reached a new section */
2097  if( isNewSection(scip, lpinput) )
2098  return SCIP_OKAY;
2099 
2100  /* the token must be the name of an existing variable */
2101  SCIP_CALL( getVariable(scip, lpinput->token, &var, &created) );
2102  if( created )
2103  {
2104  syntaxError(scip, lpinput, "unknown variable in semi-continuous section.");
2105  return SCIP_OKAY;
2106  }
2107 
2108  if( SCIPvarGetLbGlobal(var) <= 0.0 )
2109  {
2110  SCIPdebugMsg(scip, "ignore semi-continuity of variable <%s> with negative lower bound %g\n", SCIPvarGetName(var), SCIPvarGetLbGlobal(var));
2111  continue;
2112  }
2113 
2114  oldlb = SCIPvarGetLbGlobal(var);
2115 
2116  /* change the lower bound to 0.0 */
2117  SCIP_CALL( SCIPchgVarLb(scip, var, 0.0) );
2118 
2119  /* add a bound disjunction constraint to say var <= 0.0 or var >= oldlb */
2120  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "semicont_%s", SCIPvarGetName(var));
2121 
2122  vars[0] = var;
2123  vars[1] = var;
2124  boundtypes[0] = SCIP_BOUNDTYPE_UPPER;
2125  boundtypes[1] = SCIP_BOUNDTYPE_LOWER;
2126  bounds[0] = 0.0;
2127  bounds[1] = oldlb;
2128 
2129  SCIP_CALL( SCIPcreateConsBounddisjunction(scip, &cons, name, 2, vars, boundtypes, bounds,
2130  !(lpinput->dynamiccols), TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, lpinput->dynamicconss, lpinput->dynamiccols, FALSE) );
2131  SCIP_CALL( SCIPaddCons(scip, cons) );
2132 
2133  SCIPdebugMsg(scip, "add bound disjunction constraint for semi-continuity of <%s>:\n\t", SCIPvarGetName(var));
2134  SCIPdebugPrintCons(scip, cons, NULL);
2135 
2136  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
2137  }
2138 
2139  return SCIP_OKAY;
2140 }
2141 
2142 /** reads the sos section
2143  *
2144  * The format is as follows:
2145  *
2146  * SOS
2147  * <constraint name>: [S1|S2]:: {<variable name>:<weight>}
2148  * ...
2149  * <constraint name>: [S1|S2]:: {<variable name>:<weight>}
2150  * */
2151 static
2153  SCIP* scip, /**< SCIP data structure */
2154  LPINPUT* lpinput /**< LP reading data */
2155  )
2156 {
2157  SCIP_Bool initial, separate, enforce, check, propagate;
2158  SCIP_Bool local, modifiable, dynamic, removable;
2159  char name[SCIP_MAXSTRLEN];
2160  int cnt = 0;
2161 
2162  assert(lpinput != NULL);
2163 
2164  /* standard settings for SOS constraints: */
2165  initial = lpinput->initialconss;
2166  separate = TRUE;
2167  enforce = TRUE;
2168  check = TRUE;
2169  propagate = TRUE;
2170  local = FALSE;
2171  modifiable = FALSE;
2172  dynamic = lpinput->dynamicconss;
2173  removable = lpinput->dynamicrows;
2174 
2175  while( getNextToken(scip, lpinput) )
2176  {
2177  int type = -1;
2178  SCIP_CONS* cons;
2179 
2180  /* check if we reached a new section */
2181  if( isNewSection(scip, lpinput) )
2182  return SCIP_OKAY;
2183 
2184  /* check for an SOS constraint name */
2185  *name = '\0';
2186 
2187  /* remember the token in the token buffer */
2188  swapTokenBuffer(lpinput);
2189 
2190  /* get the next token and check, whether it is a colon */
2191  if( getNextToken(scip, lpinput) )
2192  {
2193  if( strcmp(lpinput->token, ":") == 0 )
2194  {
2195  /* the second token was a colon: the first token is the constraint name */
2196  (void)SCIPmemccpy(name, lpinput->tokenbuf, '\0', SCIP_MAXSTRLEN);
2197 
2198  name[SCIP_MAXSTRLEN-1] = '\0';
2199  }
2200  else
2201  {
2202  /* the second token was no colon: push the tokens back onto the token stack and parse it next */
2203  pushToken(lpinput);
2204  pushBufferToken(lpinput);
2205  }
2206  }
2207  else
2208  {
2209  /* there was only one token left: push it back onto the token stack and parse it next */
2210  pushBufferToken(lpinput);
2211  }
2212 
2213  /* get type */
2214  if( !getNextToken(scip, lpinput) )
2215  {
2216  syntaxError(scip, lpinput, "expected SOS type: 'S1::' or 'S2::'.");
2217  return SCIP_OKAY;
2218  }
2219  /* check whether constraint name was left out */
2220  if( strcmp(lpinput->token, ":") == 0 )
2221  {
2222  /* we have to push twice ':' and once the type: */
2223  pushToken(lpinput);
2224  lpinput->token[0] = ':';
2225  lpinput->token[1] = '\0';
2226  pushToken(lpinput);
2227  swapTokenBuffer(lpinput);
2228 
2229  /* set artificial name */
2230  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "SOS%d", ++cnt);
2231  }
2232 
2233  /* check whether it is type 1 or type 2 */
2234  if( strcmp(lpinput->token, "S1") == 0 )
2235  {
2236  type = 1;
2237  SCIP_CALL( SCIPcreateConsSOS1(scip, &cons, name, 0, NULL, NULL, initial, separate, enforce, check, propagate,
2238  local, modifiable, dynamic, removable) );
2239  }
2240  else if( strcmp(lpinput->token, "S2") == 0 )
2241  {
2242  type = 2;
2243  SCIP_CALL( SCIPcreateConsSOS2(scip, &cons, name, 0, NULL, NULL, initial, separate, enforce, check, propagate,
2244  local, modifiable, dynamic, removable) );
2245  }
2246  else
2247  {
2248  syntaxError(scip, lpinput, "SOS constraint type other than 1 or 2 appeared.");
2249  return SCIP_OKAY;
2250  }
2251  assert( type == 1 || type == 2 );
2252 
2253  SCIPdebugMsg(scip, "created SOS%d constraint <%s>\n", type, name);
2254 
2255  /* make sure that a colons follows */
2256  if( !getNextToken(scip, lpinput) || strcmp(lpinput->token, ":") != 0 )
2257  {
2258  syntaxError(scip, lpinput, "SOS constraint type has to be followed by two colons.");
2259  return SCIP_OKAY;
2260  }
2261 
2262  /* make sure that another colons follows */
2263  if( !getNextToken(scip, lpinput) || strcmp(lpinput->token, ":") != 0 )
2264  {
2265  syntaxError(scip, lpinput, "SOS constraint type has to be followed by two colons.");
2266  return SCIP_OKAY;
2267  }
2268 
2269  /* parse elements of SOS constraint */
2270  while( getNextToken(scip, lpinput) )
2271  {
2272  SCIP_VAR* var;
2273  SCIP_Real weight;
2274 
2275  /* check if we reached a new section */
2276  if( isNewSection(scip, lpinput) )
2277  break;
2278 
2279  /* remember the token in the token buffer */
2280  swapTokenBuffer(lpinput);
2281 
2282  /* get variable and colon */
2283  var = SCIPfindVar(scip, lpinput->tokenbuf);
2284 
2285  /* if token is a variable name */
2286  if( var == NULL )
2287  {
2288  pushBufferToken(lpinput);
2289  break;
2290  }
2291  else
2292  {
2293  SCIPdebugMsg(scip, "found variable <%s>\n", SCIPvarGetName(var));
2294  if( !getNextToken(scip, lpinput) || strcmp(lpinput->token, ":") != 0 )
2295  {
2296  syntaxError(scip, lpinput, "expected colon and weight.");
2297  return SCIP_OKAY;
2298  }
2299  /* check next token */
2300  if( !getNextToken(scip, lpinput) )
2301  {
2302  /* push back token, since it could be the name of a new constraint */
2303  pushToken(lpinput);
2304  pushBufferToken(lpinput);
2305  break;
2306  }
2307  else
2308  {
2309  int sign = +1;
2310 
2311  /* get sign */
2312  if( isSign(lpinput, &sign) )
2313  {
2314  (void) getNextToken(scip, lpinput);
2315  }
2316 
2317  /* get weight */
2318  if( !isValue(scip, lpinput, &weight) )
2319  {
2320  /* push back token, since it could be the name of a new constraint */
2321  pushToken(lpinput);
2322  pushBufferToken(lpinput);
2323  break;
2324  }
2325  else
2326  {
2327  /* we now know that we have a variable/weight pair -> add variable*/
2328  switch( type )
2329  {
2330  case 1:
2331  SCIP_CALL( SCIPaddVarSOS1(scip, cons, var, sign * weight) );
2332  break;
2333  case 2:
2334  SCIP_CALL( SCIPaddVarSOS2(scip, cons, var, sign * weight) );
2335  break;
2336  default:
2337  SCIPerrorMessage("unknown SOS type: <%d>\n", type); /* should not happen */
2338  SCIPABORT();
2339  return SCIP_INVALIDDATA; /*lint !e527*/
2340  }
2341  SCIPdebugMsg(scip, "added variable <%s> with weight %g.\n", SCIPvarGetName(var), weight);
2342  }
2343  }
2344  }
2345  }
2346 
2347  /* add the SOS constraint */
2348  SCIP_CALL( SCIPaddCons(scip, cons) );
2349  SCIPdebugMsg(scip, "(line %d) added constraint <%s>: ", lpinput->linenumber, SCIPconsGetName(cons));
2350  SCIPdebugPrintCons(scip, cons, NULL);
2351  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
2352  }
2353 
2354  return SCIP_OKAY;
2355 }
2356 
2357 /** reads an LP file
2358  *
2359  * @todo check whether variables forced to be binary for the creation of indicator constraints are
2360  * really specified to be binary (or general with 0/1 bounds) in the file.
2361  */
2362 static
2364  SCIP* scip, /**< SCIP data structure */
2365  LPINPUT* lpinput, /**< LP reading data */
2366  const char* filename /**< name of the input file */
2367  )
2368 {
2369  assert(lpinput != NULL);
2370 
2371  /* open file */
2372  lpinput->file = SCIPfopen(filename, "r");
2373  if( lpinput->file == NULL )
2374  {
2375  SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
2376  SCIPprintSysError(filename);
2377  return SCIP_NOFILE;
2378  }
2379 
2380  /* create problem */
2381  SCIP_CALL( SCIPcreateProb(scip, filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
2382 
2383  /* parse the file */
2384  lpinput->section = LP_START;
2385  while( lpinput->section != LP_END && !hasError(lpinput) )
2386  {
2387  switch( lpinput->section )
2388  {
2389  case LP_START:
2390  SCIP_CALL( readStart(scip, lpinput) );
2391  break;
2392 
2393  case LP_OBJECTIVE:
2394  SCIP_CALL( readObjective(scip, lpinput) );
2395  break;
2396 
2397  case LP_CONSTRAINTS:
2398  SCIP_CALL( readConstraints(scip, lpinput) );
2399  break;
2400 
2401  case LP_BOUNDS:
2402  SCIP_CALL( readBounds(scip, lpinput) );
2403  break;
2404 
2405  case LP_GENERALS:
2406  SCIP_CALL( readGenerals(scip, lpinput) );
2407  break;
2408 
2409  case LP_BINARIES:
2410  SCIP_CALL( readBinaries(scip, lpinput) );
2411  break;
2412 
2413  case LP_SEMICONTINUOUS:
2414  SCIP_CALL( readSemicontinuous(scip, lpinput) );
2415  break;
2416 
2417  case LP_SOS:
2418  SCIP_CALL( readSos(scip, lpinput) );
2419  break;
2420 
2421  case LP_END: /* this is already handled in the while() loop */
2422  default:
2423  SCIPerrorMessage("invalid LP file section <%d>\n", lpinput->section);
2424  return SCIP_INVALIDDATA;
2425  }
2426  }
2427 
2428  /* close file */
2429  SCIPfclose(lpinput->file);
2430 
2431  return SCIP_OKAY;
2432 }
2433 
2434 
2435 /*
2436  * Local methods (for writing)
2437  */
2438 
2439 /** hash key retrieval function for variables */
2440 static
2441 SCIP_DECL_HASHGETKEY(hashGetKeyVar)
2442 { /*lint --e{715}*/
2443  return elem;
2444 }
2445 
2446 /** returns TRUE iff the indices of both variables are equal */
2447 static
2448 SCIP_DECL_HASHKEYEQ(hashKeyEqVar)
2449 { /*lint --e{715}*/
2450  if( key1 == key2 )
2451  return TRUE;
2452  return FALSE;
2453 }
2454 
2455 /** returns the hash value of the key */
2456 static
2457 SCIP_DECL_HASHKEYVAL(hashKeyValVar)
2458 { /*lint --e{715}*/
2459  assert( SCIPvarGetIndex((SCIP_VAR*) key) >= 0 );
2460  return (unsigned int) SCIPvarGetIndex((SCIP_VAR*) key);
2461 }
2462 
2463 
2464 #if 0
2465 /* prints variable name LP format conform; always use this method to stay consistent
2466  *
2467  * 1) variable names should not start with a digit
2468  * 2) avoid variable name starting with an 'e' or 'E' since this notation is reserved for exponential entries
2469  */
2470 static
2471 void printVarName(
2472  SCIP* scip, /**< SCIP data structure */
2473  FILE* file, /**< output file (or NULL for standard output) */
2474  SCIP_VAR* var, /**< variable */
2475  SCIP_Bool genericnames /**< use generic variable names? */
2476  )
2477 {
2478  const char* name;
2479 
2480  assert( scip != NULL );
2481  assert( var != NULL );
2482 
2483  name = SCIPvarGetName(var);
2484  assert( name != NULL );
2485 
2486  if( genericnames || name[0] == '\0' )
2487  SCIPinfoMessage(scip, file, "x%d", SCIPvarGetProbindex(var) + 1);
2488  else
2489  {
2490  if( isdigit((unsigned char)name[0]) || name[0] == 'e' || name[0] == 'E' )
2491  SCIPinfoMessage(scip, file, "_%s", name);
2492  else
2493  SCIPinfoMessage(scip, file, "%s", name);
2494  }
2495 }
2496 #endif
2497 
2498 /** transforms given variables, scalars, and constant to the corresponding active variables, scalars, and constant */
2499 static
2501  SCIP* scip, /**< SCIP data structure */
2502  SCIP_VAR*** vars, /**< pointer to vars array to get active variables for */
2503  SCIP_Real** scalars, /**< pointer to scalars a_1, ..., a_n in linear sum a_1*x_1 + ... + a_n*x_n + c */
2504  int* nvars, /**< pointer to number of variables and values in vars and vals array */
2505  SCIP_Real* constant, /**< pointer to constant c in linear sum a_1*x_1 + ... + a_n*x_n + c */
2506  SCIP_Bool transformed /**< transformed constraint? */
2507  )
2508 {
2509  int requiredsize;
2510  int v;
2511 
2512  assert(scip != NULL);
2513  assert(vars != NULL);
2514  assert(scalars != NULL);
2515  assert(*vars != NULL);
2516  assert(*scalars != NULL);
2517  assert(nvars != NULL);
2518  assert(constant != NULL);
2519 
2520  if( transformed )
2521  {
2522  SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
2523 
2524  if( requiredsize > *nvars )
2525  {
2526  SCIP_CALL( SCIPreallocBufferArray(scip, vars, requiredsize) );
2527  SCIP_CALL( SCIPreallocBufferArray(scip, scalars, requiredsize) );
2528 
2529  SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize, TRUE) );
2530  assert( requiredsize <= *nvars );
2531  }
2532  }
2533  else
2534  {
2535  for( v = 0; v < *nvars; ++v )
2536  {
2537  SCIP_CALL( SCIPvarGetOrigvarSum(&(*vars)[v], &(*scalars)[v], constant) );
2538 
2539  /* negated variables with an original counterpart may also be returned by SCIPvarGetOrigvarSum();
2540  * make sure we get the original variable in that case
2541  */
2542  if( SCIPvarGetStatus((*vars)[v]) == SCIP_VARSTATUS_NEGATED )
2543  {
2544  (*vars)[v] = SCIPvarGetNegatedVar((*vars)[v]);
2545  (*scalars)[v] *= -1.0;
2546  *constant += 1.0;
2547  }
2548  }
2549  }
2550  return SCIP_OKAY;
2551 }
2552 
2553 /** clears the given line buffer */
2554 static
2556  char* linebuffer, /**< line */
2557  int* linecnt /**< number of characters in line */
2558  )
2559 {
2560  assert( linebuffer != NULL );
2561  assert( linecnt != NULL );
2562 
2563  (*linecnt) = 0;
2564  linebuffer[0] = '\0';
2565 }
2566 
2567 /** ends the given line with '\\0' and prints it to the given file stream */
2568 static
2569 void endLine(
2570  SCIP* scip, /**< SCIP data structure */
2571  FILE* file, /**< output file (or NULL for standard output) */
2572  char* linebuffer, /**< line */
2573  int* linecnt /**< number of characters in line */
2574  )
2575 {
2576  assert( scip != NULL );
2577  assert( linebuffer != NULL );
2578  assert( linecnt != NULL );
2579 
2580  if( (*linecnt) > 0 )
2581  {
2582  linebuffer[(*linecnt)] = '\0';
2583  SCIPinfoMessage(scip, file, "%s\n", linebuffer);
2584  clearLine(linebuffer, linecnt);
2585  }
2586 }
2587 
2588 /** appends extension to line and prints it to the give file stream if the
2589  * line exceeded the length given in the define LP_PRINTLEN */
2590 static
2592  SCIP* scip, /**< SCIP data structure */
2593  FILE* file, /**< output file (or NULL for standard output) */
2594  char* linebuffer, /**< line */
2595  int* linecnt, /**< number of characters in line */
2596  const char* extension /**< string to extent the line */
2597  )
2598 {
2599  assert( scip != NULL );
2600  assert( linebuffer != NULL );
2601  assert( linecnt != NULL );
2602  assert( extension != NULL );
2603  assert( strlen(linebuffer) + strlen(extension) < LP_MAX_PRINTLEN );
2604 
2605  /* NOTE: avoid
2606  * sprintf(linebuffer, "%s%s", linebuffer, extension);
2607  * because of overlapping memory areas in memcpy used in sprintf.
2608  */
2609  strncat(linebuffer, extension, LP_MAX_PRINTLEN - strlen(linebuffer));
2610 
2611  (*linecnt) += (int) strlen(extension);
2612 
2613  SCIPdebugMsg(scip, "linebuffer <%s>, length = %lu\n", linebuffer, (unsigned long)strlen(linebuffer));
2614 
2615  if( (*linecnt) > LP_PRINTLEN )
2616  endLine(scip, file, linebuffer, linecnt);
2617 }
2618 
2619 
2620 /* print row in LP format to file stream */
2621 static
2623  SCIP* scip, /**< SCIP data structure */
2624  FILE* file, /**< output file (or NULL for standard output) */
2625  const char* rowname, /**< row name */
2626  const char* rownameextension, /**< row name extension */
2627  const char* type, /**< row type ("=", "<=", or ">=") */
2628  SCIP_VAR** linvars, /**< array of linear variables */
2629  SCIP_Real* linvals, /**< array of linear coefficient values */
2630  int nlinvars, /**< number of linear variables */
2631  SCIP_QUADVARTERM* quadvarterms, /**< quadratic variable terms */
2632  int nquadvarterms, /**< number of quadratic variable terms */
2633  SCIP_BILINTERM* bilinterms, /**< bilinear terms */
2634  int nbilinterms, /**< number of bilinear terms */
2635  SCIP_Real rhs /**< right hand side */
2636  )
2637 {
2638  int v;
2639  char linebuffer[LP_MAX_PRINTLEN] = { '\0' };
2640  int linecnt;
2641 
2642  SCIP_VAR* var;
2643  char varname[LP_MAX_NAMELEN];
2644  char varname2[LP_MAX_NAMELEN];
2645  char consname[LP_MAX_NAMELEN + 1]; /* an extra character for ':' */
2646  char buffer[LP_MAX_PRINTLEN];
2647 
2648  assert( scip != NULL );
2649  assert( strcmp(type, "=") == 0 || strcmp(type, "<=") == 0 || strcmp(type, ">=") == 0 );
2650  assert( nlinvars == 0 || (linvars != NULL && linvals != NULL) );
2651  assert( nquadvarterms == 0 || quadvarterms != NULL );
2652 
2653  /* if there is a bilinear term, then there need to be at least two quadratic variables */
2654  assert( nbilinterms == 0 || (bilinterms != NULL && nquadvarterms >= 2) );
2655 
2656  clearLine(linebuffer, &linecnt);
2657 
2658  /* start each line with a space */
2659  appendLine(scip, file, linebuffer, &linecnt, " ");
2660 
2661  /* print row name */
2662  if( strlen(rowname) > 0 || strlen(rownameextension) > 0 )
2663  {
2664  (void) SCIPsnprintf(consname, LP_MAX_NAMELEN + 1, "%s%s:", rowname, rownameextension);
2665  appendLine(scip, file, linebuffer, &linecnt, consname);
2666  }
2667 
2668  /* print coefficients */
2669  for( v = 0; v < nlinvars; ++v )
2670  {
2671  var = linvars[v];
2672  assert( var != NULL );
2673 
2674  /* we start a new line; therefore we tab this line */
2675  if( linecnt == 0 )
2676  appendLine(scip, file, linebuffer, &linecnt, " ");
2677 
2678  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var));
2679  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s", linvals[v], varname);
2680 
2681  appendLine(scip, file, linebuffer, &linecnt, buffer);
2682  }
2683 
2684  /* print quadratic part */
2685  if( nquadvarterms > 0 )
2686  {
2687  /* print linear coefficients of quadratic variables */
2688  for( v = 0; v < nquadvarterms; ++v )
2689  {
2690  if( quadvarterms[v].lincoef == 0.0 )
2691  continue;
2692 
2693  /* we start a new line; therefore we tab this line */
2694  if( linecnt == 0 )
2695  appendLine(scip, file, linebuffer, &linecnt, " ");
2696 
2697  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(quadvarterms[v].var));
2698  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s", quadvarterms[v].lincoef, varname);
2699 
2700  appendLine(scip, file, linebuffer, &linecnt, buffer);
2701  }
2702 
2703  /* start quadratic part */
2704  appendLine(scip, file, linebuffer, &linecnt, " + [");
2705 
2706  /* print square terms */
2707  for( v = 0; v < nquadvarterms; ++v )
2708  {
2709  if( quadvarterms[v].sqrcoef == 0.0 )
2710  continue;
2711 
2712  /* we start a new line; therefore we tab this line */
2713  if( linecnt == 0 )
2714  appendLine(scip, file, linebuffer, &linecnt, " ");
2715 
2716  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(quadvarterms[v].var));
2717  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s^2", quadvarterms[v].sqrcoef, varname);
2718 
2719  appendLine(scip, file, linebuffer, &linecnt, buffer);
2720  }
2721 
2722  /* print bilinear terms */
2723  for( v = 0; v < nbilinterms; ++v )
2724  {
2725  /* we start a new line; therefore we tab this line */
2726  if( linecnt == 0 )
2727  appendLine(scip, file, linebuffer, &linecnt, " ");
2728 
2729  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(bilinterms[v].var1));
2730  (void) SCIPsnprintf(varname2, LP_MAX_NAMELEN, "%s", SCIPvarGetName(bilinterms[v].var2));
2731  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s * %s", bilinterms[v].coef, varname, varname2);
2732 
2733  appendLine(scip, file, linebuffer, &linecnt, buffer);
2734  }
2735 
2736  /* end quadratic part */
2737  appendLine(scip, file, linebuffer, &linecnt, " ]");
2738  }
2739 
2740  /* print left hand side */
2741  if( SCIPisZero(scip, rhs) )
2742  rhs = 0.0;
2743 
2744  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %s %+.15g", type, rhs);
2745 
2746  /* we start a new line; therefore we tab this line */
2747  if( linecnt == 0 )
2748  appendLine(scip, file, linebuffer, &linecnt, " ");
2749  appendLine(scip, file, linebuffer, &linecnt, buffer);
2750 
2751  endLine(scip, file, linebuffer, &linecnt);
2752 }
2753 
2754 
2755 /** prints given (linear or) quadratic constraint information in LP format to file stream */
2756 static
2758  SCIP* scip, /**< SCIP data structure */
2759  FILE* file, /**< output file (or NULL for standard output) */
2760  const char* rowname, /**< name of the row */
2761  SCIP_VAR** linvars, /**< array of linear variables */
2762  SCIP_Real* linvals, /**< array of linear coefficients values (or NULL if all linear coefficient values are 1) */
2763  int nlinvars, /**< number of linear variables */
2764  SCIP_QUADVARTERM* quadvarterms, /**< quadratic variable terms */
2765  int nquadvarterms, /**< number of quadratic variable terms */
2766  SCIP_BILINTERM* bilinterms, /**< bilinear terms */
2767  int nbilinterms, /**< number of bilinear terms */
2768  SCIP_Real lhs, /**< left hand side */
2769  SCIP_Real rhs, /**< right hand side */
2770  SCIP_Bool transformed /**< transformed constraint? */
2771  )
2772 {
2773  int v;
2774  SCIP_VAR** activevars = NULL;
2775  SCIP_Real* activevals = NULL;
2776  int nactivevars;
2777  SCIP_Real activeconstant = 0.0;
2778 
2779  assert( scip != NULL );
2780  assert( rowname != NULL );
2781 
2782  /* The LP format does not forbid that the variable array is empty */
2783  assert( nlinvars == 0 || linvars != NULL );
2784  assert( nquadvarterms == 0 || quadvarterms != NULL );
2785  assert( nbilinterms == 0 || bilinterms != NULL );
2786 
2787  assert( lhs <= rhs );
2788 
2789  if( SCIPisInfinity(scip, -lhs) && SCIPisInfinity(scip, rhs) )
2790  return SCIP_OKAY;
2791 
2792  nactivevars = nlinvars;
2793  if( nlinvars > 0 )
2794  {
2795  /* duplicate variable and value array */
2796  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, linvars, nactivevars ) );
2797  if( linvals != NULL )
2798  {
2799  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, linvals, nactivevars ) );
2800  }
2801  else
2802  {
2803  SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );
2804 
2805  for( v = 0; v < nactivevars; ++v )
2806  activevals[v] = 1.0;
2807  }
2808 
2809  /* retransform given variables to active variables */
2810  SCIP_CALL( getActiveVariables(scip, &activevars, &activevals, &nactivevars, &activeconstant, transformed) );
2811  }
2812 
2813  /* print row(s) in LP format */
2814  if( SCIPisEQ(scip, lhs, rhs) )
2815  {
2816  assert( !SCIPisInfinity(scip, rhs) );
2817 
2818  /* equal constraint */
2819  printRow(scip, file, rowname, "", "=", activevars, activevals, nactivevars,
2820  quadvarterms, nquadvarterms, bilinterms, nbilinterms,
2821  rhs - activeconstant);
2822  }
2823  else
2824  {
2825  if( !SCIPisInfinity(scip, -lhs) )
2826  {
2827  /* print inequality ">=" */
2828  printRow(scip, file, rowname, SCIPisInfinity(scip, rhs) ? "" : "_lhs", ">=",
2829  activevars, activevals, nactivevars,
2830  quadvarterms, nquadvarterms, bilinterms, nbilinterms,
2831  lhs - activeconstant);
2832  }
2833  if( !SCIPisInfinity(scip, rhs) )
2834  {
2835  /* print inequality "<=" */
2836  printRow(scip, file, rowname, SCIPisInfinity(scip, -lhs) ? "" : "_rhs", "<=",
2837  activevars, activevals, nactivevars,
2838  quadvarterms, nquadvarterms, bilinterms, nbilinterms,
2839  rhs - activeconstant);
2840  }
2841  }
2842 
2843  if( nlinvars > 0 )
2844  {
2845  /* free buffer arrays */
2846  SCIPfreeBufferArray(scip, &activevars);
2847  SCIPfreeBufferArray(scip, &activevals);
2848  }
2849 
2850  return SCIP_OKAY;
2851 }
2852 
2853 
2854 /** prints given SOS constraint information in LP format to file stream */
2855 static
2857  SCIP* scip, /**< SCIP data structure */
2858  FILE* file, /**< output file (or NULL for standard output) */
2859  const char* rowname, /**< name of the row */
2860  SCIP_VAR** vars, /**< array of variables */
2861  SCIP_Real* weights, /**< array of weight values (or NULL) */
2862  int nvars, /**< number of variables */
2863  int type /**< SOS type (SOS1 or SOS2) */
2864  )
2865 {
2866  int v;
2867 
2868  char linebuffer[LP_MAX_PRINTLEN];
2869  int linecnt;
2870  char buffer[LP_MAX_PRINTLEN];
2871  char varname[LP_MAX_NAMELEN];
2872 
2873  assert( scip != NULL );
2874  assert( file != NULL );
2875  assert( type == 1 || type == 2 );
2876 
2877  clearLine(linebuffer, &linecnt);
2878 
2879  /* start each line with a space */
2880  appendLine(scip, file, linebuffer, &linecnt, " ");
2881  assert( strlen(rowname) < LP_MAX_NAMELEN );
2882 
2883  if( strlen(rowname) > 0 )
2884  {
2885  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, "%s:", rowname);
2886  appendLine(scip, file, linebuffer, &linecnt, buffer);
2887  }
2888 
2889  /* SOS type */
2890  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " S%d::", type);
2891  appendLine(scip, file, linebuffer, &linecnt, buffer);
2892 
2893  for( v = 0; v < nvars; ++v )
2894  {
2895  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(vars[v]));
2896 
2897  if( weights != NULL )
2898  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %s:%.15g", varname, weights[v]);
2899  else
2900  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %s:%d", varname, v);
2901 
2902  if(linecnt == 0 )
2903  {
2904  /* we start a new line; therefore we tab this line */
2905  appendLine(scip, file, linebuffer, &linecnt, " ");
2906  }
2907  appendLine(scip, file, linebuffer, &linecnt, buffer);
2908  }
2909 
2910  endLine(scip, file, linebuffer, &linecnt);
2911 }
2912 
2913 /** prints given soc constraint in LP format to file stream */
2914 static
2916  SCIP* scip, /**< SCIP data structure */
2917  FILE* file, /**< output file (or NULL for standard output) */
2918  const char* rowname, /**< name of the row */
2919  SCIP_CONS* cons /**< second order cone constraint */
2920  )
2921 {
2922  int v;
2923  char linebuffer[LP_MAX_PRINTLEN] = { '\0' };
2924  int linecnt;
2925  SCIP_VAR* var;
2926  SCIP_Real coef;
2927  SCIP_Real offset;
2928  char varname[LP_MAX_NAMELEN];
2929  char consname[LP_MAX_NAMELEN + 1]; /* an extra character for ':' */
2930  char buffer[LP_MAX_PRINTLEN];
2931 
2932  SCIP_Real rhs;
2933 
2934  assert( scip != NULL );
2935  assert( rowname != NULL );
2936  assert( cons != NULL );
2937 
2938  /* print constraint in LP format
2939  * the SOC constraint is given as
2940  * sqrt(constant + sum_i (lhscoef_i(lhsvar_i+lhsoffset_i))^2) <= rhscoef(rhsvar+rhsoffset)
2941  * and is printed as
2942  * sum_i (2*lhscoef_i^2 lhs_offset_i) lhsvar_i - (2 * rhscoef^2 * rhsoffset) rhsvar
2943  * + [ sum_i lhscoef_i^2 lhsvar_i^2 - rhscoef^2 rhsvar^2 ]
2944  * <=
2945  * - sum_i lhscoef_i^2 lhs_offset_i^2 - constant + rhscoef^2 rhsoffset^2
2946  */
2947 
2948  clearLine(linebuffer, &linecnt);
2949 
2950  /* start each line with a space */
2951  appendLine(scip, file, linebuffer, &linecnt, " ");
2952 
2953  /* print row name */
2954  if( strlen(rowname) > 0 )
2955  {
2956  (void) SCIPsnprintf(consname, LP_MAX_NAMELEN + 1, "%s:", rowname);
2957  appendLine(scip, file, linebuffer, &linecnt, consname);
2958  }
2959 
2960  rhs = -SCIPgetLhsConstantSOC(scip, cons);
2961 
2962  /* print linear part of left hand side and add constant parts to rhs */
2963  for( v = 0; v < SCIPgetNLhsVarsSOC(scip, cons); ++v )
2964  {
2965  var = SCIPgetLhsVarsSOC(scip, cons)[v];
2966  assert( var != NULL );
2967  offset = SCIPgetLhsOffsetsSOC(scip, cons)[v];
2968  coef = SCIPgetLhsCoefsSOC(scip, cons)[v];
2969 
2970  rhs -= coef * coef * offset * offset;
2971 
2972  if( offset == 0.0 || coef == 0.0 )
2973  continue;
2974 
2975  /* we start a new line; therefore we tab this line */
2976  if( linecnt == 0 )
2977  appendLine(scip, file, linebuffer, &linecnt, " ");
2978 
2979  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var));
2980  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s", 2*offset*coef*coef, varname);
2981 
2982  appendLine(scip, file, linebuffer, &linecnt, buffer);
2983  }
2984 
2985  /* print linear part from right hand side and add constant part to rhs */
2986  offset = SCIPgetRhsOffsetSOC(scip, cons);
2987  coef = SCIPgetRhsCoefSOC(scip, cons);
2988  if( offset != 0.0 && coef != 0.0 )
2989  {
2990  var = SCIPgetRhsVarSOC(scip, cons);
2991  assert( var != NULL );
2992 
2993  rhs += coef * coef * offset * offset;
2994 
2995  if( linecnt == 0 )
2996  appendLine(scip, file, linebuffer, &linecnt, " ");
2997 
2998  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var));
2999  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s", -2*offset*coef*coef, varname);
3000 
3001  appendLine(scip, file, linebuffer, &linecnt, buffer);
3002  }
3003 
3004  /* start quadratic part */
3005  appendLine(scip, file, linebuffer, &linecnt, " + [");
3006 
3007  /* print quadratic part of left hand side */
3008  for( v = 0; v < SCIPgetNLhsVarsSOC(scip, cons); ++v )
3009  {
3010  var = SCIPgetLhsVarsSOC(scip, cons)[v];
3011  assert( var != NULL );
3012  coef = SCIPgetLhsCoefsSOC(scip, cons)[v];
3013 
3014  if( coef == 0.0 )
3015  continue;
3016 
3017  /* we start a new line; therefore we tab this line */
3018  if( linecnt == 0 )
3019  appendLine(scip, file, linebuffer, &linecnt, " ");
3020 
3021  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var));
3022  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s^2", coef*coef, varname);
3023 
3024  appendLine(scip, file, linebuffer, &linecnt, buffer);
3025  }
3026 
3027  /* print quadratic part of right hand side */
3028  coef = SCIPgetRhsCoefSOC(scip, cons);
3029  if( coef != 0.0 )
3030  {
3031  var = SCIPgetRhsVarSOC(scip, cons);
3032  assert( var != NULL );
3033 
3034  /* we start a new line; therefore we tab this line */
3035  if( linecnt == 0 )
3036  appendLine(scip, file, linebuffer, &linecnt, " ");
3037 
3038  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var));
3039  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s^2", -coef*coef, varname);
3040 
3041  appendLine(scip, file, linebuffer, &linecnt, buffer);
3042  }
3043 
3044  /* end quadratic part */
3045  appendLine(scip, file, linebuffer, &linecnt, " ]");
3046 
3047  /* print right hand side */
3048  if( SCIPisZero(scip, rhs) )
3049  rhs = 0.0;
3050 
3051  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " <= %+.15g", rhs);
3052 
3053  /* we start a new line; therefore we tab this line */
3054  if( linecnt == 0 )
3055  appendLine(scip, file, linebuffer, &linecnt, " ");
3056  appendLine(scip, file, linebuffer, &linecnt, buffer);
3057 
3058  endLine(scip, file, linebuffer, &linecnt);
3059 
3060  return SCIP_OKAY;
3061 }
3062 
3063 /** prints a linearization of an and-constraint into the given file */
3064 static
3066  SCIP* scip, /**< SCIP data structure */
3067  FILE* file, /**< output file (or NULL for standard output) */
3068  const char* consname, /**< name of the constraint */
3069  SCIP_CONS* cons, /**< and constraint */
3070  SCIP_Bool aggrlinearizationands,/**< print weak or strong realaxation */
3071  SCIP_Bool transformed /**< transformed constraint? */
3072  )
3073 {
3074  SCIP_VAR** vars;
3075  SCIP_VAR** operands;
3076  SCIP_VAR* resultant;
3077  SCIP_Real* vals;
3078  char rowname[LP_MAX_NAMELEN];
3079  int nvars;
3080  int v;
3081 
3082  assert(scip != NULL);
3083  assert(consname != NULL);
3084  assert(cons != NULL);
3085 
3086  nvars = SCIPgetNVarsAnd(scip, cons);
3087  operands = SCIPgetVarsAnd(scip, cons);
3088  resultant = SCIPgetResultantAnd(scip, cons);
3089 
3090  /* allocate buffer array */
3091  SCIP_CALL( SCIPallocBufferArray(scip, &vars, nvars + 1) );
3092  SCIP_CALL( SCIPallocBufferArray(scip, &vals, nvars + 1) );
3093 
3094  /* the tight relaxtion, number of and-constraint operands rows */
3095  if( !aggrlinearizationands )
3096  {
3097  vars[0] = resultant;
3098  vals[0] = 1.0;
3099  vals[1] = -1.0;
3100 
3101  /* print operator rows */
3102  for( v = 0; v < nvars; ++v )
3103  {
3104  (void) SCIPsnprintf(rowname, LP_MAX_NAMELEN, "%s_%d", consname, v);
3105  vars[1] = operands[v];
3106 
3107  /* print for each operator a row */
3108  SCIP_CALL( printQuadraticCons(scip, file, rowname,
3109  vars, vals, 2, NULL, 0, NULL, 0, -SCIPinfinity(scip), 0.0, transformed) );
3110  }
3111  }
3112 
3113  /* prepare for next row */
3114  for( v = nvars - 1; v >= 0; --v )
3115  {
3116  vars[v] = operands[v];
3117  vals[v] = -1.0;
3118  }
3119 
3120  vars[nvars] = resultant;
3121 
3122  /* the weak relaxtion, only one constraint */
3123  if( aggrlinearizationands )
3124  {
3125  /* adjust rowname of constraint */
3126  (void) SCIPsnprintf(rowname, LP_MAX_NAMELEN, "%s_operators", consname);
3127 
3128  vals[nvars] = (SCIP_Real) nvars;
3129 
3130  /* print aggregated operator row */
3131  SCIP_CALL( printQuadraticCons(scip, file, rowname,
3132  vars, vals, nvars + 1, NULL, 0, NULL, 0, -SCIPinfinity(scip), 0.0, transformed) );
3133  }
3134 
3135  /* create additional linear constraint */
3136  (void) SCIPsnprintf(rowname, LP_MAX_NAMELEN, "%s_add", consname);
3137 
3138  vals[nvars] = 1.0;
3139 
3140  SCIP_CALL( printQuadraticCons(scip, file, rowname,
3141  vars, vals, nvars + 1, NULL, 0, NULL, 0, -nvars + 1.0, SCIPinfinity(scip), transformed) );
3142 
3143  /* free buffer array */
3144  SCIPfreeBufferArray(scip, &vals);
3145  SCIPfreeBufferArray(scip, &vars);
3146 
3147  return SCIP_OKAY;
3148 }
3149 
3150 /** check whether given variables are aggregated and put them into an array without duplication */
3151 static
3153  SCIP* scip, /**< SCIP data structure */
3154  SCIP_VAR** vars, /**< variable array */
3155  int nvars, /**< number of active variables in the problem */
3156  SCIP_VAR*** aggvars, /**< pointer to array storing the aggregated variables on output */
3157  int* naggvars, /**< pointer to number of aggregated variables on output */
3158  int* saggvars, /**< pointer to number of slots in aggvars array */
3159  SCIP_HASHTABLE* varAggregated /**< hashtable for checking duplicates */
3160  )
3161 {
3162  int v;
3163 
3164  assert( scip != NULL );
3165  assert( aggvars != NULL );
3166  assert( naggvars != NULL );
3167  assert( saggvars != NULL );
3168 
3169  /* check variables */
3170  for( v = 0; v < nvars; ++v )
3171  {
3172  SCIP_VARSTATUS status;
3173  SCIP_VAR* var;
3174 
3175  var = vars[v];
3176  status = SCIPvarGetStatus(var);
3177 
3178  /* collect aggregated variables in a list */
3179  if( status >= SCIP_VARSTATUS_AGGREGATED )
3180  {
3181  assert( status == SCIP_VARSTATUS_AGGREGATED || status == SCIP_VARSTATUS_MULTAGGR || status == SCIP_VARSTATUS_NEGATED );
3182  assert( varAggregated != NULL );
3183 
3184  if( ! SCIPhashtableExists(varAggregated, (void*) var) )
3185  {
3186  /* possibly enlarge array */
3187  if ( *saggvars <= *naggvars )
3188  {
3189  int newsize;
3190  newsize = SCIPcalcMemGrowSize(scip, *naggvars + 1);
3191  assert( newsize > *saggvars );
3192  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &aggvars, *saggvars, newsize) );
3193  *saggvars = newsize;
3194  }
3195 
3196  (*aggvars)[*naggvars] = var;
3197  (*naggvars)++;
3198  SCIP_CALL( SCIPhashtableInsert(varAggregated, (void*) var) );
3199  assert( *naggvars <= *saggvars );
3200  }
3201  }
3202  }
3203  return SCIP_OKAY;
3204 }
3205 
3206 /** print aggregated variable-constraints */
3207 static
3209  SCIP* scip, /**< SCIP data structure */
3210  FILE* file, /**< output file (or NULL for standard output) */
3211  SCIP_Bool transformed, /**< TRUE iff problem is the transformed problem */
3212  int nvars, /**< number of active variables in the problem */
3213  int nAggregatedVars, /**< number of aggregated variables */
3214  SCIP_VAR** aggregatedVars /**< array storing the aggregated variables */
3215  )
3216 {
3217  int j;
3218 
3219  SCIP_VAR** activevars;
3220  SCIP_Real* activevals;
3221  int nactivevars;
3222  SCIP_Real activeconstant = 0.0;
3223  char consname[LP_MAX_NAMELEN];
3224 
3225  assert( scip != NULL );
3226 
3227  /* write aggregation constraints */
3228  SCIP_CALL( SCIPallocBufferArray(scip, &activevars, nvars) );
3229  SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nvars) );
3230 
3231  for( j = 0; j < nAggregatedVars; ++j )
3232  {
3233  /* set up list to obtain substitution variables */
3234  nactivevars = 1;
3235 
3236  activevars[0] = aggregatedVars[j];
3237  activevals[0] = 1.0;
3238  activeconstant = 0.0;
3239 
3240  /* retransform given variables to active variables */
3241  SCIP_CALL( getActiveVariables(scip, &activevars, &activevals, &nactivevars, &activeconstant, transformed) );
3242 
3243  activevals[nactivevars] = -1.0;
3244  activevars[nactivevars] = aggregatedVars[j];
3245  ++nactivevars;
3246 
3247  /* output constraint */
3248  (void) SCIPsnprintf(consname, LP_MAX_NAMELEN, "aggr_%s", SCIPvarGetName(aggregatedVars[j]));
3249  printRow(scip, file, consname, "", "=", activevars, activevals, nactivevars, NULL, 0, NULL, 0, - activeconstant);
3250  }
3251 
3252  /* free buffer arrays */
3253  SCIPfreeBufferArray(scip, &activevars);
3254  SCIPfreeBufferArray(scip, &activevals);
3255 
3256  return SCIP_OKAY;
3257 }
3258 
3259 /** method check if the variable names are not longer than LP_MAX_NAMELEN */
3260 static
3262  SCIP* scip, /**< SCIP data structure */
3263  SCIP_VAR** vars, /**< array of variables */
3264  int nvars /**< number of variables */
3265  )
3266 {
3267  SCIP_Bool printwarning;
3268  int v;
3269 
3270  assert(scip != NULL);
3271  assert(vars != NULL || nvars == 0);
3272 
3273  printwarning = TRUE;
3274 
3275  /* check if the variable names are not to long */
3276  for( v = 0; v < nvars; ++v )
3277  {
3278  if( strlen(SCIPvarGetName(vars[v])) > LP_MAX_NAMELEN ) /*lint !e613*/
3279  {
3280  SCIPwarningMessage(scip, "there is a variable name which has to be cut down to %d characters; LP might be corrupted\n",
3281  LP_MAX_NAMELEN - 1);
3282  return;
3283  }
3284 
3285  /* check if variable name starts with a digit */
3286  if( printwarning && isdigit((unsigned char)SCIPvarGetName(vars[v])[0]) ) /*lint !e613*/
3287  {
3288  SCIPwarningMessage(scip, "violation of LP format - a variable name starts with a digit; " \
3289  "it is not possible to read the generated LP file with SCIP; " \
3290  "use write/genproblem or write/gentransproblem for generic variable names\n");
3291  printwarning = FALSE;
3292  }
3293  }
3294 }
3295 
3296 /** method check if the constraint names are not longer than LP_MAX_NAMELEN */
3297 static
3299  SCIP* scip, /**< SCIP data structure */
3300  SCIP_CONS** conss, /**< array of constraints */
3301  int nconss, /**< number of constraints */
3302  SCIP_Bool transformed /**< TRUE iff problem is the transformed problem */
3303  )
3304 {
3305  int c;
3306  SCIP_CONS* cons;
3307  SCIP_CONSHDLR* conshdlr;
3308  const char* conshdlrname;
3309  SCIP_Bool printwarning;
3310 
3311  assert( scip != NULL );
3312  assert( conss != NULL || nconss == 0 );
3313 
3314  printwarning = TRUE;
3315 
3316  for( c = 0; c < nconss; ++c )
3317  {
3318  int len;
3319 
3320  assert(conss != NULL); /* for lint */
3321  cons = conss[c];
3322  assert(cons != NULL );
3323 
3324  /* in case the transformed is written only constraints are posted which are enabled in the current node */
3325  assert(!transformed || SCIPconsIsEnabled(cons));
3326 
3327  conshdlr = SCIPconsGetHdlr(cons);
3328  assert( conshdlr != NULL );
3329 
3330  conshdlrname = SCIPconshdlrGetName(conshdlr);
3331  assert( transformed == SCIPconsIsTransformed(cons) );
3332 
3333  len = (int) strlen(SCIPconsGetName(cons));
3334 
3335  if( strcmp(conshdlrname, "linear") == 0 )
3336  {
3337  SCIP_Real lhs = SCIPgetLhsLinear(scip, cons);
3338  SCIP_Real rhs = SCIPgetLhsLinear(scip, cons);
3339 
3340  if( (SCIPisEQ(scip, lhs, rhs) && len > LP_MAX_NAMELEN) || ( !SCIPisEQ(scip, lhs, rhs) && len > LP_MAX_NAMELEN - 4) )
3341  {
3342  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n", LP_MAX_NAMELEN - 1);
3343  return;
3344  }
3345  }
3346  else if( len > LP_MAX_NAMELEN )
3347  {
3348  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n", LP_MAX_NAMELEN - 1);
3349  return;
3350  }
3351 
3352  /* check if constraint name starts with a digit */
3353  if( printwarning && isdigit((unsigned char)SCIPconsGetName(cons)[0]) )
3354  {
3355  SCIPwarningMessage(scip, "violation of LP format - a constraint name starts with a digit; " \
3356  "it is not possible to read the generated LP file with SCIP; " \
3357  "use write/genproblem or write/gentransproblem for generic variable names\n");
3358  printwarning = FALSE;
3359  }
3360  }
3361 }
3362 
3363 /*
3364  * Callback methods of reader
3365  */
3366 
3367 /** copy method for reader plugins (called when SCIP copies plugins) */
3368 static
3370 { /*lint --e{715}*/
3371  assert(scip != NULL);
3372  assert(reader != NULL);
3373  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
3374 
3375  /* call inclusion method of reader */
3376  SCIP_CALL( SCIPincludeReaderLp(scip) );
3377 
3378  return SCIP_OKAY;
3379 }
3380 
3381 /** destructor of reader to free user data (called when SCIP is exiting) */
3382 static
3384 {
3385  SCIP_READERDATA* readerdata;
3386 
3387  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
3388  readerdata = SCIPreaderGetData(reader);
3389  assert(readerdata != NULL);
3390  SCIPfreeBlockMemory(scip, &readerdata);
3391 
3392  return SCIP_OKAY;
3393 }
3394 
3395 /** problem reading method of reader */
3396 static
3398 { /*lint --e{715}*/
3399 
3400  SCIP_CALL( SCIPreadLp(scip, reader, filename, result) );
3401 
3402  return SCIP_OKAY;
3403 }
3404 
3405 
3406 /** problem writing method of reader */
3407 static
3409 { /*lint --e{715}*/
3410  assert(reader != NULL);
3411  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
3412 
3413  SCIP_CALL( SCIPwriteLp(scip, file, name, transformed, objsense, objscale, objoffset, vars,
3414  nvars, nbinvars, nintvars, nimplvars, ncontvars, conss, nconss, result) );
3415 
3416  return SCIP_OKAY;
3417 }
3418 
3419 
3420 /*
3421  * reader specific interface methods
3422  */
3423 
3424 /** includes the lp file reader in SCIP */
3426  SCIP* scip /**< SCIP data structure */
3427  )
3428 {
3429  SCIP_READERDATA* readerdata;
3430  SCIP_READER* reader;
3431 
3432  /* create reader data */
3433  SCIP_CALL( SCIPallocBlockMemory(scip, &readerdata) );
3434 
3435  /* include reader */
3436  SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
3437 
3438  /* set non fundamental callbacks via setter functions */
3439  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyLp) );
3440  SCIP_CALL( SCIPsetReaderFree(scip, reader, readerFreeLp) );
3441  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadLp) );
3442  SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWriteLp) );
3443 
3444  /* add lp-reader parameters */
3446  "reading/" READER_NAME "/linearize-and-constraints",
3447  "should possible \"and\" constraint be linearized when writing the lp file?",
3448  &readerdata->linearizeands, TRUE, DEFAULT_LINEARIZE_ANDS, NULL, NULL) );
3450  "reading/" READER_NAME "/aggrlinearization-ands",
3451  "should an aggregated linearization for and constraints be used?",
3452  &readerdata->aggrlinearizationands, TRUE, DEFAULT_AGGRLINEARIZATION_ANDS, NULL, NULL) );
3453 
3454  return SCIP_OKAY;
3455 }
3456 
3457 
3458 /** reads problem from file */
3460  SCIP* scip, /**< SCIP data structure */
3461  SCIP_READER* reader, /**< the file reader itself */
3462  const char* filename, /**< full path and name of file to read, or NULL if stdin should be used */
3463  SCIP_RESULT* result /**< pointer to store the result of the file reading call */
3464  )
3465 { /*lint --e{715}*/
3466  SCIP_RETCODE retcode;
3467  LPINPUT lpinput;
3468  int i;
3469 
3470  /* initialize LP input data */
3471  lpinput.file = NULL;
3472  lpinput.linebuf[0] = '\0';
3473  lpinput.probname[0] = '\0';
3474  lpinput.objname[0] = '\0';
3475  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &lpinput.token, LP_MAX_LINELEN) ); /*lint !e506*/
3476  lpinput.token[0] = '\0';
3477  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &lpinput.tokenbuf, LP_MAX_LINELEN) ); /*lint !e506*/
3478  lpinput.tokenbuf[0] = '\0';
3479  for( i = 0; i < LP_MAX_PUSHEDTOKENS; ++i )
3480  {
3481  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &(lpinput.pushedtokens[i]), LP_MAX_LINELEN) ); /*lint !e866 !e506*/
3482  }
3483 
3484  lpinput.npushedtokens = 0;
3485  lpinput.linenumber = 0;
3486  lpinput.linepos = 0;
3487  lpinput.section = LP_START;
3488  lpinput.objsense = SCIP_OBJSENSE_MINIMIZE;
3489  lpinput.inlazyconstraints = FALSE;
3490  lpinput.inusercuts = FALSE;
3491  lpinput.haserror = FALSE;
3492  lpinput.comment = FALSE;
3493  lpinput.endline = FALSE;
3494 
3495  SCIP_CALL( SCIPgetBoolParam(scip, "reading/initialconss", &(lpinput.initialconss)) );
3496  SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamicconss", &(lpinput.dynamicconss)) );
3497  SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamiccols", &(lpinput.dynamiccols)) );
3498  SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamicrows", &(lpinput.dynamicrows)) );
3499 
3500  /* read the file */
3501  retcode = readLPFile(scip, &lpinput, filename);
3502 
3503  /* free dynamically allocated memory */
3504  for( i = 0; i < LP_MAX_PUSHEDTOKENS; ++i )
3505  {
3506  SCIPfreeBlockMemoryArray(scip, &lpinput.pushedtokens[i], LP_MAX_LINELEN);
3507  }
3508  SCIPfreeBlockMemoryArray(scip, &lpinput.tokenbuf, LP_MAX_LINELEN);
3509  SCIPfreeBlockMemoryArray(scip, &lpinput.token, LP_MAX_LINELEN);
3510 
3511  if( retcode == SCIP_PLUGINNOTFOUND )
3512  retcode = SCIP_READERROR;
3513 
3514  /* check for correct return value */
3515  SCIP_CALL( retcode );
3516 
3517  /* evaluate the result */
3518  if( lpinput.haserror )
3519  return SCIP_READERROR;
3520  else
3521  {
3522  /* set objective sense */
3523  SCIP_CALL( SCIPsetObjsense(scip, lpinput.objsense) );
3524  *result = SCIP_SUCCESS;
3525  }
3526 
3527  return SCIP_OKAY;
3528 }
3529 
3530 
3531 /** writes problem to file */
3533  SCIP* scip, /**< SCIP data structure */
3534  FILE* file, /**< output file, or NULL if standard output should be used */
3535  const char* name, /**< problem name */
3536  SCIP_Bool transformed, /**< TRUE iff problem is the transformed problem */
3537  SCIP_OBJSENSE objsense, /**< objective sense */
3538  SCIP_Real objscale, /**< scalar applied to objective function; external objective value is
3539  * extobj = objsense * objscale * (intobj + objoffset) */
3540  SCIP_Real objoffset, /**< objective offset from bound shifting and fixing */
3541  SCIP_VAR** vars, /**< array with active variables ordered binary, integer, implicit, continuous */
3542  int nvars, /**< number of active variables in the problem */
3543  int nbinvars, /**< number of binary variables */
3544  int nintvars, /**< number of general integer variables */
3545  int nimplvars, /**< number of implicit integer variables */
3546  int ncontvars, /**< number of continuous variables */
3547  SCIP_CONS** conss, /**< array with constraints of the problem */
3548  int nconss, /**< number of constraints in the problem */
3549  SCIP_RESULT* result /**< pointer to store the result of the file writing call */
3550  )
3551 {
3552  SCIP_READER* reader;
3553  SCIP_READERDATA* readerdata;
3554  SCIP_Bool linearizeands;
3555  SCIP_Bool aggrlinearizationands;
3556  int c;
3557  int v;
3558 
3559  int linecnt;
3560  char linebuffer[LP_MAX_PRINTLEN];
3561 
3562  char varname[LP_MAX_NAMELEN];
3563  char buffer[LP_MAX_PRINTLEN];
3564 
3565  SCIP_CONSHDLR* conshdlr;
3566  SCIP_CONSHDLR* conshdlrInd;
3567  const char* conshdlrname;
3568  SCIP_CONS* cons;
3569  SCIP_CONS** consSOS1;
3570  SCIP_CONS** consSOS2;
3571  SCIP_CONS** consQuadratic;
3572  SCIP_CONS** consSOC;
3573  SCIP_CONS** consIndicator;
3574  int nConsSOS1 = 0;
3575  int nConsSOS2 = 0;
3576  int nConsQuadratic = 0;
3577  int nConsSOC = 0;
3578  int nConsIndicator = 0;
3579  char consname[LP_MAX_NAMELEN];
3580 
3581  SCIP_VAR** aggvars;
3582  int naggvars = 0;
3583  int saggvars;
3584  SCIP_HASHTABLE* varAggregated;
3585  SCIP_HASHMAP* consHidden;
3586 
3587  SCIP_VAR** consvars;
3588  SCIP_Real* consvals;
3589  int nconsvars;
3590 
3591  SCIP_VAR* var;
3592  SCIP_Real lb;
3593  SCIP_Real ub;
3594 
3595  assert(scip != NULL);
3596 
3597  /* find indicator constraint handler */
3598  conshdlrInd = SCIPfindConshdlr(scip, "indicator");
3599  consHidden = NULL;
3600 
3601  /* if indicator constraint handler is present */
3602  if( conshdlrInd != NULL )
3603  {
3604  /* create hashtable storing linear constraints that should not be output */
3605  SCIP_CALL( SCIPhashmapCreate(&consHidden, SCIPblkmem(scip), 500) );
3606 
3607  /* loop through indicator constraints (works only in transformed problem) */
3608  if( transformed )
3609  {
3610  SCIP_CONS** consInd;
3611  int nConsInd;
3612 
3613  consInd = SCIPconshdlrGetConss(conshdlrInd);
3614  nConsInd = SCIPconshdlrGetNConss(conshdlrInd);
3615  SCIPdebugMsg(scip, "Number of indicator constraints: %d\n", nConsInd);
3616 
3617  for( c = 0; c < nConsInd; ++c )
3618  {
3619  assert( consInd[c] != NULL );
3620  cons = SCIPgetLinearConsIndicator(consInd[c]);
3621 
3622  assert( !SCIPhashmapExists(consHidden, (void*) cons) );
3623  SCIP_CALL( SCIPhashmapSetImage(consHidden, (void*) cons, (void*) TRUE) );
3624  SCIPdebugMsg(scip, "Marked linear constraint <%s> as hidden.\n", SCIPconsGetName(cons));
3625  }
3626  }
3627  else
3628  {
3629  /* otherwise we have to pass through all constraints */
3630  for( c = 0; c < nconss; ++c )
3631  {
3632  cons = conss[c];
3633  assert( cons != NULL);
3634 
3635  conshdlr = SCIPconsGetHdlr(cons);
3636  assert( conshdlr != NULL );
3637  conshdlrname = SCIPconshdlrGetName(conshdlr);
3638 
3639  if( strcmp(conshdlrname, "indicator") == 0 )
3640  {
3641  SCIP_CONS* lincons;
3642 
3643  lincons = SCIPgetLinearConsIndicator(cons);
3644  assert( lincons != NULL );
3645 
3646  assert( !SCIPhashmapExists(consHidden, (void*) lincons) );
3647  SCIP_CALL( SCIPhashmapSetImage(consHidden, (void*) lincons, (void*) TRUE) );
3648  SCIPdebugMsg(scip, "Marked linear constraint <%s> as hidden.\n", SCIPconsGetName(lincons));
3649  }
3650  }
3651  }
3652  }
3653 
3654  /* check if the variable names are not to long */
3655  checkVarnames(scip, vars, nvars);
3656  /* check if the constraint names are to long */
3657  checkConsnames(scip, conss, nconss, transformed);
3658 
3659  /* print statistics as comment to file */
3660  SCIPinfoMessage(scip, file, "\\ SCIP STATISTICS\n");
3661  SCIPinfoMessage(scip, file, "\\ Problem name : %s\n", name);
3662  SCIPinfoMessage(scip, file, "\\ Variables : %d (%d binary, %d integer, %d implicit integer, %d continuous)\n",
3663  nvars, nbinvars, nintvars, nimplvars, ncontvars);
3664  SCIPinfoMessage(scip, file, "\\ Constraints : %d\n", nconss);
3665  SCIPinfoMessage(scip, file, "\\ Obj. scale : %.15g\n", objscale);
3666  SCIPinfoMessage(scip, file, "\\ Obj. offset : %.15g\n", objoffset);
3667 
3668  /* print objective sense */
3669  SCIPinfoMessage(scip, file, "%s\n", objsense == SCIP_OBJSENSE_MINIMIZE ? "Minimize" : "Maximize");
3670 
3671  clearLine(linebuffer, &linecnt);
3672  appendLine(scip, file, linebuffer, &linecnt, " Obj:");
3673 
3674  for( v = 0; v < nvars; ++v )
3675  {
3676  var = vars[v];
3677 
3678 #ifndef NDEBUG
3679  /* in case the original problem has to be written, the variables have to be either "original" or "negated" */
3680  if( ! transformed )
3682 #endif
3683 
3684  if( SCIPisZero(scip, SCIPvarGetObj(var)) )
3685  continue;
3686 
3687  /* we start a new line; therefore we tab this line */
3688  if( linecnt == 0 )
3689  appendLine(scip, file, linebuffer, &linecnt, " ");
3690 
3691  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var));
3692  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %+.15g %s", SCIPvarGetObj(var), varname );
3693 
3694  appendLine(scip, file, linebuffer, &linecnt, buffer);
3695  }
3696 
3697  endLine(scip, file, linebuffer, &linecnt);
3698 
3699  /* print "Subject to" section */
3700  SCIPinfoMessage(scip, file, "Subject to\n");
3701 
3702  reader = SCIPfindReader(scip, READER_NAME);
3703  if( reader != NULL )
3704  {
3705  readerdata = SCIPreaderGetData(reader);
3706  assert(readerdata != NULL);
3707 
3708  linearizeands = readerdata->linearizeands;
3709  aggrlinearizationands = readerdata->aggrlinearizationands;
3710  }
3711  else
3712  {
3713  linearizeands = DEFAULT_LINEARIZE_ANDS;
3714  aggrlinearizationands = DEFAULT_AGGRLINEARIZATION_ANDS;
3715  }
3716 
3717  /* collect SOS, quadratic, and SOC constraints in array for later output */
3718  SCIP_CALL( SCIPallocBufferArray(scip, &consSOS1, nconss) );
3719  SCIP_CALL( SCIPallocBufferArray(scip, &consSOS2, nconss) );
3720  SCIP_CALL( SCIPallocBufferArray(scip, &consQuadratic, nconss) );
3721  SCIP_CALL( SCIPallocBufferArray(scip, &consSOC, nconss) );
3722  SCIP_CALL( SCIPallocBufferArray(scip, &consIndicator, nconss) );
3723 
3724  for( c = 0; c < nconss; ++c )
3725  {
3726  cons = conss[c];
3727  assert( cons != NULL);
3728 
3729  /* in case the transformed is written only constraints are posted which are enabled in the current node */
3730  assert(!transformed || SCIPconsIsEnabled(cons));
3731 
3732  /* skip marked constraints in connection with indicator constraints */
3733  if( conshdlrInd != NULL && SCIPhashmapExists(consHidden, (void*) cons) )
3734  {
3735  assert( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), "linear") == 0 );
3736  continue;
3737  }
3738 
3739  conshdlr = SCIPconsGetHdlr(cons);
3740  assert( conshdlr != NULL );
3741 
3742  (void) SCIPsnprintf(consname, LP_MAX_NAMELEN, "%s", SCIPconsGetName(cons));
3743  conshdlrname = SCIPconshdlrGetName(conshdlr);
3744  assert( transformed == SCIPconsIsTransformed(cons) );
3745 
3746  if( strcmp(conshdlrname, "linear") == 0 )
3747  {
3748  SCIP_CALL( printQuadraticCons(scip, file, consname,
3749  SCIPgetVarsLinear(scip, cons), SCIPgetValsLinear(scip, cons), SCIPgetNVarsLinear(scip, cons),
3750  NULL, 0, NULL, 0, SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons), transformed) );
3751  }
3752  else if( strcmp(conshdlrname, "setppc") == 0 )
3753  {
3754  consvars = SCIPgetVarsSetppc(scip, cons);
3755  nconsvars = SCIPgetNVarsSetppc(scip, cons);
3756 
3757  switch( SCIPgetTypeSetppc(scip, cons) )
3758  {
3760  SCIP_CALL( printQuadraticCons(scip, file, consname,
3761  consvars, NULL, nconsvars, NULL, 0, NULL, 0, 1.0, 1.0, transformed) );
3762  break;
3764  SCIP_CALL( printQuadraticCons(scip, file, consname,
3765  consvars, NULL, nconsvars, NULL, 0, NULL, 0, -SCIPinfinity(scip), 1.0, transformed) );
3766  break;
3768  SCIP_CALL( printQuadraticCons(scip, file, consname,
3769  consvars, NULL, nconsvars, NULL, 0, NULL, 0, 1.0, SCIPinfinity(scip), transformed) );
3770  break;
3771  }
3772  }
3773  else if( strcmp(conshdlrname, "logicor") == 0 )
3774  {
3775  SCIP_CALL( printQuadraticCons(scip, file, consname,
3776  SCIPgetVarsLogicor(scip, cons), NULL, SCIPgetNVarsLogicor(scip, cons),
3777  NULL, 0, NULL, 0, 1.0, SCIPinfinity(scip), transformed) );
3778  }
3779  else if( strcmp(conshdlrname, "knapsack") == 0 )
3780  {
3781  SCIP_Longint* weights;
3782 
3783  consvars = SCIPgetVarsKnapsack(scip, cons);
3784  nconsvars = SCIPgetNVarsKnapsack(scip, cons);
3785 
3786  /* copy Longint array to SCIP_Real array */
3787  weights = SCIPgetWeightsKnapsack(scip, cons);
3788  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) );
3789  for( v = 0; v < nconsvars; ++v )
3790  consvals[v] = (SCIP_Real)weights[v];
3791 
3792  SCIP_CALL( printQuadraticCons(scip, file, consname, consvars, consvals, nconsvars,
3793  NULL, 0, NULL, 0, -SCIPinfinity(scip), (SCIP_Real) SCIPgetCapacityKnapsack(scip, cons), transformed) );
3794 
3795  SCIPfreeBufferArray(scip, &consvals);
3796  }
3797  else if( strcmp(conshdlrname, "varbound") == 0 )
3798  {
3799  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) );
3800  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) );
3801 
3802  consvars[0] = SCIPgetVarVarbound(scip, cons);
3803  consvars[1] = SCIPgetVbdvarVarbound(scip, cons);
3804 
3805  consvals[0] = 1.0;
3806  consvals[1] = SCIPgetVbdcoefVarbound(scip, cons);
3807 
3808  SCIP_CALL( printQuadraticCons(scip, file, consname, consvars, consvals, 2, NULL, 0, NULL, 0,
3809  SCIPgetLhsVarbound(scip, cons), SCIPgetRhsVarbound(scip, cons), transformed) );
3810 
3811  SCIPfreeBufferArray(scip, &consvars);
3812  SCIPfreeBufferArray(scip, &consvals);
3813  }
3814  else if( strcmp(conshdlrname, "SOS1") == 0 )
3815  {
3816  /* store constraint */
3817  consSOS1[nConsSOS1++] = cons;
3818  }
3819  else if( strcmp(conshdlrname, "SOS2") == 0 )
3820  {
3821  /* store constraint */
3822  consSOS2[nConsSOS2++] = cons;
3823  }
3824  else if( strcmp(conshdlrname, "indicator") == 0 )
3825  {
3826  SCIP_CONS* lincons;
3827  SCIP_VAR* binvar;
3828  SCIP_VAR* slackvar;
3829  SCIP_VAR** linvars;
3830  SCIP_Real* linvals;
3831  int nlinvars;
3832  int cnt;
3833  int rhs;
3834 
3835  assert( conshdlrInd != NULL );
3836 
3837  lincons = SCIPgetLinearConsIndicator(cons);
3838  binvar = SCIPgetBinaryVarIndicator(cons);
3839  slackvar = SCIPgetSlackVarIndicator(cons);
3840 
3841  assert( lincons != NULL );
3842  assert( binvar != NULL );
3843  assert( slackvar != NULL );
3844 
3845  rhs = 1;
3846  if ( SCIPvarIsNegated(binvar) )
3847  {
3848  rhs = 0;
3849  binvar = SCIPvarGetNegatedVar(binvar);
3850  }
3851 
3852  /* collect linear constraint information (remove slack variable) */
3853  linvars = SCIPgetVarsLinear(scip, lincons);
3854  linvals = SCIPgetValsLinear(scip, lincons);
3855  nlinvars = SCIPgetNVarsLinear(scip, lincons);
3856  assert( linvars != NULL );
3857  assert( linvals != NULL );
3858 
3859  /* linvars always contains slack variable, thus nlinvars >= 1 */
3860  if( nlinvars > 1 && !SCIPconsIsDeleted(lincons) )
3861  {
3862  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(binvar) );
3863  if( strlen(consname) > 0 )
3864  SCIPinfoMessage(scip, file, " %s: %s = %d ->", consname, varname, rhs);
3865  else
3866  SCIPinfoMessage(scip, file, " %s = %d ->", varname, rhs);
3867 
3868  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nlinvars-1) );
3869  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nlinvars-1) );
3870 
3871  cnt = 0;
3872  for( v = 0; v < nlinvars; ++v )
3873  {
3874  var = linvars[v];
3875  if( var != slackvar )
3876  {
3877  consvars[cnt] = var;
3878  consvals[cnt++] = linvals[v];
3879  }
3880  }
3881  /* if slackvariable is fixed, it might have been removed from constraint */
3882  assert( nlinvars == 0 || cnt == nlinvars-1 || SCIPisFeasEQ(scip, SCIPvarGetLbGlobal(slackvar), SCIPvarGetUbGlobal(slackvar)) );
3883 
3884  SCIP_CALL( printQuadraticCons(scip, file, "", consvars, consvals, cnt, NULL, 0, NULL, 0,
3885  SCIPgetLhsLinear(scip, lincons), SCIPgetRhsLinear(scip, lincons), transformed) );
3886 
3887  SCIPfreeBufferArray(scip, &consvars);
3888  SCIPfreeBufferArray(scip, &consvals);
3889  }
3890 
3891  /* store constraint */
3892  consIndicator[nConsIndicator++] = cons;
3893  }
3894  else if( strcmp(conshdlrname, "quadratic") == 0 )
3895  {
3896  SCIP_CALL( printQuadraticCons(scip, file, consname,
3900  SCIPgetNBilinTermsQuadratic(scip, cons), SCIPgetLhsQuadratic(scip, cons),
3901  SCIPgetRhsQuadratic(scip, cons), transformed) );
3902 
3903  consQuadratic[nConsQuadratic++] = cons;
3904  }
3905  else if( strcmp(conshdlrname, "soc") == 0 )
3906  {
3907  SCIP_CALL( printSOCCons(scip, file, consname, cons) );
3908 
3909  consSOC[nConsSOC++] = cons;
3910  }
3911  else if( strcmp(conshdlrname, "and") == 0 )
3912  {
3913  if( linearizeands )
3914  {
3915  SCIP_CALL( printAndCons(scip, file, consname, cons, aggrlinearizationands, transformed) );
3916  }
3917  else
3918  {
3919  SCIPwarningMessage(scip, "change parameter \"reading/" READER_NAME "/linearize-and-constraints\" to TRUE to print and-constraints\n");
3920  SCIPinfoMessage(scip, file, "\\ ");
3921  SCIP_CALL( SCIPprintCons(scip, cons, file) );
3922  SCIPinfoMessage(scip, file, ";\n");
3923  }
3924  }
3925  else
3926  {
3927  SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname );
3928  SCIPinfoMessage(scip, file, "\\ ");
3929  SCIP_CALL( SCIPprintCons(scip, cons, file) );
3930  SCIPinfoMessage(scip, file, ";\n");
3931  }
3932  }
3933 
3934  /* allocate array for storing aggregated and negated variables (dynamically adjusted) */
3935  saggvars = MAX(10, nvars);
3936  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &aggvars, saggvars) );
3937 
3938  /* create hashtable for storing aggregated variables */
3939  SCIP_CALL( SCIPhashtableCreate(&varAggregated, SCIPblkmem(scip), saggvars, hashGetKeyVar, hashKeyEqVar, hashKeyValVar, NULL) );
3940 
3941  /* check for aggregated variables in SOS1 constraints and output aggregations as linear constraints */
3942  for( c = 0; c < nConsSOS1; ++c )
3943  {
3944  cons = consSOS1[c];
3945  consvars = SCIPgetVarsSOS1(scip, cons);
3946  nconsvars = SCIPgetNVarsSOS1(scip, cons);
3947 
3948  SCIP_CALL( collectAggregatedVars(scip, consvars, nconsvars, &aggvars, &naggvars, &saggvars, varAggregated) );
3949  }
3950 
3951  /* check for aggregated variables in SOS2 constraints and output aggregations as linear constraints */
3952  for( c = 0; c < nConsSOS2; ++c )
3953  {
3954  cons = consSOS2[c];
3955  consvars = SCIPgetVarsSOS2(scip, cons);
3956  nconsvars = SCIPgetNVarsSOS2(scip, cons);
3957 
3958  SCIP_CALL( collectAggregatedVars(scip, consvars, nconsvars, &aggvars, &naggvars, &saggvars, varAggregated) );
3959  }
3960 
3961  /* check for aggregated variables in quadratic parts of quadratic constraints and output aggregations as linear constraints */
3962  for( c = 0; c < nConsQuadratic; ++c )
3963  {
3964  cons = consQuadratic[c];
3965  for( v = 0; v < SCIPgetNQuadVarTermsQuadratic(scip, cons); ++v )
3966  {
3967  SCIP_CALL( collectAggregatedVars(scip, &SCIPgetQuadVarTermsQuadratic(scip, cons)[v].var, 1, &aggvars, &naggvars, &saggvars, varAggregated) );
3968  }
3969  }
3970 
3971  /* check for aggregated variables in second order cone constraints and output aggregations as linear constraints */
3972  for( c = 0; c < nConsSOC; ++c )
3973  {
3974  cons = consSOC[c];
3975 
3976  SCIP_CALL( collectAggregatedVars(scip, SCIPgetLhsVarsSOC(scip, cons), SCIPgetNLhsVarsSOC(scip, cons), &aggvars, &naggvars, &saggvars, varAggregated) );
3977  var = SCIPgetRhsVarSOC(scip, cons);
3978  SCIP_CALL( collectAggregatedVars(scip, &var, 1, &aggvars, &naggvars, &saggvars, varAggregated) );
3979  }
3980 
3981  /* check for aggregated variables in indicator constraints and output aggregations as linear constraints */
3982  for( c = 0; c < nConsIndicator; ++c )
3983  {
3984  SCIP_VAR* binvar;
3985 
3986  cons = consIndicator[c];
3987  binvar = SCIPgetBinaryVarIndicator(cons);
3988  if ( ! SCIPvarIsNegated(binvar) )
3989  {
3990  /* we take care of negated variables above, but not of aggregated variables */
3991  SCIP_CALL( collectAggregatedVars(scip, &binvar, 1, &aggvars, &naggvars, &saggvars, varAggregated) );
3992  }
3993  }
3994 
3995  /* print aggregation constraints */
3996  SCIP_CALL( printAggregatedCons(scip, file, transformed, nvars, naggvars, aggvars) );
3997 
3998  /* print "Bounds" section */
3999  SCIPinfoMessage(scip, file, "Bounds\n");
4000  for( v = 0; v < nvars; ++v )
4001  {
4002  var = vars[v];
4003  assert( var != NULL );
4004  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var) );
4005 
4006  if( transformed )
4007  {
4008  /* in case the transformed is written only local bounds are posted which are valid in the current node */
4009  lb = SCIPvarGetLbLocal(var);
4010  ub = SCIPvarGetUbLocal(var);
4011  }
4012  else
4013  {
4014  lb = SCIPvarGetLbOriginal(var);
4015  ub = SCIPvarGetUbOriginal(var);
4016  }
4017 
4018  if( SCIPisInfinity(scip, -lb) && SCIPisInfinity(scip, ub) )
4019  SCIPinfoMessage(scip, file, " %s free\n", varname);
4020  else
4021  {
4022  /* print lower bound */
4023  if( SCIPisInfinity(scip, -lb) )
4024  SCIPinfoMessage(scip, file, " -inf <= ");
4025  else
4026  {
4027  if( SCIPisZero(scip, lb) )
4028  {
4029  /* variables are nonnegative by default - so we skip these variables */
4030  if( SCIPisInfinity(scip, ub) )
4031  continue;
4032  lb = 0.0;
4033  }
4034 
4035  SCIPinfoMessage(scip, file, " %.15g <= ", lb);
4036  }
4037  /* print variable name */
4038  SCIPinfoMessage(scip, file, "%s", varname);
4039 
4040  /* print upper bound as far this one is not infinity */
4041  if( !SCIPisInfinity(scip, ub) )
4042  SCIPinfoMessage(scip, file, " <= %.15g", ub);
4043 
4044  SCIPinfoMessage(scip, file, "\n");
4045  }
4046  }
4047 
4048  /* output aggregated variables as 'free' */
4049  for( v = 0; v < naggvars; ++v )
4050  {
4051  var = aggvars[v];
4052  assert( var != NULL );
4053  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var) );
4054 
4055  SCIPinfoMessage(scip, file, " %s free\n", varname);
4056  }
4057 
4058  /* print binaries section */
4059  if( nbinvars > 0 )
4060  {
4061  SCIPinfoMessage(scip, file, "Binaries\n");
4062 
4063  clearLine(linebuffer, &linecnt);
4064 
4065  /* output active variables */
4066  for( v = 0; v < nvars; ++v )
4067  {
4068  var = vars[v];
4069  assert( var != NULL );
4070 
4071  if( SCIPvarGetType(var) == SCIP_VARTYPE_BINARY )
4072  {
4073  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var) );
4074  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %s", varname);
4075  appendLine(scip, file, linebuffer, &linecnt, buffer);
4076  }
4077  }
4078 
4079  /* possibly output aggregated variables */
4080  for( v = 0; v < naggvars; ++v )
4081  {
4082  var = aggvars[v];
4083  assert( var != NULL );
4084 
4085  if( SCIPvarGetType(var) == SCIP_VARTYPE_BINARY )
4086  {
4087  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var) );
4088  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %s", varname);
4089  appendLine(scip, file, linebuffer, &linecnt, buffer);
4090  }
4091  }
4092 
4093  endLine(scip, file, linebuffer, &linecnt);
4094  }
4095 
4096  /* print generals section */
4097  if( nintvars > 0 )
4098  {
4099  SCIPinfoMessage(scip, file, "Generals\n");
4100 
4101  /* output active variables */
4102  for( v = 0; v < nvars; ++v )
4103  {
4104  var = vars[v];
4105  assert( var != NULL );
4106 
4107  if( SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER )
4108  {
4109  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var) );
4110  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %s", varname);
4111  appendLine(scip, file, linebuffer, &linecnt, buffer);
4112  }
4113  }
4114 
4115  /* possibly output aggregated variables */
4116  for( v = 0; v < naggvars; ++v )
4117  {
4118  var = aggvars[v];
4119  assert( var != NULL );
4120 
4121  if( SCIPvarGetType(var) == SCIP_VARTYPE_INTEGER )
4122  {
4123  (void) SCIPsnprintf(varname, LP_MAX_NAMELEN, "%s", SCIPvarGetName(var) );
4124  (void) SCIPsnprintf(buffer, LP_MAX_PRINTLEN, " %s", varname);
4125  appendLine(scip, file, linebuffer, &linecnt, buffer);
4126  }
4127  }
4128 
4129  endLine(scip, file, linebuffer, &linecnt);
4130  }
4131 
4132  /* free space */
4133  SCIPfreeBlockMemoryArray(scip, &aggvars, saggvars);
4134  SCIPhashtableFree(&varAggregated);
4135  if( conshdlrInd != NULL )
4136  SCIPhashmapFree(&consHidden);
4137 
4138  /* print SOS section */
4139  if( nConsSOS1 > 0 || nConsSOS2 > 0 )
4140  {
4141  SCIP_Real* weights;
4142  SCIPinfoMessage(scip, file, "SOS\n");
4143 
4144  /* first output SOS1 constraints */
4145  for( c = 0; c < nConsSOS1; ++c )
4146  {
4147  cons = consSOS1[c];
4148  consvars = SCIPgetVarsSOS1(scip, cons);
4149  nconsvars = SCIPgetNVarsSOS1(scip, cons);
4150  weights = SCIPgetWeightsSOS1(scip, cons);
4151 
4152  (void) SCIPsnprintf(consname, LP_MAX_NAMELEN, "%s", SCIPconsGetName(cons) );
4153  printSosCons(scip, file, consname, consvars, weights, nconsvars, 1);
4154  }
4155 
4156  /* next output SOS2 constraints */
4157  for( c = 0; c < nConsSOS2; ++c )
4158  {
4159  cons = consSOS2[c];
4160  consvars = SCIPgetVarsSOS2(scip, cons);
4161  nconsvars = SCIPgetNVarsSOS2(scip, cons);
4162  weights = SCIPgetWeightsSOS2(scip, cons);
4163 
4164  (void) SCIPsnprintf(consname, LP_MAX_NAMELEN, "%s", SCIPconsGetName(cons) );
4165  printSosCons(scip, file, consname, consvars, weights, nconsvars, 2);
4166  }
4167  }
4168 
4169  /* free space */
4170  SCIPfreeBufferArray(scip, &consIndicator);
4171  SCIPfreeBufferArray(scip, &consSOC);
4172  SCIPfreeBufferArray(scip, &consQuadratic);
4173  SCIPfreeBufferArray(scip, &consSOS2);
4174  SCIPfreeBufferArray(scip, &consSOS1);
4175 
4176  /* end of lp format */
4177  SCIPinfoMessage(scip, file, "%s\n", "End");
4178 
4179  *result = SCIP_SUCCESS;
4180 
4181  return SCIP_OKAY;
4182 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
static void syntaxError(SCIP *scip, LPINPUT *lpinput, const char *msg)
Definition: reader_lp.c:137
SCIP_VAR ** SCIPgetLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip.h:21909
enum SCIP_BoundType SCIP_BOUNDTYPE
Definition: type_lp.h:50
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:46151
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip.h:21898
SCIP_VAR ** SCIPgetLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5497
SCIP_Bool SCIPconsIsEnabled(SCIP_CONS *cons)
Definition: cons.c:7978
int SCIPmemccpy(char *dest, const char *src, char stop, unsigned int cnt)
Definition: misc.c:9252
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip.h:21892
static void checkConsnames(SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_Bool transformed)
Definition: reader_lp.c:3298
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:46086
static const char commentchars[]
Definition: reader_lp.c:128
static SCIP_DECL_HASHKEYEQ(hashKeyEqVar)
Definition: reader_lp.c:2448
static SCIP_RETCODE printAndCons(SCIP *scip, FILE *file, const char *consname, SCIP_CONS *cons, SCIP_Bool aggrlinearizationands, SCIP_Bool transformed)
Definition: reader_lp.c:3065
Constraint handler for variable bound constraints .
static void swapPointers(char **pointer1, char **pointer2)
Definition: reader_lp.c:355
SCIP_VAR ** SCIPgetVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10551
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2254
enum LpExpType LPEXPTYPE
Definition: reader_lp.c:93
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:6541
int SCIPgetNVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9172
#define READER_NAME
Definition: reader_lp.c:54
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17166
int SCIPgetNVarsLogicor(SCIP *scip, SCIP_CONS *cons)
#define SCIP_MAXSTRLEN
Definition: def.h:215
SCIP_Real * SCIPgetLhsOffsetsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5523
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
Definition: scip.c:9778
#define DEFAULT_LINEARIZE_ANDS
Definition: reader_lp.c:58
static SCIP_DECL_HASHKEYVAL(hashKeyValVar)
Definition: reader_lp.c:2457
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip.c:45601
static SCIP_DECL_READERCOPY(readerCopyLp)
Definition: reader_lp.c:3369
SCIP_RETCODE SCIPaddVarSOS2(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
Definition: cons_sos2.c:2388
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17222
SCIP_Real * SCIPgetWeightsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10576
static SCIP_DECL_HASHGETKEY(hashGetKeyVar)
Definition: reader_lp.c:2441
static SCIP_Bool isSense(LPINPUT *lpinput, LPSENSE *sense)
Definition: reader_lp.c:779
const char * SCIPreaderGetName(SCIP_READER *reader)
Definition: reader.c:515
enum LpSense LPSENSE
Definition: reader_lp.c:99
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip.c:18384
#define LP_MAX_PRINTLEN
Definition: reader_lp.c:69
static SCIP_RETCODE readSemicontinuous(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:2054
#define LP_MAX_PUSHEDTOKENS
Definition: reader_lp.c:66
constraint handler for indicator constraints
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4485
#define FALSE
Definition: def.h:64
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2765
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:45816
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:9340
#define TRUE
Definition: def.h:63
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define LP_PRINTLEN
Definition: reader_lp.c:71
enum SCIP_Varstatus SCIP_VARSTATUS
Definition: type_var.h:48
static SCIP_RETCODE collectAggregatedVars(SCIP *scip, SCIP_VAR **vars, int nvars, SCIP_VAR ***aggvars, int *naggvars, int *saggvars, SCIP_HASHTABLE *varAggregated)
Definition: reader_lp.c:3152
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:16859
LpExpType
Definition: reader_diff.c:52
SCIP_Bool SCIPconsIsTransformed(SCIP_CONS *cons)
Definition: cons.c:8190
SCIP_VAR ** SCIPgetVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip.h:21907
static SCIP_RETCODE readObjective(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:1244
SCIP_READER * SCIPfindReader(SCIP *scip, const char *name)
Definition: scip.c:5327
Constraint handler for AND constraints, .
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip.h:21933
int SCIPgetNVarsSOS2(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos2.c:2439
SCIP_RETCODE SCIPchgVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:21611
#define LP_INIT_QUADCOEFSSIZE
Definition: reader_lp.c:68
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:45751
constraint handler for second order cone constraints
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:21937
static SCIP_Bool isDelimChar(char c)
Definition: reader_lp.c:175
Constraint handler for the set partitioning / packing / covering constraints .
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip.h:21890
#define SCIPdebugPrintCons(x, y, z)
Definition: pub_message.h:83
static SCIP_Bool isNewSection(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:511
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1260
int SCIPfseek(SCIP_FILE *stream, long offset, int whence)
Definition: fileio.c:199
#define SCIPdebugMsg
Definition: scip.h:451
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE getVariable(SCIP *scip, char *name, SCIP_VAR **var, SCIP_Bool *created)
Definition: reader_lp.c:810
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip.c:1336
SCIP_RETCODE SCIPcreateConsQuadratic(SCIP *scip, SCIP_CONS **cons, const char *name, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, int nquadterms, SCIP_VAR **quadvars1, SCIP_VAR **quadvars2, SCIP_Real *quadcoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable)
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
Definition: misc.c:2015
int SCIPgetNQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
enum LpSection LPSECTION
Definition: reader_diff.c:50
static SCIP_DECL_READERFREE(readerFreeLp)
Definition: reader_lp.c:3383
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
Definition: var.c:16982
static SCIP_Bool isValueChar(char c, char nextc, SCIP_Bool firstchar, SCIP_Bool *hasdot, LPEXPTYPE *exptype)
Definition: reader_lp.c:220
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2997
int SCIPgetNBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR * SCIPgetSlackVarIndicator(SCIP_CONS *cons)
static void pushToken(LPINPUT *lpinput)
Definition: reader_lp.c:474
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
Definition: scip.c:12325
SCIP_RETCODE SCIPchgVarType(SCIP *scip, SCIP_VAR *var, SCIP_VARTYPE vartype, SCIP_Bool *infeasible)
Definition: scip.c:25045
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
Definition: fileio.c:140
SCIP_READERDATA * SCIPreaderGetData(SCIP_READER *reader)
Definition: reader.c:450
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17176
struct LpInput LPINPUT
Definition: reader_diff.c:83
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
Definition: scip.c:10898
Constraint handler for knapsack constraints of the form , x binary and .
static SCIP_RETCODE readSos(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:2152
static SCIP_RETCODE readGenerals(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:1955
SCIP_VAR ** SCIPgetVarsAnd(SCIP *scip, SCIP_CONS *cons)
Definition: cons_and.c:5101
SCIP_VAR * SCIPgetVarVarbound(SCIP *scip, SCIP_CONS *cons)
#define SCIPerrorMessage
Definition: pub_message.h:45
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4113
static SCIP_Bool getNextLine(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:264
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:12410
SCIP_Real SCIPvarGetLbOriginal(SCIP_VAR *var)
Definition: var.c:17112
SCIP_VAR * SCIPgetResultantAnd(SCIP *scip, SCIP_CONS *cons)
Definition: cons_and.c:5126
static void printSosCons(SCIP *scip, FILE *file, const char *rowname, SCIP_VAR **vars, SCIP_Real *weights, int nvars, int type)
Definition: reader_lp.c:2856
SCIP_Real SCIPgetRhsVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsSOS2(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos2.c:2464
SCIP_RETCODE SCIPaddVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
Definition: cons_sos1.c:10459
Constraint handler for logicor constraints (equivalent to set covering, but algorithms are suited fo...
SCIP_Real SCIPvarGetUbOriginal(SCIP_VAR *var)
Definition: var.c:17132
SCIP_Real * SCIPgetCoefsLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetVbdcoefVarbound(SCIP *scip, SCIP_CONS *cons)
static void appendLine(SCIP *scip, FILE *file, char *linebuffer, int *linecnt, const char *extension)
Definition: reader_lp.c:2591
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:45519
struct SCIP_File SCIP_FILE
Definition: pub_fileio.h:34
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
Definition: fileio.c:187
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7881
SCIP_RETCODE SCIPchgVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:21701
SCIPInterval sign(const SCIPInterval &x)
SCIP_VAR ** SCIPgetVarsLogicor(SCIP *scip, SCIP_CONS *cons)
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16552
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2798
constraint handler for quadratic constraints
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
Definition: scip.c:4369
#define NULL
Definition: lpi_spx1.cpp:137
SCIP_VAR * SCIPgetVbdvarVarbound(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE readStart(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:855
#define SCIP_CALL(x)
Definition: def.h:306
#define LP_INIT_COEFSSIZE
Definition: reader_lp.c:67
SCIP_RETCODE SCIPgetProbvarLinearSum(SCIP *scip, SCIP_VAR **vars, SCIP_Real *scalars, int *nvars, int varssize, SCIP_Real *constant, int *requiredsize, SCIP_Bool mergemultiples)
Definition: scip.c:18873
static SCIP_RETCODE getActiveVariables(SCIP *scip, SCIP_VAR ***vars, SCIP_Real **scalars, int *nvars, SCIP_Real *constant, SCIP_Bool transformed)
Definition: reader_lp.c:2500
SCIP_RETCODE SCIPincludeReaderLp(SCIP *scip)
Definition: reader_lp.c:3425
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip.c:1353
static SCIP_Bool getNextToken(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:369
#define READER_EXTENSION
Definition: reader_lp.c:56
SCIP_BILINTERM * SCIPgetBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
int SCIPconshdlrGetNConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4515
SCIP_Real SCIPgetRhsOffsetSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5575
SCIP_Longint SCIPgetCapacityKnapsack(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE printQuadraticCons(SCIP *scip, FILE *file, const char *rowname, SCIP_VAR **linvars, SCIP_Real *linvals, int nlinvars, SCIP_QUADVARTERM *quadvarterms, int nquadvarterms, SCIP_BILINTERM *bilinterms, int nbilinterms, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool transformed)
Definition: reader_lp.c:2757
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
Definition: scip.c:21448
SCIP_Real SCIPgetRhsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE readConstraints(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:1545
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:21925
struct SCIP_ReaderData SCIP_READERDATA
Definition: type_reader.h:37
public data structures and miscellaneous methods
static SCIP_DECL_READERWRITE(readerWriteLp)
Definition: reader_lp.c:3408
#define SCIP_Bool
Definition: def.h:61
int SCIPgetNLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5484
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Definition: scip.c:5201
static SCIP_RETCODE readBounds(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:1784
void SCIPprintSysError(const char *message)
Definition: misc.c:9276
enum SCIP_Objsense SCIP_OBJSENSE
Definition: type_prob.h:41
SCIP_VAR * SCIPgetRhsVarSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5549
static SCIP_Bool isTokenChar(char c)
Definition: reader_lp.c:196
SCIP_SETPPCTYPE SCIPgetTypeSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9214
#define READER_DESC
Definition: reader_lp.c:55
static void checkVarnames(SCIP *scip, SCIP_VAR **vars, int nvars)
Definition: reader_lp.c:3261
SCIP_Real * SCIPgetWeightsSOS2(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos2.c:2489
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
Definition: scip.c:28652
static void printRow(SCIP *scip, FILE *file, const char *rowname, const char *rownameextension, const char *type, SCIP_VAR **linvars, SCIP_Real *linvals, int nlinvars, SCIP_QUADVARTERM *quadvarterms, int nquadvarterms, SCIP_BILINTERM *bilinterms, int nbilinterms, SCIP_Real rhs)
Definition: reader_lp.c:2622
#define MAX(x, y)
Definition: tclique_def.h:75
static SCIP_DECL_READERREAD(readerReadLp)
Definition: reader_lp.c:3397
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:7901
enum LpSense LPSENSE
Definition: reader_diff.c:62
SCIP_Bool SCIPconsIsDeleted(SCIP_CONS *cons)
Definition: cons.c:8010
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17014
int SCIPgetNVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10526
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
Definition: scip.c:17237
SCIP_RETCODE SCIPsetReaderWrite(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERWRITE((*readerwrite)))
Definition: scip.c:5311
static SCIP_RETCODE readBinaries(SCIP *scip, LPINPUT *lpinput)
Definition: reader_lp.c:2000
static SCIP_Bool isSign(LPINPUT *lpinput, int *sign)
Definition: reader_lp.c:722
Constraint handler for linear constraints in their most general form, .
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:45827
enum LpSection LPSECTION
Definition: reader_lp.c:87
SCIP_RETCODE SCIPvarGetOrigvarSum(SCIP_VAR **var, SCIP_Real *scalar, SCIP_Real *constant)
Definition: var.c:12080
#define LP_MAX_NAMELEN
Definition: reader_lp.c:70
SCIP_VAR * SCIPgetBinaryVarIndicator(SCIP_CONS *cons)
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
Definition: scip.c:5239
SCIP_VAR ** SCIPgetVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9193
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
Definition: misc.c:2065
static void pushBufferToken(LPINPUT *lpinput)
Definition: reader_lp.c:487
SCIP_RETCODE SCIPcreateConsIndicator(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
static SCIP_RETCODE createIndicatorConstraint(SCIP *scip, LPINPUT *lpinput, const char *name, SCIP_VAR *binvar, SCIP_Real binvalue)
Definition: reader_lp.c:1331
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define DEFAULT_AGGRLINEARIZATION_ANDS
Definition: reader_lp.c:59
int SCIPgetNLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE readCoefficients(SCIP *scip, LPINPUT *lpinput, SCIP_Bool isobjective, char *name, int *coefssize, SCIP_VAR ***vars, SCIP_Real **coefs, int *ncoefs, int *quadcoefssize, SCIP_VAR ***quadvars1, SCIP_VAR ***quadvars2, SCIP_Real **quadcoefs, int *nquadcoefs, SCIP_Bool *newsection)
Definition: reader_lp.c:876
LP file reader.
static const SCIP_Real scalars[]
Definition: lp.c:5563
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:11311
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
#define LP_MAX_LINELEN
Definition: reader_lp.c:65
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:27323
static SCIP_RETCODE printAggregatedCons(SCIP *scip, FILE *file, SCIP_Bool transformed, int nvars, int nAggregatedVars, SCIP_VAR **aggregatedVars)
Definition: reader_lp.c:3208
static SCIP_RETCODE readLPFile(SCIP *scip, LPINPUT *lpinput, const char *filename)
Definition: reader_lp.c:2363
SCIP_Real SCIPgetLhsConstantSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5536
SCIP_Real SCIPgetRhsCoefSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5562
enum LpExpType LPEXPTYPE
Definition: reader_diff.c:56
SCIP_RETCODE SCIPhashmapSetImage(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:2943
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16671
#define SCIP_Real
Definition: def.h:135
int SCIPgetNVarsAnd(SCIP *scip, SCIP_CONS *cons)
Definition: cons_and.c:5077
constraint handler for SOS type 1 constraints
static void swapTokenBuffer(LPINPUT *lpinput)
Definition: reader_lp.c:500
int SCIPgetNVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
static void endLine(SCIP *scip, FILE *file, char *linebuffer, int *linecnt)
Definition: reader_lp.c:2569
static SCIP_RETCODE printSOCCons(SCIP *scip, FILE *file, const char *rowname, SCIP_CONS *cons)
Definition: reader_lp.c:2915
LpSection
Definition: reader_diff.c:46
SCIP_RETCODE SCIPreadLp(SCIP *scip, SCIP_READER *reader, const char *filename, SCIP_RESULT *result)
Definition: reader_lp.c:3459
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
Definition: scip.c:5287
LpSense
Definition: reader_diff.c:58
#define SCIP_Longint
Definition: def.h:120
int SCIPvarGetIndex(SCIP_VAR *var)
Definition: var.c:16849
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16717
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
Definition: misc.c:2366
SCIP_RETCODE SCIPcreateConsBounddisjunction(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_BOUNDTYPE *boundtypes, SCIP_Real *bounds, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:45864
static SCIP_Bool isValue(SCIP *scip, LPINPUT *lpinput, SCIP_Real *value)
Definition: reader_lp.c:747
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPcreateConsSOS1(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_sos1.c:10322
constraint handler for SOS type 2 constraints
SCIP_RETCODE SCIPcreateConsSOS2(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_sos2.c:2289
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17232
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
Definition: scip.h:21910
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
Definition: scip.c:46187
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:85
SCIP_QUADVARTERM * SCIPgetQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPwriteLp(SCIP *scip, FILE *file, const char *name, SCIP_Bool transformed, SCIP_OBJSENSE objsense, SCIP_Real objscale, SCIP_Real objoffset, SCIP_VAR **vars, int nvars, int nbinvars, int nintvars, int nimplvars, int ncontvars, SCIP_CONS **conss, int nconss, SCIP_RESULT *result)
Definition: reader_lp.c:3532
int SCIPfclose(SCIP_FILE *fp)
Definition: fileio.c:219
constraint handler for bound disjunction constraints
SCIP_CONS * SCIPgetLinearConsIndicator(SCIP_CONS *cons)
SCIP_Longint * SCIPgetWeightsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsVarbound(SCIP *scip, SCIP_CONS *cons)
#define SCIPABORT()
Definition: def.h:278
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_Bool hasError(LPINPUT *lpinput)
Definition: reader_lp.c:164
static void clearLine(char *linebuffer, int *linecnt)
Definition: reader_lp.c:2555
SCIP_Real * SCIPgetLhsCoefsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5510
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
Definition: scip.c:5263
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
Definition: scip.c:18663
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4176
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:16707
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:21929