GCG 4.1.1 (dev)

Generic Column Generation

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