Changeset 3016


Ignore:
Timestamp:
Sep 16, 2010 2:56:50 PM (11 years ago)
Author:
wehart
Message:

Bug fix: allow set tuple templates with multiple wildcard dimension.

Location:
coopr.pyomo/trunk/coopr/pyomo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/data/process_data.py

    r3009 r3016  
    111111        ans=[]
    112112        i=0
    113         flag=type(cmd[0]) is tuple
    114113        tmp=None
    115         ndx=None
     114        ndx=[]
    116115        while i<len(cmd):
    117116          if type(cmd[i]) is not tuple:
    118             if flag:
     117            if len(ndx) > 0:
    119118               #if type(cmd[i]) is not tuple:
    120119               #   raise ValueError, "Problem initializing set="+sname+" with input data="+str(cmd)+" - first element was interpreted as a tuple, but element="+str(i)+" is of type="+str(type(cmd[i]))+"; types must be consistent"
    121120               tmpval=tmp
    122                tmpval[ndx] = _data_eval([cmd[i]])[0]
     121               for kk in range(len(ndx)):
     122                    if i == len(cmd):
     123                        raise IOError, "Expected another set value to flush out a tuple pattern!"
     124                    tmpval[ndx[kk]] = _data_eval([cmd[i]])[0]
     125                    i += 1
    123126               #
    124127               # WEH - I'm not sure what the next two lines are for
     
    128131               #   tmpval = util.tuplize(tmpval,d,sname)
    129132               ans.append(tuple(tmpval))
     133               continue
    130134            else:
    131135               ans.append(cmd[i])
     
    135139            j = i
    136140            tmp=list(cmd[j])
    137             ndx=tmp.index("*")
     141            ndx=[]
     142            for kk in range(len(tmp)):
     143                if tmp[kk] == '*':
     144                    ndx.append(kk)
     145            #print 'NDX',ndx
    138146          i += 1
    139147        if pyomo.debug("reader"):               #pragma:nocover
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_set.py

    r2867 r3016  
    21112111        self.failUnlessEqual( len(self.instance.F.keys()), 3)
    21122112        self.failUnlessEqual( len(self.instance.F['A1']), 3)
     2113
     2114    def test_io8(self):
     2115        OUTPUT=open(currdir+"setA.dat","w")
     2116        print >>OUTPUT, "data;"
     2117        print >>OUTPUT, "set E :="
     2118        print >>OUTPUT, "(A1,1,*) A1 A2"
     2119        print >>OUTPUT, "(*,2,*) A2 A3"
     2120        print >>OUTPUT, "(A3,3,*) A1 A3 ;"
     2121        print >>OUTPUT, "end;"
     2122        OUTPUT.close()
     2123        self.model.E = Set(dimen=3)
     2124        self.instance = self.model.create(currdir+"setA.dat")
     2125        self.failUnlessEqual( len(self.instance.E), 5)
     2126
     2127    def test_io9(self):
     2128        OUTPUT=open(currdir+"setA.dat","w")
     2129        print >>OUTPUT, "data;"
     2130        print >>OUTPUT, "set E :="
     2131        print >>OUTPUT, "(A1,1,A1) (A1,1,A2)"
     2132        print >>OUTPUT, "(A2,2,A3)"
     2133        print >>OUTPUT, "(A3,3,A1) (A3,3,A3) ;"
     2134        print >>OUTPUT, "end;"
     2135        OUTPUT.close()
     2136        self.model.E = Set(dimen=3)
     2137        self.instance = self.model.create(currdir+"setA.dat")
     2138        self.failUnlessEqual( len(self.instance.E), 5)
    21132139
    21142140
Note: See TracChangeset for help on using the changeset viewer.