Scippy

UG

Ubiquity Generator framework

scipParaInitiator.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 scipParaInitiator.h
27 * @brief ParaInitiator extension 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
37#ifndef __SCIP_PARA_INITIATOR_H__
38#define __SCIP_PARA_INITIATOR_H__
39
40#include <string>
41#include "ug/paraDef.h"
43#include "scipParaComm.h"
44#include "scipUserPlugins.h"
45#include "scipDiffParamSet.h"
46#include "scipParaInstance.h"
47#include "scipParaSolution.h"
49#include "objscip/objscip.h"
50#include "scip/scip.h"
51#include "scip/scipdefplugins.h"
52#ifdef UG_WITH_UGS
53#include "ugs/ugsParaCommMpi.h"
54#endif
55
56namespace ParaSCIP
57{
58
59/** Initiator class */
61{
62protected:
68 SCIP_MESSAGEHDLR *messagehdlr;
69 FILE *logfile;
72 SCIP *scip;
73 char *probname;
78 char *logname;
79 char *isolname;
83 SCIP_Real finalDualBound;
85 long long nSolved;
86 double absgap;
87 double gap;
88 double objlimit;
89 bool qsol;
90#ifdef UG_WITH_UGS
91 int seqNumber;
92#endif
93
94 bool addRootNodeCuts();
95 void outputProblemInfo(int *nNonLinearConsHdlrs);
97
98public:
99 /** constructor */
101 UG::ParaComm *inComm,
102 UG::ParaTimer *inTimer
103 )
107 absgap(-1.0), gap(-1.0), objlimit(DBL_MAX), qsol(false)
108#ifdef UG_WITH_UGS
109 , seqNumber(0)
110#endif
111 {
112 }
113
114 /** destructor */
116 )
117 {
118 if( instance ) delete instance;
119 if( solution ) delete solution;
122 if( userPlugins ) delete userPlugins;
123 if( generatedIsolname ) delete [] generatedIsolname;
124
125 // message handler is mangaed within scip. It is freed at SCIPfree
126#ifndef SCIP_THREADSAFE_MESSAGEHDLRS
127 if( messagehdlr )
128 {
129 SCIP_CALL_ABORT( SCIPsetDefaultMessagehdlr() );
130 SCIP_CALL_ABORT( SCIPfreeObjMessagehdlr(&messagehdlr) );
131 }
132#endif
133 /******************
134 * Close files *
135 ******************/
136 if( solutionFile )
137 {
138 fclose(solutionFile);
139 }
141 {
142 fclose(transSolutionFile);
143 }
144
145 /********************
146 * Deinitialization *
147 ********************/
149 {
150 SCIP_CALL_ABORT( SCIPprintStatistics(scip, NULL) ); // output statistics (only for problem info)
151 }
152 if( scip )
153 {
154 SCIP_CALL_ABORT( SCIPfree(&scip) );
155 }
156
157 if( logfile != NULL )
158 fclose(logfile);
159
160 BMScheckEmptyMemory();
161 }
162
163 /** init function */
164 virtual int init(
166 int argc,
167 char** argv
168 );
169
170
171 int reInit(
172 int nRestartedRacing
173 );
174
175 /** get instance */
177 )
178 {
179 return instance;
180 }
181
182 /** make DiffSubproblem object for root node */
184 )
185 {
186 return 0;
187 }
188
189 /** try to set incumbent solution */
190 bool tryToSetIncumbentSolution(UG::BbParaSolution *sol, bool checksol);
191
192 /** send solver initialization message */
194
195 /** generate racing ramp-up parameter sets */
196 void generateRacingRampUpParameterSets(int nParamSets, UG::ParaRacingRampUpParamSet **racingRampUpParamSets);
197
199 {
200 return solution;
201 }
202
204 {
205 return SCIPgetNSols(scip);
206 }
207
208 /** convert an internal value to external value */
210 double internalValue
211 )
212 {
213 return instance->convertToExternalValue(internalValue);
214 }
215
216 /** convert an external value to internal value */
218 double externalValue
219 )
220 {
221 return instance->convertToInternalValue(externalValue);
222 }
223
224 /** get solution file name */
226 )
227 {
228 return solutionFileName;
229 }
230
231 /** get absgap */
232 double getAbsgap(double dualBoundValue);
233
234 /** get gap */
235 double getGap(double dualBoundValue);
236
237 /** get absgap value specified */
239 {
240 if( absgap < 0.0 )
241 {
242 SCIP_CALL_ABORT( SCIPgetRealParam(scip, "limits/absgap",&absgap ) );
243 }
244 return absgap;
245 }
246
247 /** get absgap value for a specific SCIP */
248 double getAbsgapValue(SCIP *inScip)
249 {
250 double gapValue;
251 SCIP_CALL_ABORT( SCIPgetRealParam(inScip, "limits/absgap",&gapValue ) );
252 return gapValue;
253 }
254
255
256 /** get gap value specified */
257 double getGapValue()
258 {
259 if( gap < 0.0 )
260 {
261 SCIP_CALL_ABORT( SCIPgetRealParam(scip, "limits/gap",&gap ) );
262 }
263 return gap;
264 }
265
266 /** get gap value for a specific SCIP */
267 double getGapValue(SCIP *inScip)
268 {
269 double gapValue;
270 SCIP_CALL_ABORT( SCIPgetRealParam(inScip, "limits/gap",&gapValue ) );
271 return gapValue;
272 }
273
274 /** get epsilon */
275 double getEpsilon();
276
277 /** write solution */
278 void writeSolution(const std::string& message);
279
280 /** write ParaInstance */
281 void writeParaInstance(const std::string& filename);
282
283 /** write solver runtime parameters */
284 void writeSolverParameters(std::ostream *os);
285
286#ifdef UG_WITH_ZLIB
287 /** write checkpoint solution */
288 void writeCheckpointSolution(const std::string& filename);
289
290 /** read solution from checkpoint file */
291 double readSolutionFromCheckpointFile(char *afterCheckpointingSolutionFileName);
292#endif
293
294 /** get solving status string */
295 std::string getStatus();
296
297 /** print solver version **/
298 void printSolverVersion(std::ostream *os); /**< output file (or NULL for standard output) */
299
300 /** check if feasilbe soltuion exists or not */
302 {
303 return ( SCIPgetBestSol(scip) != NULL );
304 }
305
306 /** set initial stat on initiator */
308
309 /** set initial stat on DiffSubproblem */
310 void setInitialStatOnDiffSubproblem(int minDepth, int maxDepth, UG::BbParaDiffSubproblem *diffSubproblem);
311
312 /** set final solver status */
314
315 /** set number of nodes solved */
316 void setNumberOfNodesSolved(long long n);
317
318 /** set final dual bound */
319 void setDualBound(double bound);
320
321 /** output solution status */
322 void outputFinalSolverStatistics(std::ostream *os, double time);
323
324 /** set user plugins */
326 /*
327 {
328 userPlugins = inUi;
329 assert(userPlugins != 0);
330 }
331 */
332
333 /** include user plugins */
334 void includeUserPlugins(SCIP *inScip)
335 {
336 if( userPlugins )
337 {
338 (*userPlugins)(inScip);
339 }
340 }
341
342 /** returns whether the objective value is known to be integral in every feasible solution */
343 bool isObjIntegral(){ return ( SCIPisObjIntegral(scip) == TRUE );; }
344
346 {
347 SCIP_STAGE stage = SCIPgetStage(scip);
348
349 if(stage == SCIP_STAGE_PRESOLVING || stage == SCIP_STAGE_SOLVING)
350 SCIP_CALL_ABORT( SCIPinterruptSolve(scip) );
351 }
352
353#ifdef UG_WITH_UGS
354 /** read ugs incumbent solution **/
355 bool readUgsIncumbentSolution(UGS::UgsParaCommMpi *ugsComm, int source);
356
357 /** write ugs incumbent solution **/
358 void writeUgsIncumbentSolution(UGS::UgsParaCommMpi *ugsComm);
359#endif
360
361};
362
364
365}
366
367#endif // __SCIP_PARA_INITIATOR_H__
368
Base class of initiator that maintains original problem and incumbent solution.
bool tryToSetIncumbentSolution(UG::BbParaSolution *sol, bool checksol)
double convertToInternalValue(double externalValue)
void outputFinalSolverStatistics(std::ostream *os, double time)
void generateRacingRampUpParameterSets(int nParamSets, UG::ParaRacingRampUpParamSet **racingRampUpParamSets)
void writeSolverParameters(std::ostream *os)
void writeSolution(const std::string &message)
UG::BbParaSolution * getGlobalBestIncumbentSolution()
UG::BbParaDiffSubproblem * makeRootNodeDiffSubproblem()
void writeCheckpointSolution(const std::string &filename)
ScipParaInitiator(UG::ParaComm *inComm, UG::ParaTimer *inTimer)
double getAbsgapValue(SCIP *inScip)
SCIP_MESSAGEHDLR * messagehdlr
void setInitialStatOnDiffSubproblem(int minDepth, int maxDepth, UG::BbParaDiffSubproblem *diffSubproblem)
double getGap(double dualBoundValue)
double readSolutionFromCheckpointFile(char *afterCheckpointingSolutionFileName)
ScipDiffParamSet * scipDiffParamSet
UG::ParaInstance * getParaInstance()
void printSolverVersion(std::ostream *os)
double getAbsgap(double dualBoundValue)
double convertToExternalValue(double internalValue)
void writeParaInstance(const std::string &filename)
void setFinalSolverStatus(UG::FinalSolverState status)
virtual int init(UG::ParaParamSet *paraParams, int argc, char **argv)
void setUserPlugins(ScipUserPlugins *inUi)
double getGapValue(SCIP *inScip)
void outputProblemInfo(int *nNonLinearConsHdlrs)
void setNumberOfNodesSolved(long long n)
int reInit(int nRestartedRacing)
void accumulateInitialStat(UG::ParaInitialStat *initialStat)
UG::FinalSolverState finalState
UG::ParaParamSet * paraParams
ScipDiffParamSet * scipDiffParamSetRoot
void includeUserPlugins(SCIP *inScip)
double convertToInternalValue(double externalValue)
double convertToExternalValue(double internalValue)
Class for the difference between instance and subproblem.
Class for initiator.
BbParaInitiator(ParaComm *inComm, ParaTimer *inTimer)
constructor
class for solution
Base class of communicator object.
Definition: paraComm.h:102
class for initial statistics collecting after racing
class for instance data
Definition: paraInstance.h:51
class ParaParamSet
Definition: paraParamSet.h:850
bool getBoolParamValue(int param)
get bool parameter value
class ParaRacingRampUpParamSet (parameter set for racing ramp-up)
class ParaTimer
Definition: paraTimer.h:49
ScipParaInitiator * ScipParaInitiatorPtr
FinalSolverState
Final status of computation.
@ Aborted
aborted
static const int Quiet
Definition: paraParamSet.h:71
Defines for UG Framework.
SCIP parameter set to be transferred ( Only keep difference between default settings ).
ParaComm extension for SCIP solver.
ParaInitialStat extension for SCIP solver.
ParaInstance extenstion for SCIP solver.
ParaSolution extension for SCIP solver.
SCIP user plugins.