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