GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
score_bender.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 score_bender.cpp
30 * @brief benders score
31 * @author Jurgen Lentz
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
38#include "gcg/cons_decomp.h"
39#include "gcg/cons_decomp.hpp"
40#include "gcg/score_bender.h"
41
42/* score properties */
43#define SCORE_NAME "experimental benders score"
44#define SCORE_SHORTNAME "bender"
45#define SCORE_DESC "experimental score to evaluate benders decompositions"
46
47
48/*
49 * Data structures
50 */
52{
53};
54
55
56
57
58/*
59 * Local methods
60 */
61
62/* put your local methods here, and declare them static */
63
64
65
66
67/*
68 * classifier callback methods
69 */
70
71/** destructor of classifier to free user data (called when GCG is exiting) */
72#define scoreFreeBender NULL
73
74static
75GCG_DECL_SCORECALC(scoreCalcBender)
76{
77 SCIP_Real benderareascore = 0;
78
79 unsigned long nrelevantconss;
80 unsigned long nrelevantvars;
81 unsigned long nrelevantconss2;
82 unsigned long nrelevantvars2;
83 unsigned long badblockvararea;
84 long benderborderarea;
85 unsigned long totalarea;
86
87 nrelevantconss = 0;
88 nrelevantvars = 0;
89 nrelevantconss2 = 0;
90 nrelevantvars2 = 0;
91 badblockvararea = 0;
92
94
95 gcg::DETPROBDATA* detprobdata = partialdec->getDetprobdata();
96
97 /* calc bender area score (1 - fraction of white area in master constraints to complete area) */
98 for( int c = 0; c < partialdec->getNMasterconss(); ++c )
99 {
100 bool relevant = true;
101 int cons = partialdec->getMasterconss()[c];
102 for( int v = 0; v < detprobdata->getNVarsForCons(cons); ++v )
103 {
104 int var = detprobdata->getVarsForCons(cons)[v];
105 if ( partialdec->isVarOpenvar(var) || partialdec->isVarMastervar(var) || partialdec->isVarLinkingvar(var) )
106 {
107 relevant = false;
108 break;
109 }
110
111 }
112 if( relevant )
113 ++nrelevantconss;
114 }
115
116 for( int b = 0; b < partialdec->getNBlocks(); ++b )
117 {
118 for(int v = 0; v < partialdec->getNVarsForBlock(b); ++v )
119 {
120 bool relevant = true;
121 int var = partialdec->getVarsForBlock(b)[v];
122 for( int c = 0; c < detprobdata->getNConssForVar(var); ++c )
123 {
124 int cons = detprobdata->getConssForVar(var)[c];
125 if( partialdec->isConsMastercons(cons) || partialdec->isConsOpencons(cons) )
126 {
127 relevant = false;
128 for( int b2 = 0; b2 < partialdec->getNBlocks(); ++b2 )
129 {
130 if( b2 != b )
131 badblockvararea += partialdec->getNConssForBlock(b2);
132 }
133 break;
134 }
135 }
136 if( relevant )
137 ++nrelevantvars;
138 }
139 }
140
141 for( int v = 0; v < partialdec->getNLinkingvars(); ++v )
142 {
143 bool relevant = true;
144 int var = partialdec->getLinkingvars()[v];
145 for( int c = 0; c < detprobdata->getNConssForVar(var); ++c )
146 {
147 int cons = detprobdata->getConssForVar(var)[c];
148 if ( partialdec->isConsOpencons(cons) || partialdec->isConsMastercons(cons) )
149 {
150 relevant = false;
151 break;
152 }
153
154 }
155 if( relevant )
156 ++nrelevantvars2;
157 }
158
159 for( int b = 0; b < partialdec->getNBlocks(); ++b )
160 {
161 for(int c = 0; c < partialdec->getNConssForBlock(b); ++c )
162 {
163 bool relevant = true;
164 int cons = partialdec->getConssForBlock(b)[c];
165 for( int v = 0; v < detprobdata->getNVarsForCons(cons); ++v )
166 {
167 int var = detprobdata->getVarsForCons(cons)[v];
168 if( partialdec->isVarLinkingvar(var) || partialdec->isVarOpenvar(var) )
169 {
170 relevant = false;
171 break;
172 }
173 }
174 if( relevant )
175 ++nrelevantconss2;
176 }
177 }
178
179 benderborderarea = ( nrelevantconss * nrelevantvars ) + ( nrelevantconss2 * nrelevantvars2 ) - badblockvararea;
180 totalarea = ( (unsigned long) partialdec->getNConss() * (unsigned long) partialdec->getNVars() );
181 benderareascore = ( SCIP_Real) benderborderarea / totalarea;
182
183 /* get block & border area score (note: these calculations have their own clock) */
184 SCIP_Real borderareascore;
185
186 SCIP_Real blockareascore = partialdec->calcBlockAreaScore();
187 borderareascore = partialdec->getScore(GCGconshdlrDecompFindScore(gcg, "border area"));
188
189 *scorevalue = blockareascore + benderareascore + borderareascore - 1.;
190
191 if( *scorevalue < 0. )
192 *scorevalue = 0.;
193
194 return SCIP_OKAY;
195}
196
197/*
198 * score specific interface methods
199 */
200
201/** creates the bender score and includes it in SCIP */
203 GCG* gcg /**< GCG data structure */
204 )
205{
206 GCG_SCOREDATA* scoredata = NULL;
207
208 SCIP_CALL(
210 scoreFreeBender, scoreCalcBender) );
211
212 return SCIP_OKAY;
213}
SCIP_VAR ** b
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
GCG_EXPORT std::vector< int > & getConssForVar(int varIndex)
returns the constraint indices of the coefficient matrix for a variable
GCG_EXPORT int getNVarsForCons(int consIndex)
returns the number of variables for a given constraint
GCG_EXPORT int getNConssForVar(int varIndex)
returns the number of constraints for a given variable where the var has a nonzero entry in
GCG_EXPORT std::vector< int > & getVarsForCons(int consIndex)
returns the variable indices of the coefficient matrix for a constraint
class to manage partial decompositions
GCG_EXPORT int getNConss()
Gets the number of constraints.
GCG_EXPORT int getNMasterconss()
Gets size of the vector containing master conss.
GCG_EXPORT bool isConsMastercons(int cons)
Gets whether the cons is a master cons.
GCG_EXPORT SCIP_Real getScore(GCG_SCORE *score)
returns the score of the partialdec
GCG_EXPORT bool isVarLinkingvar(int var)
Checks whether the var is a linking var.
GCG_EXPORT std::vector< int > & getMasterconss()
Gets array containing all master conss indices.
GCG_EXPORT std::vector< int > & getConssForBlock(int block)
returns array containing constraints assigned to a block
GCG_EXPORT DETPROBDATA * getDetprobdata()
Gets the corresponding detprobdata.
GCG_EXPORT bool isVarMastervar(int var)
Checks whether the var is a master var.
GCG_EXPORT int getNVarsForBlock(int block)
Gets size of the vector containing vars assigned to a block.
GCG_EXPORT bool isVarOpenvar(int var)
Checks whether the var is an open var.
GCG_EXPORT std::vector< int > & getLinkingvars()
returns array containing all linking vars indices
SCIP_Real calcBlockAreaScore()
gets an intermediate score value for the blocks of a partialdec
GCG_EXPORT int getNVars()
Gets number of vars.
GCG_EXPORT int getNLinkingvars()
Gets size of the vector containing linking vars.
GCG_EXPORT int getNConssForBlock(int block)
Gets size of the vector containing conss assigned to a block.
GCG_EXPORT bool isConsOpencons(int cons)
Gets whether the cons is an open cons.
GCG_EXPORT std::vector< int > & getVarsForBlock(int block)
Gets array containing vars of a block.
GCG_EXPORT int getNBlocks()
Gets the number of blocks.
GCG_SCORE * GCGconshdlrDecompFindScore(GCG *gcg, const char *name)
searches for the score with the given name and returns it or NULL if score is not found
PARTIALDECOMP * GCGconshdlrDecompGetPartialdecFromID(GCG *gcg, int partialdecid)
local method to find a partialdec for a given id or NULL if no partialdec with such id is found
constraint handler for structure detection
C++ interface of cons_decomp.
#define SCIP_Real
GCG_EXPORT SCIP_RETCODE GCGincludeScore(GCG *gcg, const char *name, const char *shortname, const char *description, GCG_SCOREDATA *scoredata, GCG_DECL_SCOREFREE((*scorefree)),)
creates a score and includes it in GCG
Definition score.c:50
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP_VAR * var
#define NULL
#define scoreFreeBender
#define SCORE_SHORTNAME
#define SCORE_NAME
SCIP_RETCODE GCGincludeScoreBender(GCG *gcg)
#define SCORE_DESC
benders score
struct Gcg GCG
Definition type_gcg.h:44
enum SCIP_Retcode SCIP_RETCODE
struct GCG_ScoreData GCG_SCOREDATA
Definition type_score.h:46
#define GCG_DECL_SCORECALC(x)
Definition type_score.h:66