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