GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
reader_ref.c
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_ref.c
30 * @brief REF file reader for structure information
31 * @author Gerald Gamrath
32 * @author Christian Puchert
33 * @author Martin Bergner
34 */
35
36/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
37
38#include <stdlib.h>
39#include <assert.h>
40#include <string.h>
41#include <ctype.h>
42
43#include "gcg/reader_ref.h"
44#include "gcg/gcg.h"
45#include "scip/cons_linear.h"
46#include "gcg/cons_decomp.h"
47#include "gcg/relax_gcg.h"
48
49#define READER_NAME "refreader"
50#define READER_DESC "file reader for blocks corresponding to a mip in lpb format"
51#define READER_EXTENSION "ref"
52
53/*
54 * Data structures
55 */
56#define REF_MAX_LINELEN 65536
57#define REF_MAX_PUSHEDTOKENS 2
58
59/** section in REF File */
65
71
72
73/** REF reading data */
75{
76 SCIP_FILE* file; /**< file to read */
77 char linebuf[REF_MAX_LINELEN]; /**< line buffer */
78 char* token; /**< current token */
79 char* tokenbuf; /**< token buffer */
80 char* pushedtokens[REF_MAX_PUSHEDTOKENS]; /**< token stack */
81 int npushedtokens; /**< size of token stack */
82 int linenumber; /**< current line number */
83 int linepos; /**< current line position (column) */
84 int nblocks; /**< number of blocks */
85 int blocknr; /**< current block number */
86 int nassignedvars; /**< number of assigned variables */
87 int* blocksizes; /**< array of block sizes */
88 int totalconss; /**< total number of constraints */
89 int totalreadconss; /**< total number of read constraints */
90 SCIP_CONS** masterconss; /**< array of constraints to be in the master */
91 int nmasterconss; /**< number of constraints to be in the master */
92 REFSECTION section; /**< current section */
93 SCIP_Bool haserror; /**< flag to indicate an error occurence */
94 SCIP_HASHMAP* vartoblock; /**< hashmap mapping variables to blocks (1..nblocks) */
95 SCIP_HASHMAP* constoblock; /**< hashmap mapping constraints to blocks (1..nblocks) */
96};
97typedef struct RefInput REFINPUT;
98
99struct SCIP_ReaderData
100{
101 GCG* gcg; /**< GCG data structure */
102};
103
104static const char delimchars[] = " \f\n\r\t\v";
105static const char tokenchars[] = "-+:<>=";
106static const char commentchars[] = "\\";
107
108
109/*
110 * Local methods (for reading)
111 */
112
113/** issues an error message and marks the REF data to have errors */
114static
116 SCIP* scip, /**< SCIP data structure */
117 REFINPUT* refinput, /**< REF reading data */
118 const char* msg /**< error message */
119 )
120{
121 char formatstr[256];
122
123 assert(refinput != NULL);
124
125 SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "Syntax error in line %d: %s ('%s')\n",
126 refinput->linenumber, msg, refinput->token);
127 if( refinput->linebuf[strlen(refinput->linebuf)-1] == '\n' )
128 {
129 SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, " input: %s", refinput->linebuf);
130 }
131 else
132 {
133 SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, " input: %s\n", refinput->linebuf);
134 }
135 (void) SCIPsnprintf(formatstr, 256, " %%%ds\n", refinput->linepos);
137 refinput->section = REF_END;
138 refinput->haserror = TRUE;
139}
140
141/** returns whether a syntax error was detected */
142static
144 REFINPUT* refinput /**< REF reading data */
145 )
146{
147 assert(refinput != NULL);
148
149 return refinput->haserror;
150}
151
152/** returns whether the given character is a token delimiter */
153static
155 char c /**< input character */
156 )
157{
158 return (c == '\0') || (strchr(delimchars, c) != NULL);
159}
160
161/** returns whether the given character is a single token */
162static
164 char c /**< input character */
165 )
166{
167 return (strchr(tokenchars, c) != NULL);
168}
169
170/** returns whether the current character is member of a value string */
171static
173 char c, /**< input character */
174 char nextc, /**< next input character */
175 SCIP_Bool firstchar, /**< is the given character the first char of the token? */
176 SCIP_Bool* hasdot, /**< pointer to update the dot flag */
177 REFEXPTYPE* exptype /**< pointer to update the exponent type */
178 )
179{
180 assert(hasdot != NULL);
181 assert(exptype != NULL);
182
183 if( isdigit(c) )
184 return TRUE;
185 else if( (*exptype == REF_EXP_NONE) && !(*hasdot) && (c == '.') )
186 {
187 *hasdot = TRUE;
188 return TRUE;
189 }
190 else if( !firstchar && (*exptype == REF_EXP_NONE) && (c == 'e' || c == 'E') )
191 {
192 if( nextc == '+' || nextc == '-' )
193 {
194 *exptype = REF_EXP_SIGNED;
195 return TRUE;
196 }
197 else if( isdigit(nextc) )
198 {
199 *exptype = REF_EXP_UNSIGNED;
200 return TRUE;
201 }
202 }
203 else if( (*exptype == REF_EXP_SIGNED) && (c == '+' || c == '-') )
204 {
205 *exptype = REF_EXP_UNSIGNED;
206 return TRUE;
207 }
208
209 return FALSE;
210}
211
212/** reads the next line from the input file into the line buffer; skips comments;
213 * returns whether a line could be read
214 */
215static
217 REFINPUT* refinput /**< REF reading data */
218 )
219{
220 int i;
221
222 assert(refinput != NULL);
223
224 /* clear the line */
226
227 /* read next line */
228 refinput->linepos = 0;
229 refinput->linebuf[REF_MAX_LINELEN-2] = '\0';
230 if( SCIPfgets(refinput->linebuf, REF_MAX_LINELEN, refinput->file) == NULL )
231 return FALSE;
232 refinput->linenumber++;
233 if( refinput->linebuf[REF_MAX_LINELEN-2] != '\0' )
234 {
235 SCIPerrorMessage("Error: line %d exceeds %d characters\n", refinput->linenumber, REF_MAX_LINELEN-2);
236 refinput->haserror = TRUE;
237 return FALSE;
238 }
239 refinput->linebuf[REF_MAX_LINELEN-1] = '\0';
240 refinput->linebuf[REF_MAX_LINELEN-2] = '\0'; /* we want to use lookahead of one char -> we need two \0 at the end */
241
242 /* skip characters after comment symbol */
243 for( i = 0; commentchars[i] != '\0'; ++i )
244 {
245 char* commentstart;
246
247 commentstart = strchr(refinput->linebuf, commentchars[i]);
248 if( commentstart != NULL )
249 {
250 *commentstart = '\0';
251 *(commentstart+1) = '\0'; /* we want to use lookahead of one char -> we need two \0 at the end */
252 }
253 }
254
255 return TRUE;
256}
257
258/** reads the next token from the input file into the token buffer; returns whether a token was read */
259static
261 REFINPUT* refinput /**< REF reading data */
262 )
263{
264 SCIP_Bool hasdot;
265 REFEXPTYPE exptype;
266 char* buf;
267 int tokenlen;
268
269 assert(refinput != NULL);
270 assert(refinput->linepos < REF_MAX_LINELEN);
271
272 /* check the token stack */
273 if( refinput->npushedtokens > 0 )
274 {
275 SCIPswapPointers((void**)&refinput->token, (void**)&refinput->pushedtokens[refinput->npushedtokens-1]);
276 refinput->npushedtokens--;
277 SCIPdebugMessage("(line %d) read token again: '%s'\n", refinput->linenumber, refinput->token);
278 return TRUE;
279 }
280
281 /* skip delimiters */
282 buf = refinput->linebuf;
283 while( isDelimChar(buf[refinput->linepos]) )
284 {
285 if( buf[refinput->linepos] == '\0' )
286 {
287 if( !getNextLine(refinput) )
288 {
289 refinput->section = REF_END;
290 refinput->blocknr++;
291 SCIPdebugMessage("(line %d) end of file\n", refinput->linenumber);
292 return FALSE;
293 }
294 else
295 {
296 if( refinput->section == REF_START )
297 refinput->section = REF_NBLOCKS;
298 else if( refinput->section == REF_BLOCKSIZES )
299 {
300 refinput->section = REF_BLOCKS;
301 refinput->blocknr = 0;
302 }
303 return FALSE;
304 }
305 }
306 else
307 refinput->linepos++;
308 }
309 assert(refinput->linepos < REF_MAX_LINELEN);
310 assert(!isDelimChar(buf[refinput->linepos]));
311
312 /* check if the token is a value */
313 hasdot = FALSE;
314 exptype = REF_EXP_NONE;
315 if( isValueChar(buf[refinput->linepos], buf[refinput->linepos+1], TRUE, &hasdot, &exptype) ) /*lint !e679*/
316 {
317 /* read value token */
318 tokenlen = 0;
319 do
320 {
321 assert(tokenlen < REF_MAX_LINELEN);
322 assert(!isDelimChar(buf[refinput->linepos]));
323 refinput->token[tokenlen] = buf[refinput->linepos];
324 ++tokenlen;
325 ++(refinput->linepos);
326 assert(refinput->linepos < REF_MAX_LINELEN);
327 }
328 while( isValueChar(buf[refinput->linepos], buf[refinput->linepos+1], FALSE, &hasdot, &exptype) ); /*lint !e679*/
329 }
330 else
331 {
332 /* read non-value token */
333 tokenlen = 0;
334 do
335 {
336 assert(tokenlen < REF_MAX_LINELEN);
337 refinput->token[tokenlen] = buf[refinput->linepos];
338 tokenlen++;
339 refinput->linepos++;
340 if( tokenlen == 1 && isTokenChar(refinput->token[0]) )
341 break;
342 }
343 while( !isDelimChar(buf[refinput->linepos]) && !isTokenChar(buf[refinput->linepos]) );
344
345 /* if the token is an equation sense '<', '>', or '=', skip a following '='
346 * if the token is an equality token '=' and the next character is a '<' or '>', replace the token by the inequality sense
347 */
348 if( tokenlen >= 1
349 && (refinput->token[tokenlen-1] == '<' || refinput->token[tokenlen-1] == '>' || refinput->token[tokenlen-1] == '=')
350 && buf[refinput->linepos] == '=' )
351 {
352 refinput->linepos++;
353 }
354 else if( refinput->token[tokenlen-1] == '=' && (buf[refinput->linepos] == '<' || buf[refinput->linepos] == '>') )
355 {
356 refinput->token[tokenlen-1] = buf[refinput->linepos];
357 refinput->linepos++;
358 }
359 }
360 assert(tokenlen < REF_MAX_LINELEN);
361 refinput->token[tokenlen] = '\0';
362
363 return TRUE;
364}
365
366/** returns whether the current token is a value */
367static
369 SCIP* scip, /**< SCIP data structure */
370 REFINPUT* refinput, /**< REF reading data */
371 int* value /**< pointer to store the value (unchanged, if token is no value) */
372 )
373{
374 long val;
375 char* endptr;
376
377 assert(refinput != NULL);
378 assert(value != NULL);
379 assert(!(SCIPstrcasecmp(refinput->token, "INFINITY") == 0) && !(SCIPstrcasecmp(refinput->token, "INF") == 0));
380
381 val = strtol(refinput->token, &endptr, 0);
382 if( endptr != refinput->token && *endptr == '\0' )
383 {
384 if( val < INT_MIN || val > INT_MAX ) /*lint !e685*/
385 return FALSE;
386
387 *value = (int) val;
388 return TRUE;
389 }
390
391
392 return FALSE;
393}
394
395/** reads the header of the file */
396static
398 SCIP* scip, /**< SCIP data structure */
399 REFINPUT* refinput /**< REF reading data */
400 )
401{
402 assert(refinput != NULL);
403
404 (void) getNextToken(refinput);
405
406 return SCIP_OKAY;
407}
408
409/** reads the nblocks section */
410static
412 SCIP* scip, /**< SCIP data structure */
413 REFINPUT* refinput /**< REF reading data */
414 )
415{
416 int nblocks;
417
418 assert(refinput != NULL);
419
420 if( getNextToken(refinput) )
421 {
422 /* read number of blocks */
423 if( isInt(scip, refinput, &nblocks) )
424 {
425 if( refinput->nblocks == -1 )
426 {
427 refinput->nblocks = nblocks;
428 SCIP_CALL( SCIPallocBufferArray(scip, &refinput->blocksizes, nblocks) );
429 }
430 SCIPdebugMessage("Number of blocks = %d\n", refinput->nblocks);
431 }
432 else
433 syntaxError(scip, refinput, "NBlocks: Value not an integer.\n");
434 }
435 else
436 syntaxError(scip, refinput, "Could not read number of blocks.\n");
437
438 refinput->section = REF_BLOCKSIZES;
439
440 return SCIP_OKAY;
441}
442
443/** reads the blocksizes section */
444static
446 SCIP* scip, /**< SCIP data structure */
447 REFINPUT* refinput /**< REF reading data */
448 )
449{
450 int blocknr;
451 int blocksize;
452
453 assert(refinput != NULL);
454
455 for( blocknr = 0; getNextToken(refinput) && blocknr < refinput->nblocks; blocknr++ )
456 {
457 if( isInt(scip, refinput, &blocksize) )
458 {
459 refinput->blocksizes[blocknr] = blocksize;
460 refinput->totalconss += blocksize;
461 }
462 else
463 syntaxError(scip, refinput, "Blocksize: Value not integer.\n");
464 }
465 if( blocknr != refinput->nblocks )
466 syntaxError(scip, refinput, "Could not get sizes for all blocks.\n");
467
468 return SCIP_OKAY;
469}
470
471/** reads the blocks section */
472static
474 SCIP* scip, /**< SCIP data structure */
475 REFINPUT* refinput /**< REF reading data */
476 )
477{
478 int consctr;
479
480 assert(refinput != NULL);
481
482 consctr = 0;
483
484 while( refinput->blocknr < refinput->nblocks )
485 {
486 SCIPdebugMessage("Reading constraints of block %d/%d\n", refinput->blocknr + 1, refinput->nblocks);
487 while( getNextToken(refinput) )
488 {
489 SCIP_VAR** vars;
490 int consnr;
491 SCIP_CONS** conss = SCIPgetConss(scip);
492
493 if( isInt(scip, refinput, &consnr) )
494 {
495 SCIP_CONSHDLR* conshdlr;
496 int nvars;
497 int v;
498 SCIP_CONS* cons;
499
500 SCIPdebugMessage(" -> constraint %d\n", consnr);
501
502 cons = conss[consnr];
503 conshdlr = SCIPconsGetHdlr(cons);
504
505 if( strcmp(SCIPconshdlrGetName(conshdlr), "linear") == 0 )
506 {
507 vars = SCIPgetVarsLinear(scip, cons);
509 }
510 else
511 {
512 SCIPdebugMessage(" constraint of unknown type.\n");
513 continue;
514 }
515
516 SCIP_CALL( SCIPhashmapSetImage(refinput->constoblock, cons, (void*) (size_t) (refinput->blocknr+1) ) );
517
518 for( v = 0; v < nvars; v++ )
519 {
520 SCIP_VAR* var = vars[v];
521
522 SCIPdebugMessage(" -> variable %s\n", SCIPvarGetName(var));
523
524 /* set the block number of the variable to the number of the current block */
525 if( SCIPhashmapExists(refinput->vartoblock, var) )
526 {
527 int block;
528 block = (int)(size_t) SCIPhashmapGetImage(refinput->vartoblock, var); /*lint !e507*/
529 if( block != refinput->blocknr+1 && block != refinput->nblocks+1 )
530 {
532 SCIP_CALL( SCIPhashmapSetImage(refinput->vartoblock, var, (void*) (size_t) (refinput->nblocks+1)) );
533 }
534 }
535 else
536 {
537 SCIP_CALL( SCIPhashmapSetImage(refinput->vartoblock, var, (void*) (size_t) (refinput->blocknr+1)) );
538 }
539 refinput->nassignedvars++;
540 }
541 consctr++;
542 refinput->totalreadconss++;
543 }
544 else
545 syntaxError(scip, refinput, "ConsNr: Value not an integer.\n");
546 }
547
548 if( consctr == refinput->blocksizes[refinput->blocknr] )
549 {
550 refinput->blocknr++;
551 consctr = 0;
552 }
553 }
554
555 return SCIP_OKAY;
556}
557
558
559/** reads an REF file */
560static
562 SCIP* scip, /**< SCIP data structure */
563 SCIP_READER* reader, /**< reader data structure */
564 REFINPUT* refinput, /**< REF reading data */
565 GCG_DECOMP* decomp, /**< decomposition structure */
566 const char* filename /**< name of the input file */
567 )
568{
569 SCIP_READERDATA* readerdata;
570 assert(scip != NULL);
571 assert(reader != NULL);
572 assert(refinput != NULL);
573 assert(filename != NULL);
574
575 readerdata = SCIPreaderGetData(reader);
578
579 /* open file */
580 refinput->file = SCIPfopen(filename, "r");
581 if( refinput->file == NULL )
582 {
583 SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
584 SCIPprintSysError(filename);
585 return SCIP_NOFILE;
586 }
587
589 {
590 SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "Reader 'ref' can only read in unpresolved structures.\n Please re-read the problem and read the decomposition again.\n");
591 return SCIP_OKAY;
592 }
593
594 /* parse the file */
595 refinput->section = REF_START;
596 while( refinput->section != REF_END && !hasError(refinput) )
597 {
598 switch( refinput->section )
599 {
600 case REF_START:
601 SCIP_CALL( readStart(scip, refinput) );
602 break;
603
604 case REF_NBLOCKS:
605 SCIP_CALL( readNBlocks(scip, refinput) );
606 GCGdecompSetNBlocks(decomp, refinput->nblocks);
607 break;
608
609 case REF_BLOCKSIZES:
610 SCIP_CALL( readBlockSizes(scip, refinput) );
611 break;
612
613 case REF_BLOCKS:
614 SCIP_CALL( readBlocks(scip, refinput) );
615 break;
616
617 case REF_END: /* this is already handled in the while() loop */
618 default:
619 SCIPerrorMessage("invalid REF file section <%d>\n", refinput->section);
620 return SCIP_INVALIDDATA;
621 }
622 }
623
624 /* close file */
625 SCIPfclose(refinput->file);
626
627 /* copy information to decomp */
628 SCIP_CALL_QUIET( GCGfilloutDecompFromHashmaps(readerdata->gcg, decomp, refinput->vartoblock, refinput->constoblock, refinput->nblocks, FALSE) );
629
631 GCGdecompSetDetector(decomp, NULL);
632
633 return SCIP_OKAY;
634}
635
636/** writes a Ref file */
637static
639 SCIP* scip, /**< SCIP data structure */
640 SCIP_READER* reader, /**< ref reader */
641 FILE* file /**< target file */
642
643 )
644{
645 SCIP_HASHMAP *cons2origindex;
646 GCG_DECOMP* decomp;
647 SCIP_READERDATA* readerdata;
648 SCIP_CONS** conss;
649 int nconss;
650 SCIP_CONS*** subscipconss;
651 int* nsubscipconss;
652 int i;
653 int j;
654 int nblocks;
655 assert(scip != NULL);
656 assert(reader != NULL);
657 assert(file != NULL);
658
659 readerdata = SCIPreaderGetData(reader);
660 assert(readerdata != NULL);
661 decomp = GCGgetBestDecomp(readerdata->gcg, TRUE);
662
663 if( decomp == NULL )
664 {
665 decomp = GCGgetStructDecomp(readerdata->gcg);
666 }
667
668 if( decomp == NULL )
669 {
670 SCIPwarningMessage(scip, "No reformulation exists, cannot write reformulation file!\n");
671 return SCIP_OKAY;
672 }
673 nblocks = GCGdecompGetNBlocks(decomp);
674 conss = SCIPgetOrigConss(scip);
675 nconss = SCIPgetNOrigConss(scip);
676
677 SCIP_CALL( SCIPhashmapCreate(&cons2origindex, SCIPblkmem(scip), 2*nconss) );
678 for( i = 0; i < nconss; ++i )
679 {
680 int ind;
681 SCIP_CONS* cons;
682
683 ind = i+1;
684
685 assert(ind > 0);
686 assert(ind <= nconss);
687 cons = SCIPfindCons(scip, SCIPconsGetName(conss[i]));
688
689 SCIPdebugMessage("cons added: %d\t%p\t%s\n", ind, (void*)cons, SCIPconsGetName(cons));
690 SCIP_CALL( SCIPhashmapInsert(cons2origindex, cons, (void*)(size_t)(ind)) ); /* shift by 1 to enable error checking */
691 }
692
693 subscipconss = GCGdecompGetSubscipconss(decomp);
694 nsubscipconss = GCGdecompGetNSubscipconss(decomp);
695 SCIPinfoMessage(scip, file, "%d ", nblocks);
696
697 assert(nsubscipconss != NULL);
698 assert(subscipconss != NULL);
699
700 for( i = 0; i < nblocks; ++i )
701 {
702 SCIPinfoMessage(scip, file, "%d ", nsubscipconss[i]);
703 }
704 SCIPinfoMessage(scip, file, "\n");
705
706 for( i = 0; i < nblocks; ++i )
707 {
708 for( j = 0; j < nsubscipconss[i]; ++j )
709 {
710 int ind;
711 SCIP_CONS* cons;
712
713 cons = SCIPfindCons(scip, SCIPconsGetName(subscipconss[i][j]));
714 ind = (int)(size_t) SCIPhashmapGetImage(cons2origindex, cons); /*lint !e507*/
715 SCIPdebugMessage("cons retrieve (o): %d\t%p\t%s\n", ind, (void*)cons, SCIPconsGetName(cons));
716
717 assert(ind > 0); /* shift by 1 */
718 assert(ind <= nconss); /* shift by 1 */
719 SCIPinfoMessage(scip, file, "%d ", ind-1);
720 }
721 SCIPinfoMessage(scip, file, "\n");
722 }
723 SCIPhashmapFree(&cons2origindex);
724
725 GCGdecompFree(readerdata->gcg, &decomp);
726
727 return SCIP_OKAY;
728}
729
730/** reads problem from file */
731static
733 SCIP* scip, /**< SCIP data structure */
734 SCIP_READER* reader, /**< the file reader itself */
735 const char* filename, /**< full path and name of file to read, or NULL if stdin should be used */
736 SCIP_RESULT* result /**< pointer to store the result of the file reading call */
737 )
738{
740 REFINPUT refinput;
741 GCG_DECOMP* decomp;
742 int i;
743 SCIP_READERDATA* readerdata;
744#ifdef SCIP_DEBUG
745 SCIP_VAR** vars;
746 int nvars;
747#endif
748
749 readerdata = SCIPreaderGetData(reader);
750 assert(readerdata != NULL);
751
752 /* initialize REF input data */
753 refinput.file = NULL;
754 refinput.linebuf[0] = '\0';
755 SCIP_CALL( SCIPallocMemoryArray(scip, &refinput.token, REF_MAX_LINELEN) ); /*lint !e506*/
756 refinput.token[0] = '\0';
757 SCIP_CALL( SCIPallocMemoryArray(scip, &refinput.tokenbuf, REF_MAX_LINELEN) ); /*lint !e506*/
758 refinput.tokenbuf[0] = '\0';
759 for( i = 0; i < REF_MAX_PUSHEDTOKENS; ++i )
760 {
761 SCIP_CALL( SCIPallocMemoryArray(scip, &refinput.pushedtokens[i], REF_MAX_LINELEN) ); /*lint !e506 !e866*/
762 }
764
765 refinput.npushedtokens = 0;
766 refinput.linenumber = 0;
767 refinput.linepos = 0;
768 refinput.nblocks = -1;
769 refinput.blocknr = -2;
770 refinput.totalconss = 0;
771 refinput.totalreadconss = 0;
772 refinput.nassignedvars = 0;
773 refinput.nmasterconss = 0;
774 refinput.haserror = FALSE;
775
778
779 /* read the file */
780 SCIP_CALL( GCGdecompCreate(readerdata->gcg, &decomp) );
781
782 retcode = readREFFile(scip, reader, &refinput, decomp, filename);
783
784 if( retcode == SCIP_OKAY )
785 {
787 SCIPdebugMessage("Read %d/%d conss in ref-file\n", refinput.totalreadconss, refinput.totalconss);
788 SCIPdebugMessage("Assigned %d variables to %d blocks.\n", refinput.nassignedvars, refinput.nblocks);
789#ifdef SCIP_DEBUG
791
792 for( i = 0; i < nvars; i++ )
793 {
794 if( GCGvarGetBlock(vars[i]) == -1 )
795 {
796 SCIPdebugMessage(" -> not assigned: variable %s\n", SCIPvarGetName(vars[i]));
797 }
798 }
799#endif
800 }
801
802 SCIP_CALL( GCGdecompFree(readerdata->gcg, &decomp) );
803
804 /* free dynamically allocated memory */
805 SCIPfreeMemoryArray(scip, &refinput.token);
807 for( i = 0; i < REF_MAX_PUSHEDTOKENS; ++i )
808 {
810 }
813
814 /* evaluate the result */
815 if( refinput.haserror )
816 return SCIP_READERROR;
817 else if( retcode == SCIP_OKAY )
818 {
820 }
821
822 return retcode;
823}
824
825
826/*
827 * Callback methods of reader
828 */
829
830/** destructor of reader to free user data (called when SCIP is exiting) */
831static
833{
834 SCIP_READERDATA* readerdata;
835
836 assert(scip != NULL);
837 assert(reader != NULL);
838 readerdata = SCIPreaderGetData(reader);
839 SCIPfreeMemory(scip, &readerdata);
840 return SCIP_OKAY;
841}
842
843/** problem reading method of reader */
844static
846{
848 {
849 SCIPverbMessage(scip, SCIP_VERBLEVEL_DIALOG, NULL, "No problem exists, will not detect structure!\n");
850 return SCIP_OKAY;
851 }
852
853 SCIP_CALL( readRef(scip, reader, filename, result) );
854
855 return SCIP_OKAY;
856}
857
858
859/** problem writing method of reader */
860static
862{
863 /*lint --e{715}*/
864 SCIP_CALL( writeREFFile(scip, reader, file) );
866 return SCIP_OKAY;
867}
868
869/*
870 * reader specific interface methods
871 */
872
873/** includes the ref file reader in SCIP */
875 GCG* gcg /**< GCG data structure */
876 )
877{
878 SCIP_READERDATA* readerdata;
880 assert(origprob != NULL);
881
882 SCIP_CALL( SCIPallocMemory(origprob, &readerdata) );
883 readerdata->gcg = gcg;
884
885 /* include reader */
887 NULL, readerFreeRef, readerReadRef, readerWriteRef, readerdata) );
888
889 return SCIP_OKAY;
890}
SCIP_DECL_READERREAD(ReaderTSP::scip_read)
SCIP_DECL_READERWRITE(ReaderTSP::scip_write)
SCIP_DECL_READERFREE(ReaderTSP::scip_free)
SCIP_RETCODE GCGconshdlrDecompAddPreexistingDecomp(GCG *gcg, GCG_DECOMP *decomp)
adds a decomp that exists before the detection is called
GCG_DECOMP * GCGgetBestDecomp(GCG *gcg, SCIP_Bool printwarnings)
Gets the best known decomposition.
constraint handler for structure detection
void GCGdecompSetPresolved(GCG_DECOMP *decomp, SCIP_Bool presolved)
Definition decomp.c:724
void GCGdecompSetDetector(GCG_DECOMP *decomp, GCG_DETECTOR *detector)
Definition decomp.c:1605
SCIP_CONS *** GCGdecompGetSubscipconss(GCG_DECOMP *decomp)
Definition decomp.c:924
SCIP_RETCODE GCGdecompCreate(GCG *gcg, GCG_DECOMP **decdecomp)
Definition decomp.c:480
SCIP_RETCODE GCGfilloutDecompFromHashmaps(GCG *gcg, GCG_DECOMP *decomp, SCIP_HASHMAP *vartoblock, SCIP_HASHMAP *constoblock, int nblocks, SCIP_Bool staircase)
Definition decomp.c:1293
void GCGdecompSetNBlocks(GCG_DECOMP *decomp, int nblocks)
Definition decomp.c:745
SCIP_RETCODE GCGdecompFree(GCG *gcg, GCG_DECOMP **decdecomp)
Definition decomp.c:541
int GCGdecompGetNBlocks(GCG_DECOMP *decomp)
Definition decomp.c:757
int * GCGdecompGetNSubscipconss(GCG_DECOMP *decomp)
Definition decomp.c:933
#define SCIP_Bool
#define SCIP_CALL_QUIET(x)
#define TRUE
#define FALSE
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
int SCIPfclose(SCIP_FILE *fp)
char * SCIPfgets(char *s, int size, SCIP_FILE *stream)
GCG interface methods.
int GCGvarGetBlock(SCIP_VAR *var)
Definition gcgvar.c:1118
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
GCG_EXPORT GCG_DECOMP * GCGgetStructDecomp(GCG *gcg)
Definition relax_gcg.c:2331
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIP_RETCODE SCIPgetVarsData(SCIP *scip, SCIP_VAR ***vars, int *nvars, int *nbinvars, int *nintvars, int *nimplvars, int *ncontvars)
int SCIPgetNOrigConss(SCIP *scip)
SCIP_CONS ** SCIPgetConss(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_CONS ** SCIPgetOrigConss(SCIP *scip)
SCIP_CONS * SCIPfindCons(SCIP *scip, const char *name)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
SCIP_RETCODE SCIPhashmapSetImage(SCIP_HASHMAP *hashmap, void *origin, void *image)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapRemove(SCIP_HASHMAP *hashmap, void *origin)
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,...)
void SCIPswapPointers(void **pointer1, void **pointer2)
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
const char * SCIPconsGetName(SCIP_CONS *cons)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPallocMemoryArray(scip, ptr, num)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocMemory(scip, ptr)
#define SCIPfreeMemoryArray(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_RETCODE SCIPtransformProb(SCIP *scip)
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)
SCIPfreeMemory(GCGgetOrigprob(gcg), &divingdata)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
* result
SCIP_VAR * var
SCIP_VAR ** vars
int j
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
SCIP_RETCODE retcode
int i
int nvars
SCIPfreeBufferArray(scip, &cycles)
#define NULL
#define BMSclearMemoryArray(ptr, num)
struct SCIP_File SCIP_FILE
#define SCIPerrorMessage
static void syntaxError(SCIP *scip, BLKINPUT *blkinput, const char *msg)
static SCIP_Bool hasError(BLKINPUT *blkinput)
static const char tokenchars[]
static const char commentchars[]
#define READER_DESC
static SCIP_Bool isInt(SCIP *scip, BLKINPUT *blkinput, int *value)
#define READER_EXTENSION
static SCIP_RETCODE readStart(SCIP *scip, BLKINPUT *blkinput)
static SCIP_Bool isValueChar(char c, char nextc, SCIP_Bool firstchar, SCIP_Bool *hasdot, BLKEXPTYPE *exptype)
#define READER_NAME
static SCIP_Bool getNextToken(BLKINPUT *blkinput)
static SCIP_Bool isDelimChar(char c)
static SCIP_RETCODE readNBlocks(SCIP *scip, gcg::PARTIALDECOMP *partialdec, BLKINPUT *blkinput)
static const char delimchars[]
static SCIP_Bool getNextLine(BLKINPUT *blkinput)
static SCIP_Bool isTokenChar(char c)
SCIP_RETCODE GCGincludeReaderRef(GCG *gcg)
Definition reader_ref.c:874
static SCIP_RETCODE writeREFFile(SCIP *scip, SCIP_READER *reader, FILE *file)
Definition reader_ref.c:638
static SCIP_RETCODE readRef(SCIP *scip, SCIP_READER *reader, const char *filename, SCIP_RESULT *result)
Definition reader_ref.c:732
enum RefExpType REFEXPTYPE
Definition reader_ref.c:70
static SCIP_RETCODE readBlockSizes(SCIP *scip, REFINPUT *refinput)
Definition reader_ref.c:445
RefSection
Definition reader_ref.c:61
@ REF_START
Definition reader_ref.c:62
@ REF_NBLOCKS
Definition reader_ref.c:62
@ REF_END
Definition reader_ref.c:62
@ REF_BLOCKSIZES
Definition reader_ref.c:62
@ REF_BLOCKS
Definition reader_ref.c:62
static SCIP_RETCODE readREFFile(SCIP *scip, SCIP_READER *reader, REFINPUT *refinput, GCG_DECOMP *decomp, const char *filename)
Definition reader_ref.c:561
#define REF_MAX_LINELEN
Definition reader_ref.c:56
RefExpType
Definition reader_ref.c:67
@ REF_EXP_UNSIGNED
Definition reader_ref.c:68
@ REF_EXP_NONE
Definition reader_ref.c:68
@ REF_EXP_SIGNED
Definition reader_ref.c:68
struct RefInput REFINPUT
Definition reader_ref.c:97
#define REF_MAX_PUSHEDTOKENS
Definition reader_ref.c:57
static SCIP_RETCODE readBlocks(SCIP *scip, REFINPUT *refinput)
Definition reader_ref.c:473
enum RefSection REFSECTION
Definition reader_ref.c:64
REF file reader for structure information.
GCG relaxator.
SCIP_CONS ** masterconss
Definition reader_ref.c:90
int nmasterconss
Definition reader_ref.c:91
char linebuf[REF_MAX_LINELEN]
Definition reader_ref.c:77
char * tokenbuf
Definition reader_ref.c:79
SCIP_HASHMAP * vartoblock
Definition reader_ref.c:94
int nblocks
Definition reader_ref.c:84
char * token
Definition reader_ref.c:78
int blocknr
Definition reader_ref.c:85
int npushedtokens
Definition reader_ref.c:81
int totalreadconss
Definition reader_ref.c:89
int nassignedvars
Definition reader_ref.c:86
int linenumber
Definition reader_ref.c:82
int linepos
Definition reader_ref.c:83
SCIP_HASHMAP * constoblock
Definition reader_ref.c:95
SCIP_Bool haserror
Definition reader_ref.c:93
int * blocksizes
Definition reader_ref.c:87
SCIP_FILE * file
Definition reader_ref.c:76
REFSECTION section
Definition reader_ref.c:92
int totalconss
Definition reader_ref.c:88
char * pushedtokens[REF_MAX_PUSHEDTOKENS]
Definition reader_ref.c:80
struct SCIP_Cons SCIP_CONS
struct SCIP_Conshdlr SCIP_CONSHDLR
struct GCG_Decomp GCG_DECOMP
Definition type_decomp.h:45
struct Gcg GCG
Definition type_gcg.h:44
SCIP_VERBLEVEL_DIALOG
SCIP_VERBLEVEL_MINIMAL
struct SCIP_HashMap SCIP_HASHMAP
struct SCIP_ReaderData SCIP_READERDATA
struct SCIP_Reader SCIP_READER
SCIP_SUCCESS
enum SCIP_Result SCIP_RESULT
SCIP_NOFILE
SCIP_READERROR
SCIP_INVALIDDATA
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_TRANSFORMED
SCIP_STAGE_INIT
SCIP_STAGE_PRESOLVED
struct SCIP_Var SCIP_VAR