Scippy

SCIP

Solving Constraint Integer Programs

matrix.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-2015 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 matrix.c
17  * @brief methods for MILP matrix data structure
18  * @author Dieter Weninger
19  *
20  * The MILP matrix is organized as sparse data structure in row and
21  * and column major format.
22  */
23 
24 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
25 
26 #include <assert.h>
27 #include <string.h>
28 
29 #include "scip/def.h"
30 #include "scip/struct_matrix.h"
31 #include "scip/pub_matrix.h"
32 
33 #include "scip/cons_knapsack.h"
34 #include "scip/cons_linear.h"
35 #include "scip/cons_logicor.h"
36 #include "scip/cons_setppc.h"
37 #include "scip/cons_varbound.h"
38 
39 /*
40  * private functions
41  */
42 
43 /** transforms given variables, scalars and constant to the corresponding active variables, scalars and constant */
44 static
46  SCIP* scip, /**< SCIP instance */
47  SCIP_VAR*** vars, /**< vars array to get active variables for */
48  SCIP_Real** scalars, /**< scalars a_1, ..., a_n in linear sum a_1*x_1 + ... + a_n*x_n + c */
49  int* nvars, /**< pointer to number of variables and values in vars and vals array */
50  SCIP_Real* constant /**< pointer to constant c in linear sum a_1*x_1 + ... + a_n*x_n + c */
51  )
52 {
53  int requiredsize;
54 
55  assert(scip != NULL);
56  assert(vars != NULL);
57  assert(scalars != NULL);
58  assert(*vars != NULL);
59  assert(*scalars != NULL);
60  assert(nvars != NULL);
61  assert(constant != NULL);
62 
63  SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
64 
65  if( requiredsize > *nvars )
66  {
67  SCIP_CALL( SCIPreallocBufferArray(scip, vars, requiredsize) );
68  SCIP_CALL( SCIPreallocBufferArray(scip, scalars, requiredsize) );
69 
70  /* call function a second time with enough memory */
71  SCIP_CALL( SCIPgetProbvarLinearSum(scip, *vars, *scalars, nvars, requiredsize, constant, &requiredsize, TRUE) );
72  assert(requiredsize <= *nvars);
73  }
74 
75  return SCIP_OKAY;
76 }
77 
78 /** add one row to the constraint matrix */
79 static
81  SCIP* scip, /**< SCIP data structure */
82  SCIPMILPMATRIX* matrix, /**< constraint matrix */
83  SCIP_VAR** vars, /**< variables of this row */
84  SCIP_Real* vals, /**< coefficients of this row */
85  int nvars, /**< number of variables of this row */
86  SCIP_Real lhs, /**< left hand side */
87  SCIP_Real rhs, /**< right hand side */
88  int maxnnonzsmem, /**< maximal number of fillable elements */
89  SCIP_Bool* rowadded /**< flag indicating if constraint was added to matrix */
90  )
91 {
92  int j;
93  int probindex;
94  int rowidx;
95  SCIP_Real factor;
96  SCIP_Bool rangedorequality;
97 
98  assert(vars != NULL);
99  assert(vals != NULL);
100 
101  rowidx = matrix->nrows;
102  rangedorequality = FALSE;
103 
104  if( SCIPisInfinity(scip, -lhs) )
105  {
106  factor = -1.0;
107  matrix->lhs[rowidx] = -rhs;
108  matrix->rhs[rowidx] = SCIPinfinity(scip);
109  matrix->isrhsinfinite[rowidx] = TRUE;
110  }
111  else
112  {
113  factor = 1.0;
114  matrix->lhs[rowidx] = lhs;
115  matrix->rhs[rowidx] = rhs;
116  matrix->isrhsinfinite[rowidx] = SCIPisInfinity(scip, matrix->rhs[rowidx]);
117 
118  if( !SCIPisInfinity(scip, rhs) )
119  rangedorequality = TRUE;
120  }
121 
122  if(SCIPisInfinity(scip, -matrix->lhs[rowidx]))
123  {
124  /* ignore redundant constraint */
125  *rowadded = FALSE;
126  return SCIP_OKAY;
127  }
128 
129  matrix->rowmatbeg[rowidx] = matrix->nnonzs;
130 
131  /* = or ranged */
132  if( rangedorequality )
133  {
134  assert(factor > 0);
135 
136  for( j = 0; j < nvars; j++ )
137  {
138  assert(maxnnonzsmem > matrix->nnonzs);
139 
140  /* ignore variables with very small coefficients */
141  if( SCIPisZero(scip, vals[j]) )
142  continue;
143 
144  matrix->rowmatval[matrix->nnonzs] = factor * vals[j];
145  probindex = SCIPvarGetProbindex(vars[j]);
146  assert(matrix->vars[probindex] == vars[j]);
147 
148  matrix->nuplocks[probindex]++;
149  matrix->ndownlocks[probindex]++;
150 
151  assert(0 <= probindex && probindex < matrix->ncols);
152  matrix->rowmatind[matrix->nnonzs] = probindex;
153 
154  (matrix->nnonzs)++;
155  }
156  }
157  /* >= or <= */
158  else
159  {
160  for( j = 0; j < nvars; j++ )
161  {
162  assert(maxnnonzsmem > matrix->nnonzs);
163 
164  /* ignore variables with very small coefficients */
165  if( SCIPisZero(scip, vals[j]) )
166  continue;
167 
168  /* due to the factor, <= constraints will be transfered to >= */
169  matrix->rowmatval[matrix->nnonzs] = factor * vals[j];
170  probindex = SCIPvarGetProbindex(vars[j]);
171  assert(matrix->vars[probindex] == vars[j]);
172 
173  if( matrix->rowmatval[matrix->nnonzs] > 0 )
174  matrix->ndownlocks[probindex]++;
175  else
176  {
177  assert(matrix->rowmatval[matrix->nnonzs] < 0);
178  matrix->nuplocks[probindex]++;
179  }
180 
181  assert(0 <= probindex && probindex < matrix->ncols);
182  matrix->rowmatind[matrix->nnonzs] = probindex;
183 
184  (matrix->nnonzs)++;
185  }
186  }
187 
188  matrix->rowmatcnt[rowidx] = matrix->nnonzs - matrix->rowmatbeg[rowidx];
189 
190  ++(matrix->nrows);
191  *rowadded = TRUE;
192 
193  return SCIP_OKAY;
194 }
195 
196 /** add one constraint to matrix */
197 static
199  SCIP* scip, /**< current scip instance */
200  SCIPMILPMATRIX* matrix, /**< constraint matrix */
201  SCIP_VAR** vars, /**< variables of this constraint */
202  SCIP_Real* vals, /**< variable coefficients of this constraint */
203  int nvars, /**< number of variables */
204  SCIP_Real lhs, /**< left hand side */
205  SCIP_Real rhs, /**< right hand side */
206  int maxnnonzsmem, /**< maximal number of fillable elements */
207  SCIP_Bool* rowadded /**< flag indicating of row was added to matrix */
208  )
209 {
210  SCIP_VAR** activevars;
211  SCIP_Real* activevals;
212  SCIP_Real activeconstant;
213  int nactivevars;
214  int v;
215 
216  assert(scip != NULL);
217  assert(matrix != NULL);
218  assert(vars != NULL || nvars == 0);
219  assert(SCIPisLE(scip, lhs, rhs));
220  assert(rowadded != NULL);
221 
222  *rowadded = FALSE;
223 
224  /* constraint is redundant */
225  if( SCIPisInfinity(scip, -lhs) && SCIPisInfinity(scip, rhs) )
226  return SCIP_OKAY;
227 
228  /* we do not add empty constraints to the matrix */
229  if( nvars == 0 )
230  return SCIP_OKAY;
231 
232  activevars = NULL;
233  activevals = NULL;
234  nactivevars = nvars;
235  activeconstant = 0.0;
236 
237  /* duplicate variable and value array */
238  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevars, vars, nactivevars ) );
239  if( vals != NULL )
240  {
241  SCIP_CALL( SCIPduplicateBufferArray(scip, &activevals, vals, nactivevars ) );
242  }
243  else
244  {
245  SCIP_CALL( SCIPallocBufferArray(scip, &activevals, nactivevars) );
246 
247  for( v = 0; v < nactivevars; v++ )
248  activevals[v] = 1.0;
249  }
250 
251  /* retransform given variables to active variables */
252  SCIP_CALL( getActiveVariables(scip, &activevars, &activevals, &nactivevars, &activeconstant) );
253 
254  /* adapt left and right hand side */
255  if( !SCIPisInfinity(scip, -lhs) )
256  lhs -= activeconstant;
257  if( !SCIPisInfinity(scip, rhs) )
258  rhs -= activeconstant;
259 
260  /* add single row to matrix */
261  if( nactivevars > 0 )
262  {
263  SCIP_CALL( addRow(scip, matrix, activevars, activevals, nactivevars, lhs, rhs, maxnnonzsmem, rowadded) );
264  }
265 
266  /* free buffer arrays */
267  SCIPfreeBufferArray(scip, &activevals);
268  SCIPfreeBufferArray(scip, &activevars);
269 
270  return SCIP_OKAY;
271 }
272 
273 /** transform row major format into column major format */
274 static
276  SCIP* scip, /**< current scip instance */
277  SCIPMILPMATRIX* matrix /**< constraint matrix */
278  )
279 {
280  int colidx;
281  int i;
282  int* rowpnt;
283  int* rowend;
284  SCIP_Real* valpnt;
285  int* fillidx;
286 
287  assert(scip != NULL);
288  assert(matrix != NULL);
289  assert(matrix->colmatval != NULL);
290  assert(matrix->colmatind != NULL);
291  assert(matrix->colmatbeg != NULL);
292  assert(matrix->colmatcnt != NULL);
293  assert(matrix->rowmatval != NULL);
294  assert(matrix->rowmatind != NULL);
295  assert(matrix->rowmatbeg != NULL);
296  assert(matrix->rowmatcnt != NULL);
297 
298  SCIP_CALL( SCIPallocBufferArray(scip, &fillidx, matrix->ncols) );
299  BMSclearMemoryArray(fillidx, matrix->ncols);
300  BMSclearMemoryArray(matrix->colmatcnt, matrix->ncols);
301 
302  for( i = 0; i < matrix->nrows; i++ )
303  {
304  rowpnt = matrix->rowmatind + matrix->rowmatbeg[i];
305  rowend = rowpnt + matrix->rowmatcnt[i];
306  for( ; rowpnt < rowend; rowpnt++ )
307  {
308  colidx = *rowpnt;
309  (matrix->colmatcnt[colidx])++;
310  }
311  }
312 
313  matrix->colmatbeg[0] = 0;
314  for( i = 0; i < matrix->ncols-1; i++ )
315  {
316  matrix->colmatbeg[i+1] = matrix->colmatbeg[i] + matrix->colmatcnt[i];
317  }
318 
319  for( i = 0; i < matrix->nrows; i++ )
320  {
321  rowpnt = matrix->rowmatind + matrix->rowmatbeg[i];
322  rowend = rowpnt + matrix->rowmatcnt[i];
323  valpnt = matrix->rowmatval + matrix->rowmatbeg[i];
324 
325  for( ; rowpnt < rowend; rowpnt++, valpnt++ )
326  {
327  assert(*rowpnt < matrix->ncols);
328  colidx = *rowpnt;
329  matrix->colmatval[matrix->colmatbeg[colidx] + fillidx[colidx]] = *valpnt;
330  matrix->colmatind[matrix->colmatbeg[colidx] + fillidx[colidx]] = i;
331  fillidx[colidx]++;
332  }
333  }
334 
335  SCIPfreeBufferArray(scip, &fillidx);
336 
337  return SCIP_OKAY;
338 }
339 
340 /** calculate min/max activity per row */
341 static
343  SCIP* scip, /**< current scip instance */
344  SCIPMILPMATRIX* matrix /**< constraint matrix */
345  )
346 {
347  SCIP_Real val;
348  int* rowpnt;
349  int* rowend;
350  SCIP_Real* valpnt;
351  int col;
352  int row;
353 
354  assert(scip != NULL);
355  assert(matrix != NULL);
356 
357  for( row = 0; row < matrix->nrows; row++ )
358  {
359  matrix->minactivity[row] = 0;
360  matrix->maxactivity[row] = 0;
361  matrix->minactivityneginf[row] = 0;
362  matrix->minactivityposinf[row] = 0;
363  matrix->maxactivityneginf[row] = 0;
364  matrix->maxactivityposinf[row] = 0;
365 
366  rowpnt = matrix->rowmatind + matrix->rowmatbeg[row];
367  rowend = rowpnt + matrix->rowmatcnt[row];
368  valpnt = matrix->rowmatval + matrix->rowmatbeg[row];
369 
370  for( ; rowpnt < rowend; rowpnt++, valpnt++ )
371  {
372  /* get column index */
373  col = *rowpnt;
374 
375  /* get variable coefficient */
376  val = *valpnt;
377  assert(!SCIPisZero(scip, val));
378 
379  assert(matrix->ncols > col);
380 
381  assert(!SCIPisInfinity(scip, matrix->lb[col]));
382  assert(!SCIPisInfinity(scip, -matrix->ub[col]));
383 
384  /* positive coefficient */
385  if( val > 0.0 )
386  {
387  if( SCIPisInfinity(scip, matrix->ub[col]) )
388  matrix->maxactivityposinf[row]++;
389  else
390  matrix->maxactivity[row] += val * matrix->ub[col];
391 
392  if( SCIPisInfinity(scip, -matrix->lb[col]) )
393  matrix->minactivityneginf[row]++;
394  else
395  matrix->minactivity[row] += val * matrix->lb[col];
396  }
397  /* negative coefficient */
398  else
399  {
400  if( SCIPisInfinity(scip, -matrix->lb[col]) )
401  matrix->maxactivityneginf[row]++;
402  else
403  matrix->maxactivity[row] += val * matrix->lb[col];
404 
405  if( SCIPisInfinity(scip, matrix->ub[col]) )
406  matrix->minactivityposinf[row]++;
407  else
408  matrix->minactivity[row] += val * matrix->ub[col];
409  }
410  }
411 
412  /* consider infinite bound contributions for the activities */
413  if( matrix->maxactivityneginf[row] + matrix->maxactivityposinf[row] > 0 )
414  matrix->maxactivity[row] = SCIPinfinity(scip);
415 
416  if( matrix->minactivityneginf[row] + matrix->minactivityposinf[row] > 0 )
417  matrix->minactivity[row] = -SCIPinfinity(scip);
418 
419  }
420 
421  return SCIP_OKAY;
422 }
423 
424 /*
425  * public functions
426  */
427 
428 /** initialize matrix */
430  SCIP* scip, /**< current scip instance */
431  SCIPMILPMATRIX** matrixptr, /**< pointer to constraint matrix object to be initialized */
432  SCIP_Bool* initialized, /**< was the initialization successful? */
433  SCIP_Bool* complete /**< are all constraint represented within the matrix? */
434  )
435 {
436  SCIPMILPMATRIX* matrix;
437  SCIP_CONSHDLR** conshdlrs;
438  const char* conshdlrname;
439  SCIP_Bool stopped;
440  SCIP_VAR** vars;
441  SCIP_VAR* var;
442  SCIP_CONS* cons;
443  int nconshdlrs;
444  int nconss;
445  int nconssall;
446  int nnonzstmp;
447  int nvars;
448  int c;
449  int i;
450  int v;
451  int cnt;
452 
453  nnonzstmp = 0;
454 
455  assert(scip != NULL);
456  assert(matrixptr != NULL);
457  assert(initialized != NULL);
458  assert(complete != NULL);
459 
460  *initialized = FALSE;
461  *complete = FALSE;
462 
463  /* return if no variables or constraints are present */
464  if( SCIPgetNVars(scip) == 0 || SCIPgetNConss(scip) == 0 )
465  return SCIP_OKAY;
466 
467  /* loop over all constraint handlers and collect the number of checked constraints */
468  nconshdlrs = SCIPgetNConshdlrs(scip);
469  conshdlrs = SCIPgetConshdlrs(scip);
470  nconss = 0;
471  nconssall = 0;
472 
473  for( i = 0; i < nconshdlrs; ++i )
474  {
475  int nconshdlrconss;
476 
477  nconshdlrconss = SCIPconshdlrGetNCheckConss(conshdlrs[i]);
478 
479  if( nconshdlrconss > 0 )
480  {
481  conshdlrname = SCIPconshdlrGetName(conshdlrs[i]);
482 
483  if( (strcmp(conshdlrname, "linear") == 0) || (strcmp(conshdlrname, "setppc") == 0)
484  || (strcmp(conshdlrname, "logicor") == 0) || (strcmp(conshdlrname, "knapsack") == 0)
485  || (strcmp(conshdlrname, "varbound") == 0) )
486  {
487  /* increment number of supported constraints */
488  nconss += nconshdlrconss;
489  }
490 
491  /* increment number of supported and unsupported constraints */
492  nconssall += nconshdlrconss;
493  }
494  }
495 
496  /* print warning if we have unsupported constraint types.
497  * we do not abort the matrix creation process here, because
498  * it makes sometimes sense to work on an incomplete
499  * matrix as long as the number of interesting variable
500  * uplocks or downlocks of the matrix and scip
501  * are the same.
502  */
503  if( nconss < nconssall )
504  {
505  SCIPdebugMessage("Warning: milp matrix not complete!\n");
506  }
507  else
508  {
509  /* all constraints represented within the matrix */
510  *complete = TRUE;
511  }
512 
513  /* do nothing if we have no checked constraints */
514  if( nconss == 0 )
515  return SCIP_OKAY;
516 
517  stopped = FALSE;
518 
519  vars = SCIPgetVars(scip);
520  nvars = SCIPgetNVars(scip);
521 
522  /* approximate number of nonzeros by taking for each variable the number of up- and downlocks;
523  * this counts nonzeros in equalities twice, but can be at most two times as high as the exact number
524  */
525  for( i = nvars - 1; i >= 0; --i )
526  {
527  nnonzstmp += SCIPvarGetNLocksDown(vars[i]);
528  nnonzstmp += SCIPvarGetNLocksUp(vars[i]);
529  }
530 
531  /* do nothing if we have no entries */
532  if( nnonzstmp == 0 )
533  return SCIP_OKAY;
534 
535  /* build the matrix structure */
536  SCIP_CALL( SCIPallocBuffer(scip, matrixptr) );
537  matrix = *matrixptr;
538 
539  /* copy vars array and set number of variables */
540  SCIP_CALL( SCIPduplicateBufferArray(scip, &matrix->vars, SCIPgetVars(scip), nvars) );
541  matrix->ncols = nvars;
542 
543  matrix->nrows = 0;
544  matrix->nnonzs = 0;
545 
546  /* allocate memory */
547  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colmatval, nnonzstmp) );
548  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colmatind, nnonzstmp) );
549  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colmatbeg, matrix->ncols) );
550  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->colmatcnt, matrix->ncols) );
551  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->lb, matrix->ncols) );
552  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->ub, matrix->ncols) );
553  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->nuplocks, matrix->ncols) );
554  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->ndownlocks, matrix->ncols) );
555 
556  BMSclearMemoryArray(matrix->nuplocks, matrix->ncols);
557  BMSclearMemoryArray(matrix->ndownlocks, matrix->ncols);
558 
559  /* init bounds */
560  for( v = 0; v < matrix->ncols; v++ )
561  {
562  var = matrix->vars[v];
563  assert(var != NULL);
564 
565  matrix->lb[v] = SCIPvarGetLbGlobal(var);
566  matrix->ub[v] = SCIPvarGetUbGlobal(var);
567  }
568 
569  /* allocate memory */
570  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rowmatval, nnonzstmp) );
571  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rowmatind, nnonzstmp) );
572  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rowmatbeg, nconss) );
573  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rowmatcnt, nconss) );
574  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->lhs, nconss) );
575  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->rhs, nconss) );
576  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->cons, nconss) );
577  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->constype, nconss) );
578  SCIP_CALL( SCIPallocClearMemoryArray(scip, &matrix->isrhsinfinite, nconss) );
579  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->minactivity, nconss) );
580  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->maxactivity, nconss) );
581  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->minactivityneginf, nconss) );
582  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->minactivityposinf, nconss) );
583  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->maxactivityneginf, nconss) );
584  SCIP_CALL( SCIPallocBufferArray(scip, &matrix->maxactivityposinf, nconss) );
585 
586  cnt = 0;
587 
588  /* loop a second time over constraints handlers and add supported constraints to the matrix */
589  for( i = 0; i < nconshdlrs; ++i )
590  {
591  SCIP_CONS** conshdlrconss;
592  int nconshdlrconss;
593  SCIP_Bool rowadded;
594 
595  if( SCIPisStopped(scip) )
596  {
597  stopped = TRUE;
598  break;
599  }
600 
601  conshdlrname = SCIPconshdlrGetName(conshdlrs[i]);
602  conshdlrconss = SCIPconshdlrGetCheckConss(conshdlrs[i]);
603  nconshdlrconss = SCIPconshdlrGetNCheckConss(conshdlrs[i]);
604 
605  if( strcmp(conshdlrname, "linear") == 0 )
606  {
607  for( c = 0; c < nconshdlrconss && (c % 1000 != 0 || !SCIPisStopped(scip)); ++c )
608  {
609  cons = conshdlrconss[c];
610  assert(SCIPconsIsTransformed(cons));
611 
612  SCIP_CALL( addConstraint(scip, matrix, SCIPgetVarsLinear(scip, cons),
613  SCIPgetValsLinear(scip, cons), SCIPgetNVarsLinear(scip, cons),
614  SCIPgetLhsLinear(scip, cons), SCIPgetRhsLinear(scip, cons), nnonzstmp, &rowadded) );
615 
616  if(rowadded)
617  {
618  assert(cnt < nconss);
619  matrix->cons[cnt] = cons;
620  matrix->constype[cnt] = CONSTYPE_LINEAR;
621  cnt++;
622  }
623  }
624  }
625  else if( strcmp(conshdlrname, "setppc") == 0 )
626  {
627  for( c = 0; c < nconshdlrconss && (c % 1000 != 0 || !SCIPisStopped(scip)); ++c )
628  {
629  SCIP_Real lhs;
630  SCIP_Real rhs;
631 
632  cons = conshdlrconss[c];
633  assert(SCIPconsIsTransformed(cons));
634 
635  switch( SCIPgetTypeSetppc(scip, cons) )
636  {
638  lhs = 1.0;
639  rhs = 1.0;
640  break;
642  lhs = -SCIPinfinity(scip);
643  rhs = 1.0;
644  break;
646  lhs = 1.0;
647  rhs = SCIPinfinity(scip);
648  break;
649  default:
650  return SCIP_ERROR;
651  }
652 
653  SCIP_CALL( addConstraint(scip, matrix, SCIPgetVarsSetppc(scip, cons), NULL,
654  SCIPgetNVarsSetppc(scip, cons), lhs, rhs, nnonzstmp, &rowadded) );
655 
656  if(rowadded)
657  {
658  assert(cnt < nconss);
659  matrix->cons[cnt] = cons;
660  matrix->constype[cnt] = CONSTYPE_SETPPC;
661  cnt++;
662  }
663  }
664  }
665  else if( strcmp(conshdlrname, "logicor") == 0 )
666  {
667  for( c = 0; c < nconshdlrconss && (c % 1000 != 0 || !SCIPisStopped(scip)); ++c )
668  {
669  cons = conshdlrconss[c];
670  assert(SCIPconsIsTransformed(cons));
671 
672  SCIP_CALL( addConstraint(scip, matrix, SCIPgetVarsLogicor(scip, cons),
673  NULL, SCIPgetNVarsLogicor(scip, cons), 1.0, SCIPinfinity(scip), nnonzstmp, &rowadded) );
674 
675  if(rowadded)
676  {
677  assert(cnt < nconss);
678  matrix->cons[cnt] = cons;
679  matrix->constype[cnt] = CONSTYPE_LOGICOR;
680  cnt++;
681  }
682  }
683  }
684  else if( strcmp(conshdlrname, "knapsack") == 0 )
685  {
686  if( nconshdlrconss > 0 )
687  {
688  SCIP_Real* consvals;
689  int valssize;
690 
691  valssize = 100;
692  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, valssize) );
693 
694  for( c = 0; c < nconshdlrconss && (c % 1000 != 0 || !SCIPisStopped(scip)); ++c )
695  {
696  SCIP_Longint* weights;
697 
698  cons = conshdlrconss[c];
699  assert(SCIPconsIsTransformed(cons));
700 
701  weights = SCIPgetWeightsKnapsack(scip, cons);
702  nvars = SCIPgetNVarsKnapsack(scip, cons);
703 
704  if( nvars > valssize )
705  {
706  valssize = (int) (1.5 * nvars);
707  SCIP_CALL( SCIPreallocBufferArray(scip, &consvals, valssize) );
708  }
709 
710  for( v = 0; v < nvars; v++ )
711  consvals[v] = (SCIP_Real)weights[v];
712 
713  SCIP_CALL( addConstraint(scip, matrix, SCIPgetVarsKnapsack(scip, cons), consvals,
714  SCIPgetNVarsKnapsack(scip, cons), -SCIPinfinity(scip),
715  (SCIP_Real)SCIPgetCapacityKnapsack(scip, cons), nnonzstmp, &rowadded) );
716 
717  if(rowadded)
718  {
719  assert(cnt < nconss);
720  matrix->cons[cnt] = cons;
721  matrix->constype[cnt] = CONSTYPE_KNAPSACK;
722  cnt++;
723  }
724  }
725 
726  SCIPfreeBufferArray(scip, &consvals);
727  }
728  }
729  else if( strcmp(conshdlrname, "varbound") == 0 )
730  {
731  if( nconshdlrconss > 0 )
732  {
733  SCIP_VAR** consvars;
734  SCIP_Real* consvals;
735 
736  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, 2) );
737  SCIP_CALL( SCIPallocBufferArray(scip, &consvals, 2) );
738  consvals[0] = 1.0;
739 
740  for( c = 0; c < nconshdlrconss && (c % 1000 != 0 || !SCIPisStopped(scip)); ++c )
741  {
742  cons = conshdlrconss[c];
743  assert(SCIPconsIsTransformed(cons));
744 
745  consvars[0] = SCIPgetVarVarbound(scip, cons);
746  consvars[1] = SCIPgetVbdvarVarbound(scip, cons);
747 
748  consvals[1] = SCIPgetVbdcoefVarbound(scip, cons);
749 
750  SCIP_CALL( addConstraint(scip, matrix, consvars, consvals, 2, SCIPgetLhsVarbound(scip, cons),
751  SCIPgetRhsVarbound(scip, cons), nnonzstmp, &rowadded) );
752 
753  if(rowadded)
754  {
755  assert(cnt < nconss);
756  matrix->cons[cnt] = cons;
757  matrix->constype[cnt] = CONSTYPE_VARBOUND;
758  cnt++;
759  }
760  }
761 
762  SCIPfreeBufferArray(scip, &consvals);
763  SCIPfreeBufferArray(scip, &consvars);
764  }
765  }
766  }
767  assert(matrix->nrows == cnt);
768  assert(matrix->nrows <= nconss);
769  assert(matrix->nnonzs <= nnonzstmp);
770 
771  if( !stopped )
772  {
773  /* calculate row activity bounds */
774  SCIP_CALL( calcActivityBounds(scip, matrix) );
775 
776  /* transform row major format into column major format */
777  SCIP_CALL( setColumnMajorFormat(scip, matrix) );
778 
779  *initialized = TRUE;
780  }
781 
782  return SCIP_OKAY;
783 }
784 
785 
786 /** frees the constraint matrix */
788  SCIP* scip, /**< current SCIP instance */
789  SCIPMILPMATRIX** matrix /**< constraint matrix object */
790  )
791 {
792  assert(scip != NULL);
793  assert(matrix != NULL);
794 
795  if( (*matrix) != NULL )
796  {
797  assert((*matrix)->colmatval != NULL);
798  assert((*matrix)->colmatind != NULL);
799  assert((*matrix)->colmatbeg != NULL);
800  assert((*matrix)->colmatcnt != NULL);
801  assert((*matrix)->lb != NULL);
802  assert((*matrix)->ub != NULL);
803  assert((*matrix)->nuplocks != NULL);
804  assert((*matrix)->ndownlocks != NULL);
805 
806  assert((*matrix)->rowmatval != NULL);
807  assert((*matrix)->rowmatind != NULL);
808  assert((*matrix)->rowmatbeg != NULL);
809  assert((*matrix)->rowmatcnt != NULL);
810  assert((*matrix)->lhs != NULL);
811  assert((*matrix)->rhs != NULL);
812 
813  SCIPfreeBufferArray(scip, &((*matrix)->maxactivityposinf));
814  SCIPfreeBufferArray(scip, &((*matrix)->maxactivityneginf));
815  SCIPfreeBufferArray(scip, &((*matrix)->minactivityposinf));
816  SCIPfreeBufferArray(scip, &((*matrix)->minactivityneginf));
817  SCIPfreeBufferArray(scip, &((*matrix)->maxactivity));
818  SCIPfreeBufferArray(scip, &((*matrix)->minactivity));
819 
820  SCIPfreeMemoryArray(scip, &((*matrix)->isrhsinfinite));
821  SCIPfreeBufferArray(scip, &((*matrix)->constype));
822  SCIPfreeBufferArray(scip, &((*matrix)->cons));
823 
824  SCIPfreeBufferArray(scip, &((*matrix)->rhs));
825  SCIPfreeBufferArray(scip, &((*matrix)->lhs));
826  SCIPfreeBufferArray(scip, &((*matrix)->rowmatcnt));
827  SCIPfreeBufferArray(scip, &((*matrix)->rowmatbeg));
828  SCIPfreeBufferArray(scip, &((*matrix)->rowmatind));
829  SCIPfreeBufferArray(scip, &((*matrix)->rowmatval));
830 
831  SCIPfreeBufferArray(scip, &((*matrix)->ndownlocks));
832  SCIPfreeBufferArray(scip, &((*matrix)->nuplocks));
833  SCIPfreeBufferArray(scip, &((*matrix)->ub));
834  SCIPfreeBufferArray(scip, &((*matrix)->lb));
835  SCIPfreeBufferArray(scip, &((*matrix)->colmatcnt));
836  SCIPfreeBufferArray(scip, &((*matrix)->colmatbeg));
837  SCIPfreeBufferArray(scip, &((*matrix)->colmatind));
838  SCIPfreeBufferArray(scip, &((*matrix)->colmatval));
839 
840  (*matrix)->nrows = 0;
841  (*matrix)->ncols = 0;
842  (*matrix)->nnonzs = 0;
843 
844  SCIPfreeBufferArrayNull(scip, &((*matrix)->vars));
845 
846  SCIPfreeBuffer(scip, matrix);
847  }
848 }
849 
850 /** print one row of the MILP matrix */
852  SCIP* scip, /**< current SCIP instance */
853  SCIPMILPMATRIX* matrix, /**< constraint matrix object */
854  int row /**< row index */
855  )
856 {
857  int* rowpnt;
858  int* rowend;
859  int col;
860  SCIP_Real val;
861  SCIP_Real* valpnt;
862 
863  rowpnt = matrix->rowmatind + matrix->rowmatbeg[row];
864  rowend = rowpnt + matrix->rowmatcnt[row];
865  valpnt = matrix->rowmatval + matrix->rowmatbeg[row];
866 
867  printf("### %s: %.15g <=", SCIPconsGetName(matrix->cons[row]), matrix->lhs[row]);
868  for(; (rowpnt < rowend); rowpnt++, valpnt++)
869  {
870  col = *rowpnt;
871  val = *valpnt;
872  if( val < 0 )
873  printf(" %.15g %s [%.15g,%.15g]", val, SCIPvarGetName(matrix->vars[col]),
874  SCIPvarGetLbGlobal(matrix->vars[col]), SCIPvarGetUbGlobal(matrix->vars[col]));
875  else
876  printf(" +%.15g %s [%.15g,%.15g]", val, SCIPvarGetName(matrix->vars[col]),
877  SCIPvarGetLbGlobal(matrix->vars[col]), SCIPvarGetUbGlobal(matrix->vars[col]));
878  }
879  printf(" <= %.15g ###\n", matrix->rhs[row]);
880 }
881 
882 /** detect parallel rows of matrix. rhs/lhs are ignored. */
884  SCIP* scip, /**< SCIP instance */
885  SCIPMILPMATRIX* matrix, /**< matrix containing the constraints */
886  SCIP_Real* scale, /**< scale factors of rows */
887  int* pclass /**< parallel row classes */
888  )
889 {
890  SCIP_Real* valpnt;
891  SCIP_Real* values;
892  int* classsizes;
893  int* pcset;
894  int* colpnt;
895  int* colend;
896  int* rowindices;
897  int* pcs;
898  SCIP_Real startval;
899  SCIP_Real aij;
900  int startpc;
901  int startk;
902  int startt;
903  int pcsetfill;
904  int rowidx;
905  int k;
906  int t;
907  int m;
908  int i;
909  int c;
910  int newpclass;
911  int pc;
912 
913  assert(scip != NULL);
914  assert(matrix != NULL);
915  assert(pclass != NULL);
916 
917  SCIP_CALL( SCIPallocBufferArray(scip, &classsizes, matrix->nrows) );
918  SCIP_CALL( SCIPallocBufferArray(scip, &pcset, matrix->nrows) );
919  SCIP_CALL( SCIPallocBufferArray(scip, &values, matrix->nrows) );
920  SCIP_CALL( SCIPallocBufferArray(scip, &rowindices, matrix->nrows) );
921  SCIP_CALL( SCIPallocBufferArray(scip, &pcs, matrix->nrows) );
922 
923  /* init */
924  BMSclearMemoryArray(scale, matrix->nrows);
925  BMSclearMemoryArray(pclass, matrix->nrows);
926  BMSclearMemoryArray(classsizes, matrix->nrows);
927  classsizes[0] = matrix->nrows;
928  pcsetfill = 0;
929  for( t = 1; t < matrix->nrows; ++t )
930  pcset[pcsetfill++] = t;
931 
932  /* loop over all columns */
933  for( c = 0; c < matrix->ncols; ++c )
934  {
935  if( matrix->colmatcnt[c] == 0 )
936  continue;
937 
938  colpnt = matrix->colmatind + matrix->colmatbeg[c];
939  colend = colpnt + matrix->colmatcnt[c];
940  valpnt = matrix->colmatval + matrix->colmatbeg[c];
941 
942  i = 0;
943  for( ; (colpnt < colend); colpnt++, valpnt++ )
944  {
945  aij = *valpnt;
946  rowidx = *colpnt;
947 
948  if( scale[rowidx] == 0.0 )
949  scale[rowidx] = aij;
950  assert(scale[rowidx] != 0.0);
951 
952  rowindices[i] = rowidx;
953  values[i] = aij / scale[rowidx];
954  pc = pclass[rowidx];
955  assert(pc < matrix->nrows);
956 
957  /* update class sizes and pclass set */
958  assert(classsizes[pc] > 0);
959  classsizes[pc]--;
960  if( classsizes[pc] == 0 )
961  {
962  assert(pcsetfill < matrix->nrows);
963  pcset[pcsetfill++] = pc;
964  }
965  pcs[i] = pc;
966 
967  i++;
968  }
969 
970  /* sort on the pclass values */
971  if( i > 1 )
972  {
973  SCIPsortIntIntReal(pcs, rowindices, values, i);
974  }
975 
976  k = 0;
977  while( TRUE ) /*lint !e716*/
978  {
979  assert(k < i);
980  startpc = pcs[k];
981  startk = k;
982 
983  /* find pclass-sets */
984  while( k < i && pcs[k] == startpc )
985  k++;
986 
987  /* sort on the A values which have equal pclass values */
988  if( k - startk > 1 )
989  SCIPsortRealInt(&(values[startk]), &(rowindices[startk]), k - startk);
990 
991  t = 0;
992  while( TRUE ) /*lint !e716*/
993  {
994  assert(startk + t < i);
995  startval = values[startk + t];
996  startt = t;
997 
998  /* find A-sets */
999  while( t < k - startk && SCIPisEQ(scip, startval, values[startk + t]) )
1000  t++;
1001 
1002  /* get new pclass */
1003  newpclass = pcset[0];
1004  assert(pcsetfill > 0);
1005  pcset[0] = pcset[--pcsetfill];
1006 
1007  /* renumbering */
1008  for( m = startk + startt; m < startk + t; m++ )
1009  {
1010  assert(m < i);
1011  assert(rowindices[m] < matrix->nrows);
1012  assert(newpclass < matrix->nrows);
1013 
1014  pclass[rowindices[m]] = newpclass;
1015  classsizes[newpclass]++;
1016  }
1017 
1018  if( t == k - startk )
1019  break;
1020  }
1021 
1022  if( k == matrix->colmatcnt[c] )
1023  break;
1024  }
1025  }
1026 
1027  SCIPfreeBufferArray(scip, &pcs);
1028  SCIPfreeBufferArray(scip, &rowindices);
1029  SCIPfreeBufferArray(scip, &values);
1030  SCIPfreeBufferArray(scip, &pcset);
1031  SCIPfreeBufferArray(scip, &classsizes);
1032 
1033  return SCIP_OKAY;
1034 }
1035 
1036 /** detect parallel rows of matrix.
1037  * obj coefficients are ignored.
1038  */
1040  SCIP* scip, /**< SCIP instance */
1041  SCIPMILPMATRIX* matrix, /**< matrix containing the constraints */
1042  SCIP_Real* scale, /**< scale factors of cols */
1043  int* pclass, /**< parallel column classes */
1044  SCIP_Bool* varineq /**< indicating if variable is within an equation */
1045  )
1046 {
1047  SCIP_Real* valpnt;
1048  SCIP_Real* values;
1049  int* classsizes;
1050  int* pcset;
1051  int* rowpnt;
1052  int* rowend;
1053  int* colindices;
1054  int* pcs;
1055  SCIP_Real startval;
1056  SCIP_Real aij;
1057  int startpc;
1058  int startk;
1059  int startt;
1060  int pcsetfill;
1061  int colidx;
1062  int k;
1063  int t;
1064  int m;
1065  int i;
1066  int r;
1067  int newpclass;
1068  int pc;
1069 
1070  assert(scip != NULL);
1071  assert(matrix != NULL);
1072  assert(pclass != NULL);
1073  assert(varineq != NULL);
1074 
1075  SCIP_CALL( SCIPallocBufferArray(scip, &classsizes, matrix->ncols) );
1076  SCIP_CALL( SCIPallocBufferArray(scip, &pcset, matrix->ncols) );
1077  SCIP_CALL( SCIPallocBufferArray(scip, &values, matrix->ncols) );
1078  SCIP_CALL( SCIPallocBufferArray(scip, &colindices, matrix->ncols) );
1079  SCIP_CALL( SCIPallocBufferArray(scip, &pcs, matrix->ncols) );
1080 
1081  /* init */
1082  BMSclearMemoryArray(scale, matrix->ncols);
1083  BMSclearMemoryArray(pclass, matrix->ncols);
1084  BMSclearMemoryArray(classsizes, matrix->ncols);
1085  classsizes[0] = matrix->ncols;
1086  pcsetfill = 0;
1087  for( t = 1; t < matrix->ncols; ++t )
1088  pcset[pcsetfill++] = t;
1089 
1090  /* loop over all rows */
1091  for( r = 0; r < matrix->nrows; ++r )
1092  {
1093  /* we consider only equations or ranged rows */
1094  if( !matrix->isrhsinfinite[r] )
1095  {
1096  rowpnt = matrix->rowmatind + matrix->rowmatbeg[r];
1097  rowend = rowpnt + matrix->rowmatcnt[r];
1098  valpnt = matrix->rowmatval + matrix->rowmatbeg[r];
1099 
1100  i = 0;
1101  for( ; (rowpnt < rowend); rowpnt++, valpnt++ )
1102  {
1103  aij = *valpnt;
1104  colidx = *rowpnt;
1105 
1106  /* remember variable was part of an equation or ranged row */
1107  varineq[colidx] = TRUE;
1108 
1109  if( scale[colidx] == 0.0 )
1110  scale[colidx] = aij;
1111  assert(scale[colidx] != 0.0);
1112 
1113  colindices[i] = colidx;
1114  values[i] = aij / scale[colidx];
1115  pc = pclass[colidx];
1116  assert(pc < matrix->ncols);
1117 
1118  /* update class sizes and pclass set */
1119  assert(classsizes[pc] > 0);
1120  classsizes[pc]--;
1121  if( classsizes[pc] == 0 )
1122  {
1123  assert(pcsetfill < matrix->ncols);
1124  pcset[pcsetfill++] = pc;
1125  }
1126  pcs[i] = pc;
1127 
1128  i++;
1129  }
1130 
1131  /* sort on the pclass values */
1132  if( i > 1 )
1133  {
1134  SCIPsortIntIntReal(pcs, colindices, values, i);
1135  }
1136 
1137  k = 0;
1138  while( TRUE ) /*lint !e716*/
1139  {
1140  assert(k < i);
1141  startpc = pcs[k];
1142  startk = k;
1143 
1144  /* find pclass-sets */
1145  while( k < i && pcs[k] == startpc )
1146  k++;
1147 
1148  /* sort on the A values which have equal pclass values */
1149  if( k - startk > 1 )
1150  SCIPsortRealInt(&(values[startk]), &(colindices[startk]), k - startk);
1151 
1152  t = 0;
1153  while( TRUE ) /*lint !e716*/
1154  {
1155  assert(startk + t < i);
1156  startval = values[startk + t];
1157  startt = t;
1158 
1159  /* find A-sets */
1160  while( t < k - startk && SCIPisEQ(scip, startval, values[startk + t]) )
1161  t++;
1162 
1163  /* get new pclass */
1164  newpclass = pcset[0];
1165  assert(pcsetfill > 0);
1166  pcset[0] = pcset[--pcsetfill];
1167 
1168  /* renumbering */
1169  for( m = startk + startt; m < startk + t; m++ )
1170  {
1171  assert(m < i);
1172  assert(colindices[m] < matrix->ncols);
1173  assert(newpclass < matrix->ncols);
1174 
1175  pclass[colindices[m]] = newpclass;
1176  classsizes[newpclass]++;
1177  }
1178 
1179  if( t == k - startk )
1180  break;
1181  }
1182 
1183  if( k == matrix->rowmatcnt[r] )
1184  break;
1185  }
1186  }
1187  }
1188 
1189  SCIPfreeBufferArray(scip, &pcs);
1190  SCIPfreeBufferArray(scip, &colindices);
1191  SCIPfreeBufferArray(scip, &values);
1192  SCIPfreeBufferArray(scip, &pcset);
1193  SCIPfreeBufferArray(scip, &classsizes);
1194 
1195  return SCIP_OKAY;
1196 }
1197 
1198 
1199 /*
1200  * access functions implemented as defines
1201  */
1202 
1203 /* In debug mode, the following methods are implemented as function calls to ensure
1204  * type validity.
1205  * In optimized mode, the methods are implemented as defines to improve performance.
1206  * However, we want to have them in the library anyways, so we have to undef the defines.
1207  */
1208 
1209 #undef SCIPmatrixGetColValPtr
1210 #undef SCIPmatrixGetColIdxPtr
1211 #undef SCIPmatrixGetColNNonzs
1212 #undef SCIPmatrixGetNColumns
1213 #undef SCIPmatrixGetColUb
1214 #undef SCIPmatrixGetColLb
1215 #undef SCIPmatrixGetColNUplocks
1216 #undef SCIPmatrixGetColNDownlocks
1217 #undef SCIPmatrixGetVar
1218 #undef SCIPmatrixGetColName
1219 #undef SCIPmatrixGetRowValPtr
1220 #undef SCIPmatrixGetRowIdxPtr
1221 #undef SCIPmatrixGetRowNNonzs
1222 #undef SCIPmatrixGetRowName
1223 #undef SCIPmatrixGetNRows
1224 #undef SCIPmatrixGetRowLhs
1225 #undef SCIPmatrixGetRowRhs
1226 #undef SCIPmatrixIsRowRhsInfinity
1227 #undef SCIPmatrixGetNNonzs
1228 #undef SCIPmatrixGetRowMinActivity
1229 #undef SCIPmatrixGetRowMaxActivity
1230 #undef SCIPmatrixGetRowNMinActNegInf
1231 #undef SCIPmatrixGetRowNMinActPosInf
1232 #undef SCIPmatrixGetRowNMaxActNegInf
1233 #undef SCIPmatrixGetRowNMaxActPosInf
1234 #undef SCIPmatrixGetCons
1235 #undef SCIPmatrixUplockConflict
1236 #undef SCIPmatrixDownlockConflict
1237 
1238 /** get column based start pointer of values */
1240  SCIPMILPMATRIX* matrix, /**< matrix instance */
1241  int col /**< column index */
1242  )
1243 {
1244  assert(matrix != NULL);
1245  assert(0 <= col && col < matrix->ncols);
1246  return matrix->colmatval + matrix->colmatbeg[col];
1247 }
1248 
1249 /** get column based start pointer of row indices */
1251  SCIPMILPMATRIX* matrix, /**< matrix instance */
1252  int col /**< column index */
1253  )
1254 {
1255  assert(matrix != NULL);
1256  assert(0 <= col && col < matrix->ncols);
1257  return matrix->colmatind + matrix->colmatbeg[col];
1258 }
1259 
1260 /** get the number of non-zero entries of this column */
1262  SCIPMILPMATRIX* matrix, /**< matrix instance */
1263  int col /**< column index */
1264  )
1265 {
1266  assert(matrix != NULL);
1267  assert(0 <= col && col < matrix->ncols);
1268  return matrix->colmatcnt[col];
1269 }
1270 
1271 /** get number of columns of the matrix */
1273  SCIPMILPMATRIX* matrix /**< matrix instance */
1274  )
1275 {
1276  assert(matrix != NULL);
1277  return matrix->ncols;
1278 }
1279 
1280 /** get upper bound of column */
1282  SCIPMILPMATRIX* matrix, /**< matrix instance */
1283  int col /**< column index */
1284  )
1285 {
1286  assert(matrix != NULL);
1287  return matrix->ub[col];
1288 }
1289 
1290 /** get lower bound of column */
1292  SCIPMILPMATRIX* matrix, /**< matrix instance */
1293  int col /**< column index */
1294  )
1295 {
1296  assert(matrix != NULL);
1297  return matrix->lb[col];
1298 }
1299 
1300 /** get number of uplocks of column */
1302  SCIPMILPMATRIX* matrix, /**< matrix instance */
1303  int col /**< column index */
1304  )
1305 {
1306  assert(matrix != NULL);
1307  assert(0 <= col && col < matrix->ncols);
1308  return matrix->nuplocks[col];
1309 }
1310 
1311 /** get number of downlocks of column */
1313  SCIPMILPMATRIX* matrix, /**< matrix instance */
1314  int col /**< column index */
1315  )
1316 {
1317  assert(matrix != NULL);
1318  assert(0 <= col && col < matrix->ncols);
1319  return matrix->ndownlocks[col];
1320 }
1321 
1322 /** get variable pointer of column */
1324  SCIPMILPMATRIX* matrix, /**< matrix instance */
1325  int col /**< column index */
1326  )
1327 {
1328  assert(matrix != NULL);
1329  assert(0 <= col && col < matrix->ncols);
1330  return matrix->vars[col];
1331 }
1332 
1333 /** get name of column/variable */
1335  SCIPMILPMATRIX* matrix, /**< matrix instance */
1336  int col /**< column index */
1337  )
1338 {
1339  assert(matrix != NULL);
1340  assert(0 <= col && col < matrix->ncols);
1341  return SCIPvarGetName(matrix->vars[col]);
1342 }
1343 
1344 /** get row based start pointer of values */
1346  SCIPMILPMATRIX* matrix, /**< matrix instance */
1347  int row /**< row index */
1348  )
1349 {
1350  assert(matrix != NULL);
1351  assert(0 <= row && row < matrix->nrows);
1352  return matrix->rowmatval + matrix->rowmatbeg[row];
1353 }
1354 
1355 /** get row based start pointer of column indices */
1357  SCIPMILPMATRIX* matrix, /**< matrix instance */
1358  int row /**< row index */
1359  )
1360 {
1361  assert(matrix != NULL);
1362  assert(0 <= row && row < matrix->nrows);
1363  return matrix->rowmatind + matrix->rowmatbeg[row];
1364 }
1365 
1366 /** get number of non-zeros of this row */
1368  SCIPMILPMATRIX* matrix, /**< matrix instance */
1369  int row /**< row index */
1370  )
1371 {
1372  assert(matrix != NULL);
1373  assert(0 <= row && row < matrix->nrows);
1374  return matrix->rowmatcnt[row];
1375 }
1376 
1377 /** get name of row */
1379  SCIPMILPMATRIX* matrix, /**< matrix instance */
1380  int row /**< row index */
1381  )
1382 {
1383  assert(matrix != NULL);
1384  assert(0 <= row && row < matrix->nrows);
1385  return SCIPconsGetName(matrix->cons[row]);
1386 }
1387 
1388 /** get number of rows of the matrix */
1390  SCIPMILPMATRIX* matrix /**< matrix instance */
1391  )
1392 {
1393  assert(matrix != NULL);
1394  return matrix->nrows;
1395 }
1396 
1397 /** get left-hand-side of row */
1399  SCIPMILPMATRIX* matrix, /**< matrix instance */
1400  int row /**< row index */
1401  )
1402 {
1403  assert(matrix != NULL);
1404  assert(0 <= row && row < matrix->nrows);
1405  return matrix->lhs[row];
1406 }
1407 
1408 /** get right-hand-side of row */
1410  SCIPMILPMATRIX* matrix, /**< matrix instance */
1411  int row /**< row index */
1412  )
1413 {
1414  assert(matrix != NULL);
1415  assert(0 <= row && row < matrix->nrows);
1416  return matrix->rhs[row];
1417 }
1418 
1419 /** flag indicating if right-hand-side of row is infinity */
1421  SCIPMILPMATRIX* matrix, /**< matrix instance */
1422  int row /**< row index */
1423  )
1424 {
1425  assert(matrix != NULL);
1426  assert(0 <= row && row < matrix->nrows);
1427  return matrix->isrhsinfinite[row];
1428 }
1429 
1430 /** get number of non-zeros of matrix */
1432  SCIPMILPMATRIX* matrix /**< matrix instance */
1433  )
1434 {
1435  assert(matrix != NULL);
1436  return matrix->nnonzs;
1437 }
1438 
1439 /** get minimal activity of row */
1441  SCIPMILPMATRIX* matrix, /**< matrix instance */
1442  int row /**< row index */
1443  )
1444 {
1445  assert(matrix != NULL);
1446  assert(0 <= row && row < matrix->nrows);
1447  return matrix->minactivity[row];
1448 }
1449 
1450 /** get maximal activity of row */
1452  SCIPMILPMATRIX* matrix, /**< matrix instance */
1453  int row /**< row index */
1454  )
1455 {
1456  assert(matrix != NULL);
1457  assert(0 <= row && row < matrix->nrows);
1458  return matrix->maxactivity[row];
1459 }
1460 
1461 /** get number of negative infinities present within minimal activity */
1463  SCIPMILPMATRIX* matrix, /**< matrix instance */
1464  int row /**< row index */
1465  )
1466 {
1467  assert(matrix != NULL);
1468  assert(0 <= row && row < matrix->nrows);
1469  return matrix->minactivityneginf[row];
1470 }
1471 
1472 /** get number of positive infinities present within minimal activity */
1474  SCIPMILPMATRIX* matrix, /**< matrix instance */
1475  int row /**< row index */
1476  )
1477 {
1478  assert(matrix != NULL);
1479  assert(0 <= row && row < matrix->nrows);
1480  return matrix->minactivityposinf[row];
1481 }
1482 
1483 /** get number of negative infinities present within maximal activity */
1485  SCIPMILPMATRIX* matrix, /**< matrix instance */
1486  int row /**< row index */
1487  )
1488 {
1489  assert(matrix != NULL);
1490  assert(0 <= row && row < matrix->nrows);
1491  return matrix->maxactivityneginf[row];
1492 }
1493 
1494 /** get number of positive infinities present within maximal activity */
1496  SCIPMILPMATRIX* matrix, /**< matrix instance */
1497  int row /**< row index */
1498  )
1499 {
1500  assert(matrix != NULL);
1501  assert(0 <= row && row < matrix->nrows);
1502  return matrix->maxactivityposinf[row];
1503 }
1504 
1505 /** get constraint pointer for constraint representing row */
1507  SCIPMILPMATRIX* matrix, /**< matrix instance */
1508  int row /**< row index */
1509  )
1510 {
1511  assert(matrix != NULL);
1512  assert(0 <= row && row < matrix->nrows);
1513  return matrix->cons[row];
1514 }
1515 
1516 /** get if conflicting uplocks of a specific variable present */
1518  SCIPMILPMATRIX* matrix, /**< matrix instance */
1519  int col /**< column index */
1520  )
1521 {
1522  assert(matrix != NULL);
1523  assert(0 <= col && col < matrix->ncols);
1524  return (SCIPvarGetNLocksUp(matrix->vars[col]) == matrix->nuplocks[col]);
1525 }
1526 
1527 /** get if conflicting downlocks of a specific variable present */
1529  SCIPMILPMATRIX* matrix, /**< matrix instance */
1530  int col /**< column index */
1531  )
1532 {
1533  assert(matrix != NULL);
1534  assert(0 <= col && col < matrix->ncols);
1535  return (SCIPvarGetNLocksDown(matrix->vars[col]) == matrix->ndownlocks[col]);
1536 }
void SCIPsortRealInt(SCIP_Real *realarray, int *intarray, int len)
static SCIP_RETCODE setColumnMajorFormat(SCIP *scip, SCIPMILPMATRIX *matrix)
Definition: matrix.c:275
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41180
SCIP_RETCODE SCIPmatrixGetParallelRows(SCIP *scip, SCIPMILPMATRIX *matrix, SCIP_Real *scale, int *pclass)
Definition: matrix.c:883
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:41293
int SCIPgetNVars(SCIP *scip)
Definition: scip.c:10735
SCIP_Bool SCIPmatrixIsRowRhsInfinity(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1420
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16341
int SCIPmatrixGetRowNMaxActPosInf(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1495
int SCIPmatrixGetColNDownlocks(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1312
SCIP_RETCODE SCIPgetProbvarLinearSum(SCIP *scip, SCIP_VAR **vars, SCIP_Real *scalars, int *nvars, int varssize, SCIP_Real *constant, int *requiredsize, SCIP_Bool mergemultiples)
Definition: scip.c:17456
Constraint handler for variable bound constraints .
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:41256
static SCIP_RETCODE calcActivityBounds(SCIP *scip, SCIPMILPMATRIX *matrix)
Definition: matrix.c:342
MILPMATRIXCONSTYPE * constype
Definition: struct_matrix.h:72
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip.c:10690
int * minactivityposinf
Definition: struct_matrix.h:79
#define NULL
Definition: lpi_spx.cpp:130
int * minactivityneginf
Definition: struct_matrix.h:78
int SCIPgetNConshdlrs(SCIP *scip)
Definition: scip.c:5871
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1125
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:16965
int SCIPgetNVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9090
SCIP_Longint SCIPgetCapacityKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Bool SCIPmatrixUplockConflict(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1517
SCIP_Bool SCIPconsIsTransformed(SCIP_CONS *cons)
Definition: cons.c:7913
#define FALSE
Definition: def.h:53
SCIP_Real SCIPmatrixGetColUb(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1281
SCIP_Real SCIPgetLhsVarbound(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
#define TRUE
Definition: def.h:52
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_Longint * SCIPgetWeightsKnapsack(SCIP *scip, SCIP_CONS *cons)
int * maxactivityneginf
Definition: struct_matrix.h:80
SCIP_Real * minactivity
Definition: struct_matrix.h:76
#define SCIPfreeBuffer(scip, ptr)
Definition: scip.h:20424
SCIP_Real SCIPmatrixGetRowMinActivity(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1440
void SCIPsortIntIntReal(int *intarray1, int *intarray2, SCIP_Real *realarray, int len)
#define SCIPdebugMessage
Definition: pub_message.h:77
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:20414
int SCIPmatrixGetRowNMinActPosInf(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1473
int * SCIPmatrixGetColIdxPtr(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1250
SCIP_Real SCIPmatrixGetColLb(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1291
Constraint handler for the set partitioning / packing / covering constraints .
static SCIP_RETCODE addRow(SCIP *scip, SCIPMILPMATRIX *matrix, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Real lhs, SCIP_Real rhs, int maxnnonzsmem, SCIP_Bool *rowadded)
Definition: matrix.c:80
SCIP_VAR ** vars
Definition: struct_matrix.h:60
SCIP_VAR ** SCIPgetVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
int SCIPmatrixGetRowNMinActNegInf(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1462
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:20418
SCIP_Real * ub
Definition: struct_matrix.h:56
int * maxactivityposinf
Definition: struct_matrix.h:81
Constraint handler for knapsack constraints of the form , x binary and .
int SCIPgetNConss(SCIP *scip)
Definition: scip.c:11773
SCIP_Real * rhs
Definition: struct_matrix.h:69
SCIP_CONSHDLR ** SCIPgetConshdlrs(SCIP *scip)
Definition: scip.c:5860
#define SCIPallocBuffer(scip, ptr)
Definition: scip.h:20412
int SCIPmatrixGetNRows(SCIPMILPMATRIX *matrix)
Definition: matrix.c:1389
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:20426
int SCIPmatrixGetColNUplocks(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1301
int SCIPgetNVarsLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * SCIPmatrixGetRowValPtr(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1345
int SCIPmatrixGetNColumns(SCIPMILPMATRIX *matrix)
Definition: matrix.c:1272
SCIP_Bool SCIPmatrixDownlockConflict(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1528
SCIP_Real SCIPmatrixGetRowMaxActivity(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1451
Constraint handler for logicor constraints (equivalent to set covering, but algorithms are suited fo...
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:3901
SCIP_VAR ** SCIPgetVarsSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9111
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:41206
SCIP_Real * lb
Definition: struct_matrix.h:55
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7624
SCIP_RETCODE SCIPmatrixCreate(SCIP *scip, SCIPMILPMATRIX **matrixptr, SCIP_Bool *initialized, SCIP_Bool *complete)
Definition: matrix.c:429
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
int SCIPmatrixGetRowNMaxActNegInf(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1484
const char * SCIPmatrixGetColName(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1334
int SCIPvarGetNLocksUp(SCIP_VAR *var)
Definition: var.c:3204
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:41245
#define SCIP_CALL(x)
Definition: def.h:263
SCIP_RETCODE SCIPmatrixGetParallelCols(SCIP *scip, SCIPMILPMATRIX *matrix, SCIP_Real *scale, int *pclass, SCIP_Bool *varineq)
Definition: matrix.c:1039
SCIP_Real SCIPgetRhsVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPmatrixGetRowRhs(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1409
SCIP_Real * colmatval
Definition: struct_matrix.h:50
SCIP_Real SCIPgetVbdcoefVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * lhs
Definition: struct_matrix.h:68
int * SCIPmatrixGetRowIdxPtr(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1356
void SCIPmatrixFree(SCIP *scip, SCIPMILPMATRIX **matrix)
Definition: matrix.c:787
int SCIPmatrixGetNNonzs(SCIPMILPMATRIX *matrix)
Definition: matrix.c:1431
SCIP_VAR * SCIPmatrixGetVar(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1323
#define SCIP_Bool
Definition: def.h:50
SCIP_CONS ** cons
Definition: struct_matrix.h:71
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip.h:20427
const char * SCIPmatrixGetRowName(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1378
#define SCIPfreeMemoryArray(scip, ptr)
Definition: scip.h:20373
static SCIP_RETCODE addConstraint(SCIP *scip, SCIPMILPMATRIX *matrix, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Real lhs, SCIP_Real rhs, int maxnnonzsmem, SCIP_Bool *rowadded)
Definition: matrix.c:198
SCIP_VAR * SCIPgetVbdvarVarbound(SCIP *scip, SCIP_CONS *cons)
Constraint handler for linear constraints in their most general form, .
data structure for MILP matrix
int SCIPmatrixGetColNNonzs(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1261
public methods for MILP matrix
#define SCIPallocClearMemoryArray(scip, ptr, num)
Definition: scip.h:20359
SCIP_Real * SCIPmatrixGetColValPtr(SCIPMILPMATRIX *matrix, int col)
Definition: matrix.c:1239
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:16955
SCIP_Bool * isrhsinfinite
Definition: struct_matrix.h:74
SCIP_Real * maxactivity
Definition: struct_matrix.h:77
static const SCIP_Real scalars[]
Definition: lp.c:5506
SCIP_VAR ** SCIPgetVarsLogicor(SCIP *scip, SCIP_CONS *cons)
void SCIPmatrixPrintRow(SCIP *scip, SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:851
int SCIPgetNVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip.h:20422
int SCIPvarGetProbindex(SCIP_VAR *var)
Definition: var.c:16648
int SCIPconshdlrGetNCheckConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4312
#define SCIP_Real
Definition: def.h:124
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
#define SCIP_Longint
Definition: def.h:109
SCIP_SETPPCTYPE SCIPgetTypeSetppc(SCIP *scip, SCIP_CONS *cons)
Definition: cons_setppc.c:9132
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
#define BMSclearMemoryArray(ptr, num)
Definition: memory.h:85
common defines and data types used in all packages of SCIP
int SCIPmatrixGetRowNNonzs(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1367
SCIP_VAR * SCIPgetVarVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_CONS * SCIPmatrixGetCons(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1506
static SCIP_RETCODE getActiveVariables(SCIP *scip, SCIP_VAR ***vars, SCIP_Real **scalars, int *nvars, SCIP_Real *constant)
Definition: matrix.c:45
SCIP_CONS ** SCIPconshdlrGetCheckConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4282
int SCIPvarGetNLocksDown(SCIP_VAR *var)
Definition: var.c:3149
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * rowmatval
Definition: struct_matrix.h:62
SCIP_Real SCIPmatrixGetRowLhs(SCIPMILPMATRIX *matrix, int row)
Definition: matrix.c:1398