Scippy

GCG

Branch-and-Price & Column Generation for Everyone

score_fawh.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_fawh.cpp
30 * @brief maximum foreseeing white area score with aggregation info 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_fawh.h"
41
42
43/* score properties */
44#define SCORE_NAME "max foreseeing white with aggregation info"
45#define SCORE_SHORTNAME "fawh"
46#define SCORE_DESC "maximum foreseeing white area score with aggregation info (considering copied linking vars and their master conss; white area is nonblock and nonborder area)"
47
48
49/*
50 * Data structures
51 */
52struct GCG_ScoreData
53{
54};
55
56/*
57 * Local methods
58 */
59
60/* put your local methods here, and declare them static */
61
62
63
64
65/*
66 * score callback methods
67 */
68
69/** destructor of score to free user data (called when GCG is exiting) */
70#define scoreFreeFawh NULL
71
72static
73GCG_DECL_SCORECALC(scoreCalcFawh)
74{
75 unsigned long sumblockshittinglinkingvar;
76 unsigned long sumlinkingvarshittingblock;
77 unsigned long newheight;
78 unsigned long newwidth;
79 unsigned long newmasterarea;
80 unsigned long newblockareaagg;
81
84
85 std::vector<int> nlinkingvarsforblock(partialdec->getNBlocks(), 0);
86 std::vector<int> nblocksforlinkingvar(partialdec->getNLinkingvars() + partialdec->getNTotalStairlinkingvars(), 0);
87
88 gcg::DETPROBDATA* detprobdata = partialdec->getDetprobdata();
89
90 partialdec->calcAggregationInformation(false);
91
92 for( int lv = 0; lv < partialdec->getNLinkingvars(); ++lv )
93 {
94 int linkingvarid = partialdec->getLinkingvars()[lv];
95
96 for( int b = 0; b < partialdec->getNBlocks(); ++b )
97 {
98 for ( int blc = 0; blc < partialdec->getNConssForBlock(b); ++blc )
99 {
100 int blockcons = partialdec->getConssForBlock(b)[blc];
101 if( !SCIPisZero( scip, detprobdata->getVal(blockcons, linkingvarid) ) )
102 {
103 /* linking var hits block */
104 ++nlinkingvarsforblock[b];
105 ++nblocksforlinkingvar[lv];
106 break;
107 }
108 }
109 }
110 }
111
112 for( int b = 0; b < partialdec->getNBlocks(); ++b)
113 {
114 for( int slv = 0; slv < partialdec->getNStairlinkingvars(b); ++slv )
115 {
116 ++nlinkingvarsforblock[b];
117 ++nlinkingvarsforblock[b+1];
118 ++nblocksforlinkingvar[partialdec->getNLinkingvars() + slv];
119 ++nblocksforlinkingvar[partialdec->getNLinkingvars() + slv];
120 }
121 }
122
123 sumblockshittinglinkingvar = 0;
124 sumlinkingvarshittingblock = 0;
125 for( int b = 0; b < partialdec->getNBlocks(); ++b )
126 {
127 sumlinkingvarshittingblock += nlinkingvarsforblock[b];
128 }
129 for( int lv = 0; lv < partialdec->getNLinkingvars(); ++lv )
130 {
131 sumblockshittinglinkingvar += nblocksforlinkingvar[lv];
132 }
133
134 for( int slv = 0; slv < partialdec->getNTotalStairlinkingvars(); ++slv )
135 {
136 sumblockshittinglinkingvar += nblocksforlinkingvar[partialdec->getNLinkingvars() + slv];
137 }
138
139 newheight = partialdec->getNConss() + sumblockshittinglinkingvar;
140 newwidth = partialdec->getNVars() + sumlinkingvarshittingblock;
141
142 newmasterarea = ( partialdec->getNMasterconss() + sumblockshittinglinkingvar) * ( partialdec->getNVars() + sumlinkingvarshittingblock );
143 newblockareaagg = 0;
144
145 for( int br = 0; br < partialdec->getNEquivalenceClasses(); ++br )
146 {
147 newblockareaagg += partialdec->getNConssForBlock(partialdec->getBlocksForEqClass(br)[0])
148 * ( partialdec->getNVarsForBlock(partialdec->getBlocksForEqClass(br)[0]) + nlinkingvarsforblock[partialdec->getBlocksForEqClass(br)[0]] );
149 }
150
151 SCIP_Real maxforeseeingwhitescoreagg = newwidth == 0 ? 1. : ((SCIP_Real ) newblockareaagg + (SCIP_Real) newmasterarea) / (SCIP_Real) newwidth;
152 maxforeseeingwhitescoreagg = newheight == 0 ? 1. : maxforeseeingwhitescoreagg / (SCIP_Real) newheight;
153
154 maxforeseeingwhitescoreagg = 1. - maxforeseeingwhitescoreagg;
155 assert(maxforeseeingwhitescoreagg == SCIP_INVALID || (maxforeseeingwhitescoreagg >= 0.0 && maxforeseeingwhitescoreagg <= 1.0));
156 *scorevalue = maxforeseeingwhitescoreagg;
157
158 return SCIP_OKAY;
159}
160
161
162
163
164/*
165 * score specific interface methods
166 */
167
168/** creates the maximum foreseeing white area score with aggregation info score and includes it in SCIP */
170 GCG* gcg /**< GCG data structure */
171 )
172{
173 GCG_SCOREDATA* scoredata = NULL;
174
175 SCIP_CALL(
177 scoreFreeFawh, scoreCalcFawh) );
178
179 return SCIP_OKAY;
180}
SCIP_VAR ** b
class storing partialdecs and the problem matrix
class storing (potentially incomplete) decompositions
GCG_EXPORT SCIP_Real getVal(int row, int col)
returns a coefficient from the coefficient matrix
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 int getNEquivalenceClasses()
Gets the number of blockrepresentatives.
GCG_EXPORT int getNStairlinkingvars(int block)
Gets size of the vector containing stairlinking vars.
GCG_EXPORT std::vector< int > & getConssForBlock(int block)
returns array containing constraints assigned to a block
GCG_EXPORT const std::vector< int > & getBlocksForEqClass(int eqclass)
get a vector of block ids that are contained in the equivalence class eqclass
GCG_EXPORT DETPROBDATA * getDetprobdata()
Gets the corresponding detprobdata.
GCG_EXPORT void calcAggregationInformation(bool ignoreDetectionLimits)
computes if aggregation of sub problems is possible
GCG_EXPORT int getNVarsForBlock(int block)
Gets size of the vector containing vars assigned to a block.
GCG_EXPORT std::vector< int > & getLinkingvars()
returns array containing all linking vars indices
GCG_EXPORT int getNVars()
Gets number of vars.
GCG_EXPORT int getNLinkingvars()
Gets size of the vector containing linking vars.
GCG_EXPORT int getNTotalStairlinkingvars()
Gets total number of stairlinking vars.
GCG_EXPORT int getNConssForBlock(int block)
Gets size of the vector containing conss assigned to a block.
GCG_EXPORT int getNBlocks()
Gets the number of blocks.
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_INVALID
#define SCIP_Real
#define SCIP_CALL(x)
SCIP * GCGgetOrigprob(GCG *gcg)
Definition: gcg.cpp:87
GCG_EXPORT SCIP_RETCODE GCGincludeScore(GCG *gcg, const char *name, const char *shortname, const char *description, GCG_SCOREDATA *scoredata, GCG_DECL_SCOREFREE((*scorefree)), GCG_DECL_SCORECALC((*scorecalc)))
creates a score and includes it in GCG
Definition: score.c:50
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
#define NULL
#define SCORE_SHORTNAME
Definition: score_fawh.cpp:45
#define scoreFreeFawh
Definition: score_fawh.cpp:70
#define SCORE_NAME
Definition: score_fawh.cpp:44
SCIP_RETCODE GCGincludeScoreFawh(GCG *gcg)
Definition: score_fawh.cpp:169
#define SCORE_DESC
Definition: score_fawh.cpp:46
static GCG_DECL_SCORECALC(scoreCalcFawh)
Definition: score_fawh.cpp:73
maximum foreseeing white area score with aggregation infos score
Definition: struct_gcg.h:55
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE