Changeset 729
- Timestamp:
- 08/26/10 15:20:27 (1 year ago)
- Files:
-
- PythonPackages/FuncDesigner/FuncDesigner/examples/lp1.py (modified) (1 diff)
- PythonPackages/FuncDesigner/FuncDesigner/ooFun.py (modified) (1 diff)
- PythonPackages/FuncDesigner/FuncDesigner/overloads.py (modified) (4 diffs)
- PythonPackages/FuncDesigner/FuncDesigner/tests/orders.py (modified) (1 diff)
- PythonPackages/OpenOpt/openopt/kernel/baseProblem.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
PythonPackages/FuncDesigner/FuncDesigner/examples/lp1.py
r593 r729 29 29 30 30 # Decode solution 31 print('Solution: x = %s y = %f z = %f' % ( str(r[x]), r[y], r[z]))31 print('Solution: x = %s y = %f z = %f' % (r(x), r(y), r(z))) 32 32 # Solution: x = [-4.25 -4.25] y = -20.000000 z = 4.000000 PythonPackages/FuncDesigner/FuncDesigner/ooFun.py
r728 r729 957 957 958 958 def getOrder(self, Vars=None, fixedVars=None, fixedVarsScheduleID=-1): 959 960 # TODO: improve it wrt fixedVarsScheduleID 961 959 962 # returns polinomial order of the oofun 960 963 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) 962 965 963 966 if isinstance(fixedVars, oofun): fixedVars = set([fixedVars]) PythonPackages/FuncDesigner/FuncDesigner/overloads.py
r728 r729 111 111 112 112 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) 113 114 r.is_linear = is_linear 114 115 r.isCostly = True … … 241 242 def size(inp, *args, **kwargs): 242 243 if not isinstance(inp, oofun): return np.size(inp, *args, **kwargs) 243 return inp.size ()244 return inp.size 244 245 245 246 def ifThenElse(condition, val1, val2, *args, **kwargs): … … 254 255 return Val1 if condition else Val2 255 256 elif isinstance(condition, oofun): 256 257 #def f(conditionResult, value1Result, value2Result):258 #return value1Result if conditionResult else value2Result259 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 263 257 f = lambda conditionResult, value1Result, value2Result: value1Result if conditionResult else value2Result 264 258 # !!! Don't modify it elseware function will evaluate both expressions despite of condition value 265 259 r = oofun(f, [condition, val1, val2]) 266 #r._getFunc = f267 260 r.D = lambda point, *args, **kwargs: (Val1.D(point, *args, **kwargs) if isinstance(Val1, oofun) else {}) if condition(point) else \ 268 261 (Val2.D(point, *args, **kwargs) if isinstance(Val2, oofun) else {}) … … 270 263 (Val2._D(point, *args, **kwargs) if isinstance(Val2, oofun) else {}) 271 264 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 272 271 return r 273 272 else: PythonPackages/FuncDesigner/FuncDesigner/tests/orders.py
r728 r729 53 53 c17 = a>b; assert c17.getOrder() == inf 54 54 55 # test sin 56 c18 = sin(a); assert c18.getOrder() == inf 57 58 # test ifThenElse 59 c19 = ifThenElse(a>1, a, b); assert c19.getOrder() == inf 60 # TODO: try to set correct value from val1, val2 if condition is fixed 61 55 62 print 'passed' PythonPackages/OpenOpt/openopt/kernel/baseProblem.py
r717 r729 289 289 if not isinstance(self.x0, dict): 290 290 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 292 296 if self.fixedVars is None or (self.optVars is not None and len(self.optVars)<len(self.fixedVars)): 293 297 D_kwargs = {'Vars':self.optVars} … … 372 376 continue 373 377 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: 375 379 self.err('for LP/MILP/LLSP/LLAVP all constraints have to be linear, while ' + f.name + ' is not') 376 380 377 378 381 # TODO: simplify condition of box-bounded oovar detection 379 382 if f.is_oovar:
