Scippy

GCG

Branch-and-Price & Column Generation for Everyone

clsvar_objvaluesigns.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_objvaluesigns.cpp
30 *
31 * @brief classifies variables according to their objective function value signs
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 "objectivevaluesigns" /**< name of classifier */
50#define CLSVAR_DESC "objective function value signs" /**< 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
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_VARCLASSIFY(classifierClassify)
82{
83 gcg::DETPROBDATA* detprobdata;
84 SCIP* origprob = GCGgetOrigprob(gcg);
85 assert(origprob != NULL);
86 if( transformed )
87 {
89 }
90 else
91 {
93 }
94
95 // CLASSIFICATION
96 gcg::VarPartition* classifier= new gcg::VarPartition(gcg, "varobjvalsigns", 3, detprobdata->getNVars() ); /* new VarPartition */
97 SCIP_Real curobjval;
98
99 /* set up class information */
100 classifier->setClassName( 0, "zero" );
101 classifier->setClassDescription( 0, "This class contains all variables with objective function value zero." );
102 classifier->setClassDecompInfo( 0, gcg::MASTER );
103 classifier->setClassName( 1, "positive" );
104 classifier->setClassDescription( 1, "This class contains all variables with positive objective function value." );
105 classifier->setClassDecompInfo( 1, gcg::ALL );
106 classifier->setClassName( 2, "negative" );
107 classifier->setClassDescription( 2, "This class contains all variables with negative objective function value." );
108 classifier->setClassDecompInfo( 2, gcg::ALL );
109
110 /* assign vars */
111 for( int v = 0; v < detprobdata->getNVars(); ++v )
112 {
113 assert( detprobdata->getVar(v) != NULL );
114 curobjval = SCIPvarGetObj(detprobdata->getVar(v));
115
116 if( SCIPisZero(origprob, curobjval) )
117 {
118 classifier->assignVarToClass(v, 0);
119 }
120 else if ( SCIPisPositive(origprob, curobjval) )
121 {
122 classifier->assignVarToClass(v, 1);
123 }
124 else
125 {
126 classifier->assignVarToClass(v, 2);
127 }
128 }
129
130 /* remove a class if there is no variable with the respective sign */
131 classifier->removeEmptyClasses();
132
133 SCIPverbMessage(origprob, SCIP_VERBLEVEL_HIGH, NULL, " Varclassifier \"%s\" yields a classification with %d different variable classes\n", classifier->getName(), classifier->getNClasses()) ;
134
135
136 detprobdata->addVarPartition(classifier);
137 return SCIP_OKAY;
138}
139
140/*
141 * classifier specific interface methods
142 */
143
145 GCG* gcg /**< GCG data structure */
146 )
147{
148 GCG_CLASSIFIERDATA* classifierdata = NULL;
149
151
152 return SCIP_OKAY;
153}
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 int removeEmptyClasses()
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)
#define classifierFree
#define CLSVAR_ENABLED
SCIP_RETCODE GCGincludeVarClassifierObjValueSigns(GCG *gcg)
#define CLSVAR_NAME
static GCG_DECL_VARCLASSIFY(classifierClassify)
#define CLSVAR_PRIORITY
#define CLSVAR_DESC
classifies variables according to their objective function value signs
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 SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
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