Go to the documentation of this file.
30 * This file implements the reader/parser used to read the binpacking input data. For more details see \ref BINPACKING_READER.
34 * In the <code>data</code> directory you find a few data files which contain each one binpacking problem. These data
35 * files have the following structure. In the first line the name of the instance is stated. In the second line you find
36 * three integer numbers. The first one gives you the capacity \f$\kappa\f$, the second the number of items, and the
37 * last integer states the value of a known feasible solution. This means an upper bound on the number of needed
40 * For parsing that data, we implemented a reader plugin for \SCIP. A reader has several callback methods and at least
41 * one interface methods (the one including the reader into \SCIP). For our purpose we only implemented the \ref
42 * READERREAD "READERREAD" callback and the interface method which adds the reader plugin to \SCIP.
46 * The interface method <code>SCIPincludeReaderBpa()</code> is called to add the reader plugin to \SCIP (see
47 * cmain.c). This means \SCIP gets informed that this reader is available for reading input files. Therefore, the
48 * function <code>SCIPincludeReader()</code> is called within this method which passes all necessary information of the
49 * reader to SCIP. This information includes the name of the reader, a description, and the file extension for which the
50 * file reader is in charge. In our case we selected the file extension "bpa". This means that all files which have
52 * <code>SCIPincludeReader()</code> also passes for each callback of the reader a function pointers
54 * pointers are used by \SCIP to run the reader. For more information about all available reader callbacks we refer to
56 * we restrict ourself to the callback <code>READERREAD</code> which is the only one we implemented for the binpacking
61 * The READERREAD callback is in charge of parsing a file and creating the problem. To see the list of arguments this
62 * functions gets see the file type_reader.h in the source of \SCIP. The following arguments are of interest in our
63 * case. First of all the \SCIP pointer, the file name, and the SCIP_RESULT pointer. The \SCIP pointer gives us the
64 * current environment. The file name states the file which we should open and parse. Last but not least, the SCIP_RESULT
66 * not. Note that in type_reader.h you also find a list of allowable result values for the SCIP_RESULT pointer and the
71 * The file can be opened and parsed with your favorite methods. In this case we are using the functionality provided by
72 * \SCIP since this has some nice side effects. We are using the function SCIPfopen() which can besides standard
73 * files also handle files which are packed. To find all files related to the parsing of a file, we refer to the file pub_misc.h
74 * in the source of SCIP. Parsing the data out of the file is not that hard. Please look at the code and comments
79 * After parsing the file the final task for the reader is to create the problem. In our case, we pass the collected data
80 * to the \ref probdata_binpacking.h "main problem data plugin". For this, we use the interface methods
82 * problem data plugin (see probdata_binpacking.c). After that, the reader sets the result value for the SCIP_RESULT
93 #include "scip/cons_setppc.h"
95 #include "probdata_binpacking.h"
96 #include "reader_bpa.h"
103 #define READER_NAME "bpareader"
104 #define READER_DESC "file reader for binpacking data format"
105 #define READER_EXTENSION "bpa"
119 SCIP_FILE* file;
120 SCIP_Longint* weights;
122 SCIP_Bool error;
124 char name[SCIP_MAXSTRLEN];
126 char buffer[SCIP_MAXSTRLEN];
135 *result = SCIP_DIDNOTRUN;
138 file = SCIPfopen(filename, "r");
139 if( file == NULL )
141 SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
143 return SCIP_NOFILE;
150 if( !SCIPfeof(file) )
154 return SCIP_READERROR;
158 sprintf(format, "%%%ds\n", SCIP_MAXSTRLEN);
162 SCIPwarningMessage(scip, "invalid input line %d in file <%s>: <%s>\n", lineno, filename, buffer);
163 return SCIP_READERROR;
173 if( !SCIPfeof(file) )
177 return SCIP_READERROR;
184 SCIPwarningMessage(scip, "invalid input line %d in file <%s>: <%s>\n", lineno, filename, buffer);
185 return SCIP_READERROR;
188 SCIPdebugMsg(scip, "capacity = <%d>, number of items = <%d>, best known solution = <%d>\n", capacity, nitems, bestsolvalue);
197 error = FALSE;
199 while( !SCIPfeof(file) && !error )
210 SCIPwarningMessage(scip, "invalid input line %d in file <%s>: <%s>\n", lineno, filename, buffer);
211 error = TRUE;
226 SCIPwarningMessage(scip, "set nitems from <%d> to <%d> since the file <%s> only contains <%d> weights\n", nitems, nweights, filename, nweights);
241 return SCIP_READERROR;
243 *result = SCIP_SUCCESS;
245 return SCIP_OKAY;
261 SCIP_READERDATA* readerdata;
262 SCIP_READER* reader;
265 readerdata = NULL;
268 SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
269 assert(reader != NULL);
273 return SCIP_OKAY;
SCIP_RETCODE SCIPprobdataCreate(SCIP *scip, const char *probname, int *demands, SCIP_Real *rints, SCIP_Real *rexts, int ntypes, SCIP_Real width, SCIP_Real height)
Constraint handler for the set partitioning / packing / covering constraints .
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Problem data for binpacking problem.
Binpacking problem reader file reader.
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))