|
| 1 | +##@file reader.pxi |
| 2 | +#@brief Base class of the Reader Plugin |
| 3 | +cdef class Reader: |
| 4 | + cdef public Model model |
| 5 | + cdef public str name |
| 6 | + |
| 7 | + def readerfree(self): |
| 8 | + '''calls destructor and frees memory of reader''' |
| 9 | + pass |
| 10 | + |
| 11 | + def readerread(self, filename): |
| 12 | + '''calls read method of reader''' |
| 13 | + return {} |
| 14 | + |
| 15 | + def readerwrite(self, file, name, transformed, objsense, objscale, objoffset, binvars, intvars, |
| 16 | + implvars, contvars, fixedvars, startnvars, conss, maxnconss, startnconss, genericnames): |
| 17 | + '''calls write method of reader''' |
| 18 | + return {} |
| 19 | + |
| 20 | + |
| 21 | +cdef SCIP_RETCODE PyReaderCopy (SCIP* scip, SCIP_READER* reader) with gil: |
| 22 | + return SCIP_OKAY |
| 23 | + |
| 24 | +cdef SCIP_RETCODE PyReaderFree (SCIP* scip, SCIP_READER* reader) with gil: |
| 25 | + cdef SCIP_READERDATA* readerdata |
| 26 | + readerdata = SCIPreaderGetData(reader) |
| 27 | + PyReader = <Reader>readerdata |
| 28 | + PyReader.readerfree() |
| 29 | + Py_DECREF(PyReader) |
| 30 | + return SCIP_OKAY |
| 31 | + |
| 32 | +cdef SCIP_RETCODE PyReaderRead (SCIP* scip, SCIP_READER* reader, const char* filename, SCIP_RESULT* result) with gil: |
| 33 | + cdef SCIP_READERDATA* readerdata |
| 34 | + readerdata = SCIPreaderGetData(reader) |
| 35 | + PyReader = <Reader>readerdata |
| 36 | + PyFilename = filename.decode('utf-8') |
| 37 | + result_dict = PyReader.readerread(PyFilename) |
| 38 | + result[0] = result_dict.get("result", <SCIP_RESULT>result[0]) |
| 39 | + return SCIP_OKAY |
| 40 | + |
| 41 | +cdef SCIP_RETCODE PyReaderWrite (SCIP* scip, SCIP_READER* reader, FILE* file, |
| 42 | + const char* name, SCIP_PROBDATA* probdata, SCIP_Bool transformed, |
| 43 | + SCIP_OBJSENSE objsense, SCIP_Real objscale, SCIP_Real objoffset, |
| 44 | + SCIP_VAR** vars, int nvars, int nbinvars, int nintvars, int nimplvars, int ncontvars, |
| 45 | + SCIP_VAR** fixedvars, int nfixedvars, int startnvars, |
| 46 | + SCIP_CONS** conss, int nconss, int maxnconss, int startnconss, |
| 47 | + SCIP_Bool genericnames, SCIP_RESULT* result) with gil: |
| 48 | + cdef SCIP_READERDATA* readerdata |
| 49 | + readerdata = SCIPreaderGetData(reader) |
| 50 | + cdef int fd = fileno(file) |
| 51 | + PyFile = os.fdopen(fd, "w", closefd=False) |
| 52 | + PyName = name.decode('utf-8') |
| 53 | + PyBinVars = [Variable.create(vars[i]) for i in range(nbinvars)] |
| 54 | + PyIntVars = [Variable.create(vars[i]) for i in range(nbinvars, nintvars)] |
| 55 | + PyImplVars = [Variable.create(vars[i]) for i in range(nintvars, nimplvars)] |
| 56 | + PyContVars = [Variable.create(vars[i]) for i in range(nimplvars, ncontvars)] |
| 57 | + PyFixedVars = [Variable.create(fixedvars[i]) for i in range(nfixedvars)] |
| 58 | + PyConss = [Constraint.create(conss[i]) for i in range(nconss)] |
| 59 | + PyReader = <Reader>readerdata |
| 60 | + result_dict = PyReader.readerwrite(PyFile, PyName, transformed, objsense, objscale, objoffset, |
| 61 | + PyBinVars, PyIntVars, PyImplVars, PyContVars, PyFixedVars, startnvars, |
| 62 | + PyConss, maxnconss, startnconss, genericnames) |
| 63 | + result[0] = result_dict.get("result", <SCIP_RESULT>result[0]) |
| 64 | + return SCIP_OKAY |
0 commit comments