reader_jdec.cpp
Go to the documentation of this file.
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
134 std::vector<std::string> masterconstraints; /**< vector containing names of master constraints */
136 std::unordered_map<std::string, std::string> symmetryvardata; /**< symmetry mapping for variables: name of variable -> name of its representative variable */
139/** struct that stores the metadata of the read decomposition and a pointer to the actual decomposition */
188 * reads a jdec file an stores the information in a data object, returns a bool indicating success/failure
197 * writes a partialldec to a jdec file, returns a bool indicating success/failure, returns a bool indicating success/failure
209 /** serializes a specific block of a partialdec and puts it into an existing json object, returns a bool indicating success/failure */
216 /** serializes a block structure and puts it into an existing json object, returns a bool indicating success/failure */
223 /** serializes a block of a block structure and puts it into an existing json object, returns a bool indicating success/failure */
231 /** serializes a partialdec and puts it into an existing json object, returns a bool indicating success/failure */
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 */
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) */
249 bool decref = true /**< should the reference counter of the value json struct be decreased? (see JANSSON API documentation) */
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 */
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 */
325 /** parses/deserializes the decomposition contained by a json object and returns the created decomposition data*/
397 JDecDecompositionData& decdata_; /**< decomposition data struct used to store the parsed data */
485 SCIPwarningMessage(scip, "Decomposition of blocks must not belong to a presolved model, ignoring this flag.\n");
507 blockstructure->blockstructures.push_back(blockdata.decomposition->createBlockStructure(gcg, detprobdata));
543 SCIPwarningMessage(scip, "Got invalid variable mapping: <%s> -> <%s>.\n", it.first.c_str(), it.second.c_str());
730 success &= setObjectValue("symmetry_representative_block", json_integer(decomp->getReprBlockForEqClass(decomp->getEqClassForBlock(block))), json);
854 success &= setObjectValue(SCIPvarGetName(var), json_string(SCIPvarGetName(repvar)), jsonsymmetry);
939 SCIPinfoMessage(filehandler->scip, filehandler->wfile_, "%.*s", (SCIP_MAXSTRLEN - 1), &buffer[pos]);
942 SCIPinfoMessage(filehandler->scip, filehandler->wfile_, "%.*s", (int)(buflen - pos), &buffer[pos]);
1192 SCIPwarningMessage(scip, "Could not parse block number of representative block (symmetry).\n");
1290 BLOCK_STRUCTURE* nestedstructure = blockdata.decomposition->createBlockStructure(gcg, detprobdata);
1323 partialdec->getVarProbindexForBlock(detprobdata->getIndexForVar(reprvar), symmetricalblock) >= 0);
1349 assert(partialdec->getVarProbindexForBlock(ri, data.rootdecomposition->blocks[b].symmetricalblock) >= 0);
1350 return partialdec->getVarProbindexForBlock(ri, data.rootdecomposition->blocks[b].symmetricalblock);
1423 if( SCIPgetStage(scip) == SCIP_STAGE_INIT || SCIPgetNVars(scip) == 0 || SCIPgetNConss(scip) == 0 )
1473 SCIP_CALL(SCIPincludeReader(origprob, READER_NAME, READER_DESC, READER_EXTENSION, NULL, readerFreeJDec,
1477 SCIP_CALL( SCIPincludeExternalCodeInformation(origprob, name, "C library for encoding, decoding and manipulating JSON data (https://github.com/akheron/jansson)") );
SCIP_VAR ** b
~AbstractJDecDecompositionElementParser() override=default
JDecDecompositionData * parseDecomposition(json_t *value)
Definition: reader_jdec.cpp:949
AbstractJDecDecompositionElementParser(GCG *gcgstruct, JDecFileHandler &filehandler)
Definition: reader_jdec.cpp:316
Definition: reader_jdec.cpp:276
JDecFileHandler & filehandler_
Definition: reader_jdec.cpp:305
virtual ~AbstractJDecElementParser()=default
AbstractJDecElementParser(GCG *gcgstruct, JDecFileHandler &filehandler)
Definition: reader_jdec.cpp:279
virtual void handleValue(json_t *value)=0
virtual void handleKeyValuePair(const char *name, json_t *value)=0
Definition: reader_jdec.cpp:333
void handleValue(json_t *value) override
Definition: reader_jdec.cpp:1228
~JDecBlockElementParser() override=default
JDecBlockElementParser(GCG *gcgstruct, JDecFileHandler &filehandler, JDecBlockData &blockdata)
Definition: reader_jdec.cpp:336
void handleKeyValuePair(const char *name, json_t *value) override
Definition: reader_jdec.cpp:1166
void handleKeyValuePair(const char *name, json_t *value) override
Definition: reader_jdec.cpp:1025
~JDecDecompositionElementParser() override=default
void handleValue(json_t *value) override
Definition: reader_jdec.cpp:1131
JDecDecompositionElementParser(GCG *gcgstruct, JDecFileHandler &filehandler, JDecDecompositionData &decdata)
Definition: reader_jdec.cpp:370
Definition: reader_jdec.cpp:164
JDecFileHandler(GCG *gcg, const char *filename)
Definition: reader_jdec.cpp:560
bool parseElement(AbstractJDecElementParser &elementparser, json_t *element)
Definition: reader_jdec.cpp:608
Definition: reader_jdec.cpp:405
~JDecRootElementParser() override=default
void handleKeyValuePair(const char *name, json_t *value) override
Definition: reader_jdec.cpp:960
JDecRootElementParser(GCG *gcgstruct, JDecFileHandler &filehandler, JDecData &data)
Definition: reader_jdec.cpp:408
void handleValue(json_t *value) override
Definition: reader_jdec.cpp:1019
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
Definition: class_detprobdata.h:110
GCG_EXPORT int getIndexForCons(SCIP_CONS *cons)
returns the constraint index related to a SCIP constraint
Definition: class_detprobdata.cpp:792
GCG_EXPORT SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
Definition: class_detprobdata.cpp:1015
GCG_EXPORT int getIndexForVar(SCIP_VAR *var)
returns the variable index related to a SCIP variable
Definition: class_detprobdata.cpp:829
GCG_EXPORT bool fixConsToMasterByName(const char *consname)
assgins a constraint by name as master
Definition: class_partialdecomp.cpp:5673
GCG_EXPORT int getNEquivalenceClasses()
Gets the number of blockrepresentatives.
Definition: class_partialdecomp.cpp:4515
GCG_EXPORT bool fixConsToBlockByName(const char *consname, int blockid)
assigns a constraint by name to a block
Definition: class_partialdecomp.cpp:5639
GCG_EXPORT void setNBlocks(int nblocks)
sets number of blocks, only increasing number allowed
Definition: class_partialdecomp.cpp:5350
GCG_EXPORT int getVarProbindexForBlock(int varid, int block)
Gets the index of a variable in the vector returned by PARTIALDECOMP::getVarsForBlock.
Definition: class_partialdecomp.cpp:4780
GCG_EXPORT bool setSymmetryInformation(std::function< int(int)> blockmapping, std::function< int(int, int)> varmapping)
sets symmetry information
Definition: class_partialdecomp.cpp:5929
GCG_EXPORT std::vector< int > & getMasterconss()
Gets array containing all master conss indices.
Definition: class_partialdecomp.cpp:4286
GCG_EXPORT std::vector< int > & getConssForBlock(int block)
returns array containing constraints assigned to a block
Definition: class_partialdecomp.cpp:3968
GCG_EXPORT const std::vector< int > & getBlocksForEqClass(int eqclass)
get a vector of block ids that are contained in the equivalence class eqclass
Definition: class_partialdecomp.cpp:3868
void setBlockStructure(int block, BLOCK_STRUCTURE *blockstructure)
sets structure information of a specific block
Definition: class_partialdecomp.cpp:5378
GCG_EXPORT DETPROBDATA * getDetprobdata()
Gets the corresponding detprobdata.
Definition: class_partialdecomp.cpp:4725
GCG_EXPORT void calcAggregationInformation(bool ignoreDetectionLimits)
computes if aggregation of sub problems is possible
Definition: class_partialdecomp.cpp:1270
bool isNested()
Checks whether this is a nested decomposition.
Definition: class_partialdecomp.cpp:4957
GCG_EXPORT int getNVarsForBlock(int block)
Gets size of the vector containing vars assigned to a block.
Definition: class_partialdecomp.cpp:4537
GCG_EXPORT bool aggInfoCalculated()
Checks if the aggregation information was already calculated.
Definition: class_partialdecomp.cpp:5902
GCG_EXPORT int getEqClassForBlock(int blockid)
Gets index of the representative block for a block, this might be blockid itself.
Definition: class_partialdecomp.cpp:4707
GCG_EXPORT bool isAssignedToOrigProb()
Gets whether the partialdec is from the original problem.
Definition: class_partialdecomp.cpp:4835
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...
Definition: class_partialdecomp.cpp:4715
GCG_EXPORT int getReprBlockForEqClass(int eqclass)
get the representative block of the given equivalence class
Definition: class_partialdecomp.cpp:3875
GCG_EXPORT int getID()
returns the unique id of the partialdec
Definition: class_partialdecomp.cpp:4255
BLOCK_STRUCTURE * getBlockStructure(int block)
Returns the structure information of a specific block.
Definition: class_partialdecomp.cpp:4319
GCG_EXPORT std::vector< int > & getVarsForBlock(int block)
Gets array containing vars of a block.
Definition: class_partialdecomp.cpp:4771
PARTIALDECOMP * GCGgetPartialdecToWrite(GCG *gcg, SCIP_Bool transformed)
Definition: cons_decomp.cpp:2441
SCIP_RETCODE GCGconshdlrDecompAddPreexisitingPartialDec(GCG *gcg, PARTIALDECOMP *partialdec)
adds a preexisting partial dec to be considered at the beginning of the detection
Definition: cons_decomp.cpp:3133
C++ interface of cons_decomp.
#define SCIP_MAXSTRLEN
#define SCIP_CALL(x)
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_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)
#define SCIPfreeMemory(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,...)
#define NULL
Definition: class_conspartition.cpp:44
struct SCIP_File SCIP_FILE
#define SCIPdebugMessage
static SCIP_RETCODE writePartialdec(GCG *gcg, FILE *file, gcg::PARTIALDECOMP *partialdec, SCIP_RESULT *result)
Definition: reader_jdec.cpp:1375
static SCIP_RETCODE readJDec(GCG *gcg, const char *filename, SCIP_RESULT *result)
Definition: reader_jdec.cpp:1248
jdec file reader for (JSON formatted) structure information
Definition: struct_gcg.h:55
Definition: reader_jdec.cpp:79
bool operator<(const JDecBlockData &block) const
Definition: reader_jdec.cpp:462
JDecBlockData(const JDecBlockData &)=delete
JDecBlockData & operator=(const JDecBlockData &)=delete
Definition: reader_jdec.cpp:141
JDecData(const JDecData &)=delete
JDecData & operator=(const JDecData &)=delete
Definition: reader_jdec.cpp:120
~JDecDecompositionData()=default
std::vector< std::string > masterconstraints
Definition: reader_jdec.cpp:134
std::unordered_map< std::string, std::string > symmetryvardata
Definition: reader_jdec.cpp:136
BLOCK_STRUCTURE * createBlockStructure(GCG *gcg, DETPROBDATA *detprobdata)
Definition: reader_jdec.cpp:474
Definition: reader_blk.cpp:112
Definition: class_partialdecomp.h:82
std::vector< std::vector< int > > blockconss
Definition: class_partialdecomp.h:104
std::vector< int > masterconss
Definition: class_partialdecomp.h:103
std::unordered_map< int, int > symmetryvardata
Definition: class_partialdecomp.h:107
std::vector< int > symmetricalblocks
Definition: class_partialdecomp.h:106
std::vector< BLOCK_STRUCTURE * > blockstructures
Definition: class_partialdecomp.h:105
SCIP_VERBLEVEL_DIALOG
SCIP_DIDNOTRUN
SCIP_SUCCESS
enum SCIP_Result SCIP_RESULT
SCIP_READERROR
SCIP_WRITEERROR
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
SCIP_STAGE_INIT
SCIP_STAGE_PRESOLVED