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-2024 Zuse Institute Berlin (ZIB) */
7/* */
8/* Licensed under the Apache License, Version 2.0 (the "License"); */
9/* you may not use this file except in compliance with the License. */
10/* You may obtain a copy of the License at */
11/* */
12/* http://www.apache.org/licenses/LICENSE-2.0 */
13/* */
14/* Unless required by applicable law or agreed to in writing, software */
15/* distributed under the License is distributed on an "AS IS" BASIS, */
16/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17/* See the License for the specific language governing permissions and */
18/* limitations under the License. */
19/* */
20/* You should have received a copy of the Apache-2.0 license */
21/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22/* */
23/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25/**@file objreader.cpp
26 * @brief C++ wrapper for file readers and writers
27 * @author Tobias Achterberg
28 */
29
30/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31
32#include <cassert>
33
34#include "objreader.h"
35
36
37
38
39/*
40 * Data structures
41 */
42
43/** file reader data */
44struct SCIP_ReaderData
45{
46 scip::ObjReader* objreader; /**< file reader object */
47 SCIP_Bool deleteobject; /**< should the reader object be deleted when reader is freed? */
48};
49
50
51
52
53/*
54 * Callback methods of file reader
55 */
56
57extern "C"
58{
59
60/** copy method for reader plugins (called when SCIP copies plugins) */
61static
63{ /*lint --e{715}*/
64 SCIP_READERDATA* readerdata;
65
66 assert(scip != NULL);
67
68 readerdata = SCIPreaderGetData(reader);
69 assert(readerdata != NULL);
70 assert(readerdata->objreader != NULL);
71 assert(readerdata->objreader->scip_ != scip);
72
73 if( readerdata->objreader->iscloneable() )
74 {
75 scip::ObjReader* newobjreader;
76 newobjreader = dynamic_cast<scip::ObjReader*> (readerdata->objreader->clone(scip));
77
78 /* call include method of reader object */
79 SCIP_CALL( SCIPincludeObjReader(scip, newobjreader, TRUE) );
80 }
81
82 return SCIP_OKAY;
83}
84
85/** destructor of file reader to free user data (called when SCIP is exiting) */
86static
88{ /*lint --e{715}*/
89 SCIP_READERDATA* readerdata;
90
91 readerdata = SCIPreaderGetData(reader);
92 assert(readerdata != NULL);
93 assert(readerdata->objreader != NULL);
94 assert(readerdata->objreader->scip_ == scip);
95
96 /* call virtual method of reader object */
97 SCIP_CALL( readerdata->objreader->scip_free(scip, reader) );
98
99 /* free reader object */
100 if( readerdata->deleteobject )
101 delete readerdata->objreader;
102
103 /* free reader data */
104 delete readerdata;
105 SCIPreaderSetData(reader, NULL); /*lint !e64*/
106
107 return SCIP_OKAY;
108}
109
110
111/** problem reading method of reader */
112static
114{ /*lint --e{715}*/
115 SCIP_READERDATA* readerdata;
116
117 readerdata = SCIPreaderGetData(reader);
118 assert(readerdata != NULL);
119 assert(readerdata->objreader != NULL);
120 assert(readerdata->objreader->scip_ == scip);
121
122 /* call virtual method of reader object */
123 SCIP_CALL( readerdata->objreader->scip_read(scip, reader, filename, result) );
124
125 return SCIP_OKAY;
126}
127
128
129/** problem writing method of reader */
130static
132{ /*lint --e{715}*/
133 SCIP_READERDATA* readerdata;
134
135 readerdata = SCIPreaderGetData(reader);
136 assert(readerdata != NULL);
137 assert(readerdata->objreader != NULL);
138
139 /* call virtual method of reader object */
140 SCIP_CALL( readerdata->objreader->scip_write(scip, reader, file, name, probdata, transformed,
141 objsense, objscale, objoffset,
142 vars, nvars, nbinvars, nintvars, nimplvars, ncontvars, fixedvars, nfixedvars, startnvars,
143 conss, nconss, maxnconss, startnconss, genericnames, result) );
144
145 return SCIP_OKAY;
146}
147}
148
149
150/*
151 * file reader specific interface methods
152 */
153
154/** creates the file reader for the given file reader object and includes it in SCIP */
156 SCIP* scip, /**< SCIP data structure */
157 scip::ObjReader* objreader, /**< file reader object */
158 SCIP_Bool deleteobject /**< should the reader object be deleted when reader is freed? */
159 )
160{
161 SCIP_READERDATA* readerdata;
162
163 assert(scip != NULL);
164 assert(objreader != NULL);
165
166 /* create file reader data */
167 readerdata = new SCIP_READERDATA;
168 readerdata->objreader = objreader;
169 readerdata->deleteobject = deleteobject;
170
171 /* include file reader */
172 SCIP_CALL( SCIPincludeReader(scip, objreader->scip_name_, objreader->scip_desc_, objreader->scip_extension_,
173 readerCopyObj,
174 readerFreeObj, readerReadObj, readerWriteObj, readerdata) ); /*lint !e429*/
175
176 return SCIP_OKAY; /*lint !e429*/
177}
178
179/** returns the reader object of the given name, or 0 if not existing */
181 SCIP* scip, /**< SCIP data structure */
182 const char* name /**< name of file reader */
183 )
184{
185 SCIP_READER* reader;
186 SCIP_READERDATA* readerdata;
187
188 reader = SCIPfindReader(scip, name);
189 if( reader == NULL )
190 return 0;
191
192 readerdata = SCIPreaderGetData(reader);
193 assert(readerdata != NULL);
194
195 return readerdata->objreader;
196}
197
198/** returns the reader object for the given file reader */
200 SCIP* scip, /**< SCIP data structure */
201 SCIP_READER* reader /**< file reader */
202 )
203{
204 SCIP_READERDATA* readerdata;
205
206 assert(scip != NULL);
207 readerdata = SCIPreaderGetData(reader);
208 assert(readerdata != NULL);
209
210 return readerdata->objreader;
211}
C++ wrapper for file readers and writers.
Definition: objreader.h:53
char * scip_extension_
Definition: objreader.h:67
char * scip_name_
Definition: objreader.h:61
char * scip_desc_
Definition: objreader.h:64
#define NULL
Definition: def.h:267
#define SCIP_Bool
Definition: def.h:91
#define TRUE
Definition: def.h:93
#define SCIP_CALL(x)
Definition: def.h:374
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:66
SCIP_READERDATA * SCIPreaderGetData(SCIP_READER *reader)
Definition: reader.c:492
SCIP_READER * SCIPfindReader(SCIP *scip, const char *name)
Definition: scip_reader.c:235
void SCIPreaderSetData(SCIP_READER *reader, SCIP_READERDATA *readerdata)
Definition: reader.c:502
SCIP_RETCODE SCIPincludeObjReader(SCIP *scip, scip::ObjReader *objreader, SCIP_Bool deleteobject)
Definition: objreader.cpp:155
static SCIP_DECL_READERREAD(readerReadObj)
Definition: objreader.cpp:113
scip::ObjReader * SCIPfindObjReader(SCIP *scip, const char *name)
Definition: objreader.cpp:180
static SCIP_DECL_READERFREE(readerFreeObj)
Definition: objreader.cpp:87
static SCIP_DECL_READERCOPY(readerCopyObj)
Definition: objreader.cpp:62
scip::ObjReader * SCIPgetObjReader(SCIP *scip, SCIP_READER *reader)
Definition: objreader.cpp:199
static SCIP_DECL_READERWRITE(readerWriteObj)
Definition: objreader.cpp:131
C++ wrapper for file readers and writers.
struct SCIP_ReaderData SCIP_READERDATA
Definition: type_reader.h:53
@ SCIP_OKAY
Definition: type_retcode.h:42
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:63