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