Opened 13 years ago

Closed 5 years ago

#6592 closed defect (fixed)

minimize_constrained only takes lambda functions as constraints

Reported by: Robert Miller Owned by: jkantor
Priority: major Milestone: sage-8.0
Component: numerical Keywords:
Cc: Marcelo Forets Merged in:
Authors: Marcelo Forets Reviewers: Travis Scrimshaw
Report Upstream: N/A Work issues:
Branch: 79205d7 (Commits, GitHub, GitLab) Commit: 79205d73c377aef03282ccf5a7c7d749bb649904
Dependencies: Stopgaps:

Status badges

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

Change History (12)

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.11sage-5.12

comment:3 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:4 Changed 8 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:5 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:6 Changed 5 years ago by Marcelo Forets

Cc: Marcelo Forets added

comment:7 Changed 5 years ago by Marcelo Forets

Authors: Marcelo Forets
Branch: u/mforets/6592
Commit: 79205d73c377aef03282ccf5a7c7d749bb649904
Milestone: sage-6.4sage-8.0

New commits:

659e7abaccept symbolic expr as constraints
5434b52add doctest
79205d7some tweaks

comment:8 Changed 5 years ago by Marcelo Forets

Status: newneeds_review

comment:9 Changed 5 years ago by Marcelo Forets

This patch adds code branches for the cases when the constraints are one or more symbolic expressions. There is also some cleanup (PEP-8).

Last edited 5 years ago by Marcelo Forets (previous) (diff)

comment:10 Changed 5 years ago by Travis Scrimshaw

Reviewers: Travis Scrimshaw
Status: needs_reviewpositive_review

The code make sense and fixes the error.

comment:11 in reply to:  10 Changed 5 years ago by Marcelo Forets

Replying to tscrim:

The code make sense and fixes the error.

thanks for reviewing :)

comment:12 Changed 5 years ago by Volker Braun

Branch: u/mforets/659279205d73c377aef03282ccf5a7c7d749bb649904
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.