Scippy

GCG

Branch-and-Price & Column Generation for Everyone

score_forswh.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_forswh.cpp
30 * @brief max foreseeing white 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_forswh.h"
41
42
43/* score properties */
44#define SCORE_NAME "max foreseeing white"
45#define SCORE_SHORTNAME "forswh"
46#define SCORE_DESC "maximum foreseeing white area score (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 scoreFreeForswh NULL
71
72static
73GCG_DECL_SCORECALC(scoreCalcForswh)
74{
75 unsigned long sumblockshittinglinkingvar;
76 unsigned long sumlinkingvarshittingblock;
77 unsigned long newheight;
78 unsigned long newwidth;
79 unsigned long newmasterarea;
80 unsigned long newblockarea;
81
83 gcg::DETPROBDATA* detprobdata = partialdec->getDetprobdata();
84
85 std::vector<int> blockforconss(partialdec->getNConss(), -1);
86 std::vector<int> nlinkingvarsforblock(partialdec->getNBlocks(), 0);
87 std::vector<int> nblocksforlinkingvar(partialdec->getNLinkingvars() + partialdec->getNTotalStairlinkingvars(), 0);
88
89 /* store for each cons to which block it is assigned (or -1 if border or unassigned) */
90 for( int b = 0; b < partialdec->getNBlocks(); ++b )
91 {
92 std::vector<int>& blockconss = partialdec->getConssForBlock(b);
93 for ( int blc = 0; blc < partialdec->getNConssForBlock(b); ++blc )
94 {
95 int blockcons = blockconss[blc];
96 blockforconss[blockcons] = b;
97 }
98 }
99
100 /* iterate linking vars and corresponding conss to recognize hit blocks */
101 for( int lv = 0; lv < partialdec->getNLinkingvars(); ++lv )
102 {
103 int linkingvarid = partialdec->getLinkingvars()[lv];
104 int nhittingconss = detprobdata->getNConssForVar(linkingvarid);
105 std::vector<int>& hittingconss = detprobdata->getConssForVar(linkingvarid);
106
107 std::vector<bool> hitblock(partialdec->getNBlocks(), false);
108
109 /* find out which blocks the linking var is hitting */
110 for ( int hittingcons = 0; hittingcons < nhittingconss; ++hittingcons )
111 {
112 int blockforcons = blockforconss[hittingconss[hittingcons]];
113 if( blockforcons != -1 )
114 hitblock[blockforcons] = true;
115 }
116
117 /* count for each block and each linking var how many linking vars or blocks, respectively, they hit */
118 for( int b = 0; b < partialdec->getNBlocks(); ++b )
119 {
120 if ( hitblock[b] )
121 {
122 /* linking var hits block, so count it */
123 ++nlinkingvarsforblock[b];
124 ++nblocksforlinkingvar[lv];
125 }
126 }
127 }
128
129 for( int b = 0; b < partialdec->getNBlocks(); ++b)
130 {
131 for( int slv = 0; slv < partialdec->getNStairlinkingvars(b); ++slv )
132 {
133 ++nlinkingvarsforblock[b];
134 ++nlinkingvarsforblock[b+1];
135 ++nblocksforlinkingvar[partialdec->getNLinkingvars() + slv];
136 ++nblocksforlinkingvar[partialdec->getNLinkingvars() + slv];
137 }
138 }
139
140 sumblockshittinglinkingvar = 0;
141 sumlinkingvarshittingblock = 0;
142 for( int b = 0; b < partialdec->getNBlocks(); ++b )
143 {
144 sumlinkingvarshittingblock += nlinkingvarsforblock[b];
145 }
146 for( int lv = 0; lv < partialdec->getNLinkingvars(); ++lv )
147 {
148 sumblockshittinglinkingvar += nblocksforlinkingvar[lv];
149 }
150
151 for( int slv = 0; slv < partialdec->getNTotalStairlinkingvars(); ++slv )
152 {
153 sumblockshittinglinkingvar += nblocksforlinkingvar[partialdec->getNLinkingvars() + slv];
154 }
155
156 newheight = partialdec->getNConss() + sumblockshittinglinkingvar;
157 newwidth = partialdec->getNVars() + sumlinkingvarshittingblock;
158
159 newmasterarea = ( (SCIP_Real) partialdec->getNMasterconss() + sumblockshittinglinkingvar) * ( (SCIP_Real) partialdec->getNVars() + sumlinkingvarshittingblock );
160 newblockarea = 0;
161
162 for( int b = 0; b < partialdec->getNBlocks(); ++b )
163 {
164 newblockarea += ((SCIP_Real) partialdec->getNConssForBlock(b) ) * ( (SCIP_Real) partialdec->getNVarsForBlock(b) + nlinkingvarsforblock[b] );
165 }
166
167 SCIP_Real maxforeseeingwhitescore = newwidth == 0 ? 1. : ((SCIP_Real ) newblockarea + (SCIP_Real) newmasterarea) / (SCIP_Real) newwidth;
168 maxforeseeingwhitescore = newheight == 0 ? 1. : maxforeseeingwhitescore / (SCIP_Real) newheight;
169
170 maxforeseeingwhitescore = 1. - maxforeseeingwhitescore;
171 assert(maxforeseeingwhitescore == SCIP_INVALID || (maxforeseeingwhitescore >= 0. && maxforeseeingwhitescore <= 1.));
172 *scorevalue = maxforeseeingwhitescore;
173
174 return SCIP_OKAY;
175}
176
177
178
179
180/*
181 * score specific interface methods
182 */
183
184/** creates the max foreseeing white score and includes it in SCIP */
186 GCG* gcg /**< GCG data structure */
187 )
188{
189 GCG_SCOREDATA* scoredata = NULL;
190
191 SCIP_CALL(
193 scoreFreeForswh, scoreCalcForswh) );
194
195 return SCIP_OKAY;
196}
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 getNConssForVar(int varIndex)
returns the number of constraints for a given variable where the var has a nonzero entry in
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 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 DETPROBDATA * getDetprobdata()
Gets the corresponding detprobdata.
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)
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
#define NULL
#define SCORE_SHORTNAME
SCIP_RETCODE GCGincludeScoreForswh(GCG *gcg)
#define SCORE_NAME
static GCG_DECL_SCORECALC(scoreCalcForswh)
#define scoreFreeForswh
#define SCORE_DESC
max foreseeing white score
Definition: struct_gcg.h:55
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE