Scippy

SCIP

Solving Constraint Integer Programs

reader_gms.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_gms.c
17  * @brief GAMS file writer
18  * @author Ambros Gleixner
19  * @author Stefan Vigerske
20  *
21  * @todo Check for words reserved for GAMS.
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #include <stdlib.h>
27 #include <assert.h>
28 #include <string.h>
29 
30 #ifdef WITH_GAMS
31 #include <sys/stat.h>
32 
33 #include "gmomcc.h"
34 #include "gevmcc.h"
35 
36 #include "reader_gmo.h"
37 #endif
38 
39 #include "scip/reader_gms.h"
40 #include "scip/cons_knapsack.h"
41 #include "scip/cons_linear.h"
42 #include "scip/cons_logicor.h"
43 #include "scip/cons_quadratic.h"
44 #include "scip/cons_soc.h"
45 #include "scip/cons_sos1.h"
46 #include "scip/cons_sos2.h"
47 #include "scip/cons_setppc.h"
48 #include "scip/cons_varbound.h"
49 #include "scip/cons_indicator.h"
50 #include "scip/cons_abspower.h"
51 #include "scip/cons_nonlinear.h"
52 #include "scip/cons_bivariate.h"
53 #include "scip/pub_misc.h"
54 
55 #define READER_NAME "gmsreader"
56 #ifdef WITH_GAMS
57 #define READER_DESC "file writer for MI(NL)(SOC)Ps in GAMS file format"
58 #else
59 #define READER_DESC "file reader and writer for MI(NL)(SOC)Ps in GAMS file format"
60 #endif
61 #define READER_EXTENSION "gms"
62 
63 
64 #define GMS_MAX_LINELEN 256
65 #define GMS_MAX_PRINTLEN 256 /**< the maximum length of any line is 255 + '\\0' = 256*/
66 #define GMS_MAX_NAMELEN 64 /**< the maximum length for any name is 63 + '\\0' = 64 */
67 #define GMS_PRINTLEN 100
68 #define GMS_DEFAULT_BIGM 1e+6
69 #define GMS_DEFAULT_INDICATORREFORM 's'
70 #define GMS_DEFAULT_SIGNPOWER FALSE
71 
72 /*
73  * Local methods (for writing)
74  */
75 
76 static const char badchars[] = "#*+/-@$[](){}";
77 
78 /** transforms given variables, scalars, and constant to the corresponding active variables, scalars, and constant */
79 static
81  SCIP* scip, /**< SCIP data structure */
82  SCIP_VAR** vars, /**< vars array to get active variables for */
83  SCIP_Real* scalars, /**< scalars a_1, ..., a_n in linear sum a_1*x_1 + ... + a_n*x_n + c */
84  int* nvars, /**< pointer to number of variables and values in vars and vals array */
85  SCIP_Real* constant, /**< pointer to constant c in linear sum a_1*x_1 + ... + a_n*x_n + c */
86  SCIP_Bool transformed /**< transformed constraint? */
87  )
88 {
89  int requiredsize;
90  int v;
91 
92  assert( scip != NULL );
93  assert( vars != NULL );
94  assert( scalars != NULL );
95  assert( nvars != NULL );
96  assert( constant != NULL );
97 
98  if( transformed )
99  {
100  SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
101 
102  if( requiredsize > *nvars )
103  {
104  SCIP_CALL( SCIPreallocBufferArray(scip, &vars, requiredsize) );
105  SCIP_CALL( SCIPreallocBufferArray(scip, &scalars, requiredsize) );
106 
107  SCIP_CALL( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, requiredsize, constant, &requiredsize, TRUE) );
108  assert( requiredsize <= *nvars );
109  }
110  }
111  else
112  {
113  for( v = 0; v < *nvars; ++v )
114  {
115  SCIP_CALL( SCIPvarGetOrigvarSum(&vars[v], &scalars[v], constant) );
116  }
117  }
118  return SCIP_OKAY;
119 }
120 
121 /** clears the given line buffer */
122 static
124  char* linebuffer, /**< line */
125  int* linecnt /**< number of characters in line */
126  )
127 {
128  assert( linebuffer != NULL );
129  assert( linecnt != NULL );
130 
131  (*linecnt) = 0;
132  linebuffer[0] = '\0';
133 }
134 
135 /** ends the given line with '\\0' and prints it to the given file stream */
136 static
137 void endLine(
138  SCIP* scip, /**< SCIP data structure */
139  FILE* file, /**< output file (or NULL for standard output) */
140  char* linebuffer, /**< line */
141  int* linecnt /**< number of characters in line */
142  )
143 {
144  assert( scip != NULL );
145  assert( linebuffer != NULL );
146  assert( linecnt != NULL );
147 
148  if( (*linecnt) > 0 )
149  {
150  linebuffer[(*linecnt)] = '\0';
151  SCIPinfoMessage(scip, file, "%s\n", linebuffer);
152  clearLine(linebuffer, linecnt);
153  }
154 }
155 
156 /** appends extension to line and prints it to the give file stream if the
157  * line exceeded the length given in the define GMS_PRINTLEN */
158 static
160  SCIP* scip, /**< SCIP data structure */
161  FILE* file, /**< output file (or NULL for standard output) */
162  char* linebuffer, /**< line */
163  int* linecnt, /**< number of characters in line */
164  const char* extension /**< string to extend the line */
165  )
166 {
167  size_t len;
168  assert( scip != NULL );
169  assert( linebuffer != NULL );
170  assert( linecnt != NULL );
171  assert( extension != NULL );
172  assert( strlen(linebuffer) + strlen(extension) < GMS_MAX_PRINTLEN );
173 
174  /* NOTE: avoid
175  * sprintf(linebuffer, "%s%s", linebuffer, extension);
176  * because of overlapping memory areas in memcpy used in sprintf.
177  */
178  len = strlen(linebuffer);
179  strncat(linebuffer, extension, GMS_MAX_PRINTLEN - len);
180 
181  (*linecnt) += (int) strlen(extension);
182 
183  SCIPdebugMsg(scip, "linebuffer <%s>, length = %lu\n", linebuffer, (unsigned long)len);
184 
185  if( (*linecnt) > GMS_PRINTLEN )
186  endLine(scip, file, linebuffer, linecnt);
187 }
188 
189 /** appends extension to line and prints it to the give file stream if the
190  * line exceeded the length given in the define GMS_PRINTLEN
191  * indents the line by some spaces if it is a new line */
192 static
194  SCIP* scip, /**< SCIP data structure */
195  FILE* file, /**< output file (or NULL for standard output) */
196  char* linebuffer, /**< line */
197  int* linecnt, /**< number of characters in line */
198  const char* extension /**< string to extend the line */
199  )
200 {
201  if( *linecnt == 0 )
202  /* we start a new line; therefore we indent line */
203  appendLine(scip, file, linebuffer, linecnt, " ");
204 
205  appendLine(scip, file, linebuffer, linecnt, extension);
206 }
207 
208 /** checks string for occurences of bad symbols and replace those by '_' */
209 static
211  char* name /**< string to adjust */
212  )
213 {
214  const char* badchar;
215 
216  assert( name != NULL );
217 
218  for( badchar = badchars; *badchar; ++badchar )
219  {
220  char* c = strchr(name, *badchar);
221 
222  while( c != NULL )
223  {
224  assert( *c == *badchar );
225 
226  *c = '_';
227  c = strchr(c, *badchar);
228  }
229  }
230 }
231 
232 /* print first len-1 characters of name to string s and replace '#', '*', '+', '/', and '-' by '_' if necessary */
233 static
235  SCIP* scip, /**< SCIP data structure */
236  char* t, /**< target string */
237  int len, /**< length of t */
238  const char* name /**< source string or format string */
239  )
240 {
241  SCIP_Bool replaceforbiddenchars;
242 
243  assert( t != NULL );
244  assert( len > 0 );
245 
246  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/replaceforbiddenchars", &replaceforbiddenchars) );
247 
248  (void) SCIPsnprintf(t, len, "%s", name);
249 
250  if( replaceforbiddenchars )
251  conformName(t);
252 
253  return SCIP_OKAY;
254 }
255 
256 
257 /* retransform to active variables and print in GAMS format to file stream with surrounding bracket, pre- and suffix */
258 static
260  SCIP* scip, /**< SCIP data structure */
261  FILE* file, /**< output file (or NULL for standard output) */
262  char* linebuffer, /**< line */
263  int* linecnt, /**< number of characters in line */
264  const char* prefix, /**< prefix (maybe NULL) */
265  const char* suffix, /**< suffix (maybe NULL) */
266  int nvars, /**< number of variables */
267  SCIP_VAR** vars, /**< array of variables */
268  SCIP_Real* vals, /**< array of values (or NULL if all ones) */
269  SCIP_Bool transformed /**< transformed constraint? */
270  )
271 {
272  int v;
273  int closingbracket;
274 
275  SCIP_VAR* var;
276  char varname[GMS_MAX_NAMELEN];
277  char buffer[GMS_MAX_PRINTLEN];
278  char ext[GMS_MAX_PRINTLEN];
279 
280  SCIP_VAR** activevars = NULL;
281  SCIP_Real* activevals = NULL;
282  int nactivevars;
283  SCIP_Real activeconstant = 0.0;
284 
285  assert( scip != NULL );
286  assert( vars != NULL || nvars == 0 );
287 
288 
289  if( *linecnt == 0 )
290  /* we start a new line; therefore we tab this line */
291  appendLine(scip, file, linebuffer, linecnt, " ");
292 
293  if( nvars == 0 )
294  {
295  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s(0)%s", prefix != NULL ? prefix : "", suffix != NULL ? suffix : "");
296 
297  appendLine(scip, file, linebuffer, linecnt, buffer);
298  }
299  else
300  {
301  nactivevars = nvars;
302 
303  /* duplicate variable and value array */
304  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars) );
305  if( vals != NULL )
306  {
307  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars) );
308  }
309  else
310  {
311  SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );
312 
313  for( v = 0; v < nactivevars; ++v )
314  activevals[v] = 1.0;
315  }
316 
317  /* retransform given variables to active variables */
318  SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
319 
320  assert( nactivevars == 0 || activevals != NULL );
321 
322  if( nactivevars == 0 && SCIPisZero(scip, activeconstant) )
323  {
324  if( *linecnt == 0 )
325  /* we start a new line; therefore we tab this line */
326  appendLine(scip, file, linebuffer, linecnt, " ");
327 
328  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s(0)%s", prefix != NULL ? prefix : "", suffix != NULL ? suffix : "");
329 
330  appendLine(scip, file, linebuffer, linecnt, buffer);
331  }
332  else
333  {
334  /* buffer prefix */
335  (void) SCIPsnprintf(ext, GMS_MAX_PRINTLEN, "%s(", prefix != NULL ? prefix : "");
336 
337  /* find position of closing bracket */
338  closingbracket = nactivevars;
339  if( SCIPisZero(scip, activeconstant) )
340  {
341  do
342  --closingbracket;
343  while( SCIPisZero(scip, activevals[closingbracket]) && closingbracket > 0 );
344  }
345 
346  /* print active variables */
347  for( v = 0; v < nactivevars; ++v )
348  {
349  var = activevars[v];
350  assert( var != NULL );
351 
352  if( !SCIPisZero(scip, activevals[v]) )
353  {
354  if( *linecnt == 0 )
355  /* we start a new line; therefore we tab this line */
356  appendLine(scip, file, linebuffer, linecnt, " ");
357 
358  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
359 
360  if( SCIPisEQ(scip, activevals[v], 1.0) )
361  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s%s%s%s%s", ext, strchr(ext, '(') == NULL ? "+" : "",
362  varname, (v == closingbracket) ? ")" : "", (v == closingbracket && suffix) ? suffix : "");
363  else if( SCIPisEQ(scip, activevals[v], -1.0) )
364  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s-%s%s%s", ext,
365  varname, (v == closingbracket) ? ")" : "", (v == closingbracket && suffix) ? suffix : "");
366  else if( strchr(ext, '(') != NULL )
367  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s%.15g*%s%s%s", ext,
368  activevals[v], varname, (v == closingbracket) ? ")" : "", (v == closingbracket && suffix) ? suffix : "");
369  else
370  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s%+.15g*%s%s%s", ext,
371  activevals[v], varname, (v == closingbracket) ? ")" : "", (v == closingbracket && suffix) ? suffix : "");
372 
373  appendLine(scip, file, linebuffer, linecnt, buffer);
374 
375  (void) SCIPsnprintf(ext, GMS_MAX_PRINTLEN, (*linecnt == 0) ? "" : " ");
376  }
377  }
378 
379  /* print active constant */
380  if( !SCIPisZero(scip, activeconstant) )
381  {
382  if( *linecnt == 0 )
383  /* we start a new line; therefore we tab this line */
384  appendLine(scip, file, linebuffer, linecnt, " ");
385 
386  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s%+.15g)%s", ext, activeconstant, suffix ? suffix : "");
387 
388  appendLine(scip, file, linebuffer, linecnt, buffer);
389  }
390  /* nothing has been printed, yet */
391  else if( strchr(ext, '(') != NULL )
392  {
393  if( *linecnt == 0 )
394  /* we start a new line; therefore we tab this line */
395  appendLine(scip, file, linebuffer, linecnt, " ");
396 
397  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s(0)%s", prefix ? prefix : "", suffix ? suffix : "");
398 
399  appendLine(scip, file, linebuffer, linecnt, buffer);
400  }
401  }
402 
403  /* free buffer arrays */
404  SCIPfreeBufferArray(scip, &activevars);
405  SCIPfreeBufferArray(scip, &activevals);
406  }
407 
408  return SCIP_OKAY;
409 }
410 
411 
412 /* print linear row in GAMS format to file stream (without retransformation to active variables) */
413 static
415  SCIP* scip, /**< SCIP data structure */
416  FILE* file, /**< output file (or NULL for standard output) */
417  const char* rowname, /**< row name */
418  const char* rownameextension, /**< row name extension */
419  const char* type, /**< row type ("=e=", "=l=", or "=g=") */
420  int nvars, /**< number of variables */
421  SCIP_VAR** vars, /**< array of variables */
422  SCIP_Real* vals, /**< array of values */
423  SCIP_Real rhs /**< right hand side */
424  )
425 {
426  int v;
427  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
428  int linecnt;
429 
430  SCIP_VAR* var;
431  char varname[GMS_MAX_NAMELEN];
432  char consname[GMS_MAX_NAMELEN + 3]; /* four extra characters for ' ..' */
433  char buffer[GMS_MAX_PRINTLEN];
434 
435  assert( scip != NULL );
436  assert( strcmp(type, "=e=") == 0 || strcmp(type, "=l=") == 0 || strcmp(type, "=g=") == 0);
437  assert( nvars == 0 || (vars != NULL && vals != NULL) );
438 
439  clearLine(linebuffer, &linecnt);
440 
441  /* start each line with a space */
442  appendLine(scip, file, linebuffer, &linecnt, " ");
443 
444  /* print row name */
445  if( strlen(rowname) > 0 || strlen(rownameextension) > 0 )
446  {
447  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%s%s ..", rowname, rownameextension);
448  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN + 3, buffer) );
449  appendLine(scip, file, linebuffer, &linecnt, consname);
450  }
451 
452  /* print coefficients */
453  if( nvars == 0 )
454  {
455  /* we start a new line; therefore we tab this line */
456  if( linecnt == 0 )
457  appendLine(scip, file, linebuffer, &linecnt, " ");
458 
459  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " 0");
460 
461  appendLine(scip, file, linebuffer, &linecnt, buffer);
462  }
463 
464  for( v = 0; v < nvars; ++v )
465  {
466  var = vars[v];
467  assert( var != NULL );
468 
469  /* we start a new line; therefore we tab this line */
470  if( linecnt == 0 )
471  appendLine(scip, file, linebuffer, &linecnt, " ");
472 
473  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
474  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g*%s", vals[v], varname);
475 
476  appendLine(scip, file, linebuffer, &linecnt, buffer);
477  }
478 
479  /* print right hand side */
480  if( SCIPisZero(scip, rhs) )
481  rhs = 0.0;
482 
483  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s %.15g;", type, rhs);
484 
485  /* we start a new line; therefore we tab this line */
486  if( linecnt == 0 )
487  appendLine(scip, file, linebuffer, &linecnt, " ");
488  appendLine(scip, file, linebuffer, &linecnt, buffer);
489 
490  endLine(scip, file, linebuffer, &linecnt);
491 
492  return SCIP_OKAY;
493 }
494 
495 
496 /** prints given linear constraint information in GAMS format to file stream */
497 static
499  SCIP* scip, /**< SCIP data structure */
500  FILE* file, /**< output file (or NULL for standard output) */
501  const char* rowname, /**< name of the row */
502  int nvars, /**< number of variables */
503  SCIP_VAR** vars, /**< array of variables */
504  SCIP_Real* vals, /**< array of coefficients values (or NULL if all coefficient values are 1) */
505  SCIP_Real lhs, /**< left hand side */
506  SCIP_Real rhs, /**< right hand side */
507  SCIP_Bool transformed /**< transformed constraint? */
508  )
509 {
510  int v;
511  SCIP_VAR** activevars = NULL;
512  SCIP_Real* activevals = NULL;
513  int nactivevars;
514  SCIP_Real activeconstant = 0.0;
515 
516  assert( scip != NULL );
517  assert( rowname != NULL );
518 
519  /* The GAMS format does not forbid that the variable array is empty */
520  assert( nvars == 0 || vars != NULL );
521 
522  assert( lhs <= rhs );
523 
524  if( SCIPisInfinity(scip, -lhs) && SCIPisInfinity(scip, rhs) )
525  return SCIP_OKAY;
526 
527  nactivevars = nvars;
528  if( nvars > 0 )
529  {
530  /* duplicate variable and value array */
531  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars) );
532  if( vals != NULL )
533  {
534  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars) );
535  }
536  else
537  {
538  SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );
539 
540  for( v = 0; v < nactivevars; ++v )
541  activevals[v] = 1.0;
542  }
543 
544  /* retransform given variables to active variables */
545  SCIP_CALL( getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, transformed) );
546  }
547 
548  /* print row(s) in GAMS format */
549  if( SCIPisEQ(scip, lhs, rhs) )
550  {
551  assert( !SCIPisInfinity(scip, rhs) );
552 
553  /* print equality constraint */
554  SCIP_CALL( printLinearRow(scip, file, rowname, "", "=e=",
555  nactivevars, activevars, activevals, rhs - activeconstant) );
556  }
557  else
558  {
559  if( !SCIPisInfinity(scip, -lhs) )
560  {
561  /* print inequality ">=" */
562  SCIP_CALL( printLinearRow(scip, file, rowname, SCIPisInfinity(scip, rhs) ? "" : "_lhs", "=g=",
563  nactivevars, activevars, activevals, lhs - activeconstant) );
564  }
565  if( !SCIPisInfinity(scip, rhs) )
566  {
567  /* print inequality "<=" */
568  SCIP_CALL( printLinearRow(scip, file, rowname, SCIPisInfinity(scip, -lhs) ? "" : "_rhs", "=l=",
569  nactivevars, activevars, activevals, rhs - activeconstant) );
570  }
571  }
572 
573  if( nvars > 0 )
574  {
575  /* free buffer arrays */
576  SCIPfreeBufferArray(scip, &activevars);
577  SCIPfreeBufferArray(scip, &activevals);
578  }
579 
580  return SCIP_OKAY;
581 }
582 
583 
584 /* print quadratic row in GAMS format to file stream (performing retransformation to active variables) */
585 static
587  SCIP* scip, /**< SCIP data structure */
588  FILE* file, /**< output file (or NULL for standard output) */
589  const char* rowname, /**< row name */
590  const char* rownameextension, /**< row name extension */
591  const char* type, /**< row type ("=e=", "=l=", or "=g=") */
592  int nlinvars, /**< number of linear terms */
593  SCIP_VAR** linvars, /**< variables in linear part */
594  SCIP_Real* lincoeffs, /**< coefficients of variables in linear part */
595  int nquadvarterms, /**< number of quadratic variable terms */
596  SCIP_QUADVARTERM* quadvarterms, /**< quadratic variable terms */
597  int nbilinterms, /**< number of bilinear terms */
598  SCIP_BILINTERM* bilinterms, /**< bilinear terms */
599  SCIP_Real rhs, /**< right hand side */
600  SCIP_Bool transformed /**< transformed constraint? */
601  )
602 {
603  int t;
604  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
605  int linecnt;
606 
607  SCIP_VAR* var;
608  char consname[GMS_MAX_NAMELEN + 3]; /* four extra characters for ' ..' */
609  char buffer[GMS_MAX_PRINTLEN];
610 
611  assert( scip != NULL );
612  assert( strlen(rowname) > 0 || strlen(rownameextension) > 0 );
613  assert( strcmp(type, "=e=") == 0 || strcmp(type, "=l=") == 0 || strcmp(type, "=g=") == 0 );
614  assert( nlinvars == 0 || (linvars != NULL && lincoeffs != NULL) );
615  assert( nquadvarterms == 0 || quadvarterms != NULL );
616  assert( nbilinterms == 0 || bilinterms != NULL );
617  assert( nquadvarterms > 0 || nbilinterms == 0 );
618 
619  clearLine(linebuffer, &linecnt);
620 
621  /* start each line with a space */
622  appendLine(scip, file, linebuffer, &linecnt, " ");
623 
624  /* print row name */
625  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%s%s ..", rowname, rownameextension);
626  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN + 3, buffer) );
627 
628  appendLine(scip, file, linebuffer, &linecnt, consname);
629 
630  /* print linear terms */
631  if( nlinvars > 0 )
632  {
633  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", " ", nlinvars, linvars, lincoeffs, transformed) );
634  }
635 
636  /* print linear coefficients of quadratic terms */
637  for( t = 0; t < nquadvarterms; ++t )
638  {
639  var = quadvarterms[t].var;
640  assert( var != NULL );
641 
642  if( !SCIPisZero(scip, quadvarterms[t].lincoef) )
643  {
644  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%+.15g*", quadvarterms[t].lincoef);
645 
646  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, buffer, NULL, 1, &var, NULL, transformed) );
647  }
648  }
649 
650  /* print square coefficients of quadratic terms */
651  for( t = 0; t < nquadvarterms; ++t )
652  {
653  var = quadvarterms[t].var;
654  assert( var != NULL );
655 
656  if( !SCIPisZero(scip, quadvarterms[t].sqrcoef) )
657  {
658  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%+.15g*sqr", quadvarterms[t].sqrcoef);
659 
660  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, buffer, NULL, 1, &var, NULL, transformed) );
661  }
662  }
663 
664  /* print bilinear terms */
665  for( t = 0; t < nbilinterms; ++t )
666  {
667  if( !SCIPisZero(scip, bilinterms[t].coef) )
668  {
669  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%+.15g*", bilinterms[t].coef);
670 
671  /* print first variable (retransformed to active variables) */
672  var = bilinterms[t].var1;
673  assert( var != NULL );
674 
675  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, buffer, "", 1, &var, NULL, transformed) );
676 
677  /* print second variable (retransformed to active variables) */
678  var = bilinterms[t].var2;
679  assert( var != NULL );
680 
681  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "*", " ", 1, &var, NULL, transformed) );
682  }
683  }
684 
685  /* print right hand side */
686  if( linecnt == 0 )
687  /* we start a new line; therefore we tab this line */
688  appendLine(scip, file, linebuffer, &linecnt, " ");
689 
690  if( SCIPisZero(scip, rhs) )
691  rhs = 0.0;
692 
693  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s%s %.15g;", (nlinvars == 0 && nquadvarterms == 0) ? "0 " : "", type, rhs);
694 
695  appendLine(scip, file, linebuffer, &linecnt, buffer);
696 
697  endLine(scip, file, linebuffer, &linecnt);
698 
699  return SCIP_OKAY;
700 }
701 
702 
703 /** prints given quadratic constraint information in GAMS format to file stream */
704 static
706  SCIP* scip, /**< SCIP data structure */
707  FILE* file, /**< output file (or NULL for standard output) */
708  const char* rowname, /**< name of the row */
709  int nlinvars, /**< number of linear terms */
710  SCIP_VAR** linvars, /**< variables in linear part */
711  SCIP_Real* lincoeffs, /**< coefficients of variables in linear part */
712  int nquadvarterms, /**< number of quadratic variable terms */
713  SCIP_QUADVARTERM* quadvarterms, /**< quadratic variable terms */
714  int nbilinterms, /**< number of bilinear terms */
715  SCIP_BILINTERM* bilinterms, /**< bilinear terms */
716  SCIP_Real lhs, /**< left hand side */
717  SCIP_Real rhs, /**< right hand side */
718  SCIP_Bool transformed /**< transformed constraint? */
719  )
720 {
721  assert( scip != NULL );
722  assert( rowname != NULL );
723  assert( nlinvars == 0 || (linvars != NULL && lincoeffs != NULL) );
724  assert( nquadvarterms == 0 || quadvarterms != NULL );
725  assert( nbilinterms == 0 || bilinterms != NULL );
726  assert( nquadvarterms > 0 || nbilinterms == 0 );
727  assert( lhs <= rhs );
728 
729  if( SCIPisInfinity(scip, -lhs) && SCIPisInfinity(scip, rhs) )
730  return SCIP_OKAY;
731 
732  /* print row(s) in GAMS format */
733  if( SCIPisEQ(scip, lhs, rhs) )
734  {
735  assert( !SCIPisInfinity(scip, rhs) );
736 
737  /* print equality constraint */
738  SCIP_CALL( printQuadraticRow(scip, file, rowname, "", "=e=",
739  nlinvars, linvars, lincoeffs,
740  nquadvarterms, quadvarterms,
741  nbilinterms, bilinterms, rhs, transformed) );
742  }
743  else
744  {
745  if( !SCIPisInfinity(scip, -lhs) )
746  {
747  /* print inequality ">=" */
748  SCIP_CALL( printQuadraticRow(scip, file, rowname, SCIPisInfinity(scip, rhs) ? "" : "_lhs", "=g=",
749  nlinvars, linvars, lincoeffs,
750  nquadvarterms, quadvarterms,
751  nbilinterms, bilinterms, lhs, transformed) );
752  }
753  if( !SCIPisInfinity(scip, rhs) )
754  {
755  /* print inequality "<=" */
756  SCIP_CALL( printQuadraticRow(scip, file, rowname, SCIPisInfinity(scip, -lhs) ? "" : "_rhs", "=l=",
757  nlinvars, linvars, lincoeffs,
758  nquadvarterms, quadvarterms,
759  nbilinterms, bilinterms, rhs, transformed) );
760  }
761  }
762 
763  return SCIP_OKAY;
764 }
765 
766 /** check GAMS limitations on SOC constraints
767  * returns true of constraint can be written as conic equation in GAMS (using equation type =C=)
768  */
769 static
771  int nlhsvars, /**< number of variables on left hand side */
772  SCIP_VAR** lhsvars, /**< variables on left hand side */
773  SCIP_Real* lhscoeffs, /**< coefficients of variables on left hand side, or NULL if == 1.0 */
774  SCIP_Real* lhsoffsets, /**< offsets of variables on left hand side, or NULL if == 0.0 */
775  SCIP_Real lhsconstant, /**< constant on left hand side */
776  SCIP_VAR* rhsvar, /**< variable on right hand side */
777  SCIP_Real rhscoef, /**< coefficient of variable on right hand side */
778  SCIP_Real rhsoffset /**< offset of variable on right hand side */
779  )
780 {
781  int i;
782 
783  assert(nlhsvars == 0 || lhsvars != NULL);
784 
785  if( rhscoef != 1.0 )
786  return FALSE;
787 
788  if( rhsoffset != 0.0 )
789  return FALSE;
790 
791  if( rhsvar == NULL )
792  return FALSE;
793 
794  if( !SCIPvarIsActive(rhsvar) )
795  return FALSE;
796 
797  if( lhsconstant != 0.0 )
798  return FALSE;
799 
800  if( nlhsvars < 2 )
801  return FALSE;
802 
803  for( i = 0; i < nlhsvars; ++i )
804  {
805  if( lhscoeffs [i] != 1.0 )
806  return FALSE;
807 
808  if( lhsoffsets[i] != 0.0 )
809  return FALSE;
810 
811  if( !SCIPvarIsActive(lhsvars[i]) )
812  return FALSE;
813  }
814 
815  return TRUE;
816 }
817 
818 /* print second order cone row in GAMS format to file stream (performing retransformation to active variables)
819  * The constraints are of the following form:
820  * \f[
821  * \left\{ x \;:\; \sqrt{\gamma + \sum_{i=1}^{n} (\alpha_i\, (x_i + \beta_i))^2} \leq \alpha_{n+1}\, (x_{n+1}+\beta_{n+1}) \right\}.
822  * \f]
823  * */
824 static
826  SCIP* scip, /**< SCIP data structure */
827  FILE* file, /**< output file (or NULL for standard output) */
828  const char* rowname, /**< row name */
829  int nlhsvars, /**< number of variables on left hand side */
830  SCIP_VAR** lhsvars, /**< variables on left hand side */
831  SCIP_Real* lhscoeffs, /**< coefficients of variables on left hand side, or NULL if == 1.0 */
832  SCIP_Real* lhsoffsets, /**< offsets of variables on left hand side, or NULL if == 0.0 */
833  SCIP_Real lhsconstant, /**< constant on left hand side */
834  SCIP_VAR* rhsvar, /**< variable on right hand side */
835  SCIP_Real rhscoef, /**< coefficient of variable on right hand side */
836  SCIP_Real rhsoffset, /**< offset of variable on right hand side */
837  SCIP_Bool transformed /**< transformed constraint? */
838  )
839 {
840  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
841  int linecnt;
842 
843  char consname[GMS_MAX_NAMELEN + 3]; /* four extra characters for ' ..' */
844  char buffer[GMS_MAX_PRINTLEN];
845 
846  assert( scip != NULL );
847  assert( strlen(rowname) > 0 );
848  assert( nlhsvars == 0 || lhsvars != NULL );
849 
850  clearLine(linebuffer, &linecnt);
851 
852  /* start each line with a space */
853  appendLine(scip, file, linebuffer, &linecnt, " ");
854 
855  /* print row name */
856  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%s ..", rowname);
857  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN + 3, buffer) );
858 
859  appendLine(scip, file, linebuffer, &linecnt, consname);
860 
861  if( !isGAMSprintableSOC(nlhsvars, lhsvars, lhscoeffs, lhsoffsets, lhsconstant, rhsvar, rhscoef, rhsoffset) )
862  {
863  int t;
864 
865  /* print right-hand side on left */
866  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "sqr(%.15g +", rhsoffset);
867 
868  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, buffer, ")", 1, &rhsvar, &rhscoef, transformed) );
869 
870  appendLine(scip, file, linebuffer, &linecnt, " =g= ");
871 
872  /* print left-hand side on right */
873 
874  if( lhsconstant != 0.0 )
875  {
876  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", lhsconstant);
877 
878  appendLine(scip, file, linebuffer, &linecnt, buffer);
879  }
880 
881  for( t = 0; t < nlhsvars; ++t )
882  {
883  assert( lhsvars[t] != NULL );
884 
885  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "+ sqr(%.15g * (%.15g + ", lhscoeffs ? lhscoeffs[t] : 1.0, lhsoffsets ? lhsoffsets[t] : 0.0);
886 
887  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, buffer, "))", 1, &lhsvars[t], NULL, transformed) );
888  }
889  }
890  else
891  {
892  /* print right-hand side on left */
893  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", " ", 1, &rhsvar, &rhscoef, transformed) );
894 
895  appendLine(scip, file, linebuffer, &linecnt, " =c= ");
896 
897  /* print left-hand side on right */
898  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", " ", nlhsvars, lhsvars, lhscoeffs, transformed) );
899  }
900 
901  appendLine(scip, file, linebuffer, &linecnt, ";");
902 
903  endLine(scip, file, linebuffer, &linecnt);
904 
905  return SCIP_OKAY;
906 }
907 
908 /* print indicator constraint in some GAMS format to file stream (performing retransformation to active variables)
909  * The constraints are of the following form:
910  * \f[
911  * z = 1 -> s = 0
912  * \f]
913  * */
914 static
916  SCIP* scip, /**< SCIP data structure */
917  FILE* file, /**< output file (or NULL for standard output) */
918  const char* rowname, /**< row name */
919  SCIP_VAR* z, /**< indicating variable (binary) */
920  SCIP_VAR* s, /**< slack variable */
921  SCIP_Bool* sossetdeclr, /**< buffer to store whether we declared the SOS set for indicator reform */
922  SCIP_Bool transformed /**< transformed constraint? */
923  )
924 {
925  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
926  int linecnt;
927  SCIP_Real coef;
928  char indicatorform;
929 
930  char consname[GMS_MAX_NAMELEN + 30];
931  char buffer[GMS_MAX_PRINTLEN];
932 
933  assert( scip != NULL );
934  assert( strlen(rowname) > 0 );
935  assert( z != NULL );
936  assert( s != NULL );
937  assert( SCIPvarIsBinary(z) );
938  assert( sossetdeclr != NULL );
939 
940  clearLine(linebuffer, &linecnt);
941 
942  /* start each line with a space */
943  appendLine(scip, file, linebuffer, &linecnt, " ");
944 
945  SCIP_CALL( SCIPgetCharParam(scip, "reading/gmsreader/indicatorreform", &indicatorform) );
946 
947  switch( indicatorform )
948  {
949  case 'b':
950  {
951  /* print row name */
952  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%s ..", rowname);
953  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN + 3, buffer) );
954 
955  appendLine(scip, file, linebuffer, &linecnt, consname);
956 
957  /* write as s <= upperbound(s)*(1-z) or s <= upperbound(s) * negation(z) */
958  coef = 1.0;
959  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, NULL, " =l= ", 1, &s, &coef, transformed) );
960 
961  coef = SCIPvarGetUbGlobal(s);
962  if( SCIPisInfinity(scip, coef) )
963  {
964  SCIP_CALL( SCIPgetRealParam(scip, "reading/gmsreader/bigmdefault", &coef) );
965 
966  SCIPwarningMessage(scip, "do not have upper bound on slack variable <%s> in indicator constraint <%s>, will use M = %g.\n",
967  SCIPvarGetName(s), rowname, coef);
968  }
969 
970  if( SCIPvarIsNegated(z) )
971  {
972  SCIP_CALL( SCIPgetNegatedVar(scip, z, &z) );
973  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "", ";", 1, &z, &coef, transformed) );
974  }
975  else
976  {
977  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g + ", coef);
978 
979  coef = -coef;
980  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, buffer, ";", 1, &z, &coef, transformed) );
981  }
982 
983  break;
984  }
985 
986  case 's':
987  {
988  /* write as
989  * sos1 Variable name_sos(sosset);
990  * name_soseq(sosset).. name_sos(sosset) =e= s$(sameas(sosset,'slack') + z$(sameas(sosset,'bin'));
991  */
992  coef = 1.0;
993  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, rowname) );
994 
995  /* declare set for SOS1 declarations from reformulation of indicator, if needed */
996  if( !*sossetdeclr )
997  {
998  SCIPinfoMessage(scip, file, " Set sosset / slack, bin /;\n");
999  *sossetdeclr = TRUE;
1000  }
1001 
1002  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "sos1 Variable %s_sos(sosset);", consname);
1003  appendLine(scip, file, linebuffer, &linecnt, buffer);
1004  endLine(scip, file, linebuffer, &linecnt);
1005 
1006  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s(sosset).. %s_sos(sosset) =e= ", consname, consname);
1007  appendLine(scip, file, linebuffer, &linecnt, buffer);
1008  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, NULL, "$sameas(sosset,'slack')", 1, &s, &coef, transformed) );
1009  if( SCIPvarIsNegated(z) )
1010  {
1011  SCIP_CALL( SCIPgetNegatedVar(scip, z, &z) );
1012  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, " + (1-(", "))$sameas(sosset,'bin');", 1, &z, &coef, transformed) );
1013  }
1014  else
1015  {
1016  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, " + ", "$sameas(sosset,'bin');", 1, &z, &coef, transformed) );
1017  }
1018  endLine(scip, file, linebuffer, &linecnt);
1019 
1020  break;
1021  }
1022 
1023  default:
1024  SCIPerrorMessage("wrong value '%c' for parameter reading/gmsreader/indicatorreform\n", indicatorform);
1025  return SCIP_ERROR;
1026  }
1027 
1028  endLine(scip, file, linebuffer, &linecnt);
1029 
1030  return SCIP_OKAY;
1031 }
1032 
1033 /* print SOS constraint in some GAMS format to file stream (performing retransformation to active variables)
1034  *
1035  * write as
1036  * Set name_sosset /1*nvars/;
1037  * SOS1/2 Variable name_sosvar(name_sosset);
1038  * Equation name_sosequ(e1_sosset);
1039  * name_sosequ(name_sosset).. name_sosvar(e1_sosset) =e=
1040  * vars[0]$sameas(name_sosset, '1') + vars[1]$sameas(name_sosset, '2') + ... + vars[nvars-1]$sameas(name_sosset, nvars);
1041  */
1042 static
1044  SCIP* scip, /**< SCIP data structure */
1045  FILE* file, /**< output file (or NULL for standard output) */
1046  const char* rowname, /**< row name */
1047  int nvars, /**< number of variables in SOS */
1048  SCIP_VAR** vars, /**< variables in SOS */
1049  int sostype, /**< type of SOS: 1 or 2 */
1050  SCIP_Bool transformed /**< transformed constraint? */
1051  )
1052 {
1053  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
1054  int linecnt;
1055  SCIP_Real coef;
1056  int v;
1057 
1058  char consname[GMS_MAX_NAMELEN + 30];
1059  char buffer[GMS_MAX_PRINTLEN];
1060 
1061  assert( scip != NULL );
1062  assert( strlen(rowname) > 0 );
1063  assert( vars != NULL || nvars == 0 );
1064  assert( sostype == 1 || sostype == 2 );
1065 
1066  clearLine(linebuffer, &linecnt);
1067 
1068  /* start each line with a space */
1069  appendLine(scip, file, linebuffer, &linecnt, " ");
1070 
1071  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, rowname) );
1072 
1073  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "Set %s_sosset /1*%d/;", consname, nvars);
1074  appendLine(scip, file, linebuffer, &linecnt, buffer);
1075  endLine(scip, file, linebuffer, &linecnt);
1076 
1077  /* explicitly set lower bound of SOS variables to -inf, as GAMS default is 0.0 */
1078  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " SOS%d Variable %s_sosvar(%s_sosset); %s_sosvar.lo(%s_sosset) = -inf;", sostype, consname, consname, consname, consname);
1079  appendLine(scip, file, linebuffer, &linecnt, buffer);
1080  endLine(scip, file, linebuffer, &linecnt);
1081 
1082  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s(%s_sosset).. %s_sosvar(%s_sosset) =e= ", consname, consname, consname, consname);
1083  appendLine(scip, file, linebuffer, &linecnt, buffer);
1084  endLine(scip, file, linebuffer, &linecnt);
1085 
1086  coef = 1.0;
1087  for( v = 0; v < nvars; ++v )
1088  {
1089  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "$sameas(%s_sosset,'%d')", consname, v+1);
1090  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, v > 0 ? " + " : NULL, buffer, 1, &vars[v], &coef, transformed) ); /*lint !e613*/
1091  }
1092  appendLine(scip, file, linebuffer, &linecnt, ";");
1093  endLine(scip, file, linebuffer, &linecnt);
1094 
1095  return SCIP_OKAY;
1096 }
1097 
1098 /* print signpower row in GAMS format to file stream (performing retransformation to active variables) */
1099 static
1101  SCIP* scip, /**< SCIP data structure */
1102  FILE* file, /**< output file (or NULL for standard output) */
1103  const char* rowname, /**< row name */
1104  const char* rownameextension, /**< row name extension */
1105  const char* type, /**< row type ("=e=", "=l=", or "=g=") */
1106  SCIP_VAR* nonlinvar, /**< nonlinear variable */
1107  SCIP_VAR* linvar, /**< linear variable, may be NULL */
1108  SCIP_Real exponent, /**< exponent of nonlinear variable */
1109  SCIP_Real offset, /**< offset of nonlinear variable */
1110  SCIP_Real coeflinear, /**< coefficient of linear variable */
1111  SCIP_Real rhs, /**< right hand side */
1112  SCIP_Bool transformed, /**< transformed constraint? */
1113  SCIP_Bool signpowerallowed, /**< allowed to use signpower operator in GAMS? */
1114  SCIP_Bool* nsmooth /**< buffer to store whether we printed a nonsmooth function */
1115  )
1116 {
1117  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
1118  int linecnt;
1119  SCIP_Bool nisoddint;
1120  SCIP_Bool fixedsign;
1121 
1122  char consname[GMS_MAX_NAMELEN + 3]; /* four extra characters for ' ..' */
1123  char buffer[GMS_MAX_PRINTLEN];
1124 
1125  assert( scip != NULL );
1126  assert( strlen(rowname) > 0 || strlen(rownameextension) > 0 );
1127  assert( strcmp(type, "=e=") == 0 || strcmp(type, "=l=") == 0 || strcmp(type, "=g=") == 0 );
1128  assert( nonlinvar != NULL );
1129  assert( exponent > 1.0 );
1130  assert( nsmooth != NULL );
1131 
1132  clearLine(linebuffer, &linecnt);
1133 
1134  /* start each line with a space */
1135  appendLine(scip, file, linebuffer, &linecnt, " ");
1136 
1137  /* print row name */
1138  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%s%s ..", rowname, rownameextension);
1139  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN + 3, buffer) );
1140 
1141  appendLine(scip, file, linebuffer, &linecnt, consname);
1142 
1143  /* print nonlinear term
1144  * if not signpowerallowed, then signpow(x,n) is printed as x*abs(x) if n == 2, x*(abs(x)**(n-1)) if n is not 2 and not an odd integer, and as power(x,n) if n is an odd integer
1145  * if signpowerallowed, then signpow(x,n) is printed as power(x,n) if n is an odd integer and as signpower(x,n) otherwiser
1146  */
1147  nisoddint = SCIPisIntegral(scip, exponent) && ((int)SCIPfloor(scip, exponent+0.5))%2 == 1;
1148  fixedsign = !SCIPisNegative(scip, SCIPvarGetLbGlobal(nonlinvar)) || !SCIPisPositive(scip, SCIPvarGetUbGlobal(nonlinvar));
1149  if( !nisoddint && !fixedsign )
1150  {
1151  if( signpowerallowed )
1152  {
1153  if( offset != 0.0 )
1154  {
1155  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "signpower(%g ", offset);
1156  appendLine(scip, file, linebuffer, &linecnt, buffer);
1157  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", ",", 1, &nonlinvar, NULL, transformed) );
1158  }
1159  else
1160  {
1161  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "signpower(", ",", 1, &nonlinvar, NULL, transformed) );
1162  }
1163  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%g)", exponent);
1164  appendLine(scip, file, linebuffer, &linecnt, buffer);
1165  }
1166  else
1167  {
1168  if( offset != 0.0 )
1169  {
1170  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "(%g ", offset);
1171  appendLine(scip, file, linebuffer, &linecnt, buffer);
1172  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", ") * ", 1, &nonlinvar, NULL, transformed) );
1173  }
1174  else
1175  {
1176  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, NULL, " * ", 1, &nonlinvar, NULL, transformed) );
1177  }
1178 
1179  if( exponent == 2.0)
1180  {
1181  if( offset != 0.0 )
1182  {
1183  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "abs(%g ", offset);
1184  appendLine(scip, file, linebuffer, &linecnt, buffer);
1185  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", ")", 1, &nonlinvar, NULL, transformed) );
1186  }
1187  else
1188  {
1189  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "abs", NULL, 1, &nonlinvar, NULL, transformed) );
1190  }
1191  }
1192  else
1193  {
1194  if( offset != 0.0 )
1195  {
1196  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "abs(%g ", offset);
1197  appendLine(scip, file, linebuffer, &linecnt, buffer);
1198  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", ")", 1, &nonlinvar, NULL, transformed) );
1199  }
1200  else
1201  {
1202  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "abs", NULL, 1, &nonlinvar, NULL, transformed) );
1203  }
1204  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "**%g", exponent-1.0);
1205  appendLine(scip, file, linebuffer, &linecnt, buffer);
1206  }
1207  }
1208  *nsmooth = TRUE;
1209  }
1210  else if( nisoddint || !SCIPisNegative(scip, SCIPvarGetLbGlobal(nonlinvar)) )
1211  {
1212  if( exponent == 2.0 )
1213  {
1214  if( offset != 0.0 )
1215  {
1216  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "sqr(%g ", offset);
1217  appendLine(scip, file, linebuffer, &linecnt, buffer);
1218  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", ")", 1, &nonlinvar, NULL, transformed) );
1219  }
1220  else
1221  {
1222  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "sqr", NULL, 1, &nonlinvar, NULL, transformed) );
1223  }
1224  }
1225  else
1226  {
1227  if( offset != 0.0 )
1228  {
1229  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "power(%g ", offset);
1230  appendLine(scip, file, linebuffer, &linecnt, buffer);
1231  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", ",", 1, &nonlinvar, NULL, transformed) );
1232  }
1233  else
1234  {
1235  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "power(", ",", 1, &nonlinvar, NULL, transformed) );
1236  }
1237  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%g)", exponent);
1238  appendLine(scip, file, linebuffer, &linecnt, buffer);
1239  }
1240  }
1241  else
1242  {
1243  assert(fixedsign && !SCIPisPositive(scip, SCIPvarGetUbGlobal(nonlinvar)));
1244  if( exponent == 2.0 )
1245  {
1246  if( offset != 0.0 )
1247  {
1248  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "-sqr(%g ", -offset);
1249  appendLine(scip, file, linebuffer, &linecnt, buffer);
1250  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "-", ")", 1, &nonlinvar, NULL, transformed) );
1251  }
1252  else
1253  {
1254  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "-sqr(-", ")", 1, &nonlinvar, NULL, transformed) );
1255  }
1256  }
1257  else
1258  {
1259  if( offset != 0.0 )
1260  {
1261  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "-power(%g ", -offset);
1262  appendLine(scip, file, linebuffer, &linecnt, buffer);
1263  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "-", ",", 1, &nonlinvar, NULL, transformed) );
1264  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%g)", exponent);
1265  appendLine(scip, file, linebuffer, &linecnt, buffer);
1266  }
1267  else
1268  {
1269  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "-power(-", ",", 1, &nonlinvar, NULL, transformed) );
1270  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%g)", exponent);
1271  appendLine(scip, file, linebuffer, &linecnt, buffer);
1272  }
1273  }
1274  }
1275 
1276  /* print linear term */
1277  if( linvar != NULL )
1278  {
1279  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, " +", "", 1, &linvar, &coeflinear, transformed) );
1280  }
1281 
1282  /* print right hand side */
1283  if( linecnt == 0 )
1284  {
1285  /* we start a new line; therefore we tab this line */
1286  appendLine(scip, file, linebuffer, &linecnt, " ");
1287  }
1288 
1289  if( SCIPisZero(scip, rhs) )
1290  rhs = 0.0;
1291 
1292  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s %.15g;", type, rhs);
1293 
1294  appendLine(scip, file, linebuffer, &linecnt, buffer);
1295 
1296  endLine(scip, file, linebuffer, &linecnt);
1297 
1298  return SCIP_OKAY;
1299 }
1300 
1301 /* print signpower cons in GAMS format to file stream (performing retransformation to active variables)
1302  */
1303 static
1305  SCIP* scip, /**< SCIP data structure */
1306  FILE* file, /**< output file (or NULL for standard output) */
1307  const char* rowname, /**< row name */
1308  SCIP_VAR* nonlinvar, /**< nonlinear variable */
1309  SCIP_VAR* linvar, /**< linear variable, may be NULL */
1310  SCIP_Real exponent, /**< exponent of nonlinear variable */
1311  SCIP_Real offset, /**< offset of nonlinear variable */
1312  SCIP_Real coeflinear, /**< coefficient of linear variable */
1313  SCIP_Real lhs, /**< left hand side */
1314  SCIP_Real rhs, /**< right hand side */
1315  SCIP_Bool transformed, /**< transformed constraint? */
1316  SCIP_Bool signpowerallowed, /**< allowed to use signpower operator in GAMS? */
1317  SCIP_Bool* nsmooth /**< buffer to store whether we printed a nonsmooth function */
1318  )
1319 {
1320  assert( scip != NULL );
1321  assert( strlen(rowname) > 0 );
1322 
1323  /* print row(s) in GAMS format */
1324  if( SCIPisEQ(scip, lhs, rhs) )
1325  {
1326  assert( !SCIPisInfinity(scip, rhs) );
1327 
1328  /* print equality constraint */
1329  SCIP_CALL( printSignpowerRow(scip, file, rowname, "", "=e=",
1330  nonlinvar, linvar, exponent, offset, coeflinear, rhs, transformed, signpowerallowed, nsmooth) );
1331  }
1332  else
1333  {
1334  if( !SCIPisInfinity(scip, -lhs) )
1335  {
1336  /* print inequality ">=" */
1337  SCIP_CALL( printSignpowerRow(scip, file, rowname, SCIPisInfinity(scip, rhs) ? "" : "_lhs", "=g=",
1338  nonlinvar, linvar, exponent, offset, coeflinear, lhs, transformed, signpowerallowed, nsmooth) );
1339  }
1340  if( !SCIPisInfinity(scip, rhs) )
1341  {
1342  /* print inequality "<=" */
1343  SCIP_CALL( printSignpowerRow(scip, file, rowname, SCIPisInfinity(scip, -lhs) ? "" : "_rhs", "=l=",
1344  nonlinvar, linvar, exponent, offset, coeflinear, rhs, transformed, signpowerallowed, nsmooth) );
1345  }
1346  }
1347 
1348  return SCIP_OKAY;
1349 }
1350 
1351 /* prints expression in GAMS format to file stream */
1352 static
1354  SCIP* scip, /**< SCIP data structure */
1355  FILE* file, /**< output file (or NULL for standard output) */
1356  char* linebuffer, /**< line buffer of length GMS_MAX_PRINTLEN */
1357  int* linecnt, /**< number of characters in line so far */
1358  SCIP_Bool* nsmooth, /**< buffer to store whether we printed a nonsmooth function */
1359  SCIP_Bool transformed, /**< expression belongs to transformed constraint? */
1360  SCIP_EXPR* expr, /**< expression to print */
1361  SCIP_VAR** exprvars /**< variables of expression */
1362  )
1363 {
1364  char buffer[GMS_MAX_PRINTLEN];
1365 
1366  assert(scip != NULL);
1367  assert(linebuffer != NULL);
1368  assert(linecnt != NULL);
1369  assert(expr != NULL);
1370  assert(nsmooth != NULL);
1371 
1372  switch( SCIPexprGetOperator(expr) )
1373  {
1374  case SCIP_EXPR_VARIDX:
1375  {
1376  SCIP_Real one;
1377 
1378  assert(exprvars != NULL);
1379 
1380  one = 1.0;
1381  SCIP_CALL( printActiveVariables(scip, file, linebuffer, linecnt, "", "", 1, &exprvars[SCIPexprGetOpIndex(expr)], &one, transformed) );
1382 
1383  break;
1384  }
1385 
1386  case SCIP_EXPR_PARAM:
1387  {
1388  SCIPwarningMessage(scip, "parameterized expression in GAMS writer. GAMS file will not compile.\n");
1389 
1390  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "param%d", SCIPexprGetOpIndex(expr));
1391  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1392 
1393  break;
1394  }
1395 
1396  case SCIP_EXPR_CONST:
1397  {
1398  if( SCIPexprGetOpReal(expr) < 0.0 )
1399  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "(%.15g)", SCIPexprGetOpReal(expr));
1400  else
1401  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", SCIPexprGetOpReal(expr));
1402  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1403 
1404  break;
1405  }
1406 
1407  case SCIP_EXPR_PLUS:
1408  {
1409  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1410  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1411  appendLineWithIndent(scip, file, linebuffer, linecnt, " + ");
1412  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[1], exprvars) );
1413  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1414  break;
1415  }
1416 
1417  case SCIP_EXPR_MINUS:
1418  {
1419  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1420  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1421  appendLineWithIndent(scip, file, linebuffer, linecnt, " - ");
1422  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[1], exprvars) );
1423  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1424  break;
1425  }
1426 
1427  case SCIP_EXPR_MUL:
1428  {
1429  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1430  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1431  appendLineWithIndent(scip, file, linebuffer, linecnt, " * ");
1432  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[1], exprvars) );
1433  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1434  break;
1435  }
1436 
1437  case SCIP_EXPR_DIV:
1438  {
1439  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1440  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1441  appendLineWithIndent(scip, file, linebuffer, linecnt, " / ");
1442  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[1], exprvars) );
1443  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1444  break;
1445  }
1446 
1447  case SCIP_EXPR_REALPOWER:
1448  {
1449  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1450  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1451  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ")**(%.15g)", SCIPexprGetRealPowerExponent(expr));
1452  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1453  break;
1454  }
1455 
1456  case SCIP_EXPR_INTPOWER:
1457  {
1458  appendLineWithIndent(scip, file, linebuffer, linecnt, "power(");
1459  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1460  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ", %d)", SCIPexprGetIntPowerExponent(expr));
1461  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1462  break;
1463  }
1464 
1465  case SCIP_EXPR_SIGNPOWER:
1466  {
1467  SCIP_Real exponent;
1468  SCIP_Bool nisoddint;
1469 
1470  /* signpow(x,y) is printed as x*abs(x) if y == 2, x*(abs(x) ** (y-1)) if y is not 2 and not an odd integer, and as intpower(x,y) if y is an odd integer
1471  * but if reading/gmsreader/signpower is TRUE, then we print as signpower(x,y), unless y is odd integer
1472  */
1473  exponent = SCIPexprGetSignPowerExponent(expr);
1474  nisoddint = (((SCIP_Real)((int)exponent)) == exponent) && (((int)exponent)%2 == 1);
1475 
1476  if( !nisoddint )
1477  {
1478  SCIP_Bool signpowerallowed;
1479 
1480  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/signpower", &signpowerallowed) );
1481 
1482  if( signpowerallowed )
1483  {
1484  appendLineWithIndent(scip, file, linebuffer, linecnt, " * signpower(");
1485  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1486  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ", %.15g)", exponent);
1487  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1488  }
1489  else
1490  {
1491  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1492  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1493  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1494 
1495  if( exponent == 2.0)
1496  {
1497  appendLineWithIndent(scip, file, linebuffer, linecnt, " * abs(");
1498  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1499  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1500  }
1501  else
1502  {
1503  appendLineWithIndent(scip, file, linebuffer, linecnt, " * abs(");
1504  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1505  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ")**(%g)", SCIPexprGetRealPowerExponent(expr)-1.0);
1506  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1507  }
1508  }
1509  *nsmooth = TRUE;
1510  }
1511  else
1512  {
1513  appendLineWithIndent(scip, file, linebuffer, linecnt, " * power(");
1514  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1515  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ", %.15g)", exponent);
1516  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1517  }
1518 
1519  break;
1520  }
1521 
1522  case SCIP_EXPR_ABS:
1523  case SCIP_EXPR_SIGN:
1524  *nsmooth = TRUE; /*lint -fallthrough*/
1525  case SCIP_EXPR_SQUARE:
1526  case SCIP_EXPR_SQRT:
1527  case SCIP_EXPR_EXP:
1528  case SCIP_EXPR_LOG:
1529  case SCIP_EXPR_SIN:
1530  case SCIP_EXPR_COS:
1531  case SCIP_EXPR_TAN:
1532  /* case SCIP_EXPR_ERF: */
1533  /* case SCIP_EXPR_ERFI: */
1534  case SCIP_EXPR_MIN:
1535  case SCIP_EXPR_MAX:
1536  {
1537  int i;
1538 
1539  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s(", SCIPexpropGetName(SCIPexprGetOperator(expr)));
1540  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1541 
1542  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
1543  {
1544  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[i], exprvars) );
1545  if( i + 1 < SCIPexprGetNChildren(expr) )
1546  appendLineWithIndent(scip, file, linebuffer, linecnt, ", ");
1547  }
1548 
1549  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1550  break;
1551  }
1552 
1553  case SCIP_EXPR_SUM:
1554  case SCIP_EXPR_PRODUCT:
1555  {
1556  switch( SCIPexprGetNChildren(expr) )
1557  {
1558  case 0:
1559  {
1560  appendLineWithIndent(scip, file, linebuffer, linecnt, SCIPexprGetOperator(expr) == SCIP_EXPR_SUM ? "0" : "1");
1561  break;
1562  }
1563  case 1:
1564  {
1565  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[0], exprvars) );
1566  break;
1567  }
1568  default:
1569  {
1570  int i;
1571  char opstr[GMS_MAX_PRINTLEN];
1572 
1573  (void) SCIPsnprintf(opstr, GMS_MAX_PRINTLEN, SCIPexprGetOperator(expr) == SCIP_EXPR_SUM ? " + " : " * ");
1574  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1575  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
1576  {
1577  if( i > 0 )
1578  {
1579  appendLineWithIndent(scip, file, linebuffer, linecnt, opstr);
1580  }
1581  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[i], exprvars) );
1582  }
1583  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1584  }
1585  }
1586  break;
1587  }
1588 
1589  case SCIP_EXPR_LINEAR:
1590  {
1591  SCIP_Real constant;
1592  int i;
1593 
1594  constant = SCIPexprGetLinearConstant(expr);
1595 
1596  if( SCIPexprGetNChildren(expr) == 0 )
1597  {
1598  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1599  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1600  break;
1601  }
1602 
1603  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1604 
1605  if( constant != 0.0 )
1606  {
1607  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1608  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1609  }
1610 
1611  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
1612  {
1613  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g * ", SCIPexprGetLinearCoefs(expr)[i]);
1614  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1615  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[i], exprvars) );
1616  }
1617 
1618  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1619  break;
1620  }
1621 
1622  case SCIP_EXPR_QUADRATIC:
1623  {
1624  SCIP_Real constant;
1625  int i;
1626  SCIP_QUADELEM* quadelems;
1627  SCIP_Real* lincoefs;
1628 
1629  constant = SCIPexprGetQuadConstant(expr);
1630 
1631  if( SCIPexprGetNChildren(expr) == 0 )
1632  {
1633  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1634  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1635  break;
1636  }
1637 
1638  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1639 
1640  if( constant != 0.0 )
1641  {
1642  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1643  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1644  }
1645 
1646  lincoefs = SCIPexprGetQuadLinearCoefs(expr);
1647  if( lincoefs != NULL )
1648  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
1649  {
1650  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g * ", lincoefs[i]);
1651  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1652  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[i], exprvars) );
1653  }
1654 
1655  quadelems = SCIPexprGetQuadElements(expr);
1656  for( i = 0; i < SCIPexprGetNQuadElements(expr); ++i )
1657  {
1658  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g * ", quadelems[i].coef);
1659  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1660 
1661  if( quadelems[i].idx1 == quadelems[i].idx2 )
1662  {
1663  appendLineWithIndent(scip, file, linebuffer, linecnt, "sqr(");
1664  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[quadelems[i].idx1], exprvars) );
1665  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1666  }
1667  else
1668  {
1669  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[quadelems[i].idx1], exprvars) );
1670  appendLineWithIndent(scip, file, linebuffer, linecnt, " * ");
1671  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[quadelems[i].idx2], exprvars) );
1672  }
1673  }
1674 
1675  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1676  break;
1677  }
1678 
1679  case SCIP_EXPR_POLYNOMIAL:
1680  {
1681  SCIP_EXPRDATA_MONOMIAL* monomdata;
1682  SCIP_Real exponent;
1683  int i;
1684  int j;
1685 
1686  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1687 
1688  if( SCIPexprGetPolynomialConstant(expr) != 0.0 || SCIPexprGetNMonomials(expr) == 0 )
1689  {
1690  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", SCIPexprGetPolynomialConstant(expr));
1691  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1692  }
1693 
1694  for( i = 0; i < SCIPexprGetNMonomials(expr); ++i )
1695  {
1696  monomdata = SCIPexprGetMonomials(expr)[i];
1697  assert(monomdata != NULL);
1698 
1699  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g", SCIPexprGetMonomialCoef(monomdata));
1700  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1701 
1702  for( j = 0; j < SCIPexprGetMonomialNFactors(monomdata); ++j )
1703  {
1704  appendLineWithIndent(scip, file, linebuffer, linecnt, "*");
1705 
1706  exponent = SCIPexprGetMonomialExponents(monomdata)[j];
1707  if( exponent == 1.0 )
1708  {
1709  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1710  }
1711  else if( exponent == 2.0 )
1712  {
1713  appendLineWithIndent(scip, file, linebuffer, linecnt, "sqr(");
1714  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1715  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1716  }
1717  else if( exponent == 0.5 )
1718  {
1719  appendLineWithIndent(scip, file, linebuffer, linecnt, "sqrt(");
1720  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1721  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1722  }
1723  else if( ((SCIP_Real)((int)exponent)) == exponent )
1724  {
1725  appendLineWithIndent(scip, file, linebuffer, linecnt, "power(");
1726  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1727  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ", %d)", (int)SCIPround(scip, exponent));
1728  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1729  }
1730  else
1731  {
1732  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1733  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " ** %.15g", exponent);
1734  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1735  }
1736  }
1737  }
1738 
1739  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1740  break;
1741  }
1742 
1743  default:
1744  SCIPerrorMessage("unexpected operand %d in expression\n", SCIPexprGetOperator(expr));
1745  return SCIP_OKAY;
1746  } /*lint !e788*/
1747 
1748  return SCIP_OKAY;
1749 }
1750 
1751 /* print nonlinear row in GAMS format to file stream */
1752 static
1754  SCIP* scip, /**< SCIP data structure */
1755  FILE* file, /**< output file (or NULL for standard output) */
1756  const char* rowname, /**< row name */
1757  const char* rownameextension, /**< row name extension */
1758  const char* type, /**< row type ("=e=", "=l=", or "=g=") */
1759  int nlinvars, /**< number of linear terms */
1760  SCIP_VAR** linvars, /**< variables in linear part */
1761  SCIP_Real* lincoeffs, /**< coefficients of variables in linear part */
1762  int nexprtrees, /**< number of expression trees */
1763  SCIP_EXPRTREE** exprtrees, /**< expression trees */
1764  SCIP_Real* exprtreecoefs, /**< expression tree coefficients */
1765  SCIP_Real rhs, /**< right hand side */
1766  SCIP_Bool transformed, /**< transformed constraint? */
1767  SCIP_Bool* nsmooth /**< buffer to store whether we printed a nonsmooth function */
1768  )
1769 {
1770  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
1771  int linecnt;
1772 
1773  char consname[GMS_MAX_NAMELEN + 3]; /* four extra characters for ' ..' */
1774  char buffer[GMS_MAX_PRINTLEN];
1775 
1776  int i;
1777 
1778  assert( scip != NULL );
1779  assert( strlen(rowname) > 0 || strlen(rownameextension) > 0 );
1780  assert( strcmp(type, "=e=") == 0 || strcmp(type, "=l=") == 0 || strcmp(type, "=g=") == 0 );
1781 
1782  clearLine(linebuffer, &linecnt);
1783 
1784  /* start each line with a space */
1785  appendLine(scip, file, linebuffer, &linecnt, " ");
1786 
1787  /* print row name */
1788  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%s%s ..", rowname, rownameextension);
1789  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN + 3, buffer) );
1790 
1791  appendLine(scip, file, linebuffer, &linecnt, consname);
1792 
1793  /* print nonlinear terms
1794  */
1795  for( i = 0; i < nexprtrees; ++i )
1796  {
1797  assert(exprtrees[i] != NULL);
1798  if( exprtreecoefs[i] != 0.0 )
1799  {
1800  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%+g * (", exprtreecoefs[i]);
1801  appendLineWithIndent(scip, file, linebuffer, &linecnt, buffer);
1802  SCIP_CALL( printExpr(scip, file, linebuffer, &linecnt, nsmooth, transformed, SCIPexprtreeGetRoot(exprtrees[i]), SCIPexprtreeGetVars(exprtrees[i])) );
1803  appendLineWithIndent(scip, file, linebuffer, &linecnt, ")");
1804  }
1805  }
1806 
1807  /* print linear terms, do after nonlinear since nonlinear may not print sign in beginning */
1808  if( nlinvars > 0 )
1809  {
1810  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", " ", nlinvars, linvars, lincoeffs, transformed) );
1811  }
1812 
1813  /* print right hand side */
1814  if( linecnt == 0 )
1815  /* we start a new line; therefore we tab this line */
1816  appendLine(scip, file, linebuffer, &linecnt, " ");
1817 
1818  if( SCIPisZero(scip, rhs) )
1819  rhs = 0.0;
1820 
1821  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s %.15g;", type, rhs);
1822 
1823  appendLine(scip, file, linebuffer, &linecnt, buffer);
1824 
1825  endLine(scip, file, linebuffer, &linecnt);
1826 
1827  return SCIP_OKAY;
1828 }
1829 
1830 /* print nonlinear row in GAMS format to file stream (performing retransformation to active linear variables)
1831  * */
1832 static
1834  SCIP* scip, /**< SCIP data structure */
1835  FILE* file, /**< output file (or NULL for standard output) */
1836  const char* rowname, /**< row name */
1837  int nlinvars, /**< number of linear terms */
1838  SCIP_VAR** linvars, /**< variables in linear part */
1839  SCIP_Real* lincoeffs, /**< coefficients of variables in linear part */
1840  int nexprtrees, /**< number of expression trees */
1841  SCIP_EXPRTREE** exprtrees, /**< expression trees */
1842  SCIP_Real* exprtreecoefs, /**< expression tree coefficients */
1843  SCIP_Real lhs, /**< left hand side */
1844  SCIP_Real rhs, /**< right hand side */
1845  SCIP_Bool transformed, /**< transformed constraint? */
1846  SCIP_Bool* nsmooth /**< buffer to store whether we printed a nonsmooth function */
1847  )
1848 {
1849  assert( scip != NULL );
1850  assert( strlen(rowname) > 0 );
1851 
1852  /* print row(s) in GAMS format */
1853  if( SCIPisEQ(scip, lhs, rhs) )
1854  {
1855  assert( !SCIPisInfinity(scip, rhs) );
1856 
1857  /* print equality constraint */
1858  SCIP_CALL( printNonlinearRow(scip, file, rowname, "", "=e=",
1859  nlinvars, linvars, lincoeffs, nexprtrees, exprtrees, exprtreecoefs, rhs, transformed, nsmooth) );
1860  }
1861  else
1862  {
1863  if( !SCIPisInfinity(scip, -lhs) )
1864  {
1865  /* print inequality ">=" */
1866  SCIP_CALL( printNonlinearRow(scip, file, rowname, SCIPisInfinity(scip, rhs) ? "" : "_lhs", "=g=",
1867  nlinvars, linvars, lincoeffs, nexprtrees, exprtrees, exprtreecoefs, lhs, transformed, nsmooth) );
1868  }
1869  if( !SCIPisInfinity(scip, rhs) )
1870  {
1871  /* print inequality "<=" */
1872  SCIP_CALL( printNonlinearRow(scip, file, rowname, SCIPisInfinity(scip, -lhs) ? "" : "_rhs", "=l=",
1873  nlinvars, linvars, lincoeffs, nexprtrees, exprtrees, exprtreecoefs, rhs, transformed, nsmooth) );
1874  }
1875  }
1876 
1877  return SCIP_OKAY;
1878 }
1879 
1880 /** method check if the variable names are not longer than GMS_MAX_NAMELEN */
1881 static
1883  SCIP* scip, /**< SCIP data structure */
1884  SCIP_VAR** vars, /**< array of variables */
1885  int nvars /**< number of variables */
1886  )
1887 {
1888  int v;
1889  SCIP_VAR* var;
1890  SCIP_Bool replaceforbiddenchars;
1891  const char* badchar;
1892 
1893  assert( scip != NULL );
1894  assert( vars != NULL );
1895 
1896  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/replaceforbiddenchars", &replaceforbiddenchars) );
1897 
1898  /* check if the variable names contain any of the bad symbols */
1899  for( badchar = badchars; *badchar; ++badchar )
1900  {
1901  for( v = 0; v < nvars; ++v )
1902  {
1903  var = vars[v];
1904  assert( var != NULL );
1905 
1906  if( strchr(SCIPvarGetName(var), *badchar) != NULL )
1907  {
1908  if( replaceforbiddenchars )
1909  {
1910  SCIPinfoMessage(scip, NULL, "there is a variable name with symbol '%c', not allowed in GAMS format; all '%c' replaced by '_' (consider using 'write genproblem'/'write gentransproblem').\n", *badchar, *badchar);
1911  }
1912  else
1913  {
1914  SCIPwarningMessage(scip, "there is a variable name with symbol '%c', not allowed in GAMS format; use 'write genproblem'/'write gentransproblem', or set 'reading/gmsreader/replaceforbiddenchars' to TRUE and risk duplicate variable names.\n", *badchar);
1915  }
1916 
1917  break;
1918  }
1919  }
1920  }
1921 
1922  /* check if the variable names are too long */
1923  for( v = 0; v < nvars; ++v )
1924  {
1925  var = vars[v];
1926  assert( var != NULL );
1927 
1928  if( strlen(SCIPvarGetName(var)) > GMS_MAX_NAMELEN )
1929  {
1930  SCIPwarningMessage(scip, "there is a variable name which has to be cut down to %d characters; GAMS model might be corrupted.\n",
1931  GMS_MAX_NAMELEN - 1);
1932  break;
1933  }
1934  }
1935 
1936  return SCIP_OKAY;
1937 }
1938 
1939 /** method check if the constraint names are not longer than GMS_MAX_NAMELEN */
1940 static
1942  SCIP* scip, /**< SCIP data structure */
1943  SCIP_CONS** conss, /**< array of constraints */
1944  int nconss, /**< number of constraints */
1945  SCIP_Bool transformed /**< TRUE iff problem is the transformed problem */
1946  )
1947 {
1948  int c;
1949  SCIP_CONS* cons;
1950  SCIP_CONSHDLR* conshdlr;
1951  const char* conshdlrname;
1952  SCIP_Bool replaceforbiddenchars;
1953  const char* badchar;
1954 
1955  assert( scip != NULL );
1956  assert( conss != NULL );
1957 
1958  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/replaceforbiddenchars", &replaceforbiddenchars) );
1959 
1960  /* check if the constraint names contain any of the bad symbols */
1961  for( badchar = badchars; *badchar; ++badchar )
1962  {
1963  for( c = 0; c < nconss; ++c )
1964  {
1965  cons = conss[c];
1966  assert( cons != NULL );
1967 
1968  if( strchr(SCIPconsGetName(cons), *badchar) != NULL )
1969  {
1970  if( replaceforbiddenchars )
1971  {
1972  SCIPinfoMessage(scip, NULL, "there is a constraint name with symbol '%c', not allowed in GAMS format; all '%c' replaced by '_' (consider using 'write genproblem'/'write gentransproblem').\n", *badchar, *badchar);
1973  }
1974  else
1975  {
1976  SCIPwarningMessage(scip, "there is a constraint name with symbol '%c', not allowed in GAMS format; use 'write genproblem'/'write gentransproblem', or set 'reading/gmsreader/replaceforbiddenchars' to TRUE and risk duplicate variable names.\n", *badchar);
1977  }
1978 
1979  break;
1980  }
1981  }
1982  }
1983 
1984  /* check if the constraint names are too long */
1985  for( c = 0; c < nconss; ++c )
1986  {
1987  cons = conss[c];
1988  assert( cons != NULL );
1989 
1990  /* in case the transformed is written, only constraints are posted which are enabled in the current node */
1991  assert(!transformed || SCIPconsIsEnabled(cons));
1992 
1993  conshdlr = SCIPconsGetHdlr(cons);
1994  assert( conshdlr != NULL );
1995 
1996  conshdlrname = SCIPconshdlrGetName(conshdlr);
1997  assert( transformed == SCIPconsIsTransformed(cons) );
1998 
1999  if( strcmp(conshdlrname, "linear") == 0 || strcmp(conshdlrname, "quadratic") == 0 )
2000  {
2001  SCIP_Real lhs = strcmp(conshdlrname, "linear") == 0 ? SCIPgetLhsLinear(scip, cons) : SCIPgetLhsQuadratic(scip, cons);
2002  SCIP_Real rhs = strcmp(conshdlrname, "linear") == 0 ? SCIPgetLhsLinear(scip, cons) : SCIPgetRhsQuadratic(scip, cons);
2003 
2004  if( SCIPisEQ(scip, lhs, rhs) && strlen(SCIPconsGetName(conss[c])) > GMS_MAX_NAMELEN )
2005  {
2006  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n",
2007  GMS_MAX_NAMELEN - 1);
2008  break;
2009  }
2010  else if( !SCIPisEQ(scip, lhs, rhs) && strlen(SCIPconsGetName(conss[c])) > GMS_MAX_NAMELEN - 4 )
2011  {
2012  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n",
2013  GMS_MAX_NAMELEN - 5);
2014  break;
2015  }
2016  }
2017  else if( strlen(SCIPconsGetName(conss[c])) > GMS_MAX_NAMELEN )
2018  {
2019  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n",
2020  GMS_MAX_NAMELEN - 1);
2021  break;
2022  }
2023  }
2024  return SCIP_OKAY;
2025 }
2026 
2027 
2028 /*
2029  * Callback methods of reader
2030  */
2031 
2032 /** copy method for reader plugins (called when SCIP copies plugins) */
2033 static
2034 SCIP_DECL_READERCOPY(readerCopyGms)
2035 { /*lint --e{715}*/
2036  assert(scip != NULL);
2037  assert(reader != NULL);
2038  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2039 
2040  /* call inclusion method of reader */
2042 
2043  return SCIP_OKAY;
2044 }
2045 
2046 #ifdef WITH_GAMS
2047 /** problem reading method of reader */
2048 static
2049 SCIP_DECL_READERREAD(readerReadGms)
2050 {
2051  SCIP_RETCODE ret;
2052  FILE* convertdopt;
2053  char gamscall[SCIP_MAXSTRLEN];
2054  char buffer[GMS_SSSIZE];
2055  int rc;
2056  gmoHandle_t gmo = NULL;
2057  gevHandle_t gev = NULL;
2058 
2059  assert(scip != NULL);
2060  assert(reader != NULL);
2061  assert(filename != NULL);
2062  assert(result != NULL);
2063 
2064  *result = SCIP_DIDNOTRUN;
2065  ret = SCIP_ERROR;
2066 
2067  /* create temporary directory */
2068  mkdir("loadgms.tmp", S_IRWXU);
2069 
2070  /* create empty convertd options file */
2071  convertdopt = fopen("loadgms.tmp/convertd.opt", "w");
2072  if( convertdopt == NULL )
2073  {
2074  SCIPerrorMessage("Could not create convertd options file. Do you have write permissions in execution directory?\n");
2075  goto TERMINATE;
2076  }
2077  fputs(" ", convertdopt);
2078  fclose(convertdopt);
2079 
2080  /* call GAMS with convertd solver to get compiled model instance in temporary directory */
2081  SCIPsnprintf(gamscall, SCIP_MAXSTRLEN, WITH_GAMS "/gams %s LP=CONVERTD RMIP=CONVERTD QCP=CONVERTD RMIQCP=CONVERTD NLP=CONVERTD DNLP=CONVERTD RMINLP=CONVERTD CNS=CONVERTD MIP=CONVERTD MIQCP=CONVERTD MINLP=CONVERTD MCP=CONVERTD MPEC=CONVERTD RMPEC=CONVERTD SCRDIR=loadgms.tmp output=loadgms.tmp/listing optdir=loadgms.tmp optfile=1 pf4=0 solprint=0 limcol=0 limrow=0 pc=2 lo=%d",
2082  filename, SCIPgetVerbLevel(scip) == SCIP_VERBLEVEL_FULL ? 3 : 0);
2083  SCIPdebugMsg(scip, gamscall);
2084  rc = system(gamscall);
2085  if( rc != 0 )
2086  {
2087  SCIPerrorMessage("GAMS call returned with code %d, check loadgms.tmp/listing for details.\n", rc);
2088  /* likely the GAMS model could not be compiled, which we could report as a readerror */
2089  ret = SCIP_READERROR;
2090  goto TERMINATE;
2091  }
2092 
2093  /* initialize GEV library and create GEV */
2094  if( !gevCreateDD(&gev, WITH_GAMS, buffer, sizeof(buffer)) )
2095  {
2096  SCIPerrorMessage(buffer);
2097  goto TERMINATE;
2098  }
2099 
2100  /* initialize GMO library and create GMO */
2101  if( !gmoCreateDD(&gmo, WITH_GAMS, buffer, sizeof(buffer)) )
2102  {
2103  SCIPerrorMessage(buffer);
2104  goto TERMINATE;
2105  }
2106 
2107  /* load control file */
2108  if( gevInitEnvironmentLegacy(gev, "loadgms.tmp/gamscntr.dat") )
2109  {
2110  SCIPerrorMessage("Could not load control file loadgms.tmp/gamscntr.dat\n");
2111  goto TERMINATE;
2112  }
2113 
2114  /* tell GMO about GEV */
2115  if( gmoRegisterEnvironment(gmo, gev, buffer) )
2116  {
2117  SCIPerrorMessage("Error registering GAMS Environment: %s\n", buffer);
2118  goto TERMINATE;
2119  }
2120 
2121  /* load GAMS model instance into GMO */
2122  if( gmoLoadDataLegacy(gmo, buffer) )
2123  {
2124  SCIPerrorMessage("Could not load model data.\n");
2125  goto TERMINATE;
2126  }
2127 
2128  /* create SCIP problem out of GMO, using the magic from reader_gmo in interfaces/gams */
2129  SCIP_CALL( SCIPcreateProblemReaderGmo(scip, gmo, NULL, FALSE) );
2130  *result = SCIP_SUCCESS;
2131 
2132  ret = SCIP_OKAY;
2133 
2134 TERMINATE:
2135  if( gmo != NULL )
2136  gmoFree(&gmo);
2137  if( gev != NULL )
2138  gevFree(&gev);
2139 
2140  /* remove temporary directory content (should have only files and directory itself) */
2141  if( ret != SCIP_READERROR )
2142  system("rm loadgms.tmp/* && rmdir loadgms.tmp");
2143 
2144  return ret;
2145 }
2146 #endif
2147 
2148 /** problem writing method of reader */
2149 static
2150 SCIP_DECL_READERWRITE(readerWriteGms)
2151 { /*lint --e{715}*/
2152  SCIP_CALL( SCIPwriteGms(scip, file, name, transformed, objsense, objscale, objoffset, vars,
2153  nvars, nbinvars, nintvars, nimplvars, ncontvars, conss, nconss, result) );
2154 
2155  return SCIP_OKAY;
2156 }
2157 
2158 #ifdef WITH_GAMS
2159 /** destructor of reader to free user data (called when SCIP is exiting) */
2160 static
2161 SCIP_DECL_READERFREE(readerFreeGms)
2162 {
2163  if( gmoLibraryLoaded() )
2164  gmoLibraryUnload();
2165  if( gevLibraryLoaded() )
2166  gevLibraryUnload();
2167 
2168  return SCIP_OKAY;
2169 }
2170 #endif
2171 
2172 /*
2173  * reader specific interface methods
2174  */
2175 
2176 /** includes the gms file reader in SCIP */
2178  SCIP* scip /**< SCIP data structure */
2179  )
2180 {
2181  SCIP_READER* reader;
2182 
2183  /* include reader */
2185 
2186  /* set non fundamental callbacks via setter functions */
2187  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyGms) );
2188 #ifdef WITH_GAMS
2189  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadGms) );
2190  SCIP_CALL( SCIPsetReaderFree(scip, reader, readerFreeGms) );
2191 #endif
2192  SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWriteGms) );
2193 
2194  /* add gms reader parameters for writing routines*/
2196  "reading/gmsreader/freeints", "have integer variables no upper bound by default (depending on GAMS version)?",
2197  NULL, FALSE, FALSE, NULL, NULL) );
2198 
2200  "reading/gmsreader/replaceforbiddenchars", "shall characters '#', '*', '+', '/', and '-' in variable and constraint names be replaced by '_'?",
2201  NULL, FALSE, FALSE, NULL, NULL) );
2202 
2204  "reading/gmsreader/bigmdefault", "default M value for big-M reformulation of indicator constraints in case no bound on slack variable is given",
2205  NULL, FALSE, GMS_DEFAULT_BIGM, 0.0, SCIP_REAL_MAX, NULL, NULL) );
2206 
2208  "reading/gmsreader/indicatorreform", "which reformulation to use for indicator constraints: 'b'ig-M, 's'os1",
2209  NULL, FALSE, GMS_DEFAULT_INDICATORREFORM, "bs", NULL, NULL) );
2210 
2212  "reading/gmsreader/signpower", "is it allowed to use the gams function signpower(x,a)?",
2213  NULL, FALSE, GMS_DEFAULT_SIGNPOWER, NULL, NULL) );
2214 
2215  return SCIP_OKAY;
2216 }
2217 
2218 
2219 /** writes problem to gms file */
2221  SCIP* scip, /**< SCIP data structure */
2222  FILE* file, /**< output file, or NULL if standard output should be used */
2223  const char* name, /**< problem name */
2224  SCIP_Bool transformed, /**< TRUE iff problem is the transformed problem */
2225  SCIP_OBJSENSE objsense, /**< objective sense */
2226  SCIP_Real objscale, /**< scalar applied to objective function; external objective value is
2227  * extobj = objsense * objscale * (intobj + objoffset) */
2228  SCIP_Real objoffset, /**< objective offset from bound shifting and fixing */
2229  SCIP_VAR** vars, /**< array with active variables ordered binary, integer, implicit, continuous */
2230  int nvars, /**< number of active variables in the problem */
2231  int nbinvars, /**< number of binary variables */
2232  int nintvars, /**< number of general integer variables */
2233  int nimplvars, /**< number of implicit integer variables */
2234  int ncontvars, /**< number of continuous variables */
2235  SCIP_CONS** conss, /**< array with constraints of the problem */
2236  int nconss, /**< number of constraints in the problem */
2237  SCIP_RESULT* result /**< pointer to store the result of the file writing call */
2238  )
2239 {
2240  int c;
2241  int v;
2242  int linecnt;
2243  char linebuffer[GMS_MAX_PRINTLEN];
2244 
2245  char varname[GMS_MAX_NAMELEN];
2246  char buffer[GMS_MAX_PRINTLEN];
2247 
2248  SCIP_Real* objcoeffs;
2249 
2250  SCIP_CONSHDLR* conshdlr;
2251  const char* conshdlrname;
2252  SCIP_CONS* cons;
2253 
2254  char consname[GMS_MAX_NAMELEN];
2255 
2256  SCIP_VAR** consvars;
2257  SCIP_Real* consvals;
2258  int nconsvars;
2259 
2260  SCIP_VAR* var;
2261  SCIP_VAR* objvar;
2262  SCIP_Real lb;
2263  SCIP_Real ub;
2264  SCIP_Bool freeints;
2265  SCIP_Bool nondefbounds;
2266  SCIP_Bool nlcons;
2267  SCIP_Bool nqcons;
2268  SCIP_Bool nsmooth;
2269  SCIP_Bool discrete;
2270  SCIP_Bool rangedrow;
2271  SCIP_Bool indicatorsosdef;
2272  SCIP_Bool signpowerallowed;
2273  SCIP_Bool needcomma;
2274 
2275  assert( scip != NULL );
2276  assert( vars != NULL || nvars == 0 );
2277 
2278  /* check if the variable names are not too long */
2279  SCIP_CALL( checkVarnames(scip, vars, nvars) );
2280  /* check if the constraint names are too long */
2281  SCIP_CALL( checkConsnames(scip, conss, nconss, transformed) );
2282 
2283  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/signpower", &signpowerallowed) );
2284 
2285  /* check if the objective is a single continuous variable, so we would not have to introduce an auxiliary variable
2286  * for GAMS
2287  */
2288  objvar = NULL;
2289  if( objscale == 1.0 && objoffset == 0.0 )
2290  {
2291  for( v = 0; v < nvars; ++v )
2292  {
2293  if( SCIPvarGetObj(vars[v]) == 0.0 ) /*lint !e613*/
2294  continue;
2295 
2296  if( objvar == NULL )
2297  {
2298  /* first variable with nonzero obj coefficient
2299  * if not active or having coefficient != 1.0, or being binary/integer, then give up
2300  */
2301  if( !SCIPvarIsActive(vars[v]) || SCIPvarGetObj(vars[v]) != 1.0 ||
2302  SCIPvarGetType(vars[v]) < SCIP_VARTYPE_IMPLINT ) /*lint !e613*/
2303  break;
2304 
2305  objvar = vars[v]; /*lint !e613*/
2306  }
2307  else
2308  {
2309  /* second variable with nonzero obj coefficient -> give up */
2310  objvar = NULL;
2311  break;
2312  }
2313  }
2314  }
2315 
2316  /* print statistics as comment to file */
2317  SCIPinfoMessage(scip, file, "$OFFLISTING\n");
2318  SCIPinfoMessage(scip, file, "* SCIP STATISTICS\n");
2319  SCIPinfoMessage(scip, file, "* Problem name : %s\n", name);
2320  SCIPinfoMessage(scip, file, "* Variables : %d (%d binary, %d integer, %d implicit integer, %d continuous)\n",
2321  nvars, nbinvars, nintvars, nimplvars, ncontvars);
2322  SCIPinfoMessage(scip, file, "* Constraints : %d\n\n", nconss);
2323 
2324  /* print flags */
2325  SCIPinfoMessage(scip, file, "$MAXCOL %d\n", GMS_MAX_LINELEN - 1);
2326  SCIPinfoMessage(scip, file, "$OFFDIGIT\n\n");
2327 
2328  /* print variable section */
2329  SCIPinfoMessage(scip, file, "Variables\n");
2330  clearLine(linebuffer, &linecnt);
2331 
2332  if( objvar == NULL )
2333  {
2334  /* auxiliary objective variable */
2335  SCIPinfoMessage(scip, file, " objvar%c", nvars > 0 ? ',' : ';');
2336  }
2337 
2338  /* "model" variables */
2339  for( v = 0; v < nvars; ++v )
2340  {
2341  var = vars[v]; /*lint !e613*/
2342  assert( var != NULL );
2343 
2344  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2345  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%c", varname, (v < nvars - 1) ? ',' : ';');
2346  appendLine(scip, file, linebuffer, &linecnt, buffer);
2347 
2348  if( (linecnt > 0 && (v == nbinvars - 1 || v == nbinvars + nintvars - 1 ||
2349  v == nbinvars + nintvars + nimplvars - 1)) || v == nvars - 1 )
2350  {
2351  endLine(scip, file, linebuffer, &linecnt);
2352  clearLine(linebuffer, &linecnt);
2353  }
2354  }
2355 
2356  SCIPinfoMessage(scip, file, "\n");
2357 
2358  /* declare binary variables if present */
2359  if( nbinvars > 0 )
2360  {
2361  SCIPinfoMessage(scip, file, "Binary variables\n");
2362  clearLine(linebuffer, &linecnt);
2363 
2364  for( v = 0; v < nbinvars; ++v )
2365  {
2366  var = vars[v]; /*lint !e613*/
2367 
2368  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2369  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%s", varname, (v < nbinvars - 1) ? "," : ";");
2370 
2371  appendLine(scip, file, linebuffer, &linecnt, buffer);
2372  }
2373 
2374  endLine(scip, file, linebuffer, &linecnt);
2375  SCIPinfoMessage(scip, file, "\n");
2376  }
2377 
2378  /* declare integer variables if present */
2379  if( nintvars > 0 )
2380  {
2381  SCIPinfoMessage(scip, file, "Integer variables\n");
2382  clearLine(linebuffer, &linecnt);
2383 
2384  for( v = 0; v < nintvars; ++v )
2385  {
2386  var = vars[nbinvars + v]; /*lint !e613*/
2387 
2388  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2389  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%s", varname, (v < nintvars - 1) ? "," : ";");
2390 
2391  appendLine(scip, file, linebuffer, &linecnt, buffer);
2392  }
2393  endLine(scip, file, linebuffer, &linecnt);
2394  SCIPinfoMessage(scip, file, "\n");
2395  }
2396 
2397  /* print variable bounds */
2398  SCIPinfoMessage(scip, file, "* Variable bounds\n");
2399  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/freeints", &freeints) );
2400  nondefbounds = FALSE;
2401 
2402  for( v = 0; v < nvars; ++v )
2403  {
2404  var = vars[v]; /*lint !e613*/
2405  assert( var != NULL );
2406 
2407  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2408 
2409  if( transformed )
2410  {
2411  /* in case the transformed is written only local bounds are posted which are valid in the current node */
2412  lb = SCIPvarGetLbLocal(var);
2413  ub = SCIPvarGetUbLocal(var);
2414  }
2415  else
2416  {
2417  lb = SCIPvarGetLbOriginal(var);
2418  ub = SCIPvarGetUbOriginal(var);
2419  }
2420  assert( lb <= ub );
2421 
2422  /* fixed */
2423  if( SCIPisEQ(scip, lb, ub) )
2424  {
2425  if( v < nintvars )
2426  SCIPinfoMessage(scip, file, " %s.fx = %g;\n", varname, SCIPfloor(scip, lb + 0.5));
2427  else
2428  SCIPinfoMessage(scip, file, " %s.fx = %.15g;\n", varname, lb);
2429  nondefbounds = TRUE;
2430 
2431  /* no need to write lower and upper bounds additionally */
2432  continue;
2433  }
2434 
2435  /* lower bound */
2436  if( v < nbinvars + nintvars )
2437  {
2438  /* default lower bound of binaries and integers is 0 (also in recent gams versions if pf4=0 is given) */
2439  if( !SCIPisZero(scip, lb) )
2440  {
2441  if( !SCIPisInfinity(scip, -lb) )
2442  SCIPinfoMessage(scip, file, " %s.lo = %g;\n", varname, SCIPceil(scip, lb));
2443  else if( freeints )
2444  SCIPinfoMessage(scip, file, " %s.lo = -inf;\n", varname); /* -inf is allowed when running gams with pf4=0, which we assume if freeints is TRUE */
2445  else
2446  SCIPinfoMessage(scip, file, " %s.lo = %g;\n", varname, -SCIPinfinity(scip)); /* sorry, -inf not allowed in gams file here */
2447  nondefbounds = TRUE;
2448  }
2449  }
2450  else if( v >= nbinvars + nintvars && !SCIPisInfinity(scip, -lb) )
2451  {
2452  /* continuous variables are free by default */
2453  SCIPinfoMessage(scip, file, " %s.lo = %.15g;\n", varname, lb);
2454  nondefbounds = TRUE;
2455  }
2456 
2457  /* upper bound */
2458  if( v < nbinvars )
2459  {
2460  if( !SCIPisFeasEQ(scip, ub, 1.0) )
2461  {
2462  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPfeasFloor(scip, ub));
2463  nondefbounds = TRUE;
2464  }
2465  }
2466  else if( v < nbinvars + nintvars && !freeints )
2467  {
2468  /* freeints == FALSE: integer variables have upper bound 100 by default */
2469  if( !SCIPisFeasEQ(scip, ub, 100.0) )
2470  {
2471  if( !SCIPisInfinity(scip, ub) )
2472  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPfeasFloor(scip, ub));
2473  else
2474  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPinfinity(scip)); /* sorry, +inf not allowed in gams file here (unless pf4=0) */
2475  nondefbounds = TRUE;
2476  }
2477  }
2478  else if( v < nbinvars + nintvars && !SCIPisInfinity(scip, ub) )
2479  {
2480  /* freeints == TRUE: integer variables have no upper bound by default */
2481  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPfloor(scip, ub));
2482  nondefbounds = TRUE;
2483  }
2484  else if( v >= nbinvars + nintvars && !SCIPisInfinity(scip, ub) )
2485  {
2486  /* continuous variables are free by default */
2487  SCIPinfoMessage(scip, file, " %s.up = %.15g;\n", varname, ub);
2488  nondefbounds = TRUE;
2489  }
2490  }
2491 
2492  if( !nondefbounds )
2493  SCIPinfoMessage(scip, file, "* (All other bounds at default value: binary [0,1], integer [%s], continuous [-inf,+inf].)\n", freeints ? "0,+inf" : "0,100");
2494  SCIPinfoMessage(scip, file, "\n");
2495 
2496  /* print equations section */
2497  if( nconss > 0 || objvar == NULL )
2498  {
2499  SCIPinfoMessage(scip, file, "Equations\n");
2500  clearLine(linebuffer, &linecnt);
2501  }
2502  needcomma = FALSE;
2503 
2504  if( objvar == NULL )
2505  {
2506  SCIPinfoMessage(scip, file, " objequ");
2507  needcomma = TRUE;
2508  }
2509 
2510  /* declare equations */
2511  for( c = 0; c < nconss; ++c )
2512  {
2513  cons = conss[c];
2514  assert( cons != NULL );
2515 
2516  conshdlr = SCIPconsGetHdlr(cons);
2517  assert( conshdlr != NULL );
2518 
2519  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, SCIPconsGetName(cons)) );
2520  conshdlrname = SCIPconshdlrGetName(conshdlr);
2521  assert( transformed == SCIPconsIsTransformed(cons) );
2522 
2523  rangedrow = strcmp(conshdlrname, "linear") == 0
2524  && !SCIPisInfinity(scip, -SCIPgetLhsLinear(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsLinear(scip, cons))
2525  && !SCIPisEQ(scip, SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons));
2526  rangedrow = rangedrow || (strcmp(conshdlrname, "quadratic") == 0
2527  && !SCIPisInfinity(scip, -SCIPgetLhsQuadratic(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsQuadratic(scip, cons))
2528  && !SCIPisEQ(scip, SCIPgetLhsQuadratic(scip, cons), SCIPgetRhsQuadratic(scip, cons)));
2529  rangedrow = rangedrow || (strcmp(conshdlrname, "nonlinear") == 0
2530  && !SCIPisInfinity(scip, -SCIPgetLhsNonlinear(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsNonlinear(scip, cons))
2531  && !SCIPisEQ(scip, SCIPgetLhsNonlinear(scip, cons), SCIPgetRhsNonlinear(scip, cons)));
2532  rangedrow = rangedrow || (strcmp(conshdlrname, "abspower") == 0
2533  && !SCIPisInfinity(scip, -SCIPgetLhsAbspower(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsAbspower(scip, cons))
2534  && !SCIPisEQ(scip, SCIPgetLhsAbspower(scip, cons), SCIPgetRhsAbspower(scip, cons)));
2535  rangedrow = rangedrow || (strcmp(conshdlrname, "bivariate") == 0
2536  && !SCIPisInfinity(scip, -SCIPgetLhsBivariate(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsBivariate(scip, cons))
2537  && !SCIPisEQ(scip, SCIPgetLhsBivariate(scip, cons), SCIPgetRhsBivariate(scip, cons)));
2538  rangedrow = rangedrow || (strcmp(conshdlrname, "varbound") == 0
2539  && !SCIPisInfinity(scip, -SCIPgetLhsVarbound(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsVarbound(scip, cons))
2540  && !SCIPisEQ(scip, SCIPgetLhsVarbound(scip, cons), SCIPgetRhsVarbound(scip, cons)));
2541 
2542  /* we declare only those constraints which we can print in GAMS format */
2543  if( strcmp(conshdlrname, "knapsack") != 0 && strcmp(conshdlrname, "logicor") != 0 && strcmp(conshdlrname, "setppc") != 0
2544  && strcmp(conshdlrname, "linear") != 0 && strcmp(conshdlrname, "quadratic") != 0 && strcmp(conshdlrname, "varbound") != 0
2545  && strcmp(conshdlrname, "soc") != 0 && strcmp(conshdlrname, "abspower") != 0 && strcmp(conshdlrname, "bivariate") != 0
2546  && strcmp(conshdlrname, "nonlinear") != 0 && strcmp(conshdlrname, "SOS1") != 0 && strcmp(conshdlrname, "SOS2") != 0
2547  && strcmp(conshdlrname, "indicator") != 0 )
2548  {
2549  SCIPwarningMessage(scip, "Constraint type <%s> not supported. Skip writing constraint <%s>.\n", conshdlrname, SCIPconsGetName(cons));
2550  continue;
2551  }
2552 
2553  if( needcomma )
2554  appendLine(scip, file, linebuffer, &linecnt, ",");
2555 
2556  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, SCIPconsGetName(cons)) );
2557  if( rangedrow )
2558  {
2559  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%s%s%s", consname, "_lhs, ", consname, "_rhs");
2560  appendLine(scip, file, linebuffer, &linecnt, buffer);
2561  }
2562  else
2563  {
2564  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s", consname);
2565  appendLine(scip, file, linebuffer, &linecnt, buffer);
2566  }
2567  needcomma = TRUE;
2568  }
2569 
2570  if( nconss > 0 || objvar == NULL )
2571  {
2572  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ";");
2573  appendLine(scip, file, linebuffer, &linecnt, buffer);
2574 
2575  endLine(scip, file, linebuffer, &linecnt);
2576  SCIPinfoMessage(scip, file, "\n");
2577  }
2578 
2579  if( objvar == NULL )
2580  {
2581  /* print objective function equation */
2582  clearLine(linebuffer, &linecnt);
2583  if( objoffset != 0.0 )
2584  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " objequ .. objvar =e= %.15g + ", objscale * objoffset);
2585  else
2586  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " objequ .. objvar =e= ");
2587  appendLine(scip, file, linebuffer, &linecnt, buffer);
2588 
2589  SCIP_CALL( SCIPallocBufferArray(scip, &objcoeffs, nvars) );
2590 
2591  for( v = 0; v < nvars; ++v )
2592  {
2593  var = vars[v]; /*lint !e613*/
2594  assert( var != NULL );
2595 
2596  /* in case the original problem has to be posted the variables have to be either "original" or "negated" */
2597  assert( transformed || SCIPvarGetStatus(var) == SCIP_VARSTATUS_ORIGINAL || SCIPvarGetStatus(var) == SCIP_VARSTATUS_NEGATED );
2598 
2599  objcoeffs[v] = SCIPisZero(scip, SCIPvarGetObj(var)) ? 0.0 : objscale * SCIPvarGetObj(var);
2600  }
2601 
2602  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "", ";", nvars, vars, objcoeffs, transformed) );
2603 
2604  SCIPfreeBufferArray(scip, &objcoeffs);
2605  endLine(scip, file, linebuffer, &linecnt);
2606  SCIPinfoMessage(scip, file, "\n");
2607  }
2608 
2609  /* print constraints */
2610  nlcons = FALSE;
2611  nqcons = FALSE;
2612  nsmooth = FALSE;
2613  discrete = nbinvars > 0 || nintvars > 0;
2614  indicatorsosdef = FALSE;
2615  for( c = 0; c < nconss; ++c )
2616  {
2617  cons = conss[c];
2618  assert( cons != NULL );
2619 
2620  /* in case the transformed is written, only constraints are posted which are enabled in the current node */
2621  assert(!transformed || SCIPconsIsEnabled(cons));
2622 
2623  conshdlr = SCIPconsGetHdlr(cons);
2624  assert( conshdlr != NULL );
2625 
2626  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, SCIPconsGetName(cons)) );
2627  conshdlrname = SCIPconshdlrGetName(conshdlr);
2628  assert( transformed == SCIPconsIsTransformed(cons) );
2629 
2630  if( strcmp(conshdlrname, "knapsack") == 0 )
2631  {
2632  SCIP_Longint* weights;
2633 
2634  consvars = SCIPgetVarsKnapsack(scip, cons);
2635  nconsvars = SCIPgetNVarsKnapsack(scip, cons);
2636 
2637  /* copy Longint array to SCIP_Real array */
2638  weights = SCIPgetWeightsKnapsack(scip, cons);
2639  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) );
2640  for( v = 0; v < nconsvars; ++v )
2641  consvals[v] = (SCIP_Real)weights[v];
2642 
2643  SCIP_CALL( printLinearCons(scip, file, consname, nconsvars, consvars, consvals,
2644  -SCIPinfinity(scip), (SCIP_Real) SCIPgetCapacityKnapsack(scip, cons), transformed) );
2645 
2646  SCIPfreeBufferArray(scip, &consvals);
2647  }
2648  else if( strcmp(conshdlrname, "linear") == 0 )
2649  {
2650  SCIP_CALL( printLinearCons(scip, file, consname,
2651  SCIPgetNVarsLinear(scip, cons), SCIPgetVarsLinear(scip, cons), SCIPgetValsLinear(scip, cons),
2652  SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons), transformed) );
2653  }
2654  else if( strcmp(conshdlrname, "logicor") == 0 )
2655  {
2656  SCIP_CALL( printLinearCons(scip, file, consname,
2657  SCIPgetNVarsLogicor(scip, cons), SCIPgetVarsLogicor(scip, cons), NULL,
2658  1.0, SCIPinfinity(scip), transformed) );
2659  }
2660  else if( strcmp(conshdlrname, "quadratic") == 0 )
2661  {
2662  SCIP_CALL( printQuadraticCons(scip, file, consname,
2666  SCIPgetLhsQuadratic(scip, cons), SCIPgetRhsQuadratic(scip, cons), transformed) );
2667 
2668  nlcons = TRUE;
2669  }
2670  else if( strcmp(conshdlrname, "nonlinear") == 0 )
2671  {
2672  /* cons_nonlinear does not have exprtree's at hand during presolve */
2674  && SCIPgetExprgraphNonlinear(scip,conshdlr) != NULL )
2675  {
2676  SCIP_EXPRTREE* exprtree;
2677  SCIP_Real coef;
2678 
2680  coef = 1.0;
2681  SCIP_CALL( printNonlinearCons(scip, file, consname,
2683  1, &exprtree, &coef,
2684  SCIPgetLhsNonlinear(scip, cons), SCIPgetRhsNonlinear(scip, cons), transformed, &nsmooth) );
2685 
2686  SCIP_CALL( SCIPexprtreeFree(&exprtree) );
2687  }
2688  else
2689  {
2690  SCIP_CALL( printNonlinearCons(scip, file, consname,
2693  SCIPgetLhsNonlinear(scip, cons), SCIPgetRhsNonlinear(scip, cons), transformed, &nsmooth) );
2694  }
2695  nlcons = TRUE;
2696  nqcons = TRUE;
2697  }
2698  else if( strcmp(conshdlrname, "bivariate") == 0 )
2699  {
2700  SCIP_EXPRTREE* exprtree;
2701  SCIP_VAR* linvar;
2702  SCIP_Real lincoef;
2703  int exprdegree;
2704  SCIP_Real one;
2705 
2706  exprtree = SCIPgetExprtreeBivariate(scip, cons);
2707  assert(exprtree != NULL);
2708 
2709  linvar = SCIPgetLinearVarBivariate(scip, cons);
2710  lincoef = SCIPgetLinearCoefBivariate(scip, cons);
2711  one = 1.0;
2712  SCIP_CALL( printNonlinearCons(scip, file, consname,
2713  linvar == NULL ? 0 : 1, &linvar, &lincoef,
2714  1, &exprtree, &one,
2715  SCIPgetLhsBivariate(scip, cons), SCIPgetRhsBivariate(scip, cons), transformed, &nsmooth) );
2716 
2717  SCIP_CALL( SCIPexprtreeGetMaxDegree(exprtree, &exprdegree) );
2718  if( exprdegree > 1 )
2719  nlcons = TRUE;
2720  if( exprdegree > 2)
2721  nqcons = TRUE;
2722  }
2723  else if( strcmp(conshdlrname, "setppc") == 0 )
2724  {
2725  consvars = SCIPgetVarsSetppc(scip, cons);
2726  nconsvars = SCIPgetNVarsSetppc(scip, cons);
2727 
2728  switch( SCIPgetTypeSetppc(scip, cons) )
2729  {
2731  SCIP_CALL( printLinearCons(scip, file, consname,
2732  nconsvars, consvars, NULL, 1.0, 1.0, transformed) );
2733  break;
2735  SCIP_CALL( printLinearCons(scip, file, consname,
2736  nconsvars, consvars, NULL, -SCIPinfinity(scip), 1.0, transformed) );
2737  break;
2739  SCIP_CALL( printLinearCons(scip, file, consname,
2740  nconsvars, consvars, NULL, 1.0, SCIPinfinity(scip), transformed) );
2741  break;
2742  }
2743  }
2744  else if( strcmp(conshdlrname, "varbound") == 0 )
2745  {
2746  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) );
2747  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) );
2748 
2749  consvars[0] = SCIPgetVarVarbound(scip, cons);
2750  consvars[1] = SCIPgetVbdvarVarbound(scip, cons);
2751 
2752  consvals[0] = 1.0;
2753  consvals[1] = SCIPgetVbdcoefVarbound(scip, cons);
2754 
2755  SCIP_CALL( printLinearCons(scip, file, consname,
2756  2, consvars, consvals,
2757  SCIPgetLhsVarbound(scip, cons), SCIPgetRhsVarbound(scip, cons), transformed) );
2758 
2759  SCIPfreeBufferArray(scip, &consvars);
2760  SCIPfreeBufferArray(scip, &consvals);
2761  }
2762  else if( strcmp(conshdlrname, "soc") == 0 )
2763  {
2764  SCIP_CALL( printSOCCons(scip, file, consname,
2765  SCIPgetNLhsVarsSOC(scip, cons), SCIPgetLhsVarsSOC(scip, cons), SCIPgetLhsCoefsSOC(scip, cons), SCIPgetLhsOffsetsSOC(scip, cons), SCIPgetLhsConstantSOC(scip, cons),
2766  SCIPgetRhsVarSOC(scip, cons), SCIPgetRhsCoefSOC(scip, cons), SCIPgetRhsOffsetSOC(scip, cons), transformed) );
2767 
2768  nlcons = nlcons || !isGAMSprintableSOC(SCIPgetNLhsVarsSOC(scip, cons), SCIPgetLhsVarsSOC(scip, cons), SCIPgetLhsCoefsSOC(scip, cons), SCIPgetLhsOffsetsSOC(scip, cons), SCIPgetLhsConstantSOC(scip, cons),
2769  SCIPgetRhsVarSOC(scip, cons), SCIPgetRhsCoefSOC(scip, cons), SCIPgetRhsOffsetSOC(scip, cons));
2770  }
2771  else if( strcmp(conshdlrname, "indicator") == 0 )
2772  {
2773  SCIP_CALL( printIndicatorCons(scip, file, consname,
2774  SCIPgetBinaryVarIndicator(cons), SCIPgetSlackVarIndicator(cons), &indicatorsosdef,
2775  transformed) );
2776  }
2777  else if( strcmp(conshdlrname, "abspower") == 0 )
2778  {
2779  SCIP_CALL( printSignpowerCons(scip, file, consname,
2780  SCIPgetNonlinearVarAbspower(scip, cons), SCIPgetLinearVarAbspower(scip, cons),
2781  SCIPgetExponentAbspower(scip, cons), SCIPgetOffsetAbspower(scip, cons), SCIPgetCoefLinearAbspower(scip, cons),
2782  SCIPgetLhsAbspower(scip, cons), SCIPgetRhsAbspower(scip, cons), transformed, signpowerallowed, &nsmooth) );
2783 
2784  nlcons = TRUE;
2785  nqcons = TRUE;
2786  }
2787  else if( strcmp(conshdlrname, "SOS1") == 0 )
2788  {
2789  SCIP_CALL( printSOSCons(scip, file, consname,
2790  SCIPgetNVarsSOS1(scip, cons), SCIPgetVarsSOS1(scip, cons), 1,
2791  transformed) );
2792  discrete = TRUE;
2793  }
2794  else if( strcmp(conshdlrname, "SOS2") == 0 )
2795  {
2796  SCIP_CALL( printSOSCons(scip, file, consname,
2797  SCIPgetNVarsSOS2(scip, cons), SCIPgetVarsSOS2(scip, cons), 2,
2798  transformed) );
2799  discrete = TRUE;
2800  }
2801  else
2802  {
2803  SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname );
2804  SCIPinfoMessage(scip, file, "* ");
2805  SCIP_CALL( SCIPprintCons(scip, cons, file) );
2806  SCIPinfoMessage(scip, file, ";\n");
2807  }
2808 
2809  SCIPinfoMessage(scip, file, "\n");
2810  }
2811  /* if at most quadratic, then cannot have nonsmooth functions */
2812  assert(nlcons || !nsmooth);
2813 
2814  /* print model creation */
2815  SCIPinfoMessage(scip, file, "Model m / all /;\n\n");
2816 
2817  /* set some options to reduce listing file size */
2818  SCIPinfoMessage(scip, file, "option limrow = 0;\n");
2819  SCIPinfoMessage(scip, file, "option limcol = 0;\n\n");
2820 
2821  /* print solve command */
2822  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s%s",
2823  discrete ? "MI" : "", nlcons ? (nqcons ? ((nsmooth && !discrete) ? "DNLP" : "NLP") : "QCP") : (discrete > 0 ? "P" : "LP"));
2824 
2825  if( objvar != NULL )
2826  {
2827  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(objvar)) );
2828  }
2829 
2830  SCIPinfoMessage(scip, file, "$if not set %s $set %s %s\n", buffer, buffer, buffer);
2831  SCIPinfoMessage(scip, file, "Solve m using %%%s%% %simizing %s;\n",
2832  buffer, objsense == SCIP_OBJSENSE_MINIMIZE ? "min" : "max", objvar != NULL ? varname : "objvar");
2833 
2834  *result = SCIP_SUCCESS;
2835 
2836  return SCIP_OKAY;
2837 }
SCIP_Real SCIPgetCoefLinearAbspower(SCIP *scip, SCIP_CONS *cons)
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
SCIP_VAR * SCIPgetNonlinearVarAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLinearCoefBivariate(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPgetCharParam(SCIP *scip, const char *name, char *value)
Definition: scip.c:4508
SCIP_VAR ** SCIPgetLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5357
#define GMS_MAX_LINELEN
Definition: reader_gms.c:64
SCIP_EXPRGRAPH * SCIPgetExprgraphNonlinear(SCIP *scip, SCIP_CONSHDLR *conshdlr)
static SCIP_DECL_READERWRITE(readerWriteGms)
Definition: reader_gms.c:2150
SCIP_Bool SCIPconsIsEnabled(SCIP_CONS *cons)
Definition: cons.c:8083
static SCIP_RETCODE printNonlinearRow(SCIP *scip, FILE *file, const char *rowname, const char *rownameextension, const char *type, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoeffs, int nexprtrees, SCIP_EXPRTREE **exprtrees, SCIP_Real *exprtreecoefs, SCIP_Real rhs, SCIP_Bool transformed, SCIP_Bool *nsmooth)
Definition: reader_gms.c:1753
static SCIP_RETCODE printSignpowerCons(SCIP *scip, FILE *file, const char *rowname, SCIP_VAR *nonlinvar, SCIP_VAR *linvar, SCIP_Real exponent, SCIP_Real offset, SCIP_Real coeflinear, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool transformed, SCIP_Bool signpowerallowed, SCIP_Bool *nsmooth)
Definition: reader_gms.c:1304
SCIP_VAR * var2
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:47292
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip.c:821
int * SCIPexprGetMonomialChildIndices(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5920
Constraint handler for variable bound constraints .
SCIP_VAR ** SCIPgetVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10569
SCIP_Real SCIPgetRhsBivariate(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetOffsetAbspower(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9230
static SCIP_RETCODE printExpr(SCIP *scip, FILE *file, char *linebuffer, int *linecnt, SCIP_Bool *nsmooth, SCIP_Bool transformed, SCIP_EXPR *expr, SCIP_VAR **exprvars)
Definition: reader_gms.c:1353
SCIP_EXPROP SCIPexprGetOperator(SCIP_EXPR *expr)
Definition: expr.c:5693
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17276
int SCIPgetNVarsLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip.c:4489
#define SCIP_MAXSTRLEN
Definition: def.h:259
SCIP_VAR * var1
SCIP_VAR * SCIPgetLinearVarAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * SCIPgetLhsOffsetsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5381
static SCIP_Bool isGAMSprintableSOC(int nlhsvars, SCIP_VAR **lhsvars, SCIP_Real *lhscoeffs, SCIP_Real *lhsoffsets, SCIP_Real lhsconstant, SCIP_VAR *rhsvar, SCIP_Real rhscoef, SCIP_Real rhsoffset)
Definition: reader_gms.c:770
#define READER_DESC
Definition: reader_gms.c:59
const char * SCIPexpropGetName(SCIP_EXPROP op)
Definition: expr.c:3263
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
Definition: scip.c:47082
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17332
SCIP_RETCODE SCIPexprtreeGetMaxDegree(SCIP_EXPRTREE *tree, int *maxdegree)
Definition: expr.c:8710
SCIP_DECL_READERFREE(ReaderTSP::scip_free)
Definition: ReaderTSP.cpp:137
static void clearLine(char *linebuffer, int *linecnt)
Definition: reader_gms.c:123
const char * SCIPreaderGetName(SCIP_READER *reader)
Definition: reader.c:515
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:16842
constraint handler for indicator constraints
SCIP_Real SCIPexprGetRealPowerExponent(SCIP_EXPR *expr)
Definition: expr.c:5756
int SCIPexprGetOpIndex(SCIP_EXPR *expr)
Definition: expr.c:5723
SCIP_Real SCIPexprGetPolynomialConstant(SCIP_EXPR *expr)
Definition: expr.c:5888
#define FALSE
Definition: def.h:64
SCIP_Real * SCIPgetLinearCoefsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:47022
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
Definition: scip.c:1384
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:10011
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
Definition: scip.c:47094
#define TRUE
Definition: def.h:63
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define GMS_DEFAULT_INDICATORREFORM
Definition: reader_gms.c:69
static SCIP_RETCODE printConformName(SCIP *scip, char *t, int len, const char *name)
Definition: reader_gms.c:234
SCIP_Real SCIPgetRhsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPconsIsTransformed(SCIP_CONS *cons)
Definition: cons.c:8295
SCIP_VAR ** SCIPgetVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPwriteGms(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_gms.c:2220
static SCIP_RETCODE printSignpowerRow(SCIP *scip, FILE *file, const char *rowname, const char *rownameextension, const char *type, SCIP_VAR *nonlinvar, SCIP_VAR *linvar, SCIP_Real exponent, SCIP_Real offset, SCIP_Real coeflinear, SCIP_Real rhs, SCIP_Bool transformed, SCIP_Bool signpowerallowed, SCIP_Bool *nsmooth)
Definition: reader_gms.c:1100
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip.h:22628
int SCIPgetNVarsSOS2(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos2.c:2445
SCIP_EXPRTREE ** SCIPgetExprtreesNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:46957
constraint handler for second order cone constraints
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:22632
Constraint handler for the set partitioning / packing / covering constraints .
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1267
#define SCIPdebugMsg
Definition: scip.h:455
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsQuadratic(SCIP *scip, SCIP_CONS *cons)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip.c:1343
SCIP_VAR ** SCIPexprtreeGetVars(SCIP_EXPRTREE *tree)
Definition: nlp.c:101
static SCIP_RETCODE checkVarnames(SCIP *scip, SCIP_VAR **vars, int nvars)
Definition: reader_gms.c:1882
int SCIPgetNExprtreesNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_EXPRDATA_MONOMIAL ** SCIPexprGetMonomials(SCIP_EXPR *expr)
Definition: expr.c:5864
int SCIPgetNQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:47417
static void appendLineWithIndent(SCIP *scip, FILE *file, char *linebuffer, int *linecnt, const char *extension)
Definition: reader_gms.c:193
int SCIPexprGetMonomialNFactors(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5910
int SCIPexprGetIntPowerExponent(SCIP_EXPR *expr)
Definition: expr.c:5767
SCIP_EXPRTREE * SCIPgetExprtreeBivariate(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR * SCIPgetSlackVarIndicator(SCIP_CONS *cons)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17286
Constraint handler for knapsack constraints of the form , x binary and .
static SCIP_RETCODE checkConsnames(SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_Bool transformed)
Definition: reader_gms.c:1941
static void conformName(char *name)
Definition: reader_gms.c:210
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
SCIP_RETCODE SCIPincludeReaderGms(SCIP *scip)
Definition: reader_gms.c:2177
SCIP_Real SCIPvarGetLbOriginal(SCIP_VAR *var)
Definition: var.c:17222
SCIP_Real * SCIPexprGetQuadLinearCoefs(SCIP_EXPR *expr)
Definition: expr.c:5840
SCIP_Real SCIPgetRhsVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsSOS2(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos2.c:2470
Constraint handler for logicor constraints (equivalent to set covering, but algorithms are suited fo...
SCIP_Real SCIPvarGetUbOriginal(SCIP_VAR *var)
Definition: var.c:17242
SCIP_Real * SCIPgetCoefsLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetVbdcoefVarbound(SCIP *scip, SCIP_CONS *cons)
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7986
SCIP_VAR ** SCIPgetVarsLogicor(SCIP *scip, SCIP_CONS *cons)
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16662
SCIP_Real SCIPexprGetQuadConstant(SCIP_EXPR *expr)
Definition: expr.c:5827
static SCIP_RETCODE printQuadraticRow(SCIP *scip, FILE *file, const char *rowname, const char *rownameextension, const char *type, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoeffs, int nquadvarterms, SCIP_QUADVARTERM *quadvarterms, int nbilinterms, SCIP_BILINTERM *bilinterms, SCIP_Real rhs, SCIP_Bool transformed)
Definition: reader_gms.c:586
static SCIP_DECL_READERCOPY(readerCopyGms)
Definition: reader_gms.c:2034
constraint handler for quadratic constraints
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
Definition: scip.c:4432
SCIP_Real * SCIPgetExprtreeCoefsNonlinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE printActiveVariables(SCIP *scip, FILE *file, char *linebuffer, int *linecnt, const char *prefix, const char *suffix, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Bool transformed)
Definition: reader_gms.c:259
SCIP_VAR * SCIPgetVbdvarVarbound(SCIP *scip, SCIP_CONS *cons)
#define SCIP_CALL(x)
Definition: def.h:350
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:19249
#define GMS_MAX_NAMELEN
Definition: reader_gms.c:66
static SCIP_RETCODE getActiveVariables(SCIP *scip, SCIP_VAR **vars, SCIP_Real *scalars, int *nvars, SCIP_Real *constant, SCIP_Bool transformed)
Definition: reader_gms.c:80
static SCIP_RETCODE printNonlinearCons(SCIP *scip, FILE *file, const char *rowname, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoeffs, int nexprtrees, SCIP_EXPRTREE **exprtrees, SCIP_Real *exprtreecoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool transformed, SCIP_Bool *nsmooth)
Definition: reader_gms.c:1833
SCIP_BILINTERM * SCIPgetBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_EXPR * SCIPexprtreeGetRoot(SCIP_EXPRTREE *tree)
Definition: expr.c:8602
SCIP_Real SCIPgetRhsOffsetSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5429
SCIP_Longint SCIPgetCapacityKnapsack(SCIP *scip, SCIP_CONS *cons)
#define GMS_MAX_PRINTLEN
Definition: reader_gms.c:65
SCIP_Real SCIPgetRhsQuadratic(SCIP *scip, SCIP_CONS *cons)
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:22620
public data structures and miscellaneous methods
SCIP_EXPR ** SCIPexprGetChildren(SCIP_EXPR *expr)
Definition: expr.c:5713
SCIP_Real SCIPexprGetSignPowerExponent(SCIP_EXPR *expr)
Definition: expr.c:5778
#define SCIP_Bool
Definition: def.h:61
int SCIPgetNLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5345
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Definition: scip.c:5264
#define GMS_DEFAULT_SIGNPOWER
Definition: reader_gms.c:70
SCIP_Real SCIPgetLhsBivariate(SCIP *scip, SCIP_CONS *cons)
static void endLine(SCIP *scip, FILE *file, char *linebuffer, int *linecnt)
Definition: reader_gms.c:137
enum SCIP_Objsense SCIP_OBJSENSE
Definition: type_prob.h:41
#define READER_EXTENSION
Definition: reader_gms.c:61
SCIP_VAR * SCIPgetRhsVarSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5405
SCIP_Real SCIPgetLhsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_SETPPCTYPE SCIPgetTypeSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9272
constraint handler for nonlinear constraints
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
Definition: scip.c:29085
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:8006
int SCIPexprGetNChildren(SCIP_EXPR *expr)
Definition: expr.c:5703
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17124
SCIP_RETCODE SCIPexprtreeFree(SCIP_EXPRTREE **tree)
Definition: expr.c:8852
int SCIPgetNVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10544
SCIP_RETCODE SCIPsetReaderWrite(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERWRITE((*readerwrite)))
Definition: scip.c:5374
constraint handler for bivariate nonlinear constraints
Constraint handler for linear constraints in their most general form, .
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:47033
SCIP_Real SCIPexprGetMonomialCoef(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5900
Constraint handler for absolute power constraints .
SCIP_RETCODE SCIPvarGetOrigvarSum(SCIP_VAR **var, SCIP_Real *scalar, SCIP_Real *constant)
Definition: var.c:12184
SCIP_VAR * SCIPgetBinaryVarIndicator(SCIP_CONS *cons)
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
Definition: scip.c:5302
static SCIP_RETCODE printIndicatorCons(SCIP *scip, FILE *file, const char *rowname, SCIP_VAR *z, SCIP_VAR *s, SCIP_Bool *sossetdeclr, SCIP_Bool transformed)
Definition: reader_gms.c:915
static void appendLine(SCIP *scip, FILE *file, char *linebuffer, int *linecnt, const char *extension)
Definition: reader_gms.c:159
SCIP_VAR ** SCIPgetVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9251
SCIP_VAR * SCIPgetLinearVarBivariate(SCIP *scip, SCIP_CONS *cons)
#define SCIP_REAL_MAX
Definition: def.h:150
static const char badchars[]
Definition: reader_gms.c:76
GAMS file reader and writer.
#define GMS_DEFAULT_BIGM
Definition: reader_gms.c:68
int SCIPgetNLinearVarsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPisIntegral(SCIP *scip, SCIP_Real val)
Definition: scip.c:47106
SCIP_Real * SCIPexprGetLinearCoefs(SCIP_EXPR *expr)
Definition: expr.c:5789
SCIP_RETCODE SCIPaddCharParam(SCIP *scip, const char *name, const char *desc, char *valueptr, SCIP_Bool isadvanced, char defaultvalue, const char *allowedvalues, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4349
int SCIPgetNLinearVarsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetRhsAbspower(SCIP *scip, SCIP_CONS *cons)
static const SCIP_Real scalars[]
Definition: lp.c:5618
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPexprGetOpReal(SCIP_EXPR *expr)
Definition: expr.c:5734
#define READER_NAME
Definition: reader_gms.c:55
static SCIP_RETCODE printSOSCons(SCIP *scip, FILE *file, const char *rowname, int nvars, SCIP_VAR **vars, int sostype, SCIP_Bool transformed)
Definition: reader_gms.c:1043
SCIP_QUADELEM * SCIPexprGetQuadElements(SCIP_EXPR *expr)
Definition: expr.c:5815
SCIP_Real SCIPgetLhsConstantSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5393
static SCIP_RETCODE printLinearCons(SCIP *scip, FILE *file, const char *rowname, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool transformed)
Definition: reader_gms.c:498
int SCIPexprGetNMonomials(SCIP_EXPR *expr)
Definition: expr.c:5876
SCIP_Real SCIPgetRhsCoefSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5417
static SCIP_RETCODE printQuadraticCons(SCIP *scip, FILE *file, const char *rowname, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoeffs, int nquadvarterms, SCIP_QUADVARTERM *quadvarterms, int nbilinterms, SCIP_BILINTERM *bilinterms, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool transformed)
Definition: reader_gms.c:705
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16781
SCIP_RETCODE SCIPexprgraphGetTree(SCIP_EXPRGRAPH *exprgraph, SCIP_EXPRGRAPHNODE *rootnode, SCIP_EXPRTREE **exprtree)
Definition: expr.c:16206
#define SCIP_Real
Definition: def.h:149
SCIP_VAR ** SCIPgetLinearVarsNonlinear(SCIP *scip, SCIP_CONS *cons)
#define GMS_PRINTLEN
Definition: reader_gms.c:67
constraint handler for SOS type 1 constraints
int SCIPgetNVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_DECL_READERREAD(ReaderTSP::scip_read)
Definition: ReaderTSP.cpp:150
SCIP_Real SCIPgetExponentAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * SCIPexprGetMonomialExponents(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5930
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
Definition: scip.c:5350
#define SCIP_Longint
Definition: def.h:134
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16827
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:47070
static SCIP_RETCODE printSOCCons(SCIP *scip, FILE *file, const char *rowname, int nlhsvars, SCIP_VAR **lhsvars, SCIP_Real *lhscoeffs, SCIP_Real *lhsoffsets, SCIP_Real lhsconstant, SCIP_VAR *rhsvar, SCIP_Real rhscoef, SCIP_Real rhsoffset, SCIP_Bool transformed)
Definition: reader_gms.c:825
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
constraint handler for SOS type 2 constraints
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17342
SCIP_Real SCIPgetLhsAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_QUADVARTERM * SCIPgetQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_EXPRGRAPHNODE * SCIPgetExprgraphNodeNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
Definition: scip.c:47155
SCIP_Longint * SCIPgetWeightsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPexprGetLinearConstant(SCIP_EXPR *expr)
Definition: expr.c:5802
SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
Definition: scip.c:47167
int SCIPexprGetNQuadElements(SCIP_EXPR *expr)
Definition: expr.c:5852
static SCIP_RETCODE printLinearRow(SCIP *scip, FILE *file, const char *rowname, const char *rownameextension, const char *type, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real rhs)
Definition: reader_gms.c:414
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * SCIPgetLhsCoefsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5369
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4321
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:47143
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
Definition: scip.c:5326
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
Definition: scip.c:19039
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:4239
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:16949
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:16817
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:22624