Scippy

SCIP

Solving Constraint Integer Programs

scip_reader.c
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-2019 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 visit scip.zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file scip_reader.c
17  * @brief public methods for reader plugins
18  * @author Tobias Achterberg
19  * @author Timo Berthold
20  * @author Gerald Gamrath
21  * @author Robert Lion Gottwald
22  * @author Stefan Heinz
23  * @author Gregor Hendel
24  * @author Thorsten Koch
25  * @author Alexander Martin
26  * @author Marc Pfetsch
27  * @author Michael Winkler
28  * @author Kati Wolter
29  *
30  * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
31  */
32 
33 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
34 
35 #include "scip/debug.h"
36 #include "scip/pub_message.h"
37 #include "scip/reader.h"
38 #include "scip/scip_reader.h"
39 #include "scip/set.h"
40 #include "scip/struct_scip.h"
41 #include "scip/struct_set.h"
42 
43 /** creates a reader and includes it in SCIP
44  *
45  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
46  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
47  *
48  * @pre This method can be called if SCIP is in one of the following stages:
49  * - \ref SCIP_STAGE_INIT
50  * - \ref SCIP_STAGE_PROBLEM
51  *
52  * @note method has all reader callbacks as arguments and is thus changed every time a new callback is added
53  * in future releases; consider using SCIPincludeReaderBasic() and setter functions
54  * if you seek for a method which is less likely to change in future releases
55  */
57  SCIP* scip, /**< SCIP data structure */
58  const char* name, /**< name of reader */
59  const char* desc, /**< description of reader */
60  const char* extension, /**< file extension that reader processes */
61  SCIP_DECL_READERCOPY ((*readercopy)), /**< copy method of reader or NULL if you don't want to copy your plugin into sub-SCIPs */
62  SCIP_DECL_READERFREE ((*readerfree)), /**< destructor of reader */
63  SCIP_DECL_READERREAD ((*readerread)), /**< read method */
64  SCIP_DECL_READERWRITE ((*readerwrite)), /**< write method */
65  SCIP_READERDATA* readerdata /**< reader data */
66  )
67 {
68  SCIP_READER* reader;
69 
70  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeReader", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
71 
72  /* check whether reader is already present */
73  if( SCIPfindReader(scip, name) != NULL )
74  {
75  SCIPerrorMessage("reader <%s> already included.\n", name);
76  return SCIP_INVALIDDATA;
77  }
78 
79  SCIP_CALL( SCIPreaderCreate(&reader, scip->set, name, desc, extension, readercopy, readerfree, readerread,
80  readerwrite, readerdata) );
81  SCIP_CALL( SCIPsetIncludeReader(scip->set, reader) );
82 
83  return SCIP_OKAY;
84 }
85 
86 /** creates a reader and includes it in SCIP. All non-fundamental (or optional) callbacks will be set to NULL.
87  * Optional callbacks can be set via specific setter functions, see
88  * SCIPsetReaderCopy(), SCIPsetReaderFree(), SCIPsetReaderRead(), SCIPsetReaderWrite().
89  *
90  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
91  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
92  *
93  * @pre This method can be called if SCIP is in one of the following stages:
94  * - \ref SCIP_STAGE_INIT
95  * - \ref SCIP_STAGE_PROBLEM
96  *
97  * @note if you want to set all callbacks with a single method call, consider using SCIPincludeReader() instead
98  */
100  SCIP* scip, /**< SCIP data structure */
101  SCIP_READER** readerptr, /**< reference to reader pointer, or NULL */
102  const char* name, /**< name of reader */
103  const char* desc, /**< description of reader */
104  const char* extension, /**< file extension that reader processes */
105  SCIP_READERDATA* readerdata /**< reader data */
106  )
107 {
108  SCIP_READER* reader;
109 
110  SCIP_CALL( SCIPcheckStage(scip, "SCIPincludeReaderBasic", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
111 
112  /* check whether reader is already present */
113  if( SCIPfindReader(scip, name) != NULL )
114  {
115  SCIPerrorMessage("reader <%s> already included.\n", name);
116  return SCIP_INVALIDDATA;
117  }
118 
119  SCIP_CALL( SCIPreaderCreate(&reader, scip->set, name, desc, extension, NULL, NULL, NULL, NULL, readerdata) );
120  SCIP_CALL( SCIPsetIncludeReader(scip->set, reader) );
121 
122  if( readerptr != NULL )
123  *readerptr = reader;
124 
125  return SCIP_OKAY;
126 }
127 
128 /** set copy method of reader
129  *
130  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
131  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
132  *
133  * @pre This method can be called if SCIP is in one of the following stages:
134  * - \ref SCIP_STAGE_INIT
135  * - \ref SCIP_STAGE_PROBLEM
136  */
138  SCIP* scip, /**< SCIP data structure */
139  SCIP_READER* reader, /**< reader */
140  SCIP_DECL_READERCOPY ((*readercopy)) /**< copy method of reader or NULL if you don't want to copy your plugin into sub-SCIPs */
141  )
142 {
143  assert(scip != NULL);
144 
145  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetReaderCopy", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
146 
147  SCIPreaderSetCopy(reader, readercopy);
148 
149  return SCIP_OKAY;
150 }
151 
152 /** set deinitialization method of reader
153  *
154  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
155  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
156  *
157  * @pre This method can be called if SCIP is in one of the following stages:
158  * - \ref SCIP_STAGE_INIT
159  * - \ref SCIP_STAGE_PROBLEM
160  */
162  SCIP* scip, /**< SCIP data structure */
163  SCIP_READER* reader, /**< reader */
164  SCIP_DECL_READERFREE ((*readerfree)) /**< destructor of reader */
165  )
166 {
167  assert(scip != NULL);
168 
169  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetReaderFree", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
170 
171  SCIPreaderSetFree(reader, readerfree);
172 
173  return SCIP_OKAY;
174 }
175 
176 /** set read method of reader
177  *
178  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
179  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
180  *
181  * @pre This method can be called if SCIP is in one of the following stages:
182  * - \ref SCIP_STAGE_INIT
183  * - \ref SCIP_STAGE_PROBLEM
184  */
186  SCIP* scip, /**< SCIP data structure */
187  SCIP_READER* reader, /**< reader */
188  SCIP_DECL_READERREAD ((*readerread)) /**< read method of reader */
189  )
190 {
191  assert(scip != NULL);
192 
193  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetReaderRead", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
194 
195  SCIPreaderSetRead(reader, readerread);
196 
197  return SCIP_OKAY;
198 }
199 
200 /** set write method of reader
201  *
202  * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
203  * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
204  *
205  * @pre This method can be called if SCIP is in one of the following stages:
206  * - \ref SCIP_STAGE_INIT
207  * - \ref SCIP_STAGE_PROBLEM
208  */
210  SCIP* scip, /**< SCIP data structure */
211  SCIP_READER* reader, /**< reader */
212  SCIP_DECL_READERWRITE ((*readerwrite)) /**< write method of reader */
213  )
214 {
215  assert(scip != NULL);
216 
217  SCIP_CALL( SCIPcheckStage(scip, "SCIPsetReaderWrite", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE) );
218 
219  SCIPreaderSetWrite(reader, readerwrite);
220 
221  return SCIP_OKAY;
222 }
223 
224 /** returns the reader of the given name, or NULL if not existing */
226  SCIP* scip, /**< SCIP data structure */
227  const char* name /**< name of reader */
228  )
229 {
230  assert(scip != NULL);
231  assert(scip->set != NULL);
232  assert(name != NULL);
233 
234  return SCIPsetFindReader(scip->set, name);
235 }
236 
237 /** returns the array of currently available readers */
239  SCIP* scip /**< SCIP data structure */
240  )
241 {
242  assert(scip != NULL);
243  assert(scip->set != NULL);
244 
245  return scip->set->readers;
246 }
247 
248 /** returns the number of currently available readers */
250  SCIP* scip /**< SCIP data structure */
251  )
252 {
253  assert(scip != NULL);
254  assert(scip->set != NULL);
255 
256  return scip->set->nreaders;
257 }
SCIP_READER ** SCIPgetReaders(SCIP *scip)
Definition: scip_reader.c:238
#define NULL
Definition: def.h:253
SCIP_READER ** readers
Definition: struct_set.h:68
void SCIPreaderSetCopy(SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
Definition: reader.c:503
void SCIPreaderSetFree(SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
Definition: reader.c:514
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
Definition: scip_reader.c:185
#define FALSE
Definition: def.h:73
SCIP_RETCODE SCIPsetReaderCopy(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERCOPY((*readercopy)))
Definition: scip_reader.c:137
#define TRUE
Definition: def.h:72
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
SCIP_DECL_READERWRITE(ReaderTSP::scip_write)
Definition: ReaderTSP.cpp:483
SCIP_RETCODE SCIPreaderCreate(SCIP_READER **reader, SCIP_SET *set, 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: reader.c:103
SCIP_RETCODE SCIPsetReaderWrite(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERWRITE((*readerwrite)))
Definition: scip_reader.c:209
#define SCIPerrorMessage
Definition: pub_message.h:45
int SCIPgetNReaders(SCIP *scip)
Definition: scip_reader.c:249
SCIP_RETCODE SCIPcheckStage(SCIP *scip, const char *method, SCIP_Bool init, SCIP_Bool problem, SCIP_Bool transforming, SCIP_Bool transformed, SCIP_Bool initpresolve, SCIP_Bool presolving, SCIP_Bool exitpresolve, SCIP_Bool presolved, SCIP_Bool initsolve, SCIP_Bool solving, SCIP_Bool solved, SCIP_Bool exitsolve, SCIP_Bool freetrans, SCIP_Bool freescip)
Definition: debug.c:2010
void SCIPreaderSetRead(SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
Definition: reader.c:525
SCIP_RETCODE SCIPsetReaderFree(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERFREE((*readerfree)))
Definition: scip_reader.c:161
internal methods for global SCIP settings
#define SCIP_CALL(x)
Definition: def.h:365
SCIP main data structure.
SCIP_READER * SCIPsetFindReader(SCIP_SET *set, const char *name)
Definition: set.c:3575
SCIP_READER * SCIPfindReader(SCIP *scip, const char *name)
Definition: scip_reader.c:225
struct SCIP_ReaderData SCIP_READERDATA
Definition: type_reader.h:39
void SCIPreaderSetWrite(SCIP_READER *reader, SCIP_DECL_READERWRITE((*readerwrite)))
Definition: reader.c:536
internal methods for input file readers
int nreaders
Definition: struct_set.h:97
methods for debugging
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_reader.c:56
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Definition: scip_reader.c:99
#define SCIP_DECL_READERCOPY(x)
Definition: type_reader.h:48
SCIP_SET * set
Definition: struct_scip.h:62
public methods for message output
SCIP_RETCODE SCIPsetIncludeReader(SCIP_SET *set, SCIP_READER *reader)
Definition: set.c:3553
#define SCIP_DECL_READERREAD(x)
Definition: type_reader.h:73
public methods for reader plugins
datastructures for global SCIP settings
#define SCIP_DECL_READERFREE(x)
Definition: type_reader.h:57