Go to the documentation of this file.
21 * This file implements the reader/parser used to read the binpacking input data. For more details see \ref BINPACKING_READER.
25 * In the <code>data</code> directory you find a few data files which contain each one binpacking problem. These data
26 * files have the following structure. In the first line the name of the instance is stated. In the second line you find
27 * three integer numbers. The first one gives you the capacity \f$\kappa\f$, the second the number of items, and the
28 * last integer states the value of a known feasible solution. This means an upper bound on the number of needed
31 * For parsing that data, we implemented a reader plugin for \SCIP. A reader has several callback methods and at least
32 * one interface methods (the one including the reader into \SCIP). For our purpose we only implemented the \ref
33 * READERREAD "READERREAD" callback and the interface method which adds the reader plugin to \SCIP.
37 * The interface method <code>SCIPincludeReaderBpa()</code> is called to add the reader plugin to \SCIP (see
38 * cmain.c). This means \SCIP gets informed that this reader is available for reading input files. Therefore, the
39 * function <code>SCIPincludeReader()</code> is called within this method which passes all necessary information of the
40 * reader to SCIP. This information includes the name of the reader, a description, and the file extension for which the
41 * file reader is in charge. In our case we selected the file extension "bpa". This means that all files which have
43 * <code>SCIPincludeReader()</code> also passes for each callback of the reader a function pointers
45 * pointers are used by \SCIP to run the reader. For more information about all available reader callbacks we refer to
47 * we restrict ourself to the callback <code>READERREAD</code> which is the only one we implemented for the binpacking
52 * The READERREAD callback is in charge of parsing a file and creating the problem. To see the list of arguments this
53 * functions gets see the file type_reader.h in the source of \SCIP. The following arguments are of interest in our
54 * case. First of all the \SCIP pointer, the file name, and the SCIP_RESULT pointer. The \SCIP pointer gives us the
55 * current environment. The file name states the file which we should open and parse. Last but not least, the SCIP_RESULT
57 * not. Note that in type_reader.h you also find a list of allowable result values for the SCIP_RESULT pointer and the
62 * The file can be opened and parsed with your favorite methods. In this case we are using the functionality provided by
63 * \SCIP since this has some nice side effects. We are using the function SCIPfopen() which can besides standard
64 * 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
65 * in the source of SCIP. Parsing the data out of the file is not that hard. Please look at the code and comments
70 * After parsing the file the final task for the reader is to create the problem. In our case, we pass the collected data
71 * to the \ref probdata_binpacking.h "main problem data plugin". For this, we use the interface methods
73 * problem data plugin (see probdata_binpacking.c). After that, the reader sets the result value for the SCIP_RESULT
84 #include "scip/cons_setppc.h"
86 #include "probdata_binpacking.h"
87 #include "reader_bpa.h"
94 #define READER_NAME "bpareader"
95 #define READER_DESC "file reader for binpacking data format"
96 #define READER_EXTENSION "bpa"
110 SCIP_FILE* file;
111 SCIP_Longint* weights;
113 SCIP_Bool error;
115 char name[SCIP_MAXSTRLEN];
117 char buffer[SCIP_MAXSTRLEN];
126 *result = SCIP_DIDNOTRUN;
129 file = SCIPfopen(filename, "r");
130 if( file == NULL )
132 SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
134 return SCIP_NOFILE;
141 if( !SCIPfeof(file) )
145 return SCIP_READERROR;
149 sprintf(format, "%%%ds\n", SCIP_MAXSTRLEN);
153 SCIPwarningMessage(scip, "invalid input line %d in file <%s>: <%s>\n", lineno, filename, buffer);
154 return SCIP_READERROR;
164 if( !SCIPfeof(file) )
168 return SCIP_READERROR;
175 SCIPwarningMessage(scip, "invalid input line %d in file <%s>: <%s>\n", lineno, filename, buffer);
176 return SCIP_READERROR;
179 SCIPdebugMsg(scip, "capacity = <%d>, number of items = <%d>, best known solution = <%d>\n", capacity, nitems, bestsolvalue);
188 error = FALSE;
190 while( !SCIPfeof(file) && !error )
201 SCIPwarningMessage(scip, "invalid input line %d in file <%s>: <%s>\n", lineno, filename, buffer);
202 error = TRUE;
217 SCIPwarningMessage(scip, "set nitems from <%d> to <%d> since the file <%s> only contains <%d> weights\n", nitems, weights, filename, weights);
232 return SCIP_READERROR;
234 *result = SCIP_SUCCESS;
236 return SCIP_OKAY;
252 SCIP_READERDATA* readerdata;
253 SCIP_READER* reader;
256 readerdata = NULL;
259 SCIP_CALL( SCIPincludeReaderBasic(scip, &reader, READER_NAME, READER_DESC, READER_EXTENSION, readerdata) );
260 assert(reader != NULL);
264 return SCIP_OKAY;
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE SCIPsetReaderRead(SCIP *scip, SCIP_READER *reader, SCIP_DECL_READERREAD((*readerread)))
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 .
Problem data for binpacking problem.
SCIP_RETCODE SCIPincludeReaderBasic(SCIP *scip, SCIP_READER **readerptr, const char *name, const char *desc, const char *extension, SCIP_READERDATA *readerdata)
Binpacking problem reader file reader.