Scippy

SCIP

Solving Constraint Integer Programs

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