Scippy

SCIP

Solving Constraint Integer Programs

objreader.cpp
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2018 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License. */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file objreader.cpp
17  * @brief C++ wrapper for file readers
18  * @author Tobias Achterberg
19  */
20 
21 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
22 
23 #include <cassert>
24 
25 #include "objreader.h"
26 
27 
28 
29 
30 /*
31  * Data structures
32  */
33 
34 /** file reader data */
35 struct SCIP_ReaderData
36 {
37  scip::ObjReader* objreader; /**< file reader object */
38  SCIP_Bool deleteobject; /**< should the reader object be deleted when reader is freed? */
39 };
40 
41 
42 
43 
44 /*
45  * Callback methods of file reader
46  */
47 
48 extern "C"
49 {
50 
51 /** copy method for reader plugins (called when SCIP copies plugins) */
52 static
53 SCIP_DECL_READERCOPY(readerCopyObj)
54 { /*lint --e{715}*/
55  SCIP_READERDATA* readerdata;
56 
57  assert(scip != NULL);
58 
59  readerdata = SCIPreaderGetData(reader);
60  assert(readerdata != NULL);
61  assert(readerdata->objreader != NULL);
62  assert(readerdata->objreader->scip_ != scip);
63 
64  if( readerdata->objreader->iscloneable() )
65  {
66  scip::ObjReader* newobjreader;
67  newobjreader = dynamic_cast<scip::ObjReader*> (readerdata->objreader->clone(scip));
68 
69  /* call include method of reader object */
70  SCIP_CALL( SCIPincludeObjReader(scip, newobjreader, TRUE) );
71  }
72 
73  return SCIP_OKAY;
74 }
75 
76 /** destructor of file reader to free user data (called when SCIP is exiting) */
77 static
78 SCIP_DECL_READERFREE(readerFreeObj)
79 { /*lint --e{715}*/
80  SCIP_READERDATA* readerdata;
81 
82  readerdata = SCIPreaderGetData(reader);
83  assert(readerdata != NULL);
84  assert(readerdata->objreader != NULL);
85  assert(readerdata->objreader->scip_ == scip);
86 
87  /* call virtual method of reader object */
88  SCIP_CALL( readerdata->objreader->scip_free(scip, reader) );
89 
90  /* free reader object */
91  if( readerdata->deleteobject )
92  delete readerdata->objreader;
93 
94  /* free reader data */
95  delete readerdata;
96  SCIPreaderSetData(reader, NULL); /*lint !e64*/
97 
98  return SCIP_OKAY;
99 }
100 
101 
102 /** problem reading method of reader */
103 static
104 SCIP_DECL_READERREAD(readerReadObj)
105 { /*lint --e{715}*/
106  SCIP_READERDATA* readerdata;
107 
108  readerdata = SCIPreaderGetData(reader);
109  assert(readerdata != NULL);
110  assert(readerdata->objreader != NULL);
111  assert(readerdata->objreader->scip_ == scip);
112 
113  /* call virtual method of reader object */
114  SCIP_CALL( readerdata->objreader->scip_read(scip, reader, filename, result) );
115 
116  return SCIP_OKAY;
117 }
118 
119 
120 /** problem writing method of reader */
121 static
122 SCIP_DECL_READERWRITE(readerWriteObj)
123 { /*lint --e{715}*/
124  SCIP_READERDATA* readerdata;
125 
126  readerdata = SCIPreaderGetData(reader);
127  assert(readerdata != NULL);
128  assert(readerdata->objreader != NULL);
129 
130  /* call virtual method of reader object */
131  SCIP_CALL( readerdata->objreader->scip_write(scip, reader, file, name, probdata, transformed,
132  objsense, objscale, objoffset,
133  vars, nvars, nbinvars, nintvars, nimplvars, ncontvars, fixedvars, nfixedvars, startnvars,
134  conss, nconss, maxnconss, startnconss, genericnames, result) );
135 
136  return SCIP_OKAY;
137 }
138 }
139 
140 
141 /*
142  * file reader specific interface methods
143  */
144 
145 /** creates the file reader for the given file reader object and includes it in SCIP */
147  SCIP* scip, /**< SCIP data structure */
148  scip::ObjReader* objreader, /**< file reader object */
149  SCIP_Bool deleteobject /**< should the reader object be deleted when reader is freed? */
150  )
151 {
152  SCIP_READERDATA* readerdata;
153 
154  assert(scip != NULL);
155  assert(objreader != NULL);
156 
157  /* create file reader data */
158  readerdata = new SCIP_READERDATA;
159  readerdata->objreader = objreader;
160  readerdata->deleteobject = deleteobject;
161 
162  /* include file reader */
163  SCIP_CALL( SCIPincludeReader(scip, objreader->scip_name_, objreader->scip_desc_, objreader->scip_extension_,
164  readerCopyObj,
165  readerFreeObj, readerReadObj, readerWriteObj, readerdata) ); /*lint !e429*/
166 
167  return SCIP_OKAY; /*lint !e429*/
168 }
169 
170 /** returns the reader object of the given name, or 0 if not existing */
172  SCIP* scip, /**< SCIP data structure */
173  const char* name /**< name of file reader */
174  )
175 {
176  SCIP_READER* reader;
177  SCIP_READERDATA* readerdata;
178 
179  reader = SCIPfindReader(scip, name);
180  if( reader == NULL )
181  return 0;
182 
183  readerdata = SCIPreaderGetData(reader);
184  assert(readerdata != NULL);
185 
186  return readerdata->objreader;
187 }
188 
189 /** returns the reader object for the given file reader */
191  SCIP* scip, /**< SCIP data structure */
192  SCIP_READER* reader /**< file reader */
193  )
194 {
195  SCIP_READERDATA* readerdata;
196 
197  readerdata = SCIPreaderGetData(reader);
198  assert(readerdata != NULL);
199 
200  return readerdata->objreader;
201 }
char * scip_desc_
Definition: objreader.h:54
#define TRUE
Definition: def.h:63
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
scip::ObjReader * SCIPfindObjReader(SCIP *scip, const char *name)
Definition: objreader.cpp:171
SCIP_READER * SCIPfindReader(SCIP *scip, const char *name)
Definition: scip.c:5390
static SCIP_DECL_READERFREE(readerFreeObj)
Definition: objreader.cpp:78
char * scip_name_
Definition: objreader.h:51
void SCIPreaderSetData(SCIP_READER *reader, SCIP_READERDATA *readerdata)
Definition: reader.c:460
SCIP_READERDATA * SCIPreaderGetData(SCIP_READER *reader)
Definition: reader.c:450
static SCIP_DECL_READERREAD(readerReadObj)
Definition: objreader.cpp:104
#define SCIP_CALL(x)
Definition: def.h:350
scip::ObjReader * SCIPgetObjReader(SCIP *scip, SCIP_READER *reader)
Definition: objreader.cpp:190
struct SCIP_ReaderData SCIP_READERDATA
Definition: type_reader.h:37
#define SCIP_Bool
Definition: def.h:61
static SCIP_DECL_READERWRITE(readerWriteObj)
Definition: objreader.cpp:122
SCIP_RETCODE SCIPincludeReader(SCIP *scip, const char *name, const char *desc, const char *extension, SCIP_DECL_READERCOPY((*readercopy)), SCIP_DECL_READERFREE((*readerfree)), SCIP_DECL_READERREAD((*readerread)), SCIP_DECL_READERWRITE((*readerwrite)), SCIP_READERDATA *readerdata)
Definition: scip.c:5222
SCIP_RETCODE SCIPincludeObjReader(SCIP *scip, scip::ObjReader *objreader, SCIP_Bool deleteobject)
Definition: objreader.cpp:146
char * scip_extension_
Definition: objreader.h:57
static SCIP_DECL_READERCOPY(readerCopyObj)
Definition: objreader.cpp:53
C++ wrapper for file readers and writers.
Definition: objreader.h:42
C++ wrapper for file readers and writers.