Changeset 729

Show
Ignore:
Timestamp:
08/26/10 15:20:27 (1 year ago)
Author:
dmitrey
Message:

some changes, mostly for FD getOrder

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PythonPackages/FuncDesigner/FuncDesigner/examples/lp1.py

    r593 r729  
    2929 
    3030# Decode solution 
    31 print('Solution: x = %s   y = %f  z = %f' % (str(r[x]), r[y], r[z])) 
     31print('Solution: x = %s   y = %f  z = %f' % (r(x), r(y), r(z))) 
    3232# Solution: x = [-4.25 -4.25]   y = -20.000000  z = 4.000000 
  • PythonPackages/FuncDesigner/FuncDesigner/ooFun.py

    r728 r729  
    957957 
    958958    def getOrder(self, Vars=None, fixedVars=None, fixedVarsScheduleID=-1): 
     959         
     960        # TODO: improve it wrt fixedVarsScheduleID 
     961         
    959962        # returns polinomial order of the oofun 
    960963        if isinstance(Vars, oofun): Vars = set([Vars]) 
    961         elif Vars is not None and type(Vars) != set: Vars = set([Vars]
     964        elif Vars is not None and type(Vars) != set: Vars = set(Vars
    962965         
    963966        if isinstance(fixedVars, oofun): fixedVars = set([fixedVars]) 
  • PythonPackages/FuncDesigner/FuncDesigner/overloads.py

    r728 r729  
    111111         
    112112    r = oofun(lambda x, y: x * y if x.size == 1 or y.size == 1 else np.dot(x, y), [inp1, inp2], d=(lambda x, y: aux_d(x, y), lambda x, y: aux_d(y, x))) 
     113    r.getOrder = lambda *args, **kwargs: (x.getOrder(*args, **kwargs) if isinstance(x, oofun) else 0) + (y.getOrder(*args, **kwargs) if isinstance(y, oofun) else 0) 
    113114    r.is_linear = is_linear 
    114115    r.isCostly = True 
     
    241242def size(inp, *args, **kwargs): 
    242243    if not isinstance(inp, oofun): return np.size(inp, *args, **kwargs) 
    243     return inp.size() 
     244    return inp.size 
    244245     
    245246def ifThenElse(condition, val1, val2, *args, **kwargs): 
     
    254255        return Val1 if condition else Val2 
    255256    elif isinstance(condition, oofun): 
    256              
    257         #def f(conditionResult, value1Result, value2Result):  
    258             #return value1Result if conditionResult else value2Result 
    259          
    260          
    261         #f = lambda point: (Val1(point) if isinstance(Val1, oofun) else Val1) if condition(point) else (Val2(point) if isinstance(Val2, oofun) else Val2) 
    262          
    263257        f = lambda conditionResult, value1Result, value2Result: value1Result if conditionResult else value2Result 
    264258        # !!! Don't modify it elseware function will evaluate both expressions despite of condition value  
    265259        r = oofun(f, [condition, val1, val2]) 
    266         #r._getFunc = f 
    267260        r.D = lambda point, *args, **kwargs: (Val1.D(point, *args, **kwargs) if isinstance(Val1, oofun) else {}) if condition(point) else \ 
    268261        (Val2.D(point, *args, **kwargs) if isinstance(Val2, oofun) else {}) 
     
    270263        (Val2._D(point, *args, **kwargs) if isinstance(Val2, oofun) else {}) 
    271264        r.d = errFunc 
     265         
     266        # TODO: try to set correct value from val1, val2 if condition is fixed 
     267#        def getOrder(Vars=None, fixedVars=None, *args, **kwargs): 
     268#            dep = condition.getDep() 
     269#            if Vars is not None and dep.is 
     270 
    272271        return r 
    273272    else: 
  • PythonPackages/FuncDesigner/FuncDesigner/tests/orders.py

    r728 r729  
    5353c17 = a>b; assert c17.getOrder() == inf 
    5454 
     55# test sin 
     56c18 = sin(a); assert c18.getOrder() == inf 
     57 
     58# test ifThenElse 
     59c19 = ifThenElse(a>1, a, b); assert c19.getOrder() == inf 
     60# TODO: try to set correct value from val1, val2 if condition is fixed 
     61 
    5562print 'passed' 
  • PythonPackages/OpenOpt/openopt/kernel/baseProblem.py

    r717 r729  
    289289            if not isinstance(self.x0, dict): 
    290290                self.err('Unexpected start point type: Python dict expected, '+ str(type(self.x0)) + ' obtained') 
    291              
     291 
     292            if self.probType in ['LP', 'MILP'] and self.f.getOrder(self.optVars, self.fixedVars) > 1: 
     293                self.err('for LP/MILP objective function has to be linear, while this one ("%s") is not' % self.f.name) 
     294 
     295 
    292296            if self.fixedVars is None or (self.optVars is not None and len(self.optVars)<len(self.fixedVars)): 
    293297                D_kwargs = {'Vars':self.optVars} 
     
    372376                    continue 
    373377 
    374                 if self.probType in ['LP', 'MILP', 'LLSP', 'LLAVP'] and not f.is_linear
     378                if self.probType in ['LP', 'MILP', 'LLSP', 'LLAVP'] and f.getOrder(self.optVars, self.fixedVars) > 1
    375379                    self.err('for LP/MILP/LLSP/LLAVP all constraints have to be linear, while ' + f.name + ' is not') 
    376380                 
    377                      
    378381                # TODO: simplify condition of box-bounded oovar detection 
    379382                if f.is_oovar: