root/PythonPackages/OpenOpt/openopt/doc/probAssign.py

Revision 935, 1.5 kB (checked in by dmitrey, 1 year ago)

minor doc change

Line 
1 # Problem assignment in OpenOpt is performed in the following way:
2 from openopt import NLP
3 # or other constructor names: LP, MILP, QP etc,
4 # for full list see http://openopt.org/Problems
5 # p = NLP(*args, **kwargs)
6
7 """
8 you should read help(NLP) for more details,
9 also reading /examples/nlp_1.py and other files from the directory is highly recommended
10
11 Each class has some expected arguments
12 e.g. for NLP it's f and x0 - objective function and start point
13 thus using NLP(myFunc, myStartPoint) will assign myFunc to f and myStartPoint to x0 prob fields
14
15 alternatively, you could use it as kwargs, possibly along with some other kwargs:
16 """
17
18 p = NLP(x0=15, f = lambda x: x**2-0.4, df = lambda x: 2*x, iprint = 0, plot = 1)
19
20 # after the problem is assigned, you could turn the parameters,
21 # along with some other that have been set as defaults:
22
23 p.x0 = 0.15
24 p.plot = 0
25
26 def f(x):
27     return x if x>0 else x**2
28 p.f = f
29
30 # At last, you can modify any prob parameters in minimize/maximize/solve/manage functions:
31
32 r = p.minimize('ralg', x0 = -1.5,  iprint = -1, plot = 1, color = 'r')
33 # or
34 #r = p.manage('ralg', start = False, iprint = 0, x0 = -1.5)
35
36 """
37 Note that *any* kwarg passed to constructor will be assigned
38 e.g.
39 p = NLP(f, x0, myName='JohnSmith')
40 is equivalent to
41 p.myName='JohnSmith'
42 It can be very convenient for user-supplied callback functions
43 (see /examples/userCallback.py)
44 (instead of using "global" as you have to do in MATLAB)
45
46 See also http://openopt.org/OOFrameworkDoc#Result_structure for result structure (r) fields
47 """
Note: See TracBrowser for help on using the browser.