Scippy

GCG

Branch-and-Price & Column Generation for Everyone

clscons_scipconstypes.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_scipconstypes.cpp
30 *
31 * @brief classifies constraints according to their scip constypes
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 "scipconstype" /**< name of classifier */
50#define CLSCONS_DESC "scip constypes" /**< short description of classification*/
51#define CLSCONS_PRIORITY 0
52
53#define CLSCONS_ENABLED TRUE
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
80static
81GCG_DECL_CONSCLASSIFY(classifierClassify) {
82 gcg::DETPROBDATA *detprobdata;
83 SCIP* origprob = GCGgetOrigprob(gcg);
84 if( transformed )
85 {
87 }
88 else
89 {
91 }
92
93 std::vector<consType> foundConstypes(0);
94 std::vector<int> constypesIndices(0);
95 std::vector<int> classForCons = std::vector<int>(detprobdata->getNConss(), -1);
96 gcg::ConsPartition *classifier;
97
98 /* firstly, assign all constraints to classindices */
99 for (int i = 0; i < detprobdata->getNConss(); ++i) {
100 SCIP_CONS *cons;
101 bool found = false;
102 cons = detprobdata->getCons(i);
103 consType cT = GCGconsGetType(origprob, cons);
104 size_t constype;
105
106 /* check whether the constraint's constype is new */
107 for (constype = 0; constype < foundConstypes.size(); ++constype) {
108 if (foundConstypes[constype] == cT) {
109 found = true;
110 break;
111 }
112 }
113 /* if it is new, create a new classindex */
114 if (!found) {
115 foundConstypes.push_back(GCGconsGetType(origprob, cons));
116 classForCons[i] = (int) foundConstypes.size() - 1;
117 } else
118 classForCons[i] = (int) constype;
119 }
120
121 /* secondly, use these information to create a ConsPartition */
122 classifier = new gcg::ConsPartition(gcg, "constypes", (int) foundConstypes.size(), detprobdata->getNConss());
123
124 /* set class names and descriptions of every class */
125 for (int c = 0; c < classifier->getNClasses(); ++c) {
126 std::string name;
127 std::stringstream text;
128 switch (foundConstypes[c]) {
129 case linear:
130 name = "linear";
131 break;
132 case knapsack:
133 name = "knapsack";
134 break;
135 case varbound:
136 name = "varbound";
137 break;
138 case setpacking:
139 name = "setpacking";
140 break;
141 case setcovering:
142 name = "setcovering";
143 break;
144 case setpartitioning:
145 name = "setpartitioning";
146 break;
147 case logicor:
148 name = "logicor";
149 break;
150 case sos1:
151 name = "sos1";
152 break;
153 case sos2:
154 name = "sos2";
155 break;
156 case unknown:
157 name = "unknown";
158 break;
159 case nconsTypeItems:
160 name = "nconsTypeItems";
161 break;
162 default:
163 name = "newConstype";
164 break;
165 }
166 classifier->setClassName(c, name.c_str());
167 text << "This class contains all constraints that are of (SCIP) constype \"" << name << "\".";
168 classifier->setClassDescription(c, text.str().c_str());
169 }
170
171 /* copy the constraint assignment information found in first step */
172 for (int i = 0; i < classifier->getNConss(); ++i) {
173 classifier->assignConsToClass(i, classForCons[i]);
174 }
175
177 " Consclassifier \"%s\" yields a classification with %d different constraint classes \n",
178 classifier->getName(), (int) foundConstypes.size());
179
180 detprobdata->addConsPartition(classifier);
181 return SCIP_OKAY;
182}
183
184/*
185 * classifier specific interface methods
186 */
187
188/** creates the handler for XYZ classifier and includes it in SCIP */
190 GCG* gcg /**< GCG data structure */
191 )
192{
193 GCG_CLASSIFIERDATA* classifierdata = NULL;
194
195 SCIP_CALL(
197 classifierFree, classifierClassify));
198
199 return SCIP_OKAY;
200}
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()
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 int getNClasses()
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
static GCG_DECL_CONSCLASSIFY(classifierClassify)
SCIP_RETCODE GCGincludeConsClassifierScipConstypes(GCG *gcg)
classifies constraints according to their scip constypes
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)),)
constraint handler for structure detection
C++ interface of cons_decomp.
#define SCIP_CALL(x)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
consType GCGconsGetType(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:52
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
#define NULL
various SCIP helper methods
consType
Definition: scip_misc.h:49
@ setcovering
Definition: scip_misc.h:50
@ nconsTypeItems
Definition: scip_misc.h:51
@ linear
Definition: scip_misc.h:50
@ unknown
Definition: scip_misc.h:51
@ sos2
Definition: scip_misc.h:51
@ sos1
Definition: scip_misc.h:51
@ varbound
Definition: scip_misc.h:50
@ setpartitioning
Definition: scip_misc.h:50
@ setpacking
Definition: scip_misc.h:50
@ logicor
Definition: scip_misc.h:51
@ knapsack
Definition: scip_misc.h:50
Definition: struct_gcg.h:55
SCIP_VERBLEVEL_HIGH
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE