GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
clscons_consnamenonumbers.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 clscons_consnamenonumbers.cpp
30 *
31 * @brief classifies constraints according to names (without digits)
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 CLSCONS_NAME "consnamenonumbers" /**< name of classifier */
50#define CLSCONS_DESC "constraint names (remove digits; check for identity)" /**< short description of classification*/
51#define CLSCONS_PRIORITY 0
52
53#define CLSCONS_ENABLED FALSE
54
55
56/*
57 * Data structures
58 */
59
60/** classifier handler data */
62{
63};
64
65
66/*
67 * Local methods
68 */
69
70/* put your local methods here, and declare them static */
71
72
73/*
74 * classifier callback methods
75 */
76
77/** destructor of classifier to free user data (called when GCG is exiting) */
78#define classifierFree NULL
79
80/** removes all digits from string str */
82 char *str,
83 int *nremoved
84)
85{
86 char digits[11] = "0123456789";
87 * nremoved = 0;
88
89 for( int i = 0; i < 10; ++ i )
90 {
91 char digit = digits[i];
92 size_t j = 0;
93 while( j < strlen( str ) )
94 {
95 if( str[j] == digit )
96 {
97 * nremoved = * nremoved + 1;
98 for( size_t k = j; k < strlen( str ); ++ k )
99 {
100 str[k] = str[k + 1];
101 }
102 }
103 else
104 ++ j;
105 }
106 }
107}
108
109
110static
111GCG_DECL_CONSCLASSIFY(classifierClassify) {
112 gcg::DETPROBDATA* detprobdata;
114
115 if( transformed )
116 {
118 }
119 else
120 {
122 }
123
124 std::vector < std::string > consnamesToCompare( detprobdata->getNConss(), "" );
125 std::vector<int> nConssConstype( 0 );
126 std::vector<int> classForCons = std::vector<int>( detprobdata->getNConss(), - 1 );
127 std::vector < std::string > nameClasses( 0 );
128 gcg::ConsPartition* classifier;
129
130 /* firstly, remove all digits from the consnames */
131 for( int i = 0; i < detprobdata->getNConss(); ++ i )
132 {
133 int nremoved;
134 char consname[SCIP_MAXSTRLEN];
135 strcpy(consname, SCIPconsGetName(detprobdata->getCons(i)));
136
137 removeDigits(consname, &nremoved);
138 consnamesToCompare[i] = std::string(consname);
139 }
140
141 for( int i = 0; i < detprobdata->getNConss(); ++ i )
142 {
143 /* check if string belongs to an existing name class */
144 bool belongstoexistingclass = false;
145
146 for( size_t j = 0; j < nameClasses.size(); ++ j )
147 {
148 if( nameClasses[j] == consnamesToCompare[i] )
149 {
150 belongstoexistingclass = true;
151 classForCons[i] = (int) j;
152 nConssConstype[j] ++;
153 break;
154 }
155 }
156 /* if not, create a new class */
157 if( !belongstoexistingclass )
158 {
159 nameClasses.push_back(consnamesToCompare[i]);
160 nConssConstype.push_back(1);
161 classForCons[i] = (int) nameClasses.size() - 1;
162 }
163 }
164
165 /* secondly, use these information to create a ConsPartition */
166 classifier = new gcg::ConsPartition(gcg, "consnames", (int) nameClasses.size(), detprobdata->getNConss());
167
168 /* set all class names and descriptions */
169 for( int c = 0; c < classifier->getNClasses(); ++ c )
170 {
171 std::stringstream text;
172 classifier->setClassName(c, nameClasses[c].c_str());
173 text << "This class contains all constraints with name \"" << nameClasses[c] << "\".";
174 classifier->setClassDescription(c, text.str().c_str());
175 }
176
177 /* copy the constraint assignment information found in first step */
178 for( int i = 0; i < classifier->getNConss(); ++ i )
179 {
180 classifier->assignConsToClass(i, classForCons[i]);
181 }
182
183 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, " Consclassifier \"%s\" yields a classification with %d different constraint classes \n", classifier->getName(), classifier->getNClasses());
184
185 detprobdata->addConsPartition(classifier);
186 return SCIP_OKAY;
187}
188
189/*
190 * classifier specific interface methods
191 */
192
194 GCG* gcg /**< GCG data structure */
195) {
196 GCG_CLASSIFIERDATA* classifierdata = NULL;
197
198 SCIP_CALL(
200 classifierFree, classifierClassify));
201
202 return SCIP_OKAY;
203}
class representing a partition of a set of constraints
class storing partialdecs and the problem matrix
GCG_EXPORT void assignConsToClass(int consindex, int classindex)
GCG_EXPORT int getNConss()
returns the number of variables considered in the detprobdata
GCG_EXPORT void addConsPartition(ConsPartition *partition)
adds a constraint partition if it is no duplicate of an existing constraint partition
GCG_EXPORT SCIP_CONS * getCons(int consIndex)
returns the SCIP constraint related to a constraint index
GCG_EXPORT const char * getName()
GCG_EXPORT void setClassDescription(int classindex, const char *desc)
GCG_EXPORT void setClassName(int classindex, const char *name)
#define CLSCONS_DESC
#define classifierFree
#define CLSCONS_NAME
#define CLSCONS_ENABLED
#define CLSCONS_PRIORITY
SCIP_RETCODE GCGincludeConsClassifierForConsnamesDigitFreeIdentical(GCG *gcg)
void removeDigits(char *str, int *nremoved)
classifies constraints according to names (without digits)
DETPROBDATA * GCGconshdlrDecompGetDetprobdataPresolved(GCG *gcg)
help method to access detprobdata for transformed problem
DETPROBDATA * GCGconshdlrDecompGetDetprobdataOrig(GCG *gcg)
help method to access detprobdata for unpresolved problem
SCIP_RETCODE GCGincludeConsClassifier(GCG *gcg, const char *name, const char *description, int priority, SCIP_Bool enabled, GCG_CLASSIFIERDATA *classifierdata, GCG_DECL_FREECONSCLASSIFIER((*freeClassifier)),)
includes one constraint classifier
constraint handler for structure detection
C++ interface of cons_decomp.
#define SCIP_MAXSTRLEN
SCIP * GCGgetOrigprob(GCG *gcg)
Definition gcg.cpp:87
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
const char * SCIPconsGetName(SCIP_CONS *cons)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP * origprob
int j
int i
#define NULL
various SCIP helper methods
struct GCG_ClassifierData GCG_CLASSIFIERDATA
#define GCG_DECL_CONSCLASSIFY(x)
struct Gcg GCG
Definition type_gcg.h:44
SCIP_VERBLEVEL_HIGH
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP