github.com/gopherd/gonum@v0.0.4/optimize/convex/lp/simplexexample_test.go (about)

     1  // Copyright ©2016 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package lp_test
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  
    11  	"github.com/gopherd/gonum/mat"
    12  	"github.com/gopherd/gonum/optimize/convex/lp"
    13  )
    14  
    15  func ExampleSimplex() {
    16  	c := []float64{-1, -2, 0, 0}
    17  	A := mat.NewDense(2, 4, []float64{-1, 2, 1, 0, 3, 1, 0, 1})
    18  	b := []float64{4, 9}
    19  
    20  	opt, x, err := lp.Simplex(c, A, b, 0, nil)
    21  	if err != nil {
    22  		log.Fatal(err)
    23  	}
    24  	fmt.Printf("opt: %v\n", opt)
    25  	fmt.Printf("x: %v\n", x)
    26  	// Output:
    27  	// opt: -8
    28  	// x: [2 3 0 0]
    29  }