Tcl Library Source Code

Check-in [82424135be]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix problem with detecting exceptions in solving linear programs
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 82424135be412254f74e8dad9491f56733359aa4
User & Date: markus 2014-09-21 12:40:34
Context
2014-09-21
13:26
Solve two tickets (one regarding Nelder-Mead and one regarding bigfloat2). Added test cases check-in: 6922235385 user: markus tags: trunk
12:40
Fix problem with detecting exceptions in solving linear programs check-in: 82424135be user: markus tags: trunk
2014-09-02
20:37
Tkt [daa83d2edf]: uri::urn - Fix the handling of characters represented by a true multi-byte utf-8 sequence, in both encoding and decoding, i.e. quote and unquote. Fixed original test cases as well, they were broken. Bumped version to 1.0.3 check-in: 9c454867a1 user: andreask tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/math/ChangeLog.






1
2
3
4
5
6
7





2014-08-21  Arjen Markus <[email protected]>
	* calculus.tcl: Bumping version to 0.8
	* pkgIndex.tcl: Bumping version of math::calculus package to 0.8

2014-08-21  Arjen Markus <[email protected]>
	* calculus.man: Describe the qk15 procedure implementing Gauss-Kronrod 15 points quadrature rule
	* calculus.tcl: Implement the qk15 procedure for Gauss-Kronrod quadrature
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
2014-09-21  Arjen Markus <[email protected]>
	* optimize.tcl: Solve a problem with the detection of the exceptions in solving linear programs. Version 1.0.1
	* optimize.test: Added tests to distnguish infeasible and unbounded linear programs
	* pkgIndex.tcl: Bumping version of math::optimize package to 1.0.1

2014-08-21  Arjen Markus <[email protected]>
	* calculus.tcl: Bumping version to 0.8
	* pkgIndex.tcl: Bumping version of math::calculus package to 0.8

2014-08-21  Arjen Markus <[email protected]>
	* calculus.man: Describe the qk15 procedure implementing Gauss-Kronrod 15 points quadrature rule
	* calculus.tcl: Implement the qk15 procedure for Gauss-Kronrod quadrature

Changes to modules/math/optimize.tcl.

1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
        #
        # Now determine which one should leave
        # TODO: is a lack of a proper row indeed an
        #       indication of the infeasibility?
        #
        set nextrow [SimplexFindNextRow $tableau $nextcol]
        if { $nextrow == -1 } {
            return "infeasible"
        }

        #
        # Make the vector for sweeping through the tableau
        #
        set vector [SimplexMakeVector $tableau $nextcol $nextrow]








|







1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
        #
        # Now determine which one should leave
        # TODO: is a lack of a proper row indeed an
        #       indication of the infeasibility?
        #
        set nextrow [SimplexFindNextRow $tableau $nextcol]
        if { $nextrow == -1 } {
            return "unbounded"
        }

        #
        # Make the vector for sweeping through the tableau
        #
        set vector [SimplexMakeVector $tableau $nextcol $nextrow]

1127
1128
1129
1130
1131
1132
1133


1134
1135




1136
1137
1138
1139
1140
1141
1142
    set nvars     [expr {[llength $tableau]-2}]
    for {set i 0} {$i < $nvars } { incr i } {
        lappend result 0.0
    }

    set idx 0
    foreach col [lrange $firstcol 0 end-1] {


        set result [lreplace $result $col $col [lindex $secondcol $idx]]
        incr idx




    }

    return $result
}

# SimplexFindNextColumn --
#    Find the next column - the one with the largest negative







>
>
|
|
>
>
>
>







1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
    set nvars     [expr {[llength $tableau]-2}]
    for {set i 0} {$i < $nvars } { incr i } {
        lappend result 0.0
    }

    set idx 0
    foreach col [lrange $firstcol 0 end-1] {
        set value [lindex $secondcol $idx]
        if { $value >= 0.0 } {
            set result [lreplace $result $col $col [lindex $secondcol $idx]]
            incr idx
        } else {
            # If a negative component, then the problem was not feasible
            return "infeasible"
        }
    }

    return $result
}

# SimplexFindNextColumn --
#    Find the next column - the one with the largest negative
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
        lappend newtableau $newcol
    }

    return $newtableau
}

# Now we can announce our presence
package provide math::optimize 1.0

if { ![info exists ::argv0] || [string compare $::argv0 [info script]] } {
    return
}

namespace import math::optimize::min_bound_1d
namespace import math::optimize::maximum







|







1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
        lappend newtableau $newcol
    }

    return $newtableau
}

# Now we can announce our presence
package provide math::optimize 1.0.1

if { ![info exists ::argv0] || [string compare $::argv0 [info script]] } {
    return
}

namespace import math::optimize::min_bound_1d
namespace import math::optimize::maximum

Changes to modules/math/optimize.test.

446
447
448
449
450
451
452
453
454
455
456
457
458
459
460












461














462
463
464
465
466
467
468
	     ! [within_range [lindex $result 1]  0.333300 0.333360] } {
	      set ok 0
	}
	set ok
    } \
    -result 1

#
# TODO: Current algorithm makes no difference between infeasible
#       and unbounded
#
test linprog-2.1 "Unbounded program" \
    -body {
	set result [solveLinearProgram {3.0 4.0} {{1.0 -2.0 1.0} {-2.0 1.0 1.0}} ]
    } \












    -result "infeasible"















test linprog-3.1 "Simple 3D program" \
   -body {
	set result [solveLinearProgram \
	   {1.0 1.0 1.0} \
	   {{1.0  1.0  2.0  1.0}
	    {1.0  2.0  1.0  1.0}







<
<
<
<
|



>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>







446
447
448
449
450
451
452




453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
	     ! [within_range [lindex $result 1]  0.333300 0.333360] } {
	      set ok 0
	}
	set ok
    } \
    -result 1





test linprog-2.1 "Unbounded program 1" \
    -body {
	set result [solveLinearProgram {3.0 4.0} {{1.0 -2.0 1.0} {-2.0 1.0 1.0}} ]
    } \
    -result "unbounded"

test linprog-2.2 "Unbounded program 2" \
    -body {
	set result [::math::optimize::solveLinearProgram {2.0 1.0} {{3.0 0.0 6.0} {1.0  0.0 2.0}}]
    } \
    -result "unbounded"

test linprog-2.3 "Infeasible program" \
    -body {
	set result [::math::optimize::solveLinearProgram {2.0 1.0} {{3.0 1.0 6.0} {1.0 -1.0 2.0} {0.0 1.0 -3.0}}]
    } \
    -result "infeasible"

test linprog-2.4 "Degenerate program" \
    -body {
	# Solution: {1.0 3.0}
	set result [::math::optimize::solveLinearProgram {2.0 1.0} {{3.0 1.0 6.0} {1.0 -1.0 2.0} {0.0 1.0 3.0}}]
	set ok 1
	if { ! [within_range [lindex $result 0]  0.99999  1.00001] ||
	     ! [within_range [lindex $result 1]  2.99999  3.00001] } {
	      set ok 0
	}
	set ok

    } \
    -result 1

test linprog-3.1 "Simple 3D program" \
   -body {
	set result [solveLinearProgram \
	   {1.0 1.0 1.0} \
	   {{1.0  1.0  2.0  1.0}
	    {1.0  2.0  1.0  1.0}

Changes to modules/math/pkgIndex.tcl.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

if {![package vsatisfies [package provide Tcl] 8.3]} {return}
package ifneeded math::roman             1.0   [list source [file join $dir romannumerals.tcl]]

if {![package vsatisfies [package provide Tcl] 8.4]} {return}
# statistics depends on linearalgebra (for multi-variate linear regression).
package ifneeded math::statistics        0.9   [list source [file join $dir statistics.tcl]]
package ifneeded math::optimize          1.0   [list source [file join $dir optimize.tcl]]
package ifneeded math::calculus          0.8   [list source [file join $dir calculus.tcl]]
package ifneeded math::interpolate       1.1   [list source [file join $dir interpolate.tcl]]
package ifneeded math::linearalgebra     1.1.4 [list source [file join $dir linalg.tcl]]
package ifneeded math::bignum            3.1.1 [list source [file join $dir bignum.tcl]]
package ifneeded math::bigfloat          1.2.2 [list source [file join $dir bigfloat.tcl]]
package ifneeded math::machineparameters 0.1   [list source [file join $dir machineparameters.tcl]]








|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

if {![package vsatisfies [package provide Tcl] 8.3]} {return}
package ifneeded math::roman             1.0   [list source [file join $dir romannumerals.tcl]]

if {![package vsatisfies [package provide Tcl] 8.4]} {return}
# statistics depends on linearalgebra (for multi-variate linear regression).
package ifneeded math::statistics        0.9   [list source [file join $dir statistics.tcl]]
package ifneeded math::optimize          1.0.1 [list source [file join $dir optimize.tcl]]
package ifneeded math::calculus          0.8   [list source [file join $dir calculus.tcl]]
package ifneeded math::interpolate       1.1   [list source [file join $dir interpolate.tcl]]
package ifneeded math::linearalgebra     1.1.4 [list source [file join $dir linalg.tcl]]
package ifneeded math::bignum            3.1.1 [list source [file join $dir bignum.tcl]]
package ifneeded math::bigfloat          1.2.2 [list source [file join $dir bigfloat.tcl]]
package ifneeded math::machineparameters 0.1   [list source [file join $dir machineparameters.tcl]]