GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
reader_cls.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_cls.cpp
30 * @brief CLS reader for writing files containing classification data
31 * @author Michael Bastubbe
32 * @author Julius Hense
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include <assert.h>
38#include <string.h>
39#include <ctype.h>
40
41#include "gcg/reader_cls.h"
42#include "gcg/cons_decomp.h"
43#include "gcg/cons_decomp.hpp"
47
48
49#define READER_NAME "clsreader"
50#define READER_DESC "reader for writing classification data"
51#define READER_EXTENSION "cls"
52#define DEFAULT_USETRANSFORM TRUE
53
55{
56};
57
58
59
60/** data for cls reader */
61struct SCIP_ReaderData
62{
63 GCG* gcg;
65};
66
67/*
68 * Local methods
69 */
70
71
72/** write classification data */
73static
75 GCG* gcg, /**< GCG data structure */
76 FILE* file /**< File pointer to write to */
77 )
78{
79 SCIP* scip;
80 SCIP_Bool transformed;
81 gcg::DETPROBDATA* detprobdata;
82
83 assert(gcg != NULL);
84
86
88 "reading/clsreader/usetransform", &transformed));
89
91 transformed = FALSE;
92
93 if( !transformed )
95 else
97
98 if( detprobdata->conspartitioncollection.empty() )
99 {
102 }
103
104 SCIPinfoMessage(scip, file, "# a1) <number of partitions>\n" );
105 SCIPinfoMessage(scip, file, "# a2) for each partition:\n" );
106 SCIPinfoMessage(scip, file, "# b1) VAR or CONS\n" );
107 SCIPinfoMessage(scip, file, "# b2) <name of partition>\n" );
108 SCIPinfoMessage(scip, file, "# b3) <number of classes>\n" );
109 SCIPinfoMessage(scip, file, "# b4) for each class:\n" );
110 SCIPinfoMessage(scip, file, "# c1) <name of class>: <description of class>\n" );
111 SCIPinfoMessage(scip, file, "# c2) <number of class elements>\n" );
112 SCIPinfoMessage(scip, file, "# c3) for each element of class:\n" );
113 SCIPinfoMessage(scip, file, "# d1) <name of element> (e.g. variable or constraint name, concerning transformed [default] or original problem)\n" );
114 SCIPinfoMessage(scip, file, "###########################################\n" );
115
116 /* a */
117 SCIPinfoMessage(scip, file, "%d\n", (int) detprobdata->conspartitioncollection.size() + (int) detprobdata->varpartitioncollection.size() );
118
119 for( size_t c = 0; c < detprobdata->conspartitioncollection.size() ; ++c )
120 {
122
123 std::vector<std::vector<int> > conssofclasses = std::vector<std::vector<int> >(partition->getNClasses()) ;
124 for( int cons = 0; cons < detprobdata->getNConss(); ++cons )
125 conssofclasses[partition->getClassOfCons(cons)].push_back(cons);
126
127 /* b1 */
128 SCIPinfoMessage(scip, file, "CONS\n" );
129 /* b2 */
130 SCIPinfoMessage(scip, file, "%s \n", partition->getName());
131 /* b3 */
132 SCIPinfoMessage(scip, file, "%d\n", partition->getNClasses());
133 for( int cl = 0; cl < partition->getNClasses(); ++cl )
134 {
135 /* c1 */
137 /* c2 */
138 SCIPinfoMessage(scip, file, "%ld\n", conssofclasses[cl].size());
139 /* c3 */
140 for( size_t clm = 0; clm < conssofclasses[cl].size(); ++clm )
141 {
142 SCIPinfoMessage(scip, file, "%s\n", SCIPconsGetName(detprobdata->getCons(conssofclasses[cl][clm])));
143 }
144 }
145 }
146
147
148 for( size_t c = 0; c < detprobdata->varpartitioncollection.size() ; ++c )
149 {
151
152 std::vector<std::vector<int> > varsofclasses = std::vector<std::vector<int> >(partition->getNClasses()) ;
153 for( int var = 0; var < detprobdata->getNVars(); ++var )
154 varsofclasses[partition->getClassOfVar(var)].push_back(var);
155
156 /* b1 */
157 SCIPinfoMessage(scip, file, "VAR\n" );
158 /* b2 */
159 SCIPinfoMessage(scip, file, "%s \n", partition->getName());
160 /* b3 */
161 SCIPinfoMessage(scip, file, "%d\n", partition->getNClasses() );
162 for( int cl = 0; cl < partition->getNClasses(); ++cl )
163 {
164 /* c1 */
166 /* c2 */
167 SCIPinfoMessage(scip, file, "%d\n", partition->getNVarsOfClasses()[cl] );
168 /* c3 */
169 for( size_t clm = 0; clm <varsofclasses[cl].size(); ++clm )
170 {
171 SCIPinfoMessage(scip, file, "%s\n", SCIPvarGetName(detprobdata->getVar(varsofclasses[cl][clm])));
172 }
173 }
174 }
175
176
177 return SCIP_OKAY;
178}
179
180
181/*
182 * Callback methods of reader
183 */
184
185#define readerCopyCls NULL
186
187/** destructor of reader to free user data (called when SCIP is exiting) */
188static
190{
191 SCIP_READERDATA* readerdata;
192
193 readerdata = SCIPreaderGetData( reader );
194 assert( readerdata != NULL );
195
196 SCIPfreeMemory( scip, &readerdata );
197
198 assert( strcmp( SCIPreaderGetName( reader ), READER_NAME ) == 0);
199 return SCIP_OKAY;
200}
201
202/** problem reading method of reader */
203#define readerReadCls NULL
204
205/** problem writing method of reader */
206static
208{
209 /*lint --e{715}*/
210 SCIP_READERDATA* readerdata;
211
212 readerdata = SCIPreaderGetData( reader );
213 assert( readerdata != NULL );
214 SCIP_CALL( writeCls( readerdata->gcg, file ) );
215
217 return SCIP_OKAY;
218}
219
220
221/** includes the cls reader into SCIP */
223 GCG* gcg /**< GCG data structure */
224 )
225{
226 SCIP_READERDATA* readerdata = NULL;
228 assert(origprob != NULL);
229
230 /* create cls reader data */
231 SCIP_CALL( SCIPallocMemory(origprob, &readerdata) );
232 readerdata->gcg = gcg;
233
234 /* include cls reader */
236 readerCopyCls, readerFreeCls, readerReadCls, readerWriteCls, readerdata) );
237
239 "reading/clsreader/usetransform",
240 "should the transformed (and possibly presolved problem) be use or original one",
241 &readerdata->usetransform, FALSE, DEFAULT_USETRANSFORM, NULL, NULL) );
242
243
244 return SCIP_OKAY;
245}
SCIP_DECL_READERWRITE(ReaderTSP::scip_write)
SCIP_DECL_READERFREE(ReaderTSP::scip_free)
static SCIP_RETCODE partition(SCIP *scip, SCIP_VAR **J, int *Jsize, SCIP_Longint *priority, SCIP_VAR **F, int Fsize, SCIP_VAR **origvar, SCIP_Real *median)
class representing a partition of a set of constraints
class storing partialdecs and the problem matrix
class representing a partition of a set of variables
GCG_EXPORT int getClassOfCons(int consindex)
GCG_EXPORT int getNConss()
returns the number of variables considered in the detprobdata
GCG_EXPORT int getNVars()
return the number of variables considered in the detprobdata
GCG_EXPORT SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
std::vector< ConsPartition * > conspartitioncollection
std::vector< VarPartition * > varpartitioncollection
GCG_EXPORT SCIP_CONS * getCons(int consIndex)
returns the SCIP constraint related to a constraint index
GCG_EXPORT SCIP_Bool isAssignedToOrigProb()
returns true if the matrix structure corresponds to the presolved problem
GCG_EXPORT const char * getClassName(int classindex)
GCG_EXPORT const char * getName()
GCG_EXPORT const char * getClassDescription(int classindex)
GCG_EXPORT int getClassOfVar(int varindex)
GCG_EXPORT std::vector< int > getNVarsOfClasses()
SCIP_RETCODE GCGconshdlrDecompClassify(GCG *gcg, SCIP_Bool transformed)
run classification of vars and cons
void GCGconshdlrDecompCalcCandidatesNBlocks(GCG *gcg, SCIP_Bool transformed)
calculates and adds block size candidates using constraint classifications and variable classificatio...
DETPROBDATA * GCGconshdlrDecompGetDetprobdataPresolved(GCG *gcg)
help method to access detprobdata for transformed problem
DETPROBDATA * GCGconshdlrDecompGetDetprobdataOrig(GCG *gcg)
help method to access detprobdata for unpresolved problem
constraint handler for structure detection
C++ interface of cons_decomp.
#define SCIP_Bool
#define FALSE
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
SCIP_STAGE SCIPgetStage(SCIP *scip)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
const char * SCIPconsGetName(SCIP_CONS *cons)
#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)
const char * SCIPreaderGetName(SCIP_READER *reader)
const char * SCIPvarGetName(SCIP_VAR *var)
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
#define NULL
#define READER_DESC
#define READER_EXTENSION
#define READER_NAME
static SCIP_RETCODE writeCls(GCG *gcg, FILE *file)
#define readerReadCls
#define readerCopyCls
#define DEFAULT_USETRANSFORM
SCIP_RETCODE GCGincludeReaderCls(GCG *gcg)
CLS reader for writing files containing classification data.
SCIP_Bool usetransform
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_ReaderData SCIP_READERDATA
SCIP_SUCCESS
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
SCIP_STAGE_TRANSFORMED