Scippy

GCG

Branch-and-Price & Column Generation for Everyone

reader_dec.cpp
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 reader_dec.cpp
30 * @brief DEC file reader for structure information
31 * @author Lukas Kirchhart
32 * @author Martin Bergner
33 * @author Gerald Gamrath
34 * @author Christian Puchert
35 * @author Michael Bastubbe
36 */
37
38/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
39
40/* #define SCIP_DEBUG */
41
42#include <assert.h>
43#include <string.h>
44#include <ctype.h>
45
46#include "gcg/reader_dec.h"
47#include "gcg/scip_misc.h"
48#include "gcg/pub_gcgvar.h"
49
50#include "gcg/cons_decomp.h"
51#include "gcg/cons_decomp.hpp"
52#include "gcg/pub_decomp.h"
53
56
57#define READER_NAME "decreader"
58#define READER_DESC "file reader for blocks in dec format"
59#define READER_EXTENSION "dec"
60
61
62/*
63 * Data structures
64 */
65#define DEC_MAX_LINELEN 65536
66#define DEC_MAX_PUSHEDTOKENS 2
67
68/** section in DEC File */
70{
72};
74
75/** exponent indicator of the a value */
77{
79};
81
82/** DEC reading data */
84{
85 SCIP_FILE* file; /**< file to read */
86 char linebuf[DEC_MAX_LINELEN]; /**< line buffer */
87 char* token; /**< current token */
88 char* tokenbuf; /**< token buffer */
89 char* pushedtokens[DEC_MAX_PUSHEDTOKENS]; /**< token stack */
90 int npushedtokens; /**< size of token buffer */
91 int linenumber; /**< current line number */
92 int linepos; /**< current line position (column) */
93 SCIP_Bool presolved; /**< does the decomposition refer to the presolved problem? */
94 SCIP_Bool haspresolvesection; /**< does the decomposition have a presolved section */
95 SCIP_Bool incomplete; /**< if false the unspecified constraints should be forced to the master (for downward compatibility) */
96 int nblocks; /**< number of blocks */
97 int blocknr; /**< number of the currentblock between 0 and Nblocks-1*/
98 DECSECTION section; /**< current section */
99 SCIP_Bool haserror; /**< flag to indicate an error occurence */
100 gcg::PARTIALDECOMP* partialdec; /**< incomplete decomposition */
101};
102typedef struct DecInput DECINPUT;
103
104/** data for dec reader */
105struct SCIP_ReaderData
106{
107 GCG* gcg; /**< GCG data structure */
108};
109
110static const int NOVALUE = -1;
111static const int LINKINGVALUE = -2;
112static const char delimchars[] = " \f\n\r\t\v";
113static const char tokenchars[] = "-+:<>=";
114static const char commentchars[] = "\\";
115
116/*
117 * Local methods (for reading)
118 */
119
120/** issues an error message and marks the DEC data to have errors */
121static
123 SCIP* scip, /**< SCIP data structure */
124 DECINPUT* decinput, /**< DEC reading data */
125 const char* msg /**< error message */
126 )
127{
128 char formatstr[256];
129
130 assert(decinput != NULL);
131
132 SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "Syntax error in line %d: %s ('%s')\n",
133 decinput->linenumber, msg, decinput->token);
134 if( decinput->linebuf[strlen(decinput->linebuf) - 1] == '\n' )
135 {
136 SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, " input: %s", decinput->linebuf);
137 }
138 else
139 {
140 SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, " input: %s\n", decinput->linebuf);
141 }
142 (void) SCIPsnprintf(formatstr, 256, " %%%ds\n", decinput->linepos);
144 decinput->section = DEC_END;
145 decinput->haserror = TRUE;
146}
147
148/** returns whether a syntax error was detected */
149static
151 DECINPUT* decinput /**< DEC reading data */
152 )
153{
154 assert(decinput != NULL);
155 return decinput->haserror;
156}
157
158/** returns whether the given character is a token delimiter */
159static
161 char c /**< input character */
162 )
163{
164 return (c == '\0') || (strchr(delimchars, c) != NULL);
165}
166
167/** returns whether the given character is a single token */
168static
170 char c /**< input character */
171 )
172{
173 return (strchr(tokenchars, c) != NULL);
174}
175
176/** returns whether the current character is member of a value string */
177static
179 char c, /**< input character */
180 char nextc, /**< next input character */
181 SCIP_Bool firstchar, /**< is the given character the first char of the token? */
182 SCIP_Bool* hasdot, /**< pointer to update the dot flag */
183 DECEXPTYPE* exptype /**< pointer to update the exponent type */
184 )
185{ /*lint --e{715}*/
186 assert(hasdot != NULL);
187 assert(exptype != NULL);
188
189 if( isdigit(c) )
190 return TRUE;
191
192 return FALSE;
193}
194
195/** reads the next line from the input file into the line buffer; skips comments;
196 * returns whether a line could be read
197 */
198static
200 DECINPUT* decinput /**< DEC reading data */
201 )
202{
203 int i;
204
205 assert(decinput != NULL);
206
207 /* clear the line */
209
210 /* read next line */
211 decinput->linepos = 0;
212 decinput->linebuf[DEC_MAX_LINELEN - 2] = '\0';
213 if( SCIPfgets(decinput->linebuf, DEC_MAX_LINELEN, decinput->file) == NULL )
214 return FALSE;
215 decinput->linenumber ++;
216 if( decinput->linebuf[DEC_MAX_LINELEN - 2] != '\0' )
217 {
218 SCIPerrorMessage("Error: line %d exceeds %d characters\n", decinput->linenumber, DEC_MAX_LINELEN - 2);
219 decinput->haserror = TRUE;
220 return FALSE;
221 }
222 decinput->linebuf[DEC_MAX_LINELEN - 1] = '\0';
223 decinput->linebuf[DEC_MAX_LINELEN - 2] = '\0'; /* we want to use lookahead of one char -> we need two \0 at the end */
224
225 /* skip characters after comment symbol */
226 for( i = 0; commentchars[i] != '\0'; ++ i )
227 {
228 char* commentstart;
229
230 commentstart = strchr(decinput->linebuf, commentchars[i]);
231 if( commentstart != NULL )
232 {
233 *commentstart = '\0';
234 *(commentstart + 1) = '\0'; /* we want to use lookahead of one char -> we need two \0 at the end */
235 }
236 }
237
238 return TRUE;
239}
240
241/** swaps the addresses of two pointers */
242static
244 char** pointer1, /**< first pointer */
245 char** pointer2 /**< second pointer */
246 )
247{
248 char* tmp;
249
250 tmp = * pointer1;
251 *pointer1 = * pointer2;
252 *pointer2 = tmp;
253}
254
255/** reads the next token from the input file into the token buffer; returns whether a token was read */
256static
258 DECINPUT* decinput /**< DEC reading data */
259 )
260{
261 SCIP_Bool hasdot;
262 DECEXPTYPE exptype;
263 char* buf;
264 int tokenlen;
265
266 assert(decinput != NULL);
267 assert(decinput->linepos < DEC_MAX_LINELEN);
268
269 /* check the token stack */
270 if( decinput->npushedtokens > 0 )
271 {
272 swapPointers(&decinput->token, &decinput->pushedtokens[decinput->npushedtokens - 1]);
273 decinput->npushedtokens --;
274 SCIPdebugMessage("(line %d) read token again: '%s'\n", decinput->linenumber, decinput->token);
275 return TRUE;
276 }
277
278 /* skip delimiters */
279 buf = decinput->linebuf;
280 while( isDelimChar(buf[decinput->linepos]) )
281 {
282 if( buf[decinput->linepos] == '\0' )
283 {
284 if( !getNextLine(decinput) )
285 {
286 decinput->section = DEC_END;
287 SCIPdebugMessage("(line %d) end of file\n", decinput->linenumber);
288 return FALSE;
289 }
290 assert(decinput->linepos == 0);
291 }
292 else
293 decinput->linepos ++;
294 }
295 assert(decinput->linepos < DEC_MAX_LINELEN);
296 assert(! isDelimChar(buf[decinput->linepos]));
297
298 /* check if the token is a value */
299 hasdot = FALSE;
300 exptype = DEC_EXP_NONE;
301 if( isValueChar(buf[decinput->linepos], buf[decinput->linepos + 1], TRUE, &hasdot, &exptype) ) /*lint !e679*/
302 {
303 /* read value token */
304 tokenlen = 0;
305 do
306 {
307 assert(tokenlen < DEC_MAX_LINELEN);
308 assert(! isDelimChar(buf[decinput->linepos]));
309 decinput->token[tokenlen] = buf[decinput->linepos];
310 ++tokenlen;
311 ++(decinput->linepos);
312 assert(decinput->linepos < DEC_MAX_LINELEN-1);
313 }
314 while( isValueChar(buf[decinput->linepos], buf[decinput->linepos + 1], FALSE, &hasdot, &exptype) ); /*lint !e679*/
315 }
316 else
317 {
318 /* read non-value token */
319 tokenlen = 0;
320 do
321 {
322 assert(tokenlen < DEC_MAX_LINELEN);
323 decinput->token[tokenlen] = buf[decinput->linepos];
324 tokenlen ++;
325 decinput->linepos ++;
326 if( tokenlen == 1 && isTokenChar(decinput->token[0]) )
327 break;
328 }
329 while( !isDelimChar(buf[decinput->linepos]) && ! isTokenChar(buf[decinput->linepos]) );
330
331 /* if the token is an equation sense '<', '>', or '=', skip a following '='
332 * if the token is an equality token '=' and the next character is a '<' or '>', replace the token by the inequality sense
333 */
334 if( tokenlen >= 1
335 && (decinput->token[tokenlen - 1] == '<' || decinput->token[tokenlen - 1] == '>' || decinput->token[tokenlen - 1] == '=')
336 && buf[decinput->linepos] == '=' )
337 {
338 decinput->linepos ++;
339 }
340 else if( decinput->token[tokenlen - 1] == '=' && (buf[decinput->linepos] == '<' || buf[decinput->linepos] == '>') )
341 {
342 decinput->token[tokenlen - 1] = buf[decinput->linepos];
343 decinput->linepos ++;
344 }
345 }
346 assert(tokenlen < DEC_MAX_LINELEN);
347 decinput->token[tokenlen] = '\0';
348
349 SCIPdebugMessage("(line %d) read token: '%s'\n", decinput->linenumber, decinput->token);
350
351 return TRUE;
352}
353
354/** puts the current token on the token stack, such that it is read at the next call to getNextToken() */
355static
357 DECINPUT* decinput /**< DEC reading data */
358 )
359{
360 assert(decinput != NULL);
361 assert(decinput->npushedtokens < DEC_MAX_PUSHEDTOKENS);
362
363 swapPointers(&decinput->pushedtokens[decinput->npushedtokens], &decinput->token);
364 decinput->npushedtokens ++;
365}
366
367/** swaps the current token with the token buffer */
368static
370 DECINPUT* decinput /**< DEC reading data */
371 )
372{
373 assert(decinput != NULL);
374
375 swapPointers(&decinput->token, &decinput->tokenbuf);
376}
377
378/** returns whether the current token is a value */
379static
381 SCIP* scip, /**< SCIP data structure */
382 DECINPUT* decinput, /**< DEC reading data */
383 int* value /**< pointer to store the value (unchanged, if token is no value) */
384 )
385{
386 long val;
387 char* endptr;
388
389 assert(decinput != NULL);
390 assert(value != NULL);
391 assert(!(SCIPstrcasecmp(decinput->token, "INFINITY") == 0) && !(SCIPstrcasecmp(decinput->token, "INF") == 0));
392
393 val = strtol(decinput->token, &endptr, 0);
394 if( endptr != decinput->token && * endptr == '\0' )
395 {
396 if( val < INT_MIN || val > INT_MAX ) /*lint !e685*/
397 return FALSE;
398
399 *value = (int) val;
400 return TRUE;
401 }
402
403 return FALSE;
404}
405
406/** checks whether the current token is a section identifier, and if yes, switches to the corresponding section */
407static
409 SCIP* scip, /**< SCIP data structure */
410 DECINPUT* decinput /**< DEC reading data */
411 )
412{
413
414 assert(decinput != NULL);
415
416 /* remember first token by swapping the token buffer */
417 swapTokenBuffer(decinput);
418
419 /* look at next token: if this is a ':', the first token is a name and no section keyword */
420 if( getNextToken(decinput) )
421 {
422 pushToken(decinput);
423 }
424
425 /* reinstall the previous token by swapping back the token buffer */
426 swapTokenBuffer(decinput);
427
428 if( SCIPstrcasecmp(decinput->token, "INCOMPLETE") == 0 )
429 {
430 SCIPdebugMessage("(line %d) new section: INCOMPLETE\n", decinput->linenumber);
431 decinput->section = DEC_INCOMPLETE;
432 return TRUE;
433 }
434
435 if( SCIPstrcasecmp(decinput->token, "PRESOLVED") == 0 )
436 {
437 SCIPdebugMessage("(line %d) new section: PRESOLVED\n", decinput->linenumber);
438 decinput->section = DEC_PRESOLVED;
439 return TRUE;
440 }
441
442 if( SCIPstrcasecmp(decinput->token, "NBLOCKS") == 0 )
443 {
444 SCIPdebugMessage("(line %d) new section: NBLOCKS\n", decinput->linenumber);
445 decinput->section = DEC_NBLOCKS;
446 return TRUE;
447 }
448
449 if( SCIPstrcasecmp(decinput->token, "BLOCK") == 0 || SCIPstrcasecmp(decinput->token, "BLOCKCONSS") == 0 || SCIPstrcasecmp(decinput->token, "BLOCKCONS") == 0)
450 {
451 int blocknr;
452
453 decinput->section = DEC_BLOCKCONSS;
454
455 if( getNextToken(decinput) )
456 {
457 /* read block number */
458 if( isInt(scip, decinput, &blocknr) )
459 {
460 assert(blocknr >= 0);
461 assert(blocknr <= decinput->nblocks);
462
463 decinput->blocknr = blocknr - 1;
464 }
465 else
466 syntaxError(scip, decinput, "no block number after block keyword!\n");
467 }
468 else
469 syntaxError(scip, decinput, "no block number after block keyword!\n");
470
471 SCIPdebugMessage("new section: BLOCKCONSS %d\n", decinput->blocknr);
472
473 return TRUE;
474
475 }
476
477 if( SCIPstrcasecmp(decinput->token, "MASTERCONSS") == 0 || SCIPstrcasecmp(decinput->token, "MASTERCONS") == 0 )
478 {
479 decinput->section = DEC_MASTERCONSS;
480
481 SCIPdebugMessage("new section: MASTERCONSS\n");
482
483 return TRUE;
484 }
485
486 if( SCIPstrcasecmp(decinput->token, "BLOCKVARS") == 0 || SCIPstrcasecmp(decinput->token, "BLOCKVAR") == 0 )
487 {
488 int blocknr;
489
490 decinput->section = DEC_BLOCKVARS;
491
492 if( getNextToken(decinput) )
493 {
494 /* read block number */
495 if( isInt(scip, decinput, &blocknr) )
496 {
497 assert(blocknr >= 0);
498 assert(blocknr <= decinput->nblocks);
499
500 decinput->blocknr = blocknr - 1;
501 }
502 else
503 syntaxError(scip, decinput, "no block number after block keyword!\n");
504 }
505 else
506 syntaxError(scip, decinput, "no block number after block keyword!\n");
507
508 SCIPdebugMessage("new section: BLOCKVARS %d\n", decinput->blocknr);
509
510 return TRUE;
511
512 }
513
514 if( SCIPstrcasecmp(decinput->token, "MASTERVARS") == 0 || SCIPstrcasecmp(decinput->token, "MASTERVAR") == 0
515 || SCIPstrcasecmp(decinput->token, "STATICVAR") == 0 || SCIPstrcasecmp(decinput->token, "STATICVARS") == 0 )
516 {
517 decinput->section = DEC_MASTERVARS;
518
519 SCIPdebugMessage("new section: MASTERVARS\n");
520
521 return TRUE;
522 }
523
524 if( SCIPstrcasecmp(decinput->token, "LINKINGVARS") == 0 || SCIPstrcasecmp(decinput->token, "LINKINGVAR") == 0 )
525 {
526 decinput->section = DEC_LINKINGVARS;
527
528 SCIPdebugMessage("new section: LINKINGVARS\n");
529
530 return TRUE;
531 }
532
533 return FALSE;
534}
535
536/** reads the header of the file */
537static
539 SCIP* scip, /**< SCIP data structure */
540 DECINPUT* decinput /**< DEC reading data */
541 )
542{
543 assert(decinput != NULL);
544
545 /* everything before first section is treated as comment */
546 do
547 {
548 /* get token */
549 if( !getNextToken(decinput) )
550 return SCIP_OKAY;
551 }
552 while( !isNewSection(scip, decinput) );
553
554 return SCIP_OKAY;
555}
556
557/** reads the incomplete section */
558static
560 SCIP* scip, /**< SCIP data structure */
561 DECINPUT* decinput /**< DEC reading data */
562 )
563{
564 int incomplete;
565
566 assert(scip != NULL);
567 assert(decinput != NULL);
568
569 while( getNextToken(decinput) )
570 {
571 /* check if we reached a new section */
572 if( isNewSection(scip, decinput) )
573 return SCIP_OKAY;
574
575 /* read if the consdefaultmaster */
576 if( isInt(scip, decinput, &incomplete) )
577 {
578 if( incomplete == 1 )
579 decinput->incomplete = TRUE;
580 else if ( incomplete == 0 )
581 decinput->incomplete = FALSE;
582 else
583 syntaxError(scip, decinput, "incomplete parameter must be 0 or 1");
584
585 SCIPdebugMessage("The constraints that are not specified in this decomposition are %s forced to the master\n",
586 decinput->incomplete ? "" : " not");
587 }
588 }
589
590 return SCIP_OKAY;
591}
592
593
594/** reads the presolved section */
595static
597 SCIP* scip, /**< SCIP data structure */
598 DECINPUT* decinput /**< DEC reading data */
599 )
600{
601 int presolved;
602
603 assert(scip != NULL);
604 assert(decinput != NULL);
605
606 while( getNextToken(decinput) )
607 {
608 /* check if we reached a new section */
609 if( isNewSection(scip, decinput) )
610 return SCIP_OKAY;
611
612 /* read number of blocks */
613 if( isInt(scip, decinput, &presolved) )
614 {
615 decinput->haspresolvesection = TRUE;
616 if( presolved == 1 )
617 {
618 decinput->presolved = TRUE;
619 }
620 else if ( presolved == 0 )
621 {
622 decinput->presolved = FALSE;
623 }
624 else
625 syntaxError(scip, decinput, "presolved parameter must be 0 or 1");
626 SCIPdebugMessage("Decomposition is%s from presolved problem\n",
627 decinput->presolved ? "" : " not");
628 }
629 }
630
631 return SCIP_OKAY;
632}
633
634/** reads the nblocks section */
635static
637 SCIP* scip, /**< SCIP data structure */
638 DECINPUT* decinput /**< DEC reading data */
639 )
640{
641 int nblocks;
642
643 assert(scip != NULL);
644 assert(decinput != NULL);
645 assert(decinput->partialdec != NULL);
646
647 while( getNextToken(decinput) )
648 {
649 /* check if we reached a new section */
650 if( isNewSection(scip, decinput) )
651 {
652 if( decinput->nblocks == NOVALUE )
653 syntaxError(scip, decinput, "no integer value in nblocks section");
654 else
655 return SCIP_OKAY;
656 }
657
658 /* read number of blocks */
659 if( isInt(scip, decinput, &nblocks) )
660 {
661 if( decinput->nblocks == NOVALUE )
662 {
663 decinput->nblocks = nblocks;
664 decinput->partialdec->setNBlocks(nblocks);
665 }
666 else
667 syntaxError(scip, decinput, "2 integer values in nblocks section");
668 SCIPdebugMessage("Number of blocks = %d\n", decinput->nblocks);
669 }
670 }
671
672 return SCIP_OKAY;
673}
674
675/** reads the blocks section */
676static
678 SCIP* scip, /**< SCIP data structure */
679 DECINPUT* decinput, /**< DEC reading data */
680 SCIP_READERDATA* readerdata /**< reader data */
681 )
682{
683 int blockid;
684 int currblock;
685
686 SCIP_Bool success;
687 assert(decinput != NULL);
688 assert(readerdata != NULL);
689 assert(decinput->partialdec != NULL);
690
691 currblock = 0;
692
693 while( getNextToken(decinput) )
694 {
695 int i;
696 SCIP_CONS* cons;
697 SCIP_VAR** curvars = NULL;
698 int ncurvars;
699
700 SCIP_Bool conshasvar = FALSE;
701 /* check if we reached a new section */
702 if( isNewSection(scip, decinput) )
703 break;
704
705 /* the token must be the name of an existing cons */
706 if( decinput->presolved )
707 cons = SCIPfindCons(scip, decinput->token);
708 else
709 cons = SCIPfindOrigCons(scip, decinput->token);
710 if( cons == NULL )
711 {
712 syntaxError(scip, decinput, "unknown constraint in block section");
713 decinput->haserror = TRUE;
714 break;
715 }
716
717 if( !SCIPconsIsActive(cons) && decinput->presolved )
718 {
719 SCIPdebugMessage("cons is not active, skip it \n");
720 continue;
721 }
722
723 /* get all curvars for the specific constraint */
724 SCIP_CALL( SCIPgetConsNVars(scip, cons, &ncurvars, &success) );
725 assert(success);
726 if( ncurvars > 0 )
727 {
728 SCIP_CALL( SCIPallocBufferArray(scip, &curvars, ncurvars) );
729 SCIP_CALL( SCIPgetConsVars(scip, cons, curvars, ncurvars, &success) );
730 assert(success);
731 }
732
733 blockid = decinput->blocknr;
734
735 for( i = 0; i < ncurvars; i ++ )
736 {
737 assert(curvars != NULL); /* for flexelint */
738 if( decinput->presolved )
739 {
740 SCIP_VAR* var = SCIPvarGetProbvar(curvars[i]);
741 if( !GCGisVarRelevant(var) )
742 continue;
743 }
744
745 conshasvar = TRUE;
746 break; /* found var */
747 }
748
749 SCIPfreeBufferArrayNull(scip, &curvars);
750
751 if( !conshasvar )
752 {
753 SCIPdebugMessage("Cons <%s> has been deleted by presolving or has no variable at all.\n", SCIPconsGetName(cons) );
754 decinput->partialdec->fixConsToBlockByName(decinput->token, currblock);
755 ++currblock;
756 currblock = currblock % decinput->nblocks;
757 continue;
758 }
759 /*
760 * saving block <-> constraint
761 */
762
763 if( !decinput->partialdec->isConsOpencons(decinput->partialdec->getDetprobdata()->getIndexForCons(cons)) )
764 {
765 decinput->haserror = TRUE;
766 SCIPwarningMessage(scip, "cons %s is already assigned but is supposed to assigned to %d\n", SCIPconsGetName(cons), (blockid+1));
767 return SCIP_OKAY;
768 }
769
770 SCIPdebugMessage("cons %s is in block %d\n", SCIPconsGetName(cons), blockid);
771 decinput->partialdec->fixConsToBlockByName(decinput->token, blockid);
772 }
773
774 return SCIP_OKAY;
775}
776
777/** reads the block vars section */
778static
780 SCIP* scip, /**< SCIP data structure */
781 DECINPUT* decinput, /**< DEC reading data */
782 SCIP_READERDATA* readerdata /**< reader data */
783 )
784{
785 int blockid;
786
787 assert(decinput != NULL);
788 assert(readerdata != NULL);
789 assert(decinput->partialdec != NULL);
790
791 while( getNextToken(decinput) )
792 {
793 SCIP_Var* var;
794
795 /* check if we reached a new section */
796 if( isNewSection(scip, decinput) )
797 break;
798
799 /* the token must be the name of an existing cons */
800 var = SCIPfindVar(scip, decinput->token);
801 if( var == NULL )
802 {
803 syntaxError(scip, decinput, "unknown variable in block section");
804 break;
805 }
806
807 if( !SCIPvarIsActive(var) )
808 {
809 SCIPwarningMessage(scip, "Var <%s> has been fixed or aggregated by presolving, skipping.\n", SCIPvarGetName(var));
810 continue;
811 }
812
813 blockid = decinput->blocknr;
814 decinput->partialdec->fixVarToBlockByName(decinput->token, blockid);
815 }
816
817 return SCIP_OKAY;
818}
819
820/** reads the masterconss section */
821static
823 SCIP* scip, /**< SCIP data structure */
824 DECINPUT* decinput, /**< DEC reading data */
825 SCIP_READERDATA* readerdata /**< reader data */
826 )
827{
828 assert(scip != NULL);
829 assert(decinput != NULL);
830 assert(readerdata != NULL);
831 assert(decinput->partialdec != NULL);
832
833 while( getNextToken(decinput) )
834 {
835 int cons;
836
837 /* check if we reached a new section */
838 if( isNewSection(scip, decinput) )
839 break;
840
841 /* the token must be the name of an existing constraint */
842 cons = decinput->partialdec->getDetprobdata()->getIndexForCons(decinput->token);
843
844 if( cons < 0 )
845 {
846 syntaxError(scip, decinput, "unknown or deleted constraint in masterconss section");
847 break;
848 }
849 else
850 {
851 decinput->partialdec->fixConsToMaster(cons);
852 SCIPdebugMessage("cons %s is linking constraint\n", decinput->token);
853 }
854 }
855
856 return SCIP_OKAY;
857}
858
859/** reads the mastervars section */
860static
862 SCIP* scip, /**< SCIP data structure */
863 DECINPUT* decinput, /**< DEC reading data */
864 SCIP_READERDATA* readerdata /**< reader data */
865 )
866{
867 assert(scip != NULL);
868 assert(decinput != NULL);
869 assert(readerdata != NULL);
870 assert(decinput->partialdec != NULL);
871
872 while( getNextToken(decinput) )
873 {
874 SCIP_VAR* var;
875
876 /* check if we reached a new section */
877 if( isNewSection(scip, decinput) )
878 break;
879
880 /* the token must be the name of an existing constraint */
881 var = SCIPfindVar(scip, decinput->token);
882 if( var == NULL )
883 {
884 syntaxError(scip, decinput, "unknown constraint in mastervars section");
885 break;
886 }
887 else
888 {
889 if( !SCIPvarIsActive(var) )
890 {
891 SCIPdebugMessage("Var <%s> has been fixed or aggregated by presolving, skipping.\n", SCIPvarGetName(var));
892 continue;
893 }
894
895 decinput->partialdec->fixVarToMasterByName(decinput->token);
896
897 SCIPdebugMessage("var %s is master constraint\n", decinput->token);
898 }
899 }
900
901 return SCIP_OKAY;
902}
903
904/** reads the linkingvars section */
905static
907 SCIP* scip, /**< SCIP data structure */
908 DECINPUT* decinput, /**< DEC reading data */
909 SCIP_READERDATA* readerdata /**< reader data */
910 )
911{
912 assert(scip != NULL);
913 assert(decinput != NULL);
914 assert(readerdata != NULL);
915 assert(decinput->partialdec != NULL);
916
917 while( getNextToken(decinput) )
918 {
919 SCIP_Var* var;
920
921 /* check if we reached a new section */
922 if( isNewSection(scip, decinput) )
923 break;
924
925 /* the token must be the name of an existing constraint */
926 var = SCIPfindVar(scip, decinput->token);
927 if( var == NULL )
928 {
929 syntaxError(scip, decinput, "unknown constraint in masterconss section");
930 break;
931 }
932 else
933 {
934 if( !SCIPvarIsActive(var) )
935 {
936 SCIPwarningMessage(scip, "Var <%s> has been fixed or aggregated by presolving, skipping.\n", SCIPvarGetName(var));
937 continue;
938 }
939
940 decinput->partialdec->fixVarToLinkingByName(decinput->token);
941
942 SCIPdebugMessage("cons %s is linking constraint\n", decinput->token);
943 }
944 }
945
946 return SCIP_OKAY;
947}
948
949/** Reads the file and sets the decinput->presolved flag. Resets the file stream afterward.*/
950static
952 SCIP* scip, /**< SCIP data structure */
953 DECINPUT* decinput /**< DEC reading data */
954 )
955{
956 while( getNextToken(decinput) )
957 {
958 if( isNewSection(scip, decinput) && decinput->section == DEC_PRESOLVED )
959 {
960 SCIP_CALL( readPresolved(scip, decinput) );
961 break;
962 }
963 }
964 SCIPrewind(decinput->file);
965 decinput->section = DEC_START;
966 return SCIP_OKAY;
967}
968
969/** reads a DEC file */
970static
972 SCIP* scip, /**< SCIP data structure */
973 SCIP_READER* reader, /**< Reader data structure */
974 DECINPUT* decinput, /**< DEC reading data */
975 const char* filename /**< name of the input file */
976 )
977{
978 SCIP_READERDATA* readerdata;
979
980 assert(decinput != NULL);
981 assert(scip != NULL);
982 assert(reader != NULL);
983
985 {
986 SCIPverbMessage(scip, SCIP_VERBLEVEL_DIALOG, NULL, "No problem exists, will not read structure!\n");
987 return SCIP_OKAY;
988 }
989
990 /* open file */
991 decinput->file = SCIPfopen(filename, "r");
992 if( decinput->file == NULL )
993 {
994 SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
995 SCIPprintSysError(filename);
996 return SCIP_NOFILE;
997 }
998
999 readerdata = SCIPreaderGetData(reader);
1000 assert(readerdata != NULL);
1001
1002 /* parse the file */
1003 decinput->section = DEC_START;
1004
1005 setPresolved(scip, decinput);
1006 if( decinput->presolved && SCIPgetStage(scip) < SCIP_STAGE_PRESOLVED )
1007 {
1008 SCIPinfoMessage(scip, NULL, "read presolved decomposition but problem is not presolved yet -> presolve()\n");
1010 assert(decinput->haspresolvesection);
1011 }
1012
1013 decinput->partialdec = new gcg::PARTIALDECOMP(readerdata->gcg, !decinput->presolved);
1014
1015 while( decinput->section != DEC_END && !hasError(decinput) )
1016 {
1017 switch( decinput->section )
1018 {
1019 case DEC_START:
1020 SCIP_CALL( readStart(scip, decinput) );
1021 break;
1022 case DEC_INCOMPLETE:
1023 SCIP_CALL( readIncomplete(scip, decinput) );
1024 break;
1025 case DEC_PRESOLVED:
1026 while( getNextToken(decinput) )
1027 {
1028 if( isNewSection(scip, decinput) )
1029 {
1030 break;
1031 }
1032 }
1033 break;
1034 case DEC_NBLOCKS:
1035 SCIP_CALL( readNBlocks(scip, decinput) );
1036 if( decinput->haspresolvesection && !decinput->presolved && SCIPgetStage(scip) >= SCIP_STAGE_PRESOLVED )
1037 {
1038 SCIPwarningMessage(scip, "decomposition belongs to the unpresolved problem, but the problem is already presolved, please consider to re-read the problem and read the decomposition without presolving when transforming do not succeed.\n");
1039 break;
1040
1041 }
1042 if( !decinput->haspresolvesection )
1043 {
1044 SCIPwarningMessage(scip, "decomposition has no presolve section at beginning. The behaviour is undefined. Please add a presolve section. File reading is aborted. \n");
1045 }
1046 break;
1047
1048 case DEC_BLOCKCONSS:
1049 SCIP_CALL( readBlockconss(scip, decinput, readerdata) );
1050 break;
1051
1052 case DEC_MASTERCONSS:
1053 SCIP_CALL( readMasterconss(scip, decinput, readerdata) );
1054 break;
1055
1056 case DEC_BLOCKVARS:
1057 SCIP_CALL( readBlockvars(scip, decinput, readerdata) );
1058 break;
1059
1060 case DEC_MASTERVARS:
1061 SCIP_CALL( readMastervars(scip, decinput, readerdata) );
1062 break;
1063
1064 case DEC_LINKINGVARS:
1065 SCIP_CALL( readLinkingvars(scip, decinput, readerdata) );
1066 break;
1067
1068 case DEC_END: /* this is already handled in the while() loop */
1069 default:
1070 SCIPerrorMessage("invalid DEC file section <%d>\n", decinput->section);
1071 return SCIP_INVALIDDATA;
1072 }
1073 }
1074
1075 if( decinput->haserror)
1076 {
1077 SCIPinfoMessage(scip, NULL, "error occurred while reading dec file");
1078 delete decinput->partialdec;
1079 }
1080 else
1081 {
1082 if( !decinput->incomplete )
1084 SCIPinfoMessage(scip, NULL, "just read dec file:\n");
1086 }
1087
1088 /* close file */
1089 SCIPfclose(decinput->file);
1090
1091 return SCIP_OKAY;
1092}
1093
1094
1095/**
1096 * @brief write partialdec to file in dec format
1097
1098 * @return scip return code
1099 */
1100static
1102 SCIP* scip, /**< SCIP data structure */
1103 FILE* file, /**< pointer to file to write to */
1104 gcg::PARTIALDECOMP* partialdec, /**< partialdec to write */
1105 SCIP_RESULT* result /**< will be set to SCIP_SUCCESS if writing was successful */
1106 )
1107{
1108 int nconss;
1109 int nvars;
1110 std::vector<int> consindex;
1111 std::vector<int> varindex;
1112
1113 assert(partialdec != NULL);
1114
1115 gcg::DETPROBDATA* detprobdata = partialdec->getDetprobdata();
1116
1117 nconss = detprobdata->getNConss();
1118 nvars = detprobdata->getNVars();
1119
1120 consindex = std::vector<int>(nconss);
1121 varindex = std::vector<int>(nvars);
1122
1123 for( int i = 0; i < nconss; ++i )
1124 consindex[i] = i;
1125 for( int i = 0; i < nvars; ++i )
1126 varindex[i] = i;
1127
1128 /* write meta data of decomposition as comment */
1129 if( partialdec->getUsergiven() == gcg::USERGIVEN::PARTIAL )
1130 SCIPinfoMessage(scip, file, "%s%s stems from a partial decomposition provided by the user\n", commentchars, commentchars);
1131 else if( partialdec->getUsergiven() != gcg::USERGIVEN::NOT )
1132 SCIPinfoMessage(scip, file, "%s%s provided by the user\n", commentchars, commentchars);
1133 auto& detectorchain = partialdec->getDetectorchain();
1134 auto& detectorchaininfo = partialdec->getDetectorchainInfo();
1135 SCIPinfoMessage(scip, file, "%s%s ndetectors \n", commentchars, commentchars);
1136 SCIPinfoMessage(scip, file, "%s%s %ld \n", commentchars, commentchars, detectorchain.size());
1137
1138 SCIPinfoMessage(scip, file,
1139 "%s%s name info time nnewblocks %%ofnewborderconss %%ofnewblockconss %%ofnewlinkingvars %%ofnewblockvars\n",
1141
1142 for( unsigned int i = 0; i < detectorchain.size(); ++i )
1143 {
1144 SCIPinfoMessage(scip, file, "%s%s %s %s %f %d %f %f %f %f \n", commentchars, commentchars,
1145 GCGdetectorGetName(detectorchain[i]), detectorchaininfo[i].c_str(), partialdec->getDetectorClockTimes().at(i),
1146 partialdec->getNNewBlocks(i), partialdec->getPctConssToBorder(i), partialdec->getPctConssToBlock(i),
1147 partialdec->getPctVarsToBorder(i), partialdec->getPctVarsToBlock(i)) ;
1148 }
1149
1150 if( !partialdec->isComplete() )
1151 SCIPinfoMessage(scip, file, "INCOMPLETE\n1\n");
1152
1153 if( partialdec->isAssignedToOrigProb() )
1154 SCIPinfoMessage(scip, file, "PRESOLVED\n0\n");
1155 else
1156 SCIPinfoMessage(scip, file, "PRESOLVED\n1\n");
1157
1158 SCIPinfoMessage(scip, file, "NBLOCKS\n%d\n", partialdec->getNBlocks());
1159
1160 for( int b = 0; b < partialdec->getNBlocks(); ++b )
1161 {
1162 SCIPinfoMessage(scip, file, "BLOCK %d\n", b+1 );
1163 for( int c = 0; c < partialdec->getNConssForBlock(b); ++c )
1164 {
1165 SCIPinfoMessage(scip, file, "%s\n", SCIPconsGetName(detprobdata->getCons(partialdec->getConssForBlock(b)[c])));
1166 }
1167 }
1168
1169 SCIPinfoMessage(scip, file, "MASTERCONSS\n" );
1170 for( int mc = 0; mc < partialdec->getNMasterconss(); ++mc )
1171 {
1172 SCIPinfoMessage(scip, file, "%s\n", SCIPconsGetName(detprobdata->getCons(partialdec->getMasterconss()[mc])));
1173 }
1174
1175 if( partialdec->isComplete() )
1176 {
1177 *result = SCIP_SUCCESS;
1178 return SCIP_OKAY;
1179 }
1180
1181 SCIPinfoMessage(scip, file, "LINKINGVARS\n" );
1182 for( int lv = 0; lv < partialdec->getNLinkingvars(); ++lv )
1183 {
1184 SCIPinfoMessage(scip, file, "%s\n", SCIPvarGetName(detprobdata->getVar(partialdec->getLinkingvars()[lv])));
1185 }
1186
1187 SCIPinfoMessage(scip, file, "MASTERVARS\n%s%s aka STATICVARS\n", commentchars, commentchars );
1188 for( int mv = 0; mv < partialdec->getNMastervars(); ++mv )
1189 {
1190 SCIPinfoMessage(scip, file, "%s\n", SCIPvarGetName(detprobdata->getVar(partialdec->getMastervars()[mv])));
1191 }
1192
1193 for( int b = 0; b < partialdec->getNBlocks(); ++b )
1194 {
1195 SCIPinfoMessage(scip, file, "BLOCKVARS %d\n", b+1 );
1196 for( int v = 0; v < partialdec->getNVarsForBlock(b); ++v )
1197 {
1198 SCIPinfoMessage(scip, file, "%s\n", SCIPvarGetName(detprobdata->getVar(partialdec->getVarsForBlock(b)[v])));
1199 }
1200 }
1201
1202 *result = SCIP_SUCCESS;
1203
1204 return SCIP_OKAY;
1205}
1206
1207
1208/* reads problem from file */
1210 SCIP* scip, /**< SCIP data structure */
1211 const char* filename, /**< full path and name of file to read, or NULL if stdin should be used */
1212 SCIP_RESULT* result /**< pointer to store the result of the file reading call */
1213)
1214{
1215 SCIP_RETCODE retcode;
1216 SCIP_READER* reader;
1217 DECINPUT decinput;
1218 int i;
1219
1220 reader = SCIPfindReader(scip, READER_NAME);
1221 assert(reader != NULL);
1222
1223 /* initialize DEC input data */
1224 decinput.file = NULL;
1225 decinput.linebuf[0] = '\0';
1226 SCIP_CALL( SCIPallocMemoryArray(scip, &decinput.token, DEC_MAX_LINELEN) ); /*lint !e506*/
1227 decinput.token[0] = '\0';
1228 SCIP_CALL( SCIPallocMemoryArray(scip, &decinput.tokenbuf, DEC_MAX_LINELEN) ); /*lint !e506*/
1229 decinput.tokenbuf[0] = '\0';
1230 for( i = 0; i < DEC_MAX_PUSHEDTOKENS; ++ i )
1231 {
1232 SCIP_CALL( SCIPallocMemoryArray(scip, &decinput.pushedtokens[i], DEC_MAX_LINELEN) ); /*lint !e506 !e866*/
1233 }
1234
1235 decinput.npushedtokens = 0;
1236 decinput.linenumber = 0;
1237 decinput.linepos = 0;
1238 decinput.section = DEC_START;
1239 decinput.presolved = FALSE;
1240 decinput.haspresolvesection = FALSE;
1241 decinput.nblocks = NOVALUE;
1242 decinput.blocknr = - 2;
1243 decinput.haserror = FALSE;
1244 decinput.incomplete = FALSE;
1245
1246 /* read the file */
1247 retcode = readDECFile(scip, reader, &decinput, filename);
1248
1249 /* free dynamically allocated memory */
1250 SCIPfreeMemoryArray(scip, &decinput.token);
1251 SCIPfreeMemoryArray(scip, &decinput.tokenbuf);
1252 for( i = 0; i < DEC_MAX_PUSHEDTOKENS; ++ i )
1253 {
1254 SCIPfreeMemoryArray(scip, &decinput.pushedtokens[i]);
1255 }
1256
1257 /* evaluate the result */
1258 if( decinput.haserror )
1259 return SCIP_READERROR;
1260 else if( retcode == SCIP_OKAY )
1261 {
1262 *result = SCIP_SUCCESS;
1263 }
1264
1265 return retcode;
1266}
1267
1268
1269/*
1270 * Callback methods of reader
1271 */
1272
1273/** destructor of reader to free user data (called when SCIP is exiting) */
1274static
1276{
1277 SCIP_READERDATA* readerdata;
1278
1279 readerdata = SCIPreaderGetData(reader);
1280 assert(readerdata != NULL);
1281
1282 SCIPfreeMemory(scip, &readerdata);
1283
1284 return SCIP_OKAY;
1285}
1286
1287/** problem reading method of reader */
1288static
1290{ /*lint --e{715}*/
1291
1293 {
1294 SCIPverbMessage(scip, SCIP_VERBLEVEL_DIALOG, NULL, "Please read in a problem before reading in the corresponding structure file!\n");
1295 return SCIP_OKAY;
1296 }
1297
1298 SCIP_CALL( readDec(scip, filename, result) );
1299
1300 return SCIP_OKAY;
1301}
1302
1303/** problem writing method of reader */
1304static
1306{ /*lint --e{715}*/
1307 SCIP_READERDATA* readerdata;
1308 assert(scip != NULL);
1309 assert(reader != NULL);
1310
1311 readerdata = SCIPreaderGetData(reader);
1312
1313 gcg::PARTIALDECOMP* partialdec = GCGgetPartialdecToWrite(readerdata->gcg, transformed);
1314
1315 if(partialdec == NULL) {
1316 SCIPwarningMessage(scip, "There is no writable partialdec!\n");
1317 return SCIP_OKAY;
1318 }
1319
1320 writePartialdec(scip, file, partialdec, result);
1321
1322 return SCIP_OKAY;
1323}
1324
1325/*
1326 * reader specific interface methods
1327 */
1328
1329/** includes the dec file reader in SCIP */
1331 GCG* gcg /**< GCG data structure */
1332 )
1333{
1334 SCIP_READERDATA* readerdata = NULL;
1335 SCIP* origprob = GCGgetOrigprob(gcg);
1336 assert(origprob != NULL);
1337
1338 /* create dec reader data */
1339 SCIP_CALL( SCIPallocMemory(origprob, &readerdata) );
1340 readerdata->gcg = gcg;
1341
1342 /* include dec reader */
1344 readerFreeDec, readerReadDec, readerWriteDec, readerdata));
1345
1346 return SCIP_OKAY;
1347}
SCIP_VAR ** b
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 getNConss()
returns the number of variables considered in the detprobdata
GCG_EXPORT int getNVars()
return the number of variables considered in the detprobdata
GCG_EXPORT SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
GCG_EXPORT SCIP_CONS * getCons(int consIndex)
returns the SCIP constraint related to a constraint index
class to manage partial decompositions
GCG_EXPORT int getNMasterconss()
Gets size of the vector containing master conss.
GCG_EXPORT bool fixVarToMasterByName(const char *varname)
assigns a variable with given name as master
GCG_EXPORT std::vector< GCG_DETECTOR * > & getDetectorchain()
returns detector chain as vector of detector pointers
GCG_EXPORT SCIP_Real getPctConssToBorder(int detectorchainindex)
Gets fraction of constraints assigned to the border for a detector.
GCG_EXPORT SCIP_Real getPctVarsToBorder(int detectorchainindex)
Gets fraction of variables assigned to the border for a detector.
GCG_EXPORT bool fixConsToBlockByName(const char *consname, int blockid)
assigns a constraint by name to a block
GCG_EXPORT USERGIVEN getUsergiven()
Gets the USERGIVEN status of this partialdecs.
GCG_EXPORT void setNBlocks(int nblocks)
sets number of blocks, only increasing number allowed
GCG_EXPORT std::vector< SCIP_Real > & getDetectorClockTimes()
returns a vector of the clock times that each detector needed that was involved in this partialdec
GCG_EXPORT bool fixVarToLinkingByName(const char *varname)
assigns a variable by name to the linking variables
GCG_EXPORT bool fixVarToBlockByName(const char *varname, int blockid)
assigns a variable by name to a block
GCG_EXPORT std::vector< int > & getMasterconss()
Gets array containing all master conss indices.
GCG_EXPORT std::vector< int > & getConssForBlock(int block)
returns array containing constraints assigned to a block
GCG_EXPORT DETPROBDATA * getDetprobdata()
Gets the corresponding detprobdata.
GCG_EXPORT bool isComplete()
Gets whether this partialdec is complete, i.e. it has no more open constraints and variables.
GCG_EXPORT SCIP_Real getPctVarsToBlock(int detectorchainindex)
Gets fraction of variables assigned to a block for a detector.
GCG_EXPORT int getNVarsForBlock(int block)
Gets size of the vector containing vars assigned to a block.
GCG_EXPORT std::vector< int > & getLinkingvars()
returns array containing all linking vars indices
GCG_EXPORT bool isAssignedToOrigProb()
Gets whether the partialdec is from the original problem.
GCG_EXPORT std::vector< int > & getMastervars()
Gets array containing all master vars indices.
GCG_EXPORT void setUsergiven(USERGIVEN usergiven)
sets whether this partialdec is user given
GCG_EXPORT SCIP_Real getPctConssToBlock(int detectorchainindex)
Gets fraction of constraints assigned to a block for a detector.
GCG_EXPORT int getNLinkingvars()
Gets size of the vector containing linking vars.
GCG_EXPORT int getNNewBlocks(int detectorchainindex)
Gets number of blocks a detector added.
GCG_EXPORT int getNMastervars()
Gets size of the vector containing master vars.
GCG_EXPORT int getNConssForBlock(int block)
Gets size of the vector containing conss assigned to a block.
GCG_EXPORT std::vector< std::string > & getDetectorchainInfo()
Gets the detectorchain info vector.
GCG_EXPORT bool isConsOpencons(int cons)
Gets whether the cons is an open cons.
GCG_EXPORT std::vector< int >::const_iterator fixConsToMaster(std::vector< int >::const_iterator itr)
fixes a constraint to the master constraints
GCG_EXPORT std::vector< int > & getVarsForBlock(int block)
Gets array containing vars of a block.
GCG_EXPORT int getNBlocks()
Gets the number of blocks.
const char * GCGdetectorGetName(GCG_DETECTOR *detector)
returns the name of the provided detector
PARTIALDECOMP * GCGgetPartialdecToWrite(GCG *gcg, SCIP_Bool transformed)
SCIP_RETCODE GCGconshdlrDecompAddPreexisitingPartialDec(GCG *gcg, PARTIALDECOMP *partialdec)
adds a preexisting partial dec to be considered at the beginning of the detection
constraint handler for structure detection
C++ interface of cons_decomp.
#define SCIP_Bool
#define SCIP_CALL(x)
#define TRUE
#define FALSE
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
void SCIPrewind(SCIP_FILE *stream)
int SCIPfclose(SCIP_FILE *fp)
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
SCIP_STAGE SCIPgetStage(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
SCIP_CONS * SCIPfindOrigCons(SCIP *scip, const char *name)
int SCIPgetNConss(SCIP *scip)
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
SCIP_CONS * SCIPfindCons(SCIP *scip, const char *name)
SCIP_Bool GCGisVarRelevant(SCIP_VAR *var)
Definition: scip_misc.c:42
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
void SCIPwarningMessage(SCIP *scip, 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)
SCIP_Bool SCIPconsIsActive(SCIP_CONS *cons)
const char * SCIPconsGetName(SCIP_CONS *cons)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeMemoryArray(scip, ptr)
#define SCIPfreeMemory(scip, ptr)
#define SCIPfreeBufferArrayNull(scip, ptr)
SCIP_RETCODE SCIPincludeReader(SCIP *scip, const char *name, const char *desc, const char *extension, SCIP_DECL_READERCOPY((*readercopy)), SCIP_DECL_READERFREE((*readerfree)), SCIP_DECL_READERREAD((*readerread)), SCIP_DECL_READERWRITE((*readerwrite)), SCIP_READERDATA *readerdata)
SCIP_READERDATA * SCIPreaderGetData(SCIP_READER *reader)
SCIP_READER * SCIPfindReader(SCIP *scip, const char *name)
SCIP_RETCODE SCIPpresolve(SCIP *scip)
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
SCIP_VAR * SCIPvarGetProbvar(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
int SCIPstrcasecmp(const char *s1, const char *s2)
int SCIPsnprintf(char *t, int len, const char *s,...)
void SCIPprintSysError(const char *message)
#define NULL
#define BMSclearMemoryArray(ptr, num)
@ COMPLETED_CONSTOMASTER
public methods for working with decomposition structures
struct SCIP_File SCIP_FILE
public methods for GCG variables
#define SCIPerrorMessage
#define SCIPdebugMessage
static void swapTokenBuffer(DECINPUT *decinput)
Definition: reader_dec.cpp:369
static SCIP_RETCODE readBlockvars(SCIP *scip, DECINPUT *decinput, SCIP_READERDATA *readerdata)
Definition: reader_dec.cpp:779
static const int NOVALUE
Definition: reader_dec.cpp:110
static SCIP_DECL_READERREAD(readerReadDec)
static const char tokenchars[]
Definition: reader_dec.cpp:113
static SCIP_DECL_READERFREE(readerFreeDec)
#define DEC_MAX_LINELEN
Definition: reader_dec.cpp:65
#define DEC_MAX_PUSHEDTOKENS
Definition: reader_dec.cpp:66
static SCIP_RETCODE readLinkingvars(SCIP *scip, DECINPUT *decinput, SCIP_READERDATA *readerdata)
Definition: reader_dec.cpp:906
static const char commentchars[]
Definition: reader_dec.cpp:114
static const int LINKINGVALUE
Definition: reader_dec.cpp:111
static SCIP_RETCODE writePartialdec(SCIP *scip, FILE *file, gcg::PARTIALDECOMP *partialdec, SCIP_RESULT *result)
write partialdec to file in dec format
static SCIP_RETCODE readBlockconss(SCIP *scip, DECINPUT *decinput, SCIP_READERDATA *readerdata)
Definition: reader_dec.cpp:677
static SCIP_Bool getNextToken(DECINPUT *decinput)
Definition: reader_dec.cpp:257
static SCIP_RETCODE readIncomplete(SCIP *scip, DECINPUT *decinput)
Definition: reader_dec.cpp:559
#define READER_DESC
Definition: reader_dec.cpp:58
SCIP_RETCODE GCGincludeReaderDec(GCG *gcg)
DecExpType
Definition: reader_dec.cpp:77
@ DEC_EXP_NONE
Definition: reader_dec.cpp:78
static SCIP_RETCODE setPresolved(SCIP *scip, DECINPUT *decinput)
Definition: reader_dec.cpp:951
static SCIP_Bool isNewSection(SCIP *scip, DECINPUT *decinput)
Definition: reader_dec.cpp:408
#define READER_EXTENSION
Definition: reader_dec.cpp:59
static SCIP_RETCODE readDECFile(SCIP *scip, SCIP_READER *reader, DECINPUT *decinput, const char *filename)
Definition: reader_dec.cpp:971
static SCIP_Bool isValueChar(char c, char nextc, SCIP_Bool firstchar, SCIP_Bool *hasdot, DECEXPTYPE *exptype)
Definition: reader_dec.cpp:178
static SCIP_RETCODE readMastervars(SCIP *scip, DECINPUT *decinput, SCIP_READERDATA *readerdata)
Definition: reader_dec.cpp:861
#define READER_NAME
Definition: reader_dec.cpp:57
static void pushToken(DECINPUT *decinput)
Definition: reader_dec.cpp:356
static SCIP_RETCODE readStart(SCIP *scip, DECINPUT *decinput)
Definition: reader_dec.cpp:538
static SCIP_RETCODE readPresolved(SCIP *scip, DECINPUT *decinput)
Definition: reader_dec.cpp:596
static SCIP_Bool isDelimChar(char c)
Definition: reader_dec.cpp:160
enum DecExpType DECEXPTYPE
Definition: reader_dec.cpp:80
static SCIP_DECL_READERWRITE(readerWriteDec)
static void swapPointers(char **pointer1, char **pointer2)
Definition: reader_dec.cpp:243
SCIP_RETCODE readDec(SCIP *scip, const char *filename, SCIP_RESULT *result)
static SCIP_RETCODE readMasterconss(SCIP *scip, DECINPUT *decinput, SCIP_READERDATA *readerdata)
Definition: reader_dec.cpp:822
static void syntaxError(SCIP *scip, DECINPUT *decinput, const char *msg)
Definition: reader_dec.cpp:122
static const char delimchars[]
Definition: reader_dec.cpp:112
static SCIP_Bool hasError(DECINPUT *decinput)
Definition: reader_dec.cpp:150
static SCIP_Bool getNextLine(DECINPUT *decinput)
Definition: reader_dec.cpp:199
static SCIP_Bool isInt(SCIP *scip, DECINPUT *decinput, int *value)
Definition: reader_dec.cpp:380
static SCIP_RETCODE readNBlocks(SCIP *scip, DECINPUT *decinput)
Definition: reader_dec.cpp:636
DecSection
Definition: reader_dec.cpp:70
@ DEC_LINKINGVARS
Definition: reader_dec.cpp:71
@ DEC_END
Definition: reader_dec.cpp:71
@ DEC_BLOCKCONSS
Definition: reader_dec.cpp:71
@ DEC_INCOMPLETE
Definition: reader_dec.cpp:71
@ DEC_MASTERCONSS
Definition: reader_dec.cpp:71
@ DEC_NBLOCKS
Definition: reader_dec.cpp:71
@ DEC_MASTERVARS
Definition: reader_dec.cpp:71
@ DEC_START
Definition: reader_dec.cpp:71
@ DEC_BLOCKVARS
Definition: reader_dec.cpp:71
@ DEC_PRESOLVED
Definition: reader_dec.cpp:71
static SCIP_Bool isTokenChar(char c)
Definition: reader_dec.cpp:169
enum DecSection DECSECTION
Definition: reader_dec.cpp:73
DEC file reader for structure information.
various SCIP helper methods
char linebuf[DEC_MAX_LINELEN]
Definition: reader_dec.cpp:86
char * pushedtokens[DEC_MAX_PUSHEDTOKENS]
Definition: reader_dec.cpp:89
SCIP_FILE * file
Definition: reader_dec.cpp:85
DECSECTION section
Definition: reader_dec.cpp:98
int nblocks
Definition: reader_dec.cpp:96
char * token
Definition: reader_dec.cpp:87
SCIP_Bool incomplete
Definition: reader_dec.cpp:95
gcg::PARTIALDECOMP * partialdec
Definition: reader_dec.cpp:100
int linenumber
Definition: reader_dec.cpp:91
SCIP_Bool haserror
Definition: reader_dec.cpp:99
int npushedtokens
Definition: reader_dec.cpp:90
SCIP_Bool presolved
Definition: reader_dec.cpp:93
int linepos
Definition: reader_dec.cpp:92
char * tokenbuf
Definition: reader_dec.cpp:88
int blocknr
Definition: reader_dec.cpp:97
SCIP_Bool haspresolvesection
Definition: reader_dec.cpp:94
Definition: struct_gcg.h:55
SCIP_VERBLEVEL_DIALOG
SCIP_VERBLEVEL_MINIMAL
SCIP_SUCCESS
enum SCIP_Result SCIP_RESULT
SCIP_NOFILE
SCIP_READERROR
SCIP_INVALIDDATA
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
SCIP_STAGE_INIT
SCIP_STAGE_PRESOLVED