Scippy

GCG

Branch-and-Price & Column Generation for Everyone

presol_roundbound.c
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 presol_roundbound.c
30 * @brief roundbound presolver: round fractional bounds on integer variables
31 * @author Tobias Achterberg
32 * @author Michael Bastubbe
33 */
34
35/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
36
37#include <assert.h>
38#include <string.h>
39
41
42
43#define PRESOL_NAME "roundbound"
44#define PRESOL_DESC "roundbound presolver: round fractional bounds on integers"
45#define PRESOL_PRIORITY +9000000 /**< priority of the presolver (>= 0: before, < 0: after constraint handlers) */
46#define PRESOL_MAXROUNDS -1 /**< maximal number of presolving rounds the presolver participates in (-1: no limit) */
47#define PRESOL_TIMING SCIP_PRESOLTIMING_FAST /* timing of the presolver (fast, medium, or exhaustive) */
48
49#ifdef FIXSIMPLEVALUE
50#define MAXDNOM 10000LL /**< maximal denominator for simple rational fixed values */
51#endif
52
53
54/*
55 * Callback methods of presolver
56 */
57
58/** copy method for constraint handler plugins (called when SCIP copies plugins) */
59static
60SCIP_DECL_PRESOLCOPY(presolCopyRoundbound)
61{ /*lint --e{715}*/
62 assert(scip != NULL);
63 assert(presol != NULL);
64 assert(strcmp(SCIPpresolGetName(presol), PRESOL_NAME) == 0);
65
66 /* call inclusion method of presolver */
68
69 return SCIP_OKAY;
70}
71
72
73/** presolving execution method */
74static
75SCIP_DECL_PRESOLEXEC(presolExecRoundbound)
76{ /*lint --e{715}*/
77 SCIP_VAR** vars;
78 int nvars;
79 int v;
80
81 assert(result != NULL);
82
83 *result = SCIP_DIDNOTFIND;
84
85 /* get the problem variables */
86 vars = SCIPgetVars(scip);
87 nvars = SCIPgetNVars(scip);
88
89 /* scan the variables for roundbound bound reductions
90 * (loop backwards, since a variable fixing can change the current and the subsequent slots in the vars array)
91 */
92 for( v = nvars-1; v >= 0; --v )
93 {
94 SCIP_Real lb;
95 SCIP_Real ub;
96
97 /* get variable's bounds */
98 lb = SCIPvarGetLbGlobal(vars[v]);
99 ub = SCIPvarGetUbGlobal(vars[v]);
100
101 /* is variable integral? */
103 {
104 SCIP_Real newlb;
105 SCIP_Real newub;
106
107 /* round fractional bounds on integer variables */
108 newlb = SCIPfeasCeil(scip, lb);
109 newub = SCIPfeasFloor(scip, ub);
110
111 /* check bounds on variable for infeasibility */
112 if( newlb > newub + 0.5 )
113 {
115 "problem infeasible: integral variable <%s> has bounds [%.17f,%.17f] rounded to [%.17f,%.17f]\n",
116 SCIPvarGetName(vars[v]), lb, ub, newlb, newub);
117 *result = SCIP_CUTOFF;
118 return SCIP_OKAY;
119 }
120
121 /* round fractional bounds */
122 if( !SCIPisFeasEQ(scip, lb, newlb) )
123 {
124 SCIPdebugMessage("rounding lower bound of integral variable <%s>: [%.17f,%.17f] -> [%.17f,%.17f]\n",
125 SCIPvarGetName(vars[v]), lb, ub, newlb, ub);
126 SCIP_CALL( SCIPchgVarLb(scip, vars[v], newlb) );
127 (*nchgbds)++;
128 }
129 if( !SCIPisFeasEQ(scip, ub, newub) )
130 {
131 SCIPdebugMessage("rounding upper bound of integral variable <%s>: [%.17f,%.17f] -> [%.17f,%.17f]\n",
132 SCIPvarGetName(vars[v]), newlb, ub, newlb, newub);
133 SCIP_CALL( SCIPchgVarUb(scip, vars[v], newub) );
134 (*nchgbds)++;
135 }
136
137 }
138 else
139 {
140 /* check bounds on continuous variable for infeasibility */
141 if( SCIPisFeasGT(scip, lb, ub) )
142 {
144 "problem infeasible: continuous variable <%s> has bounds [%.17f,%.17f]\n",
145 SCIPvarGetName(vars[v]), lb, ub);
146 *result = SCIP_CUTOFF;
147 return SCIP_OKAY;
148 }
149 }
150 }
151
152 return SCIP_OKAY;
153}
154
155
156/*
157 * presolver specific interface methods
158 */
159
160/** creates the roundbound presolver and includes it in SCIP */
162 SCIP* scip /**< SCIP data structure */
163 )
164{
165 SCIP_PRESOLDATA* presoldata = NULL;
166 SCIP_PRESOL* presolptr;
167
168 /* include presolver */
170 presolExecRoundbound, presoldata) );
171
172 assert(presolptr != NULL);
173
174 SCIP_CALL( SCIPsetPresolCopy(scip, presolptr, presolCopyRoundbound) );
175
176 return SCIP_OKAY;
177}
#define SCIP_Real
#define SCIP_CALL(x)
int SCIPgetNVars(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
SCIP_RETCODE SCIPsetPresolCopy(SCIP *scip, SCIP_PRESOL *presol, SCIP_DECL_PRESOLCOPY((*presolcopy)))
SCIP_RETCODE SCIPincludePresolBasic(SCIP *scip, SCIP_PRESOL **presolptr, const char *name, const char *desc, int priority, int maxrounds, SCIP_PRESOLTIMING timing, SCIP_DECL_PRESOLEXEC((*presolexec)), SCIP_PRESOLDATA *presoldata)
const char * SCIPpresolGetName(SCIP_PRESOL *presol)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPchgVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIP_RETCODE SCIPchgVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
SCIP_VARTYPE SCIPvarGetType(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
#define NULL
SCIP_RETCODE GCGincludePresolRoundbound(SCIP *scip)
#define PRESOL_NAME
static SCIP_DECL_PRESOLCOPY(presolCopyRoundbound)
static SCIP_DECL_PRESOLEXEC(presolExecRoundbound)
#define PRESOL_PRIORITY
#define PRESOL_MAXROUNDS
#define PRESOL_TIMING
#define PRESOL_DESC
roundbound presolver: round fractional bounds on integer variables
#define SCIPdebugMessage
SCIP_VERBLEVEL_NORMAL
struct SCIP_PresolData SCIP_PRESOLDATA
SCIP_CUTOFF
SCIP_DIDNOTFIND
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
SCIP_VARTYPE_CONTINUOUS