Changeset 2935


Ignore:
Timestamp:
Aug 14, 2010 6:38:28 PM (9 years ago)
Author:
wehart
Message:

Merged revisions 2730-2934 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.opt/trunk

........

r2742 | khunter | 2010-06-30 09:49:47 -0600 (Wed, 30 Jun 2010) | 13 lines


Update definition formats of problem/result types


For reference:
(from the Optimization Services Users Manual, available from
https://projects.coin-or.org/OS)

  • OSiL: Optimization Services Instance Language
  • OSoL: Optimization Services Option Language
  • OSnL: Optimization Services Nonlinear Language (pulled into OSiL)
  • OSpL: Optimization Services Process Language
  • OSrL: Optimization Services Result Language


So, the problem format is OSiL, not OSpL.

........

r2764 | khunter | 2010-07-04 19:48:19 -0600 (Sun, 04 Jul 2010) | 5 lines


On the road to Coopr with Python 2.4


Another NFC: Another couple of naive and not-so-naive tricks to
bring to 80 character width code.

........

r2778 | khunter | 2010-07-06 15:31:25 -0600 (Tue, 06 Jul 2010) | 2 lines


Mild NFC refactor, while researching a #3883

........

r2927 | wehart | 2010-08-14 13:48:04 -0600 (Sat, 14 Aug 2010) | 2 lines


Added logic to confirm that a license is available if it has been reserved.

........

Location:
coopr.opt/stable/2.4
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • coopr.opt/stable/2.4

  • coopr.opt/stable/2.4/coopr/opt/base/convert.py

    r2730 r2935  
    3030
    3131
    32 def convert_problem(args, target_problem_type, valid_problem_types, has_capability=lambda x: False):
     32def convert_problem( args, target_problem_type, valid_problem_types,
     33                     has_capability=lambda x: False ):
    3334    """
    3435    Convert a problem, defined by the 'args' tuple, into another problem.
     
    3738    if len(valid_problem_types) == 0:
    3839       raise ConverterError, "No valid problem types"
     40
    3941    if not (target_problem_type is None or \
    4042             target_problem_type in valid_problem_types):
    41        raise ConverterError, "Problem type "+str(target_problem_type)+" is not valid"
     43        msg = "Problem type '%s' is not valid"
     44        raise ConverterError, msg % str( target_problem_type )
     45
    4246    if len(args) == 0:
    4347       raise ConverterError, "Empty argument list"
     
    9599                problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
    96100                return problem_files, ptype, symbol_map
    97     raise ConverterError, "No conversion possible.  Source problem type: %s.  Valid target types: %s" % (str(source_ptype[0]),map(str,valid_ptypes))
    98101
     102    msg = 'No conversion possible.  Source problem type: %s.  Valid target '  \
     103          'types: %s'
     104    raise ConverterError, msg % (str(source_ptype[0]), map(str,valid_ptypes))
  • coopr.opt/stable/2.4/coopr/opt/base/formats.py

    r2263 r2935  
    2323# mod - AMPL *.mod file
    2424# lpxlp - A LPSolve LP file
    25 # ospl - An XML file defined by the COIN-OR OS project
     25# osil - An XML file defined by the COIN-OR OS project: Instance
    2626# colin - A COLIN shell command
    2727# colin_optproblem - A Python object that inherits from
    2828#                   coopr.opt.colin.OptProblem (this can wrap a COLIN shell
    2929#                   command, or provide a runtime optimization problem)
    30 # 
    31 ProblemFormat = Enum('colin', 'pyomo', 'cpxlp', 'nl', 'mps', 'mod', 'lpxlp', 'ospl', 'colin_optproblem')
     30#
     31ProblemFormat = Enum('colin', 'pyomo', 'cpxlp', 'nl', 'mps', 'mod', 'lpxlp', 'osil', 'colin_optproblem', )
    3232
    3333#
    34 # osrl - osrl XML file defined by the COIN-OR OS project
     34# osrl - osrl XML file defined by the COIN-OR OS project: Result
    3535# results - A Pyomo results object  (reader define by solver class)
    3636# sol - AMPL *.sol file
  • coopr.opt/stable/2.4/coopr/opt/solver/ilmcmd.py

    r1768 r2935  
    1717import re
    1818import sys
     19import os
    1920
    2021class ILMLicensedSystemCallSolver(shellcmd.SystemCallSolver):
     
    4041            for line in log.split("\n"):
    4142                tokens = re.split('[\t ]+',line.strip())
    42                 if len(tokens) == 3 and tokens[0] == 'available' and tokens[1] == 'tokens:':
     43                if len(tokens) == 5 and tokens[0] == 'tokens' and tokens[1] == 'reserved:' and tokens[4] == os.environ.get('USER',None):
     44                    if not (tokens[2] == 'none' or tokens[2] == '0'):
     45                        return True
     46                    return False
     47                elif len(tokens) == 3 and tokens[0] == 'available' and tokens[1] == 'tokens:':
    4348                    if tokens[2] == '0':
    4449                        return False
  • coopr.opt/stable/2.4/coopr/opt/solver/shellcmd.py

    r2730 r2935  
    1111__all__ = ['SystemCallSolver']
    1212
     13import os
    1314import sys
    14 import os
     15import time
     16
    1517from coopr.opt.base import *
    1618from coopr.opt.base.solver import *
    1719from coopr.opt.results import SolverStatus, SolverResults
    18 import tempfile
    19 
    20 import pyutilib.common
    21 import pyutilib.services
    22 import pyutilib.subprocess
    23 import pyutilib.component.core
    24 import pyutilib.misc
    25 
    26 import time
     20
     21from pyutilib.common import ApplicationError, WindowsError
     22from pyutilib.component.core import PluginGlobals
     23from pyutilib.misc import Bunch
     24from pyutilib.services import registered_executable, TempfileManager
     25from pyutilib.subprocess import run
     26
    2727
    2828class SystemCallSolver(OptSolver):
    2929    """ A generic command line solver """
    3030
    31     def __init__(self, **kwds):
     31    def __init__(self, **kwargs):
    3232        """ Constructor """
    33         OptSolver.__init__(self, **kwds)
    34         if 'keepFiles' in kwds:
    35             self.keepFiles = kwds['keepFiles']
    36         else:
    37             self.keepFiles = False
    38         self.soln_file=None
    39         self.log_file=None
    40         self._timelimit=None
    41         self._timer=""
     33        OptSolver.__init__(self, **kwargs)
     34        self.keepFiles  = kwargs.pop('keepFiles', False )
     35        self.soln_file  = None
     36        self.log_file   = None
     37        self._timelimit = None
     38        self._timer     = ''
     39
    4240
    4341    def available(self, exception_flag=True):
     
    5149           if exception_flag:
    5250              if self.executable() is None:
    53                  raise pyutilib.common.ApplicationError, "No executable found for solver `"+self.name+"'"
     51                  msg = "No executable found for solver '%s'"
     52                  raise ApplicationError, msg % self.name
    5453              else:
    55                  raise pyutilib.common.ApplicationError, "Bad path for application `PICO' used by solver "+self.name+"': "+self.executable()
     54                  msg = "Bad path for application 'PICO' used by solver %s: " \
     55                       '%s'
     56                  raise ApplicationError, msg % ( self.name, self.executable())
    5657           return False
    5758        return True
     
    7172    def process_soln_file(self,results):
    7273        """
    73         Process auxilliary data files generated by the optimizer (e.g. solution files)
     74        Process auxilliary data files generated by the optimizer (e.g. solution
     75        files)
    7476        """
    7577        return results
     
    9092        OptSolver._presolve(self, *args, **kwds)
    9193        #
    92         # Verify that the input problem exists       
     94        # Verify that the input problem exists
    9395        #
    9496        for filename in self._problem_files:
    9597            if not os.path.exists(filename):
    96                 raise ValueError, "Solver failed to locate input problem file="+filename
     98                msg = 'Solver failed to locate input problem file: %s'
     99                raise ValueError, msg % filename
    97100        #
    98101        # Create command line
    99102        #
    100         self._command = self.create_command_line(self.executable(),self._problem_files)
     103        self._command = self.create_command_line(
     104                              self.executable(), self._problem_files )
    101105        self.log_file=self._command.log_file
    102106        #
     
    108112           os.remove(self.soln_file)
    109113
    110            
     114
    111115    def _apply_solver(self):
    112         if pyutilib.services.registered_executable("timer"):
    113             self._timer=pyutilib.services.registered_executable("timer").get_path()
     116        if registered_executable('timer'):
     117            self._timer = registered_executable('timer').get_path()
    114118        #
    115119        # Execute the command
    116120        #
    117         pyutilib.component.core.PluginGlobals.env("coopr.opt").log.debug("Running "+self._command.cmd)
     121        PluginGlobals.env("coopr.opt").log.debug("Running "+self._command.cmd)
    118122
    119123        # display the log/solver file names prior to execution. this is useful
     
    130134        [rc,log] = self._execute_command(self._command)
    131135        sys.stdout.flush()
    132         self._status = pyutilib.misc.Bunch(rc=rc, log=log)
     136        self._status = Bunch(rc=rc, log=log)
    133137
    134138    def _postsolve(self):
     
    141145           OUTPUT.close()
    142146
    143         # JPW: The cleanup of the problem file probably shouldn't be here, but rather
    144         #      in the base OptSolver class. That would require movement of the keepFiles
    145         #      attribute and associated cleanup logic to the base class, which I didn't
    146         #      feel like doing at this present time. the base class remove_files method
    147         #      should clean up the problem file.           
     147        # JPW: The cleanup of the problem file probably shouldn't be here, but
     148        #   rather in the base OptSolver class. That would require movement of
     149        #   the keepFiles attribute and associated cleanup logic to the base
     150        #   class, which I didn't feel like doing at this present time. the
     151        #   base class remove_files method should clean up the problem file.
    148152
    149153        if self.log_file is not None and not os.path.exists(self.log_file):
    150            raise IOError, "File " + self.log_file + " not generated while executing "+self.path
     154            msg = "File '%s' not generated while executing %s"
     155            raise IOError, msg % ( self.log_file, self.path )
    151156        results = None
    152157        if self._results_format is not None:
    153158           results = self.process_output(self._status.rc)
    154159           if not self.keepFiles:
    155               pyutilib.services.TempfileManager.clear_tempfiles()
     160              TempfileManager.clear_tempfiles()
    156161              # in some cases, the solution filename is not generated via the temp-file mechanism,
    157162              # instead being automatically derived from the input lp/nl filename. so, we may
     
    167172        """
    168173        try:
    169             [rc, log] = pyutilib.subprocess.run(command.cmd, timelimit=self._timelimit, env=command.env, tee=self.tee, shell=True)
    170         except pyutilib.common.WindowsError, err:
    171             raise pyutilib.common.ApplicationError, "Could not execute the command: "+command.cmd+"\tError message: "+str(err)
     174            [rc, log] = run(
     175                command.cmd,
     176                timelimit = self._timelimit,
     177                env   = command.env,
     178                tee   = self.tee,
     179                shell = True
     180             )
     181        except WindowsError, err:
     182            msg = 'Could not execute the command: %s\tError message: %s'
     183            raise ApplicationError, msg % ( command.cmd, str(err) )
    172184        sys.stdout.flush()
    173185        return [rc,log]
     
    187199           self.process_soln_file(results)
    188200           soln_file_completion_time = time.time()
    189            if self._report_timing is True:           
    190               print "Solution file read time="+str(soln_file_completion_time - log_file_completion_time)+" seconds"           
     201           if self._report_timing is True:
     202              print "Solution file read time="+str(soln_file_completion_time - log_file_completion_time)+" seconds"
    191203        else:
    192204           results = self.results_reader(self.results_file, res=results)
    193205           results_reader_completion_time = time.time()
    194206           if self._report_timing is True:
    195                 print "Results reader time="+str(results_reader_completion_time - log_file_completion_time)+" seconds"                     
     207                print "Results reader time="+str(results_reader_completion_time - log_file_completion_time)+" seconds"
    196208        if rc != None:
    197209           results.solver.error_rc=rc
Note: See TracChangeset for help on using the changeset viewer.