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-2018 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 
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_seeed.h"
42 #include "class_seeedpool.h"
43 #include <algorithm>
44 #include <set>
45 
46 namespace gcg {
47 template <class T>
49  SCIP* scip,
50  Weights w
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 
73 template <class T>
75  SCIP_CONS** conss,
76  SCIP_VAR** vars,
77  int nconss_,
78  int nvars_
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 
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  Seeedpool* seeedpool,
173  Seeed* seeed
174  )
175 {
176  int i;
177  int j;
178  unordered_map<int, int> oldToNewConsIndex;
179  unordered_map<int, int> oldToNewVarIndex;
180  vector<int> conssForGraph;
181  vector<int> varsForGraph;
182  vector<bool> varsBool(seeed->getNVars(), false);
183  vector<bool> conssBool(seeed->getNConss(), false);
186  //fillout conssForGraph and varsForGraph
187  for(int c = 0; c < seeed->getNOpenconss(); ++c)
188  {
189  int cons = seeed->getOpenconss()[c];
190  for(int v = 0; v < seeed->getNOpenvars(); ++v)
191  {
192  int var = seeed->getOpenvars()[v];
193  for(i = 0; i < seeedpool->getNVarsForCons(cons); ++i)
194  {
195  if(var == seeedpool->getVarsForCons(cons)[i])
196  {
197  varsBool[var] = true;
198  conssBool[cons] = true;
199  }
200  }
201  }
202  }
203 
204  for(int v = 0; v < seeed->getNOpenvars(); ++v)
205  {
206  int var = seeed->getOpenvars()[v];
207  if(varsBool[var])
208  varsForGraph.push_back(var);
209  }
210  for(int c = 0; c < seeed->getNOpenconss(); ++c)
211  {
212  int cons = seeed->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 
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( seeedpool->getVarForIndex(oldVarId) );
229  oldToNewVarIndex.insert({oldVarId ,i});
230 
231  this->graph.addNode(i, weight);
232  }
233 
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 
242  /* note that the first nvars nodes correspond to variables (legacy implementation) */
243  weight = this->weights.calculate( seeedpool->getConsForIndex(oldConsId) );
244  oldToNewConsIndex.insert({ oldConsId, j});
245  this->graph.addNode( this->nvars + j, weight);
246  }
247 
248  this->nnonzeroes = 0;
249  /* go through all open constraints */
250  for( i = 0; i < (int)conssForGraph.size(); ++i )
251  {
252  int oldConsId = conssForGraph[i];
253 
254  for( j = 0; j < seeedpool->getNVarsForCons(oldConsId); ++j )
255  {
256  int oldVarId = seeedpool->getVarsForCons(oldConsId)[j];
257  if(!varsBool[oldVarId])
258  continue;
259  SCIPdebugMessage("Cons <%s> (%d), var <%s> (%d), nonzero %d\n", SCIPconsGetName(seeedpool->getConsForIndex(oldConsId)), i, SCIPvarGetName(seeedpool->getVarForIndex(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 
270  this->graph.flush();
271  return SCIP_OKAY;
272 }
273 
274 
278 template <class T>
280  int fd,
281  SCIP_Bool edgeweights
282  )
283 {
284  FILE* file;
285  file = fdopen(fd, "wx");
286  if( file == NULL )
287  return SCIP_FILECREATEERROR;
288 
289  SCIPinfoMessage(this->scip_, file, "%d %d %d\n", this->nvars+this->nconss, this->nnonzeroes+this->dummynodes, edgeweights ? 1 :0);
290 
291  for( int i = 0; i < this->nvars+this->nconss; ++i )
292  {
293  std::vector<int> neighbors = graph.getNeighbors(i);
294  int nneighbors = graph.getNNeighbors(i);
295  if( edgeweights )
296  {
297  SCIPinfoMessage(this->scip_, file, "%d ", graph.getWeight(i));
298  }
299  for( int j = 0; j < nneighbors; ++j )
300  {
301  SCIPinfoMessage(this->scip_, file, "%d ",neighbors[j]+1-this->nvars-this->nconss);
302  }
303  SCIPinfoMessage(this->scip_, file, "\n");
304  }
305 
306  if( !fclose(file) )
307  return SCIP_OKAY;
308  else
309  return SCIP_WRITEERROR;
310 }
311 
312 
313 class function {
314  int diff;
315 public:
316  function(int i):diff(i) {}
317  int operator()(int i) const { return i-diff;}
318 };
319 
320 template <class T>
322  int i
323 )
324 {
325  assert(i >= 0);
326  assert(i < this->nnonzeroes);
327  function f(this->nconss+this->nvars);
328  std::vector<int>::iterator it;
329  std::set<int> neighbors;
330  std::vector<int> immediateneighbors = this->graph.getNeighbors(i+this->nconss+this->nvars);
331  for( size_t j = 0; j < immediateneighbors.size(); ++j)
332  {
333  std::vector<int> alternateneighbor = this->graph.getNeighbors(immediateneighbors[j]);
334  neighbors.insert(alternateneighbor.begin(), alternateneighbor.end() );
335  }
336  std::vector<int> r(neighbors.size(), 0);
337  std::transform(neighbors.begin(), neighbors.end(), r.begin(), f);
338  it = std::remove(r.begin(), r.end(), i);
339 
340  return std::vector<int>(r.begin(), it);
341 }
342 
343 template <class T>
345  int i
346 )
347 {
348  function f(this->nconss+this->nvars);
349  assert(i >= 0);
350  assert(i < this->nconss+this->nvars);
351 
352  std::vector<int> neighbors = this->graph.getNeighbors(i);
353  std::transform(neighbors.begin(), neighbors.end(), neighbors.begin(), f);
354  return neighbors;
355 }
356 
357 template <class T>
359  int i
360 )
361 {
362  function f(this->nconss+this->nvars);
363  assert(i >= 0);
364  assert(i < this->nconss);
365 
366  std::vector<int> neighbors = this->graph.getNeighbors(i+this->nvars);
367  std::transform(neighbors.begin(), neighbors.end(), neighbors.begin(), f);
368  return neighbors;
369 }
370 
371 template <class T>
373  int i
374 )
375 {
376  function f(this->nconss+this->nvars);
377  assert(i >= 0);
378  assert(i < this->nvars);
379 
380  std::vector<int> neighbors = this->graph.getNeighbors(i);
381  std::transform(neighbors.begin(), neighbors.end(), neighbors.begin(), f);
382  return neighbors;
383 }
384 
385 template <class T>
387  DEC_DECOMP** decomp
388  )
389 {
390  int nblocks;
391  SCIP_HASHMAP* constoblock;
392 
393  int *nsubscipconss;
394  int i;
395  SCIP_CONS **conss;
396  SCIP_Bool emptyblocks = FALSE;
397  std::vector<int> partition = graph.getPartition();
398  conss = SCIPgetConss(this->scip_);
399 
400  nblocks = *(std::max_element(partition.begin(), partition.end()))+1;
401  SCIP_CALL( SCIPallocBufferArray(this->scip_, &nsubscipconss, nblocks) );
402  BMSclearMemoryArray(nsubscipconss, nblocks);
403 
404  SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(this->scip_), this->nconss) );
405 
406  /* assign constraints to partition */
407  for( i = 0; i < this->nconss; i++ )
408  {
409  std::set<int> blocks;
410  std::vector<int> nonzeros = getConsNonzeroNodes(i);
411  for( size_t k = 0; k < nonzeros.size(); ++k )
412  {
413  blocks.insert(partition[nonzeros[k]]);
414  }
415  if( blocks.size() > 1 )
416  {
417  SCIP_CALL( SCIPhashmapInsert(constoblock, conss[i], (void*) (size_t) (nblocks+1)) );
418  }
419  else
420  {
421  int block = *(blocks.begin());
422  SCIP_CALL( SCIPhashmapInsert(constoblock, conss[i], (void*) (size_t) (block +1)) );
423  ++(nsubscipconss[block]);
424  }
425  }
426 
427  /* first, make sure that there are constraints in every block, otherwise the hole thing is useless */
428  for( i = 0; i < nblocks; ++i )
429  {
430  if( nsubscipconss[i] == 0 )
431  {
432  SCIPdebugMessage("Block %d does not have any constraints!\n", i);
433  emptyblocks = TRUE;
434  }
435  }
436 
437  if( !emptyblocks )
438  {
439  SCIP_CALL( DECdecompCreate(this->scip_, decomp) );
440  SCIP_CALL( DECfilloutDecompFromConstoblock(this->scip_, *decomp, constoblock, nblocks, FALSE) );
441  }
442  else {
443  SCIPhashmapFree(&constoblock);
444  *decomp = NULL;
445  }
446 
447  SCIPfreeBufferArray(this->scip_, &nsubscipconss);
448  return SCIP_OKAY;
449 }
450 
451 template <class T>
453  Seeed** firstSeeed,
454  Seeed** secondSeeed,
455  Seeedpool* seeedpool
456  )
457 {
458 // int nblocks;
459 // SCIP_HASHMAP* constoblock;
460 //
461 // int *nsubscipconss;
462 // int i;
463 // SCIP_CONS **conss;
464 // SCIP_Bool emptyblocks = FALSE;
465 // std::vector<int> partition = graph.getPartition();
466 // conss = SCIPgetConss(this->scip_);
467 //
468 // nblocks = *(std::max_element(partition.begin(), partition.end()))+1;
469 // SCIP_CALL( SCIPallocBufferArray(this->scip_, &nsubscipconss, nblocks) );
470 // BMSclearMemoryArray(nsubscipconss, nblocks);
471 //
472 // SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(this->scip_), this->nconss) );
473 //
474 // /* assign constraints to partition */
475 // for( i = 0; i < this->nconss; i++ )
476 // {
477 // std::set<int> blocks;
478 // std::vector<int> nonzeros = getConsNonzeroNodes(i);
479 // for( size_t k = 0; k < nonzeros.size(); ++k )
480 // {
481 // blocks.insert(partition[nonzeros[k]]);
482 // }
483 // if( blocks.size() > 1 )
484 // {
485 // SCIP_CALL( SCIPhashmapInsert(constoblock, conss[i], (void*) (size_t) (nblocks+1)) );
486 // }
487 // else
488 // {
489 // int block = *(blocks.begin());
490 // SCIP_CALL( SCIPhashmapInsert(constoblock, conss[i], (void*) (size_t) (block +1)) );
491 // ++(nsubscipconss[block]);
492 // }
493 // }
494 //
495 // /* first, make sure that there are constraints in every block, otherwise the hole thing is useless */
496 // for( i = 0; i < nblocks; ++i )
497 // {
498 // if( nsubscipconss[i] == 0 )
499 // {
500 // SCIPdebugMessage("Block %d does not have any constraints!\n", i);
501 // emptyblocks = TRUE;
502 // }
503 // }
504 //
505 // if( !emptyblocks )
506 // {
507 // (*firstSeeed) = new Seeed(this->scip_, seeedpool->getNewIdForSeeed(), seeedpool->getNConss(), seeedpool->getNVars());
508 // SCIP_CALL( (*firstSeeed)->filloutSeeedFromConstoblock(constoblock, nblocks, seeedpool) );
509 // (*secondSeeed) = new Seeed(this->scip_, seeedpool->getNewIdForSeeed(), seeedpool->getNConss(), seeedpool->getNVars());
510 // SCIP_CALL( (*secondSeeed)->filloutBorderFromConstoblock(constoblock, nblocks, seeedpool) );
511 // SCIPhashmapFree(&constoblock);
512 // }
513 // else {
514 // SCIPhashmapFree(&constoblock);
515 // (*firstSeeed) = NULL;
516 // (*secondSeeed) = NULL;
517 // }
518 //
519 // SCIPfreeBufferArray(this->scip_, &nsubscipconss);
520 // return SCIP_OKAY;
521  int nblocks;
522  SCIP_HASHMAP* constoblock;
523 
524  int *nsubscipconss;
525  int i;
526  SCIP_CONS **conss;
527  SCIP_Bool emptyblocks = FALSE;
528  std::vector<int> partition = graph.getPartition();
529  conss = SCIPgetConss(this->scip_);
530 
531  nblocks = *(std::max_element(partition.begin(), partition.end()))+1;
532  SCIP_CALL( SCIPallocBufferArray(this->scip_, &nsubscipconss, nblocks) );
533  BMSclearMemoryArray(nsubscipconss, nblocks);
534 
535  SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(this->scip_), this->nconss) );
536 
537  /* assign constraints to partition */
538  for( i = 0; i < this->nconss; i++ )
539  {
540  std::set<int> blocks;
541  std::vector<int> nonzeros = getConsNonzeroNodes(i);
542  for( size_t k = 0; k < nonzeros.size(); ++k )
543  {
544  blocks.insert(partition[nonzeros[k]]);
545  }
546  if( blocks.size() > 1 )
547  {
548  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t)seeedpool->getIndexForCons(conss[i]), (void*) (size_t) (nblocks+1)) );
549  }
550  else
551  {
552  int block = *(blocks.begin());
553  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t) seeedpool->getIndexForCons(conss[i]), (void*) (size_t) (block +1)) );
554  ++(nsubscipconss[block]);
555  }
556  }
557 
558  /* first, make sure that there are constraints in every block, otherwise the hole thing is useless */
559  for( i = 0; i < nblocks; ++i )
560  {
561  if( nsubscipconss[i] == 0 )
562  {
563  SCIPdebugMessage("Block %d does not have any constraints!\n", i);
564  emptyblocks = TRUE;
565  }
566  }
567 
568  if( !emptyblocks )
569  {
570  (*firstSeeed) = new Seeed(this->scip_, seeedpool->getNewIdForSeeed(), seeedpool);
571  SCIP_CALL( (*firstSeeed)->filloutSeeedFromConstoblock(constoblock, nblocks) );
572  (*secondSeeed) = new Seeed(this->scip_, seeedpool->getNewIdForSeeed(), seeedpool);
573  SCIP_CALL( (*secondSeeed)->filloutBorderFromConstoblock(constoblock, nblocks) );
574  for (int col = 0; col < (*firstSeeed)->getNLinkingvars(); ++col)
575  {
576  (*secondSeeed)->setVarToLinking((*firstSeeed)->getLinkingvars()[col] );
577  (*secondSeeed)->deleteOpenvar(col);
578  }
579  SCIPhashmapFree(&constoblock);
580  }
581  else {
582  SCIPhashmapFree(&constoblock);
583  (*firstSeeed) = NULL;
584  (*secondSeeed) = NULL;
585  }
586 
587  SCIPfreeBufferArray(this->scip_, &nsubscipconss);
588  return SCIP_OKAY;
589 }
590 
591 template <class T>
593  Seeed* oldSeeed,
594  Seeed** firstSeeed,
595  Seeed** secondSeeed,
596  Seeedpool* seeedpool
597  )
598 {
599  int nblocks;
600  SCIP_HASHMAP* constoblock;
601 
602  int *nsubscipconss;
603  int i;
604  SCIP_Bool emptyblocks = FALSE;
605 
606  if(this->nconss == 0)
607  {
608  (*firstSeeed) = NULL;
609  (*secondSeeed) = NULL;
610  return SCIP_OKAY;
611  }
612 
613  std::vector<int> partition = graph.getPartition();
614 
615  nblocks = *(std::max_element(partition.begin(), partition.end()))+1;
616  SCIP_CALL( SCIPallocBufferArray(this->scip_, &nsubscipconss, nblocks) );
617  BMSclearMemoryArray(nsubscipconss, nblocks);
618 
619  SCIP_CALL( SCIPhashmapCreate(&constoblock, SCIPblkmem(this->scip_), this->nconss) );
620 
621  //fillout conssForGraph
622  vector<int> conssForGraph;
623  vector<bool> conssBool(oldSeeed->getNConss(), false);
624  bool found;
625 
626  for(int c = 0; c < oldSeeed->getNOpenconss(); ++c)
627  {
628  int cons = oldSeeed->getOpenconss()[c];
629  found = false;
630  for(int v = 0; v < oldSeeed->getNOpenvars() && !found; ++v)
631  {
632  int var = oldSeeed->getOpenvars()[v];
633  for(i = 0; i < seeedpool->getNVarsForCons(cons) && !found; ++i)
634  {
635  if(var == seeedpool->getVarsForCons(cons)[i])
636  {
637  conssBool[cons] = true;
638  found = true;
639  }
640  }
641  }
642  }
643 
644  for(int c = 0; c < oldSeeed->getNOpenconss(); ++c)
645  {
646  int cons = oldSeeed->getOpenconss()[c];
647  if(conssBool[cons])
648  conssForGraph.push_back(cons);
649  }
650 
651 
652  /* assign constraints to partition */
653  for( i = 0; i < this->nconss; i++ )
654  {
655  std::set<int> blocks;
656  std::vector<int> nonzeros = getConsNonzeroNodes(i);
657  for( size_t k = 0; k < nonzeros.size(); ++k )
658  {
659  blocks.insert(partition[nonzeros[k]]);
660  }
661  if( blocks.size() > 1 )
662  {
663  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t) conssForGraph[i], (void*) (size_t) (nblocks+1)) );
664  }
665  else
666  {
667  int block = *(blocks.begin());
668  SCIP_CALL( SCIPhashmapInsert(constoblock, (void*) (size_t) conssForGraph[i], (void*) (size_t) (block +1)) );
669  ++(nsubscipconss[block]);
670  }
671  }
672 
673  /* first, make sure that there are constraints in every block, otherwise the hole thing is useless */
674  for( i = 0; i < nblocks; ++i )
675  {
676  if( nsubscipconss[i] == 0 )
677  {
678  SCIPdebugMessage("Block %d does not have any constraints!\n", i);
679  emptyblocks = TRUE;
680  }
681  }
682 
683  if( !emptyblocks )
684  {
685  (*firstSeeed) = new Seeed(oldSeeed);
686  SCIP_CALL( (*firstSeeed)->assignSeeedFromConstoblock(constoblock, nblocks) );
687  (*secondSeeed) = new Seeed(oldSeeed);
688  SCIP_CALL( (*secondSeeed)->assignBorderFromConstoblock(constoblock, nblocks) );
689  SCIPhashmapFree(&constoblock);
690  }
691  else {
692  SCIPhashmapFree(&constoblock);
693  (*firstSeeed) = NULL;
694  (*secondSeeed) = NULL;
695  }
696 
697  SCIPfreeBufferArray(this->scip_, &nsubscipconss);
698  return SCIP_OKAY;
699 }
700 
701 template <class T>
703  const char* filename
704  )
705 {
706 
707  ifstream input(filename);
708  if( !input.good() )
709  {
710  SCIPerrorMessage("Could not open file <%s> for reading\n", filename);
711  return SCIP_READERROR;
712  }
713  for( int i = 0; i < this->nnonzeroes; ++i )
714  {
715  int part = 0;
716  if( !(input >> part) )
717  {
718  SCIPerrorMessage("Could not read from file <%s>. It may be in the wrong format\n", filename);
719  return SCIP_READERROR;
720  }
721  graph.setPartition(i,part);
722  }
723 
724  input.close();
725  return SCIP_OKAY;
726 
727 }
728 
729 } /* namespace gcg */
730 #endif
std::string name
Definition: matrixgraph.h:56
int getNVarsForCons(int consIndex)
returns the number of variables for a given constraint
const int * getOpenconss()
returns array containing constraints not assigned yet
int getNVars()
returns number of vars
GraphInterface * graphiface
Definition: matrixgraph.h:63
int getNewIdForSeeed()
returns a new unique id for a new seeed
int operator()(int i) const
int getNConss()
returns the number of constraints
virtual SCIP_RETCODE writeToFile(int fd, SCIP_Bool writeweights)
virtual SCIP_RETCODE createSeeedFromPartition(Seeed **firstSeeed, Seeed **secondSeeed, Seeedpool *seeedpool)
int getNOpenvars()
returns size of vector containing variables not assigned yet
SCIP_VAR * getVarForIndex(int varIndex)
returns SCIP variable related to a variable index
virtual SCIP_RETCODE readPartition(const char *filename)
std::vector< int > getConsNonzeroNodes(int i)
various SCIP helper methods
class to manage partial decompositions (aka seeed), each seeed corresponds to one seeedpool which con...
Definition: class_seeed.h:71
SCIP_RETCODE setVarToLinking(int varToLinking)
adds a variable to the linking variables, does not delete this var from list of open vars ...
virtual SCIP_RETCODE createDecompFromPartition(DEC_DECOMP **decomp)
std::vector< int > getVarNonzeroNodes(int i)
SCIP_RETCODE DECdecompCreate(SCIP *scip, DEC_DECOMP **decdecomp)
Definition: decomp.c:467
A hypergraph with row and column nodes.
int getIndexForCons(SCIP_CONS *cons)
returns the constraint index related to a SCIP constraint
virtual std::vector< int > getHyperedgeNodes(int i)
SCIP_Bool GCGisVarRelevant(SCIP_VAR *var)
Definition: scip_misc.c:41
int calculate(SCIP_CONS *cons) const
Definition: weights.cpp:73
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)
const int * getOpenvars()
returns array containing variables not assigned yet
virtual std::vector< int > getNeighbors(int i)
SCIP_RETCODE DECfilloutDecompFromConstoblock(SCIP *scip, DEC_DECOMP *decomp, SCIP_HASHMAP *constoblock, int nblocks, SCIP_Bool staircase)
Definition: decomp.c:1454
HyperrowcolGraph(SCIP *scip, Weights w)
int getNOpenconss()
returns size of vector containing constraints not assigned yet
class with functions for seeed pool where a seeed is a (potentially incomplete) description of a deco...
SCIP_RETCODE createFromMatrix(SCIP_CONS **conss, SCIP_VAR **vars, int nconss, int nvars)
virtual SCIP_RETCODE createFromPartialMatrix(Seeedpool *seeedpool, Seeed *seeed)
SCIP_CONS * getConsForIndex(int consIndex)
returns the SCIP constraint related to a constraint index
struct DecDecomp DEC_DECOMP
Definition: type_decomp.h:43
const int * getVarsForCons(int consIndex)
returns the variable indices of the coefficient matrix for a constraint