Scippy

UG

Ubiquity Generator framework

scipParaObjBranchRule.h
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and software framework */
4/* UG --- Ubquity Generator Framework */
5/* */
6/* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7/* Copyright (C) 2021-2024 by Zuse Institute Berlin, */
8/* licensed under LGPL version 3 or later. */
9/* Commercial licenses are available through <licenses@zib.de> */
10/* */
11/* This code is free software; you can redistribute it and/or */
12/* modify it under the terms of the GNU Lesser General Public License */
13/* as published by the Free Software Foundation; either version 3 */
14/* of the License, or (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19/* GNU Lesser General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
26/**@file scipParaObjBranchRule.h
27 * @brief Branching rule plug-in for SCIP solver.
28 * @author Yuji Shinano
29 *
30 *
31 *
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#ifndef __SCIP_PARA_OBJ_BRANCHRULE_H__
37#define __SCIP_PARA_OBJ_BRANCHRULE_H__
38
39#include <cassert>
40#include <cstring>
41
42#include "scip/scip.h"
43#include "objscip/objcloneable.h"
44#include "objscip/objscip.h"
45#include "scipParaSolver.h"
46
47namespace ParaSCIP
48{
49
50/** C++ wrapper object for branching rules */
51class ScipParaObjBranchRule : public scip::ObjBranchrule
52{
53public:
54 /*lint --e{1540}*/
55
56 /** SCIP ParaSolver */
58
59 /** parasolver constructor */
61 ScipParaSolver *solver /**< SCIP ParaSolver */
62 )
63 : ObjBranchrule(solver->getScip(), "ScipParaObjBranchRule", "Branch rule plug-in for ParaSCIP",
64 999999, -1, 1.0 ), scipParaSolver(solver)
65 {
66 }
67
68 /** destructor */
70 {
71 }
72
73 /** destructor of branching rule to free user data (called when SCIP is exiting) */
74 virtual SCIP_RETCODE scip_free(
75 SCIP* scip, /**< SCIP data structure */
76 SCIP_BRANCHRULE* branchrule /**< the branching rule itself */
77 )
78 { /*lint --e{715}*/
79 return SCIP_OKAY;
80 }
81
82 /** initialization method of branching rule (called after problem was transformed) */
83 virtual SCIP_RETCODE scip_init(
84 SCIP* scip, /**< SCIP data structure */
85 SCIP_BRANCHRULE* branchrule /**< the branching rule itself */
86 )
87 { /*lint --e{715}*/
88 return SCIP_OKAY;
89 }
90
91 /** deinitialization method of branching rule (called before transformed problem is freed) */
92 virtual SCIP_RETCODE scip_exit(
93 SCIP* scip, /**< SCIP data structure */
94 SCIP_BRANCHRULE* branchrule /**< the branching rule itself */
95 )
96 { /*lint --e{715}*/
97 return SCIP_OKAY;
98 }
99
100 /** solving process initialization method of branching rule (called when branch and bound process is about to begin) */
101 virtual SCIP_RETCODE scip_initsol(
102 SCIP* scip, /**< SCIP data structure */
103 SCIP_BRANCHRULE* branchrule /**< the branching rule itself */
104 )
105 { /*lint --e{715}*/
106 return SCIP_OKAY;
107 }
108
109 /** solving process deinitialization method of branching rule (called before branch and bound process data is freed) */
110 virtual SCIP_RETCODE scip_exitsol(
111 SCIP* scip, /**< SCIP data structure */
112 SCIP_BRANCHRULE* branchrule /**< the branching rule itself */
113 )
114 { /*lint --e{715}*/
115 return SCIP_OKAY;
116 }
117
118 /** branching execution method for fractional LP solutions
119 *
120 * possible return values for *result (if more than one applies, the first in the list should be used):
121 * - SCIP_CUTOFF : the current node was detected to be infeasible
122 * - SCIP_CONSADDED : an additional constraint (e.g. a conflict clause) was generated; this result code must not be
123 * returned, if allowaddcons is FALSE
124 * - SCIP_REDUCEDDOM : a domain was reduced that rendered the current LP solution infeasible
125 * - SCIP_SEPARATED : a cutting plane was generated
126 * - SCIP_BRANCHED : branching was applied
127 * - SCIP_DIDNOTRUN : the branching rule was skipped
128 */
129 virtual SCIP_RETCODE scip_execlp(
130 SCIP* scip, /**< SCIP data structure */
131 SCIP_BRANCHRULE* branchrule, /**< the branching rule itself */
132 SCIP_Bool allowaddcons, /**< should adding constraints be allowed to avoid a branching? */
133 SCIP_RESULT* result /**< pointer to store the result of the branching call */
134 )
135 { /*lint --e{715}*/
136 assert(result != NULL);
137 *result = SCIP_DIDNOTRUN;
138 if( SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_OPTIMAL || SCIPgetLPSolstat(scip) == SCIP_LPSOLSTAT_UNBOUNDEDRAY )
139 {
140 /** set integer infeaibility statistics */
141 int ncands = 0;
142 SCIP_Real* fracs = 0;
143 SCIP_Real iisum = 0.0;
144#if (SCIP_VERSION == 301 && SCIP_SUBVERSION == 5) || (SCIP_VERSION >= 302 && SCIP_SUBVERSION != 0 || SCIP_VERSION >= 310 )
145 SCIP_CALL_ABORT( SCIPgetLPBranchCands(scip, NULL,NULL, &fracs, &ncands, NULL, NULL) );
146#else
147 SCIP_CALL_ABORT( SCIPgetLPBranchCands(scip, NULL,NULL, &fracs, &ncands, NULL) );
148#endif
149 for( int i = 0; i < ncands; ++i )
150 iisum += fracs[i];
151 scipParaSolver->setII(iisum, ncands);
152 }
153 return SCIP_OKAY;
154 }
155
156 /** branching execution method for external candidates
157 *
158 * possible return values for *result (if more than one applies, the first in the list should be used):
159 * - SCIP_CUTOFF : the current node was detected to be infeasible
160 * - SCIP_CONSADDED : an additional constraint (e.g. a conflict clause) was generated; this result code must not be
161 * returned, if allowaddcons is FALSE
162 * - SCIP_REDUCEDDOM : a domain was reduced that rendered the current pseudo solution infeasible
163 * - SCIP_BRANCHED : branching was applied
164 * - SCIP_DIDNOTRUN : the branching rule was skipped
165 */
166 virtual SCIP_RETCODE scip_execext(
167 SCIP* scip, /**< SCIP data structure */
168 SCIP_BRANCHRULE* branchrule, /**< the branching rule itself */
169 SCIP_Bool allowaddcons, /**< should adding constraints be allowed to avoid a branching? */
170 SCIP_RESULT* result /**< pointer to store the result of the branching call */
171 )
172 { /*lint --e{715}*/
173 assert(result != NULL);
174 *result = SCIP_DIDNOTRUN;
175 return SCIP_OKAY;
176 }
177
178 /** branching execution method for not completely fixed pseudo solutions
179 *
180 * possible return values for *result (if more than one applies, the first in the list should be used):
181 * - SCIP_CUTOFF : the current node was detected to be infeasible
182 * - SCIP_CONSADDED : an additional constraint (e.g. a conflict clause) was generated; this result code must not be
183 * returned, if allowaddcons is FALSE
184 * - SCIP_REDUCEDDOM : a domain was reduced that rendered the current pseudo solution infeasible
185 * - SCIP_BRANCHED : branching was applied
186 * - SCIP_DIDNOTRUN : the branching rule was skipped
187 */
188 virtual SCIP_RETCODE scip_execps(
189 SCIP* scip, /**< SCIP data structure */
190 SCIP_BRANCHRULE* branchrule, /**< the branching rule itself */
191 SCIP_Bool allowaddcons, /**< should adding constraints be allowed to avoid a branching? */
192 SCIP_RESULT* result /**< pointer to store the result of the branching call */
193 )
194 { /*lint --e{715}*/
195 assert(result != NULL);
196 *result = SCIP_DIDNOTRUN;
197 return SCIP_OKAY;
198 }
199};
200
201} /* namespace ParaSCIP */
202#endif
virtual SCIP_RETCODE scip_exit(SCIP *scip, SCIP_BRANCHRULE *branchrule)
virtual SCIP_RETCODE scip_initsol(SCIP *scip, SCIP_BRANCHRULE *branchrule)
virtual SCIP_RETCODE scip_free(SCIP *scip, SCIP_BRANCHRULE *branchrule)
virtual SCIP_RETCODE scip_init(SCIP *scip, SCIP_BRANCHRULE *branchrule)
virtual SCIP_RETCODE scip_execlp(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_Bool allowaddcons, SCIP_RESULT *result)
virtual SCIP_RETCODE scip_execext(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_Bool allowaddcons, SCIP_RESULT *result)
virtual SCIP_RETCODE scip_execps(SCIP *scip, SCIP_BRANCHRULE *branchrule, SCIP_Bool allowaddcons, SCIP_RESULT *result)
ScipParaObjBranchRule(ScipParaSolver *solver)
virtual SCIP_RETCODE scip_exitsol(SCIP *scip, SCIP_BRANCHRULE *branchrule)
void setII(double sum, int count)
set sum and number of integer infeasibility
ParaSolver extension for SCIP: Parallelized solver implementation for SCIP.