GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
reader_jdec.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_jdec.cpp
30 * @brief jdec file reader for (JSON formatted) structure information
31 * @author Erik Muehmer
32 * @ingroup FILEREADERS
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37// #define SCIP_DEBUG
38
39#include "gcg/reader_jdec.h"
42#include "gcg/cons_decomp.hpp"
43
44#include <algorithm>
45#include <cassert>
46#include <string>
47#include <jansson.h>
48
49#define READER_NAME "jdecreader"
50#define READER_DESC "jdec (JSON formatted structure information) file reader"
51#define READER_EXTENSION "jdec"
52
53#define JDEC_VERSION 1
54
55using namespace gcg;
56
57/** checks version */
58static constexpr bool checkVersion(int version)
59{
60 return version > 0 && version <= JDEC_VERSION;
61}
62
63/** checks return value of json lib calls */
64static constexpr bool checkJson(int returnvalue)
65{
66 return returnvalue == 0;
67}
68
69/** data for dec reader */
70struct SCIP_ReaderData
71{
72 GCG* gcg; /** GCG data structure */
73};
74
76
77/** struct to store block information (read from file) */
79{
80 /** constructor */
82 int number /**< number of block */
83 )
86 blocknumber(number) {}
87
88 /** deleted copy constructor */
89 JDecBlockData(const JDecBlockData&) = delete;
90
91 /** move constructor */
93 JDecBlockData&& block /**< other block data */
94 ) noexcept;
95
96 /** destructor */
98
99 /** deleted assignment operator */
101
102 /** move assignment */
104 JDecBlockData&& block /**< other block data */
105 );
106
107 /** less than operator to order block by their indices */
108 bool operator<(
109 const JDecBlockData& block /**< other block to compare against */
110 ) const;
111
112 std::vector<std::string> constraints; /**< names of constraints */
113 JDecDecompositionData* decomposition; /**< pointer to decomposition object */
114 int symmetricalblock; /**< number of representative/symmetrical block */
115 int blocknumber; /**< number of block/subproblem */
116};
117
118/** struct to store (nested) decomposition data (read from file) */
120{
121 /** constructor */
123
124 /** destructor */
126
127 /** creates a block structure object */
129 GCG* gcg, /**< GCG object */
130 DETPROBDATA* detprobdata /**< detprobdata used to create the block structure object */
131 );
132
133 bool presolved; /** is this a decomposition of a presolved model? */
134 std::vector<std::string> masterconstraints; /**< vector containing names of master constraints */
135 std::vector<JDecBlockData> blocks; /**< vector containing block data of each block */
136 std::unordered_map<std::string, std::string> symmetryvardata; /**< symmetry mapping for variables: name of variable -> name of its representative variable */
137};
138
139/** struct that stores the metadata of the read decomposition and a pointer to the actual decomposition */
141{
142 /** constructor */
144
145 /** deleted copy constructor */
146 JDecData(const JDecData&) = delete;
147
148 /** destructor */
149 ~JDecData();
150
151 /** deleted assignment operator */
152 JDecData& operator=(const JDecData&) = delete;
153
154 int version; /** version of jdec file */
155 std::string name; /** decomposition's name */
156 std::string description; /** decomposition's description */
157 JDecDecompositionData* rootdecomposition; /** actual decomposition */
158};
159
161
162/** writes and reads jdec files */
164{
165public:
166 /** constructor creating an object ready to read a jdec file */
168 GCG* gcg, /**< GCG data structure */
169 const char* filename /**< path of the jdec file to be read */
170 );
171
172 /** constructor creating an object ready to write a jdec file */
174 GCG* gcg, /**< GCG data structure */
175 FILE* wfile /**< file pointer used to write the jdec file */
176 );
177
178 /** destructor */
180
181 /** parses a json element using an element parser, returns a bool indicating success/failure */
182 bool parseElement(
183 AbstractJDecElementParser& elementparser, /**< the element parser */
184 json_t* element /**< pointer to the json element */
185 );
186
187 /**
188 * reads a jdec file an stores the information in a data object, returns a bool indicating success/failure
189 *
190 * @note must be constructed as reader
191 */
192 bool readJDec(
193 JDecData& data /**< JDecData object used to store the read information */
194 );
195
196 /**
197 * writes a partialldec to a jdec file, returns a bool indicating success/failure, returns a bool indicating success/failure
198 *
199 * @note must be constructed as writer
200 */
201 bool writeJDec(
202 PARTIALDECOMP* decomp /**< partialdec that will be written to the jdec file */
203 );
204
205private:
206 /** initialize the handler */
207 void initialize();
208
209 /** serializes a specific block of a partialdec and puts it into an existing json object, returns a bool indicating success/failure */
210 bool serializeBlock(
211 json_t* json, /**< pointer to json struct that is already initialized as json object */
212 PARTIALDECOMP* decomp, /**< pointer to partialdec */
213 int block /**< number of block that should be serialized */
214 );
215
216 /** serializes a block structure and puts it into an existing json object, returns a bool indicating success/failure */
217 bool serializeBlockStructure(
218 json_t* json, /**< pointer to json struct that is already initialized as json object */
219 PARTIALDECOMP* decomp, /**< pointer to partialdec the block structure belongs to */
220 BLOCK_STRUCTURE* blockstructure /**< pointer to block structure */
221 );
222
223 /** serializes a block of a block structure and puts it into an existing json object, returns a bool indicating success/failure */
224 bool serializeBlockStructureBlock(
225 json_t* json, /**< pointer to json struct that is already initialized as json object */
226 PARTIALDECOMP* decomp, /**< pointer to partialdec the block structure belongs to */
227 BLOCK_STRUCTURE* blockstructure, /**< pointer to block structure */
228 int block /**< number of block that should be serialized */
229 );
230
231 /** serializes a partialdec and puts it into an existing json object, returns a bool indicating success/failure */
232 bool serializeDecomposition(
233 json_t* json, /**< pointer to json struct that is already initialized as json object */
234 PARTIALDECOMP* decomp /**< pointer to partialdec that should be serialized */
235 );
236
237 /** sets a value of the root or a provided json object for a specific key (key-value pair), returns a bool indicating success/failure */
238 bool setObjectValue(
239 const char* key, /**< the key used to store the value */
240 json_t* value, /**< pointer to a json struct that will be set as value */
241 json_t* object = NULL, /**< pointer to json object that will be modified, if NULL the root json object of the handler will be modified */
242 bool decref = true /**< should the reference counter of the value json struct be decreased? (see JANSSON API documentation) */
243 );
244
245 /** appends a value to an json array, returns a bool indicating success/failure */
246 bool appendArrayValue(
247 json_t* value, /**< pointer to a json struct that will be set as value */
248 json_t* array, /**< pointer to the json array */
249 bool decref = true /**< should the reference counter of the value json struct be decreased? (see JANSSON API documentation) */
250 );
251
252 /** (static) callback provided to JANSSON used to read data: when called it writes at most buflen bytes to buffer and returns the number of bytes written */
253 static size_t jsonLoadCallback(
254 void* buffer, /**< pointer to buffer */
255 size_t buflen, /**< length of buffer */
256 void* data /**< pointer to user data, will point to the handler itself */
257 );
258
259 /** (static) callback provided to JANSSON used to write data: when called it writes the output contained in buffer to the jdec file and returns 0 on success or -1 else */
260 static int jsonDumpCallback(
261 const char* buffer, /**< pointer to buffer */
262 size_t buflen, /**< length of buffer */
263 void* data /**< pointer to user data, will point to the handler itself */
264 );
265
266 SCIP_FILE* rfile_; /**< SCIP file pointer to read from */
267 FILE* wfile_; /**< file pointer to write to */
268 json_t* json_; /**< root json object */
269 json_error_t error_; /**< will contain error information of JANSSON if decoding fails */
270 GCG* gcg; /**< GCG data structure */
271 SCIP* scip; /**< SCIP data structure (origprob) */
272};
273
274/** abstract element parser class used to process data read by the jdec file handler */
276{
277public:
278 /** constructor */
280 GCG* gcgstruct, /**< GCG data structure */
281 JDecFileHandler& filehandler /**< jdec file handler that uses this parser*/
282 ) : filehandler_(filehandler), gcg(gcgstruct), scip(GCGgetOrigprob(gcg)), error_(false) {}
283
284 /** destructor */
285 virtual ~AbstractJDecElementParser() = default;
286
287 /** abstract method that will be called for each key-value pair read by the handler */
288 virtual void handleKeyValuePair(
289 const char* name, /**< name/key of the value read */
290 json_t* value /**< pointer to the value */
291 ) = 0;
292
293 /** abstract method that will be called for each value read by the handler */
294 virtual void handleValue(
295 json_t* value /**< pointer to the value */
296 ) = 0;
297
298 /** returns true if an error occured during parsing or false otherwise */
299 bool error() const
300 {
301 return error_;
302 }
303
304protected:
305 JDecFileHandler& filehandler_; /**< the file handler that uses this parser */
306 GCG* gcg; /**< GCG data structure */
307 SCIP* scip; /**< SCIP data structure (origprob) */
308 bool error_; /**< should be set to true if an error ocurred */
309};
310
311/** abstract decomposition element parser */
313{
314public:
315 /** constructor */
317 GCG* gcgstruct, /**< GCG data structure */
318 JDecFileHandler& filehandler /**< jdec file handler using this parser */
319 ) : AbstractJDecElementParser(gcgstruct, filehandler) {}
320
321 /** destructor */
323
324protected:
325 /** parses/deserializes the decomposition contained by a json object and returns the created decomposition data*/
327 json_t* value /**< the json object */
328 );
329};
330
331/** block element parser, parses/deserializes blocks of decompositions */
333{
334public:
335 /** constructor */
337 GCG* gcgstruct, /**< GCG data structure */
338 JDecFileHandler& filehandler, /**< file handler using this parser */
339 JDecBlockData& blockdata /**< block data structure the data is stored in */
340 )
341 : AbstractJDecDecompositionElementParser(gcgstruct, filehandler),
342 blockdata_(blockdata),
343 parsingconstraints(false)
344 {}
345
346 /** destructor */
347 ~JDecBlockElementParser() override = default;
348
349 /** implements the corresponding abstract function */
351 const char* name,
352 json_t* value
353 ) override;
354
355 /** implements the corresponding abstract function */
356 void handleValue(
357 json_t* value
358 ) override;
359
360private:
361 JDecBlockData& blockdata_; /**< block data struct used to store the parsed data */
362 bool parsingconstraints; /**< are we currently parsing the constraint array? */
363};
364
365/** actual decomposition element parser, parses/deserializes a decomposition */
367{
368public:
369 /** constructor */
371 GCG* gcgstruct, /**< GCG data structure */
372 JDecFileHandler& filehandler, /**< file handler using this parser */
373 JDecDecompositionData& decdata /**< decomposition data structure the data is stored in */
374 )
375 : AbstractJDecDecompositionElementParser(gcgstruct, filehandler),
376 decdata_(decdata),
377 parsingmasterconstraints(false),
378 parsingblocks(false),
379 parsingsymmetry(false)
380 {}
381
382 /** destructor */
384
385 /** implements the corresponding abstract function */
387 const char* name,
388 json_t* value
389 ) override;
390
391 /** implements the corresponding abstract function */
392 void handleValue(
393 json_t* value
394 ) override;
395
396private:
397 JDecDecompositionData& decdata_; /**< decomposition data struct used to store the parsed data */
398 bool parsingmasterconstraints; /**< are we currently parsing the master constraints? */
399 bool parsingblocks; /**< are we currently parsing the blocks? */
400 bool parsingsymmetry; /**< are we currently parsing the symmetry mapping of the variables? */
401};
402
403/** root element parser, parses/deserializes the root object of a jdec file */
405{
406public:
407 /** constructor */
409 GCG* gcgstruct, /**< GCG data structure */
410 JDecFileHandler& filehandler, /**< file handler using this parser */
411 JDecData& data /**< jdec data structure the data is stored in */
412 ) : AbstractJDecDecompositionElementParser(gcgstruct, filehandler), data_(data) {}
413
414 /** destructor */
415 ~JDecRootElementParser() override = default;
416
417 /** implements the corresponding abstract function */
419 const char* name,
420 json_t* value
421 ) override;
422
423 /** implements the corresponding abstract function */
424 void handleValue(
425 json_t* value
426 ) override;
427
428private:
429 JDecData& data_; /**< the jdec data structure used for storing the parsed data */
430};
431
433 JDecBlockData&& block
434 ) noexcept
435{
436 blocknumber = block.blocknumber;
437 symmetricalblock = block.symmetricalblock;
438 constraints = std::move(block.constraints);
439 decomposition = block.decomposition;
440 block.decomposition = NULL;
441}
442
447
449 JDecBlockData&& block
450 )
451{
452 blocknumber = block.blocknumber;
453 symmetricalblock = block.symmetricalblock;
454 constraints = std::move(block.constraints);
455 if( decomposition != NULL )
456 delete decomposition;
457 decomposition = block.decomposition;
458 block.decomposition = NULL;
459 return *this;
460}
461
463 const JDecBlockData& block
464 ) const
465{
466 return blocknumber < block.blocknumber;
467}
468
473
475 GCG* gcg,
476 DETPROBDATA* detprobdata
477 )
478{
479 BLOCK_STRUCTURE* blockstructure = new BLOCK_STRUCTURE();
481 int idx;
482
483 if( presolved )
484 {
485 SCIPwarningMessage(scip, "Decomposition of blocks must not belong to a presolved model, ignoring this flag.\n");
486 }
487
488 // master
489 for( auto& cons : masterconstraints )
490 {
491 idx = detprobdata->getIndexForCons(cons.c_str());
492 if( idx >= 0 )
493 blockstructure->masterconss.push_back(idx);
494 }
495
496 // blocks
497 for( auto& blockdata : blocks )
498 {
499 blockstructure->blockconss.emplace_back();
500 for( auto& cons : blockdata.constraints )
501 {
502 idx = detprobdata->getIndexForCons(cons.c_str());
503 if( idx >= 0 )
504 blockstructure->blockconss.back().push_back(idx);
505 }
506 if( blockdata.decomposition )
507 blockstructure->blockstructures.push_back(blockdata.decomposition->createBlockStructure(gcg, detprobdata));
508 else
509 blockstructure->blockstructures.emplace_back();
510 }
511
512 // symmetry
513 if( !symmetryvardata.empty() )
514 {
515 bool success = true;
516 for( auto& blockdata : blocks )
517 {
518 if( blockdata.symmetricalblock >= 0 && blockdata.symmetricalblock < (int)blocks.size() )
519 {
520 blockstructure->symmetricalblocks.push_back(blockdata.symmetricalblock);
521 }
522 else
523 {
524 SCIPwarningMessage(scip, "Got invalid block number: %d.\n", blockdata.symmetricalblock);
525 success = false;
526 break;
527 }
528 }
529
530 if( success )
531 {
532 int idx2;
533 for( auto& it : symmetryvardata )
534 {
535 idx = detprobdata->getIndexForVar(it.first.c_str());
536 idx2 = detprobdata->getIndexForVar(it.second.c_str());
537 if( idx >= 0 && idx2 >= 0 )
538 {
539 blockstructure->symmetryvardata.emplace(idx, idx2);
540 }
541 else
542 {
543 SCIPwarningMessage(scip, "Got invalid variable mapping: <%s> -> <%s>.\n", it.first.c_str(), it.second.c_str());
544 success = false;
545 blockstructure->symmetryvardata.clear();
546 break;
547 }
548 }
549 }
550
551 if( !success )
552 {
553 SCIPwarningMessage(scip, "Could not set nested symmetry information.\n");
554 }
555 }
556
557 return blockstructure;
558}
559
561 GCG* gcgstruct,
562 const char* filename
563 )
564 : wfile_(NULL),
565 json_(NULL),
566 error_(),
567 gcg(gcgstruct),
568 scip(GCGgetOrigprob(gcgstruct))
569{
570 rfile_ = SCIPfopen(filename, "r");
571 initialize();
572}
573
575 GCG* gcgstruct,
576 FILE* file
577 )
578 : rfile_(NULL),
579 wfile_(file),
580 json_(NULL),
581 error_(),
582 gcg(gcgstruct),
584{
585 initialize();
586}
587
589{
590 if( json_ )
591 json_decref(json_);
592 if( rfile_ )
593 SCIPfclose(rfile_);
594}
595
596void JDecFileHandler::initialize()
597{
598 if( rfile_ )
599 {
600 json_ = json_load_callback(&jsonLoadCallback, this, 0, &error_);
601 }
602 else
603 {
604 json_ = json_object();
605 }
606}
607
609 AbstractJDecElementParser& elementparser,
610 json_t* element
611 )
612{
613 bool error = false;
614 json_t* value;
615
616 if( json_is_object(element) )
617 {
618 const char* key;
619 json_object_foreach(element, key, value)
620 {
621 elementparser.handleKeyValuePair(key, value);
622 if( elementparser.error() )
623 break;
624 }
625 }
626 else if (json_is_array(element))
627 {
628 size_t index;
629 json_array_foreach(element, index, value)
630 {
631 elementparser.handleValue(value);
632 if( elementparser.error() )
633 break;
634 }
635 }
636 else
637 {
638 SCIPwarningMessage(scip, "Unexpected JSON type: %d\n", json_typeof(element));
639 error = true;
640 }
641
642 error |= elementparser.error();
643 return !error;
644}
645
647 JDecData& data
648 )
649{
650 bool error = false;
651
652 if( rfile_ == NULL )
653 {
654 SCIPwarningMessage(scip, "JSON parser is not initialized.");
655 error = true;
656 }
657 else if( json_ == NULL )
658 {
659 SCIPwarningMessage(scip, "Could not parse JSON, line %d: %s\n", error_.line, error_.text);
660 error = true;
661 }
662 else if( !json_is_object(json_) )
663 {
664 SCIPwarningMessage(scip, "Decomposition is invalid (root has to be an object).\n");
665 error = true;
666 }
667 else
668 {
669 JDecRootElementParser rootparser(gcg, *this, data);
670 error = !parseElement(rootparser, json_);
671 }
672
673 if( !error && !checkVersion(data.version) )
674 {
675 error = true;
676 SCIPwarningMessage(scip, "Invalid version.\n");
677 }
678
679 return !error;
680}
681
683 gcg::PARTIALDECOMP* decomp
684 )
685{
686 bool success = (wfile_ != NULL && json_ != NULL);
687 if( success )
688 {
689 success &= setObjectValue("version", json_integer(JDEC_VERSION));
690 success &= setObjectValue("problem_name", json_string(SCIPgetProbName(scip)));
691 success &= setObjectValue("decomposition_id", json_integer(decomp->getID()));
692
693 json_t* jsondecomp = json_object();
694 success &= serializeDecomposition(jsondecomp, decomp);
695 success &= setObjectValue("decomposition", jsondecomp);
696 }
697 else
698 {
699 SCIPwarningMessage(scip, "JSON parser is not initialized.");
700 }
701
702 if( success )
703 {
704 success = checkJson(json_dump_callback(json_, &jsonDumpCallback, this, JSON_INDENT(2)));
705 }
706 return success;
707}
708
709bool JDecFileHandler::serializeBlock(
710 json_t* json,
711 gcg::PARTIALDECOMP* decomp,
712 int block
713 )
714{
715 bool success = true;
716 auto* detprobdata = decomp->getDetprobdata();
717 json_t* jsonconstraints = json_array();
718
719 success &= setObjectValue("index", json_integer(block), json);
720
721 for( int i: decomp->getConssForBlock(block) )
722 {
723 auto* cons = detprobdata->getCons(i);
724 success &= appendArrayValue(json_string(SCIPconsGetName(cons)), jsonconstraints);
725 }
726 success &= setObjectValue("constraints", jsonconstraints, json);
727
728 if( decomp->aggInfoCalculated() )
729 {
730 success &= setObjectValue("symmetry_representative_block", json_integer(decomp->getReprBlockForEqClass(decomp->getEqClassForBlock(block))), json);
731 }
732
733 if( decomp->isNested() && decomp->getBlockStructure(block) != NULL )
734 {
735 json_t* jsonblockstructure = json_object();
736 serializeBlockStructure(jsonblockstructure, decomp, decomp->getBlockStructure(block));
737 success &= setObjectValue("decomposition", jsonblockstructure, json);
738 }
739
740 return success;
741}
742
743bool JDecFileHandler::serializeBlockStructure(
744 json_t* json,
745 gcg::PARTIALDECOMP* decomp,
746 gcg::BLOCK_STRUCTURE* blockstructure
747 )
748{
749 bool success = true;
750 auto* detprobdata = decomp->getDetprobdata();
751
752 assert(blockstructure != NULL);
753
754 json_t* jsonmasterconstraints = json_array();
755 for( int i: blockstructure->masterconss )
756 {
757 auto* cons = detprobdata->getCons(i);
758 success &= appendArrayValue(json_string(SCIPconsGetName(cons)), jsonmasterconstraints);
759 }
760 success &= setObjectValue("master_constraints", jsonmasterconstraints, json);
761
762 json_t* jsonblocks = json_array();
763 for( int b = 0; b < (int)blockstructure->blockconss.size(); ++b )
764 {
765 json_t* jsonblock = json_object();
766 success &= serializeBlockStructureBlock(jsonblock, decomp, blockstructure, b);
767 success &= appendArrayValue(jsonblock, jsonblocks);
768 }
769 success &= setObjectValue("blocks", jsonblocks, json);
770
771 return success;
772}
773
774bool JDecFileHandler::serializeBlockStructureBlock(
775 json_t* json,
776 PARTIALDECOMP* decomp,
777 BLOCK_STRUCTURE* blockstructure,
778 int block
779 )
780{
781 bool success = true;
782 auto* detprobdata = decomp->getDetprobdata();
783 json_t* jsonconstraints = json_array();
784
785 for( int i: blockstructure->blockconss[block] )
786 {
787 auto* cons = detprobdata->getCons(i);
788 success &= appendArrayValue(json_string(SCIPconsGetName(cons)), jsonconstraints);
789 }
790 success &= setObjectValue("constraints", jsonconstraints, json);
791
792 // @todo: add "symmetry_representative_block"
793
794 if( blockstructure->blockstructures[block] )
795 {
796 json_t* jsonblockstructure = json_object();
797 serializeBlockStructure(jsonblockstructure, decomp, blockstructure->blockstructures[block]);
798 success &= setObjectValue("decomposition", jsonblockstructure, json);
799 }
800
801 return success;
802}
803
804bool JDecFileHandler::serializeDecomposition(
805 json_t* json,
806 gcg::PARTIALDECOMP* decomp
807 )
808{
809 bool success = true;
810 auto* detprobdata = decomp->getDetprobdata();
811
812 success &= setObjectValue("presolved", json_boolean(!decomp->isAssignedToOrigProb()), json);
813 success &= setObjectValue("n_blocks", json_integer(decomp->getNBlocks()), json);
814
815 json_t* jsonmasterconstraints = json_array();
816 for( int i: decomp->getMasterconss() )
817 {
818 auto* cons = detprobdata->getCons(i);
819 success &= appendArrayValue(json_string(SCIPconsGetName(cons)), jsonmasterconstraints);
820 }
821 success &= setObjectValue("master_constraints", jsonmasterconstraints, json);
822
823 if( !decomp->aggInfoCalculated() )
824 {
825 decomp->calcAggregationInformation(true);
826 }
827
828 json_t* jsonblocks = json_array();
829 for( int b = 0; b < decomp->getNBlocks(); ++b )
830 {
831 json_t* jsonblock = json_object();
832 success &= serializeBlock(jsonblock, decomp, b);
833 success &= appendArrayValue(jsonblock, jsonblocks);
834 }
835 success &= setObjectValue("blocks", jsonblocks, json);
836
837 if( decomp->aggInfoCalculated() && decomp->getNEquivalenceClasses() < decomp->getNBlocks() )
838 {
839 json_t* jsonsymmetry = json_object();
840 for( int ec = 0; ec < decomp->getNEquivalenceClasses(); ++ec )
841 {
842 int repblock = decomp->getReprBlockForEqClass(ec);
843 auto& eqclassblocks = decomp->getBlocksForEqClass(ec);
844 for( int i = 0; i < (int) eqclassblocks.size(); ++i )
845 {
846 int b = eqclassblocks[i];
847 if( b == repblock )
848 continue;
849 for( int vi = 0; vi < (int)decomp->getRepVarmap(ec, i).size(); ++vi )
850 {
851 int rvi = decomp->getRepVarmap(ec, i)[vi];
852 auto* var = detprobdata->getVar(decomp->getVarsForBlock(b)[vi]);
853 auto* repvar = detprobdata->getVar(decomp->getVarsForBlock(repblock)[rvi]);
854 success &= setObjectValue(SCIPvarGetName(var), json_string(SCIPvarGetName(repvar)), jsonsymmetry);
855 }
856 }
857 }
858 success &= setObjectValue("symmetry_var_mapping", jsonsymmetry, json);
859 }
860
861 return success;
862}
863
864bool JDecFileHandler::setObjectValue(
865 const char* key,
866 json_t* value,
867 json_t* object,
868 bool decref
869 )
870{
871 bool success;
872
873 if( !object )
874 object = json_;
875
876 if( decref )
877 {
878 success = checkJson(json_object_set_new(object, key, value));
879 }
880 else
881 {
882 success = checkJson(json_object_set(object, key, value));
883 }
884
885 if( !success )
886 {
887 SCIPwarningMessage(scip, "Could not set value with key '%s'\n", key);
888 }
889 return success;
890}
891
892bool JDecFileHandler::appendArrayValue(
893 json_t* value,
894 json_t* array,
895 bool decref
896 )
897{
898 bool success;
899
900 if( decref )
901 {
902 success = checkJson(json_array_append_new(array, value));
903 }
904 else
905 {
906 success = checkJson(json_array_append(array, value));
907 }
908
909 if( !success )
910 {
911 SCIPwarningMessage(scip, "Could not append value.\n");
912 }
913 return success;
914}
915
916size_t JDecFileHandler::jsonLoadCallback(
917 void* buffer,
918 size_t buflen,
919 void* data
920 )
921{
922 auto* filehandler = (JDecFileHandler*) data;
923 size_t size_read = SCIPfread(buffer, 1, buflen, filehandler->rfile_);
924 return (size_read == 0 && !SCIPfeof(filehandler->rfile_)) ? (size_t)-1 : size_read;
925}
926
927int JDecFileHandler::jsonDumpCallback(
928 const char* buffer,
929 size_t buflen,
930 void* data
931 )
932{
933 auto* filehandler = (JDecFileHandler*) data;
934 size_t pos = 0;
935
936 // not sure if SCIPinfoMessage is the best function to call but SCIP's readers use it too
937 while( (buflen - pos) > (SCIP_MAXSTRLEN - 1) )
938 {
939 SCIPinfoMessage(filehandler->scip, filehandler->wfile_, "%.*s", (SCIP_MAXSTRLEN - 1), &buffer[pos]);
940 pos += (SCIP_MAXSTRLEN - 1);
941 }
942 SCIPinfoMessage(filehandler->scip, filehandler->wfile_, "%.*s", (int)(buflen - pos), &buffer[pos]);
943
944 // size_t size_written = SCIPfwrite(buffer, 1, buflen, filehandler->wfile_);
945 // return (size_written == 0) ? 1 : 0;
946 return 0;
947}
948
950 json_t* value
951 )
952{
954 JDecDecompositionElementParser decompositionparser(gcg, filehandler_, *decompdata);
955 if( !filehandler_.parseElement(decompositionparser, value) )
956 error_ = true;
957 return decompdata;
958}
959
961 const char* name,
962 json_t* value
963 )
964{
965 if( strcmp(name, "version") == 0 )
966 {
967 if( json_is_integer(value) )
968 {
969 data_.version = (int) json_integer_value(value);
970 if( !checkVersion(data_.version))
971 {
972 SCIPwarningMessage(scip, "Invalid version.\n");
973 error_ = true;
974 }
975 }
976 else
977 {
978 SCIPwarningMessage(scip, "Version must be an integer.");
979 error_ = true;
980 }
981 }
982 else if( strcmp(name, "name") == 0 )
983 {
984 if( json_is_string(value) )
985 {
986 data_.name = std::string(json_string_value(value));
987 }
988 else
989 {
990 SCIPwarningMessage(scip, "Decomposition name must be a string.");
991 error_ = true;
992 }
993 }
994 else if( strcmp(name, "description") == 0 )
995 {
996 if( json_is_string(value) )
997 {
998 data_.description = std::string(json_string_value(value));
999 }
1000 }
1001 else if( strcmp(name, "decomposition") == 0 )
1002 {
1003 if( json_is_object(value) )
1004 {
1005 data_.rootdecomposition = parseDecomposition(value);
1006 }
1007 else
1008 {
1009 SCIPwarningMessage(scip, "Decomposition must be an object.\n");
1010 error_ = true;
1011 }
1012 }
1013 else
1014 {
1015 SCIPdebugMessage("Skipping unknown element '%s'.\n", name);
1016 }
1017}
1018
1020 json_t* value
1021 )
1022{
1023}
1024
1026 const char* name,
1027 json_t* value
1028 )
1029{
1030 if( parsingsymmetry )
1031 {
1032 if( json_is_string(value) )
1033 {
1034 decdata_.symmetryvardata.emplace(std::string(name), std::string(json_string_value(value)));
1035 }
1036 else
1037 {
1038 SCIPwarningMessage(scip, "Symmetry information must consist of strings.");
1039 error_ = true;
1040 }
1041 }
1042 else
1043 {
1044 if( strcmp(name, "master_constraints") == 0 )
1045 {
1046 if( json_is_array(value))
1047 {
1048 parsingmasterconstraints = true;
1049 if( !filehandler_.parseElement(*this, value) )
1050 error_ = true;
1051 parsingmasterconstraints = false;
1052 }
1053 else
1054 {
1055 SCIPwarningMessage(scip, "Constraints must be given as an array of strings.\n");
1056 error_ = true;
1057 }
1058 }
1059 else if( strcmp(name, "blocks") == 0 )
1060 {
1061 if( json_is_array(value))
1062 {
1063 parsingblocks = true;
1064 if( !filehandler_.parseElement(*this, value) )
1065 error_ = true;
1066 // sort blocks as users can assign indices which may not be sorted
1067 std::sort(decdata_.blocks.begin(), decdata_.blocks.end());
1068 // set missing numbers of block representatives, check block numbers
1069 for( int b = 0; b < (int)decdata_.blocks.size(); ++b )
1070 {
1071 auto& block = decdata_.blocks[b];
1072 if( b != block.blocknumber )
1073 {
1074 error_ = true;
1075 SCIPwarningMessage(scip, "Block indices are not consistent.\n");
1076 break;
1077 }
1078 if( block.symmetricalblock < 0 )
1079 block.symmetricalblock = block.blocknumber;
1080 }
1081 parsingblocks = false;
1082 }
1083 else
1084 {
1085 SCIPwarningMessage(scip, "Blocks must be given as an array of objects.\n");
1086 error_ = true;
1087 }
1088 }
1089 else if( strcmp(name, "symmetry_var_mapping") == 0 )
1090 {
1091 if( json_is_object(value) )
1092 {
1093 parsingsymmetry = true;
1094 if( !filehandler_.parseElement(*this, value) )
1095 error_ = true;
1096 parsingsymmetry = false;
1097 }
1098 else
1099 {
1100 SCIPwarningMessage(scip, "Symmetry information must be a mapping of strings.\n");
1101 error_ = true;
1102 }
1103 }
1104 else if( strcmp(name, "presolved") == 0 )
1105 {
1106 if( json_is_string(value) )
1107 {
1108 decdata_.presolved = strcmp(json_string_value(value), "true") == 0 ||
1109 strcmp(json_string_value(value), "t") == 0 ||
1110 strcmp(json_string_value(value), "yes") == 0 ||
1111 strcmp(json_string_value(value), "y") == 0 ||
1112 strcmp(json_string_value(value), "1") == 0;
1113 }
1114 else if ( json_is_boolean(value) )
1115 {
1116 decdata_.presolved = json_boolean_value(value);
1117 }
1118 else
1119 {
1120 SCIPwarningMessage(scip, "Could not parse value of 'presolved'.");
1121 error_ = true;
1122 }
1123 }
1124 else
1125 {
1126 SCIPdebugMessage("Skipping unknown element '%s'\n", name);
1127 }
1128 }
1129}
1130
1132 json_t* value
1133 )
1134{
1135 if( parsingblocks )
1136 {
1137 if( json_is_object(value) )
1138 {
1139 decdata_.blocks.emplace_back(static_cast<int>(decdata_.blocks.size()));
1140 JDecBlockElementParser blockparser(gcg, filehandler_, decdata_.blocks.back());
1141 if( !filehandler_.parseElement(blockparser, value) )
1142 {
1143 error_ = true;
1144 }
1145 }
1146 else
1147 {
1148 SCIPwarningMessage(scip, "Block must be an object.\n");
1149 error_ = true;
1150 }
1151 }
1152 else if( parsingmasterconstraints )
1153 {
1154 if( json_is_string(value) )
1155 {
1156 decdata_.masterconstraints.emplace_back(json_string_value(value));
1157 }
1158 else
1159 {
1160 SCIPwarningMessage(scip, "Constraints must be given as an array of strings.\n");
1161 error_ = true;
1162 }
1163 }
1164}
1165
1167 const char* name,
1168 json_t* value
1169 )
1170{
1171 if( strcmp(name, "index") == 0 )
1172 {
1173 if( json_is_integer(value) )
1174 {
1175 blockdata_.blocknumber = (int)json_integer_value(value);
1176 assert(blockdata_.blocknumber >= 0);
1177 }
1178 else
1179 {
1180 SCIPwarningMessage(scip, "Could not parse block index.\n");
1181 error_ = true;
1182 }
1183 }
1184 else if( strcmp(name, "symmetry_representative_block") == 0 )
1185 {
1186 if( json_is_integer(value) )
1187 {
1188 blockdata_.symmetricalblock = (int)json_integer_value(value);
1189 }
1190 else
1191 {
1192 SCIPwarningMessage(scip, "Could not parse block number of representative block (symmetry).\n");
1193 error_ = true;
1194 }
1195 }
1196 else if( strcmp(name, "decomposition") == 0 )
1197 {
1198 if( json_is_object(value) )
1199 {
1200 blockdata_.decomposition = parseDecomposition(value);
1201 }
1202 else
1203 {
1204 SCIPwarningMessage(scip, "Decomposition must be an object.\n");
1205 error_ = true;
1206 }
1207 }
1208 else if( strcmp(name, "constraints") == 0 )
1209 {
1210 if( json_is_array(value) )
1211 {
1212 parsingconstraints = true;
1213 filehandler_.parseElement(*this, value);
1214 parsingconstraints = false;
1215 }
1216 else
1217 {
1218 SCIPwarningMessage(scip, "Constraints must be given as an array of strings.\n");
1219 error_ = true;
1220 }
1221 }
1222 else
1223 {
1224 SCIPdebugMessage("Skipping unknown element '%s'\n", name);
1225 }
1226}
1227
1229 json_t* value
1230 )
1231{
1232 if( parsingconstraints )
1233 {
1234 if( json_is_string(value) )
1235 {
1236 blockdata_.constraints.emplace_back(json_string_value(value));
1237 }
1238 else
1239 {
1240 SCIPwarningMessage(scip, "Constraints must be given as an array of strings.\n");
1241 error_ = true;
1242 }
1243 }
1244}
1245
1246/* reads jdec file */
1247static
1249 GCG* gcg, /**< GCG data structure */
1250 const char* filename, /**< path of file */
1251 SCIP_RESULT* result /**< pointer to scip result */
1252 )
1253{
1254 JDecData data;
1256 JDecFileHandler filehandler(gcg, filename);
1257
1258 if( filehandler.readJDec(data) )
1259 {
1260 if( data.rootdecomposition )
1261 {
1262 int nblocks = (int)data.rootdecomposition->blocks.size();
1263
1265 {
1267 "Reading presolved decomposition but problem is not presolved yet. Calling SCIPpresolve()\n");
1269 }
1270
1271 PARTIALDECOMP* partialdec = new PARTIALDECOMP(gcg, !data.rootdecomposition->presolved);
1272 DETPROBDATA* detprobdata = partialdec->getDetprobdata();
1273 for( auto& cons : data.rootdecomposition->masterconstraints )
1274 {
1275 if( !partialdec->fixConsToMasterByName(cons.c_str()) )
1276 SCIPwarningMessage(scip, "Could not set constraint %s as master constraint.\n", cons.c_str());
1277 }
1278 partialdec->setNBlocks(nblocks);
1279 for( int block = 0; block < nblocks; ++block )
1280 {
1281 JDecBlockData& blockdata = data.rootdecomposition->blocks[block];
1282 assert(block == blockdata.blocknumber);
1283 for( auto& cons : blockdata.constraints )
1284 {
1285 if( !partialdec->fixConsToBlockByName(cons.c_str(), block) )
1286 SCIPwarningMessage(scip, "Could not set constraint %s as block constraint.\n", cons.c_str());
1287 }
1288 if( blockdata.decomposition )
1289 {
1290 BLOCK_STRUCTURE* nestedstructure = blockdata.decomposition->createBlockStructure(gcg, detprobdata);
1291 partialdec->setBlockStructure(block, nestedstructure);
1292 }
1293 else
1294 {
1295 partialdec->setBlockStructure(block, NULL);
1296 }
1297 }
1299
1300 if( !data.rootdecomposition->symmetryvardata.empty() )
1301 {
1302 bool success = true;
1303 auto& symmetryvardata = data.rootdecomposition->symmetryvardata;
1304
1305 // check symmetry data
1306 for( int b = 0; b < partialdec->getNBlocks() && success; ++b )
1307 {
1308 int symmetricalblock = data.rootdecomposition->blocks[b].symmetricalblock;
1309 for( int vi = 0; vi < partialdec->getNVarsForBlock(b) && success; ++vi )
1310 {
1311 SCIP_VAR* var = detprobdata->getVar(partialdec->getVarsForBlock(b)[vi]);
1312 assert(var != NULL);
1313 const auto& it = symmetryvardata.find(SCIPvarGetName(var));
1314 if( symmetricalblock == b )
1315 {
1316 success = (it == symmetryvardata.end() || it->first == it->second);
1317 assert(success);
1318 }
1319 else if( it != symmetryvardata.end() )
1320 {
1321 SCIP_VAR* reprvar = SCIPfindVar(scip, it->second.c_str());
1322 success = (reprvar != NULL &&
1323 partialdec->getVarProbindexForBlock(detprobdata->getIndexForVar(reprvar), symmetricalblock) >= 0);
1324 assert(success);
1325 }
1326 else
1327 {
1328 success = false;
1329 assert(success);
1330 }
1331 }
1332 }
1333
1334 // if successful, set symmetry data
1335 if( success )
1336 {
1337 success = partialdec->setSymmetryInformation(
1338 [&] (int b)
1339 {
1340 assert(b < (int)data.rootdecomposition->blocks.size());
1341 return data.rootdecomposition->blocks[b].symmetricalblock;
1342 },
1343 [&] (int b, int vi)
1344 {
1345 SCIP_VAR* var = detprobdata->getVar(partialdec->getVarsForBlock(b)[vi]);
1346 assert(var != NULL);
1347 assert(symmetryvardata.find(SCIPvarGetName(var)) != symmetryvardata.end());
1348 int ri = detprobdata->getIndexForVar(symmetryvardata[SCIPvarGetName(var)].c_str());
1349 assert(partialdec->getVarProbindexForBlock(ri, data.rootdecomposition->blocks[b].symmetricalblock) >= 0);
1350 return partialdec->getVarProbindexForBlock(ri, data.rootdecomposition->blocks[b].symmetricalblock);
1351 }
1352 );
1353 }
1354 if( !success )
1355 {
1356 SCIPwarningMessage(scip, "Could not set symmetry information.\n");
1357 }
1358 }
1359 }
1360 else
1361 SCIPwarningMessage(scip, "No root decomposition is specified.\n");
1363 }
1364 else
1365 {
1367 return SCIP_READERROR;
1368 }
1369
1370 return SCIP_OKAY;
1371}
1372
1373/* writes a jdec file for a given decomposition */
1374static
1376 GCG* gcg, /**< GCG data structure */
1377 FILE* file, /**< file pointer */
1378 gcg::PARTIALDECOMP* partialdec, /**< partialdec to be written */
1379 SCIP_RESULT* result /**< pointer to scip result */
1380 )
1381{
1382 JDecFileHandler filehandler(gcg, file);
1383
1384 if( filehandler.writeJDec(partialdec) )
1385 {
1387 }
1388 else
1389 {
1391 return SCIP_WRITEERROR;
1392 }
1393 return SCIP_OKAY;
1394}
1395
1396/*
1397 * Callback methods of reader
1398 */
1399
1400/** destructor of reader to free user data (called when SCIP is exiting) */
1401static
1403{
1404 SCIP_READERDATA* readerdata;
1405
1406 readerdata = SCIPreaderGetData(reader);
1407 assert(readerdata != NULL);
1408
1409 SCIPfreeMemory(scip, &readerdata);
1410
1411 return SCIP_OKAY;
1412}
1413
1414/** problem reading method of reader */
1415static
1417{ /*lint --e{715}*/
1418 SCIP_READERDATA* readerdata;
1419
1420 readerdata = SCIPreaderGetData(reader);
1421 assert(readerdata != NULL);
1422
1424 {
1426 "Please read in a problem before reading in the corresponding structure file!\n");
1427 return SCIP_OKAY;
1428 }
1429
1430 SCIP_CALL( readJDec(readerdata->gcg, filename, result) );
1431
1432 return SCIP_OKAY;
1433}
1434
1435/** problem writing method of reader */
1436static
1438{ /*lint --e{715}*/
1439 SCIP_READERDATA* readerdata;
1440
1441 assert(scip != NULL);
1442 assert(reader != NULL);
1443
1444 readerdata = SCIPreaderGetData(reader);
1445 assert(readerdata != NULL);
1446
1447 gcg::PARTIALDECOMP* partialdec = GCGgetPartialdecToWrite(readerdata->gcg, transformed);
1448
1449 if(partialdec == NULL) {
1450 SCIPwarningMessage(scip, "There is no writable partialdec!\n");
1451 return SCIP_OKAY;
1452 }
1453
1454 SCIP_CALL( writePartialdec(readerdata->gcg, file, partialdec, result) );
1455
1456 return SCIP_OKAY;
1457}
1458
1460 GCG* gcg
1461 )
1462{
1463 char name[SCIP_MAXSTRLEN];
1464 SCIP_READERDATA* readerdata = NULL;
1466 assert(origprob != NULL);
1467
1468 /* create dec reader data */
1469 SCIP_CALL( SCIPallocMemory(origprob, &readerdata) );
1470 readerdata->gcg = gcg;
1471
1472 /* include jdec reader */
1474 readerReadJDec, readerWriteJDec, readerdata));
1475
1476 SCIPsnprintf(name, SCIP_MAXSTRLEN, "Jansson %s", JANSSON_VERSION);
1477 SCIP_CALL( SCIPincludeExternalCodeInformation(origprob, name, "C library for encoding, decoding and manipulating JSON data (https://github.com/akheron/jansson)") );
1478
1479 return SCIP_OKAY;
1480}
SCIP_DECL_READERREAD(ReaderTSP::scip_read)
SCIP_DECL_READERWRITE(ReaderTSP::scip_write)
SCIP_DECL_READERFREE(ReaderTSP::scip_free)
SCIP_VAR ** b
~AbstractJDecDecompositionElementParser() override=default
JDecDecompositionData * parseDecomposition(json_t *value)
AbstractJDecDecompositionElementParser(GCG *gcgstruct, JDecFileHandler &filehandler)
JDecFileHandler & filehandler_
virtual ~AbstractJDecElementParser()=default
AbstractJDecElementParser(GCG *gcgstruct, JDecFileHandler &filehandler)
virtual void handleValue(json_t *value)=0
virtual void handleKeyValuePair(const char *name, json_t *value)=0
void handleValue(json_t *value) override
~JDecBlockElementParser() override=default
JDecBlockElementParser(GCG *gcgstruct, JDecFileHandler &filehandler, JDecBlockData &blockdata)
void handleKeyValuePair(const char *name, json_t *value) override
void handleKeyValuePair(const char *name, json_t *value) override
~JDecDecompositionElementParser() override=default
void handleValue(json_t *value) override
JDecDecompositionElementParser(GCG *gcgstruct, JDecFileHandler &filehandler, JDecDecompositionData &decdata)
JDecFileHandler(GCG *gcg, const char *filename)
bool parseElement(AbstractJDecElementParser &elementparser, json_t *element)
bool readJDec(JDecData &data)
bool writeJDec(PARTIALDECOMP *decomp)
~JDecRootElementParser() override=default
void handleKeyValuePair(const char *name, json_t *value) override
JDecRootElementParser(GCG *gcgstruct, JDecFileHandler &filehandler, JDecData &data)
void handleValue(json_t *value) override
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 SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
GCG_EXPORT int getIndexForVar(SCIP_VAR *var)
returns the variable index related to a SCIP variable
class to manage partial decompositions
GCG_EXPORT bool fixConsToMasterByName(const char *consname)
assgins a constraint by name as master
GCG_EXPORT int getNEquivalenceClasses()
Gets the number of blockrepresentatives.
GCG_EXPORT bool fixConsToBlockByName(const char *consname, int blockid)
assigns a constraint by name to a block
GCG_EXPORT void setNBlocks(int nblocks)
sets number of blocks, only increasing number allowed
GCG_EXPORT int getVarProbindexForBlock(int varid, int block)
Gets the index of a variable in the vector returned by PARTIALDECOMP::getVarsForBlock.
GCG_EXPORT bool setSymmetryInformation(std::function< int(int)> blockmapping, std::function< int(int, int)> varmapping)
sets symmetry information
GCG_EXPORT std::vector< int > & getMasterconss()
Gets array containing all master conss indices.
GCG_EXPORT PARTIALDECOMP(GCG *gcgstruct, bool originalProblem)
Standard constructor, creates empty partialdec with unique id.
GCG_EXPORT std::vector< int > & getConssForBlock(int block)
returns array containing constraints assigned to a block
GCG_EXPORT const std::vector< int > & getBlocksForEqClass(int eqclass)
get a vector of block ids that are contained in the equivalence class eqclass
void setBlockStructure(int block, BLOCK_STRUCTURE *blockstructure)
sets structure information of a specific block
GCG_EXPORT DETPROBDATA * getDetprobdata()
Gets the corresponding detprobdata.
GCG_EXPORT void calcAggregationInformation(bool ignoreDetectionLimits)
computes if aggregation of sub problems is possible
bool isNested()
Checks whether this is a nested decomposition.
GCG_EXPORT int getNVarsForBlock(int block)
Gets size of the vector containing vars assigned to a block.
GCG_EXPORT bool aggInfoCalculated()
Checks if the aggregation information was already calculated.
GCG_EXPORT int getEqClassForBlock(int blockid)
Gets index of the representative block for a block, this might be blockid itself.
GCG_EXPORT bool isAssignedToOrigProb()
Gets whether the partialdec is from the original problem.
GCG_EXPORT std::vector< int > & getRepVarmap(int eqclass, int eqclassblock)
Returns a vector that maps probvar indices of a block contained in an equivalence class to the probva...
GCG_EXPORT int getReprBlockForEqClass(int eqclass)
get the representative block of the given equivalence class
GCG_EXPORT int getID()
returns the unique id of the partialdec
BLOCK_STRUCTURE * getBlockStructure(int block)
Returns the structure information of a specific block.
GCG_EXPORT std::vector< int > & getVarsForBlock(int block)
Gets array containing vars of a block.
GCG_EXPORT int getNBlocks()
Gets the number of blocks.
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
C++ interface of cons_decomp.
#define SCIP_MAXSTRLEN
SCIP_FILE * SCIPfopen(const char *path, const char *mode)
int SCIPfeof(SCIP_FILE *stream)
size_t SCIPfread(void *ptr, size_t size, size_t nmemb, SCIP_FILE *stream)
int SCIPfclose(SCIP_FILE *fp)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_STAGE SCIPgetStage(SCIP *scip)
const char * SCIPgetProbName(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
int SCIPgetNConss(SCIP *scip)
SCIP_VAR * SCIPfindVar(SCIP *scip, const char *name)
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,...)
const char * SCIPconsGetName(SCIP_CONS *cons)
SCIP_RETCODE SCIPincludeExternalCodeInformation(SCIP *scip, const char *name, const char *description)
#define SCIPallocMemory(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 SCIPpresolve(SCIP *scip)
const char * SCIPvarGetName(SCIP_VAR *var)
int SCIPsnprintf(char *t, int len, const char *s,...)
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_Bool success
SCIPdebugMessage("feasibility pump finished [%d iterations done].\n", nloops)
int i
#define NULL
struct SCIP_File SCIP_FILE
#define READER_DESC
#define READER_EXTENSION
#define READER_NAME
static SCIP_RETCODE writePartialdec(GCG *gcg, FILE *file, gcg::PARTIALDECOMP *partialdec, SCIP_RESULT *result)
static constexpr bool checkVersion(int version)
SCIP_RETCODE GCGincludeReaderJDec(GCG *gcg)
#define JDEC_VERSION
static constexpr bool checkJson(int returnvalue)
static SCIP_RETCODE readJDec(GCG *gcg, const char *filename, SCIP_RESULT *result)
jdec file reader for (JSON formatted) structure information
JDecBlockData(int number)
bool operator<(const JDecBlockData &block) const
JDecBlockData(const JDecBlockData &)=delete
JDecDecompositionData * decomposition
std::vector< std::string > constraints
JDecBlockData & operator=(const JDecBlockData &)=delete
std::string description
std::string name
JDecData(const JDecData &)=delete
JDecDecompositionData * rootdecomposition
JDecData & operator=(const JDecData &)=delete
std::vector< JDecBlockData > blocks
~JDecDecompositionData()=default
std::vector< std::string > masterconstraints
std::unordered_map< std::string, std::string > symmetryvardata
BLOCK_STRUCTURE * createBlockStructure(GCG *gcg, DETPROBDATA *detprobdata)
std::vector< std::vector< int > > blockconss
std::vector< int > masterconss
std::unordered_map< int, int > symmetryvardata
std::vector< int > symmetricalblocks
std::vector< BLOCK_STRUCTURE * > blockstructures
struct Gcg GCG
Definition type_gcg.h:44
SCIP_VERBLEVEL_DIALOG
struct SCIP_ReaderData SCIP_READERDATA
SCIP_DIDNOTRUN
SCIP_SUCCESS
enum SCIP_Result SCIP_RESULT
SCIP_READERROR
SCIP_WRITEERROR
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_INIT
SCIP_STAGE_PRESOLVED
struct SCIP_Var SCIP_VAR