Opened 13 years ago

Closed 5 years ago

# minimize_constrained only takes lambda functions as constraints

Reported by: Owned by: Robert Miller jkantor major sage-8.0 numerical Marcelo Forets Marcelo Forets Travis Scrimshaw N/A 79205d7 79205d73c377aef03282ccf5a7c7d749bb649904

### Description

e.g.:

```sage: var('x y')
sage: f = (100 - x) + (1000 - y)
sage: c = x + y - 479 # > 0
sage: minimize_constrained(f,[c],[100,300])
Traceback (most recent call last):
...
UnboundLocalError: local variable 'min' referenced before assignment
```

### comment:1 Changed 13 years ago by Jason Grout

Report Upstream: → N/A

More clearly, here's the "bug" part of this. The documentation says that the function takes a symbolic function, but clearly does not:

```sage: f(x,y) = (100 - x) + (1000 - y)
sage: c = x + y - 479
sage: minimize_constrained(f,[c],[100,300])
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)

/home/grout/<ipython console> in <module>()

/home/grout/sage/local/lib/python2.6/site-packages/sage/numerical/optimize.pyc in minimize_constrained(func, cons, x0, gradient, algorithm, **args)
408     elif isinstance(cons, function_type):
409         min= optimize.fmin_cobyla(f,x0,cons,iprint=0,**args)
--> 410     return vector(RDF,min)
411
412

UnboundLocalError: local variable 'min' referenced before assignment

```

### comment:2 Changed 9 years ago by Jeroen Demeyer

Milestone: sage-5.11 → sage-5.12

### comment:3 Changed 9 years ago by For batch modifications

Milestone: sage-6.1 → sage-6.2

### comment:4 Changed 9 years ago by For batch modifications

Milestone: sage-6.2 → sage-6.3

### comment:5 Changed 8 years ago by For batch modifications

Milestone: sage-6.3 → sage-6.4

### comment:7 Changed 6 years ago by Marcelo Forets

Authors: → Marcelo Forets → u/mforets/6592 → 79205d73c377aef03282ccf5a7c7d749bb649904 sage-6.4 → sage-8.0

New commits:

 ​659e7ab `accept symbolic expr as constraints` ​5434b52 `add doctest` ​79205d7 `some tweaks`

### comment:8 Changed 6 years ago by Marcelo Forets

Status: new → needs_review

### comment:9 Changed 6 years ago by Marcelo Forets

This patch adds code branches for the cases when the constraints are one or more symbolic expressions.

Version 0, edited 6 years ago by Marcelo Forets (next)

### comment:10 follow-up:  11 Changed 5 years ago by Travis Scrimshaw

Reviewers: → Travis Scrimshaw needs_review → positive_review

The code make sense and fixes the error.