Scippy

SCIP

Solving Constraint Integer Programs

reader_zpl.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-2016 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_zpl.c
17  * @brief ZIMPL model file reader
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  */
21 
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23 
24 #include "scip/reader_zpl.h"
25 
26 #ifdef WITH_ZIMPL
27 
28 #include <assert.h>
29 #include <unistd.h>
30 #include <string.h>
31 
32 #include "scip/cons_linear.h"
33 #include "scip/cons_sos1.h"
34 #include "scip/cons_sos2.h"
35 #include "scip/cons_indicator.h"
36 #include "scip/cons_quadratic.h"
37 #include "scip/cons_nonlinear.h"
38 #include "scip/pub_misc.h"
39 
40 /* @Note: Due to dependencies we need the following order. */
41 /* include the ZIMPL headers necessary to define the LP and MINLP construction interface */
42 #include "zimpl/bool.h"
43 #include "zimpl/ratlptypes.h"
44 #include "zimpl/mme.h"
45 
46 #include "zimpl/numb.h"
47 #include "zimpl/bound.h"
48 #include "zimpl/mono.h"
49 #include "zimpl/term.h"
50 
51 #include "zimpl/xlpglue.h"
52 #include "zimpl/zimpllib.h"
53 
54 #define READER_NAME "zplreader"
55 #define READER_DESC "file reader for ZIMPL model files"
56 #define READER_EXTENSION "zpl"
57 
58 /*
59  * LP construction interface of ZIMPL
60  */
61 
62 /* we only support ZIMPL with a version higher than 3.2.0 */
63 #if (ZIMPL_VERSION >= 320)
64 
65 /* ZIMPL does not support user data in callbacks - we have to use static variables */
66 struct
67 SCIP_ReaderData
68 {
69  SCIP* scip; /**< scip data structure */
70  SCIP_SOL* sol; /**< primal solution candidate */
71  SCIP_Bool valid; /**< is the primal solution candidate valid */
72  SCIP_Bool branchpriowarning; /**< store if the waring regarding fractional value for the branching
73  * priority was already posted */
74  SCIP_Bool initialconss; /**< should model constraints be marked as initial? */
75  SCIP_Bool dynamicconss; /**< should model constraints be subject to aging? */
76  SCIP_Bool dynamiccols; /**< should columns be added and removed dynamically to the LP? */
77  SCIP_Bool dynamicrows; /**< should rows be added and removed dynamically to the LP? */
78  SCIP_Bool readerror; /**< was a reading error be discovered */
79  SCIP_RETCODE retcode; /**< store a none SCIP_OKAY return code if an error occurred */
80 };
81 
82 /** create problem */
83 static
84 SCIP_RETCODE createProb(
85  SCIP* scip, /**< SCIP data structure */
86  SCIP_READERDATA* readerdata, /**< reader data */
87  const char* name /**< name of the problem */
88  )
89 {
90  SCIP_Bool usestartsol;
91 
92  /* create problem */
93  SCIP_CALL( SCIPcreateProb(scip, name, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
94 
95  /* check if are interested in the primal solution candidate */
96  SCIP_CALL( SCIPgetBoolParam(scip, "reading/zplreader/usestartsol", &usestartsol) );
97 
98  if( usestartsol )
99  {
100  /* create primal solution */
101  SCIP_CALL( SCIPcreateSol(scip, &readerdata->sol, NULL) );
102  readerdata->valid = TRUE;
103  }
104 
105  return SCIP_OKAY;
106 }
107 
108 /** Allocate storage for the mathematical program instance generated by ZIMPL. xlp_alloc() is the first xlpglue routine
109  * that will be called by ZIMPL. The user_data pointer may hold an arbitray value.
110  */
111 Lps* xlp_alloc(
112  const char* name, /**< name of the problem */
113  Bool need_startval, /**< does ZIMPL provides a primal solution candidate */
114  void* user_data /**< user data which was previously passed to ZIMPL */
115  )
116 { /*lint --e{715}*/
117  SCIP* scip;
118  SCIP_READERDATA* readerdata;
119 
120  readerdata = (SCIP_READERDATA*)user_data;
121  assert(readerdata != NULL);
122  assert(readerdata->retcode == SCIP_OKAY);
123  assert(!readerdata->readerror);
124 
125  scip = readerdata->scip;
126  assert(scip != NULL);
127 
128  readerdata->retcode = createProb(scip, readerdata, name);
129 
130  /* return the reader data pointer to receive it all other ZIMPL call backs */
131  return (Lps*) readerdata;
132 }
133 
134 /** free storage for mathematical program. xlp_free() is the last xlpglue routine that will be called by Zimpl */
135 void xlp_free(
136  Lps* data /**< pointer to reader data */
137  )
138 { /*lint --e{715}*/
139  /* nothing to be done here */
140 }
141 
142 /** does there already exists a constraint with the given name? */
143 Bool xlp_conname_exists(
144  const Lps* data, /**< pointer to reader data */
145  const char* name /**< constraint name to check */
146  )
147 {
148  SCIP_READERDATA* readerdata;
149 
150  readerdata = (SCIP_READERDATA*)data;
151  assert(readerdata != NULL);
152 
153  /* check if constraint with the given name already exists */
154  return (SCIPfindCons(readerdata->scip, name) != NULL);
155 }
156 
157 
158 /** method creates a constraint and is called directly from ZIMPL
159  *
160  * @note this method is used by ZIMPL beginning from version 3.00
161  */
162 static
163 SCIP_RETCODE addConsTerm(
164  SCIP* scip, /**< SCIP data structure */
165  SCIP_READERDATA* readerdata, /**< reader data */
166  const char* name, /**< constraint name */
167  ConType type, /**< constraint type (LHS, RHS, EQUAL, RANGE, etc) */
168  const Numb* lhs, /**< left hand side */
169  const Numb* rhs, /**< right hand side */
170  unsigned int flags, /**< special constraint flags, see ratlptypes.h */
171  const Term* term, /**< term to use */
172  SCIP_Bool* created /**< pointer to store if a constraint was created */
173  )
174 {
175  SCIP_CONS* cons;
176  SCIP_Real sciplhs;
177  SCIP_Real sciprhs;
178  SCIP_Bool initial;
179  SCIP_Bool separate;
180  SCIP_Bool enforce;
181  SCIP_Bool check;
182  SCIP_Bool propagate;
183  SCIP_Bool local;
184  SCIP_Bool modifiable;
185  SCIP_Bool usercut;
186  SCIP_Bool lazycut;
187  int i;
188 
189  switch( type )
190  {
191  case CON_FREE:
192  sciplhs = -SCIPinfinity(scip);
193  sciprhs = SCIPinfinity(scip);
194  break;
195  case CON_LHS:
196  sciplhs = (SCIP_Real)numb_todbl(lhs);
197  sciprhs = SCIPinfinity(scip);
198  break;
199  case CON_RHS:
200  sciplhs = -SCIPinfinity(scip);
201  sciprhs = (SCIP_Real)numb_todbl(rhs);
202  break;
203  case CON_RANGE:
204  sciplhs = (SCIP_Real)numb_todbl(lhs);
205  sciprhs = (SCIP_Real)numb_todbl(rhs);
206  break;
207  case CON_EQUAL:
208  sciplhs = (SCIP_Real)numb_todbl(lhs);
209  sciprhs = (SCIP_Real)numb_todbl(rhs);
210  assert(sciplhs == sciprhs); /*lint !e777*/
211  break;
212  default:
213  SCIPwarningMessage(scip, "invalid constraint type <%d> in ZIMPL callback xlp_addcon()\n", type);
214  sciplhs = (SCIP_Real)numb_todbl(lhs);
215  sciprhs = (SCIP_Real)numb_todbl(rhs);
216  readerdata->readerror = TRUE;
217  break;
218  }
219 
220  cons = NULL;
221 
222  /* default values */
223  initial = readerdata->initialconss;
224  separate = TRUE;
225  propagate = TRUE;
226  enforce = TRUE;
227  check = TRUE;
228  local = FALSE;
229  modifiable = FALSE;
230 
231  usercut = (flags & LP_FLAG_CON_SEPAR) != 0;
232  lazycut = (flags & LP_FLAG_CON_CHECK) != 0;
233 
234  /* evaluate constraint flags */
235  if( usercut && lazycut )
236  {
237  initial = FALSE;
238  separate = TRUE;
239  check = TRUE;
240  }
241  else if( usercut )
242  {
243  initial = FALSE;
244  separate = TRUE;
245  check = FALSE;
246  }
247  else if( lazycut )
248  {
249  initial = FALSE;
250  separate = FALSE;
251  check = TRUE;
252  }
253 
254  if( term_is_linear(term) )
255  {
256  /* if the constraint gives an indicator constraint */
257  if ( flags & LP_FLAG_CON_INDIC )
258  {
259  Bool lhsIndCons = FALSE; /* generate lhs form for indicator constraints */
260  Bool rhsIndCons = FALSE; /* generate rhs form for indicator constraints */
261 
262  /* currently indicator constraints can only handle "<=" constraints */
263  switch( type )
264  {
265  case CON_LHS:
266  lhsIndCons = TRUE;
267  break;
268  case CON_RHS:
269  rhsIndCons = TRUE;
270  break;
271  case CON_RANGE:
272  case CON_EQUAL:
273  lhsIndCons = TRUE;
274  rhsIndCons = TRUE;
275  break;
276  case CON_FREE:
277  /*lint -fallthrough*/
278  default:
279  SCIPerrorMessage("invalid constraint type <%d> in ZIMPL callback xlp_addcon()\n", type);
280  readerdata->readerror = TRUE;
281  break;
282  }
283 
284  /* insert lhs form of indicator */
285  if ( lhsIndCons )
286  {
287  SCIP_CALL( SCIPcreateConsIndicator(scip, &cons, name, NULL, 0, NULL, NULL, -sciplhs,
288  initial, separate, enforce, check, propagate, local, readerdata->dynamicconss, readerdata->dynamicrows, FALSE) );
289  SCIP_CALL( SCIPaddCons(scip, cons) );
290 
291  for( i = 0; i < term_get_elements(term); i++ )
292  {
293  SCIP_VAR* scipvar;
294  SCIP_Real scipval;
295  const Mono* mono = term_get_element(term, i);
296  MFun mfun;
297 
298  scipvar = (SCIP_VAR*)mono_get_var(mono, 0);
299 
300  /* check whether variable is the binary variable */
301  mfun = mono_get_function(mono);
302  if (mfun == MFUN_TRUE || mfun == MFUN_FALSE)
303  {
304  scipvar = (SCIP_VAR*)mono_get_var(mono, 0);
305  SCIP_CALL( SCIPsetBinaryVarIndicator(scip, cons, scipvar) );
306  }
307  else
308  {
309  assert(!numb_equal(mono_get_coeff(mono), numb_zero()));
310  assert(mono_is_linear(mono));
311 
312  scipval = -numb_todbl(mono_get_coeff(mono));
313  SCIP_CALL( SCIPaddVarIndicator(scip, cons, scipvar, scipval) );
314  }
315  }
316 
317  (*created) = TRUE;
318  }
319 
320  /* insert rhs form of indicator */
321  if ( rhsIndCons )
322  {
323  SCIP_CALL( SCIPcreateConsIndicator(scip, &cons, name, NULL, 0, NULL, NULL, sciprhs,
324  initial, separate, enforce, check, propagate, local, readerdata->dynamicconss, readerdata->dynamicrows, FALSE) );
325  SCIP_CALL( SCIPaddCons(scip, cons) );
326 
327  for( i = 0; i < term_get_elements(term); i++ )
328  {
329  SCIP_VAR* scipvar;
330  SCIP_Real scipval;
331  const Mono* mono = term_get_element(term, i);
332  MFun mfun;
333 
334  scipvar = (SCIP_VAR*)mono_get_var(mono, 0);
335 
336  /* check whether variable is the binary variable */
337  mfun = mono_get_function(mono);
338  if (mfun == MFUN_TRUE || mfun == MFUN_FALSE)
339  {
340  scipvar = (SCIP_VAR*)mono_get_var(mono, 0);
341  SCIP_CALL( SCIPsetBinaryVarIndicator(scip, cons, scipvar) );
342  }
343  else
344  {
345  assert(!numb_equal(mono_get_coeff(mono), numb_zero()));
346  assert(mono_is_linear(mono));
347 
348  scipval = numb_todbl(mono_get_coeff(mono));
349  SCIP_CALL( SCIPaddVarIndicator(scip, cons, scipvar, scipval) );
350  }
351  }
352 
353  (*created) = TRUE;
354  }
355  }
356  else
357  {
358  SCIP_CALL( SCIPcreateConsLinear(scip, &cons, name, 0, NULL, NULL, sciplhs, sciprhs,
359  initial, separate, enforce, check, propagate, local, modifiable, readerdata->dynamicconss, readerdata->dynamicrows, FALSE) );
360  SCIP_CALL( SCIPaddCons(scip, cons) );
361 
362  for( i = 0; i < term_get_elements(term); i++ )
363  {
364  SCIP_VAR* scipvar;
365  SCIP_Real scipval;
366 
367  assert(!numb_equal(mono_get_coeff(term_get_element(term, i)), numb_zero()));
368  assert(mono_is_linear(term_get_element(term, i)));
369 
370  scipvar = (SCIP_VAR*)mono_get_var(term_get_element(term, i), 0);
371  scipval = numb_todbl(mono_get_coeff(term_get_element(term, i)));
372 
373  SCIP_CALL( SCIPaddCoefLinear(scip, cons, scipvar, scipval) );
374  }
375 
376  (*created) = TRUE;
377  }
378  }
379  else if( term_get_degree(term) == 2 )
380  {
381  int nlinvars;
382  int nquadterms;
383  SCIP_VAR** linvars;
384  SCIP_VAR** quadvar1;
385  SCIP_VAR** quadvar2;
386  SCIP_Real* lincoefs;
387  SCIP_Real* quadcoefs;
388  Mono* monom;
389 
390  nlinvars = 0;
391  nquadterms = 0;
392 
393  SCIP_CALL( SCIPallocBufferArray(scip, &linvars, term_get_elements(term)) );
394  SCIP_CALL( SCIPallocBufferArray(scip, &quadvar1, term_get_elements(term)) );
395  SCIP_CALL( SCIPallocBufferArray(scip, &quadvar2, term_get_elements(term)) );
396  SCIP_CALL( SCIPallocBufferArray(scip, &lincoefs, term_get_elements(term)) );
397  SCIP_CALL( SCIPallocBufferArray(scip, &quadcoefs, term_get_elements(term)) );
398 
399  for( i = 0; i < term_get_elements(term); ++i )
400  {
401  monom = term_get_element(term, i);
402  assert(!numb_equal(mono_get_coeff(monom), numb_zero()));
403  assert(mono_get_degree(monom) <= 2);
404  assert(mono_get_degree(monom) > 0);
405  if (mono_get_degree(monom) == 1)
406  {
407  linvars [nlinvars] = (SCIP_VAR*)mono_get_var(monom, 0);
408  lincoefs[nlinvars] = numb_todbl(mono_get_coeff(monom));
409  ++nlinvars;
410  }
411  else
412  {
413  assert(mono_get_degree(monom) == 2);
414  quadvar1 [nquadterms] = (SCIP_VAR*)mono_get_var(monom, 0);
415  quadvar2 [nquadterms] = (SCIP_VAR*)mono_get_var(monom, 1);
416  quadcoefs[nquadterms] = numb_todbl(mono_get_coeff(monom));
417  ++nquadterms;
418  }
419  }
420 
421  SCIP_CALL( SCIPcreateConsQuadratic(scip, &cons, name, nlinvars, linvars, lincoefs, nquadterms, quadvar1, quadvar2, quadcoefs, sciplhs, sciprhs,
422  initial, separate, enforce, check, propagate, local, modifiable, readerdata->dynamicconss, readerdata->dynamicrows) );
423  SCIP_CALL( SCIPaddCons(scip, cons) );
424 
425  SCIPfreeBufferArray(scip, &linvars);
426  SCIPfreeBufferArray(scip, &quadvar1);
427  SCIPfreeBufferArray(scip, &quadvar2);
428  SCIPfreeBufferArray(scip, &lincoefs);
429  SCIPfreeBufferArray(scip, &quadcoefs);
430 
431  (*created) = TRUE;
432  }
433  else
434  {
435  SCIP_VAR** polyvars;
436  int npolyvars;
437  int polyvarssize;
438  SCIP_HASHMAP* polyvarmap;
439  SCIP_VAR** vars;
440  int nvars;
441  int varssize;
442  SCIP_HASHMAP* varmap;
443  SCIP_EXPRDATA_MONOMIAL** simplemonomials;
444  int nsimplemonomials;
445  int simplemonomialssize;
446  SCIP_EXPR** extramonomials;
447  SCIP_Real* extracoefs;
448  int nextramonomials;
449  int extramonomialssize;
450  Mono* monomial;
451  int varpos;
452  int j;
453 
454  (*created) = TRUE;
455 
456  vars = NULL;
457  nvars = 0;
458  varssize = 0;
459  varmap = NULL;
460 
461  polyvars = NULL;
462  npolyvars = 0;
463  polyvarssize = 0;
464 
465  simplemonomials = NULL;
466  nsimplemonomials = 0;
467  simplemonomialssize = 0;
468 
469  extramonomials = NULL;
470  extracoefs = NULL;
471  nextramonomials = 0;
472  extramonomialssize = 0;
473 
474  SCIP_CALL( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), SCIPcalcMemGrowSize(scip, 10)) );
475  SCIP_CALL( SCIPhashmapCreate(&polyvarmap, SCIPblkmem(scip), SCIPcalcMemGrowSize(scip, 10)) );
476 
477  for( i = 0; i < term_get_elements(term); ++i )
478  {
479  monomial = term_get_element(term, i);
480  assert(monomial != NULL);
481  assert(!numb_equal(mono_get_coeff(monomial), numb_zero()));
482  assert(mono_get_degree(monomial) > 0);
483 
484  if( mono_get_function(monomial) == MFUN_NONE )
485  {
486  /* nonlinear monomial without extra function around it */
487  SCIP_Real one;
488 
489  one = 1.0;
490 
491  /* create SCIP monomial */
492  if( simplemonomialssize == 0 )
493  {
494  simplemonomialssize = SCIPcalcMemGrowSize(scip, 1);
495  SCIP_CALL( SCIPallocBufferArray(scip, &simplemonomials, simplemonomialssize) );
496  }
497  else if( simplemonomialssize < nsimplemonomials + 1 )
498  {
499  simplemonomialssize = SCIPcalcMemGrowSize(scip, nsimplemonomials+1);
500  SCIP_CALL( SCIPreallocBufferArray(scip, &simplemonomials, simplemonomialssize) );
501  }
502  assert(simplemonomials != NULL);
503  SCIP_CALL( SCIPexprCreateMonomial(SCIPblkmem(scip), &simplemonomials[nsimplemonomials], numb_todbl(mono_get_coeff(monomial)), 0, NULL, NULL) );
504 
505  for( j = 0; j < mono_get_degree(monomial); ++j )
506  {
507  /* get variable index in polyvars; add to polyvars if not existing yet */
508  if( !SCIPhashmapExists(polyvarmap, (void*)mono_get_var(monomial, j)) ) /*lint !e826*/
509  {
510  if( polyvarssize == 0 )
511  {
512  polyvarssize = SCIPcalcMemGrowSize(scip, 1);
513  SCIP_CALL( SCIPallocBufferArray(scip, &polyvars, polyvarssize) );
514  }
515  else if( polyvarssize < npolyvars + 1 )
516  {
517  polyvarssize = SCIPcalcMemGrowSize(scip, npolyvars+1);
518  SCIP_CALL( SCIPreallocBufferArray(scip, &polyvars, polyvarssize) );
519  }
520  assert(polyvars != NULL);
521 
522  polyvars[npolyvars] = (SCIP_VAR*)mono_get_var(monomial, j); /*lint !e826*/
523  ++npolyvars;
524  varpos = npolyvars-1;
525  SCIP_CALL( SCIPhashmapInsert(polyvarmap, (void*)mono_get_var(monomial, j), (void*)(size_t)varpos) ); /*lint !e826*/
526  }
527  else
528  {
529  varpos = (int)(size_t)SCIPhashmapGetImage(polyvarmap, (void*)mono_get_var(monomial, j)); /*lint !e826*/
530  }
531  assert(polyvars != NULL);
532  assert(polyvars[varpos] == (SCIP_VAR*)mono_get_var(monomial, j));
533 
534  SCIP_CALL( SCIPexprAddMonomialFactors(SCIPblkmem(scip), simplemonomials[nsimplemonomials], 1, &varpos, &one) );
535  }
536  SCIPexprMergeMonomialFactors(simplemonomials[nsimplemonomials], 0.0);
537 
538  ++nsimplemonomials;
539  }
540  else
541  {
542  /* nonlinear monomial with extra function around it, put into new expression */
543  SCIP_EXPR** children;
544  SCIP_EXPR* expr;
545  SCIP_EXPROP op;
546  SCIP_Real coef;
547  SCIP_Real argdbl;
548  int argint;
549 
550  coef = 1.0;
551  argint = 0;
552  argdbl = 0.0;
553  switch( mono_get_function(monomial) )
554  {
555  case MFUN_SQRT:
556  op = SCIP_EXPR_SQRT;
557  break;
558  case MFUN_LOG:
559  /* log10(x) = ln(x) / ln(10.0) */
560  op = SCIP_EXPR_LOG;
561  coef = 1.0 / log(10.0);
562  break;
563  case MFUN_EXP:
564  op = SCIP_EXPR_EXP;
565  break;
566 #if ZIMPL_VERSION >= 330
567  case MFUN_LN:
568  op = SCIP_EXPR_LOG;
569  break;
570  /*
571  case MFUN_SIN:
572  op = SCIP_EXPR_SIN;
573  break;
574  case MFUN_COS:
575  op = SCIP_EXPR_COS;
576  break;
577  case MFUN_TAN:
578  op = SCIP_EXPR_TAN;
579  break;
580  */
581  case MFUN_ABS:
582  op = SCIP_EXPR_ABS;
583  break;
584  case MFUN_SGN:
585  op = SCIP_EXPR_SIGN;
586  break;
587  case MFUN_POW:
588  if( numb_is_int(mono_get_coeff(monomial)) )
589  {
590  op = SCIP_EXPR_INTPOWER;
591  argint = numb_toint(mono_get_coeff(monomial));
592  }
593  else
594  {
595  op = SCIP_EXPR_REALPOWER;
596  argdbl = numb_todbl(mono_get_coeff(monomial));
597  }
598  break;
599  case MFUN_SGNPOW:
600  op = SCIP_EXPR_SIGNPOWER;
601  argdbl = numb_todbl(mono_get_coeff(monomial));
602  break;
603 #endif
604  case MFUN_NONE:
605  case MFUN_TRUE:
606  case MFUN_FALSE:
607  SCIPerrorMessage("ZIMPL function %d invalid here.\n", mono_get_function(monomial));
608  (*created) = FALSE;
609  break;
610 #if ZIMPL_VERSION >= 330
611  case MFUN_SIN:
612  case MFUN_COS:
613  case MFUN_TAN:
614 #endif
615  default:
616  SCIPerrorMessage("ZIMPL function %d not supported\n", mono_get_function(monomial));
617  (*created) = FALSE;
618  break;
619  } /*lint !e788*/
620  if( !(*created) )
621  break;
622 
623  if( extramonomialssize == 0 )
624  {
625  extramonomialssize = SCIPcalcMemGrowSize(scip, 1);
626  SCIP_CALL( SCIPallocBufferArray(scip, &extramonomials, extramonomialssize) );
627  SCIP_CALL( SCIPallocBufferArray(scip, &extracoefs, extramonomialssize) );
628  }
629  else if( extramonomialssize < nextramonomials + 1 )
630  {
631  extramonomialssize = SCIPcalcMemGrowSize(scip, nextramonomials+1);
632  SCIP_CALL( SCIPreallocBufferArray(scip, &extramonomials, extramonomialssize) );
633  SCIP_CALL( SCIPreallocBufferArray(scip, &extracoefs, extramonomialssize) );
634  }
635  assert(extracoefs != NULL);
636  assert(extramonomials != NULL);
637  extracoefs[nextramonomials] = coef;
638 
639  /* create children expressions */
640  SCIP_CALL( SCIPallocBufferArray(scip, &children, mono_get_degree(monomial)) );
641  for( j = 0; j < mono_get_degree(monomial); ++j )
642  {
643  /* get variable index in vars; add to vars if not existing yet */
644  if( !SCIPhashmapExists(varmap, (void*)mono_get_var(monomial, j)) ) /*lint !e826*/
645  {
646  if( varssize == 0 )
647  {
648  varssize = SCIPcalcMemGrowSize(scip, 1);
649  SCIP_CALL( SCIPallocBufferArray(scip, &vars, varssize) );
650  }
651  else if( varssize < nvars + 1 )
652  {
653  varssize = SCIPcalcMemGrowSize(scip, nvars+1);
654  SCIP_CALL( SCIPreallocBufferArray(scip, &vars, varssize) );
655  }
656  assert(vars != NULL);
657 
658  vars[nvars] = (SCIP_VAR*)mono_get_var(monomial, j); /*lint !e826*/
659  ++nvars;
660  varpos = nvars-1;
661  SCIP_CALL( SCIPhashmapInsert(varmap, (void*)mono_get_var(monomial, j), (void*)(size_t)varpos) ); /*lint !e826*/
662  }
663  else
664  {
665  varpos = (int)(size_t)SCIPhashmapGetImage(varmap, (void*)mono_get_var(monomial, j)); /*lint !e826*/
666  }
667  assert(vars != NULL);
668  assert(vars[varpos] == (SCIP_VAR*)mono_get_var(monomial, j));
669 
670  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &children[j], SCIP_EXPR_VARIDX, varpos) );
671  }
672 
673  /* create expression for product of variables */
674  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &expr, SCIP_EXPR_PRODUCT, mono_get_degree(monomial), children) );
675 
676  /* create expression for function of product of variables */
677  if( op == SCIP_EXPR_INTPOWER ) /*lint !e644 */
678  {
679  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &extramonomials[nextramonomials], op, expr, argint) ); /*lint !e644*/
680  }
681  else if( op == SCIP_EXPR_REALPOWER || op == SCIP_EXPR_SIGNPOWER )
682  {
683  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &extramonomials[nextramonomials], op, expr, argdbl) ); /*lint !e644*/
684  }
685  else
686  {
687  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &extramonomials[nextramonomials], op, expr) ); /*lint !e644*/
688  }
689 
690  ++nextramonomials;
691 
692  SCIPfreeBufferArray(scip, &children);
693  }
694  }
695 
696  if( *created )
697  {
698  SCIP_EXPRTREE* exprtree;
699  SCIP_EXPR* polynomial;
700  SCIP_EXPR** children;
701  int nchildren;
702 
703  assert(polyvars != NULL || npolyvars == 0);
704 
705  nchildren = npolyvars + nextramonomials;
706  SCIP_CALL( SCIPallocBufferArray(scip, &children, nchildren) );
707  /* add polynomial variables to vars
708  * create children expressions for polynomial variables
709  */
710  for( i = 0; i < npolyvars; ++i )
711  {
712  /* get variable index in vars; add to vars if not existing yet */
713  if( !SCIPhashmapExists(varmap, (void*)polyvars[i]) ) /*lint !e613*/
714  {
715  if( varssize == 0 )
716  {
717  varssize = SCIPcalcMemGrowSize(scip, 1);
718  SCIP_CALL( SCIPallocBufferArray(scip, &vars, varssize) );
719  }
720  else if( varssize < nvars + 1 )
721  {
722  varssize = SCIPcalcMemGrowSize(scip, nvars+1);
723  SCIP_CALL( SCIPreallocBufferArray(scip, &vars, varssize) );
724  }
725  assert(vars != NULL);
726 
727  vars[nvars] = polyvars[i]; /*lint !e613*/
728  ++nvars;
729  varpos = nvars-1;
730  SCIP_CALL( SCIPhashmapInsert(varmap, (void*)polyvars[i], (void*)(size_t)varpos) ); /*lint !e613*/
731  }
732  else
733  {
734  varpos = (int)(size_t)SCIPhashmapGetImage(varmap, (void*)polyvars[i]); /*lint !e613*/
735  }
736  assert(vars[varpos] == polyvars[i]); /*lint !e613*/
737 
738  SCIP_CALL( SCIPexprCreate(SCIPblkmem(scip), &children[i], SCIP_EXPR_VARIDX, varpos) ); /*lint !e866*/
739  }
740 
741  /* add simple monomials as additional children */
742  BMScopyMemoryArray(&children[npolyvars], extramonomials, nextramonomials); /*lint !e866*/
743 
744  assert(extracoefs != NULL || nextramonomials == 0);
745  assert(extramonomials != NULL || nextramonomials == 0);
746 
747  /* create polynomial expression including simple monomials */
748  SCIP_CALL( SCIPexprCreatePolynomial(SCIPblkmem(scip), &polynomial, nchildren, children, nsimplemonomials, simplemonomials, 0.0, FALSE) );
749  /* add extra monomials */
750  for( i = 0; i < nextramonomials; ++i )
751  {
752  SCIP_EXPRDATA_MONOMIAL* monomialdata;
753  int childidx;
754  SCIP_Real exponent;
755 
756  childidx = npolyvars + i;
757  exponent = 1.0;
758  SCIP_CALL( SCIPexprCreateMonomial(SCIPblkmem(scip), &monomialdata, extracoefs[i], 1, &childidx, &exponent) ); /*lint !e613*/
759  SCIP_CALL( SCIPexprAddMonomials(SCIPblkmem(scip), polynomial, 1, &monomialdata, FALSE) );
760  }
761 
762  SCIPfreeBufferArray(scip, &children);
763 
764  /* create expression tree */
765  SCIP_CALL( SCIPexprtreeCreate(SCIPblkmem(scip), &exprtree, polynomial, nvars, 0, NULL) );
766  SCIP_CALL( SCIPexprtreeSetVars(exprtree, nvars, vars) );
767 
768  /* create constraint */
769  SCIP_CALL( SCIPcreateConsNonlinear(scip, &cons, name, 0, NULL, NULL, 1, &exprtree, NULL, sciplhs, sciprhs,
770  initial, separate, enforce, check, propagate, local, modifiable, readerdata->dynamicconss, readerdata->dynamicrows, FALSE) );
771  SCIP_CALL( SCIPexprtreeFree(&exprtree) );
772  SCIP_CALL( SCIPaddCons(scip, cons) );
773  }
774 
775  /* free memory */
776  SCIPhashmapFree(&varmap);
777  SCIPfreeBufferArrayNull(scip, &vars);
778  SCIPhashmapFree(&polyvarmap);
779  SCIPfreeBufferArrayNull(scip, &polyvars);
780  SCIPfreeBufferArrayNull(scip, &simplemonomials);
781  SCIPfreeBufferArrayNull(scip, &extramonomials);
782  SCIPfreeBufferArrayNull(scip, &extracoefs);
783  }
784 
785  if( cons != NULL )
786  {
787  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
788  }
789 
790  return SCIP_OKAY;
791 }
792 
793 /** method creates a constraint and is called directly from ZIMPL
794  *
795  * @note this method is used by ZIMPL beginning from version 3.00
796  */
797 Bool xlp_addcon_term(
798  Lps* data, /**< pointer to reader data */
799  const char* name, /**< constraint name */
800  ConType type, /**< constraint type (LHS, RHS, EQUAL, RANGE, etc) */
801  const Numb* lhs, /**< left hand side */
802  const Numb* rhs, /**< right hand side */
803  unsigned int flags, /**< special constraint flags, see ratlptypes.h */
804  const Term* term /**< term to use */
805  )
806 {
807  SCIP* scip;
808  SCIP_READERDATA* readerdata;
809  SCIP_Bool created = FALSE;
810 
811  readerdata = (SCIP_READERDATA*)data;
812  assert(readerdata != NULL);
813 
814  scip = readerdata->scip;
815  assert(scip != NULL);
816 
817  if( readerdata->retcode != SCIP_OKAY || readerdata->readerror )
818  return TRUE;
819 
820  readerdata->retcode = addConsTerm(scip, readerdata, name, type, lhs, rhs, flags, term, &created);
821 
822  return !created;
823 }
824 
825 /** adde variable */
826 static
827 SCIP_RETCODE addVar(
828  SCIP* scip, /**< SCIP data structure */
829  SCIP_READERDATA* readerdata, /**< reader data */
830  const char* name, /**< variable name */
831  VarClass usevarclass, /**< variable type */
832  const Bound* lower, /**< lower bound */
833  const Bound* upper, /**< upper bound */
834  const Numb* priority, /**< branching priority */
835  const Numb* startval, /**< start value for the variable within in the start solution */
836  Var** zplvar /**< pointer to store the created variable */
837  )
838 {
839  SCIP_VAR* var;
840  SCIP_Real lb;
841  SCIP_Real ub;
842  SCIP_VARTYPE vartype;
843  SCIP_Bool initial;
844  SCIP_Bool removable;
845  int branchpriority;
846 
847  switch( bound_get_type(lower) )
848  {
849  case BOUND_VALUE:
850  lb = (SCIP_Real)numb_todbl(bound_get_value(lower));
851  break;
852  case BOUND_INFTY:
853  lb = SCIPinfinity(scip);
854  break;
855  case BOUND_MINUS_INFTY:
856  lb = -SCIPinfinity(scip);
857  break;
858  case BOUND_ERROR:
859  default:
860  SCIPerrorMessage("invalid lower bound type <%d> in ZIMPL reader\n", bound_get_type(lower));
861  lb = 0.0;
862  break;
863  }
864 
865  switch( bound_get_type(upper) )
866  {
867  case BOUND_VALUE:
868  ub = (SCIP_Real)numb_todbl(bound_get_value(upper));
869  break;
870  case BOUND_INFTY:
871  ub = SCIPinfinity(scip);
872  break;
873  case BOUND_MINUS_INFTY:
874  ub = -SCIPinfinity(scip);
875  break;
876  case BOUND_ERROR:
877  default:
878  SCIPerrorMessage("invalid upper bound type <%d> in ZIMPL reader\n", bound_get_type(upper));
879  ub = 0.0;
880  break;
881  }
882 
883  switch( usevarclass )
884  {
885  case VAR_CON:
886  vartype = SCIP_VARTYPE_CONTINUOUS;
887  break;
888  case VAR_INT:
889  vartype = SCIP_VARTYPE_INTEGER;
890  break;
891  case VAR_IMP:
892  vartype = SCIP_VARTYPE_IMPLINT;
893  break;
894  default:
895  SCIPwarningMessage(scip, "invalid variable class <%d> in ZIMPL callback xlp_addvar()\n", usevarclass);
896  vartype = SCIP_VARTYPE_CONTINUOUS;
897  readerdata->readerror = TRUE;
898  break;
899  }
900  initial = !(readerdata->dynamiccols);
901  removable = readerdata->dynamiccols;
902 
903  /* create variable */
904  SCIP_CALL( SCIPcreateVar(scip, &var, name, lb, ub, 0.0, vartype, initial, removable, NULL, NULL, NULL, NULL, NULL) );
905 
906  /* add variable to the problem; we are releasing the variable later */
907  SCIP_CALL( SCIPaddVar(scip, var) );
908 
909  if( !numb_equal(priority, numb_unknown()) )
910  {
911  if( numb_is_int(priority) )
912  branchpriority = numb_toint(priority);
913  else
914  {
915  if( !readerdata->branchpriowarning )
916  {
918  "ZIMPL reader: fractional branching priorities in input - rounding down to integer values\n");
919  readerdata->branchpriowarning = TRUE;
920  }
921  branchpriority = (int)numb_todbl(priority);
922  }
923 
924  /* change the branching priority of the variable */
925  SCIP_CALL( SCIPchgVarBranchPriority(scip, var, branchpriority) );
926  }
927 
928  /* check if we are willing to except a primal solution candidate */
929  if( readerdata->valid )
930  {
931  /* if the number is unknown we have no valid primal solution candidate */
932  if( numb_equal(startval, numb_unknown()) )
933  {
934  SCIPdebugMessage("primal solution candidate contains an unknown value for variable <%s>(%g)\n",
935  SCIPvarGetName(var), (SCIP_Real)numb_todbl(startval));
936  readerdata->valid = FALSE;
937  }
938  else
939  {
940  assert(readerdata->sol != NULL);
941  SCIPdebugMessage("change solution solution <%p>: <%s> = <%g>\n",
942  (void*)readerdata->sol, SCIPvarGetName(var), (SCIP_Real)numb_todbl(startval));
943 
944  /* set value within the primal solution candidate */
945  SCIP_CALL( SCIPsetSolVal(scip, readerdata->sol, var, (SCIP_Real)numb_todbl(startval)) );
946  }
947  }
948 
949  /* copy the variable pointer before we release the variable */
950  (*zplvar) = (Var*)var;
951 
952  /* release variable */
953  SCIP_CALL( SCIPreleaseVar(scip, &var) );
954 
955  return SCIP_OKAY;
956 }
957 
958 /** method adds a variable; is called directly by ZIMPL */
959 Var* xlp_addvar(
960  Lps* data, /**< pointer to reader data */
961  const char* name, /**< variable name */
962  VarClass usevarclass, /**< variable type */
963  const Bound* lower, /**< lower bound */
964  const Bound* upper, /**< upper bound */
965  const Numb* priority, /**< branching priority */
966  const Numb* startval /**< start value for the variable within in the start solution */
967  )
968 { /*lint --e{715}*/
969  SCIP* scip;
970  SCIP_READERDATA* readerdata;
971  Var* zplvar;
972 
973  readerdata = (SCIP_READERDATA*)data;
974  assert(readerdata != NULL);
975 
976  scip = readerdata->scip;
977  assert(scip != NULL);
978 
979  zplvar = NULL;
980 
981  if( readerdata->retcode != SCIP_OKAY || readerdata->readerror )
982  return NULL;
983 
984  readerdata->retcode = addVar(scip, readerdata, name, usevarclass, lower, upper, priority, startval, &zplvar);
985 
986  return zplvar;
987 }
988 
989 /** add a SOS constraint. Add a given a Zimpl term as an SOS constraint to the mathematical program */
990 static
991 SCIP_RETCODE addSOS(
992  SCIP* scip, /**< SCIP data structure */
993  SCIP_READERDATA* readerdata, /**< reader data */
994  const char* name, /**< constraint name */
995  SosType type, /**< SOS type */
996  const Term* term /**< terms indicating sos */
997  )
998 {
999  SCIP_CONS* cons;
1000  SCIP_Bool separate;
1001  SCIP_Bool enforce;
1002  SCIP_Bool check;
1003  SCIP_Bool propagate;
1004  SCIP_Bool local;
1005  int i;
1006 
1007  switch( type )
1008  {
1009  case SOS_TYPE1:
1010  separate = TRUE;
1011  enforce = TRUE;
1012  check = enforce;
1013  propagate = TRUE;
1014  local = FALSE;
1015 
1016  SCIP_CALL( SCIPcreateConsSOS1(scip, &cons, name, 0, NULL, NULL,
1017  readerdata->initialconss, separate, enforce, check, propagate, local, readerdata->dynamicconss, readerdata->dynamicrows, FALSE) );
1018  SCIP_CALL( SCIPaddCons(scip, cons) );
1019 
1020  for( i = 0; i < term_get_elements(term); i++ )
1021  {
1022  SCIP_VAR* var;
1023  SCIP_Real weight;
1024 
1025  assert( mono_is_linear(term_get_element(term, i)) );
1026 
1027  var = (SCIP_VAR*) mono_get_var(term_get_element(term, i), 0);
1028  weight = numb_todbl(mono_get_coeff(term_get_element(term, i)));
1029 
1030  SCIP_CALL( SCIPaddVarSOS1(scip, cons, var, weight) );
1031  }
1032  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
1033  break;
1034  case SOS_TYPE2:
1035  separate = TRUE;
1036  enforce = TRUE;
1037  check = enforce;
1038  propagate = TRUE;
1039  local = FALSE;
1040 
1041  SCIP_CALL( SCIPcreateConsSOS2(scip, &cons, name, 0, NULL, NULL,
1042  readerdata->initialconss, separate, enforce, check, propagate, local, readerdata->dynamicconss, readerdata->dynamicrows, FALSE) );
1043  SCIP_CALL( SCIPaddCons(scip, cons) );
1044  for( i = 0; i < term_get_elements(term); i++ )
1045  {
1046  SCIP_VAR* var;
1047  SCIP_Real weight;
1048 
1049  assert( mono_is_linear(term_get_element(term, i)) );
1050 
1051  var = (SCIP_VAR*) mono_get_var(term_get_element(term, i), 0);
1052  weight = numb_todbl(mono_get_coeff(term_get_element(term, i)));
1053 
1054  SCIP_CALL( SCIPaddVarSOS2(scip, cons, var, weight) );
1055  }
1056  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
1057  break;
1058  case SOS_ERR:
1059  /*lint -fallthrough*/
1060  default:
1061  SCIPerrorMessage("invalid SOS type <%d> in ZIMPL callback xlp_addsos_term()\n", type);
1062  readerdata->readerror = TRUE;
1063  break;
1064  }
1065 
1066  return SCIP_OKAY;
1067 }
1068 
1069 /** add a SOS constraint. Add a given a Zimpl term as an SOS constraint to the mathematical program */
1070 Bool xlp_addsos_term(
1071  Lps* data, /**< pointer to reader data */
1072  const char* name, /**< constraint name */
1073  SosType type, /**< SOS type */
1074  const Numb* priority, /**< priority */
1075  const Term* term /**< terms indicating sos */
1076  )
1077 {
1078  /*lint --e{715}*/
1079  SCIP* scip;
1080  SCIP_READERDATA* readerdata;
1081 
1082  readerdata = (SCIP_READERDATA*)data;
1083  assert(readerdata != NULL);
1084 
1085  scip = readerdata->scip;
1086  assert(scip != NULL);
1087 
1088  if( readerdata->retcode != SCIP_OKAY || readerdata->readerror )
1089  return TRUE;
1090 
1091  readerdata->retcode = addSOS(scip, readerdata, name, type, term);
1092 
1093  return FALSE;
1094 }
1095 
1096 /** returns the variable name */
1097 const char* xlp_getvarname(
1098  const Lps* data, /**< pointer to reader data */
1099  const Var* var /**< variable */
1100  )
1101 {
1102 #ifndef NDEBUG
1103  SCIP* scip;
1104  SCIP_READERDATA* readerdata;
1105 
1106  readerdata = (SCIP_READERDATA*)data;
1107  assert(readerdata != NULL);
1108 
1109  scip = readerdata->scip;
1110  assert(scip != NULL);
1111 #endif
1112 
1113  return SCIPvarGetName((SCIP_VAR*)var);
1114 }
1115 
1116 /** return variable type */
1117 VarClass xlp_getclass(
1118  const Lps* data, /**< pointer to reader data */
1119  const Var* var /**< variable */
1120  )
1121 {
1122  SCIP_READERDATA* readerdata;
1123  SCIP_VAR* scipvar;
1124 
1125  readerdata = (SCIP_READERDATA*)data;
1126  assert(readerdata != NULL);
1127 
1128  scipvar = (SCIP_VAR*)var;
1129  switch( SCIPvarGetType(scipvar) )
1130  {
1131  case SCIP_VARTYPE_BINARY:
1132  case SCIP_VARTYPE_INTEGER:
1133  return VAR_INT;
1134  case SCIP_VARTYPE_IMPLINT:
1135  return VAR_IMP;
1137  return VAR_CON;
1138  default:
1139  SCIPerrorMessage("invalid SCIP variable type <%d> in ZIMPL callback xlp_getclass()\n", SCIPvarGetType(scipvar));
1140  readerdata->readerror = TRUE;
1141  break;
1142  }
1143 
1144  return VAR_CON;
1145 }
1146 
1147 /** returns lower bound */
1148 Bound* xlp_getlower(
1149  const Lps* data, /**< pointer to reader data */
1150  const Var* var /**< variable */
1151  )
1152 {
1153  SCIP* scip;
1154  SCIP_READERDATA* readerdata;
1155  SCIP_VAR* scipvar;
1156  SCIP_Real lb;
1157  char s[SCIP_MAXSTRLEN];
1158  BoundType boundtype;
1159  Numb* numb;
1160  Bound* bound;
1161 
1162  readerdata = (SCIP_READERDATA*)data;
1163  assert(readerdata != NULL);
1164 
1165  scip = readerdata->scip;
1166  assert(scip != NULL);
1167 
1168  scipvar = (SCIP_VAR*)var;
1169  assert(scipvar != NULL);
1170 
1171  /* collect lower bound */
1172  lb = SCIPvarGetLbGlobal(scipvar);
1173  numb = NULL;
1174 
1175  /* check if lower bound is infinity */
1176  if( SCIPisInfinity(scip, -lb) )
1177  boundtype = BOUND_MINUS_INFTY;
1178  else if( SCIPisInfinity(scip, lb) )
1179  boundtype = BOUND_INFTY;
1180  else
1181  {
1182  boundtype = BOUND_VALUE;
1183 
1184  /* create double form string */
1185  (void) SCIPsnprintf(s, SCIP_MAXSTRLEN, "%.20f", lb);
1186  numb = numb_new_ascii(s);
1187  }
1188 
1189  /* create bound */
1190  bound = bound_new(boundtype, numb);
1191 
1192  if( numb != NULL )
1193  numb_free(numb);
1194 
1195  return bound;
1196 }
1197 
1198 /** returns upper bound */
1199 Bound* xlp_getupper(
1200  const Lps* data, /**< pointer to reader data */
1201  const Var* var /**< variable */
1202  )
1203 {
1204  SCIP* scip;
1205  SCIP_READERDATA* readerdata;
1206  SCIP_VAR* scipvar;
1207  SCIP_Real ub;
1208  char s[SCIP_MAXSTRLEN];
1209  BoundType boundtype;
1210  Numb* numb;
1211  Bound* bound;
1212 
1213  readerdata = (SCIP_READERDATA*)data;
1214  assert(readerdata != NULL);
1215 
1216  scip = readerdata->scip;
1217  assert(scip != NULL);
1218 
1219  scipvar = (SCIP_VAR*)var;
1220  assert(scipvar != NULL);
1221 
1222  /* collect upper bound */
1223  ub = SCIPvarGetUbGlobal(scipvar);
1224  numb = NULL;
1225 
1226  /* check if upper bound is infinity */
1227  if( SCIPisInfinity(scip, -ub) )
1228  boundtype = BOUND_MINUS_INFTY;
1229  else if( SCIPisInfinity(scip, ub) )
1230  boundtype = BOUND_INFTY;
1231  else
1232  {
1233  boundtype = BOUND_VALUE;
1234  (void) SCIPsnprintf(s, SCIP_MAXSTRLEN, "%.20f", ub);
1235  numb = numb_new_ascii(s);
1236  }
1237 
1238  /* create ZIMPL bound */
1239  bound = bound_new(boundtype, numb);
1240 
1241  if (numb != NULL)
1242  numb_free(numb);
1243 
1244  return bound;
1245 }
1246 
1247 /* set the name of the objective function */
1248 void xlp_objname(
1249  Lps* data, /**< pointer to reader data */
1250  const char* name /**< name of the objective function */
1251  )
1252 { /*lint --e{715}*/
1253  /* nothing to be done */
1254 }
1255 
1256 /* set the name of the objective function */
1257 void xlp_setdir(
1258  Lps* data, /**< pointer to reader data */
1259  Bool minimize /**<True if the problem should be minimized, False if it should be maximized */
1260  )
1261 {
1262  SCIP* scip;
1263  SCIP_READERDATA* readerdata;
1264  SCIP_OBJSENSE objsense;
1265 
1266  readerdata = (SCIP_READERDATA*)data;
1267  assert(readerdata != NULL);
1268 
1269  scip = readerdata->scip;
1270  assert(scip != NULL);
1271 
1272  if( readerdata->retcode != SCIP_OKAY || readerdata->readerror )
1273  return;
1274 
1275  objsense = (minimize ? SCIP_OBJSENSE_MINIMIZE : SCIP_OBJSENSE_MAXIMIZE);
1276  readerdata->retcode = SCIPsetObjsense(scip, objsense);
1277 }
1278 
1279 /** changes objective coefficient of a variable */
1280 void xlp_addtocost(
1281  Lps* data, /**< pointer to reader data */
1282  Var* var, /**< variable */
1283  const Numb* cost /**< objective coefficient */
1284  )
1285 {
1286  SCIP* scip;
1287  SCIP_READERDATA* readerdata;
1288  SCIP_VAR* scipvar;
1289  SCIP_Real scipval;
1290 
1291  readerdata = (SCIP_READERDATA*)data;
1292  assert(readerdata != NULL);
1293 
1294  scip = readerdata->scip;
1295  assert(scip != NULL);
1296 
1297  if( readerdata->retcode != SCIP_OKAY || readerdata->readerror )
1298  return;
1299 
1300  scipvar = (SCIP_VAR*)var;
1301  assert(scipvar != NULL);
1302  scipval = numb_todbl(cost);
1303 
1304  readerdata->retcode = SCIPchgVarObj(scip, scipvar, SCIPvarGetObj(scipvar) + scipval);
1305 }
1306 
1307 /*
1308  * Callback methods of reader
1309  */
1310 
1311 /** copy method for reader plugins (called when SCIP copies plugins) */
1312 static
1313 SCIP_DECL_READERCOPY(readerCopyZpl)
1314 { /*lint --e{715}*/
1315  assert(scip != NULL);
1316  assert(reader != NULL);
1317  assert(strcmp(SCIPreaderGetName(reader), READER_NAME) == 0);
1318 
1319  /* call inclusion method of reader */
1321 
1322  return SCIP_OKAY;
1323 }
1324 
1325 
1326 /** problem reading method of reader */
1327 static
1328 SCIP_DECL_READERREAD(readerReadZpl)
1329 { /*lint --e{715}*/
1330  SCIP_READERDATA* readerdata;
1331  SCIP_RETCODE retcode;
1332  char oldpath[SCIP_MAXSTRLEN];
1333  char buffer[SCIP_MAXSTRLEN];
1334  char compextension[SCIP_MAXSTRLEN];
1335  char namewithoutpath[SCIP_MAXSTRLEN];
1336  char* path;
1337  char* name;
1338  char* extension;
1339  char* compression;
1340  char* paramstr;
1341 
1342  SCIP_Bool changedir;
1343  int i;
1344 
1345  SCIP_CALL( SCIPgetBoolParam(scip, "reading/zplreader/changedir", &changedir) );
1346 
1347  path = NULL;
1348  oldpath[0] = '\0';
1349  if( changedir )
1350  {
1351  /* change to the directory of the ZIMPL file, s.t. paths of data files read by the ZIMPL model are relative to
1352  * the location of the ZIMPL file
1353  */
1354  (void)strncpy(buffer, filename, SCIP_MAXSTRLEN-1);
1355  buffer[SCIP_MAXSTRLEN-1] = '\0';
1356  SCIPsplitFilename(buffer, &path, &name, &extension, &compression);
1357  if( compression != NULL )
1358  (void) SCIPsnprintf(compextension, SCIP_MAXSTRLEN, ".%s", compression);
1359  else
1360  *compextension = '\0';
1361  (void) SCIPsnprintf(namewithoutpath, SCIP_MAXSTRLEN, "%s.%s%s", name, extension, compextension);
1362  if( getcwd(oldpath, SCIP_MAXSTRLEN) == NULL )
1363  {
1364  SCIPerrorMessage("error getting the current path\n");
1365  return SCIP_READERROR;
1366  }
1367  if( path != NULL )
1368  {
1369  if( chdir(path) != 0 )
1370  {
1371  SCIPerrorMessage("error changing to directory <%s>\n", path);
1372  return SCIP_NOFILE;
1373  }
1374  }
1375  filename = namewithoutpath;
1376  }
1377 
1378  /* get current path for output */
1380  {
1381  char currentpath[SCIP_MAXSTRLEN];
1382  if( getcwd(currentpath, SCIP_MAXSTRLEN) == NULL )
1383  {
1384  SCIPerrorMessage("error getting the current path\n");
1385  return SCIP_READERROR;
1386  }
1387  /* an extra blank line should be printed separately since the buffer message handler only handle up to one line
1388  * correctly */
1390  SCIPverbMessage(scip, SCIP_VERBLEVEL_NORMAL, NULL, "base directory for ZIMPL parsing: <%s>\n", currentpath);
1391  /* an extra blank line should be printed separately since the buffer message handler only handle up to one line
1392  * correctly */
1394  }
1395 
1396  /* allocate storage */
1397  SCIP_CALL( SCIPallocBuffer(scip, &readerdata) );
1398 
1399  readerdata->scip = scip;
1400  readerdata->sol = NULL;
1401  readerdata->valid = FALSE;
1402  readerdata->branchpriowarning = FALSE;
1403  readerdata->readerror = FALSE;
1404  readerdata->retcode = SCIP_OKAY;
1405  SCIP_CALL( SCIPgetBoolParam(scip, "reading/initialconss", &(readerdata->initialconss)) );
1406  SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamicconss", &(readerdata->dynamicconss)) );
1407  SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamiccols", &(readerdata->dynamiccols)) );
1408  SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamicrows", &(readerdata->dynamicrows)) );
1409 
1410  /* get the parameter string */
1411  SCIP_CALL( SCIPgetStringParam(scip, "reading/zplreader/parameters", &paramstr) );
1412  if( strcmp(paramstr, "-") == 0 )
1413  {
1414  /* call ZIMPL parser without arguments */
1415  if( !zpl_read(filename, TRUE, (void*)readerdata) )
1416  readerdata->readerror = TRUE;
1417  else
1418  {
1419  /* evaluate retcode */
1420  if ( readerdata->retcode != SCIP_OKAY )
1421  {
1422  SCIPfreeBuffer(scip, &readerdata);
1423  return readerdata->retcode;
1424  }
1425  }
1426  }
1427  else
1428  {
1429  char dummy[2] = "x";
1430  char** argv;
1431  int argc;
1432  int p;
1433  int len;
1434 
1435  len = (int) strlen(paramstr);
1436  SCIP_CALL( SCIPallocBufferArray(scip, &argv, len+1) );
1437  argv[0] = dummy; /* argument 0 is irrelevant */
1438  argc = 1;
1439  p = 0;
1440  while( p < len )
1441  {
1442  int arglen;
1443 
1444  /* process next argument */
1445  SCIP_CALL( SCIPallocBufferArray(scip, &argv[argc], len+1) ); /*lint !e866*/
1446  arglen = 0;
1447 
1448  /* skip spaces */
1449  while( p < len && paramstr[p] == ' ' )
1450  p++;
1451 
1452  /* process characters */
1453  while( p < len && paramstr[p] != ' ' )
1454  {
1455  switch( paramstr[p] )
1456  {
1457  case '"':
1458  p++;
1459  /* read characters as they are until the next " */
1460  while( p < len && paramstr[p] != '"' )
1461  {
1462  argv[argc][arglen] = paramstr[p];
1463  arglen++;
1464  p++;
1465  }
1466  p++; /* skip final " */
1467  break;
1468  case '\\':
1469  /* read next character as it is */
1470  p++;
1471  argv[argc][arglen] = paramstr[p];
1472  arglen++;
1473  p++;
1474  break;
1475  default:
1476  argv[argc][arglen] = paramstr[p];
1477  arglen++;
1478  p++;
1479  break;
1480  }
1481  }
1482  argv[argc][arglen] = '\0';
1483 
1484  /* check for empty argument */
1485  if( arglen == 0 )
1486  {
1487  SCIPfreeBufferArray(scip, &argv[argc]);
1488  }
1489  else
1490  argc++;
1491  }
1492 
1493  /* append file name as last argument */
1494  SCIP_CALL( SCIPduplicateBufferArray(scip, &argv[argc], filename, (int) strlen(filename)+1) ); /*lint !e866*/
1495  argc++;
1496 
1497  /* display parsed arguments */
1498  if( SCIPgetVerbLevel(scip) >= SCIP_VERBLEVEL_FULL )
1499  {
1500  SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "ZIMPL arguments:\n");
1501  for( i = 1; i < argc; ++i )
1502  {
1503  SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "%d: <%s>\n", i, argv[i]);
1504  }
1505  }
1506 
1507  /* call ZIMPL parser with arguments */
1508  if( !zpl_read_with_args(argv, argc, TRUE, (void*)readerdata) )
1509  readerdata->readerror = TRUE;
1510 
1511  /* free argument memory */
1512  for( i = argc - 1; i >= 1; --i )
1513  {
1514  SCIPfreeBufferArray(scip, &argv[i]);
1515  }
1516  SCIPfreeBufferArray(scip, &argv);
1517 
1518  if ( readerdata->retcode != SCIP_OKAY )
1519  {
1520  SCIPfreeBuffer(scip, &readerdata);
1521  return readerdata->retcode;
1522  }
1523  }
1524 
1525  if( changedir )
1526  {
1527  /* change directory back to old path */
1528  if( path != NULL )
1529  {
1530  if( chdir(oldpath) != 0 )
1531  {
1532  SCIPwarningMessage(scip, "error changing back to directory <%s>\n", oldpath);
1533  }
1534  }
1535  }
1536 
1537  if( readerdata->valid )
1538  {
1539  SCIP_Bool stored;
1540 
1541  assert(readerdata->sol != NULL);
1542 
1543  stored = FALSE;
1544 
1545  /* add primal solution to solution candidate storage, frees the solution afterwards */
1546  SCIP_CALL( SCIPaddSolFree(scip, &readerdata->sol, &stored) );
1547 
1548  if( stored )
1549  {
1550  SCIPverbMessage(scip, SCIP_VERBLEVEL_FULL, NULL, "ZIMPL starting solution candidate accepted\n");
1551  }
1552  }
1553 
1554  *result = SCIP_SUCCESS;
1555 
1556  /* evaluate if a reading error occurred */
1557  if( readerdata->readerror )
1558  retcode = SCIP_READERROR;
1559  else
1560  retcode = SCIP_OKAY;
1561 
1562  /* free primal solution candidate */
1563  if( readerdata->sol != NULL )
1564  {
1565  SCIP_CALL( SCIPfreeSol(scip, &readerdata->sol) );
1566  }
1567 
1568  /* free reader data */
1569  SCIPfreeBuffer(scip, &readerdata);
1570 
1571  return retcode;
1572 }
1573 
1574 
1575 #endif
1576 #endif
1577 
1578 
1579 /*
1580  * reader specific interface methods
1581  */
1582 
1583 /** includes the zpl file reader in SCIP */
1585  SCIP* scip /**< SCIP data structure */
1586  )
1587 {
1588 #ifdef WITH_ZIMPL
1589 #if (ZIMPL_VERSION >= 320)
1590  SCIP_READERDATA* readerdata;
1591  SCIP_READER* reader;
1592  char extcodename[SCIP_MAXSTRLEN];
1593 
1594  /* create zpl reader data */
1595  readerdata = NULL;
1596  reader = NULL;
1597  /* include zpl reader */
1598  SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
1599  assert(reader != NULL);
1600 
1601  SCIP_CALL( SCIPsetReaderCopy(scip, reader, readerCopyZpl) );
1602  SCIP_CALL( SCIPsetReaderRead(scip, reader, readerReadZpl) );
1603 
1604  /* add zpl reader parameters */
1606  "reading/zplreader/changedir", "should the current directory be changed to that of the ZIMPL file before parsing?",
1607  NULL, FALSE, TRUE, NULL, NULL) );
1609  "reading/zplreader/usestartsol", "should ZIMPL starting solutions be forwarded to SCIP?",
1610  NULL, FALSE, TRUE, NULL, NULL) );
1612  "reading/zplreader/parameters", "additional parameter string passed to the ZIMPL parser (or - for no additional parameters)",
1613  NULL, FALSE, "-", NULL, NULL) );
1614 
1615  (void) SCIPsnprintf(extcodename, SCIP_MAXSTRLEN, "ZIMPL %d.%d.%d", ZIMPL_VERSION/100, (ZIMPL_VERSION%100)/10, ZIMPL_VERSION%10);
1616  SCIP_CALL( SCIPincludeExternalCodeInformation(scip, extcodename, "Zuse Institute Mathematical Programming Language developed by T. Koch (zimpl.zib.de)"));
1617 #else
1618  SCIPwarningMessage(scip, "SCIP does only support ZIMPL 3.2.0 and higher. Please update your ZIMPL version %d.%d.%d\n",
1619  ZIMPL_VERSION/100, (ZIMPL_VERSION%100)/10, ZIMPL_VERSION%10);
1620 #endif
1621 #endif
1622 
1623  return SCIP_OKAY;
1624 }
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16443
SCIP_RETCODE SCIPaddSolFree(SCIP *scip, SCIP_SOL **sol, SCIP_Bool *stored)
Definition: scip.c:36107
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:20589
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:41648
const char * SCIPreaderGetName(SCIP_READER *reader)
Definition: reader.c:510
SCIP_RETCODE SCIPaddVar(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:10378
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
Definition: scip.c:1248
SCIP_RETCODE SCIPcreateVar(SCIP *scip, SCIP_VAR **var, const char *name, SCIP_Real lb, SCIP_Real ub, SCIP_Real obj, SCIP_VARTYPE vartype, SCIP_Bool initial, SCIP_Bool removable, SCIP_DECL_VARDELORIG((*vardelorig)), SCIP_DECL_VARTRANS((*vartrans)), SCIP_DECL_VARDELTRANS((*vardeltrans)), SCIP_DECL_VARCOPY((*varcopy)), SCIP_VARDATA *vardata)
Definition: scip.c:15737
#define SCIP_MAXSTRLEN
Definition: def.h:201
#define NULL
Definition: lpi_spx.cpp:130
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17067
SCIP_RETCODE SCIPexprCreateMonomial(BMS_BLKMEM *blkmem, SCIP_EXPRDATA_MONOMIAL **monomial, SCIP_Real coef, int nfactors, int *childidxs, SCIP_Real *exponents)
Definition: expr.c:6913
void SCIPsplitFilename(char *filename, char **path, char **name, char **extension, char **compression)
Definition: misc.c:8363
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:34843
constraint handler for indicator constraints
SCIP_RETCODE SCIPaddVarIndicator(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
#define FALSE
Definition: def.h:56
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2057
SCIP_RETCODE SCIPincludeExternalCodeInformation(SCIP *scip, const char *name, const char *description)
Definition: scip.c:8711
#define READER_NAME
Definition: reader_bnd.c:36
SCIP_RETCODE SCIPexprtreeSetVars(SCIP_EXPRTREE *tree, int nvars, SCIP_VAR **vars)
Definition: nlp.c:111
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:8174
#define TRUE
Definition: def.h:55
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
#define SCIP_CALL(x)
Definition: def.h:266
SCIP_RETCODE SCIPchgVarObj(SCIP *scip, SCIP_VAR *var, SCIP_Real newobj)
Definition: scip.c:19590
#define READER_DESC
Definition: reader_bnd.c:37
#define SCIPdebugMessage
Definition: pub_message.h:77
SCIP_RETCODE SCIPcreateConsIndicator(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_VAR *binvar, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
Definition: var.c:16905
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2116
SCIP_RETCODE SCIPexprtreeCreate(BMS_BLKMEM *blkmem, SCIP_EXPRTREE **tree, SCIP_EXPR *root, int nvars, int nparams, SCIP_Real *params)
Definition: expr.c:8611
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:24949
SCIP_RETCODE SCIPgetStringParam(SCIP *scip, const char *name, char **value)
Definition: scip.c:3835
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:3547
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2159
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
Definition: scip.c:4601
SCIP_RETCODE SCIPcreateConsQuadratic(SCIP *scip, SCIP_CONS **cons, const char *name, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, int nquadterms, SCIP_VAR **quadvars1, SCIP_VAR **quadvars2, SCIP_Real *quadcoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable)
SCIP_RETCODE SCIPexprAddMonomials(BMS_BLKMEM *blkmem, SCIP_EXPR *expr, int nmonomials, SCIP_EXPRDATA_MONOMIAL **monomials, SCIP_Bool copymonomials)
Definition: expr.c:6545
#define SCIPerrorMessage
Definition: pub_message.h:45
enum SCIP_ExprOp SCIP_EXPROP
Definition: type_expr.h:89
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)
Definition: scip.c:34002
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:41353
ZIMPL model file reader.
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2075
constraint handler for quadratic constraints
SCIP_RETCODE SCIPcreateProb(SCIP *scip, const char *name, SCIP_DECL_PROBDELORIG((*probdelorig)), SCIP_DECL_PROBTRANS((*probtrans)), SCIP_DECL_PROBDELTRANS((*probdeltrans)), SCIP_DECL_PROBINITSOL((*probinitsol)), SCIP_DECL_PROBEXITSOL((*probexitsol)), SCIP_DECL_PROBCOPY((*probcopy)), SCIP_PROBDATA *probdata)
Definition: scip.c:9019
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:41637
SCIP_RETCODE SCIPexprCreatePolynomial(BMS_BLKMEM *blkmem, SCIP_EXPR **expr, int nchildren, SCIP_EXPR **children, int nmonomials, SCIP_EXPRDATA_MONOMIAL **monomials, SCIP_Real constant, SCIP_Bool copymonomials)
Definition: expr.c:6510
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
Definition: scip.c:4649
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip.h:20598
SCIP_RETCODE SCIPaddStringParam(SCIP *scip, const char *name, const char *desc, char **valueptr, SCIP_Bool isadvanced, const char *defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:3684
SCIP_RETCODE SCIPreleaseVar(SCIP *scip, SCIP_VAR **var)
Definition: scip.c:16884
SCIP_VERBLEVEL SCIPgetVerbLevel(SCIP *scip)
Definition: scip.c:1322
void SCIPexprMergeMonomialFactors(SCIP_EXPRDATA_MONOMIAL *monomial, SCIP_Real eps)
Definition: expr.c:6834
struct SCIP_ReaderData SCIP_READERDATA
Definition: type_reader.h:37
public data structures and miscellaneous methods
SCIP_RETCODE SCIPcreateConsNonlinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nlinvars, SCIP_VAR **linvars, SCIP_Real *lincoefs, int nexprtrees, SCIP_EXPRTREE **exprtrees, SCIP_Real *nonlincoefs, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define SCIP_Bool
Definition: def.h:53
enum SCIP_Objsense SCIP_OBJSENSE
Definition: type_prob.h:41
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Definition: scip.c:4563
constraint handler for nonlinear constraints
SCIP_RETCODE SCIPaddVarSOS2(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
Definition: cons_sos2.c:2369
SCIP_CONS * SCIPfindCons(SCIP *scip, const char *name)
Definition: scip.c:11641
SCIP_RETCODE SCIPexprCreate(BMS_BLKMEM *blkmem, SCIP_EXPR **expr, SCIP_EXPROP op,...)
Definition: expr.c:5853
SCIP_RETCODE SCIPexprtreeFree(SCIP_EXPRTREE **tree)
Definition: expr.c:8692
SCIP_RETCODE SCIPcreateConsSOS2(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_sos2.c:2270
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:89
SCIP_RETCODE SCIPchgVarBranchPriority(SCIP *scip, SCIP_VAR *var, int branchpriority)
Definition: scip.c:22487
SCIPInterval log(const SCIPInterval &x)
SCIP_RETCODE SCIPcreateConsSOS1(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_sos1.c:10266
Constraint handler for linear constraints in their most general form, .
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip.c:1298
#define SCIP_DECL_READERCOPY(x)
Definition: type_reader.h:46
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:11477
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
Definition: var.c:16608
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:20585
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17057
SCIP_RETCODE SCIPsetObjsense(SCIP *scip, SCIP_OBJSENSE objsense)
Definition: scip.c:10014
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip.h:20593
#define SCIP_Real
Definition: def.h:127
SCIP_RETCODE SCIPsetBinaryVarIndicator(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *binvar)
constraint handler for SOS type 1 constraints
#define SCIP_DECL_READERREAD(x)
Definition: type_reader.h:71
SCIP_RETCODE SCIPexprAddMonomialFactors(BMS_BLKMEM *blkmem, SCIP_EXPRDATA_MONOMIAL *monomial, int nfactors, int *childidxs, SCIP_Real *exponents)
Definition: expr.c:6740
#define SCIPfreeBuffer(scip, ptr)
Definition: scip.h:20595
enum SCIP_Vartype SCIP_VARTYPE
Definition: type_var.h:58
constraint handler for SOS type 2 constraints
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:20597
#define READER_EXTENSION
Definition: reader_bnd.c:38
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip.c:41422
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:2094
SCIP_RETCODE SCIPincludeReaderZpl(SCIP *scip)
Definition: reader_zpl.c:1584
SCIP_RETCODE SCIPaddVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
Definition: cons_sos1.c:10403
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
Definition: scip.c:3740
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
Definition: scip.c:34607
#define SCIPallocBuffer(scip, ptr)
Definition: scip.h:20583