GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
clsvar_scipvartypes.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 clsvar_scipvartypes.cpp
30 *
31 * @brief classifies variables according to their scip vartypes
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
37#include "gcg/cons_decomp.h"
38#include "gcg/cons_decomp.hpp"
39#include <vector>
40#include <stdio.h>
41#include <sstream>
42
44
46#include "gcg/scip_misc.h"
47
48/* classifier properties */
49#define CLSVAR_NAME "scipvartype" /**< name of classifier */
50#define CLSVAR_DESC "scipvartypes" /**< short description of classification*/
51#define CLSVAR_PRIORITY 0
52
53#define CLSVAR_ENABLED TRUE
54
55
56/*
57 * Data structures
58 */
59
60/** classifier handler data */
62{
63};
64
65/* local enum of possible classes considered by this classifier */
74
75
76/*
77 * Local methods
78 */
79
80/* put your local methods here, and declare them static */
81
82
83/*
84 * classifier callback methods
85 */
86
87/** destructor of classifier to free user data (called when GCG is exiting) */
88#define classifierFree NULL
89
90static
91GCG_DECL_VARCLASSIFY(classifierClassify)
92{
93 gcg::DETPROBDATA* detprobdata;
96 if( transformed )
97 {
99 }
100 else
101 {
103 }
104
105 // CLASSIFICATION
106 std::vector<GCG_CLSVAR_VARTYPE_CLASS> foundVartypes;
107 std::vector<int> classForVars(detprobdata->getNVars(), -1);
108 gcg::VarPartition* classifier;
109
110 SCIP_Bool onlycontsub;
111 SCIP_Bool onlybinmaster;
112
113 SCIPgetBoolParam(origprob, "detection/benders/onlycontsubpr", &onlycontsub);
114 SCIPgetBoolParam(origprob, "detection/benders/onlybinmaster", &onlybinmaster);
115
116 /* firstly, assign all variables to classindices */
117 for( int i = 0; i < detprobdata->getNVars(); ++ i )
118 {
119 SCIP_VAR* var;
120 bool found = false;
121 var = detprobdata->getVar(i);
124 size_t j;
125
126 if( onlycontsub )
127 {
128 if ( vt == SCIP_VARTYPE_BINARY )
130 }
131
132 switch( vt )
133 {
136 break;
139 break;
141 if( onlycontsub || SCIPvarGetImplType(var) == SCIP_IMPLINTTYPE_NONE )
143 else
145 break;
146 default:
148 SCIPwarningMessage(origprob, "Encountered unknown variable type: %d.\n", vt);
149 break;
150 }
151
152 /* check whether the variable's vartype is new */
153 for( j = 0; j < foundVartypes.size(); ++ j )
154 {
155 if( foundVartypes[j] == vtc )
156 {
157 found = true;
158 break;
159 }
160 }
161 /* if it is new, create a new class index */
162 if( !found )
163 {
164 foundVartypes.push_back(vtc);
165 classForVars[i] = (int) foundVartypes.size() - 1;
166 }
167 else
168 classForVars[i] = (int) j;
169 }
170
171 /* secondly, use these information to create a VarPartition */
172 classifier = new gcg::VarPartition(gcg, "vartypes", (int) foundVartypes.size(), detprobdata->getNVars() );
173
174 /* set class names and descriptions of every class */
175 for( int c = 0; c < classifier->getNClasses(); ++ c )
176 {
177 std::string name;
178 std::stringstream text;
179 switch( foundVartypes[c] )
180 {
182 name = "bin";
183 if( onlybinmaster )
184 classifier->setClassDecompInfo(c, gcg::LINKING);
185 break;
187 name = "int";
188 if( onlycontsub )
189 classifier->setClassDecompInfo(c, gcg::LINKING);
190 if( onlybinmaster )
191 classifier->setClassDecompInfo(c, gcg::BLOCK);
192 break;
194 name = "impl";
195 if( onlybinmaster )
196 classifier->setClassDecompInfo(c, gcg::BLOCK);
197 break;
199 name = "cont";
200 if( onlycontsub )
201 classifier->setClassDecompInfo(c, gcg::BLOCK);
202 if( onlybinmaster )
203 classifier->setClassDecompInfo(c, gcg::BLOCK);
204 break;
205 default:
206 name = "newVartype";
207 break;
208 }
209 classifier->setClassName(c, name.c_str());
210 text << "This class contains all variables that are of (SCIP) vartype \"" << name << "\".";
211 classifier->setClassDescription(c, text.str().c_str());
212 }
213
214 /* copy the variable assignment information found in first step */
215 for( int i = 0; i < classifier->getNVars(); ++ i )
216 {
217 classifier->assignVarToClass(i, classForVars[i]);
218 }
219
220 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, " Varclassifier \"%s\" yields a classification with %d different variable classes\n", classifier->getName(), classifier->getNClasses()) ;
221
222 detprobdata->addVarPartition(classifier);
223 return SCIP_OKAY;
224}
225
226/*
227 * classifier specific interface methods
228 */
229
231 GCG* gcg /**< GCG data structure */
232 )
233{
234 GCG_CLASSIFIERDATA* classifierdata = NULL;
235
237
238 return SCIP_OKAY;
239}
class storing partialdecs and the problem matrix
class representing a partition of a set of variables
GCG_EXPORT int getNVars()
return the number of variables considered in the detprobdata
GCG_EXPORT void addVarPartition(VarPartition *partition)
adds a variable partition if it is no duplicate of an existing variable partition
GCG_EXPORT SCIP_VAR * getVar(int varIndex)
returns SCIP variable related to a variable index
GCG_EXPORT const char * getName()
GCG_EXPORT void setClassDescription(int classindex, const char *desc)
GCG_EXPORT void setClassName(int classindex, const char *name)
GCG_EXPORT void setClassDecompInfo(int classindex, VAR_DECOMPINFO decompInfo)
GCG_EXPORT void assignVarToClass(int varindex, int classindex)
GCG_EXPORT int getNVars()
#define classifierFree
#define CLSVAR_ENABLED
#define CLSVAR_NAME
#define CLSVAR_PRIORITY
#define CLSVAR_DESC
SCIP_RETCODE GCGincludeVarClassifierScipVartypes(GCG *gcg)
GCG_CLSVAR_VARTYPE_CLASS
@ GCG_CLSVAR_VARTYPE_CLASS_CONTINUOUS
@ GCG_CLSVAR_VARTYPE_CLASS_UNKNOWN
@ GCG_CLSVAR_VARTYPE_CLASS_BINARY
@ GCG_CLSVAR_VARTYPE_CLASS_INTEGER
@ GCG_CLSVAR_VARTYPE_CLASS_CONTINUOUS_IMPLINT
classifies variables according to their scip vartypes
DETPROBDATA * GCGconshdlrDecompGetDetprobdataPresolved(GCG *gcg)
help method to access detprobdata for transformed problem
SCIP_RETCODE GCGincludeVarClassifier(GCG *gcg, const char *name, const char *description, int priority, SCIP_Bool enabled, GCG_CLASSIFIERDATA *classifierdata, GCG_DECL_FREEVARCLASSIFIER((*freeClassifier)),)
includes one variable classifier
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
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPgetBoolParam(SCIP *scip, const char *name, SCIP_Bool *value)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIP_IMPLINTTYPE SCIPvarGetImplType(SCIP_VAR *var)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
SCIP_VAR * var
int j
int i
#define NULL
various SCIP helper methods
struct GCG_ClassifierData GCG_CLASSIFIERDATA
struct Gcg GCG
Definition type_gcg.h:44
SCIP_VERBLEVEL_HIGH
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Var SCIP_VAR
SCIP_IMPLINTTYPE_NONE
SCIP_VARTYPE_INTEGER
SCIP_VARTYPE_CONTINUOUS
SCIP_VARTYPE_BINARY
enum SCIP_Vartype SCIP_VARTYPE
#define GCG_DECL_VARCLASSIFY(x)