tp

package
v0.0.0-...-d7aea0d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 2 Imported by: 1

README

Transportation Problem Implementation

It first tries to find a feasible solution with the "Least Cost" method and then tries to optimize it with the U,V method.

Documentation

Index

Constants

View Source
const (
	// default EPSILON value for checking if a value is zero or not
	EPSILON = float64(1e-6)

	// default max iterations for optimizing the solution
	MAX_ITER = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Problem

type Problem struct {
	// contains filtered or unexported fields
}

func CreateProblem

func CreateProblem(supply, demand []float64, costs [][]float64, opts ...float64) (*Problem, error)

Create a transportation problem from the given args.

supply, demand: positive float64 array/slice.
costs: 2-D matrix, row size should match supply length, column
       size should match demand length.

opts is for optional args:
 opts[0]: MAX_ITER, max iterations to run when optimizing the
          solution, default to 100.
 opts[1]: EPSILON, used to tell if a float64 value is zero or not,
          default to 1e-6.
 if you need to use a non-default EPSILON (opt[1]), you must also
 set MAX_ITER (opt[0]).

returns the Problem{} struct.

func (*Problem) GetCost

func (es *Problem) GetCost() float64

Get the solution cost, should be called after calling Solve().

func (*Problem) GetCostAndFlow

func (es *Problem) GetCostAndFlow() (float64, [][]float64)

Get the solution (both the total cost and the flow matrix), should be called after calling Solve().

func (*Problem) GetFlow

func (es *Problem) GetFlow() [][]float64

Get the flow matrix, should be called after calling Solve().

func (*Problem) Solve

func (es *Problem) Solve() error

Solve the transportation problem. Returns error if something goes wrong.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL