math::optimize - Optimisation routines
package require Tcl 8.2
package require math::optimize ?0.1?
|
This package implements several optimisation algorithms:
The package is fully implemented in Tcl. No particular attention has been paid to the accuracy of the calculations. Instead, the algorithms have been used in a straightforward manner.
This document describes the procedures and explains their usage.
Note: The linear programming algorithm is described but not yet operational.
This package defines the following public procedures:
Several of the above procedures take the names of procedures as arguments. To avoid problems with the visibility of these procedures, the fully-qualified name of these procedures is determined inside the optimize routines. For the user this has only one consequence: the named procedure must be visible in the calling procedure. For instance:
namespace eval ::mySpace {
namespace export calcfunc
proc calcfunc { x } { return $x }
}
#
# Use a fully-qualified name
#
namespace eval ::myCalc {
puts [minimum ::myCalc::calcfunc $begin $end]
}
#
# Import the name
#
namespace eval ::myCalc {
namespace import ::mySpace::calcfunc
puts [minimum calcfunc $begin $end]
}
|
Let us take a few simple examples:
Determine the maximum of f(x) = x^3 exp(-3x), on the interval (0,10):
proc efunc { x } { expr {[$x*$x*$x * exp(-3.0*$x)]} }
puts "Maximum at: [::math::optimize::maximum 0.0 10.0 efunc]"
|
The maximum allowed error determines the number of steps taken (with each step in the iteration the interval is reduced with a factor 1/2). Hence, a maximum error of 0.0001 is achieved in approximately 14 steps.
An example of a linear program is:
Optimise the expression 3x+2y, where:
x >= 0 and y >= 0 (implicit constraints, part of the
definition of linear programs)
x + y <= 1 (constraints specific to the problem)
2x + 5y <= 10
|
This problem can be solved as follows:
set solution [::math::optimize::solveLinearProgram \
{ { 1.0 1.0 1.0 }
{ 2.0 5.0 10.0 } } \
{ 3.0 2.0 }]
|
Note, that a constraint like:
x + y >= 1 |
-x -y <= -1 |
The theory of linear programming is the subject of many a text book and the Simplex algorithm that is implemented here is the most well-known method to solve this type of problems.
linear program , math , maximum , minimum , optimization