source: coopr.opt/trunk/coopr/opt/base/formats.py @ 1938

Last change on this file since 1938 was 1938, checked in by wehart, 10 years ago

Changes to clarify what solver outputs entail. Now, logfiles
are processed whenever available, and other data is processed with
an appropriate reader. The exception is 'soln' files, which
generically refers to solver-specific solution results. These are
parsed with a solver method.

File size: 2.0 KB
Line 
1#  _________________________________________________________________________
2#
3#  Coopr: A COmmon Optimization Python Repository
4#  Copyright (c) 2008 Sandia Corporation.
5#  This software is distributed under the BSD License.
6#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7#  the U.S. Government retains certain rights in this software.
8#  For more information, see the Coopr README.txt file.
9#  _________________________________________________________________________
10
11#
12# The formats that are supported by Pyomo
13#
14__all__ = ['ProblemFormat', 'ResultsFormat', 'guess_format']
15
16from pyutilib.enum import Enum
17
18#
19# pyomo - A coopr.pyomo.PyomoModel object
20# cpxlp - A CPLEX LP file
21# nl - AMPL *.nl file
22# mps - A free-format MPS file
23# mod - AMPL *.mod file
24# lpxlp - A LPSolve LP file
25# ospl - An XML file defined by the COIN-OR OS project
26# colin - A COLIN shell command
27# colin_optproblem - A Python object that inherits from
28#                   coopr.opt.colin.OptProblem (this can wrap a COLIN shell
29#                   command, or provide a runtime optimization problem)
30#
31ProblemFormat = Enum('colin', 'pyomo', 'cpxlp', 'nl', 'mps', 'mod', 'lpxlp', 'ospl', 'colin_optproblem')
32
33#
34# osrl - osrl XML file defined by the COIN-OR OS project
35# results - A Pyomo results object  (reader define by solver class)
36# sol - AMPL *.sol file
37# soln - A solver-specific solution file  (reader define by solver class)
38# yaml - A Pyomo results file in YAML format
39#
40ResultsFormat = Enum('osrl', 'results', 'sol', 'soln', 'yaml')
41
42
43def guess_format(filename):
44    formats = {}
45    formats['py']=ProblemFormat.pyomo
46    formats['nl']=ProblemFormat.nl
47    formats['mps']=ProblemFormat.mps
48    formats['mod']=ProblemFormat.mod
49    formats['lp']=ProblemFormat.cpxlp
50    formats['sol']=ResultsFormat.sol
51    formats['osrl']=ResultsFormat.osrl
52    formats['soln']=ResultsFormat.soln
53    formats['yaml']=ResultsFormat.yaml
54    formats['results']=ResultsFormat.yaml
55    for fmt in formats:
56        if filename.endswith('.'+fmt):
57            return formats[fmt]
58   
Note: See TracBrowser for help on using the repository browser.