Changeset 2263


Ignore:
Timestamp:
Feb 5, 2010 10:18:57 AM (10 years ago)
Author:
wehart
Message:

Misc rework of the converter utility to recognize that *.py files have
Pyomo models.

NOTE: If we start working with PuLP, then we might have an issue
distinguishing PuLP vs Pyomo Python files.

Location:
coopr.opt/trunk/coopr/opt/base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • coopr.opt/trunk/coopr/opt/base/convert.py

    r2201 r2263  
    1313import copy
    1414import os
    15 from formats import ProblemFormat
     15from formats import ProblemFormat, guess_format
    1616from error import *
    1717from pyutilib.component.core import *
     
    4848       if os.sep in fname:   #pragma:nocover
    4949          fname = tmp.split(os.sep)[-1]
    50        suffix = fname.split('.')[-1]
    51        try:
    52           if suffix == "lp":
    53              source_ptype = [ProblemFormat.cpxlp]
    54           else:
    55              source_ptype = [getattr(ProblemFormat,suffix)]
    56        except AttributeError:
    57           raise ConverterError, "Unknown suffix type: "+suffix
     50       source_ptype = [guess_format(fname)]
     51       if source_ptype is [None]:
     52            raise ConverterError, "Unknown suffix type: "+suffix
    5853    else:
    5954       source_ptype = args[0].valid_problem_types()
  • coopr.opt/trunk/coopr/opt/base/formats.py

    r1938 r2263  
    1717
    1818#
    19 # pyomo - A coopr.pyomo.PyomoModel object
     19# pyomo - A coopr.pyomo.PyomoModel object, or a *.py file that defines such an object
    2020# cpxlp - A CPLEX LP file
    2121# nl - AMPL *.nl file
     
    5151    formats['osrl']=ResultsFormat.osrl
    5252    formats['soln']=ResultsFormat.soln
    53     formats['yaml']=ResultsFormat.yaml
     53    formats['yml']=ResultsFormat.yaml
    5454    formats['results']=ResultsFormat.yaml
    5555    for fmt in formats:
    5656        if filename.endswith('.'+fmt):
    5757            return formats[fmt]
    58    
     58    return None
     59
Note: See TracChangeset for help on using the changeset viewer.