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  const char* opstr = SCIPexprGetOperator(expr) == SCIP_EXPR_SUM ? " + " : " * ";
1572 
1573  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1574  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
1575  {
1576  if( i > 0 )
1577  {
1578  appendLineWithIndent(scip, file, linebuffer, linecnt, opstr);
1579  }
1580  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[i], exprvars) );
1581  }
1582  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1583  }
1584  }
1585  break;
1586  }
1587 
1588  case SCIP_EXPR_LINEAR:
1589  {
1590  SCIP_Real constant;
1591  int i;
1592 
1593  constant = SCIPexprGetLinearConstant(expr);
1594 
1595  if( SCIPexprGetNChildren(expr) == 0 )
1596  {
1597  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1598  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1599  break;
1600  }
1601 
1602  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1603 
1604  if( constant != 0.0 )
1605  {
1606  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1607  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1608  }
1609 
1610  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
1611  {
1612  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g * ", SCIPexprGetLinearCoefs(expr)[i]);
1613  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1614  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[i], exprvars) );
1615  }
1616 
1617  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1618  break;
1619  }
1620 
1621  case SCIP_EXPR_QUADRATIC:
1622  {
1623  SCIP_Real constant;
1624  int i;
1625  SCIP_QUADELEM* quadelems;
1626  SCIP_Real* lincoefs;
1627 
1628  constant = SCIPexprGetQuadConstant(expr);
1629 
1630  if( SCIPexprGetNChildren(expr) == 0 )
1631  {
1632  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1633  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1634  break;
1635  }
1636 
1637  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1638 
1639  if( constant != 0.0 )
1640  {
1641  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", constant);
1642  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1643  }
1644 
1645  lincoefs = SCIPexprGetQuadLinearCoefs(expr);
1646  if( lincoefs != NULL )
1647  for( i = 0; i < SCIPexprGetNChildren(expr); ++i )
1648  {
1649  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g * ", lincoefs[i]);
1650  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1651  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[i], exprvars) );
1652  }
1653 
1654  quadelems = SCIPexprGetQuadElements(expr);
1655  for( i = 0; i < SCIPexprGetNQuadElements(expr); ++i )
1656  {
1657  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g * ", quadelems[i].coef);
1658  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1659 
1660  if( quadelems[i].idx1 == quadelems[i].idx2 )
1661  {
1662  appendLineWithIndent(scip, file, linebuffer, linecnt, "sqr(");
1663  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[quadelems[i].idx1], exprvars) );
1664  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1665  }
1666  else
1667  {
1668  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[quadelems[i].idx1], exprvars) );
1669  appendLineWithIndent(scip, file, linebuffer, linecnt, " * ");
1670  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[quadelems[i].idx2], exprvars) );
1671  }
1672  }
1673 
1674  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1675  break;
1676  }
1677 
1678  case SCIP_EXPR_POLYNOMIAL:
1679  {
1680  SCIP_EXPRDATA_MONOMIAL* monomdata;
1681  SCIP_Real exponent;
1682  int i;
1683  int j;
1684 
1685  appendLineWithIndent(scip, file, linebuffer, linecnt, "(");
1686 
1687  if( SCIPexprGetPolynomialConstant(expr) != 0.0 || SCIPexprGetNMonomials(expr) == 0 )
1688  {
1689  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%.15g", SCIPexprGetPolynomialConstant(expr));
1690  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1691  }
1692 
1693  for( i = 0; i < SCIPexprGetNMonomials(expr); ++i )
1694  {
1695  monomdata = SCIPexprGetMonomials(expr)[i];
1696  assert(monomdata != NULL);
1697 
1698  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %+.15g", SCIPexprGetMonomialCoef(monomdata));
1699  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1700 
1701  for( j = 0; j < SCIPexprGetMonomialNFactors(monomdata); ++j )
1702  {
1703  appendLineWithIndent(scip, file, linebuffer, linecnt, "*");
1704 
1705  exponent = SCIPexprGetMonomialExponents(monomdata)[j];
1706  if( exponent == 1.0 )
1707  {
1708  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1709  }
1710  else if( exponent == 2.0 )
1711  {
1712  appendLineWithIndent(scip, file, linebuffer, linecnt, "sqr(");
1713  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1714  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1715  }
1716  else if( exponent == 0.5 )
1717  {
1718  appendLineWithIndent(scip, file, linebuffer, linecnt, "sqrt(");
1719  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1720  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1721  }
1722  else if( ((SCIP_Real)((int)exponent)) == exponent )
1723  {
1724  appendLineWithIndent(scip, file, linebuffer, linecnt, "power(");
1725  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1726  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ", %d)", (int)SCIPround(scip, exponent));
1727  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1728  }
1729  else
1730  {
1731  SCIP_CALL( printExpr(scip, file, linebuffer, linecnt, nsmooth, transformed, SCIPexprGetChildren(expr)[SCIPexprGetMonomialChildIndices(monomdata)[j]], exprvars) );
1732  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " ** %.15g", exponent);
1733  appendLineWithIndent(scip, file, linebuffer, linecnt, buffer);
1734  }
1735  }
1736  }
1737 
1738  appendLineWithIndent(scip, file, linebuffer, linecnt, ")");
1739  break;
1740  }
1741 
1742  default:
1743  SCIPerrorMessage("unexpected operand %d in expression\n", SCIPexprGetOperator(expr));
1744  return SCIP_OKAY;
1745  } /*lint !e788*/
1746 
1747  return SCIP_OKAY;
1748 }
1749 
1750 /* print nonlinear row in GAMS format to file stream */
1751 static
1753  SCIP* scip, /**< SCIP data structure */
1754  FILE* file, /**< output file (or NULL for standard output) */
1755  const char* rowname, /**< row name */
1756  const char* rownameextension, /**< row name extension */
1757  const char* type, /**< row type ("=e=", "=l=", or "=g=") */
1758  int nlinvars, /**< number of linear terms */
1759  SCIP_VAR** linvars, /**< variables in linear part */
1760  SCIP_Real* lincoeffs, /**< coefficients of variables in linear part */
1761  int nexprtrees, /**< number of expression trees */
1762  SCIP_EXPRTREE** exprtrees, /**< expression trees */
1763  SCIP_Real* exprtreecoefs, /**< expression tree coefficients */
1764  SCIP_Real rhs, /**< right hand side */
1765  SCIP_Bool transformed, /**< transformed constraint? */
1766  SCIP_Bool* nsmooth /**< buffer to store whether we printed a nonsmooth function */
1767  )
1768 {
1769  char linebuffer[GMS_MAX_PRINTLEN] = { '\0' };
1770  int linecnt;
1771 
1772  char consname[GMS_MAX_NAMELEN + 3]; /* four extra characters for ' ..' */
1773  char buffer[GMS_MAX_PRINTLEN];
1774 
1775  int i;
1776 
1777  assert( scip != NULL );
1778  assert( strlen(rowname) > 0 || strlen(rownameextension) > 0 );
1779  assert( strcmp(type, "=e=") == 0 || strcmp(type, "=l=") == 0 || strcmp(type, "=g=") == 0 );
1780 
1781  clearLine(linebuffer, &linecnt);
1782 
1783  /* start each line with a space */
1784  appendLine(scip, file, linebuffer, &linecnt, " ");
1785 
1786  /* print row name */
1787  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%s%s ..", rowname, rownameextension);
1788  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN + 3, buffer) );
1789 
1790  appendLine(scip, file, linebuffer, &linecnt, consname);
1791 
1792  /* print nonlinear terms
1793  */
1794  for( i = 0; i < nexprtrees; ++i )
1795  {
1796  assert(exprtrees[i] != NULL);
1797  if( exprtreecoefs[i] != 0.0 )
1798  {
1799  (void) SCIPsnprintf(buffer, GMS_MAX_NAMELEN + 3, "%+g * (", exprtreecoefs[i]);
1800  appendLineWithIndent(scip, file, linebuffer, &linecnt, buffer);
1801  SCIP_CALL( printExpr(scip, file, linebuffer, &linecnt, nsmooth, transformed, SCIPexprtreeGetRoot(exprtrees[i]), SCIPexprtreeGetVars(exprtrees[i])) );
1802  appendLineWithIndent(scip, file, linebuffer, &linecnt, ")");
1803  }
1804  }
1805 
1806  /* print linear terms, do after nonlinear since nonlinear may not print sign in beginning */
1807  if( nlinvars > 0 )
1808  {
1809  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "+", " ", nlinvars, linvars, lincoeffs, transformed) );
1810  }
1811 
1812  /* print right hand side */
1813  if( linecnt == 0 )
1814  /* we start a new line; therefore we tab this line */
1815  appendLine(scip, file, linebuffer, &linecnt, " ");
1816 
1817  if( SCIPisZero(scip, rhs) )
1818  rhs = 0.0;
1819 
1820  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s %.15g;", type, rhs);
1821 
1822  appendLine(scip, file, linebuffer, &linecnt, buffer);
1823 
1824  endLine(scip, file, linebuffer, &linecnt);
1825 
1826  return SCIP_OKAY;
1827 }
1828 
1829 /* print nonlinear row in GAMS format to file stream (performing retransformation to active linear variables)
1830  * */
1831 static
1833  SCIP* scip, /**< SCIP data structure */
1834  FILE* file, /**< output file (or NULL for standard output) */
1835  const char* rowname, /**< row name */
1836  int nlinvars, /**< number of linear terms */
1837  SCIP_VAR** linvars, /**< variables in linear part */
1838  SCIP_Real* lincoeffs, /**< coefficients of variables in linear part */
1839  int nexprtrees, /**< number of expression trees */
1840  SCIP_EXPRTREE** exprtrees, /**< expression trees */
1841  SCIP_Real* exprtreecoefs, /**< expression tree coefficients */
1842  SCIP_Real lhs, /**< left hand side */
1843  SCIP_Real rhs, /**< right hand side */
1844  SCIP_Bool transformed, /**< transformed constraint? */
1845  SCIP_Bool* nsmooth /**< buffer to store whether we printed a nonsmooth function */
1846  )
1847 {
1848  assert( scip != NULL );
1849  assert( strlen(rowname) > 0 );
1850 
1851  /* print row(s) in GAMS format */
1852  if( SCIPisEQ(scip, lhs, rhs) )
1853  {
1854  assert( !SCIPisInfinity(scip, rhs) );
1855 
1856  /* print equality constraint */
1857  SCIP_CALL( printNonlinearRow(scip, file, rowname, "", "=e=",
1858  nlinvars, linvars, lincoeffs, nexprtrees, exprtrees, exprtreecoefs, rhs, transformed, nsmooth) );
1859  }
1860  else
1861  {
1862  if( !SCIPisInfinity(scip, -lhs) )
1863  {
1864  /* print inequality ">=" */
1865  SCIP_CALL( printNonlinearRow(scip, file, rowname, SCIPisInfinity(scip, rhs) ? "" : "_lhs", "=g=",
1866  nlinvars, linvars, lincoeffs, nexprtrees, exprtrees, exprtreecoefs, lhs, transformed, nsmooth) );
1867  }
1868  if( !SCIPisInfinity(scip, rhs) )
1869  {
1870  /* print inequality "<=" */
1871  SCIP_CALL( printNonlinearRow(scip, file, rowname, SCIPisInfinity(scip, -lhs) ? "" : "_rhs", "=l=",
1872  nlinvars, linvars, lincoeffs, nexprtrees, exprtrees, exprtreecoefs, rhs, transformed, nsmooth) );
1873  }
1874  }
1875 
1876  return SCIP_OKAY;
1877 }
1878 
1879 /** method check if the variable names are not longer than GMS_MAX_NAMELEN */
1880 static
1882  SCIP* scip, /**< SCIP data structure */
1883  SCIP_VAR** vars, /**< array of variables */
1884  int nvars /**< number of variables */
1885  )
1886 {
1887  int v;
1888  SCIP_VAR* var;
1889  SCIP_Bool replaceforbiddenchars;
1890  const char* badchar;
1891 
1892  assert( scip != NULL );
1893  assert( vars != NULL );
1894 
1895  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/replaceforbiddenchars", &replaceforbiddenchars) );
1896 
1897  /* check if the variable names contain any of the bad symbols */
1898  for( badchar = badchars; *badchar; ++badchar )
1899  {
1900  for( v = 0; v < nvars; ++v )
1901  {
1902  var = vars[v];
1903  assert( var != NULL );
1904 
1905  if( strchr(SCIPvarGetName(var), *badchar) != NULL )
1906  {
1907  if( replaceforbiddenchars )
1908  {
1909  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);
1910  }
1911  else
1912  {
1913  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);
1914  }
1915 
1916  break;
1917  }
1918  }
1919  }
1920 
1921  /* check if the variable names are too long */
1922  for( v = 0; v < nvars; ++v )
1923  {
1924  var = vars[v];
1925  assert( var != NULL );
1926 
1927  if( strlen(SCIPvarGetName(var)) > GMS_MAX_NAMELEN )
1928  {
1929  SCIPwarningMessage(scip, "there is a variable name which has to be cut down to %d characters; GAMS model might be corrupted.\n",
1930  GMS_MAX_NAMELEN - 1);
1931  break;
1932  }
1933  }
1934 
1935  return SCIP_OKAY;
1936 }
1937 
1938 /** method check if the constraint names are not longer than GMS_MAX_NAMELEN */
1939 static
1941  SCIP* scip, /**< SCIP data structure */
1942  SCIP_CONS** conss, /**< array of constraints */
1943  int nconss, /**< number of constraints */
1944  SCIP_Bool transformed /**< TRUE iff problem is the transformed problem */
1945  )
1946 {
1947  int c;
1948  SCIP_CONS* cons;
1949  SCIP_CONSHDLR* conshdlr;
1950  const char* conshdlrname;
1951  SCIP_Bool replaceforbiddenchars;
1952  const char* badchar;
1953 
1954  assert( scip != NULL );
1955  assert( conss != NULL );
1956 
1957  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/replaceforbiddenchars", &replaceforbiddenchars) );
1958 
1959  /* check if the constraint names contain any of the bad symbols */
1960  for( badchar = badchars; *badchar; ++badchar )
1961  {
1962  for( c = 0; c < nconss; ++c )
1963  {
1964  cons = conss[c];
1965  assert( cons != NULL );
1966 
1967  if( strchr(SCIPconsGetName(cons), *badchar) != NULL )
1968  {
1969  if( replaceforbiddenchars )
1970  {
1971  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);
1972  }
1973  else
1974  {
1975  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);
1976  }
1977 
1978  break;
1979  }
1980  }
1981  }
1982 
1983  /* check if the constraint names are too long */
1984  for( c = 0; c < nconss; ++c )
1985  {
1986  cons = conss[c];
1987  assert( cons != NULL );
1988 
1989  /* in case the transformed is written, only constraints are posted which are enabled in the current node */
1990  assert(!transformed || SCIPconsIsEnabled(cons));
1991 
1992  conshdlr = SCIPconsGetHdlr(cons);
1993  assert( conshdlr != NULL );
1994 
1995  conshdlrname = SCIPconshdlrGetName(conshdlr);
1996  assert( transformed == SCIPconsIsTransformed(cons) );
1997 
1998  if( strcmp(conshdlrname, "linear") == 0 || strcmp(conshdlrname, "quadratic") == 0 )
1999  {
2000  SCIP_Real lhs = strcmp(conshdlrname, "linear") == 0 ? SCIPgetLhsLinear(scip, cons) : SCIPgetLhsQuadratic(scip, cons);
2001  SCIP_Real rhs = strcmp(conshdlrname, "linear") == 0 ? SCIPgetLhsLinear(scip, cons) : SCIPgetRhsQuadratic(scip, cons);
2002 
2003  if( SCIPisEQ(scip, lhs, rhs) && strlen(SCIPconsGetName(conss[c])) > GMS_MAX_NAMELEN )
2004  {
2005  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n",
2006  GMS_MAX_NAMELEN - 1);
2007  break;
2008  }
2009  else if( !SCIPisEQ(scip, lhs, rhs) && strlen(SCIPconsGetName(conss[c])) > GMS_MAX_NAMELEN - 4 )
2010  {
2011  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n",
2012  GMS_MAX_NAMELEN - 5);
2013  break;
2014  }
2015  }
2016  else if( strlen(SCIPconsGetName(conss[c])) > GMS_MAX_NAMELEN )
2017  {
2018  SCIPwarningMessage(scip, "there is a constraint name which has to be cut down to %d characters;\n",
2019  GMS_MAX_NAMELEN - 1);
2020  break;
2021  }
2022  }
2023  return SCIP_OKAY;
2024 }
2025 
2026 
2027 /*
2028  * Callback methods of reader
2029  */
2030 
2031 /** copy method for reader plugins (called when SCIP copies plugins) */
2032 static
2033 SCIP_DECL_READERCOPY(readerCopyGms)
2034 { /*lint --e{715}*/
2035  assert(scip != NULL);
2036  assert(reader != NULL);
2037  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
2038 
2039  /* call inclusion method of reader */
2041 
2042  return SCIP_OKAY;
2043 }
2044 
2045 #ifdef WITH_GAMS
2046 /** problem reading method of reader */
2047 static
2048 SCIP_DECL_READERREAD(readerReadGms)
2049 {
2050  SCIP_RETCODE ret;
2051  FILE* convertdopt;
2052  char gamscall[SCIP_MAXSTRLEN];
2053  char buffer[GMS_SSSIZE];
2054  int rc;
2055  gmoHandle_t gmo = NULL;
2056  gevHandle_t gev = NULL;
2057 
2058  assert(scip != NULL);
2059  assert(reader != NULL);
2060  assert(filename != NULL);
2061  assert(result != NULL);
2062 
2063  *result = SCIP_DIDNOTRUN;
2064  ret = SCIP_ERROR;
2065 
2066  /* create temporary directory */
2067  mkdir("loadgms.tmp", S_IRWXU);
2068 
2069  /* create empty convertd options file */
2070  convertdopt = fopen("loadgms.tmp/convertd.opt", "w");
2071  if( convertdopt == NULL )
2072  {
2073  SCIPerrorMessage("Could not create convertd options file. Do you have write permissions in execution directory?\n");
2074  goto TERMINATE;
2075  }
2076  fputs(" ", convertdopt);
2077  fclose(convertdopt);
2078 
2079  /* call GAMS with convertd solver to get compiled model instance in temporary directory */
2080  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",
2081  filename, SCIPgetVerbLevel(scip) == SCIP_VERBLEVEL_FULL ? 3 : 0);
2082  SCIPdebugMsg(scip, gamscall);
2083  rc = system(gamscall);
2084  if( rc != 0 )
2085  {
2086  SCIPerrorMessage("GAMS call returned with code %d, check loadgms.tmp/listing for details.\n", rc);
2087  /* likely the GAMS model could not be compiled, which we could report as a readerror */
2088  ret = SCIP_READERROR;
2089  goto TERMINATE;
2090  }
2091 
2092  /* initialize GEV library and create GEV */
2093  if( !gevCreateDD(&gev, WITH_GAMS, buffer, sizeof(buffer)) )
2094  {
2095  SCIPerrorMessage(buffer);
2096  goto TERMINATE;
2097  }
2098 
2099  /* initialize GMO library and create GMO */
2100  if( !gmoCreateDD(&gmo, WITH_GAMS, buffer, sizeof(buffer)) )
2101  {
2102  SCIPerrorMessage(buffer);
2103  goto TERMINATE;
2104  }
2105 
2106  /* load control file */
2107  if( gevInitEnvironmentLegacy(gev, "loadgms.tmp/gamscntr.dat") )
2108  {
2109  SCIPerrorMessage("Could not load control file loadgms.tmp/gamscntr.dat\n");
2110  goto TERMINATE;
2111  }
2112 
2113  /* tell GMO about GEV */
2114  if( gmoRegisterEnvironment(gmo, gev, buffer) )
2115  {
2116  SCIPerrorMessage("Error registering GAMS Environment: %s\n", buffer);
2117  goto TERMINATE;
2118  }
2119 
2120  /* load GAMS model instance into GMO */
2121  if( gmoLoadDataLegacy(gmo, buffer) )
2122  {
2123  SCIPerrorMessage("Could not load model data.\n");
2124  goto TERMINATE;
2125  }
2126 
2127  /* create SCIP problem out of GMO, using the magic from reader_gmo in interfaces/gams */
2128  SCIP_CALL( SCIPcreateProblemReaderGmo(scip, gmo, NULL, FALSE) );
2129  *result = SCIP_SUCCESS;
2130 
2131  ret = SCIP_OKAY;
2132 
2133 TERMINATE:
2134  if( gmo != NULL )
2135  gmoFree(&gmo);
2136  if( gev != NULL )
2137  gevFree(&gev);
2138 
2139  /* remove temporary directory content (should have only files and directory itself) */
2140  if( ret != SCIP_READERROR )
2141  system("rm loadgms.tmp/* && rmdir loadgms.tmp");
2142 
2143  return ret;
2144 }
2145 #endif
2146 
2147 /** problem writing method of reader */
2148 static
2149 SCIP_DECL_READERWRITE(readerWriteGms)
2150 { /*lint --e{715}*/
2151  SCIP_CALL( SCIPwriteGms(scip, file, name, transformed, objsense, objscale, objoffset, vars,
2152  nvars, nbinvars, nintvars, nimplvars, ncontvars, conss, nconss, result) );
2153 
2154  return SCIP_OKAY;
2155 }
2156 
2157 #ifdef WITH_GAMS
2158 /** destructor of reader to free user data (called when SCIP is exiting) */
2159 static
2160 SCIP_DECL_READERFREE(readerFreeGms)
2161 {
2162  if( gmoLibraryLoaded() )
2163  gmoLibraryUnload();
2164  if( gevLibraryLoaded() )
2165  gevLibraryUnload();
2166 
2167  return SCIP_OKAY;
2168 }
2169 #endif
2170 
2171 /*
2172  * reader specific interface methods
2173  */
2174 
2175 /** includes the gms file reader in SCIP */
2177  SCIP* scip /**< SCIP data structure */
2178  )
2179 {
2180  SCIP_READER* reader;
2181 
2182  /* include reader */
2184 
2185  /* set non fundamental callbacks via setter functions */
2186  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyGms) );
2187 #ifdef WITH_GAMS
2188  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadGms) );
2189  SCIP_CALL( SCIPsetReaderFree(scip, reader, readerFreeGms) );
2190 #endif
2191  SCIP_CALL( SCIPsetReaderWrite(scip, reader, readerWriteGms) );
2192 
2193  /* add gms reader parameters for writing routines*/
2195  "reading/gmsreader/freeints", "have integer variables no upper bound by default (depending on GAMS version)?",
2196  NULL, FALSE, FALSE, NULL, NULL) );
2197 
2199  "reading/gmsreader/replaceforbiddenchars", "shall characters '#', '*', '+', '/', and '-' in variable and constraint names be replaced by '_'?",
2200  NULL, FALSE, FALSE, NULL, NULL) );
2201 
2203  "reading/gmsreader/bigmdefault", "default M value for big-M reformulation of indicator constraints in case no bound on slack variable is given",
2205 
2207  "reading/gmsreader/indicatorreform", "which reformulation to use for indicator constraints: 'b'ig-M, 's'os1",
2209 
2211  "reading/gmsreader/signpower", "is it allowed to use the gams function signpower(x,a)?",
2213 
2214  return SCIP_OKAY;
2215 }
2216 
2217 
2218 /** writes problem to gms file */
2220  SCIP* scip, /**< SCIP data structure */
2221  FILE* file, /**< output file, or NULL if standard output should be used */
2222  const char* name, /**< problem name */
2223  SCIP_Bool transformed, /**< TRUE iff problem is the transformed problem */
2224  SCIP_OBJSENSE objsense, /**< objective sense */
2225  SCIP_Real objscale, /**< scalar applied to objective function; external objective value is
2226  * extobj = objsense * objscale * (intobj + objoffset) */
2227  SCIP_Real objoffset, /**< objective offset from bound shifting and fixing */
2228  SCIP_VAR** vars, /**< array with active variables ordered binary, integer, implicit, continuous */
2229  int nvars, /**< number of active variables in the problem */
2230  int nbinvars, /**< number of binary variables */
2231  int nintvars, /**< number of general integer variables */
2232  int nimplvars, /**< number of implicit integer variables */
2233  int ncontvars, /**< number of continuous variables */
2234  SCIP_CONS** conss, /**< array with constraints of the problem */
2235  int nconss, /**< number of constraints in the problem */
2236  SCIP_RESULT* result /**< pointer to store the result of the file writing call */
2237  )
2238 {
2239  int c;
2240  int v;
2241  int linecnt;
2242  char linebuffer[GMS_MAX_PRINTLEN];
2243 
2244  char varname[GMS_MAX_NAMELEN];
2245  char buffer[GMS_MAX_PRINTLEN];
2246 
2247  SCIP_Real* objcoeffs;
2248 
2249  SCIP_CONSHDLR* conshdlr;
2250  const char* conshdlrname;
2251  SCIP_CONS* cons;
2252 
2253  char consname[GMS_MAX_NAMELEN];
2254 
2255  SCIP_VAR** consvars;
2256  SCIP_Real* consvals;
2257  int nconsvars;
2258 
2259  SCIP_VAR* var;
2260  SCIP_VAR* objvar;
2261  SCIP_Real lb;
2262  SCIP_Real ub;
2263  SCIP_Bool freeints;
2264  SCIP_Bool nondefbounds;
2265  SCIP_Bool nlcons;
2266  SCIP_Bool nqcons;
2267  SCIP_Bool nsmooth;
2268  SCIP_Bool discrete;
2269  SCIP_Bool rangedrow;
2270  SCIP_Bool indicatorsosdef;
2271  SCIP_Bool signpowerallowed;
2272  SCIP_Bool needcomma;
2273 
2274  assert( scip != NULL );
2275  assert( vars != NULL || nvars == 0 );
2276 
2277  /* check if the variable names are not too long */
2278  SCIP_CALL( checkVarnames(scip, vars, nvars) );
2279  /* check if the constraint names are too long */
2280  SCIP_CALL( checkConsnames(scip, conss, nconss, transformed) );
2281 
2282  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/signpower", &signpowerallowed) );
2283 
2284  /* check if the objective is a single continuous variable, so we would not have to introduce an auxiliary variable
2285  * for GAMS
2286  */
2287  objvar = NULL;
2288  if( objscale == 1.0 && objoffset == 0.0 )
2289  {
2290  for( v = 0; v < nvars; ++v )
2291  {
2292  if( SCIPvarGetObj(vars[v]) == 0.0 ) /*lint !e613*/
2293  continue;
2294 
2295  if( objvar == NULL )
2296  {
2297  /* first variable with nonzero obj coefficient
2298  * if not active or having coefficient != 1.0, or being binary/integer, then give up
2299  */
2300  if( !SCIPvarIsActive(vars[v]) || SCIPvarGetObj(vars[v]) != 1.0 ||
2301  SCIPvarGetType(vars[v]) < SCIP_VARTYPE_IMPLINT ) /*lint !e613*/
2302  break;
2303 
2304  objvar = vars[v]; /*lint !e613*/
2305  }
2306  else
2307  {
2308  /* second variable with nonzero obj coefficient -> give up */
2309  objvar = NULL;
2310  break;
2311  }
2312  }
2313  }
2314 
2315  /* print statistics as comment to file */
2316  SCIPinfoMessage(scip, file, "$OFFLISTING\n");
2317  SCIPinfoMessage(scip, file, "* SCIP STATISTICS\n");
2318  SCIPinfoMessage(scip, file, "* Problem name : %s\n", name);
2319  SCIPinfoMessage(scip, file, "* Variables : %d (%d binary, %d integer, %d implicit integer, %d continuous)\n",
2320  nvars, nbinvars, nintvars, nimplvars, ncontvars);
2321  SCIPinfoMessage(scip, file, "* Constraints : %d\n\n", nconss);
2322 
2323  /* print flags */
2324  SCIPinfoMessage(scip, file, "$MAXCOL %d\n", GMS_MAX_LINELEN - 1);
2325  SCIPinfoMessage(scip, file, "$OFFDIGIT\n\n");
2326 
2327  /* print variable section */
2328  SCIPinfoMessage(scip, file, "Variables\n");
2329  clearLine(linebuffer, &linecnt);
2330 
2331  if( objvar == NULL )
2332  {
2333  /* auxiliary objective variable */
2334  SCIPinfoMessage(scip, file, " objvar%c", nvars > 0 ? ',' : ';');
2335  }
2336 
2337  /* "model" variables */
2338  for( v = 0; v < nvars; ++v )
2339  {
2340  var = vars[v]; /*lint !e613*/
2341  assert( var != NULL );
2342 
2343  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2344  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%c", varname, (v < nvars - 1) ? ',' : ';');
2345  appendLine(scip, file, linebuffer, &linecnt, buffer);
2346 
2347  if( (linecnt > 0 && (v == nbinvars - 1 || v == nbinvars + nintvars - 1 ||
2348  v == nbinvars + nintvars + nimplvars - 1)) || v == nvars - 1 )
2349  {
2350  endLine(scip, file, linebuffer, &linecnt);
2351  clearLine(linebuffer, &linecnt);
2352  }
2353  }
2354 
2355  SCIPinfoMessage(scip, file, "\n");
2356 
2357  /* declare binary variables if present */
2358  if( nbinvars > 0 )
2359  {
2360  SCIPinfoMessage(scip, file, "Binary variables\n");
2361  clearLine(linebuffer, &linecnt);
2362 
2363  for( v = 0; v < nbinvars; ++v )
2364  {
2365  var = vars[v]; /*lint !e613*/
2366 
2367  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2368  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%s", varname, (v < nbinvars - 1) ? "," : ";");
2369 
2370  appendLine(scip, file, linebuffer, &linecnt, buffer);
2371  }
2372 
2373  endLine(scip, file, linebuffer, &linecnt);
2374  SCIPinfoMessage(scip, file, "\n");
2375  }
2376 
2377  /* declare integer variables if present */
2378  if( nintvars > 0 )
2379  {
2380  SCIPinfoMessage(scip, file, "Integer variables\n");
2381  clearLine(linebuffer, &linecnt);
2382 
2383  for( v = 0; v < nintvars; ++v )
2384  {
2385  var = vars[nbinvars + v]; /*lint !e613*/
2386 
2387  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2388  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%s", varname, (v < nintvars - 1) ? "," : ";");
2389 
2390  appendLine(scip, file, linebuffer, &linecnt, buffer);
2391  }
2392  endLine(scip, file, linebuffer, &linecnt);
2393  SCIPinfoMessage(scip, file, "\n");
2394  }
2395 
2396  /* print variable bounds */
2397  SCIPinfoMessage(scip, file, "* Variable bounds\n");
2398  SCIP_CALL( SCIPgetBoolParam(scip, "reading/gmsreader/freeints", &freeints) );
2399  nondefbounds = FALSE;
2400 
2401  for( v = 0; v < nvars; ++v )
2402  {
2403  var = vars[v]; /*lint !e613*/
2404  assert( var != NULL );
2405 
2406  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(var)) );
2407 
2408  if( transformed )
2409  {
2410  /* in case the transformed is written only local bounds are posted which are valid in the current node */
2411  lb = SCIPvarGetLbLocal(var);
2412  ub = SCIPvarGetUbLocal(var);
2413  }
2414  else
2415  {
2416  lb = SCIPvarGetLbOriginal(var);
2417  ub = SCIPvarGetUbOriginal(var);
2418  }
2419  assert( lb <= ub );
2420 
2421  /* fixed */
2422  if( SCIPisEQ(scip, lb, ub) )
2423  {
2424  if( v < nintvars )
2425  SCIPinfoMessage(scip, file, " %s.fx = %g;\n", varname, SCIPfloor(scip, lb + 0.5));
2426  else
2427  SCIPinfoMessage(scip, file, " %s.fx = %.15g;\n", varname, lb);
2428  nondefbounds = TRUE;
2429 
2430  /* no need to write lower and upper bounds additionally */
2431  continue;
2432  }
2433 
2434  /* lower bound */
2435  if( v < nbinvars + nintvars )
2436  {
2437  /* default lower bound of binaries and integers is 0 (also in recent gams versions if pf4=0 is given) */
2438  if( !SCIPisZero(scip, lb) )
2439  {
2440  if( !SCIPisInfinity(scip, -lb) )
2441  SCIPinfoMessage(scip, file, " %s.lo = %g;\n", varname, SCIPceil(scip, lb));
2442  else if( freeints )
2443  SCIPinfoMessage(scip, file, " %s.lo = -inf;\n", varname); /* -inf is allowed when running gams with pf4=0, which we assume if freeints is TRUE */
2444  else
2445  SCIPinfoMessage(scip, file, " %s.lo = %g;\n", varname, -SCIPinfinity(scip)); /* sorry, -inf not allowed in gams file here */
2446  nondefbounds = TRUE;
2447  }
2448  }
2449  else if( v >= nbinvars + nintvars && !SCIPisInfinity(scip, -lb) )
2450  {
2451  /* continuous variables are free by default */
2452  SCIPinfoMessage(scip, file, " %s.lo = %.15g;\n", varname, lb);
2453  nondefbounds = TRUE;
2454  }
2455 
2456  /* upper bound */
2457  if( v < nbinvars )
2458  {
2459  if( !SCIPisFeasEQ(scip, ub, 1.0) )
2460  {
2461  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPfeasFloor(scip, ub));
2462  nondefbounds = TRUE;
2463  }
2464  }
2465  else if( v < nbinvars + nintvars && !freeints )
2466  {
2467  /* freeints == FALSE: integer variables have upper bound 100 by default */
2468  if( !SCIPisFeasEQ(scip, ub, 100.0) )
2469  {
2470  if( !SCIPisInfinity(scip, ub) )
2471  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPfeasFloor(scip, ub));
2472  else
2473  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPinfinity(scip)); /* sorry, +inf not allowed in gams file here (unless pf4=0) */
2474  nondefbounds = TRUE;
2475  }
2476  }
2477  else if( v < nbinvars + nintvars && !SCIPisInfinity(scip, ub) )
2478  {
2479  /* freeints == TRUE: integer variables have no upper bound by default */
2480  SCIPinfoMessage(scip, file, " %s.up = %g;\n", varname, SCIPfloor(scip, ub));
2481  nondefbounds = TRUE;
2482  }
2483  else if( v >= nbinvars + nintvars && !SCIPisInfinity(scip, ub) )
2484  {
2485  /* continuous variables are free by default */
2486  SCIPinfoMessage(scip, file, " %s.up = %.15g;\n", varname, ub);
2487  nondefbounds = TRUE;
2488  }
2489  }
2490 
2491  if( !nondefbounds )
2492  SCIPinfoMessage(scip, file, "* (All other bounds at default value: binary [0,1], integer [%s], continuous [-inf,+inf].)\n", freeints ? "0,+inf" : "0,100");
2493  SCIPinfoMessage(scip, file, "\n");
2494 
2495  /* print equations section */
2496  if( nconss > 0 || objvar == NULL )
2497  {
2498  SCIPinfoMessage(scip, file, "Equations\n");
2499  clearLine(linebuffer, &linecnt);
2500  }
2501  needcomma = FALSE;
2502 
2503  if( objvar == NULL )
2504  {
2505  SCIPinfoMessage(scip, file, " objequ");
2506  needcomma = TRUE;
2507  }
2508 
2509  /* declare equations */
2510  for( c = 0; c < nconss; ++c )
2511  {
2512  cons = conss[c];
2513  assert( cons != NULL );
2514 
2515  conshdlr = SCIPconsGetHdlr(cons);
2516  assert( conshdlr != NULL );
2517 
2518  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, SCIPconsGetName(cons)) );
2519  conshdlrname = SCIPconshdlrGetName(conshdlr);
2520  assert( transformed == SCIPconsIsTransformed(cons) );
2521 
2522  rangedrow = strcmp(conshdlrname, "linear") == 0
2523  && !SCIPisInfinity(scip, -SCIPgetLhsLinear(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsLinear(scip, cons))
2524  && !SCIPisEQ(scip, SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons));
2525  rangedrow = rangedrow || (strcmp(conshdlrname, "quadratic") == 0
2526  && !SCIPisInfinity(scip, -SCIPgetLhsQuadratic(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsQuadratic(scip, cons))
2527  && !SCIPisEQ(scip, SCIPgetLhsQuadratic(scip, cons), SCIPgetRhsQuadratic(scip, cons)));
2528  rangedrow = rangedrow || (strcmp(conshdlrname, "nonlinear") == 0
2529  && !SCIPisInfinity(scip, -SCIPgetLhsNonlinear(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsNonlinear(scip, cons))
2530  && !SCIPisEQ(scip, SCIPgetLhsNonlinear(scip, cons), SCIPgetRhsNonlinear(scip, cons)));
2531  rangedrow = rangedrow || (strcmp(conshdlrname, "abspower") == 0
2532  && !SCIPisInfinity(scip, -SCIPgetLhsAbspower(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsAbspower(scip, cons))
2533  && !SCIPisEQ(scip, SCIPgetLhsAbspower(scip, cons), SCIPgetRhsAbspower(scip, cons)));
2534  rangedrow = rangedrow || (strcmp(conshdlrname, "bivariate") == 0
2535  && !SCIPisInfinity(scip, -SCIPgetLhsBivariate(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsBivariate(scip, cons))
2536  && !SCIPisEQ(scip, SCIPgetLhsBivariate(scip, cons), SCIPgetRhsBivariate(scip, cons)));
2537  rangedrow = rangedrow || (strcmp(conshdlrname, "varbound") == 0
2538  && !SCIPisInfinity(scip, -SCIPgetLhsVarbound(scip, cons)) && !SCIPisInfinity(scip, SCIPgetRhsVarbound(scip, cons))
2539  && !SCIPisEQ(scip, SCIPgetLhsVarbound(scip, cons), SCIPgetRhsVarbound(scip, cons)));
2540 
2541  /* we declare only those constraints which we can print in GAMS format */
2542  if( strcmp(conshdlrname, "knapsack") != 0 && strcmp(conshdlrname, "logicor") != 0 && strcmp(conshdlrname, "setppc") != 0
2543  && strcmp(conshdlrname, "linear") != 0 && strcmp(conshdlrname, "quadratic") != 0 && strcmp(conshdlrname, "varbound") != 0
2544  && strcmp(conshdlrname, "soc") != 0 && strcmp(conshdlrname, "abspower") != 0 && strcmp(conshdlrname, "bivariate") != 0
2545  && strcmp(conshdlrname, "nonlinear") != 0 && strcmp(conshdlrname, "SOS1") != 0 && strcmp(conshdlrname, "SOS2") != 0
2546  && strcmp(conshdlrname, "indicator") != 0 )
2547  {
2548  SCIPwarningMessage(scip, "Constraint type <%s> not supported. Skip writing constraint <%s>.\n", conshdlrname, SCIPconsGetName(cons));
2549  continue;
2550  }
2551 
2552  if( needcomma )
2553  appendLine(scip, file, linebuffer, &linecnt, ",");
2554 
2555  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, SCIPconsGetName(cons)) );
2556  if( rangedrow )
2557  {
2558  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s%s%s%s", consname, "_lhs, ", consname, "_rhs");
2559  appendLine(scip, file, linebuffer, &linecnt, buffer);
2560  }
2561  else
2562  {
2563  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " %s", consname);
2564  appendLine(scip, file, linebuffer, &linecnt, buffer);
2565  }
2566  needcomma = TRUE;
2567  }
2568 
2569  if( nconss > 0 || objvar == NULL )
2570  {
2571  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, ";");
2572  appendLine(scip, file, linebuffer, &linecnt, buffer);
2573 
2574  endLine(scip, file, linebuffer, &linecnt);
2575  SCIPinfoMessage(scip, file, "\n");
2576  }
2577 
2578  if( objvar == NULL )
2579  {
2580  /* print objective function equation */
2581  clearLine(linebuffer, &linecnt);
2582  if( objoffset != 0.0 )
2583  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " objequ .. objvar =e= %.15g + ", objscale * objoffset);
2584  else
2585  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, " objequ .. objvar =e= ");
2586  appendLine(scip, file, linebuffer, &linecnt, buffer);
2587 
2588  SCIP_CALL( SCIPallocBufferArray(scip, &objcoeffs, nvars) );
2589 
2590  for( v = 0; v < nvars; ++v )
2591  {
2592  var = vars[v]; /*lint !e613*/
2593  assert( var != NULL );
2594 
2595  /* in case the original problem has to be posted the variables have to be either "original" or "negated" */
2596  assert( transformed || SCIPvarGetStatus(var) == SCIP_VARSTATUS_ORIGINAL || SCIPvarGetStatus(var) == SCIP_VARSTATUS_NEGATED );
2597 
2598  objcoeffs[v] = SCIPisZero(scip, SCIPvarGetObj(var)) ? 0.0 : objscale * SCIPvarGetObj(var);
2599  }
2600 
2601  SCIP_CALL( printActiveVariables(scip, file, linebuffer, &linecnt, "", ";", nvars, vars, objcoeffs, transformed) );
2602 
2603  SCIPfreeBufferArray(scip, &objcoeffs);
2604  endLine(scip, file, linebuffer, &linecnt);
2605  SCIPinfoMessage(scip, file, "\n");
2606  }
2607 
2608  /* print constraints */
2609  nlcons = FALSE;
2610  nqcons = FALSE;
2611  nsmooth = FALSE;
2612  discrete = nbinvars > 0 || nintvars > 0;
2613  indicatorsosdef = FALSE;
2614  for( c = 0; c < nconss; ++c )
2615  {
2616  cons = conss[c];
2617  assert( cons != NULL );
2618 
2619  /* in case the transformed is written, only constraints are posted which are enabled in the current node */
2620  assert(!transformed || SCIPconsIsEnabled(cons));
2621 
2622  conshdlr = SCIPconsGetHdlr(cons);
2623  assert( conshdlr != NULL );
2624 
2625  SCIP_CALL( printConformName(scip, consname, GMS_MAX_NAMELEN, SCIPconsGetName(cons)) );
2626  conshdlrname = SCIPconshdlrGetName(conshdlr);
2627  assert( transformed == SCIPconsIsTransformed(cons) );
2628 
2629  if( strcmp(conshdlrname, "knapsack") == 0 )
2630  {
2631  SCIP_Longint* weights;
2632 
2633  consvars = SCIPgetVarsKnapsack(scip, cons);
2634  nconsvars = SCIPgetNVarsKnapsack(scip, cons);
2635 
2636  /* copy Longint array to SCIP_Real array */
2637  weights = SCIPgetWeightsKnapsack(scip, cons);
2638  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, nconsvars) );
2639  for( v = 0; v < nconsvars; ++v )
2640  consvals[v] = (SCIP_Real)weights[v];
2641 
2642  SCIP_CALL( printLinearCons(scip, file, consname, nconsvars, consvars, consvals,
2643  -SCIPinfinity(scip), (SCIP_Real) SCIPgetCapacityKnapsack(scip, cons), transformed) );
2644 
2645  SCIPfreeBufferArray(scip, &consvals);
2646  }
2647  else if( strcmp(conshdlrname, "linear") == 0 )
2648  {
2649  SCIP_CALL( printLinearCons(scip, file, consname,
2650  SCIPgetNVarsLinear(scip, cons), SCIPgetVarsLinear(scip, cons), SCIPgetValsLinear(scip, cons),
2651  SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons), transformed) );
2652  }
2653  else if( strcmp(conshdlrname, "logicor") == 0 )
2654  {
2655  SCIP_CALL( printLinearCons(scip, file, consname,
2656  SCIPgetNVarsLogicor(scip, cons), SCIPgetVarsLogicor(scip, cons), NULL,
2657  1.0, SCIPinfinity(scip), transformed) );
2658  }
2659  else if( strcmp(conshdlrname, "quadratic") == 0 )
2660  {
2661  SCIP_CALL( printQuadraticCons(scip, file, consname,
2665  SCIPgetLhsQuadratic(scip, cons), SCIPgetRhsQuadratic(scip, cons), transformed) );
2666 
2667  nlcons = TRUE;
2668  }
2669  else if( strcmp(conshdlrname, "nonlinear") == 0 )
2670  {
2671  /* cons_nonlinear does not have exprtree's at hand during presolve */
2673  && SCIPgetExprgraphNonlinear(scip,conshdlr) != NULL )
2674  {
2675  SCIP_EXPRTREE* exprtree;
2676  SCIP_Real coef;
2677 
2679  coef = 1.0;
2680  SCIP_CALL( printNonlinearCons(scip, file, consname,
2682  1, &exprtree, &coef,
2683  SCIPgetLhsNonlinear(scip, cons), SCIPgetRhsNonlinear(scip, cons), transformed, &nsmooth) );
2684 
2685  SCIP_CALL( SCIPexprtreeFree(&exprtree) );
2686  }
2687  else
2688  {
2689  SCIP_CALL( printNonlinearCons(scip, file, consname,
2692  SCIPgetLhsNonlinear(scip, cons), SCIPgetRhsNonlinear(scip, cons), transformed, &nsmooth) );
2693  }
2694  nlcons = TRUE;
2695  nqcons = TRUE;
2696  }
2697  else if( strcmp(conshdlrname, "bivariate") == 0 )
2698  {
2699  SCIP_EXPRTREE* exprtree;
2700  SCIP_VAR* linvar;
2701  SCIP_Real lincoef;
2702  int exprdegree;
2703  SCIP_Real one;
2704 
2705  exprtree = SCIPgetExprtreeBivariate(scip, cons);
2706  assert(exprtree != NULL);
2707 
2708  linvar = SCIPgetLinearVarBivariate(scip, cons);
2709  lincoef = SCIPgetLinearCoefBivariate(scip, cons);
2710  one = 1.0;
2711  SCIP_CALL( printNonlinearCons(scip, file, consname,
2712  linvar == NULL ? 0 : 1, &linvar, &lincoef,
2713  1, &exprtree, &one,
2714  SCIPgetLhsBivariate(scip, cons), SCIPgetRhsBivariate(scip, cons), transformed, &nsmooth) );
2715 
2716  SCIP_CALL( SCIPexprtreeGetMaxDegree(exprtree, &exprdegree) );
2717  if( exprdegree > 1 )
2718  nlcons = TRUE;
2719  if( exprdegree > 2)
2720  nqcons = TRUE;
2721  }
2722  else if( strcmp(conshdlrname, "setppc") == 0 )
2723  {
2724  consvars = SCIPgetVarsSetppc(scip, cons);
2725  nconsvars = SCIPgetNVarsSetppc(scip, cons);
2726 
2727  switch( SCIPgetTypeSetppc(scip, cons) )
2728  {
2730  SCIP_CALL( printLinearCons(scip, file, consname,
2731  nconsvars, consvars, NULL, 1.0, 1.0, transformed) );
2732  break;
2734  SCIP_CALL( printLinearCons(scip, file, consname,
2735  nconsvars, consvars, NULL, -SCIPinfinity(scip), 1.0, transformed) );
2736  break;
2738  SCIP_CALL( printLinearCons(scip, file, consname,
2739  nconsvars, consvars, NULL, 1.0, SCIPinfinity(scip), transformed) );
2740  break;
2741  }
2742  }
2743  else if( strcmp(conshdlrname, "varbound") == 0 )
2744  {
2745  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) );
2746  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) );
2747 
2748  consvars[0] = SCIPgetVarVarbound(scip, cons);
2749  consvars[1] = SCIPgetVbdvarVarbound(scip, cons);
2750 
2751  consvals[0] = 1.0;
2752  consvals[1] = SCIPgetVbdcoefVarbound(scip, cons);
2753 
2754  SCIP_CALL( printLinearCons(scip, file, consname,
2755  2, consvars, consvals,
2756  SCIPgetLhsVarbound(scip, cons), SCIPgetRhsVarbound(scip, cons), transformed) );
2757 
2758  SCIPfreeBufferArray(scip, &consvars);
2759  SCIPfreeBufferArray(scip, &consvals);
2760  }
2761  else if( strcmp(conshdlrname, "soc") == 0 )
2762  {
2763  SCIP_CALL( printSOCCons(scip, file, consname,
2764  SCIPgetNLhsVarsSOC(scip, cons), SCIPgetLhsVarsSOC(scip, cons), SCIPgetLhsCoefsSOC(scip, cons), SCIPgetLhsOffsetsSOC(scip, cons), SCIPgetLhsConstantSOC(scip, cons),
2765  SCIPgetRhsVarSOC(scip, cons), SCIPgetRhsCoefSOC(scip, cons), SCIPgetRhsOffsetSOC(scip, cons), transformed) );
2766 
2767  nlcons = nlcons || !isGAMSprintableSOC(SCIPgetNLhsVarsSOC(scip, cons), SCIPgetLhsVarsSOC(scip, cons), SCIPgetLhsCoefsSOC(scip, cons), SCIPgetLhsOffsetsSOC(scip, cons), SCIPgetLhsConstantSOC(scip, cons),
2768  SCIPgetRhsVarSOC(scip, cons), SCIPgetRhsCoefSOC(scip, cons), SCIPgetRhsOffsetSOC(scip, cons));
2769  }
2770  else if( strcmp(conshdlrname, "indicator") == 0 )
2771  {
2772  SCIP_CALL( printIndicatorCons(scip, file, consname,
2773  SCIPgetBinaryVarIndicator(cons), SCIPgetSlackVarIndicator(cons), &indicatorsosdef,
2774  transformed) );
2775  }
2776  else if( strcmp(conshdlrname, "abspower") == 0 )
2777  {
2778  SCIP_CALL( printSignpowerCons(scip, file, consname,
2779  SCIPgetNonlinearVarAbspower(scip, cons), SCIPgetLinearVarAbspower(scip, cons),
2780  SCIPgetExponentAbspower(scip, cons), SCIPgetOffsetAbspower(scip, cons), SCIPgetCoefLinearAbspower(scip, cons),
2781  SCIPgetLhsAbspower(scip, cons), SCIPgetRhsAbspower(scip, cons), transformed, signpowerallowed, &nsmooth) );
2782 
2783  nlcons = TRUE;
2784  nqcons = TRUE;
2785  }
2786  else if( strcmp(conshdlrname, "SOS1") == 0 )
2787  {
2788  SCIP_CALL( printSOSCons(scip, file, consname,
2789  SCIPgetNVarsSOS1(scip, cons), SCIPgetVarsSOS1(scip, cons), 1,
2790  transformed) );
2791  discrete = TRUE;
2792  }
2793  else if( strcmp(conshdlrname, "SOS2") == 0 )
2794  {
2795  SCIP_CALL( printSOSCons(scip, file, consname,
2796  SCIPgetNVarsSOS2(scip, cons), SCIPgetVarsSOS2(scip, cons), 2,
2797  transformed) );
2798  discrete = TRUE;
2799  }
2800  else
2801  {
2802  SCIPwarningMessage(scip, "constraint handler <%s> cannot print requested format\n", conshdlrname );
2803  SCIPinfoMessage(scip, file, "* ");
2804  SCIP_CALL( SCIPprintCons(scip, cons, file) );
2805  SCIPinfoMessage(scip, file, ";\n");
2806  }
2807 
2808  SCIPinfoMessage(scip, file, "\n");
2809  }
2810  /* if at most quadratic, then cannot have nonsmooth functions */
2811  assert(nlcons || !nsmooth);
2812 
2813  /* print model creation */
2814  SCIPinfoMessage(scip, file, "Model m / all /;\n\n");
2815 
2816  /* set some options to reduce listing file size */
2817  SCIPinfoMessage(scip, file, "option limrow = 0;\n");
2818  SCIPinfoMessage(scip, file, "option limcol = 0;\n\n");
2819 
2820  /* print solve command */
2821  (void) SCIPsnprintf(buffer, GMS_MAX_PRINTLEN, "%s%s",
2822  discrete ? "MI" : "", nlcons ? (nqcons ? ((nsmooth && !discrete) ? "DNLP" : "NLP") : "QCP") : (discrete > 0 ? "P" : "LP"));
2823 
2824  if( objvar != NULL )
2825  {
2826  SCIP_CALL( printConformName(scip, varname, GMS_MAX_NAMELEN, SCIPvarGetName(objvar)) );
2827  }
2828 
2829  SCIPinfoMessage(scip, file, "$if not set %s $set %s %s\n", buffer, buffer, buffer);
2830  SCIPinfoMessage(scip, file, "Solve m using %%%s%% %simizing %s;\n",
2831  buffer, objsense == SCIP_OBJSENSE_MINIMIZE ? "min" : "max", objvar != NULL ? varname : "objvar");
2832 
2833  *result = SCIP_SUCCESS;
2834 
2835  return SCIP_OKAY;
2836 }
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:4480
SCIP_VAR ** SCIPgetLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5398
#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:2149
SCIP_Bool SCIPconsIsEnabled(SCIP_CONS *cons)
Definition: cons.c:7978
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:1752
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:46320
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip.c:814
int * SCIPexprGetMonomialChildIndices(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5897
Constraint handler for variable bound constraints .
SCIP_VAR ** SCIPgetVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10557
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:9172
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:5670
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17169
int SCIPgetNVarsLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPgetRealParam(SCIP *scip, const char *name, SCIP_Real *value)
Definition: scip.c:4461
#define SCIP_MAXSTRLEN
Definition: def.h:225
SCIP_VAR * var1
SCIP_VAR * SCIPgetLinearVarAbspower(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * SCIPgetLhsOffsetsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5424
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:46110
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17225
SCIP_RETCODE SCIPexprtreeGetMaxDegree(SCIP_EXPRTREE *tree, int *maxdegree)
Definition: expr.c:8657
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:16735
constraint handler for indicator constraints
SCIP_Real SCIPexprGetRealPowerExponent(SCIP_EXPR *expr)
Definition: expr.c:5733
int SCIPexprGetOpIndex(SCIP_EXPR *expr)
Definition: expr.c:5700
SCIP_Real SCIPexprGetPolynomialConstant(SCIP_EXPR *expr)
Definition: expr.c:5865
#define FALSE
Definition: def.h:64
SCIP_Real * SCIPgetLinearCoefsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:46050
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
Definition: scip.c:1377
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:9340
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
Definition: scip.c:46122
#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:8190
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:2219
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:21999
int SCIPgetNVarsSOS2(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos2.c:2441
SCIP_EXPRTREE ** SCIPgetExprtreesNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:45985
constraint handler for second order cone constraints
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:22003
Constraint handler for the set partitioning / packing / covering constraints .
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1260
#define SCIPdebugMsg
Definition: scip.h:451
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:1336
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:1881
int SCIPgetNExprtreesNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_EXPRDATA_MONOMIAL ** SCIPexprGetMonomials(SCIP_EXPR *expr)
Definition: expr.c:5841
int SCIPgetNQuadVarTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:46445
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:5887
int SCIPexprGetIntPowerExponent(SCIP_EXPR *expr)
Definition: expr.c:5744
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:17179
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:1940
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:2176
SCIP_Real SCIPvarGetLbOriginal(SCIP_VAR *var)
Definition: var.c:17115
SCIP_Real * SCIPexprGetQuadLinearCoefs(SCIP_EXPR *expr)
Definition: expr.c:5817
SCIP_Real SCIPgetRhsVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsSOS2(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos2.c:2466
Constraint handler for logicor constraints (equivalent to set covering, but algorithms are suited fo...
SCIP_Real SCIPvarGetUbOriginal(SCIP_VAR *var)
Definition: var.c:17135
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:7881
SCIP_VAR ** SCIPgetVarsLogicor(SCIP *scip, SCIP_CONS *cons)
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16555
SCIP_Real SCIPexprGetQuadConstant(SCIP_EXPR *expr)
Definition: expr.c:5804
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:2033
constraint handler for quadratic constraints
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
Definition: scip.c:4404
SCIP_Real * SCIPgetExprtreeCoefsNonlinear(SCIP *scip, SCIP_CONS *cons)
#define NULL
Definition: lpi_spx1.cpp:137
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:316
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:18950
#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:1832
SCIP_BILINTERM * SCIPgetBilinTermsQuadratic(SCIP *scip, SCIP_CONS *cons)
SCIP_EXPR * SCIPexprtreeGetRoot(SCIP_EXPRTREE *tree)
Definition: expr.c:8549
SCIP_Real SCIPgetRhsOffsetSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5476
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:21991
public data structures and miscellaneous methods
SCIP_EXPR ** SCIPexprGetChildren(SCIP_EXPR *expr)
Definition: expr.c:5690
SCIP_Real SCIPexprGetSignPowerExponent(SCIP_EXPR *expr)
Definition: expr.c:5755
#define SCIP_Bool
Definition: def.h:61
int SCIPgetNLhsVarsSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5385
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Definition: scip.c:5236
#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:5450
SCIP_Real SCIPgetLhsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_SETPPCTYPE SCIPgetTypeSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9214
constraint handler for nonlinear constraints
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
Definition: scip.c:28746
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:7901
int SCIPexprGetNChildren(SCIP_EXPR *expr)
Definition: expr.c:5680
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:17017
SCIP_RETCODE SCIPexprtreeFree(SCIP_EXPRTREE **tree)
Definition: expr.c:8799
int SCIPgetNVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10532
SCIP_RETCODE SCIPsetReaderWrite(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERWRITE((*readerwrite)))
Definition: scip.c:5346
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:46061
SCIP_Real SCIPexprGetMonomialCoef(SCIP_EXPRDATA_MONOMIAL *monomial)
Definition: expr.c:5877
Constraint handler for absolute power constraints .
SCIP_RETCODE SCIPvarGetOrigvarSum(SCIP_VAR **var, SCIP_Real *scalar, SCIP_Real *constant)
Definition: var.c:12080
SCIP_VAR * SCIPgetBinaryVarIndicator(SCIP_CONS *cons)
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
Definition: scip.c:5274
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:9193
SCIP_VAR * SCIPgetLinearVarBivariate(SCIP *scip, SCIP_CONS *cons)
#define SCIP_REAL_MAX
Definition: def.h:146
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:46134
SCIP_Real * SCIPexprGetLinearCoefs(SCIP_EXPR *expr)
Definition: expr.c:5766
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:4321
int SCIPgetNLinearVarsNonlinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetRhsAbspower(SCIP *scip, SCIP_CONS *cons)
static const SCIP_Real scalars[]
Definition: lp.c:5573
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPexprGetOpReal(SCIP_EXPR *expr)
Definition: expr.c:5711
#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:5792
SCIP_Real SCIPgetLhsConstantSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5437
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:5853
SCIP_Real SCIPgetRhsCoefSOC(SCIP *scip, SCIP_CONS *cons)
Definition: cons_soc.c:5463
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:16674
SCIP_RETCODE SCIPexprgraphGetTree(SCIP_EXPRGRAPH *exprgraph, SCIP_EXPRGRAPHNODE *rootnode, SCIP_EXPRTREE **exprtree)
Definition: expr.c:16146
#define SCIP_Real
Definition: def.h:145
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:5907
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
Definition: scip.c:5322
#define SCIP_Longint
Definition: def.h:130
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16720
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:46098
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:17235
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:46183
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:5779
SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
Definition: scip.c:46195
int SCIPexprGetNQuadElements(SCIP_EXPR *expr)
Definition: expr.c:5829
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:5411
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:4293
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:46171
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
Definition: scip.c:5298
SCIP_RETCODE SCIPgetNegatedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **negvar)
Definition: scip.c:18740
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:4211
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:16842
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
Definition: var.c:16710
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:21995