Scippy

GCG

Branch-and-Price & Column Generation for Everyone

clsvar_objvalues.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_objvalues.cpp
30 *
31 * @brief classifies variables according to their objective function values
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#include <iomanip>
43
45
47#include "gcg/scip_misc.h"
48
49/* classifier properties */
50#define CLSVAR_NAME "objectivevalues" /**< name of classifier */
51#define CLSVAR_DESC "objective function values" /**< short description of classification*/
52#define CLSVAR_PRIORITY 0
53
54#define CLSVAR_ENABLED TRUE
55
56
57/*
58 * Data structures
59 */
60
61/** classifier handler data */
63{
64};
65
66
67/*
68 * Local methods
69 */
70
71/* put your local methods here, and declare them static */
72
73
74/*
75 * classifier callback methods
76 */
77
78/** destructor of classifier to free user data (called when GCG is exiting) */
79#define classifierFree NULL
80
81static
82GCG_DECL_VARCLASSIFY(classifierClassify)
83{
84 gcg::DETPROBDATA* detprobdata;
85 SCIP* origprob = GCGgetOrigprob(gcg);
86 assert(origprob != NULL);
87 if( transformed )
88 {
90 }
91 else
92 {
94 }
95
96 // CLASSIFICATION
97 std::vector<SCIP_Real> foundobjvals; /* all found objective function values */
98 std::vector<int> classforvars(detprobdata->getNVars(), -1); /* vector assigning a class index to each variable */
99 int curclassindex; /* stores a var's classindex if the objective value of a var has already been found for another var */
100 SCIP_Real curobjval;
101 gcg::VarPartition* classifier; /* new VarPartition */
102
103 for( int v = 0; v < detprobdata->getNVars(); ++v )
104 {
105 assert( detprobdata->getVar(v) != NULL );
106 curobjval = SCIPvarGetObj(detprobdata->getVar(v));
107 curclassindex = -1;
108
109 /* check whether current objective funtion value already exists */
110 for( size_t c = 0; c < foundobjvals.size(); ++c )
111 {
112 if( SCIPisEQ(origprob, curobjval, foundobjvals[c]) )
113 {
114 curclassindex = (int) c;
115 break;
116 }
117 }
118
119 /* assign var to class and save objective function value, if it is new */
120 if( curclassindex == -1 )
121 {
122 foundobjvals.push_back(curobjval);
123 classforvars[v] = (int) foundobjvals.size() - 1;
124 }
125 else
126 {
127 classforvars[v] = curclassindex;
128 }
129 }
130
131 classifier = new gcg::VarPartition(gcg, "varobjvals", (int) foundobjvals.size(), detprobdata->getNVars());
132
133 /* set up class information */
134 for ( int c = 0; c < classifier->getNClasses(); ++c )
135 {
136 std::stringstream name;
137 std::stringstream text;
138
139 name << std::setprecision( 5 ) << foundobjvals[c];
140 text << "This class contains all variables with objective function value " << name.str() << ".";
141
142 classifier->setClassName(c, name.str().c_str());
143 classifier->setClassDescription(c, text.str().c_str());
144 }
145
146 /* assign vars according to classforvars vactor */
147 for ( int v = 0; v < classifier->getNVars(); ++v )
148 {
149 classifier->assignVarToClass(v, classforvars[v]);
150 }
151
152 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, " Varclassifier \"%s\" yields a classification with %d different variable classes\n", classifier->getName(), classifier->getNClasses()) ;
153
154 detprobdata->addVarPartition(classifier);
155 return SCIP_OKAY;
156}
157
158/*
159 * classifier specific interface methods
160 */
161
163 GCG* gcg /**< GCG data structure */
164 )
165{
166 GCG_CLASSIFIERDATA* classifierdata = NULL;
167
169
170 return SCIP_OKAY;
171}
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 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)
GCG_EXPORT void assignVarToClass(int varindex, int classindex)
GCG_EXPORT int getNVars()
#define classifierFree
#define CLSVAR_ENABLED
SCIP_RETCODE GCGincludeVarClassifierObjValues(GCG *gcg)
#define CLSVAR_NAME
static GCG_DECL_VARCLASSIFY(classifierClassify)
#define CLSVAR_PRIORITY
#define CLSVAR_DESC
classifies variables according to their objective function values
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)),)
DETPROBDATA * GCGconshdlrDecompGetDetprobdataOrig(GCG *gcg)
help method to access detprobdata for unpresolved problem
constraint handler for structure detection
C++ interface of cons_decomp.
#define SCIP_Real
#define SCIP_CALL(x)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPvarGetObj(SCIP_VAR *var)
#define NULL
various SCIP helper methods
Definition: struct_gcg.h:55
SCIP_VERBLEVEL_HIGH
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE