Exemplo n.º 1
0
 def _cplex_read(cls, filename, verbose=False):
     # print("-> start reading file: {0}".format(filename))
     cpx = _safe_cplex()
     # no warnings
     if not verbose:
         cpx.set_results_stream(None)
         cpx.set_log_stream(None)
         cpx.set_warning_stream(None)
         cpx.set_error_stream(None)  # remove messages about names
     try:
         cpx.read(filename)
         return cpx
     except CplexError as cpx_e:
         raise ModelReaderError("*CPLEX error {0!s} reading file {1} - exiting".format(cpx_e, filename))
Exemplo n.º 2
0
    def __enter__(self):
        cpx = _safe_cplex()
        # no output from CPLEX
        cpx.set_results_stream(None)
        cpx.set_log_stream(None)
        cpx.set_warning_stream(None)
        cpx.set_error_stream(None)
        self_read_fn = cpx
        for m in self._read_method:
            self_read_fn = self_read_fn.__getattribute__(m)

        try:
            self_read_fn(self._filename)
            self._cplex = cpx
            return cpx

        except CplexError as cpx_e:  # pragma: no cover
            # delete cplex instance
            del cpx
            raise ModelReaderError("*CPLEX error {0!s} reading file {1} - exiting".format(cpx_e, self._filename))