Exemple #1
0
    def load(self,
             arg,
             namespaces=[None],
             profile_memory=0,
             report_timing=False):
        """
        Load the model with data from a file, dictionary or DataPortal object.
        """
        if arg is None or isinstance(arg, basestring):
            dp = DataPortal(filename=arg, model=self)
        elif type(arg) is DataPortal:
            dp = arg
        elif type(arg) is dict:
            dp = DataPortal(data_dict=arg, model=self)
        elif isinstance(arg, SolverResults):
            if len(arg.solution):
                logger.warning(
                    """DEPRECATION WARNING: the Model.load() method is deprecated for
loading solutions stored in SolverResults objects.  Call
Model.solutions.load_from().""")
                self.solutions.load_from(arg)
            else:
                logger.warning(
                    """DEPRECATION WARNING: the Model.load() method is deprecated for
loading solutions stored in SolverResults objects.  By default, results
from solvers are immediately loaded into the original model instance.""")
            return
        else:
            msg = "Cannot load model model data from with object of type '%s'"
            raise ValueError(msg % str(type(arg)))
        self._load_model_data(dp,
                              namespaces,
                              profile_memory=profile_memory,
                              report_timing=report_timing)
Exemple #2
0
 def load(self,
          arg,
          namespaces=[None],
          profile_memory=0,
          report_timing=False):
     """
     Load the model with data from a file, dictionary or DataPortal object.
     """
     if arg is None or isinstance(arg, basestring):
         dp = DataPortal(filename=arg, model=self)
     elif type(arg) is DataPortal:
         dp = arg
     elif type(arg) is dict:
         dp = DataPortal(data_dict=arg, model=self)
     elif isinstance(arg, SolverResults):
         logger.warning("DEPRECATION WARNING: the Model.load() method "
                        "should not be used to load solver results. "
                        "Call Model.solutions.load_from().")
         self.solutions.load_from(arg)
         return
     else:
         msg = "Cannot load model model data from with object of type '%s'"
         raise ValueError(msg % str(type(arg)))
     self._load_model_data(dp,
                           namespaces,
                           profile_memory=profile_memory,
                           report_timing=report_timing)