Scippy

GCG

Branch-and-Price & Column Generation for Everyone

hyperrowcolgraph_def.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program */
4 /* GCG --- Generic Column Generation */
5 /* a Dantzig-Wolfe decomposition based extension */
6 /* of the branch-cut-and-price framework */
7 /* SCIP --- Solving Constraint Integer Programs */
8 /* */
9 /* Copyright (C) 2010-2021 Operations Research, RWTH Aachen University */
10 /* Zuse Institute Berlin (ZIB) */
11 /* */
12 /* This program is free software; you can redistribute it and/or */
13 /* modify it under the terms of the GNU Lesser General Public License */
14 /* as published by the Free Software Foundation; either version 3 */
15 /* of the License, or (at your option) any later version. */
16 /* */
17 /* This program is distributed in the hope that it will be useful, */
18 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
19 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
20 /* GNU Lesser General Public License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with this program; if not, write to the Free Software */
24 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
25 /* */
26 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
27 
28 /**@file hyperrowcolgraph_def.h
29  * @brief A hypergraph with row and column nodes
30  * @author Martin Bergner
31  * @author Annika Thome
32  */
33 
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35 
36 #ifndef GCG_HYPERROWCOLGRAPH_DEF_H_
37 #define GCG_HYPERROWCOLGRAPH_DEF_H_
38 
39 #include "hyperrowcolgraph.h"
40 #include "scip_misc.h"
41 #include "class_partialdecomp.h"
42 #include "class_detprobdata.h"
43 #include <algorithm>
44 #include <set>
45 
46 namespace gcg {
47 template <class T>
49  SCIP* scip, /**< SCIP data structure */
50  Weights w /**< weights for the given graph */
51 ): MatrixGraph<T>(scip, w),graph(scip)
52 {
53  this->graphiface = &graph;
54  this->name = std::string("hyperrowcol");
55 }
56 
57 template <class T>
59 {
60 
61 }
62 
63 
64 /**
65  * Builds a bipartite representation of the hyperrowcol graph out of the matrix.
66  *
67  * The function will create an node for every constraint, every variable and every nonzero entry of the matrix.
68  * One side of the bipartite graph are the nonzero entries (nodes), the constraints and variables are on the other side (hyperedges).
69  * A nonzero entry a_{ij} is incident to the constraint i and the variable j.
70  *
71  * @todo The nonzeroness is not checked, all variables in the variable array are considered
72  */
73 template <class T>
75  SCIP_CONS** conss, /**< constraints for which graph should be created */
76  SCIP_VAR** vars, /**< variables for which graph should be created */
77  int nconss_, /**< number of constraints */
78  int nvars_ /**< number of variables */
79  )
80 {
81  int i;
82  int j;
83  SCIP_Bool success;
84 
85  assert(conss != NULL);
86  assert(vars != NULL);
87  assert(nvars_ > 0);
88  assert(nconss_ > 0);
89 
90  this->nvars = nvars_;
91  this->nconss = nconss_;
92 
93  /* create nodes for constraints and variables (hyperedges) */
94  for( i = 0; i < this->nvars + this->nconss; ++i )
95  {
96  TCLIQUE_WEIGHT weight;
97 
98  /* note that the first nvars nodes correspond to variables */
99  if( i < this->nvars )
100  {
101  weight = this->weights.calculate(vars[i]);
102  SCIPdebugMessage("Weight for var <%s> is %d\n", SCIPvarGetName(vars[i]), weight);
103  }
104 
105  else
106  {
107  weight = this->weights.calculate(conss[i-this->nvars]);
108  SCIPdebugMessage("Weight for cons <%s> is %d\n", SCIPconsGetName(conss[i-this->nvars]), weight);
109  }
110 
111  SCIP_CALL( this->graph.addNode(i, weight) );
112  }
113 
114  /* go through all constraints */
115  for( i = 0; i < this->nconss; ++i )
116  {
117  SCIP_VAR **curvars;
118 
119  int ncurvars;
120  SCIP_CALL( SCIPgetConsNVars(this->scip_, conss[i], &ncurvars, &success) );
121  assert(success);
122  if( ncurvars == 0 )
123  continue;
124 
125  /*
126  * may work as is, as we are copying the constraint later regardless
127  * if there are variables in it or not
128  */
129  SCIP_CALL( SCIPallocBufferArray(this->scip_, &curvars, ncurvars) );
130  SCIP_CALL( SCIPgetConsVars(this->scip_, conss[i], curvars, ncurvars, &success) );
131  assert(success);
132 
133  /** @todo skip all variables that have a zero coeffient or where all coefficients add to zero */
134  /** @todo Do more then one entry per variable actually work? */
135 
136  for( j = 0; j < ncurvars; ++j )
137  {
138  SCIP_VAR* var;
139  int varIndex;
140 
141  if( SCIPgetStage(this->scip_) >= SCIP_STAGE_TRANSFORMED)
142  var = SCIPvarGetProbvar(curvars[j]);
143  else
144  var = curvars[j];
145 
146  if( !GCGisVarRelevant(var) )
147  continue;
148 
149  assert(var != NULL);
150  varIndex = SCIPvarGetProbindex(var);
151  assert(varIndex >= 0);
152  assert(varIndex < this->nvars);
153 
154  SCIPdebugMessage("Cons <%s> (%d), var <%s> (%d), nonzero %d\n", SCIPconsGetName(conss[i]), i, SCIPvarGetName(var), varIndex, this->nnonzeroes);
155  /* add nonzero node and edge to variable and constraint) */;
156  SCIP_CALL( this->graph.addNode( this->nvars+this->nconss+this->nnonzeroes, 0) );
157  SCIP_CALL( this->graph.addEdge(varIndex, this->nvars+this->nconss+this->nnonzeroes) );
158  SCIP_CALL( this->graph.addEdge(this->nvars+i, this->nvars+this->nconss+this->nnonzeroes) );
159 
160  this->nnonzeroes++;
161  }
162  SCIPfreeBufferArray(this->scip_, &curvars);
163  }
164 
165  SCIP_CALL( this->graph.flush() );
166 
167  return SCIP_OKAY;
168 }
169 
170 template <class T>
172  DETPROBDATA* detprobdata,
173  PARTIALDECOMP* partialdec
174  )
175 {
176  int i;
177  int j;
178  unordered_map<int, int> oldToNewConsIndex;
179  unordered_map<int, int> oldToNewVarIndex;
180  vector<int> conssForGraph; /** stores the conss included by the graph */
181  vector<int> varsForGraph; /** stores the vars included by the graph */
182  vector<bool> varsBool(partialdec->getNVars(), false); /**< true, if the var will be part of the graph */
183  vector<bool> conssBool(partialdec->getNConss(), false); /**< true, if the cons will be part of the graph */
184 
185 
186  //fillout conssForGraph and varsForGraph
187  for(int c = 0; c < partialdec->getNOpenconss(); ++c)
188  {
189  int cons = partialdec->getOpenconss()[c];
190  for(int v = 0; v < partialdec->getNOpenvars(); ++v)
191  {
192  int var = partialdec->getOpenvars()[v];
193  for(i = 0; i < detprobdata->getNVarsForCons(cons); ++i)
194  {
195  if(var == detprobdata->getVarsForCons(cons)[i])
196  {
197  varsBool[var] = true;
198  conssBool[cons] = true;
199  }
200  }
201  }
202  }
203 
204  for(int v = 0; v < partialdec->getNOpenvars(); ++v)
205  {
206  int var = partialdec->getOpenvars()[v];
207  if(varsBool[var])
208  varsForGraph.push_back(var);
209  }
210  for(int c = 0; c < partialdec->getNOpenconss(); ++c)
211  {
212  int cons = partialdec->getOpenconss()[c];
213  if(conssBool[cons])
214  conssForGraph.push_back(cons);
215  }
216 
217  this->nconss = (int)conssForGraph.size();
218  this->nvars = (int)varsForGraph.size();
219 
220  /** add node for every var */
221  for( i = 0 ; i < (int)varsForGraph.size(); ++i )
222  {
223  int oldVarId = varsForGraph[i];
224  assert(varsBool[oldVarId]);
225  TCLIQUE_WEIGHT weight;
226 
227  /* note that the first nvars nodes correspond to variables */
228  weight = this->weights.calculate(detprobdata->getVar(oldVarId));
229  oldToNewVarIndex.insert({oldVarId ,i});
230 
231  this->graph.addNode(i, weight);
232  }
233 
234  /** add node for every cons */
235  for( j = 0 ; j < (int)conssForGraph.size(); ++j )
236  {
237  int oldConsId = conssForGraph[j];
238  assert(conssBool[oldConsId]);
239  TCLIQUE_WEIGHT weight;
240 
241  /* note that the first nvars nodes correspond to variables (legacy implementation) */
242  weight = this->weights.calculate(detprobdata->getCons(oldConsId));
243  oldToNewConsIndex.insert({ oldConsId, j});
244  this->graph.addNode( this->nvars + j, weight);
245  }
246 
247  this->nnonzeroes = 0;
248  /* go through all open constraints */
249  for( i = 0; i < (int)conssForGraph.size(); ++i )
250  {
251  int oldConsId = conssForGraph[i];
252 
253  for( j = 0; j < detprobdata->getNVarsForCons(oldConsId); ++j )
254  {
255  int oldVarId = detprobdata->getVarsForCons(oldConsId)[j];
256  if(!varsBool[oldVarId])
257  continue;
258  SCIPdebugMessage("Cons <%s> (%d), var <%s> (%d), nonzero %d\n", SCIPconsGetName(detprobdata->getCons(oldConsId)), i,
259  SCIPvarGetName(detprobdata->getVar(oldVarId)), oldToNewVarIndex[oldVarId], this->nnonzeroes);
260  /* add nonzero node and edge to variable and constraint) */;
261  SCIP_CALL( this->graph.addNode( this->nvars+this->nconss+this->nnonzeroes, 0) );
262  SCIP_CALL( this->graph.addEdge(oldToNewVarIndex[oldVarId], this->nvars+this->nconss+this->nnonzeroes) );
263  SCIP_CALL( this->graph.addEdge(this->nvars+oldToNewConsIndex[oldConsId], this->nvars+this->nconss+this->nnonzeroes) );
264 
265  this->nnonzeroes++;
266  }
267  }
268 
269  this->graph.flush();
270  return SCIP_OKAY;
271 }
272 
273 
274 /** writes the graph to the given file.
275  * The format is graph dependent
276  */
277 template <class T>
279  int fd, /**< filename where the graph should be written to */
280  SCIP_Bool edgeweights /**< whether to write edgeweights */
281  )
282 {
283  FILE* file;
284  file = fdopen(fd, "wx");
285  if( file == NULL )
286  return SCIP_FILECREATEERROR;
287 
288  SCIPinfoMessage(this->scip_, file, "%d %d %d\n", this->nvars+this->nconss, this->nnonzeroes+this->dummynodes, edgeweights ? 1 :0);
289 
290  for( int i = 0; i < this->nvars+this->nconss; ++i )
291  {
292  std::vector<int> neighbors = graph.getNeighbors(i);
293  int nneighbors = graph.getNNeighbors(i);
294  if( edgeweights )
295  {
296  SCIPinfoMessage(this->scip_, file, "%d ", graph.getWeight(i));
297  }
298  for( int j = 0; j < nneighbors; ++j )
299  {
300  SCIPinfoMessage(this->scip_, file, "%d ",neighbors[j]+1-this->nvars-this->nconss);
301  }
302  SCIPinfoMessage(this->scip_, file, "\n");
303  }
304 
305  if( !fclose(file) )
306  return SCIP_OKAY;
307  else
308  return SCIP_WRITEERROR;
309 }
310 
311 
312 class function {
313  int diff;
314 public:
315  function(int i):diff(i) {}
316  int operator()(int i) const { return i-diff;}
317 };
318 
319 template <class T>
321  int i
322 )
323 {
324  assert(i >= 0);
325  assert(i < this->nnonzeroes);
326  function f(this->nconss+this->nvars);
327  std::vector<int>::iterator it;
328  std::set<int> neighbors;
329  std::vector<int> immediateneighbors = this->graph.getNeighbors(i+this->nconss+this->nvars);
330  for( size_t j = 0; j < immediateneighbors.size(); ++j)
331  {
332  std::vector<int> alternateneighbor = this->graph.getNeighbors(immediateneighbors[j]);
333  neighbors.insert(alternateneighbor.begin(), alternateneighbor.end() );
334  }
335  std::vector<int> r(neighbors.size(), 0);
336  std::transform(neighbors.begin(), neighbors.end(), r.begin(), f);
337  it = std::remove(r.begin(), r.end(), i);
338 
339  return std::vector<int>(r.begin(), it);
340 }
341 
342 template <class T>
344  int i
345 )
346 {
347  function f(this->nconss+this->nvars);
348  assert(i >= 0);
349  assert(i < this->nconss+this->nvars);
350 
351  std::vector<int> neighbors = this->graph.getNeighbors(i);
352  std::transform(neighbors.begin(), neighbors.end(), neighbors.begin(), f);
353  return neighbors;
354 }
355 
356 template <class T>
358  int i
359 )
360 {
361  function f(this->nconss+this->nvars);
362  assert(i >= 0);
363  assert(i < this->nconss);
364 
365  std::vector<int> neighbors = this->graph.getNeighbors(i+this->nvars);
366  std::transform(neighbors.begin(), neighbors.end(), neighbors.begin(), f);
367  return neighbors;
368 }
369 
370 template <class T>
372  int i
373 )
374 {
375  function f(this->nconss+this->nvars);
376  assert(i >= 0);
377  assert(i < this->nvars);
378 
379  std::vector<int> neighbors = this->graph.getNeighbors(i);
380  std::transform(neighbors.begin(), neighbors.end(), neighbors.begin(), f);
381  return neighbors;
382 }
383 
384 template <class T>
386  DEC_DECOMP** decomp /**< decomposition structure to generate */
387  )
388 {
389  int nblocks;
390  SCIP_HASHMAP* constoblock;
391 
392  int *nsubscipconss;
393  int i;
394  SCIP_CONS **conss;
395  SCIP_Bool emptyblocks = FALSE;
396  std::vector<int> partition = graph.getPartition();
397  conss = SCIPgetConss(this->scip_);
398 
399  nblocks = *(std::max_element(partition.begin(), partition.end()))+1;
400  SCIP_CALL( SCIPallocBufferArray(this->scip_, &nsubscipconss, nblocks) );
401  BMSclearMemoryArray(nsubscipconss, nblocks);
402 
403  SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(this->scip_), this->nconss) );
404 
405  /* assign constraints to partition */
406  for( i = 0; i < this->nconss; i++ )
407  {
408  std::set<int> blocks;
409  std::vector<int> nonzeros = getConsNonzeroNodes(i);
410  for( size_t k = 0; k < nonzeros.size(); ++k )
411  {
412  blocks.insert(partition[nonzeros[k]]);
413  }
414  if( blocks.size() > 1 )
415  {
416  SCIP_CALL( SCIPhashmapInsert(constoblock, conss[i], (void*) (size_t) (nblocks+1)) );
417  }
418  else
419  {
420  int block = *(blocks.begin());
421  SCIP_CALL( SCIPhashmapInsert(constoblock, conss[i], (void*) (size_t) (block +1)) );
422  ++(nsubscipconss[block]);
423  }
424  }
425 
426  /* first, make sure that there are constraints in every block, otherwise the hole thing is useless */
427  for( i = 0; i < nblocks; ++i )
428  {
429  if( nsubscipconss[i] == 0 )
430  {
431  SCIPdebugMessage("Block %d does not have any constraints!\n", i);
432  emptyblocks = TRUE;
433  }
434  }
435 
436  if( !emptyblocks )
437  {
438  SCIP_CALL( DECdecompCreate(this->scip_, decomp) );
439  SCIP_CALL( DECfilloutDecompFromConstoblock(this->scip_, *decomp, constoblock, nblocks, FALSE) );
440  }
441  else {
442  SCIPhashmapFree(&constoblock);
443  *decomp = NULL;
444  }
445 
446  SCIPfreeBufferArray(this->scip_, &nsubscipconss);
447  return SCIP_OKAY;
448 }
449 
450 template <class T>
452  PARTIALDECOMP** firstpartialdec,
453  PARTIALDECOMP** secondpartialdec,
454  DETPROBDATA* detprobdata
455  )
456 {
457  int nblocks;
458  SCIP_HASHMAP* constoblock;
459 
460  int *nsubscipconss;
461  int i;
462  SCIP_CONS **conss;
463  SCIP_Bool emptyblocks = FALSE;
464  std::vector<int> partition = graph.getPartition();
465  conss = SCIPgetConss(this->scip_);
466 
467  nblocks = *(std::max_element(partition.begin(), partition.end()))+1;
468  SCIP_CALL( SCIPallocBufferArray(this->scip_, &nsubscipconss, nblocks) );
469  BMSclearMemoryArray(nsubscipconss, nblocks);
470 
471  SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(this->scip_), this->nconss) );
472 
473  /* assign constraints to partition */
474  for( i = 0; i < this->nconss; i++ )
475  {
476  std::set<int> blocks;
477  std::vector<int> nonzeros = getConsNonzeroNodes(i);
478  for( size_t k = 0; k < nonzeros.size(); ++k )
479  {
480  blocks.insert(partition[nonzeros[k]]);
481  }
482  if( blocks.size() > 1 )
483  {
484  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t)detprobdata->getIndexForCons(conss[i]), (void*) (size_t) (nblocks+1)) );
485  }
486  else
487  {
488  int block = *(blocks.begin());
489  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t) detprobdata->getIndexForCons(conss[i]), (void*) (size_t) (block +1)) );
490  ++(nsubscipconss[block]);
491  }
492  }
493 
494  /* first, make sure that there are constraints in every block, otherwise the whole thing is useless */
495  for( i = 0; i < nblocks; ++i )
496  {
497  if( nsubscipconss[i] == 0 )
498  {
499  SCIPdebugMessage("Block %d does not have any constraints!\n", i);
500  emptyblocks = TRUE;
501  }
502  }
503 
504  if( !emptyblocks )
505  {
506  bool original = detprobdata->isAssignedToOrigProb();
507  if( firstpartialdec != NULL )
508  {
509  (*firstpartialdec) = new PARTIALDECOMP(this->scip_, original);
510  SCIP_CALL((*firstpartialdec)->filloutPartialdecFromConstoblock(constoblock, nblocks));
511  }
512  if( secondpartialdec != NULL )
513  {
514  (*secondpartialdec) = new PARTIALDECOMP(this->scip_, original);
515  SCIP_CALL((*secondpartialdec)->filloutBorderFromConstoblock(constoblock, nblocks));
516  for( int col = 0; col < (*firstpartialdec)->getNLinkingvars(); ++col )
517  {
518  (*secondpartialdec)->setVarToLinking((*firstpartialdec)->getLinkingvars()[col]);
519  (*secondpartialdec)->deleteOpenvar(col);
520  }
521  }
522  SCIPhashmapFree(&constoblock);
523  }
524  else {
525  SCIPhashmapFree(&constoblock);
526  if( firstpartialdec != NULL )
527  {
528  (*firstpartialdec) = NULL;
529  }
530  if( secondpartialdec != NULL)
531  {
532  (*secondpartialdec) = NULL;
533  }
534  }
535 
536  SCIPfreeBufferArray(this->scip_, &nsubscipconss);
537  return SCIP_OKAY;
538 }
539 
540 template <class T>
542  PARTIALDECOMP* oldpartialdec,
543  PARTIALDECOMP** firstpartialdec,
544  PARTIALDECOMP** secondpartialdec,
545  DETPROBDATA* detprobdata
546  )
547 {
548  int nblocks;
549  SCIP_HASHMAP* constoblock;
550 
551  int *nsubscipconss;
552  int i;
553  SCIP_Bool emptyblocks = FALSE;
554 
555  if(this->nconss == 0)
556  {
557  (*firstpartialdec) = NULL;
558  (*secondpartialdec) = NULL;
559  return SCIP_OKAY;
560  }
561 
562  std::vector<int> partition = graph.getPartition();
563 
564  nblocks = *(std::max_element(partition.begin(), partition.end()))+1;
565  SCIP_CALL( SCIPallocBufferArray(this->scip_, &nsubscipconss, nblocks) );
566  BMSclearMemoryArray(nsubscipconss, nblocks);
567 
568  SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(this->scip_), this->nconss) );
569 
570  //fillout conssForGraph
571  vector<int> conssForGraph; /** stores the conss included by the graph */
572  vector<bool> conssBool(oldpartialdec->getNConss(), false); /**< true, if the cons will be part of the graph */
573  bool found;
574 
575  for(int c = 0; c < oldpartialdec->getNOpenconss(); ++c)
576  {
577  int cons = oldpartialdec->getOpenconss()[c];
578  found = false;
579  for(int v = 0; v < oldpartialdec->getNOpenvars() && !found; ++v)
580  {
581  int var = oldpartialdec->getOpenvars()[v];
582  for(i = 0; i < detprobdata->getNVarsForCons(cons) && !found; ++i)
583  {
584  if(var == detprobdata->getVarsForCons(cons)[i])
585  {
586  conssBool[cons] = true;
587  found = true;
588  }
589  }
590  }
591  }
592 
593  for(int c = 0; c < oldpartialdec->getNOpenconss(); ++c)
594  {
595  int cons = oldpartialdec->getOpenconss()[c];
596  if(conssBool[cons])
597  conssForGraph.push_back(cons);
598  }
599 
600 
601  /* assign constraints to partition */
602  for( i = 0; i < this->nconss; i++ )
603  {
604  std::set<int> blocks;
605  std::vector<int> nonzeros = getConsNonzeroNodes(i);
606  for( size_t k = 0; k < nonzeros.size(); ++k )
607  {
608  blocks.insert(partition[nonzeros[k]]);
609  }
610  if( blocks.size() > 1 )
611  {
612  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t) conssForGraph[i], (void*) (size_t) (nblocks+1)) );
613  }
614  else
615  {
616  int block = *(blocks.begin());
617  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t) conssForGraph[i], (void*) (size_t) (block +1)) );
618  ++(nsubscipconss[block]);
619  }
620  }
621 
622  /* first, make sure that there are constraints in every block, otherwise the hole thing is useless */
623  for( i = 0; i < nblocks; ++i )
624  {
625  if( nsubscipconss[i] == 0 )
626  {
627  SCIPdebugMessage("Block %d does not have any constraints!\n", i);
628  emptyblocks = TRUE;
629  }
630  }
631 
632  if( !emptyblocks )
633  {
634  (*firstpartialdec) = new PARTIALDECOMP(oldpartialdec);
635  SCIP_CALL( (*firstpartialdec)->assignPartialdecFromConstoblock(constoblock, nblocks) );
636  (*secondpartialdec) = new PARTIALDECOMP(oldpartialdec);
637  SCIP_CALL( (*secondpartialdec)->assignBorderFromConstoblock(constoblock, nblocks) );
638  SCIPhashmapFree(&constoblock);
639  }
640  else {
641  SCIPhashmapFree(&constoblock);
642  (*firstpartialdec) = NULL;
643  (*secondpartialdec) = NULL;
644  }
645 
646  SCIPfreeBufferArray(this->scip_, &nsubscipconss);
647  return SCIP_OKAY;
648 }
649 
650 template <class T>
652  const char* filename /**< filename where the partition is stored */
653  )
654 {
655 
656  ifstream input(filename);
657  if( !input.good() )
658  {
659  SCIPerrorMessage("Could not open file <%s> for reading\n", filename);
660  return SCIP_READERROR;
661  }
662  for( int i = 0; i < this->nnonzeroes; ++i )
663  {
664  int part = 0;
665  if( !(input >> part) )
666  {
667  SCIPerrorMessage("Could not read from file <%s>. It may be in the wrong format\n", filename);
668  return SCIP_READERROR;
669  }
670  graph.setPartition(i,part);
671  }
672 
673  input.close();
674  return SCIP_OKAY;
675 
676 }
677 
678 } /* namespace gcg */
679 #endif
int getNOpenvars()
Gets size of vector containing variables not assigned yet.
A hypergraph with row and column nodes.
SCIP_Bool isAssignedToOrigProb()
returns true if the matrix structure corresponds to the presolved problem
int operator()(int i) const
virtual SCIP_RETCODE readPartition(const char *filename)
std::vector< int > getConsNonzeroNodes(int i)
virtual SCIP_RETCODE writeToFile(int fd, SCIP_Bool writeweights)
SCIP_Bool GCGisVarRelevant(SCIP_VAR *var)
Definition: scip_misc.c:41
various SCIP helper methods
GraphInterface * graphiface
Definition: matrixgraph.h:63
static SCIP_RETCODE partition(SCIP *scip, SCIP_VAR **J, int *Jsize, SCIP_Longint *priority, SCIP_VAR **F, int Fsize, SCIP_VAR **origvar, SCIP_Real *median)
SCIP_CONS * getCons(int consIndex)
returns the SCIP constraint related to a constraint index
virtual SCIP_RETCODE createDecompFromPartition(DEC_DECOMP **decomp)
virtual std::vector< int > getHyperedgeNodes(int i)
virtual SCIP_RETCODE createPartialdecFromPartition(PARTIALDECOMP **firstpartialdec, PARTIALDECOMP **secondpartialdec, DETPROBDATA *detprobdata)
int getIndexForCons(SCIP_CONS *cons)
returns the constraint index related to a SCIP constraint
SCIP_RETCODE DECfilloutDecompFromConstoblock(SCIP *scip, DEC_DECOMP *decomp, SCIP_HASHMAP *constoblock, int nblocks, SCIP_Bool staircase)
Definition: decomp.c:1455
const int * getOpenconss()
Gets array containing constraints not assigned yet.
int getNConss()
Gets the number of constraints.
std::string name
Definition: matrixgraph.h:56
virtual SCIP_RETCODE createFromPartialMatrix(DETPROBDATA *detprobdata, PARTIALDECOMP *partialdec)
class to manage partial decompositions
std::vector< int > getVarNonzeroNodes(int i)
int getNVarsForCons(int consIndex)
returns the number of variables for a given constraint
int getNOpenconss()
Gets size of vector containing constraints not assigned yet.
HyperrowcolGraph(SCIP *scip, Weights w)
SCIP_RETCODE DECdecompCreate(SCIP *scip, DEC_DECOMP **decdecomp)
Definition: decomp.c:471
class storing (potentially incomplete) decompositions
std::vector< int > & getVarsForCons(int consIndex)
returns the variable indices of the coefficient matrix for a constraint
virtual std::vector< int > getNeighbors(int i)
SCIP_RETCODE createFromMatrix(SCIP_CONS **conss, SCIP_VAR **vars, int nconss, int nvars)
const int * getOpenvars()
Gets array containing variables not assigned yet.
SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
class storing partialdecs and the problem matrix
int getNVars()
Gets number of vars.